diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2019-09-07 01:57:15 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-09-06 12:57:15 -0400 |
commit | 595b4daa77771458457e178b6b590a044cd41ad0 (patch) | |
tree | d8b19636e4795bcb11ba5c45982d32334da60115 | |
parent | ca000392857b4c79a3609ddbc20073222498998b (diff) |
Remove replacements hack in deno_typescript (#2864)
-rw-r--r-- | cli/ops/os.rs | 12 | ||||
-rw-r--r-- | deno_typescript/compiler_main.js | 13 | ||||
-rw-r--r-- | deno_typescript/lib.rs | 26 | ||||
-rw-r--r-- | js/build.ts | 15 | ||||
-rw-r--r-- | js/main.ts | 4 | ||||
-rw-r--r-- | js/os.ts | 3 | ||||
-rw-r--r-- | js/process.ts | 12 |
7 files changed, 41 insertions, 44 deletions
diff --git a/cli/ops/os.rs b/cli/ops/os.rs index d644d893b..61484ca41 100644 --- a/cli/ops/os.rs +++ b/cli/ops/os.rs @@ -11,6 +11,16 @@ use std::collections::HashMap; use std::env; 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( state: &ThreadSafeState, _args: Value, @@ -31,6 +41,8 @@ pub fn op_start( "tsVersion": version::typescript(), "noColor": !ansi::use_color(), "xevalDelim": state.flags.xeval_delim.clone(), + "os": BUILD_OS, + "arch": BUILD_ARCH, }))) } diff --git a/deno_typescript/compiler_main.js b/deno_typescript/compiler_main.js index 1cc42072a..3a916f540 100644 --- a/deno_typescript/compiler_main.js +++ b/deno_typescript/compiler_main.js @@ -3,15 +3,10 @@ const ASSETS = "$asset$"; -let replacements; - -function main(configText, rootNames, replacements_) { +function main(configText, rootNames) { println(`>>> ts version ${ts.version}`); println(`>>> rootNames ${rootNames}`); - replacements = replacements_; - println(`>>> replacements ${JSON.stringify(replacements)}`); - const host = new Host(); assert(rootNames.length > 0); @@ -148,12 +143,6 @@ class Host { 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); sourceFile.moduleName = moduleName; return sourceFile; diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs index cf4b39d09..a9b95421d 100644 --- a/deno_typescript/lib.rs +++ b/deno_typescript/lib.rs @@ -12,7 +12,6 @@ use deno::ModuleSpecifier; use deno::StartupData; pub use ops::EmitResult; use ops::WrittenFile; -use std::collections::HashMap; use std::fs; use std::path::Path; use std::path::PathBuf; @@ -78,12 +77,8 @@ impl TSIsolate { root_names: Vec<String>, ) -> Result<Arc<Mutex<TSState>>, ErrBox> { let root_names_json = serde_json::json!(root_names).to_string(); - let source = &format!( - "main({:?}, {}, {})", - config_json.to_string(), - root_names_json, - preprocessor_replacements_json() - ); + let source = + &format!("main({:?}, {})", config_json.to_string(), root_names_json); self.isolate.execute("<anon>", source)?; Ok(self.state.clone()) } @@ -269,20 +264,3 @@ pub fn trace_serializer() { deno::v8_set_flags(vec![dummy.clone(), "--trace-serializer".to_string()]); 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() -} diff --git a/js/build.ts b/js/build.ts index 157de30bc..16640d793 100644 --- a/js/build.ts +++ b/js/build.ts @@ -14,14 +14,17 @@ export interface BuildInfo { os: OperatingSystem; } -// 'build' is injected by rollup.config.js at compile time. export const build: BuildInfo = { - // These string will be replaced by rollup - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ - arch: `DENO_REPLACE_ARCH` as any, - /* eslint-disable-next-line @typescript-eslint/no-explicit-any */ - os: `DENO_REPLACE_OS` as any + arch: "" as Arch, + os: "" as OperatingSystem }; +export function setBuildInfo(os: OperatingSystem, arch: Arch): void { + build.os = os; + build.arch = arch; + + Object.freeze(build); +} + // TODO(kevinkassimo): deprecate Deno.platform export const platform = build; diff --git a/js/main.ts b/js/main.ts index 6ce3551ac..474fc74a4 100644 --- a/js/main.ts +++ b/js/main.ts @@ -10,10 +10,14 @@ import { xevalMain, XevalFunc } from "./xeval.ts"; import { setVersions } from "./version.ts"; import { window } from "./window.ts"; import { setLocation } from "./location.ts"; +import { setBuildInfo } from "./build.ts"; +import { setSignals } from "./process.ts"; function denoMain(preserveDenoNamespace: boolean = true, name?: string): void { const s = os.start(preserveDenoNamespace, name); + setBuildInfo(s.os, s.arch); + setSignals(); setVersions(s.denoVersion, s.v8Version, s.tsVersion); setPrepareStackTrace(Error); @@ -5,6 +5,7 @@ import { sendSync } from "./dispatch_json.ts"; import { assert } from "./util.ts"; import * as util from "./util.ts"; import { window } from "./window.ts"; +import { OperatingSystem, Arch } from "./build.ts"; // builtin modules import { _setGlobals } from "./deno.ts"; @@ -62,6 +63,8 @@ interface Start { tsVersion: string; noColor: boolean; xevalDelim: string; + os: OperatingSystem; + arch: Arch; } // This function bootstraps an environment within Deno, it is shared both by diff --git a/js/process.ts b/js/process.ts index 4de9fe774..0c77929f9 100644 --- a/js/process.ts +++ b/js/process.ts @@ -5,7 +5,7 @@ import { File, close } from "./files.ts"; import { ReadCloser, WriteCloser } from "./io.ts"; import { readAll } from "./buffer.ts"; import { assert, unreachable } from "./util.ts"; -import { platform } from "./build.ts"; +import { build } from "./build.ts"; /** How to handle subprocess stdio. * @@ -296,4 +296,12 @@ enum MacOSSignal { /** 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); + } +} |