mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
feat: add lockfile support to bundle (#6624)
This commit is contained in:
parent
61d9952ff9
commit
14a44464a6
5 changed files with 63 additions and 0 deletions
26
cli/flags.rs
26
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)
|
||||
|
@ -2109,6 +2112,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![
|
||||
|
|
|
@ -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",
|
||||
|
|
5
cli/tests/lock_check_err_with_bundle.json
Normal file
5
cli/tests/lock_check_err_with_bundle.json
Normal file
|
@ -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"
|
||||
}
|
3
cli/tests/lock_check_err_with_bundle.out
Normal file
3
cli/tests/lock_check_err_with_bundle.out
Normal file
|
@ -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
|
22
cli/tsc.rs
22
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");
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue