0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-10-29 08:58:01 -04:00

Remove replacements hack in deno_typescript (#2864)

This commit is contained in:
Yoshiya Hinosawa 2019-09-07 01:57:15 +09:00 committed by Ryan Dahl
parent ca00039285
commit 595b4daa77
7 changed files with 41 additions and 44 deletions

View file

@ -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,
})))
}

View file

@ -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;

View file

@ -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()
}

View file

@ -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;

View file

@ -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);

View file

@ -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

View file

@ -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);
}
}