diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2024-09-09 16:19:29 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-09 20:19:29 +0000 |
commit | 72f025c74320ffd6df9758ac53c74db68e0a3e10 (patch) | |
tree | b7c72a6055cbd13bedcc0132af0c1f96342858ea /cli/args/package_json.rs | |
parent | 1e0ac609b57b9efdafd54de4cb56f98c507c032f (diff) |
fix: remove recently added deno.json node_modules aliasing (#25542)
This was initially added in #25399 in order to make transitioning over
from package.json to deno.json more easy, but it causes some problems
that are shown in the issue and it also means that the output of `deno
install` would have different resolution than `npm install`. Overall, I
think it's too much complexity to be smarter about this and it's
probably best to not do it. If someone needs an aliased folder then they
should keep using a package.json
Closes #25538
Diffstat (limited to 'cli/args/package_json.rs')
-rw-r--r-- | cli/args/package_json.rs | 34 |
1 files changed, 9 insertions, 25 deletions
diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs index b9f0919d5..2529e54fd 100644 --- a/cli/args/package_json.rs +++ b/cli/args/package_json.rs @@ -1,6 +1,5 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. -use std::collections::HashSet; use std::path::PathBuf; use std::sync::Arc; @@ -10,18 +9,16 @@ use deno_package_json::PackageJsonDepValue; use deno_semver::npm::NpmPackageReqReference; use deno_semver::package::PackageReq; -use crate::util::path::is_banned_path_char; - #[derive(Debug)] pub struct InstallNpmRemotePkg { - pub alias: String, + pub alias: Option<String>, pub base_dir: PathBuf, pub req: PackageReq, } #[derive(Debug)] pub struct InstallNpmWorkspacePkg { - pub alias: String, + pub alias: Option<String>, pub target_dir: PathBuf, } @@ -43,16 +40,13 @@ impl NpmInstallDepsProvider { let workspace_npm_pkgs = workspace.npm_packages(); for (_, folder) in workspace.config_folders() { - let mut deno_json_aliases = HashSet::new(); - // deal with the deno.json first because it takes precedence during resolution if let Some(deno_json) = &folder.deno_json { // don't bother with externally referenced import maps as users // should inline their import map to get this behaviour if let Some(serde_json::Value::Object(obj)) = &deno_json.json.imports { - deno_json_aliases.reserve(obj.len()); let mut pkg_pkgs = Vec::with_capacity(obj.len()); - for (alias, value) in obj { + for (_alias, value) in obj { let serde_json::Value::String(specifier) = value else { continue; }; @@ -60,11 +54,6 @@ impl NpmInstallDepsProvider { else { continue; }; - // skip any aliases with banned characters - if alias.chars().any(|c| c == '\\' || is_banned_path_char(c)) { - continue; - } - deno_json_aliases.insert(alias.to_lowercase()); let pkg_req = npm_req_ref.into_inner().req; let workspace_pkg = workspace_npm_pkgs .iter() @@ -72,12 +61,12 @@ impl NpmInstallDepsProvider { if let Some(pkg) = workspace_pkg { workspace_pkgs.push(InstallNpmWorkspacePkg { - alias: alias.to_string(), + alias: None, target_dir: pkg.pkg_json.dir_path().to_path_buf(), }); } else { pkg_pkgs.push(InstallNpmRemotePkg { - alias: alias.to_string(), + alias: None, base_dir: deno_json.dir_path(), req: pkg_req, }); @@ -85,7 +74,7 @@ impl NpmInstallDepsProvider { } // sort within each package (more like npm resolution) - pkg_pkgs.sort_by(|a, b| a.alias.cmp(&b.alias)); + pkg_pkgs.sort_by(|a, b| a.req.cmp(&b.req)); remote_pkgs.extend(pkg_pkgs); } } @@ -97,11 +86,6 @@ impl NpmInstallDepsProvider { let Ok(dep) = dep else { continue; }; - if deno_json_aliases.contains(&alias.to_lowercase()) { - // aliases in deno.json take precedence over package.json, so - // since this can't be resolved don't bother installing it - continue; - } match dep { PackageJsonDepValue::Req(pkg_req) => { let workspace_pkg = workspace_npm_pkgs.iter().find(|pkg| { @@ -112,12 +96,12 @@ impl NpmInstallDepsProvider { if let Some(pkg) = workspace_pkg { workspace_pkgs.push(InstallNpmWorkspacePkg { - alias, + alias: Some(alias), target_dir: pkg.pkg_json.dir_path().to_path_buf(), }); } else { pkg_pkgs.push(InstallNpmRemotePkg { - alias, + alias: Some(alias), base_dir: pkg_json.dir_path().to_path_buf(), req: pkg_req, }); @@ -128,7 +112,7 @@ impl NpmInstallDepsProvider { pkg.matches_name_and_version_req(&alias, &version_req) }) { workspace_pkgs.push(InstallNpmWorkspacePkg { - alias, + alias: Some(alias), target_dir: pkg.pkg_json.dir_path().to_path_buf(), }); } |