From 854c7ba1980e949642c7240f38318cdd31f0113c Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Fri, 9 Aug 2024 15:35:54 +0200 Subject: [PATCH] fix(install): Properly handle dist tags when setting up node_modules (#24968) Fixes https://github.com/denoland/deno/issues/24966. Fixes https://github.com/denoland/deno/issues/24932. --- cli/npm/managed/resolvers/local.rs | 15 +++++++++++--- .../__test__.jsonc | 12 +++++++++++ .../install.out | 20 +++++++++++++++++++ .../package.json | 5 +++++ 4 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 tests/specs/install/future_install_node_modules_tag/__test__.jsonc create mode 100644 tests/specs/install/future_install_node_modules_tag/install.out create mode 100644 tests/specs/install/future_install_node_modules_tag/package.json diff --git a/cli/npm/managed/resolvers/local.rs b/cli/npm/managed/resolvers/local.rs index 7687e23f88..adfd04b9e4 100644 --- a/cli/npm/managed/resolvers/local.rs +++ b/cli/npm/managed/resolvers/local.rs @@ -612,12 +612,21 @@ async fn sync_resolution_with_fs( // 4. Create symlinks for package json dependencies { for remote in pkg_json_deps_provider.remote_pkgs() { - let Some(remote_id) = snapshot + let remote_pkg = if let Ok(remote_pkg) = + snapshot.resolve_pkg_from_pkg_req(&remote.req) + { + remote_pkg + } else if remote.req.version_req.tag().is_some() { + // couldn't find a match, and `resolve_best_package_id` + // panics if you give it a tag + continue; + } else if let Some(remote_id) = snapshot .resolve_best_package_id(&remote.req.name, &remote.req.version_req) - else { + { + snapshot.package_from_id(&remote_id).unwrap() + } else { continue; // skip, package not found }; - let remote_pkg = snapshot.package_from_id(&remote_id).unwrap(); let alias_clashes = remote.req.name != remote.alias && newest_packages_by_name.contains_key(&remote.alias); let install_in_child = { diff --git a/tests/specs/install/future_install_node_modules_tag/__test__.jsonc b/tests/specs/install/future_install_node_modules_tag/__test__.jsonc new file mode 100644 index 0000000000..31c53749a5 --- /dev/null +++ b/tests/specs/install/future_install_node_modules_tag/__test__.jsonc @@ -0,0 +1,12 @@ +{ + "tempDir": true, + "steps": [ + { + "envs": { + "DENO_FUTURE": "1" + }, + "args": "install", + "output": "install.out" + } + ] +} diff --git a/tests/specs/install/future_install_node_modules_tag/install.out b/tests/specs/install/future_install_node_modules_tag/install.out new file mode 100644 index 0000000000..f48a9d8587 --- /dev/null +++ b/tests/specs/install/future_install_node_modules_tag/install.out @@ -0,0 +1,20 @@ +[UNORDERED_START] +Download http://localhost:4260/ajv +Download http://localhost:4260/fast-deep-equal +Download http://localhost:4260/json-schema-traverse +Download http://localhost:4260/require-from-string +Download http://localhost:4260/uri-js +Download http://localhost:4260/punycode +Download http://localhost:4260/ajv/ajv-8.11.0.tgz +Download http://localhost:4260/json-schema-traverse/json-schema-traverse-1.0.0.tgz +Download http://localhost:4260/fast-deep-equal/fast-deep-equal-3.1.3.tgz +Download http://localhost:4260/require-from-string/require-from-string-2.0.2.tgz +Download http://localhost:4260/uri-js/uri-js-4.4.1.tgz +Download http://localhost:4260/punycode/punycode-2.1.1.tgz +Initialize require-from-string@2.0.2 +Initialize punycode@2.1.1 +Initialize fast-deep-equal@3.1.3 +Initialize json-schema-traverse@1.0.0 +Initialize uri-js@4.4.1 +Initialize ajv@8.11.0 +[UNORDERED_END] diff --git a/tests/specs/install/future_install_node_modules_tag/package.json b/tests/specs/install/future_install_node_modules_tag/package.json new file mode 100644 index 0000000000..efcd075e88 --- /dev/null +++ b/tests/specs/install/future_install_node_modules_tag/package.json @@ -0,0 +1,5 @@ +{ + "dependencies": { + "ajv": "latest" + } +}