diff options
author | Takahiko Inayama <sagittariusm25@gmail.com> | 2020-07-07 20:05:28 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-07 13:05:28 +0200 |
commit | 14a44464a6e2c078fd329c26eff2ecfbc9b58603 (patch) | |
tree | 236bd6af3f692f56c5c34fd7f7449de9e9e7a005 | |
parent | 61d9952ff93d8dff26f6f3adb955affe09a951bc (diff) |
feat: add lockfile support to bundle (#6624)
-rw-r--r-- | cli/flags.rs | 26 | ||||
-rw-r--r-- | cli/tests/integration_tests.rs | 7 | ||||
-rw-r--r-- | cli/tests/lock_check_err_with_bundle.json | 5 | ||||
-rw-r--r-- | cli/tests/lock_check_err_with_bundle.out | 3 | ||||
-rw-r--r-- | cli/tsc.rs | 22 |
5 files changed, 63 insertions, 0 deletions
diff --git a/cli/flags.rs b/cli/flags.rs index bcc04d94d..b78dc646a 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -381,6 +381,7 @@ fn bundle_parse(flags: &mut Flags, matches: &clap::ArgMatches) { config_arg_parse(flags, matches); importmap_arg_parse(flags, matches); unstable_arg_parse(flags, matches); + lock_args_parse(flags, matches); let source_file = matches.value_of("source_file").unwrap().to_string(); @@ -720,6 +721,8 @@ These must be added to the path manually if required.") fn bundle_subcommand<'a, 'b>() -> App<'a, 'b> { SubCommand::with_name("bundle") + .arg(lock_arg()) + .arg(lock_write_arg()) .arg( Arg::with_name("source_file") .takes_value(true) @@ -2110,6 +2113,29 @@ mod tests { } #[test] + fn bundle_with_lock() { + let r = flags_from_vec_safe(svec![ + "deno", + "bundle", + "--lock-write", + "--lock=lock.json", + "source.ts" + ]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Bundle { + source_file: "source.ts".to_string(), + out_file: None, + }, + lock_write: true, + lock: Some("lock.json".to_string()), + ..Flags::default() + } + ); + } + + #[test] fn run_importmap() { let r = flags_from_vec_safe(svec![ "deno", diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index 651ffa110..562c25de2 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -1629,6 +1629,13 @@ itest!(lock_check_err2 { http_server: true, }); +itest!(lock_check_err_with_bundle { + args: "bundle --lock=lock_check_err_with_bundle.json http://127.0.0.1:4545/cli/tests/subdir/mod1.ts", + output: "lock_check_err_with_bundle.out", + exit_code: 10, + http_server: true, +}); + itest!(async_error { exit_code: 1, args: "run --reload async_error.ts", diff --git a/cli/tests/lock_check_err_with_bundle.json b/cli/tests/lock_check_err_with_bundle.json new file mode 100644 index 000000000..ae8f9dd9d --- /dev/null +++ b/cli/tests/lock_check_err_with_bundle.json @@ -0,0 +1,5 @@ +{ + "http://127.0.0.1:4545/cli/tests/subdir/mod1.ts": "f627f1649f9853adfa096241ae2defa75e4e327cbeb6af0e82a11304b3e5c8be", + "http://127.0.0.1:4545/cli/tests/subdir/print_hello.ts": "fe7bbccaedb6579200a8b582f905139296402d06b1b91109d6e12c41a23125da", + "http://127.0.0.1:4545/cli/tests/subdir/subdir2/mod2.ts": "bad" +} diff --git a/cli/tests/lock_check_err_with_bundle.out b/cli/tests/lock_check_err_with_bundle.out new file mode 100644 index 000000000..ce0e029ef --- /dev/null +++ b/cli/tests/lock_check_err_with_bundle.out @@ -0,0 +1,3 @@ +[WILDCARD] +Subresource integrity check failed --lock=lock_check_err_with_bundle.json +http://127.0.0.1:4545/cli/tests/subdir/subdir2/mod2.ts diff --git a/cli/tsc.rs b/cli/tsc.rs index 0d61e2e72..9f8216e52 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -625,6 +625,28 @@ impl TsCompiler { .add_to_graph(&module_specifier, None) .await?; let module_graph = module_graph_loader.get_graph(); + let module_graph_files = module_graph.values().collect::<Vec<_>>(); + // Check integrity of every file in module graph + if let Some(ref lockfile) = global_state.lockfile { + let mut g = lockfile.lock().unwrap(); + + for graph_file in &module_graph_files { + let check_passed = + g.check_or_insert(&graph_file.url, &graph_file.source_code); + + if !check_passed { + eprintln!( + "Subresource integrity check failed --lock={}\n{}", + g.filename, graph_file.url + ); + std::process::exit(10); + } + } + } + if let Some(ref lockfile) = global_state.lockfile { + let g = lockfile.lock().unwrap(); + g.write()?; + } let module_graph_json = serde_json::to_value(module_graph).expect("Failed to serialize data"); |