From be888c068cbe42c1cb93d9885827dc97aa40d6f6 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 8 Jan 2024 19:30:36 -0500 Subject: [PATCH] fix(task): do not eagerly auto-install packages in package.json when `"nodeModulesDir": false` (#21858) There's no need to auto-install the package.json if the user is not using a node_modules directory. Closes #21850 --- cli/tests/integration/task_tests.rs | 12 ++++++++++++ .../task/package_json_node_modules_dir_false/bin.out | 2 ++ .../package_json_node_modules_dir_false/deno.json | 3 +++ .../package_json_node_modules_dir_false/package.json | 9 +++++++++ cli/tools/task.rs | 11 +++++++---- 5 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 cli/tests/testdata/task/package_json_node_modules_dir_false/bin.out create mode 100644 cli/tests/testdata/task/package_json_node_modules_dir_false/deno.json create mode 100644 cli/tests/testdata/task/package_json_node_modules_dir_false/package.json diff --git a/cli/tests/integration/task_tests.rs b/cli/tests/integration/task_tests.rs index 603fa9bfa2..c8531c13f1 100644 --- a/cli/tests/integration/task_tests.rs +++ b/cli/tests/integration/task_tests.rs @@ -178,6 +178,18 @@ itest!(task_package_json_npm_bin { http_server: true, }); +// should not auto-install the packages in the package.json +// when using nodeModulesDir: false +itest!(task_package_json_node_modules_dir_false { + args: "task echo", + cwd: Some("task/package_json_node_modules_dir_false/"), + output: "task/package_json_node_modules_dir_false/bin.out", + copy_temp_dir: Some("task/package_json_node_modules_dir_false/"), + envs: env_vars_for_npm_tests(), + exit_code: 0, + http_server: true, +}); + itest!(task_both_no_arg { args: "task", cwd: Some("task/both/"), diff --git a/cli/tests/testdata/task/package_json_node_modules_dir_false/bin.out b/cli/tests/testdata/task/package_json_node_modules_dir_false/bin.out new file mode 100644 index 0000000000..d5d59d5515 --- /dev/null +++ b/cli/tests/testdata/task/package_json_node_modules_dir_false/bin.out @@ -0,0 +1,2 @@ +Task echo deno eval 'console.log(1)' +1 diff --git a/cli/tests/testdata/task/package_json_node_modules_dir_false/deno.json b/cli/tests/testdata/task/package_json_node_modules_dir_false/deno.json new file mode 100644 index 0000000000..23a325cfc2 --- /dev/null +++ b/cli/tests/testdata/task/package_json_node_modules_dir_false/deno.json @@ -0,0 +1,3 @@ +{ + "nodeModulesDir": false +} diff --git a/cli/tests/testdata/task/package_json_node_modules_dir_false/package.json b/cli/tests/testdata/task/package_json_node_modules_dir_false/package.json new file mode 100644 index 0000000000..081e076b9f --- /dev/null +++ b/cli/tests/testdata/task/package_json_node_modules_dir_false/package.json @@ -0,0 +1,9 @@ +{ + "scripts": { + "echo": "deno eval 'console.log(1)'" + }, + "dependencies": { + "@denotest/bin": "0.5", + "other": "npm:@denotest/bin@1.0" + } +} diff --git a/cli/tools/task.rs b/cli/tools/task.rs index ffeea74605..dfb0c585e0 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -88,10 +88,13 @@ pub async fn execute_script( } } - // install the npm packages if we're using a managed resolver - if let Some(npm_resolver) = npm_resolver.as_managed() { - npm_resolver.ensure_top_level_package_json_install().await?; - npm_resolver.resolve_pending().await?; + // ensure the npm packages are installed if using a node_modules + // directory and managed resolver + if cli_options.has_node_modules_dir() { + if let Some(npm_resolver) = npm_resolver.as_managed() { + npm_resolver.ensure_top_level_package_json_install().await?; + npm_resolver.resolve_pending().await?; + } } let cwd = match task_flags.cwd {