-
Notifications
You must be signed in to change notification settings - Fork 5.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(npm): reload an npm package's dependency's information when version not found #18622
fix(npm): reload an npm package's dependency's information when version not found #18622
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, this change is so welcome
// should error when `--cache-only` is used now because the version is not in the cache | ||
let output = test_context | ||
.new_command() | ||
.args("run --cached-only main.ts") | ||
.run(); | ||
output.assert_exit_code(1); | ||
output.assert_matches_text("error: Could not find npm package '@denotest/cjs-default-export' matching '^1.0.0'.\n"); | ||
|
||
// now try running without it, it should download the package now | ||
let output = test_context.new_command().args("run main.ts").run(); | ||
output.assert_matches_text(concat!( | ||
"Download https://localhost:4545/npm/registry/@denotest/esm-import-cjs-default\n", | ||
"Download https://localhost:4545/npm/registry/@denotest/cjs-default-export\n", | ||
"Node esm importing node cjs\n[WILDCARD]", | ||
)); | ||
output.assert_exit_code(0); | ||
|
||
// now remove the information for the top level package | ||
let registry_json_path = "npm/localhost_4545/npm/registry/@denotest/esm-import-cjs-default/registry.json"; | ||
let mut registry_json: Value = | ||
serde_json::from_str(&deno_dir.read_to_string(registry_json_path)).unwrap(); | ||
remove_version(&mut registry_json, "1.0.0"); | ||
deno_dir.write( | ||
registry_json_path, | ||
serde_json::to_string(®istry_json).unwrap(), | ||
); | ||
|
||
// should error again for --cached-only | ||
let output = test_context | ||
.new_command() | ||
.args("run --cached-only main.ts") | ||
.run(); | ||
output.assert_exit_code(1); | ||
output.assert_matches_text(concat!( | ||
"error: Could not find npm package '@denotest/esm-import-cjs-default' matching '1.0.0'. Try retrieving the latest npm package information by running with --reload\n", | ||
" at file:https:///[WILDCARD]/main.ts:1:8\n", | ||
)); | ||
|
||
// now try running without it, it currently will error, but this should work in the future | ||
// todo(https://github.com/denoland/deno/issues/16901): fix this | ||
let output = test_context.new_command().args("run main.ts").run(); | ||
output.assert_exit_code(1); | ||
output.assert_matches_text(concat!( | ||
"error: Could not find npm package '@denotest/esm-import-cjs-default' matching '1.0.0'. Try retrieving the latest npm package information by running with --reload\n", | ||
" at file:https:///[WILDCARD]/main.ts:1:8\n", | ||
)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great test, I really like the reviewing them with the new test infrastructure. So much easier to understand without the boilerplate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's less arduous to write too!
@@ -188,7 +191,7 @@ impl NpmResolution { | |||
pub fn resolve_pkg_id_from_deno_module( | |||
&self, | |||
id: &NpmPackageNv, | |||
) -> Result<NpmPackageId, AnyError> { | |||
) -> Result<NpmPackageId, PackageNvNotFoundError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slowly grinding to strongly typed errors 💪
match package_info.version_info(&nv) { | ||
Ok(version_info) => Ok(version_info), | ||
Err(err) => { | ||
bail!("Could not find '{}' specified in the lockfile. Maybe try again with --reload", err.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, we should update this to also not require --reload
. I will do it in a future PR. (edit: opened #18624)
Part 1: #18622 Part 2: This PR Closes #16901 --------- Co-authored-by: Luca Casonato <[email protected]>
…on not found (#18622) This reloads an npm package's dependency's information when a version/version req/tag is not found. This PR applies only to dependencies of npm packages. It does NOT yet cause npm specifiers to have their dependency information cache busted. That requires a different solution, but this should help cache bust in more scenarios. Part of #16901, but doesn't close it yet
Part 1: #18622 Part 2: This PR Closes #16901 --------- Co-authored-by: Luca Casonato <[email protected]>
This reloads an npm package's dependency's information when a version/version req/tag is not found.
This PR applies only to dependencies of npm packages. It does NOT yet cause npm specifiers to have their dependency information cache busted. That requires a different solution, but this should help cache bust in more scenarios.
Part of #16901, but doesn't close it yet