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;
|
|
|
|
use super::resolution::NpmResolution;
|
2023-09-30 12:06:38 -04:00
|
|
|
|
|
|
|
pub fn create_npm_fs_resolver(
|
|
|
|
fs: Arc<dyn FileSystem>,
|
|
|
|
cache: Arc<NpmCache>,
|
|
|
|
progress_bar: &ProgressBar,
|
|
|
|
resolution: Arc<NpmResolution>,
|
|
|
|
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(
|
|
|
|
fs,
|
|
|
|
cache,
|
|
|
|
progress_bar.clone(),
|
|
|
|
node_modules_folder,
|
|
|
|
resolution,
|
|
|
|
system_info,
|
|
|
|
)),
|
|
|
|
None => Arc::new(GlobalNpmPackageResolver::new(
|
|
|
|
fs,
|
|
|
|
cache,
|
|
|
|
resolution,
|
|
|
|
system_info,
|
|
|
|
)),
|
|
|
|
}
|
|
|
|
}
|