From 8d03397293b388317299dfb0648b541a7005807d Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Thu, 14 Nov 2019 02:35:56 +1100 Subject: Make bundles fully standalone (#3325) - Bundles are fully standalone. They now include the shared loader with `deno_typescript`. - Refactor of the loader in `deno_typescript` to perform module instantiation in a more - Change of behaviour when an output file is not specified on the CLI. Previously a default name was determined and the bundle written to that file, now the bundle will be sent to `stdout`. - Refactors in the TypeScript compiler to be able to support the concept of a request type. This provides a cleaner abstraction and makes it easier to support things like single module transpiles to the userland. - Remove a "dangerous" circular dependency between `os.ts` and `deno.ts`, and define `pid` and `noColor` in a better way. - Don't bind early to `console` in `repl.ts`. - Add an integration test for generating a bundle. --- deno_typescript/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'deno_typescript/lib.rs') diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs index d130ee4c6..509bce56f 100644 --- a/deno_typescript/lib.rs +++ b/deno_typescript/lib.rs @@ -22,7 +22,7 @@ use std::sync::Mutex; static TYPESCRIPT_CODE: &str = include_str!("typescript/lib/typescript.js"); static COMPILER_CODE: &str = include_str!("compiler_main.js"); -static AMD_RUNTIME_CODE: &str = include_str!("amd_runtime.js"); +static BUNDLE_LOADER: &str = include_str!("bundle_loader.js"); pub fn ts_version() -> String { let data = include_str!("typescript/package.json"); @@ -181,11 +181,13 @@ pub fn mksnapshot_bundle( let source_code_vec = std::fs::read(bundle)?; let source_code = std::str::from_utf8(&source_code_vec)?; - js_check(runtime_isolate.execute("amd_runtime.js", AMD_RUNTIME_CODE)); + js_check(runtime_isolate.execute("bundle_loader.js", BUNDLE_LOADER)); js_check(runtime_isolate.execute(&bundle.to_string_lossy(), &source_code)); let main = state.lock().unwrap().main_module_name(); - js_check(runtime_isolate.execute("anon", &format!("require('{}')", main))); + js_check( + runtime_isolate.execute("anon", &format!("instantiate('{}')", main)), + ); write_snapshot(runtime_isolate, bundle)?; @@ -202,12 +204,14 @@ pub fn mksnapshot_bundle_ts( let source_code_vec = std::fs::read(bundle)?; let source_code = std::str::from_utf8(&source_code_vec)?; - js_check(runtime_isolate.execute("amd_runtime.js", AMD_RUNTIME_CODE)); + js_check(runtime_isolate.execute("bundle_loader.js", BUNDLE_LOADER)); js_check(runtime_isolate.execute("typescript.js", TYPESCRIPT_CODE)); js_check(runtime_isolate.execute(&bundle.to_string_lossy(), &source_code)); let main = state.lock().unwrap().main_module_name(); - js_check(runtime_isolate.execute("anon", &format!("require('{}')", main))); + js_check( + runtime_isolate.execute("anon", &format!("instantiate('{}')", main)), + ); write_snapshot(runtime_isolate, bundle)?; @@ -249,6 +253,7 @@ pub fn get_asset(name: &str) -> Option<&'static str> { }; } match name { + "bundle_loader.js" => Some(include_str!("bundle_loader.js")), "lib.deno_core.d.ts" => Some(include_str!("lib.deno_core.d.ts")), "typescript.d.ts" => inc!("typescript.d.ts"), "lib.esnext.d.ts" => inc!("lib.esnext.d.ts"), -- cgit v1.2.3