diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index bd52909980..2060b9a13f 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -723,6 +723,10 @@ async fn npm_install_after_modification( // npm install cache_deps::cache_top_level_deps(&cli_factory, jsr_resolver).await?; + if let Some(lockfile) = cli_factory.cli_options()?.maybe_lockfile() { + lockfile.write_if_changed()?; + } + Ok(()) } diff --git a/tests/specs/add/update_lockfile_if_package_json/__test__.jsonc b/tests/specs/add/update_lockfile_if_package_json/__test__.jsonc new file mode 100644 index 0000000000..80b35dc3c2 --- /dev/null +++ b/tests/specs/add/update_lockfile_if_package_json/__test__.jsonc @@ -0,0 +1,31 @@ +{ + "tempDir": true, + "tests": { + "updates_lockfile": { + "steps": [ + { + "args": "add npm:@denotest/esm-basic npm:@denotest/say-hello", + "output": "add.out" + }, + { + "args": [ + "eval", + "console.log(Deno.readTextFileSync('deno.lock'))" + ], + "output": "lockfile_add.out" + }, + { + "args": "remove @denotest/esm-basic @denotest/say-hello", + "output": "remove.out" + }, + { + "args": [ + "eval", + "console.log(Deno.readTextFileSync('deno.lock'))" + ], + "output": "lockfile_remove.out" + } + ] + } + } +} diff --git a/tests/specs/add/update_lockfile_if_package_json/add.out b/tests/specs/add/update_lockfile_if_package_json/add.out new file mode 100644 index 0000000000..97989b0c38 --- /dev/null +++ b/tests/specs/add/update_lockfile_if_package_json/add.out @@ -0,0 +1,5 @@ +[UNORDERED_START] +Add npm:@denotest/esm-basic@1.0.0 +Add npm:@denotest/say-hello@1.0.0 +[UNORDERED_END] +[WILDCARD] \ No newline at end of file diff --git a/tests/specs/add/update_lockfile_if_package_json/lockfile_add.out b/tests/specs/add/update_lockfile_if_package_json/lockfile_add.out new file mode 100644 index 0000000000..d452c2de82 --- /dev/null +++ b/tests/specs/add/update_lockfile_if_package_json/lockfile_add.out @@ -0,0 +1,7 @@ +{ + "version": "4", + "specifiers": { + "npm:@denotest/esm-basic@1": "1.0.0", + "npm:@denotest/say-hello@1": "1.0.0" + }, +[WILDCARD] diff --git a/tests/specs/add/update_lockfile_if_package_json/lockfile_remove.out b/tests/specs/add/update_lockfile_if_package_json/lockfile_remove.out new file mode 100644 index 0000000000..fdd4f1cc60 --- /dev/null +++ b/tests/specs/add/update_lockfile_if_package_json/lockfile_remove.out @@ -0,0 +1,4 @@ +{ + "version": "4" +} + diff --git a/tests/specs/add/update_lockfile_if_package_json/package.json b/tests/specs/add/update_lockfile_if_package_json/package.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/specs/add/update_lockfile_if_package_json/remove.out b/tests/specs/add/update_lockfile_if_package_json/remove.out new file mode 100644 index 0000000000..8efb0810cf --- /dev/null +++ b/tests/specs/add/update_lockfile_if_package_json/remove.out @@ -0,0 +1,4 @@ +[UNORDERED_START] +Removed @denotest/esm-basic +Removed @denotest/say-hello +[UNORDERED_END]