2024-01-01 14:58:21 -05:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-09-30 12:06:38 -04:00
|
|
|
|
|
|
|
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::util::progress_bar::ProgressBar;
|
|
|
|
|
|
|
|
pub use self::common::NpmPackageFsResolver;
|
2023-10-02 17:53:55 -04:00
|
|
|
|
2023-09-30 12:06:38 -04:00
|
|
|
use self::global::GlobalNpmPackageResolver;
|
|
|
|
use self::local::LocalNpmPackageResolver;
|
|
|
|
|
2023-10-02 17:53:55 -04:00
|
|
|
use super::cache::NpmCache;
|
2024-06-02 21:39:13 -04:00
|
|
|
use super::cache::TarballCache;
|
2023-10-02 17:53:55 -04:00
|
|
|
use super::resolution::NpmResolution;
|
2023-09-30 12:06:38 -04:00
|
|
|
|
|
|
|
pub fn create_npm_fs_resolver(
|
|
|
|
fs: Arc<dyn FileSystem>,
|
2024-06-02 21:39:13 -04:00
|
|
|
npm_cache: Arc<NpmCache>,
|
2023-09-30 12:06:38 -04:00
|
|
|
progress_bar: &ProgressBar,
|
|
|
|
resolution: Arc<NpmResolution>,
|
2024-06-03 17:17:08 -04:00
|
|
|
tarball_cache: Arc<TarballCache>,
|
2023-09-30 12:06:38 -04:00
|
|
|
maybe_node_modules_path: Option<PathBuf>,
|
|
|
|
system_info: NpmSystemInfo,
|
|
|
|
) -> Arc<dyn NpmPackageFsResolver> {
|
|
|
|
match maybe_node_modules_path {
|
|
|
|
Some(node_modules_folder) => Arc::new(LocalNpmPackageResolver::new(
|
2024-06-02 21:39:13 -04:00
|
|
|
npm_cache,
|
2023-09-30 12:06:38 -04:00
|
|
|
fs,
|
|
|
|
progress_bar.clone(),
|
|
|
|
resolution,
|
2024-06-02 21:39:13 -04:00
|
|
|
tarball_cache,
|
|
|
|
node_modules_folder,
|
2023-09-30 12:06:38 -04:00
|
|
|
system_info,
|
|
|
|
)),
|
|
|
|
None => Arc::new(GlobalNpmPackageResolver::new(
|
2024-06-02 21:39:13 -04:00
|
|
|
npm_cache,
|
2023-09-30 12:06:38 -04:00
|
|
|
fs,
|
2024-06-02 21:39:13 -04:00
|
|
|
tarball_cache,
|
2023-09-30 12:06:38 -04:00
|
|
|
resolution,
|
|
|
|
system_info,
|
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|