summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVedant Pandey <vedantpandey46@gmail.com>2023-07-25 21:53:43 +0530
committerGitHub <noreply@github.com>2023-07-25 18:23:43 +0200
commit4a5aaceb26cb7441d0702d30961e0059256826b7 (patch)
tree50b157a21bcf09ec9ab48d0ef86fa598193a39c0
parentbd79baea5e6734ab70802cd2c2532a491a987ff7 (diff)
fix: deno info should respect import map (#19781)
Closes #19742
-rw-r--r--cli/tests/integration/info_tests.rs7
-rw-r--r--cli/tests/testdata/info/with_import_map/deno.json6
-rw-r--r--cli/tests/testdata/info/with_import_map/deno.lock7
-rw-r--r--cli/tests/testdata/info/with_import_map/main.tsx2
-rw-r--r--cli/tests/testdata/info/with_import_map/with_import_map.out16
-rw-r--r--cli/tools/info.rs20
6 files changed, 57 insertions, 1 deletions
diff --git a/cli/tests/integration/info_tests.rs b/cli/tests/integration/info_tests.rs
index 856d92f9f..aeabf8208 100644
--- a/cli/tests/integration/info_tests.rs
+++ b/cli/tests/integration/info_tests.rs
@@ -147,3 +147,10 @@ itest!(package_json_basic {
copy_temp_dir: Some("package_json/basic"),
exit_code: 0,
});
+
+itest!(info_import_map {
+ args: "info preact/debug",
+ output: "info/with_import_map/with_import_map.out",
+ cwd: Some("info/with_import_map"),
+ exit_code: 0,
+});
diff --git a/cli/tests/testdata/info/with_import_map/deno.json b/cli/tests/testdata/info/with_import_map/deno.json
new file mode 100644
index 000000000..aaf7260c6
--- /dev/null
+++ b/cli/tests/testdata/info/with_import_map/deno.json
@@ -0,0 +1,6 @@
+{
+ "imports": {
+ "preact": "https://esm.sh/preact@10.15.1",
+ "preact/": "https://esm.sh/preact@10.15.1/"
+ }
+}
diff --git a/cli/tests/testdata/info/with_import_map/deno.lock b/cli/tests/testdata/info/with_import_map/deno.lock
new file mode 100644
index 000000000..78080ede2
--- /dev/null
+++ b/cli/tests/testdata/info/with_import_map/deno.lock
@@ -0,0 +1,7 @@
+{
+ "version": "2",
+ "remote": {
+ "https://esm.sh/preact@10.15.1": "2b79349676a4942fbcf835c4efa909791c2f0aeca195225bf22bac9866e94b4e",
+ "https://esm.sh/stable/preact@10.15.1/denonext/preact.mjs": "30710ac1d5ff3711ae0c04eddbeb706f34f82d97489f61aaf09897bc75d2a628"
+ }
+}
diff --git a/cli/tests/testdata/info/with_import_map/main.tsx b/cli/tests/testdata/info/with_import_map/main.tsx
new file mode 100644
index 000000000..e38f14a58
--- /dev/null
+++ b/cli/tests/testdata/info/with_import_map/main.tsx
@@ -0,0 +1,2 @@
+import { render } from "preact";
+console.log(render);
diff --git a/cli/tests/testdata/info/with_import_map/with_import_map.out b/cli/tests/testdata/info/with_import_map/with_import_map.out
new file mode 100644
index 000000000..29dc17737
--- /dev/null
+++ b/cli/tests/testdata/info/with_import_map/with_import_map.out
@@ -0,0 +1,16 @@
+Download https://esm.sh/preact@10.15.1/debug
+Download https://esm.sh/stable/preact@10.15.1/denonext/preact.mjs
+Download https://esm.sh/stable/preact@10.15.1/denonext/devtools.js
+Download https://esm.sh/stable/preact@10.15.1/denonext/debug.js
+local: [WILDCARD]
+type: JavaScript
+dependencies: 3 unique
+size: [WILDCARD]
+
+https://esm.sh/preact@10.15.1/debug [WILDCARD]
+├── https://esm.sh/stable/preact@10.15.1/denonext/preact.mjs [WILDCARD]
+├─┬ https://esm.sh/stable/preact@10.15.1/denonext/devtools.js [WILDCARD]
+│ └── https://esm.sh/stable/preact@10.15.1/denonext/preact.mjs [WILDCARD]
+└─┬ https://esm.sh/stable/preact@10.15.1/denonext/debug.js [WILDCARD]
+ ├── https://esm.sh/stable/preact@10.15.1/denonext/preact.mjs [WILDCARD]
+ └── https://esm.sh/stable/preact@10.15.1/denonext/devtools.js [WILDCARD]
diff --git a/cli/tools/info.rs b/cli/tools/info.rs
index 95a7da7b0..2262f1423 100644
--- a/cli/tools/info.rs
+++ b/cli/tools/info.rs
@@ -40,7 +40,25 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let module_graph_builder = factory.module_graph_builder().await?;
let npm_resolver = factory.npm_resolver().await?;
let maybe_lockfile = factory.maybe_lockfile();
- let specifier = resolve_url_or_path(&specifier, cli_options.initial_cwd())?;
+ let maybe_imports_map = factory.maybe_import_map().await?;
+
+ let maybe_import_specifier = if let Some(imports_map) = maybe_imports_map {
+ if let Ok(imports_specifier) =
+ imports_map.resolve(&specifier, imports_map.base_url())
+ {
+ Some(imports_specifier)
+ } else {
+ None
+ }
+ } else {
+ None
+ };
+
+ let specifier = match maybe_import_specifier {
+ Some(specifier) => specifier,
+ None => resolve_url_or_path(&specifier, cli_options.initial_cwd())?,
+ };
+
let mut loader = module_graph_builder.create_graph_loader();
loader.enable_loading_cache_info(); // for displaying the cache information
let graph = module_graph_builder