未验证 提交 2cd39949 编写于 作者: T Tim Ermilov 提交者: GitHub

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

上级 1dc8afe3
......@@ -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 =
......
......@@ -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();
......
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
import "http://localhost:4545/cli/tests/subdir/mt_text_typescript.t1.ts";
import "http://localhost:4545/cli/tests/subdir/mod2.ts";
......@@ -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",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册