diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/Cargo.toml | 25 | ||||
-rw-r--r-- | js/README.md | 10 | ||||
-rw-r--r-- | js/build.rs | 28 | ||||
-rw-r--r-- | js/lib.rs | 55 | ||||
-rw-r--r-- | js/ts_global.d.ts | 7 | ||||
-rw-r--r-- | js/version_test.ts | 2 |
6 files changed, 125 insertions, 2 deletions
diff --git a/js/Cargo.toml b/js/Cargo.toml new file mode 100644 index 000000000..32fab5a60 --- /dev/null +++ b/js/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "deno_cli_snapshots" +version = "0.18.3" +license = "MIT" +authors = ["the Deno authors"] +edition = "2018" +description = "Provides snapshots for the deno CLI" +repository = "https://github.com/denoland/deno" +exclude = [ + "deps/https/deno.land/std/fs/testdata/0-link.ts", + "deps/https/deno.land/std/fs/testdata/copy_dir_link_file/0.txt", +] + +[lib] +path = "lib.rs" + +[dependencies] +deno_typescript = { path = "../deno_typescript", version = "0.18.3" } + +[dev-dependencies] +deno = { path = "../core", version = "0.18.0" } + +[build-dependencies] +deno_typescript = { path = "../deno_typescript", version = "0.18.3" } + diff --git a/js/README.md b/js/README.md new file mode 100644 index 000000000..850adb6ee --- /dev/null +++ b/js/README.md @@ -0,0 +1,10 @@ +# Crate: `deno_cli_snapshots` + +## AKA `cli_snapshots` AKA `//js` + +This is a small crate which exports just a few static blobs. It contains a +build.rs file which compiles Deno's internal JavaScript and TypeScript code +first into a single AMD bundle, and then into a binary V8 Snapshot. + +The main Deno executable crate ("cli") depends on this crate and has access to +all the runtime code. diff --git a/js/build.rs b/js/build.rs new file mode 100644 index 000000000..1063fd8eb --- /dev/null +++ b/js/build.rs @@ -0,0 +1,28 @@ +// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +use std::env; +use std::path::PathBuf; + +fn main() { + // To debug snapshot issues uncomment: + // deno_typescript::trace_serializer(); + + println!( + "cargo:rustc-env=TS_VERSION={}", + deno_typescript::ts_version() + ); + + let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); + let o = PathBuf::from(env::var_os("OUT_DIR").unwrap()); + + let root_names = vec![c.join("main.ts")]; + let bundle = o.join("CLI_SNAPSHOT.js"); + let state = deno_typescript::compile_bundle(&bundle, root_names).unwrap(); + assert!(bundle.exists()); + deno_typescript::mksnapshot_bundle(&bundle, state).unwrap(); + + let root_names = vec![c.join("compiler.ts")]; + let bundle = o.join("COMPILER_SNAPSHOT.js"); + let state = deno_typescript::compile_bundle(&bundle, root_names).unwrap(); + assert!(bundle.exists()); + deno_typescript::mksnapshot_bundle_ts(&bundle, state).unwrap(); +} diff --git a/js/lib.rs b/js/lib.rs new file mode 100644 index 000000000..89688b9a5 --- /dev/null +++ b/js/lib.rs @@ -0,0 +1,55 @@ +pub const TS_VERSION: &str = env!("TS_VERSION"); + +pub static CLI_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.bin")); +pub static CLI_SNAPSHOT_MAP: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.js.map")); +pub static CLI_SNAPSHOT_DTS: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.d.ts")); + +pub static COMPILER_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.bin")); +pub static COMPILER_SNAPSHOT_MAP: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.js.map")); +pub static COMPILER_SNAPSHOT_DTS: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.d.ts")); + +static DENO_RUNTIME: &str = include_str!("lib.deno_runtime.d.ts"); + +/// Same as deno_typescript::get_asset but also has lib.deno_runtime.d.ts +pub fn get_asset(name: &str) -> Option<&'static str> { + match name { + "lib.deno_runtime.d.ts" => Some(DENO_RUNTIME), + _ => deno_typescript::get_asset(name), + } +} + +#[test] +fn cli_snapshot() { + let mut isolate = + deno::Isolate::new(deno::StartupData::Snapshot(CLI_SNAPSHOT), false); + deno::js_check(isolate.execute( + "<anon>", + r#" + if (!window) { + throw Error("bad"); + } + console.log("we have console.log!!!"); + "#, + )); +} + +#[test] +fn compiler_snapshot() { + let mut isolate = + deno::Isolate::new(deno::StartupData::Snapshot(COMPILER_SNAPSHOT), false); + deno::js_check(isolate.execute( + "<anon>", + r#" + if (!compilerMain) { + throw Error("bad"); + } + console.log(`ts version: ${ts.version}`); + "#, + )); +} diff --git a/js/ts_global.d.ts b/js/ts_global.d.ts index d4b027926..71a01e30e 100644 --- a/js/ts_global.d.ts +++ b/js/ts_global.d.ts @@ -4,8 +4,13 @@ // when building Deno, but the `typescript/lib/typescript.d.ts` is defined as a // module. +// Warning! This is a magical import. We don't want to have multiple copies of +// typescript.d.ts around the repo, there's already one in +// deno_typescript/typescript/lib/typescript.d.ts. Ideally we could simply point +// to that in this import specifier, but "cargo package" is very strict and +// requires all files to be present in a crate's subtree. // eslint-disable-next-line @typescript-eslint/no-unused-vars -import * as ts_ from "../node_modules/typescript/lib/typescript.d.ts"; +import * as ts_ from "$asset$/typescript.d.ts"; declare global { namespace ts { diff --git a/js/version_test.ts b/js/version_test.ts index 7cc7bd404..b32230812 100644 --- a/js/version_test.ts +++ b/js/version_test.ts @@ -1,7 +1,7 @@ import { test, assert } from "./test_util.ts"; test(function version(): void { - const pattern = /^\d+\.\d+\.\d+$/; + const pattern = /^\d+\.\d+\.\d+/; assert(pattern.test(Deno.version.deno)); assert(pattern.test(Deno.version.v8)); assert(pattern.test(Deno.version.typescript)); |