mirror of
https://github.com/denoland/deno.git
synced 2024-12-24 16:19:12 -05:00
Handle typescript version in rust (#2855)
This commit is contained in:
parent
e9908453df
commit
249db0f7d9
7 changed files with 29 additions and 18 deletions
|
@ -398,6 +398,12 @@ fn run_script(flags: DenoFlags, argv: Vec<String>) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn version_command() {
|
||||||
|
println!("deno: {}", version::DENO);
|
||||||
|
println!("v8: {}", version::v8());
|
||||||
|
println!("typescript: {}", version::typescript());
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
ansi_term::enable_ansi_support().ok(); // For Windows 10
|
ansi_term::enable_ansi_support().ok(); // For Windows 10
|
||||||
|
@ -425,7 +431,7 @@ fn main() {
|
||||||
DenoSubcommand::Repl => run_repl(flags, argv),
|
DenoSubcommand::Repl => run_repl(flags, argv),
|
||||||
DenoSubcommand::Run => run_script(flags, argv),
|
DenoSubcommand::Run => run_script(flags, argv),
|
||||||
DenoSubcommand::Types => types_command(),
|
DenoSubcommand::Types => types_command(),
|
||||||
DenoSubcommand::Version => run_repl(flags, argv),
|
DenoSubcommand::Version => version_command(),
|
||||||
DenoSubcommand::Xeval => xeval_command(flags, argv),
|
DenoSubcommand::Xeval => xeval_command(flags, argv),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ pub fn op_start(
|
||||||
"versionFlag": state.flags.version,
|
"versionFlag": state.flags.version,
|
||||||
"v8Version": version::v8(),
|
"v8Version": version::v8(),
|
||||||
"denoVersion": version::DENO,
|
"denoVersion": version::DENO,
|
||||||
|
"tsVersion": version::typescript(),
|
||||||
"noColor": !ansi::use_color(),
|
"noColor": !ansi::use_color(),
|
||||||
"xevalDelim": state.flags.xeval_delim.clone(),
|
"xevalDelim": state.flags.xeval_delim.clone(),
|
||||||
})))
|
})))
|
||||||
|
|
|
@ -1,6 +1,17 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
|
use serde_json;
|
||||||
pub const DENO: &str = env!("CARGO_PKG_VERSION");
|
pub const DENO: &str = env!("CARGO_PKG_VERSION");
|
||||||
|
|
||||||
pub fn v8() -> &'static str {
|
pub fn v8() -> &'static str {
|
||||||
deno::v8_version()
|
deno::v8_version()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn typescript() -> String {
|
||||||
|
// TODO: By using include_str! we are including the package.json into
|
||||||
|
// the deno binary using serde to decode it at runtime. This is suboptimal
|
||||||
|
// in space and time. We need to extract the TypeScript version at compile
|
||||||
|
// time instead. This will be easier after #2608.
|
||||||
|
let data = include_str!("../node_modules/typescript/package.json");
|
||||||
|
let pkg: serde_json::Value = serde_json::from_str(data).unwrap();
|
||||||
|
pkg["version"].as_str().unwrap().to_string()
|
||||||
|
}
|
||||||
|
|
|
@ -10,7 +10,6 @@ function main(configText, rootNames, replacements_) {
|
||||||
println(`>>> rootNames ${rootNames}`);
|
println(`>>> rootNames ${rootNames}`);
|
||||||
|
|
||||||
replacements = replacements_;
|
replacements = replacements_;
|
||||||
replacements["DENO_REPLACE_TS_VERSION"] = ts.version;
|
|
||||||
println(`>>> replacements ${JSON.stringify(replacements)}`);
|
println(`>>> replacements ${JSON.stringify(replacements)}`);
|
||||||
|
|
||||||
const host = new Host();
|
const host = new Host();
|
||||||
|
|
13
js/main.ts
13
js/main.ts
|
@ -1,5 +1,4 @@
|
||||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
import "./globals.ts";
|
import "./globals.ts";
|
||||||
|
|
||||||
import { assert, log } from "./util.ts";
|
import { assert, log } from "./util.ts";
|
||||||
|
@ -11,21 +10,11 @@ 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 * as Deno from "./deno.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);
|
||||||
|
|
||||||
setVersions(s.denoVersion, s.v8Version);
|
setVersions(s.denoVersion, s.v8Version, s.tsVersion);
|
||||||
|
|
||||||
// handle `--version`
|
|
||||||
if (s.versionFlag) {
|
|
||||||
const { console } = window;
|
|
||||||
console.log("deno:", Deno.version.deno);
|
|
||||||
console.log("v8:", Deno.version.v8);
|
|
||||||
console.log("typescript:", Deno.version.typescript);
|
|
||||||
os.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
setPrepareStackTrace(Error);
|
setPrepareStackTrace(Error);
|
||||||
|
|
||||||
|
|
1
js/os.ts
1
js/os.ts
|
@ -59,6 +59,7 @@ interface Start {
|
||||||
versionFlag: boolean;
|
versionFlag: boolean;
|
||||||
denoVersion: string;
|
denoVersion: string;
|
||||||
v8Version: string;
|
v8Version: string;
|
||||||
|
tsVersion: string;
|
||||||
noColor: boolean;
|
noColor: boolean;
|
||||||
xevalDelim: string;
|
xevalDelim: string;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,17 +8,21 @@ interface Version {
|
||||||
export const version: Version = {
|
export const version: Version = {
|
||||||
deno: "",
|
deno: "",
|
||||||
v8: "",
|
v8: "",
|
||||||
// This string will be replaced by rollup
|
typescript: ""
|
||||||
typescript: `DENO_REPLACE_TS_VERSION`
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the deno and v8 versions and freezes the version object.
|
* Sets the deno, v8, and typescript versions and freezes the version object.
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export function setVersions(denoVersion: string, v8Version: string): void {
|
export function setVersions(
|
||||||
|
denoVersion: string,
|
||||||
|
v8Version: string,
|
||||||
|
tsVersion: string
|
||||||
|
): void {
|
||||||
version.deno = denoVersion;
|
version.deno = denoVersion;
|
||||||
version.v8 = v8Version;
|
version.v8 = v8Version;
|
||||||
|
version.typescript = tsVersion;
|
||||||
|
|
||||||
Object.freeze(version);
|
Object.freeze(version);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue