From 2cd3994902fb6a4d4d0603c839a78503d792b96a Mon Sep 17 00:00:00 2001 From: Tim Ermilov Date: Fri, 31 Jan 2020 22:07:37 +0100 Subject: [PATCH] Add support for multiple files in fetch command (#3845) --- cli/flags.rs | 29 +++++++++++++++++++++++++---- cli/lib.rs | 14 ++++++++++++++ cli/tests/037_fetch_multiple.out | 5 +++++ cli/tests/fetch/other.ts | 1 + cli/tests/fetch/test.ts | 1 + cli/tests/integration_tests.rs | 7 +++++++ 6 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 cli/tests/037_fetch_multiple.out create mode 100644 cli/tests/fetch/other.ts create mode 100644 cli/tests/fetch/test.ts diff --git a/cli/flags.rs b/cli/flags.rs index 1eda8765..a0d322e5 100644 --- a/cli/flags.rs +++ b/cli/flags.rs @@ -401,8 +401,10 @@ fn fetch_parse(flags: &mut DenoFlags, matches: &clap::ArgMatches) { importmap_arg_parse(flags, matches); config_arg_parse(flags, matches); no_remote_arg_parse(flags, matches); - if let Some(file) = matches.value_of("file") { - flags.argv.push(file.into()); + if let Some(files) = matches.values_of("file") { + for file in files { + flags.argv.push(file.into()); + } } } @@ -525,7 +527,7 @@ fn fmt_subcommand<'a, 'b>() -> App<'a, 'b> { deno fmt deno fmt myfile1.ts myfile2.ts - + deno fmt --check", ) .arg( @@ -669,7 +671,12 @@ fn fetch_subcommand<'a, 'b>() -> App<'a, 'b> { .arg(importmap_arg()) .arg(config_arg()) .arg(no_remote_arg()) - .arg(Arg::with_name("file").takes_value(true).required(true)) + .arg( + Arg::with_name("file") + .takes_value(true) + .required(true) + .min_values(1), + ) .about("Fetch the dependencies") .long_about( "Fetch and compile remote dependencies recursively. @@ -1683,6 +1690,20 @@ mod tests { ); } + #[test] + fn fetch_multiple() { + let r = + flags_from_vec_safe(svec!["deno", "fetch", "script.ts", "script_two.ts"]); + assert_eq!( + r.unwrap(), + DenoFlags { + subcommand: DenoSubcommand::Fetch, + argv: svec!["deno", "script.ts", "script_two.ts"], + ..DenoFlags::default() + } + ); + } + #[test] fn run_seed() { let r = diff --git a/cli/lib.rs b/cli/lib.rs index 227dcdb4..42f5bbad 100644 --- a/cli/lib.rs +++ b/cli/lib.rs @@ -303,6 +303,8 @@ async fn install_command( } async fn fetch_command(flags: DenoFlags) { + let args = flags.argv.clone(); + let (mut worker, state) = create_worker_and_state(flags); let main_module = state.main_module.as_ref().unwrap().clone(); @@ -313,6 +315,18 @@ async fn fetch_command(flags: DenoFlags) { let result = worker.execute_mod_async(&main_module, None, true).await; js_check(result); + + // resolve modules for rest of args if present + let files_len = args.len(); + if files_len > 2 { + for next_specifier in args.iter().take(files_len).skip(2) { + let next_module = + ModuleSpecifier::resolve_url_or_path(&next_specifier).unwrap(); + let result = worker.execute_mod_async(&next_module, None, true).await; + js_check(result); + } + } + if state.flags.lock_write { if let Some(ref lockfile) = state.lockfile { let g = lockfile.lock().unwrap(); diff --git a/cli/tests/037_fetch_multiple.out b/cli/tests/037_fetch_multiple.out new file mode 100644 index 00000000..cdb6fe2b --- /dev/null +++ b/cli/tests/037_fetch_multiple.out @@ -0,0 +1,5 @@ +Compile [WILDCARD]/fetch/test.ts +Download http://localhost:4545/cli/tests/subdir/mod2.ts +Download http://localhost:4545/cli/tests/subdir/print_hello.ts +Compile [WILDCARD]/fetch/other.ts +Download http://localhost:4545/cli/tests/subdir/mt_text_typescript.t1.ts diff --git a/cli/tests/fetch/other.ts b/cli/tests/fetch/other.ts new file mode 100644 index 00000000..ab85b226 --- /dev/null +++ b/cli/tests/fetch/other.ts @@ -0,0 +1 @@ +import "http://localhost:4545/cli/tests/subdir/mt_text_typescript.t1.ts"; diff --git a/cli/tests/fetch/test.ts b/cli/tests/fetch/test.ts new file mode 100644 index 00000000..1b49a76c --- /dev/null +++ b/cli/tests/fetch/test.ts @@ -0,0 +1 @@ +import "http://localhost:4545/cli/tests/subdir/mod2.ts"; diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs index fef69ad9..b7dfc4e3 100644 --- a/cli/tests/integration_tests.rs +++ b/cli/tests/integration_tests.rs @@ -413,6 +413,13 @@ itest!(_036_import_map_fetch { output: "036_import_map_fetch.out", }); +itest!(_037_fetch_multiple { + args: "fetch --reload fetch/test.ts fetch/other.ts", + check_stderr: true, + http_server: true, + output: "037_fetch_multiple.out", +}); + itest!(_038_checkjs { // checking if JS file is run through TS compiler args: "run --reload --config 038_checkjs.tsconfig.json 038_checkjs.js", -- GitLab