diff --git a/BUILD.gn b/BUILD.gn index 4f8550d0df..456da61feb 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -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 diff --git a/js/deno.ts b/js/deno.ts index 490494cc69..66d7d796c7 100644 --- a/js/deno.ts +++ b/js/deno.ts @@ -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. diff --git a/js/main.ts b/js/main.ts index 1116a11652..a5aae51a1d 100644 --- a/js/main.ts +++ b/js/main.ts @@ -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); } diff --git a/js/unit_tests.ts b/js/unit_tests.ts index a5fc836c50..c8479145b9 100644 --- a/js/unit_tests.ts +++ b/js/unit_tests.ts @@ -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"; diff --git a/js/version.ts b/js/version.ts new file mode 100644 index 0000000000..805e565a07 --- /dev/null +++ b/js/version.ts @@ -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); +} diff --git a/js/version_test.ts b/js/version_test.ts new file mode 100644 index 0000000000..d3d1bc3dfe --- /dev/null +++ b/js/version_test.ts @@ -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)); +}); diff --git a/package.json b/package.json index 08e8ea436d..ee97f7fc7e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/rollup.config.js b/rollup.config.js index 5bfab06d91..34f998b739 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -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 diff --git a/third_party b/third_party index c274593346..42eb39c9b4 160000 --- a/third_party +++ b/third_party @@ -1 +1 @@ -Subproject commit c2745933463333cd2f864614d481881f73447cf2 +Subproject commit 42eb39c9b4e4e6e4a84a97039f1f19e33b53b8bd