summaryrefslogtreecommitdiff
path: root/cli/args/mod.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-08-01 20:49:09 -0400
committerGitHub <noreply@github.com>2023-08-02 00:49:09 +0000
commit1cefa831fd74b14121494045a347024502d74e34 (patch)
treecc7791cf674e427fe4165262db416e6c537e99a3 /cli/args/mod.rs
parent36ae37604a0ddab4349df6eb6fafb8ae39fd20fc (diff)
feat(unstable): optional `deno_modules` directory (#19977)
Closes #15633
Diffstat (limited to 'cli/args/mod.rs')
-rw-r--r--cli/args/mod.rs40
1 files changed, 38 insertions, 2 deletions
diff --git a/cli/args/mod.rs b/cli/args/mod.rs
index 68cd3faa7..9df26b063 100644
--- a/cli/args/mod.rs
+++ b/cli/args/mod.rs
@@ -539,6 +539,7 @@ pub struct CliOptions {
flags: Flags,
initial_cwd: PathBuf,
maybe_node_modules_folder: Option<PathBuf>,
+ maybe_deno_modules_folder: Option<PathBuf>,
maybe_config_file: Option<ConfigFile>,
maybe_package_json: Option<PackageJson>,
maybe_lockfile: Option<Arc<Mutex<Lockfile>>>,
@@ -567,13 +568,18 @@ impl CliOptions {
eprintln!("{}", colors::yellow(msg));
}
- let maybe_node_modules_folder = resolve_local_node_modules_folder(
+ let maybe_node_modules_folder = resolve_node_modules_folder(
&initial_cwd,
&flags,
maybe_config_file.as_ref(),
maybe_package_json.as_ref(),
)
.with_context(|| "Resolving node_modules folder.")?;
+ let maybe_deno_modules_folder = resolve_deno_modules_folder(
+ &initial_cwd,
+ &flags,
+ maybe_config_file.as_ref(),
+ );
Ok(Self {
flags,
@@ -582,6 +588,7 @@ impl CliOptions {
maybe_lockfile,
maybe_package_json,
maybe_node_modules_folder,
+ maybe_deno_modules_folder,
overrides: Default::default(),
})
}
@@ -865,6 +872,10 @@ impl CliOptions {
.map(|path| ModuleSpecifier::from_directory_path(path).unwrap())
}
+ pub fn deno_modules_dir_path(&self) -> Option<&PathBuf> {
+ self.maybe_deno_modules_folder.as_ref()
+ }
+
pub fn resolve_root_cert_store_provider(
&self,
) -> Arc<dyn RootCertStoreProvider> {
@@ -1159,7 +1170,7 @@ impl CliOptions {
}
/// Resolves the path to use for a local node_modules folder.
-fn resolve_local_node_modules_folder(
+fn resolve_node_modules_folder(
cwd: &Path,
flags: &Flags,
maybe_config_file: Option<&ConfigFile>,
@@ -1188,6 +1199,31 @@ fn resolve_local_node_modules_folder(
Ok(Some(canonicalize_path_maybe_not_exists(&path)?))
}
+fn resolve_deno_modules_folder(
+ cwd: &Path,
+ flags: &Flags,
+ maybe_config_file: Option<&ConfigFile>,
+) -> Option<PathBuf> {
+ let use_deno_modules_dir = flags
+ .deno_modules_dir
+ .or_else(|| maybe_config_file.and_then(|c| c.deno_modules_dir()))
+ .unwrap_or(false);
+ // Unlike the node_modules directory, there is no need to canonicalize
+ // this directory because it's just used as a cache and the resolved
+ // specifier is not based on the canonicalized path (unlike the modules
+ // in the node_modules folder).
+ if !use_deno_modules_dir {
+ None
+ } else if let Some(config_path) = maybe_config_file
+ .as_ref()
+ .and_then(|c| c.specifier.to_file_path().ok())
+ {
+ Some(config_path.parent().unwrap().join("deno_modules"))
+ } else {
+ Some(cwd.join("deno_modules"))
+ }
+}
+
fn resolve_import_map_specifier(
maybe_import_map_path: Option<&str>,
maybe_config_file: Option<&ConfigFile>,