mirror of
https://github.com/denoland/deno.git
synced 2025-08-03 10:33:54 +00:00
feat(compile): support "bring your own node_modules" in deno compile (#21377)
Not tested thoroughly. This is a good start. Closes #21350
This commit is contained in:
parent
7e56a0466f
commit
9ac405d587
13 changed files with 245 additions and 121 deletions
|
@ -19,7 +19,7 @@ use deno_semver::package::PackageReq;
|
|||
use crate::args::package_json::get_local_package_json_version_reqs;
|
||||
use crate::args::NpmProcessState;
|
||||
use crate::args::NpmProcessStateKind;
|
||||
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
||||
use crate::util::fs::canonicalize_path_maybe_not_exists_with_fs;
|
||||
use crate::util::path::specifier_to_file_path;
|
||||
|
||||
use super::common::types_package_name;
|
||||
|
@ -188,8 +188,8 @@ impl CliNpmResolver for ByonmCliNpmResolver {
|
|||
InnerCliNpmResolverRef::Byonm(self)
|
||||
}
|
||||
|
||||
fn root_node_modules_path(&self) -> Option<std::path::PathBuf> {
|
||||
Some(self.root_node_modules_dir.clone())
|
||||
fn root_node_modules_path(&self) -> Option<&PathBuf> {
|
||||
Some(&self.root_node_modules_dir)
|
||||
}
|
||||
|
||||
fn resolve_pkg_folder_from_deno_module_req(
|
||||
|
@ -215,7 +215,10 @@ impl CliNpmResolver for ByonmCliNpmResolver {
|
|||
.unwrap()
|
||||
.join("node_modules")
|
||||
.join(key);
|
||||
return Ok(canonicalize_path_maybe_not_exists(&package_path)?);
|
||||
return Ok(canonicalize_path_maybe_not_exists_with_fs(
|
||||
&package_path,
|
||||
fs,
|
||||
)?);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -288,12 +288,8 @@ impl ManagedCliNpmResolver {
|
|||
pkg_id: &NpmPackageId,
|
||||
) -> Result<PathBuf, AnyError> {
|
||||
let path = self.fs_resolver.package_folder(pkg_id)?;
|
||||
let path = canonicalize_path_maybe_not_exists_with_fs(&path, |path| {
|
||||
self
|
||||
.fs
|
||||
.realpath_sync(path)
|
||||
.map_err(|err| err.into_io_error())
|
||||
})?;
|
||||
let path =
|
||||
canonicalize_path_maybe_not_exists_with_fs(&path, self.fs.as_ref())?;
|
||||
log::debug!(
|
||||
"Resolved package folder of {} to {}",
|
||||
pkg_id.as_serialized(),
|
||||
|
@ -560,7 +556,7 @@ impl CliNpmResolver for ManagedCliNpmResolver {
|
|||
&self.progress_bar,
|
||||
self.api.base_url().clone(),
|
||||
npm_resolution,
|
||||
self.root_node_modules_path(),
|
||||
self.root_node_modules_path().map(ToOwned::to_owned),
|
||||
self.npm_system_info.clone(),
|
||||
),
|
||||
self.global_npm_cache.clone(),
|
||||
|
@ -575,7 +571,7 @@ impl CliNpmResolver for ManagedCliNpmResolver {
|
|||
InnerCliNpmResolverRef::Managed(self)
|
||||
}
|
||||
|
||||
fn root_node_modules_path(&self) -> Option<PathBuf> {
|
||||
fn root_node_modules_path(&self) -> Option<&PathBuf> {
|
||||
self.fs_resolver.node_modules_path()
|
||||
}
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ pub trait NpmPackageFsResolver: Send + Sync {
|
|||
fn root_dir_url(&self) -> &Url;
|
||||
|
||||
/// The local node_modules folder if it is applicable to the implementation.
|
||||
fn node_modules_path(&self) -> Option<PathBuf>;
|
||||
fn node_modules_path(&self) -> Option<&PathBuf>;
|
||||
|
||||
fn package_folder(
|
||||
&self,
|
||||
|
|
|
@ -75,7 +75,7 @@ impl NpmPackageFsResolver for GlobalNpmPackageResolver {
|
|||
self.cache.root_dir_url()
|
||||
}
|
||||
|
||||
fn node_modules_path(&self) -> Option<PathBuf> {
|
||||
fn node_modules_path(&self) -> Option<&PathBuf> {
|
||||
None
|
||||
}
|
||||
|
||||
|
|
|
@ -122,14 +122,9 @@ impl LocalNpmPackageResolver {
|
|||
};
|
||||
// Canonicalize the path so it's not pointing to the symlinked directory
|
||||
// in `node_modules` directory of the referrer.
|
||||
canonicalize_path_maybe_not_exists_with_fs(&path, |path| {
|
||||
self
|
||||
.fs
|
||||
.realpath_sync(path)
|
||||
.map_err(|err| err.into_io_error())
|
||||
})
|
||||
.map(Some)
|
||||
.map_err(|err| err.into())
|
||||
canonicalize_path_maybe_not_exists_with_fs(&path, self.fs.as_ref())
|
||||
.map(Some)
|
||||
.map_err(|err| err.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -139,8 +134,8 @@ impl NpmPackageFsResolver for LocalNpmPackageResolver {
|
|||
&self.root_node_modules_url
|
||||
}
|
||||
|
||||
fn node_modules_path(&self) -> Option<PathBuf> {
|
||||
Some(self.root_node_modules_path.clone())
|
||||
fn node_modules_path(&self) -> Option<&PathBuf> {
|
||||
Some(&self.root_node_modules_path)
|
||||
}
|
||||
|
||||
fn package_folder(&self, id: &NpmPackageId) -> Result<PathBuf, AnyError> {
|
||||
|
|
|
@ -75,7 +75,7 @@ pub trait CliNpmResolver: NpmResolver {
|
|||
}
|
||||
}
|
||||
|
||||
fn root_node_modules_path(&self) -> Option<PathBuf>;
|
||||
fn root_node_modules_path(&self) -> Option<&PathBuf>;
|
||||
|
||||
fn resolve_pkg_folder_from_deno_module_req(
|
||||
&self,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue