From 5de30c53239ac74843725d981afc0bb8c45bdf16 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Thu, 23 May 2024 12:31:05 -0700 Subject: fix(cli): Support deno.lock with only package.json present + fix DENO_FUTURE install interactions with lockfile (#23918) Fixes #23571. Previously, we required a `deno.json` to be present (or the `--lock` flag) in order for us to resolve a `deno.lock` file. This meant that if you were using deno in an npm-first project deno wouldn't use a lockfile. Additionally, while I was fixing that, I discovered there were a couple bugs keeping the future `install` command from using a lockfile. With this PR, `install` will actually resolve the lockfile (or create one if not present), and update it if it's not up-to-date. This also speeds up `deno install`, as we can use the lockfile to skip work during npm resolution. --- .../future_install_node_modules/__test__.jsonc | 65 +++++++++++++++++----- .../install/future_install_node_modules/corrupt.js | 5 ++ .../future_install_node_modules/corrupted.out | 3 + .../future_install_node_modules/deno.lock.out | 19 +++++++ 4 files changed, 79 insertions(+), 13 deletions(-) create mode 100644 tests/specs/install/future_install_node_modules/corrupt.js create mode 100644 tests/specs/install/future_install_node_modules/corrupted.out create mode 100644 tests/specs/install/future_install_node_modules/deno.lock.out (limited to 'tests/specs/install/future_install_node_modules') diff --git a/tests/specs/install/future_install_node_modules/__test__.jsonc b/tests/specs/install/future_install_node_modules/__test__.jsonc index eb780d962..571216557 100644 --- a/tests/specs/install/future_install_node_modules/__test__.jsonc +++ b/tests/specs/install/future_install_node_modules/__test__.jsonc @@ -1,17 +1,56 @@ { - "tempDir": true, - "envs": { - "DENO_FUTURE": "1" - }, - "steps": [ - { - "args": "install", - "output": "install.out" + "tests": { + "install_sets_up_node_modules": { + "tempDir": true, + "envs": { + "DENO_FUTURE": "1" + }, + "steps": [ + { + "args": "install", + "output": "install.out" + }, + { + // ensure deps are actually cached + "args": "run --cached-only main.js", + "output": "" + }, + { + // check for lockfile + "args": [ + "eval", + "console.log(Deno.readTextFileSync('./deno.lock').trim())" + ], + "output": "deno.lock.out" + } + ] }, - { - // ensure deps are actually cached - "args": "run --cached-only main.js", - "output": "" + "install_errors_corrupted_lockfile": { + "tempDir": true, + "envs": { + "DENO_FUTURE": "1" + }, + "steps": [ + { + "args": "install", + "output": "install.out" + }, + { + // Mess up the lockfile + "args": [ + "run", + "-A", + "corrupt.js" + ], + "output": "" + }, + { + // Run the install again + "args": "install", + "output": "corrupted.out", + "exitCode": 10 + } + ] } - ] + } } diff --git a/tests/specs/install/future_install_node_modules/corrupt.js b/tests/specs/install/future_install_node_modules/corrupt.js new file mode 100644 index 000000000..fcc146081 --- /dev/null +++ b/tests/specs/install/future_install_node_modules/corrupt.js @@ -0,0 +1,5 @@ +const lock = JSON.parse(Deno.readTextFileSync("./deno.lock")); +const pkg = lock.packages.npm["@denotest/esm-basic@1.0.0"]; +// Corrupt the integrity hash +pkg.integrity = pkg.integrity.slice(0, -1); +Deno.writeTextFileSync("./deno.lock", JSON.stringify(lock)); diff --git a/tests/specs/install/future_install_node_modules/corrupted.out b/tests/specs/install/future_install_node_modules/corrupted.out new file mode 100644 index 000000000..89578cbe2 --- /dev/null +++ b/tests/specs/install/future_install_node_modules/corrupted.out @@ -0,0 +1,3 @@ +[WILDCARD] +error: Integrity check failed for package: "npm:@denotest/esm-basic@1.0.0".[WILDCARD] +Use "--lock-write" flag to regenerate the lockfile at [WILDCARD] \ No newline at end of file diff --git a/tests/specs/install/future_install_node_modules/deno.lock.out b/tests/specs/install/future_install_node_modules/deno.lock.out new file mode 100644 index 000000000..b30232996 --- /dev/null +++ b/tests/specs/install/future_install_node_modules/deno.lock.out @@ -0,0 +1,19 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "npm:@denotest/esm-basic": "npm:@denotest/esm-basic@1.0.0" + }, + "npm": { + "@denotest/esm-basic@1.0.0": [WILDCARD] + } + }, + "remote": {}, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:@denotest/esm-basic" + ] + } + } +} -- cgit v1.2.3