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. --- cli/compilers/ts.rs | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'cli/compilers/ts.rs') diff --git a/cli/compilers/ts.rs b/cli/compilers/ts.rs index 327b3fbeb..cac382659 100644 --- a/cli/compilers/ts.rs +++ b/cli/compilers/ts.rs @@ -156,20 +156,23 @@ impl CompiledFileMetadata { } /// Creates the JSON message send to compiler.ts's onmessage. fn req( + request_type: msg::CompilerRequestType, root_names: Vec, compiler_config: CompilerConfig, - bundle: Option, + out_file: Option, ) -> Buf { let j = match (compiler_config.path, compiler_config.content) { (Some(config_path), Some(config_data)) => json!({ + "type": request_type as i32, "rootNames": root_names, - "bundle": bundle, + "outFile": out_file, "configPath": config_path, "config": str::from_utf8(&config_data).unwrap(), }), _ => json!({ + "type": request_type as i32, "rootNames": root_names, - "bundle": bundle, + "outFile": out_file, }), }; @@ -250,7 +253,7 @@ impl TsCompiler { self: &Self, global_state: ThreadSafeGlobalState, module_name: String, - out_file: String, + out_file: Option, ) -> impl Future { debug!( "Invoking the compiler to bundle. module_name: {}", @@ -258,7 +261,12 @@ impl TsCompiler { ); let root_names = vec![module_name.clone()]; - let req_msg = req(root_names, self.config.clone(), Some(out_file)); + let req_msg = req( + msg::CompilerRequestType::Bundle, + root_names, + self.config.clone(), + out_file, + ); let worker = TsCompiler::setup_worker(global_state.clone()); let worker_ = worker.clone(); @@ -360,7 +368,12 @@ impl TsCompiler { ); let root_names = vec![module_url.to_string()]; - let req_msg = req(root_names, self.config.clone(), None); + let req_msg = req( + msg::CompilerRequestType::Compile, + root_names, + self.config.clone(), + None, + ); let worker = TsCompiler::setup_worker(global_state.clone()); let worker_ = worker.clone(); @@ -709,7 +722,7 @@ mod tests { .bundle_async( state.clone(), module_name, - String::from("$deno$/bundle.js"), + Some(String::from("$deno$/bundle.js")), ) .then(|result| { assert!(result.is_ok()); -- cgit v1.2.3