1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-24 08:09:08 -05:00

fix(info): resolve workspace member mappings (#26350)

This PR fixes the issue where mapped specifiers in a workspace member
would never be found. Only mapped paths from the workspace root would
resolve.

This was caused by always passing the workspace root url to the import
map resolver instead of the workspace member one.

Fixes https://github.com/denoland/deno/issues/26138
Fixes https://github.com/denoland/fresh/issues/2615

---------

Signed-off-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
Co-authored-by: David Sherret <dsherret@users.noreply.github.com>
This commit is contained in:
Marvin Hagemeister 2024-10-18 21:45:05 +02:00 committed by Bartek Iwańczuk
parent 998a371f5d
commit 25c857c822
No known key found for this signature in database
GPG key ID: 0C6BCDDC3B3AD750
8 changed files with 57 additions and 13 deletions

View file

@ -11,6 +11,7 @@ use deno_core::anyhow::bail;
use deno_core::error::AnyError;
use deno_core::resolve_url_or_path;
use deno_core::serde_json;
use deno_core::url;
use deno_graph::Dependency;
use deno_graph::GraphKind;
use deno_graph::Module;
@ -51,18 +52,20 @@ pub async fn info(
let npmrc = cli_options.npmrc();
let resolver = factory.workspace_resolver().await?;
let maybe_import_specifier =
if let Some(import_map) = resolver.maybe_import_map() {
if let Ok(imports_specifier) =
import_map.resolve(&specifier, import_map.base_url())
{
Some(imports_specifier)
} else {
None
}
let cwd_url =
url::Url::from_directory_path(cli_options.initial_cwd()).unwrap();
let maybe_import_specifier = if let Some(import_map) =
resolver.maybe_import_map()
{
if let Ok(imports_specifier) = import_map.resolve(&specifier, &cwd_url) {
Some(imports_specifier)
} else {
None
};
}
} else {
None
};
let specifier = match maybe_import_specifier {
Some(specifier) => specifier,

View file

@ -1,5 +1,9 @@
{
"args": "info preact/debug",
"output": "with_import_map.out",
"exitCode": 0
"steps": [
{
"args": "info preact/debug",
"output": "with_import_map.out",
"exitCode": 0
}
]
}

View file

@ -0,0 +1,16 @@
{
"tests": {
"member_folder": {
"args": "info --quiet foo",
"cwd": "member",
"output": "info_workspace_member.out",
"exitCode": 0
},
"member_folder_sub": {
"args": "info --quiet foo",
"cwd": "member/sub",
"output": "info_workspace_member_sub.out",
"exitCode": 0
}
}
}

View file

@ -0,0 +1,3 @@
{
"workspace": ["./member"]
}

View file

@ -0,0 +1,6 @@
local: [WILDCARD]file.ts
type: TypeScript
dependencies: 0 unique
size: [WILDCARD]
file://[WILDCARD]/member/sub/file.ts ([WILDCARD])

View file

@ -0,0 +1,6 @@
local: [WILDCARD]file.ts
type: TypeScript
dependencies: 0 unique
size: [WILDCARD]
file://[WILDCARD]/member/sub/file.ts ([WILDCARD])

View file

@ -0,0 +1,5 @@
{
"imports": {
"foo": "./sub/file.ts"
}
}

View file

@ -0,0 +1 @@
export {};