diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-09-04 16:00:44 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-04 14:00:44 +0000 |
commit | c6d1b0a1ccf45b7819b1e6f1efe8687b240f495a (patch) | |
tree | 6be2c0c611e4aee950402a34aaedd1c9b6bcaac3 /cli/standalone | |
parent | 13911eb8efb77bd14a80412072aecb664aa55fd5 (diff) |
fix(byonm): resolve npm deps of jsr deps (#25399)
This allows using npm deps of jsr deps without having to add them to the
root package.json.
Works by taking the package requirement and scanning the
`node_modules/.deno` directory for the best matching package, so it
relies on deno's node_modules structure.
Additionally to make the transition from package.json to deno.json
easier, Deno now:
1. Installs npm deps in a deno.json at the same time as installing npm
deps from a package.json.
2. Uses the alias in the import map for `node_modules/<alias>` for
better package.json compatiblity.
Diffstat (limited to 'cli/standalone')
-rw-r--r-- | cli/standalone/binary.rs | 2 | ||||
-rw-r--r-- | cli/standalone/mod.rs | 22 |
2 files changed, 13 insertions, 11 deletions
diff --git a/cli/standalone/binary.rs b/cli/standalone/binary.rs index 45d9b7c63..27308c901 100644 --- a/cli/standalone/binary.rs +++ b/cli/standalone/binary.rs @@ -45,7 +45,7 @@ use serde::Serialize; use crate::args::CaData; use crate::args::CliOptions; use crate::args::CompileFlags; -use crate::args::PackageJsonInstallDepsProvider; +use crate::args::NpmInstallDepsProvider; use crate::args::PermissionFlags; use crate::args::UnstableConfig; use crate::cache::DenoDir; diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index a0a312ad9..f1f687eed 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -48,7 +48,7 @@ use crate::args::get_root_cert_store; use crate::args::npm_pkg_req_ref_to_binary_command; use crate::args::CaData; use crate::args::CacheSetting; -use crate::args::PackageJsonInstallDepsProvider; +use crate::args::NpmInstallDepsProvider; use crate::args::StorageKeyResolver; use crate::cache::Caches; use crate::cache::DenoDirProvider; @@ -138,7 +138,7 @@ pub const UNSUPPORTED_SCHEME: &str = "Unsupported scheme"; impl ModuleLoader for EmbeddedModuleLoader { fn resolve( &self, - specifier: &str, + raw_specifier: &str, referrer: &str, kind: ResolutionKind, ) -> Result<ModuleSpecifier, AnyError> { @@ -162,13 +162,15 @@ impl ModuleLoader for EmbeddedModuleLoader { self .shared .node_resolver - .resolve(specifier, &referrer, NodeResolutionMode::Execution)? + .resolve(raw_specifier, &referrer, NodeResolutionMode::Execution)? .into_url(), ); } - let mapped_resolution = - self.shared.workspace_resolver.resolve(specifier, &referrer); + let mapped_resolution = self + .shared + .workspace_resolver + .resolve(raw_specifier, &referrer); match mapped_resolution { Ok(MappedResolution::WorkspaceJsrPackage { specifier, .. }) => { @@ -262,7 +264,7 @@ impl ModuleLoader for EmbeddedModuleLoader { if err.is_unmapped_bare_specifier() && referrer.scheme() == "file" => { let maybe_res = self.shared.node_resolver.resolve_if_for_npm_pkg( - specifier, + raw_specifier, &referrer, NodeResolutionMode::Execution, )?; @@ -502,9 +504,9 @@ pub async fn run( text_only_progress_bar: progress_bar, maybe_node_modules_path, npm_system_info: Default::default(), - package_json_deps_provider: Arc::new( + npm_install_deps_provider: Arc::new( // this is only used for installing packages, which isn't necessary with deno compile - PackageJsonInstallDepsProvider::empty(), + NpmInstallDepsProvider::empty(), ), // create an npmrc that uses the fake npm_registry_url to resolve packages npmrc: Arc::new(ResolvedNpmRc { @@ -554,9 +556,9 @@ pub async fn run( text_only_progress_bar: progress_bar, maybe_node_modules_path: None, npm_system_info: Default::default(), - package_json_deps_provider: Arc::new( + npm_install_deps_provider: Arc::new( // this is only used for installing packages, which isn't necessary with deno compile - PackageJsonInstallDepsProvider::empty(), + NpmInstallDepsProvider::empty(), ), // Packages from different registries are already inlined in the ESZip, // so no need to create actual `.npmrc` configuration. |