1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 17:19:06 -05:00

Add support for multiple files in fetch command (#3845)

This commit is contained in:
Tim Ermilov 2020-01-31 22:07:37 +01:00 committed by GitHub
parent 1dc8afe3af
commit 2cd3994902
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 4 deletions

View file

@ -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 =

View file

@ -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();

View file

@ -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

1
cli/tests/fetch/other.ts Normal file
View file

@ -0,0 +1 @@
import "http://localhost:4545/cli/tests/subdir/mt_text_typescript.t1.ts";

1
cli/tests/fetch/test.ts Normal file
View file

@ -0,0 +1 @@
import "http://localhost:4545/cli/tests/subdir/mod2.ts";

View file

@ -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",