mirror of
https://github.com/denoland/deno.git
synced 2025-09-28 05:04:48 +00:00
Remove replacements hack in deno_typescript (#2864)
This commit is contained in:
parent
ca00039285
commit
595b4daa77
7 changed files with 41 additions and 44 deletions
|
@ -11,6 +11,16 @@ use std::collections::HashMap;
|
||||||
use std::env;
|
use std::env;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
/// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts.
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
static BUILD_OS: &str = "mac";
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
static BUILD_OS: &str = "linux";
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
static BUILD_OS: &str = "win";
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
static BUILD_ARCH: &str = "x64";
|
||||||
|
|
||||||
pub fn op_start(
|
pub fn op_start(
|
||||||
state: &ThreadSafeState,
|
state: &ThreadSafeState,
|
||||||
_args: Value,
|
_args: Value,
|
||||||
|
@ -31,6 +41,8 @@ pub fn op_start(
|
||||||
"tsVersion": version::typescript(),
|
"tsVersion": version::typescript(),
|
||||||
"noColor": !ansi::use_color(),
|
"noColor": !ansi::use_color(),
|
||||||
"xevalDelim": state.flags.xeval_delim.clone(),
|
"xevalDelim": state.flags.xeval_delim.clone(),
|
||||||
|
"os": BUILD_OS,
|
||||||
|
"arch": BUILD_ARCH,
|
||||||
})))
|
})))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,15 +3,10 @@
|
||||||
|
|
||||||
const ASSETS = "$asset$";
|
const ASSETS = "$asset$";
|
||||||
|
|
||||||
let replacements;
|
function main(configText, rootNames) {
|
||||||
|
|
||||||
function main(configText, rootNames, replacements_) {
|
|
||||||
println(`>>> ts version ${ts.version}`);
|
println(`>>> ts version ${ts.version}`);
|
||||||
println(`>>> rootNames ${rootNames}`);
|
println(`>>> rootNames ${rootNames}`);
|
||||||
|
|
||||||
replacements = replacements_;
|
|
||||||
println(`>>> replacements ${JSON.stringify(replacements)}`);
|
|
||||||
|
|
||||||
const host = new Host();
|
const host = new Host();
|
||||||
|
|
||||||
assert(rootNames.length > 0);
|
assert(rootNames.length > 0);
|
||||||
|
@ -148,12 +143,6 @@ class Host {
|
||||||
sourceCode = sourceCode.replace("export = ts;", "");
|
sourceCode = sourceCode.replace("export = ts;", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(ry) A terrible hack. Please remove ASAP.
|
|
||||||
for (let key of Object.keys(replacements)) {
|
|
||||||
let val = replacements[key];
|
|
||||||
sourceCode = sourceCode.replace(key, val);
|
|
||||||
}
|
|
||||||
|
|
||||||
let sourceFile = ts.createSourceFile(fileName, sourceCode, languageVersion);
|
let sourceFile = ts.createSourceFile(fileName, sourceCode, languageVersion);
|
||||||
sourceFile.moduleName = moduleName;
|
sourceFile.moduleName = moduleName;
|
||||||
return sourceFile;
|
return sourceFile;
|
||||||
|
|
|
@ -12,7 +12,6 @@ use deno::ModuleSpecifier;
|
||||||
use deno::StartupData;
|
use deno::StartupData;
|
||||||
pub use ops::EmitResult;
|
pub use ops::EmitResult;
|
||||||
use ops::WrittenFile;
|
use ops::WrittenFile;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -78,12 +77,8 @@ impl TSIsolate {
|
||||||
root_names: Vec<String>,
|
root_names: Vec<String>,
|
||||||
) -> Result<Arc<Mutex<TSState>>, ErrBox> {
|
) -> Result<Arc<Mutex<TSState>>, ErrBox> {
|
||||||
let root_names_json = serde_json::json!(root_names).to_string();
|
let root_names_json = serde_json::json!(root_names).to_string();
|
||||||
let source = &format!(
|
let source =
|
||||||
"main({:?}, {}, {})",
|
&format!("main({:?}, {})", config_json.to_string(), root_names_json);
|
||||||
config_json.to_string(),
|
|
||||||
root_names_json,
|
|
||||||
preprocessor_replacements_json()
|
|
||||||
);
|
|
||||||
self.isolate.execute("<anon>", source)?;
|
self.isolate.execute("<anon>", source)?;
|
||||||
Ok(self.state.clone())
|
Ok(self.state.clone())
|
||||||
}
|
}
|
||||||
|
@ -269,20 +264,3 @@ pub fn trace_serializer() {
|
||||||
deno::v8_set_flags(vec![dummy.clone(), "--trace-serializer".to_string()]);
|
deno::v8_set_flags(vec![dummy.clone(), "--trace-serializer".to_string()]);
|
||||||
assert_eq!(r, vec![dummy]);
|
assert_eq!(r, vec![dummy]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn preprocessor_replacements_json() -> String {
|
|
||||||
/// BUILD_OS and BUILD_ARCH match the values in Deno.build. See js/build.ts.
|
|
||||||
#[cfg(target_os = "macos")]
|
|
||||||
static BUILD_OS: &str = "mac";
|
|
||||||
#[cfg(target_os = "linux")]
|
|
||||||
static BUILD_OS: &str = "linux";
|
|
||||||
#[cfg(target_os = "windows")]
|
|
||||||
static BUILD_OS: &str = "win";
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
static BUILD_ARCH: &str = "x64";
|
|
||||||
|
|
||||||
let mut replacements = HashMap::new();
|
|
||||||
replacements.insert("DENO_REPLACE_OS", BUILD_OS);
|
|
||||||
replacements.insert("DENO_REPLACE_ARCH", BUILD_ARCH);
|
|
||||||
serde_json::json!(replacements).to_string()
|
|
||||||
}
|
|
||||||
|
|
15
js/build.ts
15
js/build.ts
|
@ -14,14 +14,17 @@ export interface BuildInfo {
|
||||||
os: OperatingSystem;
|
os: OperatingSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 'build' is injected by rollup.config.js at compile time.
|
|
||||||
export const build: BuildInfo = {
|
export const build: BuildInfo = {
|
||||||
// These string will be replaced by rollup
|
arch: "" as Arch,
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
os: "" as OperatingSystem
|
||||||
arch: `DENO_REPLACE_ARCH` as any,
|
|
||||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
||||||
os: `DENO_REPLACE_OS` as any
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function setBuildInfo(os: OperatingSystem, arch: Arch): void {
|
||||||
|
build.os = os;
|
||||||
|
build.arch = arch;
|
||||||
|
|
||||||
|
Object.freeze(build);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO(kevinkassimo): deprecate Deno.platform
|
// TODO(kevinkassimo): deprecate Deno.platform
|
||||||
export const platform = build;
|
export const platform = build;
|
||||||
|
|
|
@ -10,10 +10,14 @@ import { xevalMain, XevalFunc } from "./xeval.ts";
|
||||||
import { setVersions } from "./version.ts";
|
import { setVersions } from "./version.ts";
|
||||||
import { window } from "./window.ts";
|
import { window } from "./window.ts";
|
||||||
import { setLocation } from "./location.ts";
|
import { setLocation } from "./location.ts";
|
||||||
|
import { setBuildInfo } from "./build.ts";
|
||||||
|
import { setSignals } from "./process.ts";
|
||||||
|
|
||||||
function denoMain(preserveDenoNamespace: boolean = true, name?: string): void {
|
function denoMain(preserveDenoNamespace: boolean = true, name?: string): void {
|
||||||
const s = os.start(preserveDenoNamespace, name);
|
const s = os.start(preserveDenoNamespace, name);
|
||||||
|
|
||||||
|
setBuildInfo(s.os, s.arch);
|
||||||
|
setSignals();
|
||||||
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
|
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
|
||||||
|
|
||||||
setPrepareStackTrace(Error);
|
setPrepareStackTrace(Error);
|
||||||
|
|
3
js/os.ts
3
js/os.ts
|
@ -5,6 +5,7 @@ import { sendSync } from "./dispatch_json.ts";
|
||||||
import { assert } from "./util.ts";
|
import { assert } from "./util.ts";
|
||||||
import * as util from "./util.ts";
|
import * as util from "./util.ts";
|
||||||
import { window } from "./window.ts";
|
import { window } from "./window.ts";
|
||||||
|
import { OperatingSystem, Arch } from "./build.ts";
|
||||||
|
|
||||||
// builtin modules
|
// builtin modules
|
||||||
import { _setGlobals } from "./deno.ts";
|
import { _setGlobals } from "./deno.ts";
|
||||||
|
@ -62,6 +63,8 @@ interface Start {
|
||||||
tsVersion: string;
|
tsVersion: string;
|
||||||
noColor: boolean;
|
noColor: boolean;
|
||||||
xevalDelim: string;
|
xevalDelim: string;
|
||||||
|
os: OperatingSystem;
|
||||||
|
arch: Arch;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function bootstraps an environment within Deno, it is shared both by
|
// This function bootstraps an environment within Deno, it is shared both by
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { File, close } from "./files.ts";
|
||||||
import { ReadCloser, WriteCloser } from "./io.ts";
|
import { ReadCloser, WriteCloser } from "./io.ts";
|
||||||
import { readAll } from "./buffer.ts";
|
import { readAll } from "./buffer.ts";
|
||||||
import { assert, unreachable } from "./util.ts";
|
import { assert, unreachable } from "./util.ts";
|
||||||
import { platform } from "./build.ts";
|
import { build } from "./build.ts";
|
||||||
|
|
||||||
/** How to handle subprocess stdio.
|
/** How to handle subprocess stdio.
|
||||||
*
|
*
|
||||||
|
@ -296,4 +296,12 @@ enum MacOSSignal {
|
||||||
|
|
||||||
/** Signals numbers. This is platform dependent.
|
/** Signals numbers. This is platform dependent.
|
||||||
*/
|
*/
|
||||||
export const Signal = platform.os === "mac" ? MacOSSignal : LinuxSignal;
|
export const Signal = {};
|
||||||
|
|
||||||
|
export function setSignals(): void {
|
||||||
|
if (build.os === "mac") {
|
||||||
|
Object.assign(Signal, MacOSSignal);
|
||||||
|
} else {
|
||||||
|
Object.assign(Signal, LinuxSignal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue