diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-09-22 11:17:02 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-22 11:17:02 -0400 |
commit | 716005a0d4afd1042fa75d8bdc32fd13e9ebe95f (patch) | |
tree | 4c417eb7b91d6203aacba7dcd81bee3f13c0cfd3 /cli/args/mod.rs | |
parent | 9a216806d514b5f41c73c777010572cdf3c51eab (diff) |
feat(npm): add flag for creating and resolving npm packages to a local node_modules folder (#15971)
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r-- | cli/args/mod.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs index e4c0d8556..1e0c72b1c 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -42,6 +42,7 @@ use crate::emit::TsConfigWithIgnoredOptions; use crate::emit::TsTypeLib; use crate::file_fetcher::get_root_cert_store; use crate::file_fetcher::CacheSetting; +use crate::fs_util; use crate::lockfile::Lockfile; use crate::version; @@ -146,6 +147,24 @@ impl CliOptions { self.overrides.import_map_specifier = Some(path); } + /// Resolves the path to use for a local node_modules folder. + pub fn resolve_local_node_modules_folder( + &self, + ) -> Result<Option<PathBuf>, AnyError> { + let path = if !self.flags.node_modules_dir { + return Ok(None); + } else if let Some(config_path) = self + .maybe_config_file + .as_ref() + .and_then(|c| c.specifier.to_file_path().ok()) + { + config_path.parent().unwrap().join("node_modules") + } else { + std::env::current_dir()?.join("node_modules") + }; + Ok(Some(fs_util::canonicalize_path_maybe_not_exists(&path)?)) + } + pub fn resolve_root_cert_store(&self) -> Result<RootCertStore, AnyError> { get_root_cert_store( None, |