mirror of
https://github.com/denoland/deno.git
synced 2024-11-22 15:06:54 -05:00
c6d1b0a1cc
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.
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
|
|
mod common;
|
|
mod global;
|
|
mod local;
|
|
|
|
use std::path::PathBuf;
|
|
use std::sync::Arc;
|
|
|
|
use deno_npm::NpmSystemInfo;
|
|
use deno_runtime::deno_fs::FileSystem;
|
|
|
|
use crate::args::LifecycleScriptsConfig;
|
|
use crate::args::NpmInstallDepsProvider;
|
|
use crate::util::progress_bar::ProgressBar;
|
|
|
|
pub use self::common::NpmPackageFsResolver;
|
|
pub use self::local::normalize_pkg_name_for_node_modules_deno_folder;
|
|
|
|
use self::global::GlobalNpmPackageResolver;
|
|
use self::local::LocalNpmPackageResolver;
|
|
|
|
use super::cache::NpmCache;
|
|
use super::cache::TarballCache;
|
|
use super::resolution::NpmResolution;
|
|
|
|
#[allow(clippy::too_many_arguments)]
|
|
pub fn create_npm_fs_resolver(
|
|
fs: Arc<dyn FileSystem>,
|
|
npm_cache: Arc<NpmCache>,
|
|
npm_install_deps_provider: &Arc<NpmInstallDepsProvider>,
|
|
progress_bar: &ProgressBar,
|
|
resolution: Arc<NpmResolution>,
|
|
tarball_cache: Arc<TarballCache>,
|
|
maybe_node_modules_path: Option<PathBuf>,
|
|
system_info: NpmSystemInfo,
|
|
lifecycle_scripts: LifecycleScriptsConfig,
|
|
) -> Arc<dyn NpmPackageFsResolver> {
|
|
match maybe_node_modules_path {
|
|
Some(node_modules_folder) => Arc::new(LocalNpmPackageResolver::new(
|
|
npm_cache,
|
|
fs,
|
|
npm_install_deps_provider.clone(),
|
|
progress_bar.clone(),
|
|
resolution,
|
|
tarball_cache,
|
|
node_modules_folder,
|
|
system_info,
|
|
lifecycle_scripts,
|
|
)),
|
|
None => Arc::new(GlobalNpmPackageResolver::new(
|
|
npm_cache,
|
|
fs,
|
|
tarball_cache,
|
|
resolution,
|
|
system_info,
|
|
)),
|
|
}
|
|
}
|