summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2019-09-02 17:07:11 -0400
committerGitHub <noreply@github.com>2019-09-02 17:07:11 -0400
commitd43b43ca781b025b9a6a54827ea3ef193972ef24 (patch)
tree84173b6a653802a41c23145dd3b2048d9075e2a4
parent56508f113d9fe61ffcce4cbbb85e3d6961888e1d (diff)
Refactor snapshot build (#2825)
Instead of using core/snapshot_creator.rs, instead two crates are introduced which allow building the snapshot during build.rs. Rollup is removed and replaced with our own bundler. This removes the Node build dependency. Modules in //js now use Deno-style imports with file extensions, rather than Node style extensionless imports. This improves incremental build time when changes are made to //js files by about 40 seconds.
-rw-r--r--.appveyor.yml33
-rw-r--r--Cargo.lock19
-rw-r--r--Cargo.toml2
-rw-r--r--cli/BUILD.gn150
-rw-r--r--cli/Cargo.toml2
-rw-r--r--cli/assets.rs53
-rw-r--r--cli/build.rs15
-rw-r--r--cli/deno.gni65
-rw-r--r--cli/main.rs1
-rw-r--r--cli/source_maps.rs26
-rw-r--r--cli/startup_data.rs10
-rw-r--r--cli_snapshots/BUILD.gn121
-rw-r--r--cli_snapshots/Cargo.toml18
-rw-r--r--cli_snapshots/README.md9
-rw-r--r--cli_snapshots/build.rs24
-rw-r--r--cli_snapshots/lib.rs43
-rw-r--r--cli_snapshots/run.py15
-rw-r--r--core/BUILD.gn12
-rw-r--r--core/Cargo.toml6
-rw-r--r--core/core.d.ts26
-rw-r--r--core/snapshot_creator.rs44
-rw-r--r--deno_typescript/BUILD.gn22
-rw-r--r--deno_typescript/Cargo.toml16
-rw-r--r--deno_typescript/README.md8
-rw-r--r--deno_typescript/amd_runtime.js39
-rw-r--r--deno_typescript/compiler_main.js320
-rw-r--r--deno_typescript/lib.deno_core.d.ts (renamed from core/libdeno/libdeno.d.ts)33
-rw-r--r--deno_typescript/lib.rs288
-rw-r--r--deno_typescript/ops.rs141
-rw-r--r--js/blob.ts8
-rw-r--r--js/body.ts10
-rw-r--r--js/buffer.ts8
-rw-r--r--js/build.ts4
-rw-r--r--js/chmod.ts4
-rw-r--r--js/chown.ts4
-rw-r--r--js/colors.ts2
-rw-r--r--js/compiler.ts40
-rw-r--r--js/console.ts10
-rw-r--r--js/console_table.ts4
-rw-r--r--js/copy_file.ts4
-rw-r--r--js/core.ts2
-rw-r--r--js/custom_event.ts6
-rw-r--r--js/deno.ts90
-rw-r--r--js/diagnostics.ts2
-rw-r--r--js/dir.ts4
-rw-r--r--js/dispatch.ts4
-rw-r--r--js/dispatch_json.ts8
-rw-r--r--js/dispatch_json_test.ts6
-rw-r--r--js/dispatch_minimal.ts4
-rw-r--r--js/dom_file.ts4
-rw-r--r--js/dom_util.ts2
-rw-r--r--js/error_stack.ts6
-rw-r--r--js/error_stack_test.ts11
-rw-r--r--js/event.ts4
-rw-r--r--js/event_target.ts8
-rw-r--r--js/fetch.ts29
-rw-r--r--js/file_info.ts2
-rw-r--r--js/files.ts8
-rw-r--r--js/form_data.ts10
-rw-r--r--js/format_error.ts4
-rw-r--r--js/get_random_values.ts6
-rw-r--r--js/globals.ts45
-rw-r--r--js/headers.ts6
-rw-r--r--js/link.ts4
-rw-r--r--js/location.ts8
-rw-r--r--js/main.ts44
-rw-r--r--js/make_temp_dir.ts4
-rw-r--r--js/metrics.ts4
-rw-r--r--js/mixins/dom_iterable.ts6
-rw-r--r--js/mkdir.ts4
-rw-r--r--js/net.ts10
-rw-r--r--js/os.ts31
-rw-r--r--js/performance.ts4
-rw-r--r--js/permissions.ts4
-rw-r--r--js/plugins.d.ts9
-rw-r--r--js/process.ts14
-rw-r--r--js/read_dir.ts8
-rw-r--r--js/read_file.ts4
-rw-r--r--js/read_link.ts4
-rw-r--r--js/remove.ts4
-rw-r--r--js/rename.ts4
-rw-r--r--js/repl.ts18
-rw-r--r--js/request.ts6
-rw-r--r--js/resources.ts4
-rw-r--r--js/stat.ts6
-rw-r--r--js/symlink.ts8
-rw-r--r--js/text_encoding.ts6
-rw-r--r--js/timers.ts10
-rw-r--r--js/truncate.ts4
-rw-r--r--js/url.ts8
-rw-r--r--js/url_search_params.ts4
-rw-r--r--js/util.ts4
-rw-r--r--js/utime.ts4
-rw-r--r--js/version.ts2
-rw-r--r--js/workers.ts14
-rw-r--r--js/write_file.ts8
-rw-r--r--js/xeval.ts8
-rw-r--r--package.json12
-rw-r--r--rollup.config.js231
-rw-r--r--tests/error_004_missing_module.ts.out16
-rw-r--r--tests/error_005_missing_dynamic_import.ts.out14
-rw-r--r--tests/error_006_import_ext_failure.ts.out14
-rw-r--r--tests/error_011_bad_module_specifier.ts.out14
-rw-r--r--tests/error_012_bad_dynamic_import_specifier.ts.out14
-rw-r--r--tests/error_type_definitions.ts.out4
m---------third_party0
-rwxr-xr-xtools/benchmark.py35
-rwxr-xr-xtools/benchmark_test.py6
-rwxr-xr-xtools/format.py18
-rw-r--r--website/manual.md3
110 files changed, 1550 insertions, 1045 deletions
diff --git a/.appveyor.yml b/.appveyor.yml
index 617a5c034..e1e564576 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -200,10 +200,6 @@ test_script:
- ps: Exec { & python tools\test.py --build-dir $env:DENO_BUILD_PATH }
after_test:
- # Delete the the rollup cache, which is unreliable, so that it doesn't get
- # persisted in the appveyor cache.
- - ps: if (Get-SaveCache) { Delete-Tree "$env:DENO_BUILD_PATH\.rpt2_cache" }
-
# Stop sccache and show stats.
- ps: sccache --stop-server
@@ -215,36 +211,15 @@ after_test:
throw "Build should be up-to-date but isn't."
}
- # Verify that javascript and typescript files which are bundled by rollup are
- # listed explicitly in cli\BUILD.gn. This is not an air-tight check.
- # TODO: make rollup or another bundler write a depfile.
+ # Verify that the bundled javascript and typescript files are listed
+ # explicitly in cli_snapshots\BUILD.gn. This is not an air-tight check.
- ps: |-
$ignore = "test_util.ts", "unit_tests.ts", "unit_test_runner.ts", "*_test.ts"
Get-ChildItem "js" -File -Force -Name |
where { $name = $_; -not ($ignore | where { $name -like $_ }) } |
- where { -not (Select-String -Pattern $_ -Path cli\BUILD.gn `
+ where { -not (Select-String -Pattern $_ -Path cli_snapshots\BUILD.gn `
-SimpleMatch -CaseSensitive) } |
- foreach { throw "$_ should be listed in cli\BUILD.gn but isn't." }
-
- # Verify that generated ninja files do not use absolute path names.
- # If they do, it makes ccache/sccache much less effective.
- - ps: |-
- $trap = "NO_ABS_PATH_PLS"
- $dir = "$env:APPVEYOR_BUILD_FOLDER\out\$trap"
- Exec { gn gen $dir | Out-Null }
- $files = Get-Tree $dir -File -Force -Recurse | where Extension -ne ".dll"
- Select-String $trap -Path $files -SimpleMatch | where {
- # V8 took the liberty to produce an absolute path in their ninja
- # output. We can't do much about that, so we just ignore it.
- $_.Line -notmatch "v8/builtins-generated/bytecodes-builtins-list.h"
- } | tee -Variable line_matches
- if ($line_matches) {
- $ctx = $line_matches.Line |
- Select-String "[^\s;,]*[\s=]*[^\s;,=]*$trap[^\s;,]*" -AllMatches |
- foreach { $_.Matches.Value -replace '\$(.)', '$1' } |
- sort -Unique
- throw @("Absolute path(s) found in build script:") + $ctx -join "`n "
- }
+ foreach { throw "$_ should be listed in cli_snapshots\BUILD.gn but isn't." }
# If this build is going to be deployed, build a zip file.
- ps: |-
diff --git a/Cargo.lock b/Cargo.lock
index cc6dde370..c1bab2c7e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -272,6 +272,8 @@ dependencies = [
"atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
"deno 0.16.0",
+ "deno_cli_snapshots 0.0.3",
+ "deno_typescript 0.0.3",
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
"fwdansi 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -309,6 +311,23 @@ dependencies = [
]
[[package]]
+name = "deno_cli_snapshots"
+version = "0.0.3"
+dependencies = [
+ "deno 0.16.0",
+ "deno_typescript 0.0.3",
+]
+
+[[package]]
+name = "deno_typescript"
+version = "0.0.3"
+dependencies = [
+ "deno 0.16.0",
+ "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
name = "dirs"
version = "2.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 1aa173285..084258c32 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -3,4 +3,6 @@ members = [
"cli",
"core",
"tools/hyper_hello",
+ "deno_typescript",
+ "cli_snapshots",
]
diff --git a/cli/BUILD.gn b/cli/BUILD.gn
index fd89d1941..ce18eb297 100644
--- a/cli/BUILD.gn
+++ b/cli/BUILD.gn
@@ -1,9 +1,6 @@
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
import("//build/toolchain/cc_wrapper.gni")
import("//build_extra/rust/rust.gni")
-import("//third_party/v8/gni/snapshot_toolchain.gni")
-import("//third_party/v8/gni/v8.gni")
-import("deno.gni")
main_extern = [
{
@@ -12,6 +9,16 @@ main_extern = [
crate_type = "rlib"
},
{
+ label = "../cli_snapshots:deno_cli_snapshots"
+ crate_name = "deno_cli_snapshots"
+ crate_type = "rlib"
+ },
+ {
+ label = "../deno_typescript:deno_typescript"
+ crate_name = "deno_typescript"
+ crate_type = "rlib"
+ },
+ {
label = "$rust_build:serde_derive"
crate_name = "serde_derive"
crate_type = "proc_macro"
@@ -61,109 +68,6 @@ if (is_posix) {
main_extern_rlib += [ "nix" ]
}
-ts_sources = [
- "../js/base64.ts",
- "../js/blob.ts",
- "../js/body.ts",
- "../js/buffer.ts",
- "../js/build.ts",
- "../js/chmod.ts",
- "../js/chown.ts",
- "../js/colors.ts",
- "../js/compiler.ts",
- "../js/console.ts",
- "../js/console_table.ts",
- "../js/copy_file.ts",
- "../js/core.ts",
- "../js/custom_event.ts",
- "../js/deno.ts",
- "../js/diagnostics.ts",
- "../js/dir.ts",
- "../js/dispatch.ts",
- "../js/dispatch_json.ts",
- "../js/dispatch_minimal.ts",
- "../js/dom_file.ts",
- "../js/dom_types.ts",
- "../js/dom_util.ts",
- "../js/error_stack.ts",
- "../js/errors.ts",
- "../js/event.ts",
- "../js/event_target.ts",
- "../js/fetch.ts",
- "../js/file_info.ts",
- "../js/files.ts",
- "../js/form_data.ts",
- "../js/format_error.ts",
- "../js/get_random_values.ts",
- "../js/globals.ts",
- "../js/headers.ts",
- "../js/io.ts",
- "../js/lib.deno_runtime.d.ts",
- "../js/lib.web_assembly.d.ts",
- "../js/link.ts",
- "../js/location.ts",
- "../js/main.ts",
- "../js/make_temp_dir.ts",
- "../js/metrics.ts",
- "../js/mkdir.ts",
- "../js/mock_builtin.js",
- "../js/net.ts",
- "../js/os.ts",
- "../js/performance.ts",
- "../js/permissions.ts",
- "../js/plugins.d.ts",
- "../js/process.ts",
- "../js/read_dir.ts",
- "../js/read_file.ts",
- "../js/read_link.ts",
- "../js/remove.ts",
- "../js/rename.ts",
- "../js/repl.ts",
- "../js/request.ts",
- "../js/resources.ts",
- "../js/stat.ts",
- "../js/symlink.ts",
- "../js/text_encoding.ts",
- "../js/timers.ts",
- "../js/truncate.ts",
- "../js/type_directives.ts",
- "../js/types.ts",
- "../js/url.ts",
- "../js/url_search_params.ts",
- "../js/util.ts",
- "../js/utime.ts",
- "../js/version.ts",
- "../js/window.ts",
- "../js/workers.ts",
- "../js/write_file.ts",
- "../js/xeval.ts",
- "../tsconfig.json",
-
- # Listing package.json and yarn.lock as sources ensures the bundle is rebuilt
- # when npm packages are added/removed or their contents changes.
- "../package.json",
- "../third_party/yarn.lock",
-]
-
-# When Cargo is driving the build, GN/Ninja are used to produce these non-Rust
-# targets. Cargo handles all Rust source files and the final linking step.
-group("deno_deps") {
- deps = [
- ":snapshot_compiler",
- ":snapshot_deno",
- ]
-}
-
-# Optimized dependencies for cross compiled builds.
-# This can be removed once we get snapshots into cross compiled builds.
-group("deno_deps_cross") {
- testonly = true
- deps = [
- ":compiler_bundle",
- ":main_bundle",
- ]
-}
-
# Reads the cargo info from Cargo.toml
deno_cargo_info = exec_script("../build_extra/rust/get_cargo_info.py",
[ rebase_path("Cargo.toml", root_build_dir) ],
@@ -173,9 +77,6 @@ rust_executable("deno") {
source_root = "main.rs"
extern = main_extern
extern_rlib = main_extern_rlib
- deps = [
- ":deno_deps",
- ]
# Extract version from Cargo.toml
# TODO integrate this into rust.gni by allowing the rust_executable template
@@ -190,9 +91,6 @@ rust_test("cli_test") {
source_root = "main.rs"
extern = main_extern
extern_rlib = main_extern_rlib
- deps = [
- ":deno_deps",
- ]
# Extract version from Cargo.toml
inputs = [
@@ -200,31 +98,3 @@ rust_test("cli_test") {
]
env = [ "CARGO_PKG_VERSION=${deno_cargo_info.version}" ]
}
-
-bundle("main_bundle") {
- sources = ts_sources
- out_dir = "$target_gen_dir/bundle/"
- out_name = "main"
-}
-
-bundle("compiler_bundle") {
- sources = ts_sources
- out_dir = "$target_gen_dir/bundle/"
- out_name = "compiler"
-}
-
-# Generates $target_gen_dir/snapshot_deno.bin
-snapshot("snapshot_deno") {
- source_root = "$target_gen_dir/bundle/main.js"
- deps = [
- ":main_bundle",
- ]
-}
-
-# Generates $target_gen_dir/snapshot_compiler.bin
-snapshot("snapshot_compiler") {
- source_root = "$target_gen_dir/bundle/compiler.js"
- deps = [
- ":compiler_bundle",
- ]
-}
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 6fac49e3d..02d241003 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -52,6 +52,8 @@ tokio-rustls = "0.10.0"
tokio-threadpool = "0.1.15"
url = "1.7.2"
utime = "0.2.1"
+deno_cli_snapshots = { path = "../cli_snapshots" }
+deno_typescript = { path = "../deno_typescript" }
[target.'cfg(windows)'.dependencies]
winapi = "0.3.7"
diff --git a/cli/assets.rs b/cli/assets.rs
index c7bfc484d..a0abca115 100644
--- a/cli/assets.rs
+++ b/cli/assets.rs
@@ -1,59 +1,8 @@
static DENO_RUNTIME: &str = include_str!("../js/lib.deno_runtime.d.ts");
-macro_rules! inc {
- ($e:expr) => {
- Some(include_str!(concat!(
- "../third_party/node_modules/typescript/lib/",
- $e
- )))
- };
-}
-
pub fn get_source_code(name: &str) -> Option<&'static str> {
match name {
"lib.deno_runtime.d.ts" => Some(DENO_RUNTIME),
- "lib.es2015.collection.d.ts" => inc!("lib.es2015.collection.d.ts"),
- "lib.es2015.core.d.ts" => inc!("lib.es2015.core.d.ts"),
- "lib.es2015.d.ts" => inc!("lib.es2015.d.ts"),
- "lib.es2015.generator.d.ts" => inc!("lib.es2015.generator.d.ts"),
- "lib.es2015.iterable.d.ts" => inc!("lib.es2015.iterable.d.ts"),
- "lib.es2015.promise.d.ts" => inc!("lib.es2015.promise.d.ts"),
- "lib.es2015.proxy.d.ts" => inc!("lib.es2015.proxy.d.ts"),
- "lib.es2015.reflect.d.ts" => inc!("lib.es2015.reflect.d.ts"),
- "lib.es2015.symbol.d.ts" => inc!("lib.es2015.symbol.d.ts"),
- "lib.es2015.symbol.wellknown.d.ts" => {
- inc!("lib.es2015.symbol.wellknown.d.ts")
- }
- "lib.es2016.array.include.d.ts" => inc!("lib.es2016.array.include.d.ts"),
- "lib.es2016.d.ts" => inc!("lib.es2016.d.ts"),
- "lib.es2017.d.ts" => inc!("lib.es2017.d.ts"),
- "lib.es2017.intl.d.ts" => inc!("lib.es2017.intl.d.ts"),
- "lib.es2017.object.d.ts" => inc!("lib.es2017.object.d.ts"),
- "lib.es2017.sharedmemory.d.ts" => inc!("lib.es2017.sharedmemory.d.ts"),
- "lib.es2017.string.d.ts" => inc!("lib.es2017.string.d.ts"),
- "lib.es2017.typedarrays.d.ts" => inc!("lib.es2017.typedarrays.d.ts"),
- "lib.es2018.d.ts" => inc!("lib.es2018.d.ts"),
- "lib.es2018.asynciterable.d.ts" => inc!("lib.es2018.asynciterable.d.ts"),
- "lib.es2018.intl.d.ts" => inc!("lib.es2018.intl.d.ts"),
- "lib.es2018.promise.d.ts" => inc!("lib.es2018.promise.d.ts"),
- "lib.es2018.regexp.d.ts" => inc!("lib.es2018.regexp.d.ts"),
- "lib.es2019.d.ts" => inc!("lib.es2019.d.ts"),
- "lib.es2019.array.d.ts" => inc!("lib.es2019.array.d.ts"),
- "lib.es2019.object.d.ts" => inc!("lib.es2019.object.d.ts"),
- "lib.es2019.string.d.ts" => inc!("lib.es2019.string.d.ts"),
- "lib.es2019.symbol.d.ts" => inc!("lib.es2019.symbol.d.ts"),
- "lib.es2020.d.ts" => inc!("lib.es2020.d.ts"),
- "lib.es2020.string.d.ts" => inc!("lib.es2020.string.d.ts"),
- "lib.es2020.symbol.wellknown.d.ts" => {
- inc!("lib.es2020.symbol.wellknown.d.ts")
- }
- "lib.es5.d.ts" => inc!("lib.es5.d.ts"),
- "lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
- "lib.esnext.array.d.ts" => inc!("lib.esnext.array.d.ts"),
- "lib.esnext.asynciterable.d.ts" => inc!("lib.esnext.asynciterable.d.ts"),
- "lib.esnext.bigint.d.ts" => inc!("lib.esnext.bigint.d.ts"),
- "lib.esnext.intl.d.ts" => inc!("lib.esnext.intl.d.ts"),
- "lib.esnext.symbol.d.ts" => inc!("lib.esnext.symbol.d.ts"),
- _ => None,
+ _ => deno_typescript::get_asset(name),
}
}
diff --git a/cli/build.rs b/cli/build.rs
deleted file mode 100644
index 55451e6b7..000000000
--- a/cli/build.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-// Run "cargo build -vv" if you want to see gn output.
-mod gn {
- include!("../tools/gn.rs");
-}
-
-fn main() {
- let build = gn::Build::setup();
- // When RLS is running "cargo check" to analyze the source code, we're not
- // trying to build a working executable, rather we're just compiling all
- // rust code.
- if !build.check_only {
- build.run("cli:deno_deps");
- }
-}
diff --git a/cli/deno.gni b/cli/deno.gni
deleted file mode 100644
index dabcd43ca..000000000
--- a/cli/deno.gni
+++ /dev/null
@@ -1,65 +0,0 @@
-# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import("//build/compiled_action.gni")
-
-# Tempalte to generate a Rollup bundle of code.
-template("bundle") {
- action(target_name) {
- forward_variables_from(invoker, "*")
- script = "//tools/run_node.py"
- outputs = [
- out_dir + out_name + ".js",
- out_dir + out_name + ".js.map",
- ]
- inputs = [
- "//js/" + out_name + ".ts",
- "//rollup.config.js",
- ]
- depfile = out_dir + out_name + ".d"
- args = [
- rebase_path("//third_party/node_modules/rollup/bin/rollup",
- root_build_dir),
- "-c",
- rebase_path("//rollup.config.js", root_build_dir),
- "-i",
- rebase_path(inputs[0], root_build_dir),
- "-o",
- rebase_path(outputs[0], root_build_dir),
- "--sourcemapFile",
- rebase_path("."),
- "--silent",
- ]
- }
-}
-
-template("run_node") {
- action(target_name) {
- forward_variables_from(invoker, "*")
- script = "//tools/run_node.py"
- }
-}
-
-# Template to generate different V8 snapshots based on different runtime flags.
-template("snapshot") {
- compiled_action(target_name) {
- forward_variables_from(invoker,
- [
- "testonly",
- "deps",
- ])
- tool = "//core:snapshot_creator"
- visibility = [ ":*" ] # Only targets in this file can depend on this.
- snapshot_out_bin = "$target_gen_dir/$target_name.bin"
- inputs = [
- invoker.source_root,
- ]
-
- outputs = [
- snapshot_out_bin,
- ]
- args = rebase_path(outputs, root_build_dir) +
- rebase_path(inputs, root_build_dir)
-
- # To debug snapshotting problems:
- # args += ["--trace-serializer"]
- }
-}
diff --git a/cli/main.rs b/cli/main.rs
index 1f2451567..682d1055f 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -9,6 +9,7 @@ extern crate futures;
extern crate serde_json;
extern crate clap;
extern crate deno;
+extern crate deno_typescript;
extern crate indexmap;
#[cfg(unix)]
extern crate nix;
diff --git a/cli/source_maps.rs b/cli/source_maps.rs
index 5a34041c5..b3b8d7e56 100644
--- a/cli/source_maps.rs
+++ b/cli/source_maps.rs
@@ -73,22 +73,12 @@ fn builtin_source_map(_: &str) -> Option<Vec<u8>> {
#[cfg(not(feature = "check-only"))]
fn builtin_source_map(script_name: &str) -> Option<Vec<u8>> {
- match script_name {
- "gen/cli/bundle/main.js" => Some(
- include_bytes!(concat!(
- env!("GN_OUT_DIR"),
- "/gen/cli/bundle/main.js.map"
- ))
- .to_vec(),
- ),
- "gen/cli/bundle/compiler.js" => Some(
- include_bytes!(concat!(
- env!("GN_OUT_DIR"),
- "/gen/cli/bundle/compiler.js.map"
- ))
- .to_vec(),
- ),
- _ => None,
+ if script_name.ends_with("CLI_SNAPSHOT.js") {
+ Some(deno_cli_snapshots::CLI_SNAPSHOT_MAP.to_vec())
+ } else if script_name.ends_with("COMPILER_SNAPSHOT.js") {
+ Some(deno_cli_snapshots::COMPILER_SNAPSHOT_MAP.to_vec())
+ } else {
+ None
}
}
@@ -405,7 +395,7 @@ mod tests {
frames: vec![StackFrame {
line: 11,
column: 12,
- script_name: "gen/cli/bundle/main.js".to_string(),
+ script_name: "CLI_SNAPSHOT.js".to_string(),
function_name: "setLogDebug".to_string(),
is_eval: false,
is_constructor: false,
@@ -417,7 +407,7 @@ mod tests {
assert_eq!(actual.message, "TypeError: baz");
// Because this is accessing the live bundle, this test might be more fragile
assert_eq!(actual.frames.len(), 1);
- assert!(actual.frames[0].script_name.ends_with("js/util.ts"));
+ assert!(actual.frames[0].script_name.ends_with("js/window.ts"));
}
#[test]
diff --git a/cli/startup_data.rs b/cli/startup_data.rs
index e7d0a08a8..593859be7 100644
--- a/cli/startup_data.rs
+++ b/cli/startup_data.rs
@@ -3,6 +3,8 @@
use deno::Script;
use deno::StartupData;
+use deno_cli_snapshots::CLI_SNAPSHOT;
+use deno_cli_snapshots::COMPILER_SNAPSHOT;
#[cfg(feature = "no-snapshot-init")]
pub fn deno_isolate_init() -> StartupData<'static> {
@@ -23,8 +25,7 @@ pub fn deno_isolate_init() -> StartupData<'static> {
pub fn deno_isolate_init() -> StartupData<'static> {
debug!("Deno isolate init with snapshots.");
#[cfg(not(feature = "check-only"))]
- let data =
- include_bytes!(concat!(env!("GN_OUT_DIR"), "/gen/cli/snapshot_deno.bin"));
+ let data = CLI_SNAPSHOT;
#[cfg(feature = "check-only")]
let data = b"";
@@ -50,10 +51,7 @@ pub fn compiler_isolate_init() -> StartupData<'static> {
pub fn compiler_isolate_init() -> StartupData<'static> {
debug!("Deno isolate init with snapshots.");
#[cfg(not(feature = "check-only"))]
- let data = include_bytes!(concat!(
- env!("GN_OUT_DIR"),
- "/gen/cli/snapshot_compiler.bin"
- ));
+ let data = COMPILER_SNAPSHOT;
#[cfg(feature = "check-only")]
let data = b"";
diff --git a/cli_snapshots/BUILD.gn b/cli_snapshots/BUILD.gn
new file mode 100644
index 000000000..c22305579
--- /dev/null
+++ b/cli_snapshots/BUILD.gn
@@ -0,0 +1,121 @@
+import("//build_extra/rust/rust.gni")
+
+rust_rlib("deno_cli_snapshots") {
+ source_root = "lib.rs"
+ generated_source_dir = rebase_path(root_out_dir)
+ deps = [
+ ":deno_cli_snapshots_build_run",
+ ]
+}
+
+ts_sources = [
+ "../js/base64.ts",
+ "../js/blob.ts",
+ "../js/body.ts",
+ "../js/buffer.ts",
+ "../js/build.ts",
+ "../js/chmod.ts",
+ "../js/chown.ts",
+ "../js/colors.ts",
+ "../js/compiler.ts",
+ "../js/console.ts",
+ "../js/console_table.ts",
+ "../js/copy_file.ts",
+ "../js/core.ts",
+ "../js/custom_event.ts",
+ "../js/deno.ts",
+ "../js/diagnostics.ts",
+ "../js/dir.ts",
+ "../js/dispatch.ts",
+ "../js/dispatch_json.ts",
+ "../js/dispatch_minimal.ts",
+ "../js/dom_file.ts",
+ "../js/dom_types.ts",
+ "../js/dom_util.ts",
+ "../js/error_stack.ts",
+ "../js/errors.ts",
+ "../js/event.ts",
+ "../js/event_target.ts",
+ "../js/fetch.ts",
+ "../js/file_info.ts",
+ "../js/files.ts",
+ "../js/form_data.ts",
+ "../js/format_error.ts",
+ "../js/get_random_values.ts",
+ "../js/globals.ts",
+ "../js/headers.ts",
+ "../js/io.ts",
+ "../js/lib.deno_runtime.d.ts",
+ "../js/lib.web_assembly.d.ts",
+ "../js/link.ts",
+ "../js/location.ts",
+ "../js/main.ts",
+ "../js/make_temp_dir.ts",
+ "../js/metrics.ts",
+ "../js/mkdir.ts",
+ "../js/mock_builtin.js",
+ "../js/net.ts",
+ "../js/os.ts",
+ "../js/performance.ts",
+ "../js/permissions.ts",
+ "../js/process.ts",
+ "../js/read_dir.ts",
+ "../js/read_file.ts",
+ "../js/read_link.ts",
+ "../js/remove.ts",
+ "../js/rename.ts",
+ "../js/repl.ts",
+ "../js/request.ts",
+ "../js/resources.ts",
+ "../js/stat.ts",
+ "../js/symlink.ts",
+ "../js/text_encoding.ts",
+ "../js/timers.ts",
+ "../js/truncate.ts",
+ "../js/type_directives.ts",
+ "../js/types.ts",
+ "../js/url.ts",
+ "../js/url_search_params.ts",
+ "../js/util.ts",
+ "../js/utime.ts",
+ "../js/version.ts",
+ "../js/window.ts",
+ "../js/workers.ts",
+ "../js/write_file.ts",
+ "../js/xeval.ts",
+]
+
+action("deno_cli_snapshots_build_run") {
+ script = "run.py"
+ inputs = ts_sources
+ outputs = [
+ "$root_out_dir/CLI_SNAPSHOT.bin",
+ "$root_out_dir/CLI_SNAPSHOT.js",
+ "$root_out_dir/CLI_SNAPSHOT.js.map",
+ "$root_out_dir/CLI_SNAPSHOT.d.ts",
+ "$root_out_dir/COMPILER_SNAPSHOT.bin",
+ "$root_out_dir/COMPILER_SNAPSHOT.js",
+ "$root_out_dir/COMPILER_SNAPSHOT.js.map",
+ "$root_out_dir/COMPILER_SNAPSHOT.d.ts",
+ ]
+ args = [ rebase_path("$root_out_dir/deno_cli_snapshots_build", ".") ]
+ deps = [
+ ":deno_cli_snapshots_build",
+ ]
+}
+
+rust_executable("deno_cli_snapshots_build") {
+ source_root = "build.rs"
+ extern = [
+ {
+ label = "../deno_typescript:deno_typescript"
+ crate_name = "deno_typescript"
+ crate_type = "rlib"
+ },
+ {
+ label = "../core:deno"
+ crate_name = "deno"
+ crate_type = "rlib"
+ },
+ ]
+}
diff --git a/cli_snapshots/Cargo.toml b/cli_snapshots/Cargo.toml
new file mode 100644
index 000000000..e6cbf6a25
--- /dev/null
+++ b/cli_snapshots/Cargo.toml
@@ -0,0 +1,18 @@
+[package]
+name = "deno_cli_snapshots"
+version = "0.0.3"
+license = "MIT"
+authors = ["Ryan Dahl <ry@tinyclouds.org>"]
+edition = "2018"
+description = "Provides snapshots for the deno CLI"
+repository = "https://github.com/ry/deno_typescript"
+
+[lib]
+path = "lib.rs"
+
+[dev-dependencies]
+deno = { path = "../core" }
+
+[build-dependencies]
+deno_typescript = { path = "../deno_typescript", version = "0.0.3" }
+
diff --git a/cli_snapshots/README.md b/cli_snapshots/README.md
new file mode 100644
index 000000000..427429a2b
--- /dev/null
+++ b/cli_snapshots/README.md
@@ -0,0 +1,9 @@
+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.
+
+The //js/ directory should be moved as a sub-directory of this crate, to denote
+the dependency structure. However, that is left to future work.
diff --git a/cli_snapshots/build.rs b/cli_snapshots/build.rs
new file mode 100644
index 000000000..cffa3d6b3
--- /dev/null
+++ b/cli_snapshots/build.rs
@@ -0,0 +1,24 @@
+// 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();
+
+ let c = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
+ let o = PathBuf::from(env::var_os("OUT_DIR").unwrap());
+ let js_dir = c.join("../js");
+
+ let root_names = vec![js_dir.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![js_dir.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/cli_snapshots/lib.rs b/cli_snapshots/lib.rs
new file mode 100644
index 000000000..1147e7903
--- /dev/null
+++ b/cli_snapshots/lib.rs
@@ -0,0 +1,43 @@
+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"));
+
+#[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/cli_snapshots/run.py b/cli_snapshots/run.py
new file mode 100644
index 000000000..4dba78768
--- /dev/null
+++ b/cli_snapshots/run.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+# This script is to execute build.rs during the GN build. See BUILD.gn.
+import subprocess
+import sys
+import os
+
+d = os.path.dirname(os.path.realpath(__file__))
+exe = sys.argv[1]
+env = os.environ.copy()
+env["CARGO_MANIFEST_DIR"] = d
+env["OUT_DIR"] = os.path.dirname(exe)
+# To match the behavior of cargo, we need to cd into this directory.
+os.chdir(d)
+sys.exit(subprocess.call([exe], env=env))
diff --git a/core/BUILD.gn b/core/BUILD.gn
index 0f1eba8ca..bf9d910c0 100644
--- a/core/BUILD.gn
+++ b/core/BUILD.gn
@@ -7,7 +7,6 @@ group("default") {
":deno_core_http_bench",
":deno_core_http_bench_test",
":deno_core_test",
- ":snapshot_creator",
]
}
@@ -78,14 +77,3 @@ rust_test("deno_core_http_bench_test") {
extern = http_bench_extern
extern_rlib = http_bench_extern_rlib
}
-
-rust_executable("snapshot_creator") {
- source_root = "snapshot_creator.rs"
- extern = [
- {
- label = ":deno"
- crate_name = "deno"
- crate_type = "rlib"
- },
- ]
-}
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 02932df35..fd6f5548f 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -13,12 +13,6 @@ repository = "https://github.com/denoland/deno"
[lib]
path = "lib.rs"
-# NOTE: The ninja build of snapshot_creator gets clobbered by 'cargo build' if
-# the following is added. This breaks incremental 'cargo build'.
-# [[bin]]
-# name = "snapshot_creator"
-# path = "snapshot_creator.rs"
-
[dependencies]
futures = "0.1.28"
lazy_static = "1.3.0"
diff --git a/core/core.d.ts b/core/core.d.ts
deleted file mode 100644
index 1e9eb7c04..000000000
--- a/core/core.d.ts
+++ /dev/null
@@ -1,26 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-
-// This file contains APIs that are introduced into the global namespace by
-// Deno core. These are not intended to be used directly by runtime users of
-// Deno and therefore do not flow through to the runtime type library.
-
-declare interface MessageCallback {
- (opId: number, msg: Uint8Array): void;
-}
-
-declare interface DenoCore {
- dispatch(
- opId: number,
- control: Uint8Array,
- zeroCopy?: ArrayBufferView | null
- ): Uint8Array | null;
- setAsyncHandler(cb: MessageCallback): void;
- sharedQueue: {
- head(): number;
- numRecords(): number;
- size(): number;
- push(buf: Uint8Array): boolean;
- reset(): void;
- shift(): Uint8Array | null;
- };
-}
diff --git a/core/snapshot_creator.rs b/core/snapshot_creator.rs
deleted file mode 100644
index 1d43b9174..000000000
--- a/core/snapshot_creator.rs
+++ /dev/null
@@ -1,44 +0,0 @@
-// Note: This is a nearly identical rewrite of core/libdeno/snapshot_creator.cc
-// but in Rust.
-//
-// This snapshot program is considered "basic" because the code being
-// snapshotted cannot call ops.
-
-extern crate deno;
-
-use deno::js_check;
-use deno::Isolate;
-use deno::StartupData;
-use std::env;
-use std::io::Write;
-
-fn main() {
- let args: Vec<String> = env::args().collect();
- // NOTE: `--help` arg will display V8 help and exit
- let args = deno::v8_set_flags(args);
-
- let (snapshot_out_bin, js_filename) = if args.len() == 3 {
- (args[1].clone(), args[2].clone())
- } else {
- eprintln!("Usage: snapshot_creator <out_filename> <js_filename>");
- std::process::exit(1);
- };
-
- let js_source =
- std::fs::read(&js_filename).expect("couldn't read js_filename");
- let js_source_str = std::str::from_utf8(&js_source).unwrap();
-
- let will_snapshot = true;
- let mut isolate = Isolate::new(StartupData::None, will_snapshot);
-
- js_check(isolate.execute(&js_filename, js_source_str));
-
- let snapshot = isolate.snapshot().expect("error snapshotting");
-
- let mut out_file = std::fs::File::create(snapshot_out_bin).unwrap();
- let snapshot_slice =
- unsafe { std::slice::from_raw_parts(snapshot.data_ptr, snapshot.data_len) };
- out_file
- .write_all(snapshot_slice)
- .expect("Failed to write snapshot file");
-}
diff --git a/deno_typescript/BUILD.gn b/deno_typescript/BUILD.gn
new file mode 100644
index 000000000..0b868c7bd
--- /dev/null
+++ b/deno_typescript/BUILD.gn
@@ -0,0 +1,22 @@
+import("//build_extra/rust/rust.gni")
+
+rust_rlib("deno_typescript") {
+ source_root = "lib.rs"
+ generated_source_dir = "."
+ extern = [
+ {
+ label = "../core:deno"
+ crate_name = "deno"
+ crate_type = "rlib"
+ },
+ {
+ label = "$rust_build:serde_derive"
+ crate_name = "serde_derive"
+ crate_type = "proc_macro"
+ },
+ ]
+ extern_rlib = [
+ "serde_json",
+ "serde",
+ ]
+}
diff --git a/deno_typescript/Cargo.toml b/deno_typescript/Cargo.toml
new file mode 100644
index 000000000..514e0098a
--- /dev/null
+++ b/deno_typescript/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "deno_typescript"
+version = "0.0.3"
+license = "MIT"
+description = "To compile TypeScript to a snapshot during build.rs"
+repository = "https://github.com/ry/deno_typescript"
+authors = ["Ryan Dahl <ry@tinyclouds.org>"]
+edition = "2018"
+
+[lib]
+path = "lib.rs"
+
+[dependencies]
+deno = { path = "../core" }
+serde_json = "1.0"
+serde = { version = "1.0", features = ["derive"] }
diff --git a/deno_typescript/README.md b/deno_typescript/README.md
new file mode 100644
index 000000000..63b6d5874
--- /dev/null
+++ b/deno_typescript/README.md
@@ -0,0 +1,8 @@
+This crate provides utilies to compile typescript, bundle it up, and create a V8
+snapshot, all during build. This allows users to startup fast.
+
+The cli_snapshots crate, neighboring this one uses deno_typescript at build
+time.
+
+This crate does not depend on Node, Python, nor any other external dependencies
+besides those listed as such in Cargo.toml.
diff --git a/deno_typescript/amd_runtime.js b/deno_typescript/amd_runtime.js
new file mode 100644
index 000000000..fda850c5c
--- /dev/null
+++ b/deno_typescript/amd_runtime.js
@@ -0,0 +1,39 @@
+// A very very basic AMD preamble to support the output of TypeScript outFile
+// bundles.
+let require, define;
+
+(function() {
+ const modules = new Map();
+
+ function println(first, ...s) {
+ Deno.core.print(first + " " + s.map(JSON.stringify).join(" ") + "\n");
+ }
+
+ function createOrLoadModule(name) {
+ if (!modules.has(name)) {
+ const m = { name, exports: {} };
+ modules.set(name, m);
+ }
+ return modules.get(name);
+ }
+
+ require = name => {
+ return createOrLoadModule(name).exports;
+ };
+
+ define = (name, deps, factory) => {
+ const currentModule = createOrLoadModule(name);
+ const localExports = currentModule.exports;
+ const args = deps.map(dep => {
+ if (dep === "require") {
+ return require;
+ } else if (dep === "exports") {
+ return localExports;
+ } else {
+ const depModule = createOrLoadModule(dep);
+ return depModule.exports;
+ }
+ });
+ factory(...args);
+ };
+})();
diff --git a/deno_typescript/compiler_main.js b/deno_typescript/compiler_main.js
new file mode 100644
index 000000000..74b6a8dd5
--- /dev/null
+++ b/deno_typescript/compiler_main.js
@@ -0,0 +1,320 @@
+// Because we're bootstrapping the TS compiler without dependencies on Node,
+// this is written in JS.
+
+const ASSETS = "$asset$";
+
+let replacements;
+
+function main(configText, rootNames, replacements_) {
+ println(`>>> ts version ${ts.version}`);
+ println(`>>> rootNames ${rootNames}`);
+
+ replacements = replacements_;
+ replacements["DENO_REPLACE_TS_VERSION"] = ts.version;
+ println(`>>> replacements ${JSON.stringify(replacements)}`);
+
+ const host = new Host();
+
+ assert(rootNames.length > 0);
+
+ let { options, diagnostics } = configure(configText);
+ handleDiagnostics(host, diagnostics);
+
+ println(`>>> TS config: ${JSON.stringify(options)}`);
+
+ const program = ts.createProgram(rootNames, options, host);
+
+ diagnostics = ts.getPreEmitDiagnostics(program).filter(({ code }) => {
+ // TS2691: An import path cannot end with a '.ts' extension. Consider
+ // importing 'bad-module' instead.
+ if (code === 2691) return false;
+ // TS5009: Cannot find the common subdirectory path for the input files.
+ if (code === 5009) return false;
+ return true;
+ });
+ handleDiagnostics(host, diagnostics);
+
+ const emitResult = program.emit();
+ handleDiagnostics(host, emitResult.diagnostics);
+
+ dispatch("setEmitResult", emitResult);
+}
+
+function println(...s) {
+ Deno.core.print(s.join(" ") + "\n");
+}
+
+function unreachable() {
+ throw Error("unreachable");
+}
+
+function assert(cond) {
+ if (!cond) {
+ throw Error("assert");
+ }
+}
+
+// decode(Uint8Array): string
+function decodeAscii(ui8) {
+ let out = "";
+ for (let i = 0; i < ui8.length; i++) {
+ out += String.fromCharCode(ui8[i]);
+ }
+ return out;
+}
+
+function encode(str) {
+ const charCodes = str.split("").map(c => c.charCodeAt(0));
+ const ui8 = new Uint8Array(charCodes);
+ return ui8;
+}
+
+// Warning! The op_id values below are shared between this code and
+// the Rust side. Update with care!
+const ops = {
+ readFile: 49,
+ exit: 50,
+ writeFile: 51,
+ resolveModuleNames: 52,
+ setEmitResult: 53
+};
+
+// interface CompilerHost extends ModuleResolutionHost {
+class Host {
+ // fileExists(fileName: string): boolean;
+ fileExists(fileName) {
+ return true;
+ }
+
+ // readFile(fileName: string): string | undefined;
+ readFile() {
+ unreachable();
+ }
+
+ // trace?(s: string): void;
+ // directoryExists?(directoryName: string): boolean;
+ // realpath?(path: string): string;
+ // getCurrentDirectory?(): string;
+ // getDirectories?(path: string): string[];
+
+ // useCaseSensitiveFileNames(): boolean;
+ useCaseSensitiveFileNames() {
+ return false;
+ }
+
+ // getDefaultLibFileName(options: CompilerOptions): string;
+ getDefaultLibFileName(options) {
+ return "lib.deno_core.d.ts";
+ }
+
+ // getDefaultLibLocation?(): string;
+ getDefaultLibLocation() {
+ return ASSETS;
+ }
+
+ // getCurrentDirectory(): string;
+ getCurrentDirectory() {
+ return ".";
+ }
+
+ // getCanonicalFileName(fileName: string): string
+ getCanonicalFileName(fileName) {
+ unreachable();
+ }
+
+ // getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?:
+ // (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile
+ // | undefined;
+ getSourceFile(fileName, languageVersion, onError, shouldCreateNewSourceFile) {
+ assert(!shouldCreateNewSourceFile); // We haven't yet encountered this.
+
+ // This hacks around the fact that TypeScript tries to magically guess the
+ // d.ts filename.
+ if (fileName.startsWith("$typeRoots$")) {
+ assert(fileName.startsWith("$typeRoots$/"));
+ assert(fileName.endsWith("/index.d.ts"));
+ fileName = fileName
+ .replace("$typeRoots$/", "")
+ .replace("/index.d.ts", "");
+ }
+
+ let { sourceCode, moduleName } = dispatch("readFile", {
+ fileName,
+ languageVersion,
+ shouldCreateNewSourceFile
+ });
+
+ // TODO(ry) A terrible hack. Please remove ASAP.
+ if (fileName.endsWith("typescript.d.ts")) {
+ 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;
+ }
+
+ /*
+ writeFile(
+ fileName: string,
+ data: string,
+ writeByteOrderMark: boolean,
+ onError?: (message: string) => void,
+ sourceFiles?: ReadonlyArray<ts.SourceFile>
+ ): void
+ */
+ writeFile(
+ fileName,
+ data,
+ writeByteOrderMark,
+ onError = null,
+ sourceFiles = null
+ ) {
+ const moduleName = sourceFiles[sourceFiles.length - 1].moduleName;
+ return dispatch("writeFile", { fileName, moduleName, data });
+ }
+
+ // getSourceFileByPath?(fileName: string, path: Path, languageVersion: ScriptTarget, onError?: (message: string) => void, shouldCreateNewSourceFile?: boolean): SourceFile | undefined;
+ getSourceFileByPath(
+ fileName,
+ path,
+ languageVersion,
+ onError,
+ shouldCreateNewSourceFile
+ ) {
+ unreachable();
+ }
+
+ // getCancellationToken?(): CancellationToken;
+ getCancellationToken() {
+ unreachable();
+ }
+
+ // getCanonicalFileName(fileName: string): string;
+ getCanonicalFileName(fileName) {
+ return fileName;
+ }
+
+ // getNewLine(): string
+ getNewLine() {
+ return "\n";
+ }
+
+ // readDirectory?(rootDir: string, extensions: ReadonlyArray<string>, excludes: ReadonlyArray<string> | undefined, includes: ReadonlyArray<string>, depth?: number): string[];
+ readDirectory() {
+ unreachable();
+ }
+
+ // resolveModuleNames?(
+ // moduleNames: string[],
+ // containingFile: string,
+ // reusedNames?: string[],
+ // redirectedReference?: ResolvedProjectReference
+ // ): (ResolvedModule | undefined)[];
+ resolveModuleNames(moduleNames, containingFile) {
+ const resolvedNames = dispatch("resolveModuleNames", {
+ moduleNames,
+ containingFile
+ });
+ const r = resolvedNames.map(resolvedFileName => {
+ const extension = getExtension(resolvedFileName);
+ return { resolvedFileName, extension };
+ });
+ return r;
+ }
+
+ // resolveTypeReferenceDirectives?(typeReferenceDirectiveNames: string[], containingFile: string, redirectedReference?: ResolvedProjectReference): (ResolvedTypeReferenceDirective | undefined)[];
+ /*
+ resolveTypeReferenceDirectives() {
+ unreachable();
+ }
+ */
+
+ // getEnvironmentVariable?(name: string): string | undefined;
+ getEnvironmentVariable() {
+ unreachable();
+ }
+
+ // createHash?(data: string): string;
+ createHash() {
+ unreachable();
+ }
+
+ // getParsedCommandLine?(fileName: string): ParsedCommandLine | undefined;
+ getParsedCommandLine() {
+ unreachable();
+ }
+}
+
+function configure(configurationText) {
+ const { config, error } = ts.parseConfigFileTextToJson(
+ "tsconfig.json",
+ configurationText
+ );
+ if (error) {
+ return { diagnostics: [error] };
+ }
+ const { options, errors } = ts.convertCompilerOptionsFromJson(
+ config.compilerOptions,
+ ""
+ );
+ return {
+ options,
+ diagnostics: errors.length ? errors : undefined
+ };
+}
+
+function dispatch(opName, obj) {
+ const s = JSON.stringify(obj);
+ const msg = encode(s);
+ const resUi8 = Deno.core.dispatch(ops[opName], msg);
+ const resStr = decodeAscii(resUi8);
+ const res = JSON.parse(resStr);
+ if (!res["ok"]) {
+ throw Error(`${opName} failed ${res["err"]}. Args: ${JSON.stringify(obj)}`);
+ }
+ return res["ok"];
+}
+
+function exit(code) {
+ dispatch("exit", { code });
+ unreachable();
+}
+
+// Maximum number of diagnostics to display.
+const MAX_ERRORS = 5;
+
+function handleDiagnostics(host, diagnostics) {
+ if (diagnostics && diagnostics.length) {
+ let rest = 0;
+ if (diagnostics.length > MAX_ERRORS) {
+ rest = diagnostics.length - MAX_ERRORS;
+ diagnostics = diagnostics.slice(0, MAX_ERRORS);
+ }
+ const msg = ts.formatDiagnosticsWithColorAndContext(diagnostics, host);
+ println(msg);
+ if (rest) {
+ println(`And ${rest} other errors.`);
+ }
+ exit(1);
+ }
+}
+
+/** Returns the TypeScript Extension enum for a given media type. */
+function getExtension(fileName) {
+ if (fileName.endsWith(".d.ts")) {
+ return ts.Extension.Dts;
+ } else if (fileName.endsWith(".ts")) {
+ return ts.Extension.Ts;
+ } else if (fileName.endsWith(".js")) {
+ return ts.Extension.Js;
+ } else {
+ throw TypeError(`Cannot resolve extension for ${fileName}`);
+ }
+}
diff --git a/core/libdeno/libdeno.d.ts b/deno_typescript/lib.deno_core.d.ts
index 8a26e49ca..18583fadd 100644
--- a/core/libdeno/libdeno.d.ts
+++ b/deno_typescript/lib.deno_core.d.ts
@@ -1,5 +1,13 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+// This file contains APIs that are introduced into the global namespace by
+// Deno core. These are not intended to be used directly by runtime users of
+// Deno and therefore do not flow through to the runtime type library.
+
+declare interface MessageCallback {
+ (opId: number, msg: Uint8Array): void;
+}
+
interface EvalErrorInfo {
// Is the object thrown a native Error?
isNativeError: boolean;
@@ -12,11 +20,23 @@ interface EvalErrorInfo {
thrown: any;
}
-declare interface MessageCallback {
- (opId: number, msg: Uint8Array): void;
-}
-
declare interface DenoCore {
+ print(s: string, is_err?: boolean);
+ dispatch(
+ opId: number,
+ control: Uint8Array,
+ zeroCopy?: ArrayBufferView | null
+ ): Uint8Array | null;
+ setAsyncHandler(cb: MessageCallback): void;
+ sharedQueue: {
+ head(): number;
+ numRecords(): number;
+ size(): number;
+ push(buf: Uint8Array): boolean;
+ reset(): void;
+ shift(): Uint8Array | null;
+ };
+
recv(cb: MessageCallback): void;
send(
@@ -39,3 +59,8 @@ declare interface DenoCore {
errorToJSON: (e: Error) => string;
}
+
+declare interface DenoInterface {
+ core: DenoCore;
+}
+declare var Deno: DenoInterface;
diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs
new file mode 100644
index 000000000..cf4b39d09
--- /dev/null
+++ b/deno_typescript/lib.rs
@@ -0,0 +1,288 @@
+// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
+extern crate deno;
+extern crate serde;
+extern crate serde_json;
+
+mod ops;
+use deno::js_check;
+pub use deno::v8_set_flags;
+use deno::ErrBox;
+use deno::Isolate;
+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;
+use std::sync::Arc;
+use std::sync::Mutex;
+
+static TYPESCRIPT_CODE: &str =
+ include_str!("../third_party/node_modules/typescript/lib/typescript.js");
+static COMPILER_CODE: &str = include_str!("compiler_main.js");
+static AMD_RUNTIME_CODE: &str = include_str!("amd_runtime.js");
+
+#[derive(Debug)]
+pub struct TSState {
+ bundle: bool,
+ exit_code: i32,
+ emit_result: Option<EmitResult>,
+ /// A list of files emitted by typescript. WrittenFile is tuple of the form
+ /// (url, corresponding_module, source_code)
+ written_files: Vec<WrittenFile>,
+}
+
+impl TSState {
+ fn main_module_name(&self) -> String {
+ // Assuming that TypeScript has emitted the main file last.
+ self.written_files.last().unwrap().module_name.clone()
+ }
+}
+
+pub struct TSIsolate {
+ isolate: Isolate,
+ state: Arc<Mutex<TSState>>,
+}
+
+impl TSIsolate {
+ fn new(bundle: bool) -> TSIsolate {
+ let mut isolate = Isolate::new(StartupData::None, false);
+ js_check(isolate.execute("assets/typescript.js", TYPESCRIPT_CODE));
+ js_check(isolate.execute("compiler_main.js", COMPILER_CODE));
+
+ let state = Arc::new(Mutex::new(TSState {
+ bundle,
+ exit_code: 0,
+ emit_result: None,
+ written_files: Vec::new(),
+ }));
+ let state_ = state.clone();
+ isolate.set_dispatch(move |op_id, control_buf, zero_copy_buf| {
+ assert!(zero_copy_buf.is_none()); // zero_copy_buf unused in compiler.
+ let mut s = state_.lock().unwrap();
+ ops::dispatch_op(&mut s, op_id, control_buf)
+ });
+ TSIsolate { isolate, state }
+ }
+
+ // TODO(ry) Instead of Result<Arc<Mutex<TSState>>, ErrBox>, return something
+ // like Result<TSState, ErrBox>. I think it would be nicer if this function
+ // consumes TSIsolate.
+ /// Compiles each module to ESM. Doesn't write any files to disk.
+ /// Passes all output via state.
+ fn compile(
+ mut self,
+ config_json: &serde_json::Value,
+ 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()
+ );
+ self.isolate.execute("<anon>", source)?;
+ Ok(self.state.clone())
+ }
+}
+
+pub fn compile_bundle(
+ bundle: &Path,
+ root_names: Vec<PathBuf>,
+) -> Result<Arc<Mutex<TSState>>, ErrBox> {
+ let ts_isolate = TSIsolate::new(true);
+
+ let config_json = serde_json::json!({
+ "compilerOptions": {
+ "declaration": true,
+ "lib": ["esnext"],
+ "module": "amd",
+ "target": "esnext",
+ "listFiles": true,
+ "listEmittedFiles": true,
+ // "types" : ["typescript.d.ts"],
+ "typeRoots" : ["$typeRoots$"],
+ // Emit the source alongside the sourcemaps within a single file;
+ // requires --inlineSourceMap or --sourceMap to be set.
+ // "inlineSources": true,
+ "sourceMap": true,
+ "outFile": bundle,
+ },
+ });
+
+ let mut root_names_str: Vec<String> = root_names
+ .iter()
+ .map(|p| {
+ if !p.exists() {
+ panic!("File not found {}", p.display());
+ }
+
+ let module_specifier =
+ ModuleSpecifier::resolve_url_or_path(&p.to_string_lossy()).unwrap();
+ module_specifier.as_str().to_string()
+ })
+ .collect();
+ root_names_str.push("$asset$/lib.deno_core.d.ts".to_string());
+
+ // TODO lift js_check to caller?
+ let state = js_check(ts_isolate.compile(&config_json, root_names_str));
+
+ Ok(state)
+}
+
+#[allow(dead_code)]
+fn print_source_code(code: &str) {
+ let mut i = 1;
+ for line in code.lines() {
+ println!("{:3} {}", i, line);
+ i += 1;
+ }
+}
+
+/// Create a V8 snapshot.
+pub fn mksnapshot_bundle(
+ bundle: &Path,
+ state: Arc<Mutex<TSState>>,
+) -> Result<(), ErrBox> {
+ let mut runtime_isolate = Isolate::new(StartupData::None, true);
+ let source_code_vec = std::fs::read(bundle)?;
+ let source_code = std::str::from_utf8(&source_code_vec)?;
+
+ js_check(runtime_isolate.execute("amd_runtime.js", AMD_RUNTIME_CODE));
+ js_check(runtime_isolate.execute(&bundle.to_string_lossy(), &source_code));
+
+ let main = state.lock().unwrap().main_module_name();
+ js_check(runtime_isolate.execute("anon", &format!("require('{}')", main)));
+
+ write_snapshot(runtime_isolate, bundle)?;
+
+ Ok(())
+}
+
+/// Create a V8 snapshot. This differs from mksnapshot_bundle in that is also
+/// runs typescript.js
+pub fn mksnapshot_bundle_ts(
+ bundle: &Path,
+ state: Arc<Mutex<TSState>>,
+) -> Result<(), ErrBox> {
+ let mut runtime_isolate = Isolate::new(StartupData::None, true);
+ let source_code_vec = std::fs::read(bundle)?;
+ let source_code = std::str::from_utf8(&source_code_vec)?;
+
+ js_check(runtime_isolate.execute("amd_runtime.js", AMD_RUNTIME_CODE));
+ js_check(runtime_isolate.execute("typescript.js", TYPESCRIPT_CODE));
+ js_check(runtime_isolate.execute(&bundle.to_string_lossy(), &source_code));
+
+ let main = state.lock().unwrap().main_module_name();
+ js_check(runtime_isolate.execute("anon", &format!("require('{}')", main)));
+
+ write_snapshot(runtime_isolate, bundle)?;
+
+ Ok(())
+}
+
+fn write_snapshot(
+ runtime_isolate: Isolate,
+ bundle: &Path,
+) -> Result<(), ErrBox> {
+ println!("creating snapshot...");
+ let snapshot = runtime_isolate.snapshot()?;
+ let snapshot_slice =
+ unsafe { std::slice::from_raw_parts(snapshot.data_ptr, snapshot.data_len) };
+ println!("snapshot bytes {}", snapshot_slice.len());
+
+ let snapshot_path = bundle.with_extension("bin");
+
+ fs::write(&snapshot_path, snapshot_slice)?;
+ println!("snapshot path {} ", snapshot_path.display());
+ Ok(())
+}
+
+macro_rules! inc {
+ ($e:expr) => {
+ Some(include_str!(concat!(
+ "../third_party/node_modules/typescript/lib/",
+ $e
+ )))
+ };
+}
+
+/// Same as get_asset() but returns NotFound intead of None.
+pub fn get_asset2(name: &str) -> Result<&'static str, ErrBox> {
+ match get_asset(name) {
+ Some(a) => Ok(a),
+ None => Err(
+ std::io::Error::new(std::io::ErrorKind::NotFound, "Asset not found")
+ .into(),
+ ),
+ }
+}
+
+pub fn get_asset(name: &str) -> Option<&'static str> {
+ match name {
+ "lib.deno_core.d.ts" => Some(include_str!("lib.deno_core.d.ts")),
+ "lib.esnext.d.ts" => inc!("lib.esnext.d.ts"),
+ "lib.es2019.d.ts" => inc!("lib.es2019.d.ts"),
+ "lib.es2018.d.ts" => inc!("lib.es2018.d.ts"),
+ "lib.es2017.d.ts" => inc!("lib.es2017.d.ts"),
+ "lib.es2016.d.ts" => inc!("lib.es2016.d.ts"),
+ "lib.es5.d.ts" => inc!("lib.es5.d.ts"),
+ "lib.es2015.d.ts" => inc!("lib.es2015.d.ts"),
+ "lib.es2015.core.d.ts" => inc!("lib.es2015.core.d.ts"),
+ "lib.es2015.collection.d.ts" => inc!("lib.es2015.collection.d.ts"),
+ "lib.es2015.generator.d.ts" => inc!("lib.es2015.generator.d.ts"),
+ "lib.es2015.iterable.d.ts" => inc!("lib.es2015.iterable.d.ts"),
+ "lib.es2015.promise.d.ts" => inc!("lib.es2015.promise.d.ts"),
+ "lib.es2015.symbol.d.ts" => inc!("lib.es2015.symbol.d.ts"),
+ "lib.es2015.proxy.d.ts" => inc!("lib.es2015.proxy.d.ts"),
+ "lib.es2015.symbol.wellknown.d.ts" => {
+ inc!("lib.es2015.symbol.wellknown.d.ts")
+ }
+ "lib.es2015.reflect.d.ts" => inc!("lib.es2015.reflect.d.ts"),
+ "lib.es2016.array.include.d.ts" => inc!("lib.es2016.array.include.d.ts"),
+ "lib.es2017.object.d.ts" => inc!("lib.es2017.object.d.ts"),
+ "lib.es2017.sharedmemory.d.ts" => inc!("lib.es2017.sharedmemory.d.ts"),
+ "lib.es2017.string.d.ts" => inc!("lib.es2017.string.d.ts"),
+ "lib.es2017.intl.d.ts" => inc!("lib.es2017.intl.d.ts"),
+ "lib.es2017.typedarrays.d.ts" => inc!("lib.es2017.typedarrays.d.ts"),
+ "lib.es2018.asynciterable.d.ts" => inc!("lib.es2018.asynciterable.d.ts"),
+ "lib.es2018.promise.d.ts" => inc!("lib.es2018.promise.d.ts"),
+ "lib.es2018.regexp.d.ts" => inc!("lib.es2018.regexp.d.ts"),
+ "lib.es2018.intl.d.ts" => inc!("lib.es2018.intl.d.ts"),
+ "lib.es2019.array.d.ts" => inc!("lib.es2019.array.d.ts"),
+ "lib.es2019.object.d.ts" => inc!("lib.es2019.object.d.ts"),
+ "lib.es2019.string.d.ts" => inc!("lib.es2019.string.d.ts"),
+ "lib.es2019.symbol.d.ts" => inc!("lib.es2019.symbol.d.ts"),
+ "lib.esnext.bigint.d.ts" => inc!("lib.esnext.bigint.d.ts"),
+ "lib.esnext.intl.d.ts" => inc!("lib.esnext.intl.d.ts"),
+ _ => None,
+ }
+}
+
+/// Sets the --trace-serializer V8 flag for debugging snapshots.
+pub fn trace_serializer() {
+ let dummy = "foo".to_string();
+ let r =
+ 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()
+}
diff --git a/deno_typescript/ops.rs b/deno_typescript/ops.rs
new file mode 100644
index 000000000..f1c7840f9
--- /dev/null
+++ b/deno_typescript/ops.rs
@@ -0,0 +1,141 @@
+use crate::TSState;
+use deno::CoreOp;
+use deno::ErrBox;
+use deno::ModuleSpecifier;
+use deno::Op;
+use deno::OpId;
+use serde::Deserialize;
+use serde_json::json;
+use serde_json::Value;
+
+#[derive(Debug)]
+pub struct WrittenFile {
+ pub url: String,
+ pub module_name: String,
+ pub source_code: String,
+}
+
+fn dispatch2(
+ s: &mut TSState,
+ op_id: OpId,
+ control_buf: &[u8],
+) -> Result<Value, ErrBox> {
+ let v = serde_json::from_slice(control_buf)?;
+ // Warning! The op_id values below are shared between this code and
+ // compiler_main.js. Update with care!
+ match op_id {
+ 49 => read_file(s, v),
+ 50 => exit(s, v),
+ 51 => write_file(s, v),
+ 52 => resolve_module_names(s, v),
+ 53 => set_emit_result(s, v),
+ _ => unreachable!(),
+ }
+}
+
+pub fn dispatch_op(s: &mut TSState, op_id: OpId, control_buf: &[u8]) -> CoreOp {
+ let result = dispatch2(s, op_id, control_buf);
+ let response = match result {
+ Ok(v) => json!({ "ok": v }),
+ Err(err) => json!({ "err": err.to_string() }),
+ };
+ let x = serde_json::to_string(&response).unwrap();
+ let vec = x.into_bytes();
+ Op::Sync(vec.into_boxed_slice())
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct ReadFile {
+ file_name: String,
+ language_version: Option<i32>,
+ should_create_new_source_file: bool,
+}
+
+fn read_file(_s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
+ let v: ReadFile = serde_json::from_value(v)?;
+ let (module_name, source_code) = if v.file_name.starts_with("$asset$/") {
+ let asset = v.file_name.replace("$asset$/", "");
+ let source_code = crate::get_asset2(&asset)?.to_string();
+ (asset, source_code)
+ } else {
+ assert!(!v.file_name.starts_with("$assets$"), "you meant $asset$");
+ let module_specifier = ModuleSpecifier::resolve_url_or_path(&v.file_name)?;
+ let path = module_specifier.as_url().to_file_path().unwrap();
+ println!("cargo:rerun-if-changed={}", path.display());
+ (
+ module_specifier.as_str().to_string(),
+ std::fs::read_to_string(&path)?,
+ )
+ };
+ Ok(json!({
+ "moduleName": module_name,
+ "sourceCode": source_code,
+ }))
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct WriteFile {
+ file_name: String,
+ data: String,
+ module_name: String,
+}
+
+fn write_file(s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
+ let v: WriteFile = serde_json::from_value(v)?;
+ let module_specifier = ModuleSpecifier::resolve_url_or_path(&v.file_name)?;
+ if s.bundle {
+ std::fs::write(&v.file_name, &v.data)?;
+ }
+ s.written_files.push(WrittenFile {
+ url: module_specifier.as_str().to_string(),
+ module_name: v.module_name,
+ source_code: v.data,
+ });
+ Ok(json!(true))
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct ResolveModuleNames {
+ module_names: Vec<String>,
+ containing_file: String,
+}
+
+fn resolve_module_names(_s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
+ let v: ResolveModuleNames = serde_json::from_value(v).unwrap();
+ let mut resolved = Vec::<String>::new();
+ let referrer = ModuleSpecifier::resolve_url_or_path(&v.containing_file)?;
+ for specifier in v.module_names {
+ let ms = ModuleSpecifier::resolve_import(&specifier, referrer.as_str())?;
+ resolved.push(ms.as_str().to_string());
+ }
+ Ok(json!(resolved))
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+struct Exit {
+ code: i32,
+}
+
+fn exit(s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
+ let v: Exit = serde_json::from_value(v)?;
+ s.exit_code = v.code;
+ std::process::exit(v.code)
+}
+
+#[derive(Debug, Deserialize)]
+#[serde(rename_all = "camelCase")]
+pub struct EmitResult {
+ pub emit_skipped: bool,
+ pub diagnostics: Vec<String>,
+ pub emitted_files: Vec<String>,
+}
+
+fn set_emit_result(s: &mut TSState, v: Value) -> Result<Value, ErrBox> {
+ let v: EmitResult = serde_json::from_value(v)?;
+ s.emit_result = Some(v);
+ Ok(json!(true))
+}
diff --git a/js/blob.ts b/js/blob.ts
index 94d03c97f..4c86f1f24 100644
--- a/js/blob.ts
+++ b/js/blob.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types";
-import { containsOnlyASCII, hasOwnProperty } from "./util";
-import { TextEncoder } from "./text_encoding";
-import { build } from "./build";
+import * as domTypes from "./dom_types.ts";
+import { containsOnlyASCII, hasOwnProperty } from "./util.ts";
+import { TextEncoder } from "./text_encoding.ts";
+import { build } from "./build.ts";
export const bytesSymbol = Symbol("bytes");
diff --git a/js/body.ts b/js/body.ts
index b1f1af8a5..6567b1934 100644
--- a/js/body.ts
+++ b/js/body.ts
@@ -1,8 +1,8 @@
-import * as formData from "./form_data";
-import * as blob from "./blob";
-import * as encoding from "./text_encoding";
-import * as headers from "./headers";
-import * as domTypes from "./dom_types";
+import * as formData from "./form_data.ts";
+import * as blob from "./blob.ts";
+import * as encoding from "./text_encoding.ts";
+import * as headers from "./headers.ts";
+import * as domTypes from "./dom_types.ts";
const { Headers } = headers;
diff --git a/js/buffer.ts b/js/buffer.ts
index 9525e6954..dc73b7e60 100644
--- a/js/buffer.ts
+++ b/js/buffer.ts
@@ -4,10 +4,10 @@
// Copyright 2009 The Go Authors. All rights reserved. BSD license.
// https://github.com/golang/go/blob/master/LICENSE
-import { Reader, Writer, EOF, SyncReader, SyncWriter } from "./io";
-import { assert } from "./util";
-import { TextDecoder } from "./text_encoding";
-import { DenoError, ErrorKind } from "./errors";
+import { Reader, Writer, EOF, SyncReader, SyncWriter } from "./io.ts";
+import { assert } from "./util.ts";
+import { TextDecoder } from "./text_encoding.ts";
+import { DenoError, ErrorKind } from "./errors.ts";
// MIN_READ is the minimum ArrayBuffer size passed to a read call by
// buffer.ReadFrom. As long as the Buffer has at least MIN_READ bytes beyond
diff --git a/js/build.ts b/js/build.ts
index 1b02e7862..157de30bc 100644
--- a/js/build.ts
+++ b/js/build.ts
@@ -18,9 +18,9 @@ export interface BuildInfo {
export const build: BuildInfo = {
// These string will be replaced by rollup
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
- arch: `ROLLUP_REPLACE_ARCH` as any,
+ arch: `DENO_REPLACE_ARCH` as any,
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
- os: `ROLLUP_REPLACE_OS` as any
+ os: `DENO_REPLACE_OS` as any
};
// TODO(kevinkassimo): deprecate Deno.platform
diff --git a/js/chmod.ts b/js/chmod.ts
index 23b3dff25..7bf54cc5b 100644
--- a/js/chmod.ts
+++ b/js/chmod.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/** Changes the permission of a specific file/directory of specified path
* synchronously.
diff --git a/js/chown.ts b/js/chown.ts
index 6bfddab98..a8bad1193 100644
--- a/js/chown.ts
+++ b/js/chown.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/**
* Change owner of a regular file or directory synchronously. Unix only at the moment.
diff --git a/js/colors.ts b/js/colors.ts
index ab89af81c..47a893036 100644
--- a/js/colors.ts
+++ b/js/colors.ts
@@ -3,7 +3,7 @@
// TODO(kitsonk) Replace with `deno_std/colors/mod.ts` when we can load modules
// which end in `.ts`.
-import { noColor } from "./os";
+import { noColor } from "./deno.ts";
interface Code {
open: string;
diff --git a/js/compiler.ts b/js/compiler.ts
index 71b1b06c9..255ac9774 100644
--- a/js/compiler.ts
+++ b/js/compiler.ts
@@ -1,20 +1,25 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as ts from "typescript";
-import { bold, cyan, yellow } from "./colors";
-import { Console } from "./console";
-import { core } from "./core";
-import { Diagnostic, fromTypeScriptDiagnostic } from "./diagnostics";
-import { cwd } from "./dir";
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
-import * as os from "./os";
-import { TextEncoder } from "./text_encoding";
-import { getMappedModuleName, parseTypeDirectives } from "./type_directives";
-import { assert, notImplemented } from "./util";
-import * as util from "./util";
-import { window } from "./window";
-import { postMessage, workerClose, workerMain } from "./workers";
-import { writeFileSync } from "./write_file";
+// TODO(ry) Combine this implementation with //deno_typescript/compiler_main.js
+
+/// <reference types="../third_party/node_modules/typescript/lib/typescript.d.ts"/>
+
+import "./globals.ts";
+
+import { bold, cyan, yellow } from "./colors.ts";
+import { Console } from "./console.ts";
+import { core } from "./core.ts";
+import { Diagnostic, fromTypeScriptDiagnostic } from "./diagnostics.ts";
+import { cwd } from "./dir.ts";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
+import * as os from "./os.ts";
+import { TextEncoder } from "./text_encoding.ts";
+import { getMappedModuleName, parseTypeDirectives } from "./type_directives.ts";
+import { assert, notImplemented } from "./util.ts";
+import * as util from "./util.ts";
+import { window } from "./window.ts";
+import { postMessage, workerClose, workerMain } from "./workers.ts";
+import { writeFileSync } from "./write_file.ts";
// Warning! The values in this enum are duplicated in cli/msg.rs
// Update carefully!
@@ -31,9 +36,10 @@ enum MediaType {
const console = new Console(core.print);
window.console = console;
window.workerMain = workerMain;
-export default function denoMain(): void {
+function denoMain(): void {
os.start(true, "TS");
}
+window["denoMain"] = denoMain;
const ASSETS = "$asset$";
const OUT_DIR = "$deno$";
diff --git a/js/console.ts b/js/console.ts
index db6a87296..2ce4b20cd 100644
--- a/js/console.ts
+++ b/js/console.ts
@@ -1,9 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { isTypedArray } from "./util";
-import { TypedArray } from "./types";
-import { TextEncoder } from "./text_encoding";
-import { File, stdout } from "./files";
-import { cliTable } from "./console_table";
+import { isTypedArray } from "./util.ts";
+import { TypedArray } from "./types.ts";
+import { TextEncoder } from "./text_encoding.ts";
+import { File, stdout } from "./files.ts";
+import { cliTable } from "./console_table.ts";
type ConsoleContext = Set<unknown>;
type ConsoleOptions = Partial<{
diff --git a/js/console_table.ts b/js/console_table.ts
index d4a404aa1..d74dc0127 100644
--- a/js/console_table.ts
+++ b/js/console_table.ts
@@ -1,8 +1,8 @@
// Copyright Joyent, Inc. and other Node contributors. MIT license.
// Forked from Node's lib/internal/cli_table.js
-import { TextEncoder } from "./text_encoding";
-import { hasOwnProperty } from "./util";
+import { TextEncoder } from "./text_encoding.ts";
+import { hasOwnProperty } from "./util.ts";
const encoder = new TextEncoder();
diff --git a/js/copy_file.ts b/js/copy_file.ts
index b299a52bc..94d2b63db 100644
--- a/js/copy_file.ts
+++ b/js/copy_file.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/** Copies the contents of a file to another by name synchronously.
* Creates a new file if target does not exists, and if target exists,
diff --git a/js/core.ts b/js/core.ts
index 436ba7ccb..d394d822f 100644
--- a/js/core.ts
+++ b/js/core.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { window } from "./window";
+import { window } from "./window.ts";
// This allows us to access core in API even if we
// dispose window.Deno
diff --git a/js/custom_event.ts b/js/custom_event.ts
index 5f9e413fb..67668bbb7 100644
--- a/js/custom_event.ts
+++ b/js/custom_event.ts
@@ -1,7 +1,7 @@
// Copyright 2018 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types";
-import * as event from "./event";
-import { getPrivateValue, requiredArguments } from "./util";
+import * as domTypes from "./dom_types.ts";
+import * as event from "./event.ts";
+import { getPrivateValue, requiredArguments } from "./util.ts";
// WeakMaps are recommended for private attributes (see MDN link below)
// https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Add-on_SDK/Guides/Contributor_s_Guide/Private_Properties#Using_WeakMaps
diff --git a/js/deno.ts b/js/deno.ts
index 65a93c467..efccb7741 100644
--- a/js/deno.ts
+++ b/js/deno.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Public deno module.
-export { noColor, pid, env, exit, isTTY, execPath, homeDir } from "./os";
-export { chdir, cwd } from "./dir";
+export { env, exit, isTTY, execPath, homeDir } from "./os.ts";
+export { chdir, cwd } from "./dir.ts";
export {
File,
open,
@@ -18,7 +18,7 @@ export {
seekSync,
close,
OpenMode
-} from "./files";
+} from "./files.ts";
export {
EOF,
copy,
@@ -37,40 +37,46 @@ export {
WriteSeeker,
ReadWriteCloser,
ReadWriteSeeker
-} from "./io";
-export { Buffer, readAll, readAllSync, writeAll, writeAllSync } from "./buffer";
-export { mkdirSync, mkdir } from "./mkdir";
+} from "./io.ts";
+export {
+ Buffer,
+ readAll,
+ readAllSync,
+ writeAll,
+ writeAllSync
+} from "./buffer.ts";
+export { mkdirSync, mkdir } from "./mkdir.ts";
export {
makeTempDirSync,
makeTempDir,
MakeTempDirOptions
-} from "./make_temp_dir";
-export { chmodSync, chmod } from "./chmod";
-export { chownSync, chown } from "./chown";
-export { utimeSync, utime } from "./utime";
-export { removeSync, remove, RemoveOption } from "./remove";
-export { renameSync, rename } from "./rename";
-export { readFileSync, readFile } from "./read_file";
-export { readDirSync, readDir } from "./read_dir";
-export { copyFileSync, copyFile } from "./copy_file";
-export { readlinkSync, readlink } from "./read_link";
-export { statSync, lstatSync, stat, lstat } from "./stat";
-export { linkSync, link } from "./link";
-export { symlinkSync, symlink } from "./symlink";
-export { writeFileSync, writeFile, WriteFileOptions } from "./write_file";
-export { applySourceMap } from "./error_stack";
-export { ErrorKind, DenoError } from "./errors";
+} from "./make_temp_dir.ts";
+export { chmodSync, chmod } from "./chmod.ts";
+export { chownSync, chown } from "./chown.ts";
+export { utimeSync, utime } from "./utime.ts";
+export { removeSync, remove, RemoveOption } from "./remove.ts";
+export { renameSync, rename } from "./rename.ts";
+export { readFileSync, readFile } from "./read_file.ts";
+export { readDirSync, readDir } from "./read_dir.ts";
+export { copyFileSync, copyFile } from "./copy_file.ts";
+export { readlinkSync, readlink } from "./read_link.ts";
+export { statSync, lstatSync, stat, lstat } from "./stat.ts";
+export { linkSync, link } from "./link.ts";
+export { symlinkSync, symlink } from "./symlink.ts";
+export { writeFileSync, writeFile, WriteFileOptions } from "./write_file.ts";
+export { applySourceMap } from "./error_stack.ts";
+export { ErrorKind, DenoError } from "./errors.ts";
export {
permissions,
revokePermission,
Permission,
Permissions
-} from "./permissions";
-export { truncateSync, truncate } from "./truncate";
-export { FileInfo } from "./file_info";
-export { connect, dial, listen, Listener, Conn } from "./net";
-export { metrics, Metrics } from "./metrics";
-export { resources } from "./resources";
+} from "./permissions.ts";
+export { truncateSync, truncate } from "./truncate.ts";
+export { FileInfo } from "./file_info.ts";
+export { connect, dial, listen, Listener, Conn } from "./net.ts";
+export { metrics, Metrics } from "./metrics.ts";
+export { resources } from "./resources.ts";
export {
kill,
run,
@@ -78,23 +84,35 @@ export {
Process,
ProcessStatus,
Signal
-} from "./process";
-export { inspect, customInspect } from "./console";
-export { build, platform, OperatingSystem, Arch } from "./build";
-export { version } from "./version";
+} from "./process.ts";
+export { inspect, customInspect } from "./console.ts";
+export { build, platform, OperatingSystem, Arch } from "./build.ts";
+export { version } from "./version.ts";
export const args: string[] = [];
// These are internal Deno APIs. We are marking them as internal so they do not
// appear in the runtime type library.
/** @internal */
-export { core } from "./core";
+export { core } from "./core.ts";
/** @internal */
-export { setPrepareStackTrace } from "./error_stack";
+export { setPrepareStackTrace } from "./error_stack.ts";
// TODO Don't expose Console nor stringifyArgs.
/** @internal */
-export { Console, stringifyArgs } from "./console";
+export { Console, stringifyArgs } from "./console.ts";
// TODO Don't expose DomIterableMixin.
/** @internal */
-export { DomIterableMixin } from "./mixins/dom_iterable";
+export { DomIterableMixin } from "./mixins/dom_iterable.ts";
+
+/** The current process id of the runtime. */
+export let pid: number;
+
+/** Reflects the NO_COLOR environment variable: https://no-color.org/ */
+export let noColor: boolean;
+
+// TODO(ry) This should not be exposed to Deno.
+export function _setGlobals(pid_: number, noColor_: boolean): void {
+ pid = pid_;
+ noColor = noColor_;
+}
diff --git a/js/diagnostics.ts b/js/diagnostics.ts
index 1207eca4f..4085d31fe 100644
--- a/js/diagnostics.ts
+++ b/js/diagnostics.ts
@@ -4,7 +4,7 @@
// compiler, which is strongly influenced by the format of TypeScript
// diagnostics.
-import * as ts from "typescript";
+/// <reference types="../third_party/node_modules/typescript/lib/typescript.d.ts"/>
/** The log category for a diagnostic message */
export enum DiagnosticCategory {
diff --git a/js/dir.ts b/js/dir.ts
index f2cf91c21..ef1111555 100644
--- a/js/dir.ts
+++ b/js/dir.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/**
* `cwd()` Return a string representing the current working directory.
diff --git a/js/dispatch.ts b/js/dispatch.ts
index af91a9b9e..1a60a5363 100644
--- a/js/dispatch.ts
+++ b/js/dispatch.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as minimal from "./dispatch_minimal";
-import * as json from "./dispatch_json";
+import * as minimal from "./dispatch_minimal.ts";
+import * as json from "./dispatch_json.ts";
// These consts are shared with Rust. Update with care.
export const OP_READ = 1;
diff --git a/js/dispatch_json.ts b/js/dispatch_json.ts
index 8ec924f4c..572ec855a 100644
--- a/js/dispatch_json.ts
+++ b/js/dispatch_json.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as util from "./util";
-import { TextEncoder, TextDecoder } from "./text_encoding";
-import { core } from "./core";
-import { ErrorKind, DenoError } from "./errors";
+import * as util from "./util.ts";
+import { TextEncoder, TextDecoder } from "./text_encoding.ts";
+import { core } from "./core.ts";
+import { ErrorKind, DenoError } from "./errors.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Ok = any;
diff --git a/js/dispatch_json_test.ts b/js/dispatch_json_test.ts
index 47e5cef2f..11dadc620 100644
--- a/js/dispatch_json_test.ts
+++ b/js/dispatch_json_test.ts
@@ -2,9 +2,9 @@ import { testPerm, assertMatch, unreachable } from "./test_util.ts";
const openErrorStackPattern = new RegExp(
`^.*
- at unwrapResponse \\(js\\/dispatch_json\\.ts:.*\\)
- at sendAsync.* \\(js\\/dispatch_json\\.ts:.*\\)
- at async Object\\.open \\(js\\/files\\.ts:.*\\).*$`,
+ at unwrapResponse \\(.*dispatch_json\\.ts:.*\\)
+ at Object.sendAsync \\(.*dispatch_json\\.ts:.*\\)
+ at async Object\\.open \\(.*files\\.ts:.*\\).*$`,
"ms"
);
diff --git a/js/dispatch_minimal.ts b/js/dispatch_minimal.ts
index 75514368c..98636f85b 100644
--- a/js/dispatch_minimal.ts
+++ b/js/dispatch_minimal.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as util from "./util";
-import { core } from "./core";
+import * as util from "./util.ts";
+import { core } from "./core.ts";
const promiseTableMin = new Map<number, util.Resolvable<number>>();
// Note it's important that promiseId starts at 1 instead of 0, because sync
diff --git a/js/dom_file.ts b/js/dom_file.ts
index 88d8ba4a9..1340da125 100644
--- a/js/dom_file.ts
+++ b/js/dom_file.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types";
-import * as blob from "./blob";
+import * as domTypes from "./dom_types.ts";
+import * as blob from "./blob.ts";
// TODO Rename this to DomFileImpl
export class DenoFile extends blob.DenoBlob implements domTypes.DomFile {
diff --git a/js/dom_util.ts b/js/dom_util.ts
index 7a5dc80b9..85a33fad1 100644
--- a/js/dom_util.ts
+++ b/js/dom_util.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Utility functions for DOM nodes
-import * as domTypes from "./dom_types";
+import * as domTypes from "./dom_types.ts";
export function isNode(nodeImpl: domTypes.EventTarget | null): boolean {
return Boolean(nodeImpl && "nodeType" in nodeImpl);
diff --git a/js/error_stack.ts b/js/error_stack.ts
index 7d41b9cf4..98b0b02d4 100644
--- a/js/error_stack.ts
+++ b/js/error_stack.ts
@@ -1,9 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// Some of the code here is adapted directly from V8 and licensed under a BSD
// style license available here: https://github.com/v8/v8/blob/24886f2d1c565287d33d71e4109a53bf0b54b75c/LICENSE.v8
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
-import { assert } from "./util";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
+import { assert } from "./util.ts";
export interface Location {
/** The full url for the module, e.g. `file://some/file.ts` or
diff --git a/js/error_stack_test.ts b/js/error_stack_test.ts
index 0df491f39..4c7edb2fd 100644
--- a/js/error_stack_test.ts
+++ b/js/error_stack_test.ts
@@ -90,22 +90,19 @@ test(function prepareStackTrace(): void {
structuredStackTrace: CallSite[]
) => string = MockError.prepareStackTrace;
const result = prepareStackTrace(new Error("foo"), [
- getMockCallSite("gen/cli/bundle/main.js", 23, 0)
+ getMockCallSite("CLI_SNAPSHOT.js", 23, 0)
]);
assert(result.startsWith("Error: foo\n"));
- assert(
- result.includes("<anonymous> (js/"),
- "should remap to something in 'js/'"
- );
+ assert(result.includes(".ts:"), "should remap to something in 'js/'");
});
test(function applySourceMap(): void {
const result = Deno.applySourceMap({
- filename: "gen/cli/bundle/main.js",
+ filename: "CLI_SNAPSHOT.js",
line: 23,
column: 0
});
- assert(result.filename.startsWith("js/"));
+ assert(result.filename.endsWith(".ts"));
assert(result.line != null);
assert(result.column != null);
});
diff --git a/js/event.ts b/js/event.ts
index 222b562a2..723926054 100644
--- a/js/event.ts
+++ b/js/event.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types";
-import { getPrivateValue, requiredArguments } from "./util";
+import * as domTypes from "./dom_types.ts";
+import { getPrivateValue, requiredArguments } from "./util.ts";
// WeakMaps are recommended for private attributes (see MDN link below)
// https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Add-on_SDK/Guides/Contributor_s_Guide/Private_Properties#Using_WeakMaps
diff --git a/js/event_target.ts b/js/event_target.ts
index e376e78a1..96ce8e2a8 100644
--- a/js/event_target.ts
+++ b/js/event_target.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types";
-import { DenoError, ErrorKind } from "./errors";
-import { hasOwnProperty, requiredArguments } from "./util";
+import * as domTypes from "./dom_types.ts";
+import { DenoError, ErrorKind } from "./errors.ts";
+import { hasOwnProperty, requiredArguments } from "./util.ts";
import {
getRoot,
isNode,
@@ -9,7 +9,7 @@ import {
isShadowInclusiveAncestor,
isSlotable,
retarget
-} from "./dom_util";
+} from "./dom_util.ts";
// https://dom.spec.whatwg.org/#get-the-parent
// Note: Nodes, shadow roots, and documents override this algorithm so we set it to null.
diff --git a/js/fetch.ts b/js/fetch.ts
index 2e18ece9a..d66eb1c48 100644
--- a/js/fetch.ts
+++ b/js/fetch.ts
@@ -1,16 +1,21 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { assert, createResolvable, notImplemented, isTypedArray } from "./util";
-import * as domTypes from "./dom_types";
-import { TextDecoder, TextEncoder } from "./text_encoding";
-import { DenoBlob, bytesSymbol as blobBytesSymbol } from "./blob";
-import { Headers } from "./headers";
-import * as io from "./io";
-import { read, close } from "./files";
-import { Buffer } from "./buffer";
-import { FormData } from "./form_data";
-import { URLSearchParams } from "./url_search_params";
-import * as dispatch from "./dispatch";
-import { sendAsync } from "./dispatch_json";
+import {
+ assert,
+ createResolvable,
+ notImplemented,
+ isTypedArray
+} from "./util.ts";
+import * as domTypes from "./dom_types.ts";
+import { TextDecoder, TextEncoder } from "./text_encoding.ts";
+import { DenoBlob, bytesSymbol as blobBytesSymbol } from "./blob.ts";
+import { Headers } from "./headers.ts";
+import * as io from "./io.ts";
+import { read, close } from "./files.ts";
+import { Buffer } from "./buffer.ts";
+import { FormData } from "./form_data.ts";
+import { URLSearchParams } from "./url_search_params.ts";
+import * as dispatch from "./dispatch.ts";
+import { sendAsync } from "./dispatch_json.ts";
function getHeaderValueParams(value: string): Map<string, string> {
const params = new Map();
diff --git a/js/file_info.ts b/js/file_info.ts
index c124e06bf..a98989e79 100644
--- a/js/file_info.ts
+++ b/js/file_info.ts
@@ -1,5 +1,5 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { StatResponse } from "./stat";
+import { StatResponse } from "./stat.ts";
/** A FileInfo describes a file and is returned by `stat`, `lstat`,
* `statSync`, `lstatSync`.
diff --git a/js/files.ts b/js/files.ts
index 0335056b3..98d18f0cf 100644
--- a/js/files.ts
+++ b/js/files.ts
@@ -9,13 +9,13 @@ import {
SyncReader,
SyncWriter,
SyncSeeker
-} from "./io";
-import { sendAsyncMinimal, sendSyncMinimal } from "./dispatch_minimal";
-import * as dispatch from "./dispatch";
+} from "./io.ts";
+import { sendAsyncMinimal, sendSyncMinimal } from "./dispatch_minimal.ts";
+import * as dispatch from "./dispatch.ts";
import {
sendSync as sendSyncJson,
sendAsync as sendAsyncJson
-} from "./dispatch_json";
+} from "./dispatch_json.ts";
/** Open a file and return an instance of the `File` object
* synchronously.
diff --git a/js/form_data.ts b/js/form_data.ts
index 3c40e64d3..f5ae290eb 100644
--- a/js/form_data.ts
+++ b/js/form_data.ts
@@ -1,9 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types";
-import * as blob from "./blob";
-import * as domFile from "./dom_file";
-import { DomIterableMixin } from "./mixins/dom_iterable";
-import { requiredArguments } from "./util";
+import * as domTypes from "./dom_types.ts";
+import * as blob from "./blob.ts";
+import * as domFile from "./dom_file.ts";
+import { DomIterableMixin } from "./mixins/dom_iterable.ts";
+import { requiredArguments } from "./util.ts";
const dataSymbol = Symbol("data");
diff --git a/js/format_error.ts b/js/format_error.ts
index dde0f6a58..801da0d0b 100644
--- a/js/format_error.ts
+++ b/js/format_error.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
// TODO(bartlomieju): move to `repl.ts`?
export function formatError(errString: string): string {
diff --git a/js/get_random_values.ts b/js/get_random_values.ts
index 154e77f75..e54f34785 100644
--- a/js/get_random_values.ts
+++ b/js/get_random_values.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
-import { assert } from "./util";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
+import { assert } from "./util.ts";
/** Synchronously collects cryptographically secure random values. The
* underlying CSPRNG in use is Rust's `rand::rngs::ThreadRng`.
diff --git a/js/globals.ts b/js/globals.ts
index ed7621165..6de8a5d89 100644
--- a/js/globals.ts
+++ b/js/globals.ts
@@ -7,31 +7,31 @@
// Modules which will make up part of the global public API surface should be
// imported as namespaces, so when the runtime type library is generated they
// can be expressed as a namespace in the type library.
-import { window } from "./window";
-import * as blob from "./blob";
-import * as consoleTypes from "./console";
-import * as csprng from "./get_random_values";
-import * as customEvent from "./custom_event";
-import * as Deno from "./deno";
-import * as domTypes from "./dom_types";
-import * as domFile from "./dom_file";
-import * as event from "./event";
-import * as eventTarget from "./event_target";
-import * as formData from "./form_data";
-import * as fetchTypes from "./fetch";
-import * as headers from "./headers";
-import * as textEncoding from "./text_encoding";
-import * as timers from "./timers";
-import * as url from "./url";
-import * as urlSearchParams from "./url_search_params";
-import * as workers from "./workers";
-import * as performanceUtil from "./performance";
-
-import * as request from "./request";
+import { window } from "./window.ts";
+import * as blob from "./blob.ts";
+import * as consoleTypes from "./console.ts";
+import * as csprng from "./get_random_values.ts";
+import * as customEvent from "./custom_event.ts";
+import * as Deno from "./deno.ts";
+import * as domTypes from "./dom_types.ts";
+import * as domFile from "./dom_file.ts";
+import * as event from "./event.ts";
+import * as eventTarget from "./event_target.ts";
+import * as formData from "./form_data.ts";
+import * as fetchTypes from "./fetch.ts";
+import * as headers from "./headers.ts";
+import * as textEncoding from "./text_encoding.ts";
+import * as timers from "./timers.ts";
+import * as url from "./url.ts";
+import * as urlSearchParams from "./url_search_params.ts";
+import * as workers from "./workers.ts";
+import * as performanceUtil from "./performance.ts";
+
+import * as request from "./request.ts";
// These imports are not exposed and therefore are fine to just import the
// symbols required.
-import { core } from "./core";
+import { core } from "./core.ts";
// During the build process, augmentations to the variable `window` in this
// file are tracked and created as part of default library that is built into
@@ -72,7 +72,6 @@ window.window = window;
// properties when building the runtime type library, as the whole module
// is flattened into a single namespace.
window.Deno = Deno;
-Object.freeze(window.Deno);
// Globally available functions and object instances.
window.atob = textEncoding.atob;
diff --git a/js/headers.ts b/js/headers.ts
index e31c0903e..dc0de54dd 100644
--- a/js/headers.ts
+++ b/js/headers.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as domTypes from "./dom_types";
-import { DomIterableMixin } from "./mixins/dom_iterable";
-import { requiredArguments } from "./util";
+import * as domTypes from "./dom_types.ts";
+import { DomIterableMixin } from "./mixins/dom_iterable.ts";
+import { requiredArguments } from "./util.ts";
// From node-fetch
// Copyright (c) 2016 David Frank. MIT License.
diff --git a/js/link.ts b/js/link.ts
index f6c6530b2..a6f732926 100644
--- a/js/link.ts
+++ b/js/link.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/** Synchronously creates `newname` as a hard link to `oldname`.
*
diff --git a/js/location.ts b/js/location.ts
index 535a2bcea..d495f99ca 100644
--- a/js/location.ts
+++ b/js/location.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { URL } from "./url";
-import { notImplemented } from "./util";
-import { Location } from "./dom_types";
-import { window } from "./window";
+import { URL } from "./url.ts";
+import { notImplemented } from "./util.ts";
+import { Location } from "./dom_types.ts";
+import { window } from "./window.ts";
export class LocationImpl implements Location {
constructor(url: string) {
diff --git a/js/main.ts b/js/main.ts
index 25e27b69f..31a7647df 100644
--- a/js/main.ts
+++ b/js/main.ts
@@ -1,36 +1,29 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-// eslint-disable-next-line @typescript-eslint/no-triple-slash-reference
-/// <reference path="./plugins.d.ts" />
-
-import "./globals";
-
-import { assert, log } from "./util";
-import * as os from "./os";
-import { args } from "./deno";
-import { setPrepareStackTrace } from "./error_stack";
-import { replLoop } from "./repl";
-import { xevalMain, XevalFunc } from "./xeval";
-import { setVersions } from "./version";
-import { window } from "./window";
-import { setLocation } from "./location";
-
-// builtin modules
-import * as deno from "./deno";
-
-export default function denoMain(
- preserveDenoNamespace: boolean = true,
- name?: string
-): void {
+import "./globals.ts";
+
+import { assert, log } from "./util.ts";
+import * as os from "./os.ts";
+import { args } from "./deno.ts";
+import { setPrepareStackTrace } from "./error_stack.ts";
+import { replLoop } from "./repl.ts";
+import { xevalMain, XevalFunc } from "./xeval.ts";
+import { setVersions } from "./version.ts";
+import { window } from "./window.ts";
+import { setLocation } from "./location.ts";
+import * as Deno from "./deno.ts";
+
+function denoMain(preserveDenoNamespace: boolean = true, name?: string): void {
const s = os.start(preserveDenoNamespace, name);
setVersions(s.denoVersion, s.v8Version);
// handle `--version`
if (s.versionFlag) {
- console.log("deno:", deno.version.deno);
- console.log("v8:", deno.version.v8);
- console.log("typescript:", deno.version.typescript);
+ const { console } = window;
+ console.log("deno:", Deno.version.deno);
+ console.log("v8:", Deno.version.v8);
+ console.log("typescript:", Deno.version.typescript);
os.exit(0);
}
@@ -55,3 +48,4 @@ export default function denoMain(
replLoop();
}
}
+window["denoMain"] = denoMain;
diff --git a/js/make_temp_dir.ts b/js/make_temp_dir.ts
index 5e0a28205..14494b5da 100644
--- a/js/make_temp_dir.ts
+++ b/js/make_temp_dir.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
export interface MakeTempDirOptions {
dir?: string;
diff --git a/js/metrics.ts b/js/metrics.ts
index 48e3102e5..b32c29789 100644
--- a/js/metrics.ts
+++ b/js/metrics.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
export interface Metrics {
opsDispatched: number;
diff --git a/js/mixins/dom_iterable.ts b/js/mixins/dom_iterable.ts
index 97e8133ec..bbd1905ce 100644
--- a/js/mixins/dom_iterable.ts
+++ b/js/mixins/dom_iterable.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
// eslint-disable-next-line @typescript-eslint/no-unused-vars
-import { DomIterable } from "../dom_types";
-import { window } from "../window";
-import { requiredArguments } from "../util";
+import { DomIterable } from "../dom_types.ts";
+import { window } from "../window.ts";
+import { requiredArguments } from "../util.ts";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Constructor<T = {}> = new (...args: any[]) => T;
diff --git a/js/mkdir.ts b/js/mkdir.ts
index 54f99224b..bc09ba358 100644
--- a/js/mkdir.ts
+++ b/js/mkdir.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/** Creates a new directory with the specified path synchronously.
* If `recursive` is set to true, nested directories will be created (also known
diff --git a/js/net.ts b/js/net.ts
index 809dd4092..b0651b326 100644
--- a/js/net.ts
+++ b/js/net.ts
@@ -1,9 +1,9 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { EOF, Reader, Writer, Closer } from "./io";
-import { notImplemented } from "./util";
-import { read, write, close } from "./files";
-import * as dispatch from "./dispatch";
-import { sendSync, sendAsync } from "./dispatch_json";
+import { EOF, Reader, Writer, Closer } from "./io.ts";
+import { notImplemented } from "./util.ts";
+import { read, write, close } from "./files.ts";
+import * as dispatch from "./dispatch.ts";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
export type Network = "tcp";
// TODO support other types:
diff --git a/js/os.ts b/js/os.ts
index c44c27825..dbfbf3c88 100644
--- a/js/os.ts
+++ b/js/os.ts
@@ -1,22 +1,13 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { core } from "./core";
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
-import { assert } from "./util";
-import * as util from "./util";
-import { window } from "./window";
+import { core } from "./core.ts";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
+import { assert } from "./util.ts";
+import * as util from "./util.ts";
+import { window } from "./window.ts";
-/** The current process id of the runtime. */
-export let pid: number;
-
-/** Reflects the NO_COLOR environment variable: https://no-color.org/ */
-export let noColor: boolean;
-
-function setGlobals(pid_: number, noColor_: boolean): void {
- assert(!pid);
- pid = pid_;
- noColor = noColor_;
-}
+// builtin modules
+import { _setGlobals } from "./deno.ts";
/** Check if running in terminal.
*
@@ -85,7 +76,11 @@ export function start(preserveDenoNamespace = true, source?: string): Start {
util.setLogDebug(s.debugFlag, source);
- setGlobals(s.pid, s.noColor);
+ // pid and noColor need to be set in the Deno module before it's set to be
+ // frozen.
+ _setGlobals(s.pid, s.noColor);
+ delete window.Deno._setGlobals;
+ Object.freeze(window.Deno);
if (preserveDenoNamespace) {
util.immutableDefine(window, "Deno", window.Deno);
diff --git a/js/performance.ts b/js/performance.ts
index d2f339c46..6ea8e56e1 100644
--- a/js/performance.ts
+++ b/js/performance.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
interface NowResponse {
seconds: number;
diff --git a/js/permissions.ts b/js/permissions.ts
index bc969f3a8..4f393501c 100644
--- a/js/permissions.ts
+++ b/js/permissions.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
/** Permissions as granted by the caller */
export interface Permissions {
diff --git a/js/plugins.d.ts b/js/plugins.d.ts
deleted file mode 100644
index 842a897de..000000000
--- a/js/plugins.d.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-
-// This allows TypeScript to resolve any modules that end with `!string`
-// as there is a rollup plugin that will take any mids ending with `!string`
-// and return them as a string to rollup for inlining
-declare module "*!string" {
- const value: string;
- export default value;
-}
diff --git a/js/process.ts b/js/process.ts
index dd4f70103..4de9fe774 100644
--- a/js/process.ts
+++ b/js/process.ts
@@ -1,11 +1,11 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
-import { File, close } from "./files";
-import { ReadCloser, WriteCloser } from "./io";
-import { readAll } from "./buffer";
-import { assert, unreachable } from "./util";
-import { platform } from "./build";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
+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";
/** How to handle subprocess stdio.
*
diff --git a/js/read_dir.ts b/js/read_dir.ts
index 27d011a08..2fa6a566b 100644
--- a/js/read_dir.ts
+++ b/js/read_dir.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
-import { FileInfo, FileInfoImpl } from "./file_info";
-import { StatResponse } from "./stat";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
+import { FileInfo, FileInfoImpl } from "./file_info.ts";
+import { StatResponse } from "./stat.ts";
interface ReadDirResponse {
entries: StatResponse[];
diff --git a/js/read_file.ts b/js/read_file.ts
index 1ca52e276..de6630cc0 100644
--- a/js/read_file.ts
+++ b/js/read_file.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { open, openSync } from "./files";
-import { readAll, readAllSync } from "./buffer";
+import { open, openSync } from "./files.ts";
+import { readAll, readAllSync } from "./buffer.ts";
/** Read the entire contents of a file synchronously.
*
diff --git a/js/read_link.ts b/js/read_link.ts
index fae1e64b6..861fbff0b 100644
--- a/js/read_link.ts
+++ b/js/read_link.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/** Returns the destination of the named symbolic link synchronously.
*
diff --git a/js/remove.ts b/js/remove.ts
index f2a94f395..36413a7c4 100644
--- a/js/remove.ts
+++ b/js/remove.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
export interface RemoveOption {
recursive?: boolean;
diff --git a/js/rename.ts b/js/rename.ts
index 80794747d..c906ce37b 100644
--- a/js/rename.ts
+++ b/js/rename.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
/** Synchronously renames (moves) `oldpath` to `newpath`. If `newpath` already
* exists and is not a directory, `renameSync()` replaces it. OS-specific
diff --git a/js/repl.ts b/js/repl.ts
index 08a4fb210..966e809e8 100644
--- a/js/repl.ts
+++ b/js/repl.ts
@@ -1,12 +1,14 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { close } from "./files";
-import { exit } from "./os";
-import { window } from "./window";
-import { core } from "./core";
-import { formatError } from "./format_error";
-import { stringifyArgs } from "./console";
-import * as dispatch from "./dispatch";
-import { sendSync, sendAsync } from "./dispatch_json";
+import { close } from "./files.ts";
+import { exit } from "./os.ts";
+import { window } from "./window.ts";
+import { core } from "./core.ts";
+import { formatError } from "./format_error.ts";
+import { stringifyArgs } from "./console.ts";
+import * as dispatch from "./dispatch.ts";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+
+const { console } = window;
/**
* REPL logging.
diff --git a/js/request.ts b/js/request.ts
index 5ed1e9d63..f7a3cdfc1 100644
--- a/js/request.ts
+++ b/js/request.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as headers from "./headers";
-import * as body from "./body";
-import * as domTypes from "./dom_types";
+import * as headers from "./headers.ts";
+import * as body from "./body.ts";
+import * as domTypes from "./dom_types.ts";
const { Headers } = headers;
diff --git a/js/resources.ts b/js/resources.ts
index 6e2ec202b..27598ce09 100644
--- a/js/resources.ts
+++ b/js/resources.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as dispatch from "./dispatch";
-import { sendSync } from "./dispatch_json";
+import * as dispatch from "./dispatch.ts";
+import { sendSync } from "./dispatch_json.ts";
export interface ResourceMap {
[rid: number]: string;
diff --git a/js/stat.ts b/js/stat.ts
index 1cc8d070a..1f53e6f7b 100644
--- a/js/stat.ts
+++ b/js/stat.ts
@@ -1,7 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
-import { FileInfo, FileInfoImpl } from "./file_info";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
+import { FileInfo, FileInfoImpl } from "./file_info.ts";
export interface StatResponse {
isFile: boolean;
diff --git a/js/symlink.ts b/js/symlink.ts
index 6fd2e90a5..4418e22ce 100644
--- a/js/symlink.ts
+++ b/js/symlink.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
-import * as util from "./util";
-import { platform } from "./build";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
+import * as util from "./util.ts";
+import { platform } from "./build.ts";
/** Synchronously creates `newname` as a symbolic link to `oldname`. The type
* argument can be set to `dir` or `file` and is only available on Windows
diff --git a/js/text_encoding.ts b/js/text_encoding.ts
index 830b4278e..5aed7ac07 100644
--- a/js/text_encoding.ts
+++ b/js/text_encoding.ts
@@ -23,9 +23,9 @@
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
-import * as base64 from "./base64";
-import * as domTypes from "./dom_types";
-import { DenoError, ErrorKind } from "./errors";
+import * as base64 from "./base64.ts";
+import * as domTypes from "./dom_types.ts";
+import { DenoError, ErrorKind } from "./errors.ts";
const CONTINUE = null;
const END_OF_STREAM = -1;
diff --git a/js/timers.ts b/js/timers.ts
index 4b8596cb7..8aec33d92 100644
--- a/js/timers.ts
+++ b/js/timers.ts
@@ -1,8 +1,10 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { assert } from "./util";
-import { window } from "./window";
-import * as dispatch from "./dispatch";
-import { sendSync, sendAsync } from "./dispatch_json";
+import { assert } from "./util.ts";
+import { window } from "./window.ts";
+import * as dispatch from "./dispatch.ts";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+
+const { console } = window;
interface Timer {
id: number;
diff --git a/js/truncate.ts b/js/truncate.ts
index c6e5b3ad0..5ce7b5158 100644
--- a/js/truncate.ts
+++ b/js/truncate.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import * as dispatch from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import * as dispatch from "./dispatch.ts";
function coerceLen(len?: number): number {
if (!len) {
diff --git a/js/url.ts b/js/url.ts
index 6520af834..334d1c09b 100644
--- a/js/url.ts
+++ b/js/url.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import * as urlSearchParams from "./url_search_params";
-import * as domTypes from "./dom_types";
-import { getRandomValues } from "./get_random_values";
-import { window } from "./window";
+import * as urlSearchParams from "./url_search_params.ts";
+import * as domTypes from "./dom_types.ts";
+import { getRandomValues } from "./get_random_values.ts";
+import { window } from "./window.ts";
interface URLParts {
protocol: string;
diff --git a/js/url_search_params.ts b/js/url_search_params.ts
index 8e122191d..63c02d3b8 100644
--- a/js/url_search_params.ts
+++ b/js/url_search_params.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { URL } from "./url";
-import { requiredArguments, isIterable } from "./util";
+import { URL } from "./url.ts";
+import { requiredArguments, isIterable } from "./util.ts";
export class URLSearchParams {
private params: Array<[string, string]> = [];
diff --git a/js/util.ts b/js/util.ts
index da56465a2..86a856170 100644
--- a/js/util.ts
+++ b/js/util.ts
@@ -1,5 +1,7 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { TypedArray } from "./types";
+import { TypedArray } from "./types.ts";
+import { window } from "./window.ts";
+const { console } = window;
let logDebug = false;
let logSource = "JS";
diff --git a/js/utime.ts b/js/utime.ts
index c71710458..7495378b1 100644
--- a/js/utime.ts
+++ b/js/utime.ts
@@ -1,6 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { sendSync, sendAsync } from "./dispatch_json";
-import { OP_UTIME } from "./dispatch";
+import { sendSync, sendAsync } from "./dispatch_json.ts";
+import { OP_UTIME } from "./dispatch.ts";
function toSecondsFromEpoch(v: number | Date): number {
return v instanceof Date ? v.valueOf() / 1000 : v;
diff --git a/js/version.ts b/js/version.ts
index 471072d81..3ceade24e 100644
--- a/js/version.ts
+++ b/js/version.ts
@@ -9,7 +9,7 @@ export const version: Version = {
deno: "",
v8: "",
// This string will be replaced by rollup
- typescript: `ROLLUP_REPLACE_TS_VERSION`
+ typescript: `DENO_REPLACE_TS_VERSION`
};
/**
diff --git a/js/workers.ts b/js/workers.ts
index 7bcbe6279..36c2aa50b 100644
--- a/js/workers.ts
+++ b/js/workers.ts
@@ -1,12 +1,12 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
/* eslint-disable @typescript-eslint/no-explicit-any */
-import * as dispatch from "./dispatch";
-import { sendAsync, sendSync } from "./dispatch_json";
-import { log } from "./util";
-import { TextDecoder, TextEncoder } from "./text_encoding";
-import { window } from "./window";
-import { blobURLMap } from "./url";
-import { blobBytesWeakMap } from "./blob";
+import * as dispatch from "./dispatch.ts";
+import { sendAsync, sendSync } from "./dispatch_json.ts";
+import { log } from "./util.ts";
+import { TextDecoder, TextEncoder } from "./text_encoding.ts";
+import { window } from "./window.ts";
+import { blobURLMap } from "./url.ts";
+import { blobBytesWeakMap } from "./blob.ts";
const encoder = new TextEncoder();
const decoder = new TextDecoder();
diff --git a/js/write_file.ts b/js/write_file.ts
index c7b71725c..d6307e002 100644
--- a/js/write_file.ts
+++ b/js/write_file.ts
@@ -1,8 +1,8 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-import { stat, statSync } from "./stat";
-import { open, openSync } from "./files";
-import { chmod, chmodSync } from "./chmod";
-import { writeAll, writeAllSync } from "./buffer";
+import { stat, statSync } from "./stat.ts";
+import { open, openSync } from "./files.ts";
+import { chmod, chmodSync } from "./chmod.ts";
+import { writeAll, writeAllSync } from "./buffer.ts";
/** Options for writing to a file.
* `perm` would change the file's permission if set.
diff --git a/js/xeval.ts b/js/xeval.ts
index fa706ae20..2ef90ce29 100644
--- a/js/xeval.ts
+++ b/js/xeval.ts
@@ -1,7 +1,7 @@
-import { Buffer, writeAll } from "./buffer";
-import { stdin } from "./files";
-import { TextEncoder, TextDecoder } from "./text_encoding";
-import { Reader, EOF } from "./io";
+import { Buffer, writeAll } from "./buffer.ts";
+import { stdin } from "./files.ts";
+import { TextEncoder, TextDecoder } from "./text_encoding.ts";
+import { Reader, EOF } from "./io.ts";
export type XevalFunc = (v: string) => void;
diff --git a/package.json b/package.json
index 23e4c8f4e..08415982d 100644
--- a/package.json
+++ b/package.json
@@ -8,18 +8,6 @@
"eslint-config-prettier": "4.1.0",
"magic-string": "0.25.2",
"prettier": "1.17.1",
- "rollup": "1.4.1",
- "rollup-plugin-alias": "1.5.1",
- "rollup-plugin-analyzer": "3.0.0",
- "rollup-plugin-commonjs": "9.1.3",
- "rollup-plugin-node-globals": "1.4.0",
- "rollup-plugin-node-resolve": "4.0.1",
- "rollup-plugin-replace": "2.1.0",
- "rollup-plugin-string": "3.0.0",
- "rollup-plugin-typescript2": "0.19.3",
- "rollup-pluginutils": "2.4.1",
- "ts-morph": "1.3.0",
- "ts-node": "8.0.2",
"typescript": "3.5.1"
}
}
diff --git a/rollup.config.js b/rollup.config.js
deleted file mode 100644
index cc583c59c..000000000
--- a/rollup.config.js
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-// @ts-check
-import * as fs from "fs";
-import path from "path";
-import alias from "rollup-plugin-alias";
-import { plugin as analyze } from "rollup-plugin-analyzer";
-import commonjs from "rollup-plugin-commonjs";
-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";
-
-const mockPath = path.resolve(__dirname, "js/mock_builtin.js");
-const tsconfig = path.resolve(__dirname, "tsconfig.json");
-const typescriptPath = path.resolve(
- __dirname,
- "third_party/node_modules/typescript/lib/typescript.js"
-);
-
-// We will allow generated modules to be resolvable by TypeScript based on
-// the current build path
-const tsconfigOverride = {
- compilerOptions: {
- paths: {
- "*": ["*", path.resolve("*")]
- }
- }
-};
-
-const archNodeToDeno = {
- x64: "x64"
-};
-const osNodeToDeno = {
- win32: "win",
- darwin: "mac",
- linux: "linux"
-};
-
-function generateDepFile({ outputFile, sourceFiles = [], configFiles = [] }) {
- let timestamp = new Date();
-
- // Save the depfile just before the node process exits.
- process.once("beforeExit", () =>
- writeDepFile({ outputFile, sourceFiles, configFiles, timestamp })
- );
-
- return {
- name: "depfile",
- load(sourceFile) {
- // The 'globals' plugin adds generated files that don't exist on disk.
- // Don't add them to the depfile.
- if (/^[0-9a-f]{30}$/.test(sourceFile)) {
- return;
- }
- sourceFiles.push(sourceFile);
- // Remember the time stamp that we last resolved a dependency.
- // We'll set the last modified time of the depfile to that.
- timestamp = new Date();
- }
- };
-}
-
-function writeDepFile({ outputFile, sourceFiles, configFiles, timestamp }) {
- const buildDir = process.cwd();
- const outputDir = path.dirname(outputFile);
-
- // Assert that the discovered bundle inputs are files that exist on disk.
- sourceFiles.forEach(f => fs.accessSync(f));
- // Since we also want to rebuild the bundle if rollup configuration or the the
- // tooling changes (e.g. when typescript is updated), add the currently loaded
- // node.js modules to the list of dependencies.
- let inputs = [...sourceFiles, ...configFiles, ...Object.keys(require.cache)];
- // Deduplicate the list of inputs.
- inputs = Array.from(new Set(inputs.map(f => path.resolve(f))));
- // Turn filenames into relative paths and format/escape them for a Makefile.
- inputs = inputs.map(formatPath);
-
- // Build a list of output filenames and normalize those too.
- const depFile = path.join(
- outputDir,
- path.basename(outputFile, path.extname(outputFile)) + ".d"
- );
- const outputs = [outputFile, depFile].map(formatPath);
-
- // Generate depfile contents.
- const depFileContent = [
- ...outputs.map(filename => `${filename}: ` + inputs.join(" ") + "\n\n"),
- ...inputs.map(filename => `${filename}:\n`)
- ].join("");
-
- // Since we're writing the depfile when node's "beforeExit" hook triggers,
- // it's getting written _after_ the regular outputs are saved to disk.
- // Therefore, after writing the depfile, reset its timestamps to when we last
- // discovered a dependency, which was certainly before the bundle was built.
- fs.writeFileSync(depFile, depFileContent);
- fs.utimesSync(depFile, timestamp, timestamp);
-
- // Renders path to make it suitable for a depfile.
- function formatPath(filename) {
- // Make the path relative to the root build directory.
- filename = path.relative(buildDir, filename);
- // Use forward slashes on Windows.
- if (process.platform === "win32") {
- filename = filename.replace(/\\/g, "/");
- }
- // Escape spaces with a backslash. This is what rust and clang do too.
- filename = filename.replace(/ /g, "\\ ");
- return filename;
- }
-}
-
-export default function makeConfig(commandOptions) {
- return {
- output: {
- format: "iife",
- name: "denoMain",
- sourcemap: true,
- sourcemapExcludeSources: true
- },
-
- plugins: [
- // inject build and version info
- replace({
- ROLLUP_REPLACE_TS_VERSION: typescript.version,
- ROLLUP_REPLACE_ARCH: archNodeToDeno[process.arch],
- ROLLUP_REPLACE_OS: osNodeToDeno[process.platform]
- }),
-
- // 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
- // a physical module to substitute
- alias({
- fs: mockPath,
- path: mockPath,
- os: mockPath,
- crypto: mockPath,
- buffer: mockPath,
- module: mockPath
- }),
-
- // Allows rollup to resolve modules based on Node.js resolution
- nodeResolve(),
-
- // Allows rollup to import CommonJS modules
- commonjs({
- namedExports: {
- // Static analysis of `typescript.js` does detect the exports properly, therefore
- // rollup requires them to be explicitly defined to make them available in the
- // bundle
- [typescriptPath]: [
- "convertCompilerOptionsFromJson",
- "createLanguageService",
- "createProgram",
- "createSourceFile",
- "getPreEmitDiagnostics",
- "formatDiagnostics",
- "formatDiagnosticsWithColorAndContext",
- "parseConfigFileTextToJson",
- "version",
- "CompilerHost",
- "DiagnosticCategory",
- "Extension",
- "ModuleKind",
- "ScriptKind",
- "ScriptSnapshot",
- "ScriptTarget"
- ]
- }
- }),
-
- typescriptPlugin({
- // The build script is invoked from `out/:target` so passing an absolute file path is needed
- tsconfig,
-
- // This provides any overrides to the `tsconfig.json` that are needed to bundle
- tsconfigOverride,
-
- // This provides the locally configured version of TypeScript instead of the plugins
- // default version
- typescript,
-
- // By default, the include path only includes the cwd and below, need to include the root of the project
- // and build path to be passed to this plugin. This is different front tsconfig.json include
- include: ["*.ts", `${__dirname}/**/*.ts`, `${process.cwd()}/**/*.ts`],
-
- // d.ts files are not bundled and by default like include, it only includes the cwd and below
- exclude: [
- "*.d.ts",
- `${__dirname}/**/*.d.ts`,
- `${process.cwd()}/**/*.d.ts`
- ]
- }),
-
- // Provide some concise information about the bundle
- analyze({
- skipFormatted: true,
- onAnalysis({
- bundleSize,
- bundleOrigSize,
- bundleReduction,
- moduleCount
- }) {
- if (!commandOptions.silent) {
- console.log(
- `Bundle size: ${Math.round((bundleSize / 1000000) * 100) / 100}Mb`
- );
- console.log(
- `Original size: ${Math.round((bundleOrigSize / 1000000) * 100) /
- 100}Mb`
- );
- console.log(`Reduction: ${bundleReduction}%`);
- console.log(`Module count: ${moduleCount}`);
- }
- }
- }),
-
- // source-map-support, which is required by TypeScript to support source maps, requires Node.js Buffer
- // implementation. This needs to come at the end of the plugins because of the impact it has on
- // the existing runtime environment, which breaks other plugins and features of the bundler.
- globals(),
-
- generateDepFile({
- outputFile: commandOptions.o,
- configFiles: [commandOptions.c, tsconfig]
- })
- ]
- };
-}
diff --git a/tests/error_004_missing_module.ts.out b/tests/error_004_missing_module.ts.out
index a0ce342e9..db56f51a5 100644
--- a/tests/error_004_missing_module.ts.out
+++ b/tests/error_004_missing_module.ts.out
@@ -1,12 +1,12 @@
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts"
-[WILDCARD] js/dispatch_json.ts:[WILDCARD]
- at DenoError (js/errors.ts:[WILDCARD])
- at unwrapResponse (js/dispatch_json.ts:[WILDCARD])
- at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
- at fetchSourceFile (js/compiler.ts:[WILDCARD])
- at _resolveModule (js/compiler.ts:[WILDCARD])
- at js/compiler.ts:[WILDCARD]
- at resolveModuleNames (js/compiler.ts:[WILDCARD])
+[WILDCARD]dispatch_json.ts:[WILDCARD]
+ at DenoError ([WILDCARD]errors.ts:[WILDCARD])
+ at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at fetchSourceFile ([WILDCARD]compiler.ts:[WILDCARD])
+ at _resolveModule ([WILDCARD]compiler.ts:[WILDCARD])
+ at [WILDCARD]compiler.ts:[WILDCARD]
+ at resolveModuleNames ([WILDCARD]compiler.ts:[WILDCARD])
at resolveModuleNamesWorker ([WILDCARD]typescript.js:[WILDCARD])
at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD])
at processImportedModules ([WILDCARD]typescript.js:[WILDCARD])
diff --git a/tests/error_005_missing_dynamic_import.ts.out b/tests/error_005_missing_dynamic_import.ts.out
index a580368ba..eb1d7b7b1 100644
--- a/tests/error_005_missing_dynamic_import.ts.out
+++ b/tests/error_005_missing_dynamic_import.ts.out
@@ -1,11 +1,11 @@
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/bad-module.ts"
-[WILDCARD] js/dispatch_json.ts:[WILDCARD]
- at DenoError (js/errors.ts:[WILDCARD])
- at unwrapResponse (js/dispatch_json.ts:[WILDCARD])
- at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
- at fetchSourceFile (js/compiler.ts:[WILDCARD])
- at _resolveModule (js/compiler.ts:[WILDCARD])
- at js/compiler.ts:[WILDCARD]
+[WILDCARD]dispatch_json.ts:[WILDCARD]
+ at DenoError ([WILDCARD]errors.ts:[WILDCARD])
+ at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at fetchSourceFile ([WILDCARD]compiler.ts:[WILDCARD])
+ at _resolveModule ([WILDCARD]compiler.ts:[WILDCARD])
+ at [WILDCARD]compiler.ts:[WILDCARD]
at resolveModuleNamesWorker ([WILDCARD])
at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD])
at processImportedModules ([WILDCARD]typescript.js:[WILDCARD])
diff --git a/tests/error_006_import_ext_failure.ts.out b/tests/error_006_import_ext_failure.ts.out
index 442ef9c53..d0e14520b 100644
--- a/tests/error_006_import_ext_failure.ts.out
+++ b/tests/error_006_import_ext_failure.ts.out
@@ -1,11 +1,11 @@
[WILDCARD]error: Uncaught NotFound: Cannot resolve module "[WILDCARD]/non-existent"
-[WILDCARD] js/dispatch_json.ts:[WILDCARD]
- at DenoError (js/errors.ts:[WILDCARD])
- at unwrapResponse (js/dispatch_json.ts:[WILDCARD])
- at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
- at fetchSourceFile (js/compiler.ts:[WILDCARD])
- at _resolveModule (js/compiler.ts:[WILDCARD])
- at js/compiler.ts:[WILDCARD]
+[WILDCARD]dispatch_json.ts:[WILDCARD]
+ at DenoError ([WILDCARD]errors.ts:[WILDCARD])
+ at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at fetchSourceFile ([WILDCARD]compiler.ts:[WILDCARD])
+ at _resolveModule ([WILDCARD]compiler.ts:[WILDCARD])
+ at [WILDCARD]compiler.ts:[WILDCARD]
at resolveModuleNamesWorker ([WILDCARD])
at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD])
at processImportedModules ([WILDCARD]typescript.js:[WILDCARD])
diff --git a/tests/error_011_bad_module_specifier.ts.out b/tests/error_011_bad_module_specifier.ts.out
index 518ad08b3..9918c503c 100644
--- a/tests/error_011_bad_module_specifier.ts.out
+++ b/tests/error_011_bad_module_specifier.ts.out
@@ -1,11 +1,11 @@
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../
-[WILDCARD] js/dispatch_json.ts:[WILDCARD]
- at DenoError (js/errors.ts:[WILDCARD])
- at unwrapResponse (js/dispatch_json.ts:[WILDCARD])
- at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
- at fetchSourceFile (js/compiler.ts:[WILDCARD])
- at _resolveModule (js/compiler.ts:[WILDCARD])
- at js/compiler.ts:[WILDCARD]
+[WILDCARD]dispatch_json.ts:[WILDCARD]
+ at DenoError ([WILDCARD]errors.ts:[WILDCARD])
+ at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at fetchSourceFile ([WILDCARD]compiler.ts:[WILDCARD])
+ at _resolveModule ([WILDCARD]compiler.ts:[WILDCARD])
+ at [WILDCARD]compiler.ts:[WILDCARD]
at resolveModuleNamesWorker ([WILDCARD])
at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD])
at processImportedModules ([WILDCARD]typescript.js:[WILDCARD])
diff --git a/tests/error_012_bad_dynamic_import_specifier.ts.out b/tests/error_012_bad_dynamic_import_specifier.ts.out
index 518ad08b3..9918c503c 100644
--- a/tests/error_012_bad_dynamic_import_specifier.ts.out
+++ b/tests/error_012_bad_dynamic_import_specifier.ts.out
@@ -1,11 +1,11 @@
[WILDCARD]error: Uncaught ImportPrefixMissing: relative import path "bad-module.ts" not prefixed with / or ./ or ../
-[WILDCARD] js/dispatch_json.ts:[WILDCARD]
- at DenoError (js/errors.ts:[WILDCARD])
- at unwrapResponse (js/dispatch_json.ts:[WILDCARD])
- at sendSync[WILDCARD] (js/dispatch_json.ts:[WILDCARD])
- at fetchSourceFile (js/compiler.ts:[WILDCARD])
- at _resolveModule (js/compiler.ts:[WILDCARD])
- at js/compiler.ts:[WILDCARD]
+[WILDCARD]dispatch_json.ts:[WILDCARD]
+ at DenoError ([WILDCARD]errors.ts:[WILDCARD])
+ at unwrapResponse ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at sendSync[WILDCARD] ([WILDCARD]dispatch_json.ts:[WILDCARD])
+ at fetchSourceFile ([WILDCARD]compiler.ts:[WILDCARD])
+ at _resolveModule ([WILDCARD]compiler.ts:[WILDCARD])
+ at [WILDCARD]compiler.ts:[WILDCARD]
at resolveModuleNamesWorker ([WILDCARD])
at resolveModuleNamesReusingOldState ([WILDCARD]typescript.js:[WILDCARD])
at processImportedModules ([WILDCARD]typescript.js:[WILDCARD])
diff --git a/tests/error_type_definitions.ts.out b/tests/error_type_definitions.ts.out
index 4b29b5b83..cc09c149d 100644
--- a/tests/error_type_definitions.ts.out
+++ b/tests/error_type_definitions.ts.out
@@ -1,4 +1,4 @@
[WILDCARD]error: Uncaught TypeError: Automatic type resolution not supported
-[WILDCARD]js/compiler.ts:[WILDCARD]
- at fileExists (js/compiler.ts:[WILDCARD])
+[WILDCARD]compiler.ts:[WILDCARD]
+ at fileExists ([WILDCARD]compiler.ts:[WILDCARD])
[WILDCARD] \ No newline at end of file
diff --git a/third_party b/third_party
-Subproject b9427d8eee3bf17c4d1281e88f0ef7b611f13c9
+Subproject 2f1a94bafe78962c39f51bb4249cfe19fe11879
diff --git a/tools/benchmark.py b/tools/benchmark.py
index 8615a17d9..d6c45259d 100755
--- a/tools/benchmark.py
+++ b/tools/benchmark.py
@@ -11,7 +11,8 @@ import sys
import json
import time
import shutil
-from util import root_path, run, run_output, build_path, executable_suffix
+from util import find_exts, root_path, run, run_output
+from util import build_path, executable_suffix
import tempfile
import http_server
import throughput_benchmark
@@ -59,22 +60,26 @@ def import_data_from_gh_pages():
def get_binary_sizes(build_dir):
+ # Because cargo's OUT_DIR is not predictable, we have to search the build
+ # tree for these files...
+ files = find_exts([build_dir], ["js", "map", "bin"])
path_dict = {
- "deno":
- os.path.join(build_dir, "deno" + executable_suffix),
- "main.js":
- os.path.join(build_dir, "gen/cli/bundle/main.js"),
- "main.js.map":
- os.path.join(build_dir, "gen/cli/bundle/main.js.map"),
- "compiler.js":
- os.path.join(build_dir, "gen/cli/bundle/compiler.js"),
- "compiler.js.map":
- os.path.join(build_dir, "gen/cli/bundle/compiler.js.map"),
- "snapshot_deno.bin":
- os.path.join(build_dir, "gen/cli/snapshot_deno.bin"),
- "snapshot_compiler.bin":
- os.path.join(build_dir, "gen/cli/snapshot_compiler.bin")
+ "deno": os.path.join(build_dir, "deno" + executable_suffix),
}
+ for f in files:
+ if f.endswith("CLI_SNAPSHOT.js"):
+ path_dict["CLI_SNAPSHOT.js"] = f
+ elif f.endswith("CLI_SNAPSHOT.js.map"):
+ path_dict["CLI_SNAPSHOT.js.map"] = f
+ elif f.endswith("CLI_SNAPSHOT.bin"):
+ path_dict["CLI_SNAPSHOT.bin"] = f
+ elif f.endswith("COMPILER_SNAPSHOT.js"):
+ path_dict["COMPILER_SNAPSHOT.js"] = f
+ elif f.endswith("COMPILER_SNAPSHOT.js.map"):
+ path_dict["COMPILER_SNAPSHOT.js.map"] = f
+ elif f.endswith("COMPILER_SNAPSHOT.bin"):
+ path_dict["COMPILER_SNAPSHOT.bin"] = f
+
sizes = {}
for name, path in path_dict.items():
assert os.path.exists(path)
diff --git a/tools/benchmark_test.py b/tools/benchmark_test.py
index a49db7b74..d84451494 100755
--- a/tools/benchmark_test.py
+++ b/tools/benchmark_test.py
@@ -32,9 +32,9 @@ class TestBenchmark(DenoTestCase):
def test_binary_size(self):
binary_size_dict = benchmark.get_binary_sizes(self.build_dir)
assert binary_size_dict["deno"] > 0
- assert binary_size_dict["main.js"] > 0
- assert binary_size_dict["main.js.map"] > 0
- assert binary_size_dict["snapshot_deno.bin"] > 0
+ assert binary_size_dict["CLI_SNAPSHOT.js"] > 0
+ assert binary_size_dict["CLI_SNAPSHOT.js.map"] > 0
+ assert binary_size_dict["CLI_SNAPSHOT.bin"] > 0
@unittest.skipIf("linux" not in sys.platform,
"strace only supported on linux")
diff --git a/tools/format.py b/tools/format.py
index c7465516a..aa2208b01 100755
--- a/tools/format.py
+++ b/tools/format.py
@@ -64,13 +64,15 @@ def rustfmt():
"rustfmt",
"--config-path",
rustfmt_config,
- ] + find_exts(["cli", "core", "tools"], [".rs"]))
+ ] + find_exts(["cli", "core", "tools", "deno_typescript", "cli_snapshots"],
+ [".rs"]))
def gn_format():
print "gn format"
- for fn in ["BUILD.gn", ".gn"] + find_exts(["build_extra", "cli", "core"],
- [".gn", ".gni"]):
+ for fn in ["BUILD.gn", ".gn"] + find_exts(
+ ["build_extra", "cli", "core", "deno_typescript", "cli_snapshots"],
+ [".gn", ".gni"]):
qrun(["third_party/depot_tools/gn", "format", fn], env=google_env())
@@ -78,14 +80,18 @@ def yapf():
print "yapf"
qrun(
[sys.executable, "third_party/python_packages/bin/yapf", "-i"] +
- find_exts(["tools", "build_extra"], [".py"], skip=["tools/clang"]),
+ find_exts(["tools", "build_extra", "deno_typescript", "cli_snapshots"],
+ [".py"],
+ skip=["tools/clang"]),
env=python_env())
def prettier():
print "prettier"
- files = find_exts([".github", "js", "tests", "tools", "website", "core"],
- [".js", ".json", ".ts", ".md"],
+ files = find_exts([
+ ".github", "js", "tests", "tools", "website", "core",
+ "deno_typescript", "cli_snapshots"
+ ], [".js", ".json", ".ts", ".md"],
skip=["tools/clang", "js/deps", "js/gen"])
qrun(["node", prettier_path, "--write", "--loglevel=error"] +
["rollup.config.js"] + files)
diff --git a/website/manual.md b/website/manual.md
index 317d6b546..e7adab0f0 100644
--- a/website/manual.md
+++ b/website/manual.md
@@ -174,8 +174,7 @@ To ensure reproducible builds, deno has most of its dependencies in a git
submodule. However, you need to install separately:
1. [Rust](https://www.rust-lang.org/en-US/install.html) >= 1.36.0
-2. [Node](https://nodejs.org/)
-3. Python 2.
+2. Python 2.
[Not 3](https://github.com/denoland/deno/issues/464#issuecomment-411795578).
Extra steps for Mac users: install [XCode](https://developer.apple.com/xcode/)