Skip to content

Commit

Permalink
fix(task): do not eagerly auto-install packages in package.json when …
Browse files Browse the repository at this point in the history
…`"nodeModulesDir": false` (denoland#21858)

There's no need to auto-install the package.json if the user is not
using a node_modules directory.

Closes denoland#21850
  • Loading branch information
dsherret committed Jan 9, 2024
1 parent 0efb17b commit be888c0
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
12 changes: 12 additions & 0 deletions cli/tests/integration/task_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Task echo deno eval 'console.log(1)'
1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"nodeModulesDir": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"scripts": {
"echo": "deno eval 'console.log(1)'"
},
"dependencies": {
"@denotest/bin": "0.5",
"other": "npm:@denotest/[email protected]"
}
}
11 changes: 7 additions & 4 deletions cli/tools/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit be888c0

Please sign in to comment.