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:
parent
16e16690af
commit
76daa03aa9
14 changed files with 120 additions and 13 deletions
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
dependencies: 0 unique
|
||||
size: 471B
|
||||
|
||||
npm:/@denotest/esm-basic@1.0.0 (471B)
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{
|
||||
"workspace": ["./member"]
|
||||
"workspace": ["./member", "./member2", "./member3"]
|
||||
}
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
local: [WILDCARD]mod.ts
|
||||
type: TypeScript
|
||||
dependencies: 0 unique
|
||||
size: [WILDCARD]
|
||||
|
||||
file://[WILDCARD]member/mod.ts ([WILDCARD])
|
|
@ -0,0 +1,6 @@
|
|||
local: [WILDCARD]mod.ts
|
||||
type: TypeScript
|
||||
dependencies: 0 unique
|
||||
size: [WILDCARD]
|
||||
|
||||
file://[WILDCARD]member3/mod.ts ([WILDCARD])
|
|
@ -0,0 +1,6 @@
|
|||
local: [WILDCARD]bar.ts
|
||||
type: TypeScript
|
||||
dependencies: 0 unique
|
||||
size: [WILDCARD]
|
||||
|
||||
file://[WILDCARD]member3/bar.ts ([WILDCARD])
|
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
"name": "@denotest/workspace-member",
|
||||
"exports": "./mod.ts",
|
||||
"imports": {
|
||||
"foo": "./sub/file.ts"
|
||||
}
|
||||
|
|
3
tests/specs/info/workspace_member/member/mod.ts
Normal file
3
tests/specs/info/workspace_member/member/mod.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export function hi() {
|
||||
console.log("hi");
|
||||
}
|
1
tests/specs/info/workspace_member/member2/deno.json
Normal file
1
tests/specs/info/workspace_member/member2/deno.json
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
0
tests/specs/info/workspace_member/member3/bar.ts
Normal file
0
tests/specs/info/workspace_member/member3/bar.ts
Normal file
0
tests/specs/info/workspace_member/member3/mod.ts
Normal file
0
tests/specs/info/workspace_member/member3/mod.ts
Normal file
7
tests/specs/info/workspace_member/member3/package.json
Normal file
7
tests/specs/info/workspace_member/member3/package.json
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"name": "@denotest/workspace-member-package-json",
|
||||
"exports": {
|
||||
".": "./mod.ts",
|
||||
"./foo": "./bar.ts"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue