diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2019-11-14 02:35:56 +1100 |
---|---|---|
committer | Ry Dahl <ry@tinyclouds.org> | 2019-11-13 10:35:56 -0500 |
commit | 8d03397293b388317299dfb0648b541a7005807d (patch) | |
tree | 38aeb4deb371e81f47b6750110d96de46b9f5b05 /cli/compilers/ts.rs | |
parent | ee1b8dc883db1531d913f7b10a8d1160f3209d93 (diff) |
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.
Diffstat (limited to 'cli/compilers/ts.rs')
-rw-r--r-- | cli/compilers/ts.rs | 27 |
1 files changed, 20 insertions, 7 deletions
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<String>, compiler_config: CompilerConfig, - bundle: Option<String>, + out_file: Option<String>, ) -> 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<String>, ) -> impl Future<Item = (), Error = ErrBox> { 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()); |