summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-09-30 15:46:43 -0400
committerGitHub <noreply@github.com>2024-09-30 19:46:43 +0000
commitd7b787792c09569bd718d9acf2d2b73ae406828c (patch)
treeb09fa58618fcd1ee9849437e9a43059a5daa0acd
parentc5c18699921cd45021f8c130eecdc09099c26878 (diff)
fix(info): error instead of panic for npm specifiers when using byonm (#25947)
-rw-r--r--cli/args/mod.rs4
-rw-r--r--cli/graph_util.rs7
-rw-r--r--tests/specs/info/byonm/__test__.jsonc11
-rw-r--r--tests/specs/info/byonm/deno.json6
-rw-r--r--tests/specs/info/byonm/info.out1
-rw-r--r--tests/specs/info/byonm/package.json5
6 files changed, 30 insertions, 4 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 3ff2a427f..2ae7098da 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -1144,10 +1144,6 @@ impl CliOptions {
DenoSubcommand::Run(run_flags) => {
if run_flags.is_stdin() {
resolve_url_or_path("./$deno$stdin.ts", self.initial_cwd())?
- } else if NpmPackageReqReference::from_str(&run_flags.script)
- .is_ok()
- {
- ModuleSpecifier::parse(&run_flags.script)?
} else {
resolve_url_or_path(&run_flags.script, self.initial_cwd())?
}
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index f7194ac11..e2f6246e7 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -21,6 +21,7 @@ use crate::tools::check::TypeChecker;
use crate::util::file_watcher::WatcherCommunicator;
use crate::util::fs::canonicalize_path;
use deno_config::workspace::JsrPackageConfig;
+use deno_core::anyhow::bail;
use deno_graph::source::LoaderChecksum;
use deno_graph::FillFromLockfileOptions;
use deno_graph::JsrLoadError;
@@ -593,6 +594,12 @@ impl ModuleGraphBuilder {
let initial_package_deps_len = graph.packages.package_deps_sum();
let initial_package_mappings_len = graph.packages.mappings().len();
+ if roots.iter().any(|r| r.scheme() == "npm")
+ && self.npm_resolver.as_byonm().is_some()
+ {
+ bail!("Resolving npm specifier entrypoints this way is currently not supported with \"nodeModules\": \"manual\". In the meantime, try with --node-modules-dir=auto instead");
+ }
+
graph.build(roots, loader, options).await;
let has_redirects_changed = graph.redirects.len() != initial_redirects_len;
diff --git a/tests/specs/info/byonm/__test__.jsonc b/tests/specs/info/byonm/__test__.jsonc
new file mode 100644
index 000000000..6c9ba7dad
--- /dev/null
+++ b/tests/specs/info/byonm/__test__.jsonc
@@ -0,0 +1,11 @@
+{
+ "tempDir": true,
+ "steps": [{
+ "args": "install",
+ "output": "[WILDCARD]"
+ }, {
+ "args": "info npm:@denotest/add",
+ "output": "info.out",
+ "exitCode": 1
+ }]
+}
diff --git a/tests/specs/info/byonm/deno.json b/tests/specs/info/byonm/deno.json
new file mode 100644
index 000000000..4b88c71fb
--- /dev/null
+++ b/tests/specs/info/byonm/deno.json
@@ -0,0 +1,6 @@
+{
+ "nodeModulesDir": "manual",
+ "imports": {
+ "chalk": "npm:@denotest/add"
+ }
+}
diff --git a/tests/specs/info/byonm/info.out b/tests/specs/info/byonm/info.out
new file mode 100644
index 000000000..4e6f11a88
--- /dev/null
+++ b/tests/specs/info/byonm/info.out
@@ -0,0 +1 @@
+error: Resolving npm specifier entrypoints this way is currently not supported with "nodeModules": "manual". In the meantime, try with --node-modules-dir=auto instead
diff --git a/tests/specs/info/byonm/package.json b/tests/specs/info/byonm/package.json
new file mode 100644
index 000000000..15a786ad7
--- /dev/null
+++ b/tests/specs/info/byonm/package.json
@@ -0,0 +1,5 @@
+{
+ "dependencies": {
+ "@denotest/add": "*"
+ }
+}