1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-03 04:48:52 -05:00

fix(info): resolve bare specifier pointing to workspace member (#27020)

Fixes https://github.com/denoland/deno/issues/26721

Previously, we were applying only the import map, which would result in
`@scope/foo` expanding to (e.g.) `jsr:@scope/foo@1.0.0`. Since that
didn't exist it would error and fail to resolve.
This commit is contained in:
Nathan Whitaker 2024-11-27 13:54:26 -08:00 committed by GitHub
parent 16e16690af
commit 76daa03aa9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 120 additions and 13 deletions

View file

@ -49,19 +49,67 @@ pub async fn info(
let module_graph_creator = factory.module_graph_creator().await?;
let npm_resolver = factory.npm_resolver().await?;
let maybe_lockfile = cli_options.maybe_lockfile();
let resolver = factory.workspace_resolver().await?.clone();
let npmrc = cli_options.npmrc();
let resolver = factory.workspace_resolver().await?;
let node_resolver = factory.node_resolver().await?;
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()
let maybe_import_specifier = if let Ok(resolved) =
resolver.resolve(&specifier, &cwd_url)
{
if let Ok(imports_specifier) = import_map.resolve(&specifier, &cwd_url) {
Some(imports_specifier)
} else {
None
match resolved {
deno_config::workspace::MappedResolution::Normal {
specifier, ..
}
| deno_config::workspace::MappedResolution::ImportMap {
specifier,
..
}
| deno_config::workspace::MappedResolution::WorkspaceJsrPackage {
specifier,
..
} => Some(specifier),
deno_config::workspace::MappedResolution::WorkspaceNpmPackage {
target_pkg_json,
sub_path,
..
} => Some(node_resolver.resolve_package_subpath_from_deno_module(
target_pkg_json.clone().dir_path(),
sub_path.as_deref(),
Some(&cwd_url),
node_resolver::ResolutionMode::Import,
node_resolver::NodeResolutionKind::Execution,
)?),
deno_config::workspace::MappedResolution::PackageJson {
alias,
sub_path,
dep_result,
..
} => match dep_result.as_ref().map_err(|e| e.clone())? {
deno_package_json::PackageJsonDepValue::Workspace(version_req) => {
let pkg_folder = resolver
.resolve_workspace_pkg_json_folder_for_pkg_json_dep(
alias,
version_req,
)?;
Some(node_resolver.resolve_package_subpath_from_deno_module(
pkg_folder,
sub_path.as_deref(),
Some(&cwd_url),
node_resolver::ResolutionMode::Import,
node_resolver::NodeResolutionKind::Execution,
)?)
}
deno_package_json::PackageJsonDepValue::Req(req) => {
Some(ModuleSpecifier::parse(&format!(
"npm:{}{}",
req,
sub_path.map(|s| format!("/{}", s)).unwrap_or_default()
))?)
}
},
}
} else {
None

View file

@ -1,9 +1,21 @@
{
"tempDir": true,
"steps": [
{
"args": "info --quiet main.ts",
"output": "info.out"
"tests": {
"resolves_npm_deps": {
"steps": [
{
"args": "info --quiet main.ts",
"output": "info.out"
}
]
},
"bare_specifier": {
"steps": [
{
"args": "info --quiet @denotest/esm-basic",
"output": "info_bare.out"
}
]
}
]
}
}

View file

@ -0,0 +1,4 @@
dependencies: 0 unique
size: 471B
npm:/@denotest/esm-basic@1.0.0 (471B)

View file

@ -11,6 +11,18 @@
"cwd": "member/sub",
"output": "info_workspace_member_sub.out",
"exitCode": 0
},
"member_bare_specifier": {
"args": "info @denotest/workspace-member",
"output": "info_bare_specifier.out"
},
"member_package_json_specifier": {
"args": "info @denotest/workspace-member-package-json",
"output": "info_bare_specifier_package_json.out"
},
"member_package_json_specifier_subpath": {
"args": "info @denotest/workspace-member-package-json/foo",
"output": "info_bare_specifier_package_json_subpath.out"
}
}
}

View file

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

View file

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

View file

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

View file

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

View file

@ -1,4 +1,6 @@
{
"name": "@denotest/workspace-member",
"exports": "./mod.ts",
"imports": {
"foo": "./sub/file.ts"
}

View file

@ -0,0 +1,3 @@
export function hi() {
console.log("hi");
}

View file

@ -0,0 +1 @@
{}

View file

@ -0,0 +1,7 @@
{
"name": "@denotest/workspace-member-package-json",
"exports": {
".": "./mod.ts",
"./foo": "./bar.ts"
}
}