diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-17 09:13:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-17 09:13:22 -0400 |
commit | f4b9d8586215fc07c28998e5d896fefa876139b7 (patch) | |
tree | 9ee42eb4bb62af04b1c3b049cd179dfa6fe908bb /cli/standalone/mod.rs | |
parent | 078def0ff8501bb07f3f286515acd8c6a2181037 (diff) |
fix(workspace): support resolving bare specifiers to npm pkgs within a workspace (#24611)
This makes bare specifiers for npm packages work when inside a
workspace, which emulates the same behaviour as when there's a
node_modules directory. The bare specifier can be overwritten by
specifying an import map entry or package.json dependency entry.
* https://github.com/denoland/deno_config/pull/88
Closes #24605
Diffstat (limited to 'cli/standalone/mod.rs')
-rw-r--r-- | cli/standalone/mod.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 1df3895ef..e0c8e66ff 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -88,7 +88,7 @@ struct WorkspaceEszipModule { struct WorkspaceEszip { eszip: eszip::EszipV2, - root_dir_url: ModuleSpecifier, + root_dir_url: Arc<ModuleSpecifier>, } impl WorkspaceEszip { @@ -166,6 +166,22 @@ impl ModuleLoader for EmbeddedModuleLoader { self.shared.workspace_resolver.resolve(specifier, &referrer); match mapped_resolution { + Ok(MappedResolution::WorkspaceNpmPackage { + target_pkg_json: pkg_json, + sub_path, + .. + }) => Ok( + self + .shared + .node_resolver + .resolve_package_sub_path_from_deno_module( + pkg_json.dir_path(), + sub_path.as_deref(), + Some(&referrer), + NodeResolutionMode::Execution, + )? + .into_url(), + ), Ok(MappedResolution::PackageJson { dep_result, sub_path, @@ -427,7 +443,8 @@ pub async fn run( let npm_registry_url = ModuleSpecifier::parse("https://localhost/").unwrap(); let root_path = std::env::temp_dir().join(format!("deno-compile-{}", current_exe_name)); - let root_dir_url = ModuleSpecifier::from_directory_path(&root_path).unwrap(); + let root_dir_url = + Arc::new(ModuleSpecifier::from_directory_path(&root_path).unwrap()); let main_module = root_dir_url.join(&metadata.entrypoint_key).unwrap(); let root_node_modules_path = root_path.join("node_modules"); let npm_cache_dir = NpmCacheDir::new( @@ -579,6 +596,7 @@ pub async fn run( }) .collect(); WorkspaceResolver::new_raw( + root_dir_url.clone(), import_map, pkg_jsons, metadata.workspace_resolver.pkg_json_resolution, |