Add back typescript version number and add Deno.version object. (#1788)

This commit is contained in:
Yoshiya Hinosawa 2019-02-19 08:43:02 +09:00 committed by Ryan Dahl
parent 077af20ceb
commit 55edc06218
9 changed files with 48 additions and 5 deletions

View File

@ -109,6 +109,7 @@ ts_sources = [
"js/workers.ts",
"js/write_file.ts",
"js/performance.ts",
"js/version.ts",
"tsconfig.json",
# Listing package.json and yarn.lock as sources ensures the bundle is rebuilt

View File

@ -58,6 +58,7 @@ export { metrics, Metrics } from "./metrics";
export { resources } from "./resources";
export { run, RunOptions, Process, ProcessStatus } from "./process";
export { inspect } from "./console";
export { version } from "./version";
export const args: string[] = [];
// TODO Don't expose Console nor stringifyArgs.

View File

@ -9,6 +9,7 @@ import * as os from "./os";
import { libdeno } from "./libdeno";
import { args } from "./deno";
import { replLoop } from "./repl";
import { setVersions } from "./version";
// builtin modules
import * as deno from "./deno";
@ -24,12 +25,13 @@ export default function denoMain() {
libdeno.builtinModules["deno"] = deno;
Object.freeze(libdeno.builtinModules);
setVersions(startResMsg.denoVersion()!, startResMsg.v8Version()!);
// handle `--version`
if (startResMsg.versionFlag()) {
console.log("deno:", startResMsg.denoVersion());
console.log("v8:", startResMsg.v8Version());
// TODO figure out a way to restore functionality
// console.log("typescript:", version);
console.log("deno:", deno.version.deno);
console.log("v8:", deno.version.v8);
console.log("typescript:", deno.version.typescript);
os.exit(0);
}

View File

@ -44,6 +44,7 @@ import "./url_test.ts";
import "./url_search_params_test.ts";
import "./write_file_test.ts";
import "./performance_test.ts";
import "./version_test.ts";
import "../website/app_test.js";

23
js/version.ts Normal file
View File

@ -0,0 +1,23 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
interface Version {
deno: string;
v8: string;
typescript: string;
}
export const version: Version = {
deno: "",
v8: "",
typescript: "TS_VERSION" // This string will be replaced by rollup
};
/**
* Sets the deno and v8 versions and freezes the version object.
* @internal
*/
export function setVersions(denoVersion: string, v8Version: string): void {
version.deno = denoVersion;
version.v8 = v8Version;
Object.freeze(version);
}

8
js/version_test.ts Normal file
View File

@ -0,0 +1,8 @@
import { test, assert } from "./test_util.ts";
test(function version() {
const pattern = /^\d+\.\d+\.\d+$/;
assert(pattern.test(Deno.version.deno));
assert(pattern.test(Deno.version.v8));
assert(pattern.test(Deno.version.typescript));
});

View File

@ -15,6 +15,7 @@
"rollup-plugin-commonjs": "^9.1.3",
"rollup-plugin-node-globals": "^1.2.1",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-string": "^2.0.2",
"rollup-plugin-typescript2": "^0.16.1",
"rollup-pluginutils": "^2.3.0",

View File

@ -9,6 +9,7 @@ import globals from "rollup-plugin-node-globals";
import nodeResolve from "rollup-plugin-node-resolve";
import typescriptPlugin from "rollup-plugin-typescript2";
import { createFilter } from "rollup-pluginutils";
import replace from "rollup-plugin-replace";
import typescript from "typescript";
import MagicString from "magic-string";
@ -225,6 +226,11 @@ export default function makeConfig(commandOptions) {
include: [platformPath]
}),
// replace strings
replace({
TS_VERSION: typescript.version
}),
// would prefer to use `rollup-plugin-virtual` to inject the empty module, but there
// is an issue with `rollup-plugin-commonjs` which causes errors when using the
// virtual plugin (see: rollup/rollup-plugin-commonjs#315), this means we have to use

@ -1 +1 @@
Subproject commit c2745933463333cd2f864614d481881f73447cf2
Subproject commit 42eb39c9b4e4e6e4a84a97039f1f19e33b53b8bd