mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(future): Emit deno install
warning less often, suggest deno install
in error message (#24706)
Two small changes: - In our BYONM errors, suggest running `deno install` instead of `npm install` if `DENO_FUTURE` is set - Only emit warning about `deno install` changes if you do `deno install <foo>` with deno_future unset
This commit is contained in:
parent
1fad6eb2ac
commit
795ed23b35
29 changed files with 87 additions and 156 deletions
|
@ -286,9 +286,14 @@ impl CliNpmResolver for ByonmCliNpmResolver {
|
|||
concat!(
|
||||
"Could not find \"{}\" in a node_modules folder. ",
|
||||
"Deno expects the node_modules/ directory to be up to date. ",
|
||||
"Did you forget to run `npm install`?"
|
||||
"Did you forget to run `{}`?"
|
||||
),
|
||||
alias,
|
||||
if *crate::args::DENO_FUTURE {
|
||||
"deno install"
|
||||
} else {
|
||||
"npm install"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -233,8 +233,13 @@ impl CliNodeResolver {
|
|||
let package_json_path = package_folder.join("package.json");
|
||||
if !self.fs.exists_sync(&package_json_path) {
|
||||
return Err(anyhow!(
|
||||
"Could not find '{}'. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?",
|
||||
package_json_path.display()
|
||||
"Could not find '{}'. Deno expects the node_modules/ directory to be up to date. Did you forget to run `{}`?",
|
||||
package_json_path.display(),
|
||||
if *crate::args::DENO_FUTURE {
|
||||
"deno install"
|
||||
} else {
|
||||
"npm install"
|
||||
},
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -283,12 +283,12 @@ pub async fn install_command(
|
|||
flags: Arc<Flags>,
|
||||
install_flags: InstallFlags,
|
||||
) -> Result<(), AnyError> {
|
||||
match install_flags.kind {
|
||||
InstallKind::Global(global_flags) => {
|
||||
if !install_flags.global {
|
||||
log::warn!("⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.");
|
||||
}
|
||||
|
||||
match install_flags.kind {
|
||||
InstallKind::Global(global_flags) => {
|
||||
install_global(flags, global_flags).await
|
||||
}
|
||||
InstallKind::Local(maybe_add_flags) => {
|
||||
|
|
|
@ -109,7 +109,7 @@ fn install_basic_global() {
|
|||
let output_text = output.combined_output();
|
||||
assert_not_contains!(
|
||||
output_text,
|
||||
"`deno install` behavior will change in Deno 2. To preserve the current behavior use `-g` or `--global` flag."
|
||||
"`deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag."
|
||||
);
|
||||
|
||||
// no lockfile should be created locally
|
||||
|
|
|
@ -2453,138 +2453,6 @@ fn byonm_package_specifier_not_installed_and_invalid_subpath() {
|
|||
output.assert_exit_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn future_byonm_package_specifier_not_installed_and_invalid_subpath() {
|
||||
let test_context = TestContextBuilder::for_npm()
|
||||
.env("DENO_FUTURE", "1")
|
||||
.use_temp_cwd()
|
||||
.build();
|
||||
let dir = test_context.temp_dir();
|
||||
dir.path().join("package.json").write_json(&json!({
|
||||
"dependencies": {
|
||||
"chalk": "4",
|
||||
"@denotest/conditional-exports-strict": "1"
|
||||
}
|
||||
}));
|
||||
dir.write(
|
||||
"main.ts",
|
||||
"import chalk from 'chalk'; console.log(chalk.green('hi'));",
|
||||
);
|
||||
|
||||
// no npm install has been run, so this should give an informative error
|
||||
let output = test_context.new_command().args("run main.ts").run();
|
||||
output.assert_matches_text(
|
||||
r#"error: Could not resolve "chalk", but found it in a package.json. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?
|
||||
at file:///[WILDCARD]/main.ts:1:19
|
||||
"#,
|
||||
);
|
||||
output.assert_exit_code(1);
|
||||
|
||||
// now test for an invalid sub path after doing an npm install
|
||||
dir.write(
|
||||
"main.ts",
|
||||
"import '@denotest/conditional-exports-strict/test';",
|
||||
);
|
||||
|
||||
test_context.run_npm("install");
|
||||
|
||||
let output = test_context.new_command().args("run main.ts").run();
|
||||
output.assert_matches_text(
|
||||
r#"error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './test' is not defined by "exports" in '[WILDCARD]' imported from '[WILDCARD]main.ts'
|
||||
at file:///[WILDCARD]/main.ts:1:8
|
||||
"#,
|
||||
);
|
||||
output.assert_exit_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn byonm_package_npm_specifier_not_installed_and_invalid_subpath() {
|
||||
let test_context = TestContextBuilder::for_npm()
|
||||
.env("DENO_UNSTABLE_BYONM", "1")
|
||||
.use_temp_cwd()
|
||||
.build();
|
||||
let dir = test_context.temp_dir();
|
||||
dir.path().join("package.json").write_json(&json!({
|
||||
"dependencies": {
|
||||
"chalk": "4",
|
||||
"@denotest/conditional-exports-strict": "1"
|
||||
}
|
||||
}));
|
||||
dir.write(
|
||||
"main.ts",
|
||||
"import chalk from 'npm:chalk'; console.log(chalk.green('hi'));",
|
||||
);
|
||||
|
||||
// no npm install has been run, so this should give an informative error
|
||||
let output = test_context.new_command().args("run main.ts").run();
|
||||
output.assert_matches_text(
|
||||
r#"error: Could not find "chalk" in a node_modules folder. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?
|
||||
at file:///[WILDCARD]/main.ts:1:19
|
||||
"#,
|
||||
);
|
||||
output.assert_exit_code(1);
|
||||
|
||||
// now test for an invalid sub path after doing an npm install
|
||||
dir.write(
|
||||
"main.ts",
|
||||
"import 'npm:@denotest/conditional-exports-strict/test';",
|
||||
);
|
||||
|
||||
test_context.run_npm("install");
|
||||
|
||||
let output = test_context.new_command().args("run main.ts").run();
|
||||
output.assert_matches_text(
|
||||
r#"error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './test' is not defined by "exports" in '[WILDLINE]package.json' imported from '[WILDLINE]main.ts'
|
||||
at file:///[WILDLINE]/main.ts:1:8
|
||||
"#,
|
||||
);
|
||||
output.assert_exit_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn future_byonm_package_npm_specifier_not_installed_and_invalid_subpath() {
|
||||
let test_context = TestContextBuilder::for_npm()
|
||||
.env("DENO_FUTURE", "1")
|
||||
.use_temp_cwd()
|
||||
.build();
|
||||
let dir = test_context.temp_dir();
|
||||
dir.path().join("package.json").write_json(&json!({
|
||||
"dependencies": {
|
||||
"chalk": "4",
|
||||
"@denotest/conditional-exports-strict": "1"
|
||||
}
|
||||
}));
|
||||
dir.write(
|
||||
"main.ts",
|
||||
"import chalk from 'npm:chalk'; console.log(chalk.green('hi'));",
|
||||
);
|
||||
|
||||
// no npm install has been run, so this should give an informative error
|
||||
let output = test_context.new_command().args("run main.ts").run();
|
||||
output.assert_matches_text(
|
||||
r#"error: Could not find "chalk" in a node_modules folder. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?
|
||||
at file:///[WILDCARD]/main.ts:1:19
|
||||
"#,
|
||||
);
|
||||
output.assert_exit_code(1);
|
||||
|
||||
// now test for an invalid sub path after doing an npm install
|
||||
dir.write(
|
||||
"main.ts",
|
||||
"import 'npm:@denotest/conditional-exports-strict/test';",
|
||||
);
|
||||
|
||||
test_context.run_npm("install");
|
||||
|
||||
let output = test_context.new_command().args("run main.ts").run();
|
||||
output.assert_matches_text(
|
||||
r#"error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './test' is not defined by "exports" in '[WILDLINE]package.json' imported from '[WILDLINE]main.ts'
|
||||
at file:///[WILDLINE]/main.ts:1:8
|
||||
"#,
|
||||
);
|
||||
output.assert_exit_code(1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn byonm_npm_workspaces() {
|
||||
let test_context = TestContextBuilder::for_npm().use_temp_cwd().build();
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
[UNORDERED_START]
|
||||
Download http://localhost:4261/@denotest/basic
|
||||
Download http://localhost:4262/@denotest2/basic
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
Add @denotest/esm-basic - npm:@denotest/esm-basic@^1.0.0
|
||||
Download http://localhost:4260/@denotest/esm-basic
|
||||
Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
Add @denotest/esm-basic - npm:@denotest/esm-basic@^1.0.0
|
||||
Download http://localhost:4260/@denotest/esm-basic
|
||||
Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
[UNORDERED_START]
|
||||
Download http://localhost:4545/v1/extensionless
|
||||
Download http://localhost:4545/subdir/mod1.ts
|
||||
|
|
|
@ -1,3 +1,2 @@
|
|||
[WILDCARD]
|
||||
error: Integrity check failed for package: "npm:@denotest/esm-basic@1.0.0".[WILDCARD]
|
||||
Use the --lock-write flag to regenerate the lockfile at [WILDCARD]
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
Download http://localhost:4260/@denotest/esm-basic
|
||||
Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz
|
||||
Initialize @denotest/esm-basic@1.0.0
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
Initialize @denotest/esm-basic@1.0.0
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
error: The lockfile is out of date. Run `deno cache --frozen=false`, `deno install --frozen=false`, or rerun with `--frozen=false` to update it.
|
||||
changes:
|
||||
5 | - "npm:@denotest/add@1": "npm:@denotest/add@1.0.0"
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
[UNORDERED_START]
|
||||
Download http://localhost:4260/@denotest/transitive-bin
|
||||
Download http://localhost:4260/@denotest/bin
|
||||
|
|
52
tests/specs/npm/byonm/__test__.jsonc
Normal file
52
tests/specs/npm/byonm/__test__.jsonc
Normal file
|
@ -0,0 +1,52 @@
|
|||
{
|
||||
"tempDir": true,
|
||||
"tests": {
|
||||
"future_not_installed": {
|
||||
"envs": {
|
||||
"DENO_FUTURE": "1"
|
||||
},
|
||||
"steps": [{
|
||||
"args": "run -A not_installed.ts",
|
||||
"output": "future_not_installed.out",
|
||||
"exitCode": 1
|
||||
}]
|
||||
},
|
||||
"future_invalid_sub_path": {
|
||||
"envs": {
|
||||
"DENO_FUTURE": "1"
|
||||
},
|
||||
"steps": [{
|
||||
"args": "install",
|
||||
"output": "[WILDCARD]"
|
||||
}, {
|
||||
"args": "run -A invalid_sub_path.ts",
|
||||
"output": "invalid_sub_path.out",
|
||||
"exitCode": 1
|
||||
}]
|
||||
},
|
||||
"not_installed": {
|
||||
"envs": {
|
||||
"DENO_UNSTABLE_BYONM": "1"
|
||||
},
|
||||
"steps": [{
|
||||
"args": "run -A not_installed.ts",
|
||||
"output": "not_installed.out",
|
||||
"exitCode": 1
|
||||
}]
|
||||
},
|
||||
"invalid_sub_path": {
|
||||
"envs": {
|
||||
"DENO_UNSTABLE_BYONM": "1"
|
||||
},
|
||||
"steps": [{
|
||||
"args": "install",
|
||||
"commandName": "npm",
|
||||
"output": "[WILDCARD]"
|
||||
}, {
|
||||
"args": "run -A invalid_sub_path.ts",
|
||||
"output": "invalid_sub_path.out",
|
||||
"exitCode": 1
|
||||
}]
|
||||
}
|
||||
}
|
||||
}
|
2
tests/specs/npm/byonm/future_invalid_sub_path.out
Normal file
2
tests/specs/npm/byonm/future_invalid_sub_path.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './test' is not defined by "exports" in '[WILDLINE]package.json' imported from '[WILDLINE]invalid_sub_path.ts'
|
||||
at file:///[WILDLINE]/invalid_sub_path.ts:1:8
|
2
tests/specs/npm/byonm/future_not_installed.out
Normal file
2
tests/specs/npm/byonm/future_not_installed.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
error: Could not find "chalk" in a node_modules folder. Deno expects the node_modules/ directory to be up to date. Did you forget to run `deno install`?
|
||||
at file:///[WILDCARD]/not_installed.ts:1:19
|
2
tests/specs/npm/byonm/invalid_sub_path.out
Normal file
2
tests/specs/npm/byonm/invalid_sub_path.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './test' is not defined by "exports" in '[WILDLINE]package.json' imported from '[WILDLINE]invalid_sub_path.ts'
|
||||
at file:///[WILDLINE]/invalid_sub_path.ts:1:8
|
1
tests/specs/npm/byonm/invalid_sub_path.ts
Normal file
1
tests/specs/npm/byonm/invalid_sub_path.ts
Normal file
|
@ -0,0 +1 @@
|
|||
import "npm:@denotest/conditional-exports-strict/test";
|
2
tests/specs/npm/byonm/not_installed.out
Normal file
2
tests/specs/npm/byonm/not_installed.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
error: Could not find "chalk" in a node_modules folder. Deno expects the node_modules/ directory to be up to date. Did you forget to run `npm install`?
|
||||
at file:///[WILDCARD]/not_installed.ts:1:19
|
2
tests/specs/npm/byonm/not_installed.ts
Normal file
2
tests/specs/npm/byonm/not_installed.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
import chalk from "npm:chalk";
|
||||
console.log(chalk.green("hi"));
|
6
tests/specs/npm/byonm/package.json
Normal file
6
tests/specs/npm/byonm/package.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"dependencies": {
|
||||
"chalk": "4",
|
||||
"@denotest/conditional-exports-strict": "1"
|
||||
}
|
||||
}
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
preinstall
|
||||
deno preinstall.js
|
||||
node preinstall.js
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
[UNORDERED_START]
|
||||
Download http://localhost:4260/@denotest/node-lifecycle-scripts
|
||||
Download http://localhost:4260/@denotest/bin
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
[UNORDERED_START]
|
||||
Download http://localhost:4261/@denotest/basic
|
||||
Download http://localhost:4262/@denotest2/basic
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
Download http://localhost:4261/@denotest/basic
|
||||
error: Error getting response at http://localhost:4261/@denotest/basic for package "@denotest/basic": Bad response: 401
|
||||
[WILDCARD]
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
Download http://localhost:4261/@denotest/basic
|
||||
error: Error getting response at http://localhost:4261/@denotest/basic for package "@denotest/basic": Bad response: 401
|
||||
[WILDCARD]
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
[UNORDERED_START]
|
||||
Download http://localhost:4261/@denotest/basic
|
||||
Download http://localhost:4262/@denotest2/basic
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
⚠️ `deno install` behavior will change in Deno 2. To preserve the current behavior use the `-g` or `--global` flag.
|
||||
[UNORDERED_START]
|
||||
Download http://localhost:4261/@denotest/basic
|
||||
Download http://localhost:4262/@denotest2/basic
|
||||
|
|
Loading…
Reference in a new issue