From 473c07feb5b00270e41acc1072fd43ffca90be6e Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Wed, 28 Aug 2019 11:59:23 -0400 Subject: [PATCH] Refactor snapshots 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 improve incremental build time when changes are made //js files by about 40 seconds. --- Cargo.lock | 81 +++++++ Cargo.toml | 2 + build_extra/rust/run.py | 1 + cli/BUILD.gn | 145 +----------- cli/Cargo.toml | 1 + cli/build.rs | 15 -- cli/deno.gni | 65 ------ cli/source_maps.rs | 22 +- cli/startup_data.rs | 10 +- cli_snapshots/BUILD.gn | 124 ++++++++++ cli_snapshots/Cargo.toml | 19 ++ cli_snapshots/build.rs | 23 ++ cli_snapshots/lib.rs | 39 ++++ cli_snapshots/print_hello.ts | 3 + cli_snapshots/run.py | 21 ++ deno_typescript/BUILD.gn | 21 ++ deno_typescript/Cargo.toml | 17 ++ deno_typescript/amd_runtime.js | 41 ++++ deno_typescript/compiler_main.js | 320 ++++++++++++++++++++++++++ deno_typescript/lib.deno_core.d.ts | 66 ++++++ deno_typescript/lib.rs | 350 +++++++++++++++++++++++++++++ deno_typescript/ops.rs | 159 +++++++++++++ js/blob.ts | 8 +- js/body.ts | 14 +- js/buffer.ts | 8 +- js/chmod.ts | 4 +- js/chown.ts | 4 +- js/colors.ts | 2 +- js/compiler.ts | 37 +-- js/console.ts | 10 +- js/console_table.ts | 4 +- js/copy_file.ts | 4 +- js/core.ts | 2 +- js/custom_event.ts | 6 +- js/deno.ts | 78 ++++--- js/diagnostics.ts | 2 +- js/dir.ts | 4 +- js/dispatch.ts | 4 +- js/dispatch_json.ts | 8 +- js/dispatch_minimal.ts | 4 +- js/dom_file.ts | 4 +- js/dom_util.ts | 2 +- js/error_stack.ts | 6 +- js/event.ts | 4 +- js/event_target.ts | 8 +- js/fetch.ts | 29 ++- js/file_info.ts | 2 +- js/files.ts | 8 +- js/form_data.ts | 10 +- js/format_error.ts | 4 +- js/get_random_values.ts | 6 +- js/globals.ts | 44 ++-- js/headers.ts | 6 +- js/link.ts | 4 +- js/location.ts | 8 +- js/main.ts | 27 ++- js/make_temp_dir.ts | 4 +- js/metrics.ts | 4 +- js/mixins/dom_iterable.ts | 6 +- js/mkdir.ts | 4 +- js/net.ts | 10 +- js/os.ts | 12 +- js/performance.ts | 4 +- js/permissions.ts | 4 +- js/process.ts | 14 +- js/read_dir.ts | 8 +- js/read_file.ts | 4 +- js/read_link.ts | 4 +- js/remove.ts | 4 +- js/rename.ts | 4 +- js/repl.ts | 16 +- js/request.ts | 13 +- js/resources.ts | 4 +- js/stat.ts | 6 +- js/symlink.ts | 8 +- js/text_encoding.ts | 6 +- js/timers.ts | 10 +- js/truncate.ts | 4 +- js/url.ts | 8 +- js/url_search_params.ts | 4 +- js/util.ts | 4 +- js/utime.ts | 4 +- js/workers.ts | 14 +- js/write_file.ts | 8 +- js/xeval.ts | 8 +- rollup.config.js | 231 ------------------- tools/format.py | 18 +- 87 files changed, 1612 insertions(+), 760 deletions(-) delete mode 100644 cli/build.rs delete mode 100644 cli/deno.gni create mode 100644 cli_snapshots/BUILD.gn create mode 100644 cli_snapshots/Cargo.toml create mode 100644 cli_snapshots/build.rs create mode 100644 cli_snapshots/lib.rs create mode 100644 cli_snapshots/print_hello.ts create mode 100644 cli_snapshots/run.py create mode 100644 deno_typescript/BUILD.gn create mode 100644 deno_typescript/Cargo.toml create mode 100644 deno_typescript/amd_runtime.js create mode 100644 deno_typescript/compiler_main.js create mode 100644 deno_typescript/lib.deno_core.d.ts create mode 100644 deno_typescript/lib.rs create mode 100644 deno_typescript/ops.rs delete mode 100644 rollup.config.js diff --git a/Cargo.lock b/Cargo.lock index 1ce8cc89b26614..0371698fca063f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -212,6 +212,22 @@ dependencies = [ "sct 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "deno" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "deno-x86_64-apple-darwin 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "deno-x86_64-pc-windows-msvc 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "deno-x86_64-unknown-linux-gnu 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "deno" version = "0.16.0" @@ -225,6 +241,21 @@ dependencies = [ "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "deno-x86_64-apple-darwin" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "deno-x86_64-pc-windows-msvc" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "deno-x86_64-unknown-linux-gnu" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "deno_cli" version = "0.16.0" @@ -233,6 +264,7 @@ 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", "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)", @@ -268,6 +300,23 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "deno_cli_snapshots" +version = "0.0.3" +dependencies = [ + "deno 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", + "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" @@ -484,6 +533,16 @@ dependencies = [ "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "idna" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "indexmap" version = "1.1.0" @@ -706,6 +765,11 @@ name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "percent-encoding" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "ppv-lite86" version = "0.2.5" @@ -1503,6 +1567,16 @@ dependencies = [ "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "url" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "utf8parse" version = "0.1.1" @@ -1737,6 +1811,10 @@ dependencies = [ "checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" "checksum crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04973fa96e96579258a5091af6003abde64af786b860f18622b82e026cca60e6" "checksum ct-logs 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4d3686f5fa27dbc1d76c751300376e167c5a43387f44bb451fd1c24776e49113" +"checksum deno 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8f4c3038311f8cabdd13eb37a6f186a55fc7eac511d1ae8204920fe7f0bdd68e" +"checksum deno-x86_64-apple-darwin 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ccde4d5ec90ca1696b5c844054253cbe901761e60ab26fba6b4fbb591e5e535d" +"checksum deno-x86_64-pc-windows-msvc 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a3207176cb4d5095216d4378965ac4ee299415c1ea5037910fb5002c99b8b7d9" +"checksum deno-x86_64-unknown-linux-gnu 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "99ee4c7861b8be58e11b6f1d0700f419718f235309b1338690abc8b1062ce89d" "checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3" "checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b" "checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" @@ -1758,6 +1836,7 @@ dependencies = [ "checksum hyper 0.12.33 (registry+https://github.com/rust-lang/crates.io-index)" = "7cb44cbce9d8ee4fb36e4c0ad7b794ac44ebaad924b9c8291a63215bb44c2c8f" "checksum hyper-rustls 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)" = "719d85c7df4a7f309a77d145340a063ea929dcb2e025bae46a80345cffec2952" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" +"checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum indexmap 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a4d6d89e0948bf10c08b9ecc8ac5b83f07f857ebe2c0cbe38de15b4e4f510356" "checksum integer-atomics 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5c33cd4d18b4ade167caace0e92364e8568c1e47c193738397b4b48a3e414139" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" @@ -1785,6 +1864,7 @@ dependencies = [ "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" +"checksum percent-encoding 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" "checksum ppv-lite86 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e3cbf9f658cdb5000fcf6f362b8ea2ba154b9f146a61c7a20d647034c6b6561b" "checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" "checksum proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5c2380ae88876faae57698be9e9775e3544decad214599c3a6266cca6ac802" @@ -1871,6 +1951,7 @@ dependencies = [ "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" +"checksum url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75b414f6c464c879d7f9babf951f23bc3743fb7313c081b2e6ca719067ea9d61" "checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" "checksum utime 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "055058552ca15c566082fc61da433ae678f78986a6f16957e33162d1b218792a" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" diff --git a/Cargo.toml b/Cargo.toml index 1aa1732857beb1..084258c324fcfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,6 @@ members = [ "cli", "core", "tools/hyper_hello", + "deno_typescript", + "cli_snapshots", ] diff --git a/build_extra/rust/run.py b/build_extra/rust/run.py index 7c6bea08afaa48..0d1f4264b0dd4a 100644 --- a/build_extra/rust/run.py +++ b/build_extra/rust/run.py @@ -28,6 +28,7 @@ # When building with Cargo this variable is set by build.rs. env["GN_OUT_DIR"] = os.path.abspath(".") assert os.path.isdir(env["GN_OUT_DIR"]) +env["OUT_DIR"] = os.path.abspath(".") # Environment variables can be specified on the command line using # '--env=variable=value' flags. These flags are not passed through to rustc. diff --git a/cli/BUILD.gn b/cli/BUILD.gn index 6704659db428d1..97f15a8b767888 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 = [ { @@ -11,6 +8,11 @@ main_extern = [ crate_name = "deno" crate_type = "rlib" }, + { + label = "../cli_snapshots:deno_cli_snapshots" + crate_name = "deno_cli_snapshots" + crate_type = "rlib" + }, { label = "$rust_build:serde_derive" crate_name = "serde_derive" @@ -60,109 +62,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) ], @@ -172,9 +71,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 @@ -189,9 +85,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 = [ @@ -199,31 +92,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 e1597b799ed422..d3b9aaecb46ded 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -51,6 +51,7 @@ tokio-rustls = "0.10.0" tokio-threadpool = "0.1.15" url = "1.7.2" utime = "0.2.1" +deno_cli_snapshots = { path = "../cli_snapshots" } [target.'cfg(windows)'.dependencies] winapi = "0.3.7" diff --git a/cli/build.rs b/cli/build.rs deleted file mode 100644 index 55451e6b73f032..00000000000000 --- 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 dabcd43caa9ffa..00000000000000 --- 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/source_maps.rs b/cli/source_maps.rs index 5a34041c55601c..0898feb9279f9b 100644 --- a/cli/source_maps.rs +++ b/cli/source_maps.rs @@ -73,22 +73,12 @@ fn builtin_source_map(_: &str) -> Option> { #[cfg(not(feature = "check-only"))] fn builtin_source_map(script_name: &str) -> Option> { - 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") { + return 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 } } diff --git a/cli/startup_data.rs b/cli/startup_data.rs index e7d0a08a861b2f..593859be73fb90 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 00000000000000..f5f85940686edd --- /dev/null +++ b/cli_snapshots/BUILD.gn @@ -0,0 +1,124 @@ +import("//build_extra/rust/rust.gni") + +rust_rlib("deno_cli_snapshots") { + source_root = "lib.rs" + 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.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", +] + +action("deno_cli_snapshots_build_run") { + script = "run.py" + inputs = ts_sources + outputs = [ + "$target_out_dir/CLI_SNAPSHOT", + "$target_out_dir/CLI_SNAPSHOT.js", + "$target_out_dir/CLI_SNAPSHOT.js.map", + "$target_out_dir/CLI_SNAPSHOT.d.ts", + "$target_out_dir/COMPILER_SNAPSHOT", + "$target_out_dir/COMPILER_SNAPSHOT.js", + "$target_out_dir/COMPILER_SNAPSHOT.js.map", + "$target_out_dir/COMPILER_SNAPSHOT.d.ts", + ] + args = [ + rebase_path("$root_out_dir/deno_cli_snapshots_build"), + rebase_path(".", root_build_dir), + rebase_path(root_out_dir), + ] + 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 00000000000000..5c151eb1948f26 --- /dev/null +++ b/cli_snapshots/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "deno_cli_snapshots" +version = "0.0.3" +license = "MIT" +authors = ["Ryan Dahl "] +edition = "2018" +description = "Provides snapshots for the deno CLI" +repository = "https://github.com/ry/deno_typescript" +readme = "../README.md" + +[lib] +path = "lib.rs" + +[dev-dependencies] +deno = "0.15.0" + +[build-dependencies] +deno_typescript = { path = "../deno_typescript", version = "0.0.3" } + diff --git a/cli_snapshots/build.rs b/cli_snapshots/build.rs new file mode 100644 index 00000000000000..e9d9c2f937ff52 --- /dev/null +++ b/cli_snapshots/build.rs @@ -0,0 +1,23 @@ +use std::env; +use std::path::PathBuf; + +fn main() { + // 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, "CLI_SNAPSHOT", 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, "COMPILER_SNAPSHOT", state) + .unwrap(); +} diff --git a/cli_snapshots/lib.rs b/cli_snapshots/lib.rs new file mode 100644 index 00000000000000..691daaf6143a6b --- /dev/null +++ b/cli_snapshots/lib.rs @@ -0,0 +1,39 @@ +pub static CLI_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT")); +pub static CLI_SNAPSHOT_MAP: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/CLI_SNAPSHOT.js.map")); + +pub static COMPILER_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT")); +pub static COMPILER_SNAPSHOT_MAP: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.js.map")); + +#[test] +fn cli_snapshot() { + let mut isolate = + deno::Isolate::new(deno::StartupData::Snapshot(CLI_SNAPSHOT), false); + deno::js_check(isolate.execute( + "", + 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( + "", + r#" + if (!compilerMain) { + throw Error("bad"); + } + console.log(`ts version: ${ts.version}`); + "#, + )); +} diff --git a/cli_snapshots/print_hello.ts b/cli_snapshots/print_hello.ts new file mode 100644 index 00000000000000..470e0bfc1765d5 --- /dev/null +++ b/cli_snapshots/print_hello.ts @@ -0,0 +1,3 @@ +export function printHello(): void { + Deno.core.print("hello\n"); +} diff --git a/cli_snapshots/run.py b/cli_snapshots/run.py new file mode 100644 index 00000000000000..96368eba72c759 --- /dev/null +++ b/cli_snapshots/run.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python +# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license. +# This file just executes its arguments, except that also adds GN_OUT_DIR and +# CARGO_PKG_VERSION to the environ. This is for compatibility with cargo. +import subprocess +import sys +import os +import re + +exe = sys.argv[1] +d = sys.argv[2] +root_out_dir = sys.argv[3] + +assert os.path.exists(exe) + +env = os.environ.copy() +env["CARGO_MANIFEST_DIR"] = os.path.abspath(d) +env["OUT_DIR"] = root_out_dir + +os.chdir(d) +sys.exit(subprocess.call([exe, "foo"], env=env)) diff --git a/deno_typescript/BUILD.gn b/deno_typescript/BUILD.gn new file mode 100644 index 00000000000000..3d361df6dbab63 --- /dev/null +++ b/deno_typescript/BUILD.gn @@ -0,0 +1,21 @@ +import("//build_extra/rust/rust.gni") + +rust_rlib("deno_typescript") { + source_root = "lib.rs" + 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 00000000000000..4cfa6f9ce824ad --- /dev/null +++ b/deno_typescript/Cargo.toml @@ -0,0 +1,17 @@ +[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" +readme = "../README.md" +authors = ["Ryan Dahl "] +edition = "2018" + +[lib] +path = "lib.rs" + +[dependencies] +deno = { version = "0.16.0", path = "../core" } +serde_json = "1.0" +serde = { version = "1.0", features = ["derive"] } diff --git a/deno_typescript/amd_runtime.js b/deno_typescript/amd_runtime.js new file mode 100644 index 00000000000000..f0c0c0c576df66 --- /dev/null +++ b/deno_typescript/amd_runtime.js @@ -0,0 +1,41 @@ +// 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 => { + // println("globalRequire"); + return createOrLoadModule(name).exports; + }; + + define = (name, deps, factory) => { + const currentModule = createOrLoadModule(name); + const localExports = currentModule.exports; + // println("localDefine", name, deps, localExports); + 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 00000000000000..5b0ca76c557b4d --- /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$"; + +function main(configText, rootNames) { + println(`>>> ts version ${ts.version}`); + println(`>>> rootNames ${rootNames}`); + 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; + /* + // TS5055: Cannot write file + // 'http://localhost:4545/tests/subdir/mt_application_x_javascript.j4.js' + // because it would overwrite input file. + if (code === 5055) return false; + // TypeScript is overly opinionated that only CommonJS modules kinds can + // support JSON imports. Allegedly this was fixed in + // Microsoft/TypeScript#26825 but that doesn't seem to be working here, + // so we will ignore complaints about this compiler setting. + if (code === 5070) 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); + // println(`encode ${ui8}`); + return ui8; +} + +const ops = { + readFile: 49, + exit: 50, + writeFile: 51, + resolveModuleNames: 52, + setEmitResult: 53 +}; + +// interface CompilerHost extends ModuleResolutionHost { +class Host { + // fileExists(fileName: string): boolean; + fileExists(fileName) { + println(`fileExists ${fileName}`); + return true; + // unreachable(); + } + + // 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;", ""); + } + + 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 + ): 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, excludes: ReadonlyArray | undefined, includes: ReadonlyArray, 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 { + // return msg.MediaType.Unknown: + throw TypeError(`Cannot resolve extension for ${fileName}`); + } +} diff --git a/deno_typescript/lib.deno_core.d.ts b/deno_typescript/lib.deno_core.d.ts new file mode 100644 index 00000000000000..18583fadd30554 --- /dev/null +++ b/deno_typescript/lib.deno_core.d.ts @@ -0,0 +1,66 @@ +// 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; + // Was the error happened during compilation? + isCompileError: boolean; + // The actual thrown entity + // (might be an Error or anything else thrown by the user) + // If isNativeError is true, this is an Error + // eslint-disable-next-line @typescript-eslint/no-explicit-any + thrown: any; +} + +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( + opId: number, + control: null | ArrayBufferView, + data?: ArrayBufferView + ): null | Uint8Array; + + print(x: string, isErr?: boolean): void; + + shared: SharedArrayBuffer; + + /** Evaluate provided code in the current context. + * It differs from eval(...) in that it does not create a new context. + * Returns an array: [output, errInfo]. + * If an error occurs, `output` becomes null and `errInfo` is non-null. + */ + // eslint-disable-next-line @typescript-eslint/no-explicit-any + evalContext(code: string): [any, EvalErrorInfo | null]; + + 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 00000000000000..771ad7805ea2c0 --- /dev/null +++ b/deno_typescript/lib.rs @@ -0,0 +1,350 @@ +extern crate deno; +extern crate serde; +extern crate serde_json; + +mod ops; +use deno::deno_mod; +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; + +/// 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]); +} + +#[derive(Debug)] +pub struct TSState { + bundle: bool, + exit_code: i32, + + emit_result: Option, + // (url, corresponding_module, source_code) + written_files: Vec, +} + +pub struct TSIsolate { + isolate: Isolate, + state: Arc>, +} + +static TYPESCRIPT_CODE: &str = + include_str!("../third_party/node_modules/typescript/lib/typescript.js"); + +impl TSIsolate { + fn new(bundle: bool) -> TSIsolate { + let mut isolate = Isolate::new(StartupData::None, false); + let main_code = include_str!("compiler_main.js"); + js_check(isolate.execute("assets/typescript.js", TYPESCRIPT_CODE)); + js_check(isolate.execute("compiler_main.js", main_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>, ErrBox>, return something + // like Result. 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, + ) -> Result>, ErrBox> { + let root_names_json = serde_json::json!(root_names).to_string(); + let source = + &format!("main({:?}, {})", config_json.to_string(), root_names_json); + self.isolate.execute("", source)?; + Ok(self.state.clone()) + } +} + +// TODO(ry) Instead of Result>, ErrBox>, return something +// like Result +pub fn compile( + root_names: Vec, +) -> Result>, ErrBox> { + let ts_isolate = TSIsolate::new(false); + + let config_json = serde_json::json!({ + "compilerOptions": { + "declaration": true, + "lib": ["esnext"], + "module": "esnext", + "target": "esnext", + "listFiles": true, + "listEmittedFiles": true, + // Emit the source alongside the sourcemaps within a single file; + // requires --inlineSourceMap or --sourceMap to be set. + // "inlineSources": true, + "sourceMap": true, + }, + }); + + let mut root_names_str: Vec = root_names + .iter() + .map(|p| { + assert!(p.exists()); + p.to_string_lossy().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) +} + +pub fn compile_bundle( + bundle: &Path, + root_names: Vec, +) -> Result>, 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 = 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() + // p.to_string_lossy().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; + } +} + +pub fn mksnapshot_bundle( + bundle: &Path, + env_var: &str, + state: Arc>, +) -> 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", include_str!("amd_runtime.js")), + ); + + js_check(runtime_isolate.execute("bundle", &source_code)); + + // execute main. + + let state = state.lock().unwrap(); + let main = state.written_files.last().unwrap().module_name.clone(); + // let main = "file:///Users/rld/src/deno_typescript/cli_snapshots/js/main.ts"; + js_check(runtime_isolate.execute("anon", &format!("require('{}')", main))); + + snapshot_to_env(runtime_isolate, env_var)?; + + Ok(()) +} + +pub fn mksnapshot_bundle_ts( + bundle: &Path, + env_var: &str, + state: Arc>, +) -> 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", include_str!("amd_runtime.js")), + ); + js_check(runtime_isolate.execute(&bundle.to_string_lossy(), &source_code)); + + let state = state.lock().unwrap(); + let main = state.written_files.last().unwrap().module_name.clone(); + + js_check(runtime_isolate.execute("typescript.js", TYPESCRIPT_CODE)); + js_check(runtime_isolate.execute("anon", &format!("require('{}')", main))); + + snapshot_to_env(runtime_isolate, env_var)?; + + Ok(()) +} + +// TODO(ry) Instead of state: Arc>, take something like state: +// &TSState +pub fn mksnapshot( + env_var: &str, + state: Arc>, +) -> Result<(), ErrBox> { + assert!(!state.lock().unwrap().bundle); + + let mut runtime_isolate = Isolate::new(StartupData::None, true); + let mut url2id: HashMap = HashMap::new(); + let mut id2url: HashMap = HashMap::new(); + + let state = state.lock().unwrap(); + + let main = state.written_files.last().unwrap().module_name.clone(); + + for f in state.written_files.iter() { + if f.url.ends_with(".js") { + let is_main = f.module_name == main; + let id = + js_check(runtime_isolate.mod_new(is_main, &f.url, &f.source_code)); + url2id.insert(f.module_name.clone(), id); + id2url.insert(id, f.module_name.clone()); + + if f.url.ends_with("flatbuffers/flatbuffers.js") { + print_source_code(&f.source_code); + } + } + } + + let url2id_ = url2id.clone(); // FIXME + let mut resolve = move |specifier: &str, referrer: deno_mod| -> deno_mod { + let referrer_url = id2url.get(&referrer).unwrap(); + let import_url = + ModuleSpecifier::resolve_import(specifier, referrer_url.as_str()) + .unwrap(); + let import_url_str = import_url.as_str(); + *url2id_.get(import_url_str).unwrap_or_else(|| { + panic!("Could not resolve {}", import_url_str); + }) + }; + + // Instantiate each module. + for (_url, id) in url2id.iter() { + js_check(runtime_isolate.mod_instantiate(*id, &mut resolve)); + } + + // Execute the main module. + let main_id = url2id.get(main.as_str()).unwrap(); + js_check(runtime_isolate.mod_evaluate(*main_id)); + + snapshot_to_env(runtime_isolate, env_var)?; + Ok(()) +} + +fn snapshot_to_env( + runtime_isolate: Isolate, + env_var: &str, +) -> 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 out_dir = PathBuf::from(std::env::var_os("OUT_DIR").unwrap()); + let snapshot_path = out_dir.join(env_var); + + fs::write(&snapshot_path, snapshot_slice)?; + println!("snapshot path {} ", snapshot_path.display()); + println!("cargo:rustc-env={}={}", env_var, snapshot_path.display()); + Ok(()) +} + +macro_rules! inc { + ($e:expr) => { + include_str!(concat!("../third_party/node_modules/typescript/lib/", $e)) + }; +} + +pub fn get_asset(asset: &str) -> String { + String::from(match asset { + "lib.deno_core.d.ts" => 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"), + _ => panic!("Unknown asset {}", asset), + }) +} diff --git a/deno_typescript/ops.rs b/deno_typescript/ops.rs new file mode 100644 index 00000000000000..d410d09735e2f0 --- /dev/null +++ b/deno_typescript/ops.rs @@ -0,0 +1,159 @@ +use crate::get_asset; +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 { + let v = serde_json::from_slice(control_buf)?; + 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.to_string().into_bytes(); + Op::Sync(vec.into_boxed_slice()) +} + +#[derive(Debug, Deserialize)] +#[serde(rename_all = "camelCase")] +struct ReadFile { + file_name: String, + language_version: Option, + should_create_new_source_file: bool, +} + +fn read_file(_s: &mut TSState, v: Value) -> Result { + 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 = get_asset(&asset); + (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 { + 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, + containing_file: String, +} + +fn resolve_module_names(_s: &mut TSState, v: Value) -> Result { + let v: ResolveModuleNames = serde_json::from_value(v).unwrap(); + let mut resolved = Vec::::new(); + + /* + use std::path::Path; + let referrer = Path::new(&v.containing_file).parent().unwrap(); + for specifier in v.module_names { + let s = referrer.join(specifier); + resolved.push(s.to_string_lossy().to_string()); + } + */ + + /* TODO Using ModuleSpecifier and URLs results in + + TS5009: Cannot find the common subdirectory path for the input files. + + If that error disabled/ignored, then the writeFile orders are issued to + write them as neighbors. + */ + + 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 { + 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, + pub emitted_files: Vec, // "sourceMaps": [] +} + +fn set_emit_result(s: &mut TSState, v: Value) -> Result { + 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 94d03c97f53dc4..4c86f1f24a6a0b 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 b1f1af8a57b74c..0eb0248c0b61eb 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; @@ -17,7 +17,6 @@ export type BodySource = | domTypes.BufferSource | domTypes.FormData | domTypes.URLSearchParams - | domTypes.ReadableStream | string; function validateBodyType(owner: Body, bodySource: BodySource): boolean { @@ -81,9 +80,6 @@ export class Body implements domTypes.Body { if (this._stream) { return this._stream; } - if (typeof this._bodySource === "string") { - throw Error("not implemented"); - } return this._stream; } diff --git a/js/buffer.ts b/js/buffer.ts index 9525e6954fc3e2..dc73b7e60e1db8 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/chmod.ts b/js/chmod.ts index 23b3dff25f7d6d..7bf54cc5ba06aa 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 6bfddab98fe193..a8bad119342fef 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 ab89af81cd417e..566a7922ae3f59 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 "./os.ts"; interface Code { open: string; diff --git a/js/compiler.ts b/js/compiler.ts index 71b1b06c9ea7ea..593fc7ed5eb7de 100644 --- a/js/compiler.ts +++ b/js/compiler.ts @@ -1,20 +1,24 @@ // 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"; + +/// + +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! @@ -34,6 +38,7 @@ window.workerMain = workerMain; export default 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 db6a87296add11..2ce4b20cdd8417 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; type ConsoleOptions = Partial<{ diff --git a/js/console_table.ts b/js/console_table.ts index d4a404aa139143..d74dc012777516 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 b299a52bc556cf..94d2b63db93c70 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 436ba7ccbe0c25..d394d822fda135 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 5f9e413fba3780..67668bbb74ae6d 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 65a93c467ac06f..5adb620bdfe103 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 { noColor, pid, 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,23 @@ 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"; diff --git a/js/diagnostics.ts b/js/diagnostics.ts index 1207eca4fd7c57..4085d31fe1fd81 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"; +/// /** The log category for a diagnostic message */ export enum DiagnosticCategory { diff --git a/js/dir.ts b/js/dir.ts index f2cf91c21bbb14..ef111155549960 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 af91a9b9ef873e..1a60a536339b74 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 8ec924f4c3defa..572ec855a06b7d 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_minimal.ts b/js/dispatch_minimal.ts index 75514368c96539..98636f85b47b02 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>(); // 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 88d8ba4a9af0b1..1340da1251d218 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 7a5dc80b94b971..85a33fad1c7dae 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 7d41b9cf4a59aa..98b0b02d499856 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/event.ts b/js/event.ts index 222b562a25d684..72392605408560 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 e376e78a1c576d..96ce8e2a89b430 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 317239630a31f3..a8a811878e7546 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 { const params = new Map(); diff --git a/js/file_info.ts b/js/file_info.ts index c124e06bfdf1cb..a98989e796b3a5 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 0335056b331722..98d18f0cf9e658 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 3c40e64d3a3ade..f5ae290eb2371d 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 dde0f6a583b3be..801da0d0b9a40b 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 154e77f753dbb1..e54f347858afa2 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 b47cd80f35d8fc..cd7326939a2a07 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 diff --git a/js/headers.ts b/js/headers.ts index e31c0903ea4e8c..dc0de54dd0192f 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 f6c6530b2469e6..a6f732926ec9af 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 535a2bceab8d84..d495f99ca56c66 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 25e27b69fe9479..adffad5f3c9365 100644 --- a/js/main.ts +++ b/js/main.ts @@ -3,20 +3,22 @@ // eslint-disable-next-line @typescript-eslint/no-triple-slash-reference /// -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"; +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"; // builtin modules -import * as deno from "./deno"; +import * as deno from "./deno.ts"; + +const { console } = window; export default function denoMain( preserveDenoNamespace: boolean = true, @@ -55,3 +57,4 @@ export default function denoMain( replLoop(); } } +window["denoMain"] = denoMain; diff --git a/js/make_temp_dir.ts b/js/make_temp_dir.ts index 5e0a28205a212b..14494b5da27982 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 48e3102e529ff4..b32c2978979696 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 97e8133ec0e3a1..bbd1905ceea38f 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 = new (...args: any[]) => T; diff --git a/js/mkdir.ts b/js/mkdir.ts index 54f99224bda3aa..bc09ba35871375 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 809dd40929f56d..b0651b32614726 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 c44c2782551081..1e054b43ac80b8 100644 --- a/js/os.ts +++ b/js/os.ts @@ -1,10 +1,10 @@ // 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; diff --git a/js/performance.ts b/js/performance.ts index d2f339c467a937..6ea8e56e1261f7 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 bc969f3a83577d..4f393501c6a895 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/process.ts b/js/process.ts index dd4f70103523f2..4de9fe77414b23 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 27d011a089d647..2fa6a566b1965c 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 1ca52e2769af85..de6630cc058b86 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 fae1e64b6f5791..861fbff0bc7147 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 f2a94f395359aa..36413a7c45029e 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 80794747d6ea7c..c906ce37bd4934 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 ac67006576fb2e..5b22326172eb57 100644 --- a/js/repl.ts +++ b/js/repl.ts @@ -1,12 +1,12 @@ // 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"; /** * REPL logging. diff --git a/js/request.ts b/js/request.ts index 5ed1e9d634cfc3..3e1c45b0c2e649 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; @@ -50,17 +50,14 @@ export class Request extends body.Body implements domTypes.Request { // prefer body from init if (init.body) { - b = init.body; + throw Error("not implemented"); } else if (input instanceof Request && input._bodySource) { if (input.bodyUsed) { throw TypeError(body.BodyUsedError); } b = input._bodySource; } else if (typeof input === "object" && "body" in input && input.body) { - if (input.bodyUsed) { - throw TypeError(body.BodyUsedError); - } - b = input.body; + throw Error("not implemented"); } else { b = ""; } diff --git a/js/resources.ts b/js/resources.ts index 6e2ec202b764b6..27598ce099ade5 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 1cc8d070a9388b..1f53e6f7bec831 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 6fd2e90a589507..4418e22ceb1889 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 830b4278e030b4..5aed7ac07d79ab 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 4b8596cb7c12cb..8aec33d92b55d4 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 c6e5b3ad089657..5ce7b5158836ce 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 6520af83489a9c..334d1c09bc590e 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 8e122191d4fdf6..63c02d3b837658 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 da56465a2c7b71..86a85617015336 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 c71710458bcf0b..7495378b1dbb09 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/workers.ts b/js/workers.ts index 7bcbe6279adbb3..36c2aa50b47649 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 c7b71725c87d81..d6307e0029c2c1 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 fa706ae2069429..2ef90ce29f28c4 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/rollup.config.js b/rollup.config.js deleted file mode 100644 index cc583c59c79914..00000000000000 --- 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/tools/format.py b/tools/format.py index c7465516a2ee7d..aa2208b01a7415 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)