summaryrefslogtreecommitdiff
path: root/cli/args/package_json.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-02-23 12:33:23 -0500
committerGitHub <noreply@github.com>2023-02-23 17:33:23 +0000
commit6233c0aff0dc9e58b02dfc9499048385bbf836c6 (patch)
treeb6f09c73bbaca669e22b5f5c6f30961a87f78be5 /cli/args/package_json.rs
parent344317ec501fa124f0c74b44035fa4516999dce6 (diff)
fix(npm): support bare specifiers in package.json having a path (#17903)
For example `import * as test from "package/path.js"`
Diffstat (limited to 'cli/args/package_json.rs')
-rw-r--r--cli/args/package_json.rs11
1 files changed, 5 insertions, 6 deletions
diff --git a/cli/args/package_json.rs b/cli/args/package_json.rs
index 73bcfb582..667918cd1 100644
--- a/cli/args/package_json.rs
+++ b/cli/args/package_json.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
+use std::collections::BTreeMap;
use std::collections::HashMap;
use std::path::Path;
use std::path::PathBuf;
@@ -36,10 +37,10 @@ pub fn parse_dep_entry_name_and_raw_version<'a>(
/// entries to npm specifiers which can then be used in the resolver.
pub fn get_local_package_json_version_reqs(
package_json: &PackageJson,
-) -> Result<HashMap<String, NpmPackageReq>, AnyError> {
+) -> Result<BTreeMap<String, NpmPackageReq>, AnyError> {
fn insert_deps(
deps: Option<&HashMap<String, String>>,
- result: &mut HashMap<String, NpmPackageReq>,
+ result: &mut BTreeMap<String, NpmPackageReq>,
) -> Result<(), AnyError> {
if let Some(deps) = deps {
for (key, value) in deps {
@@ -73,9 +74,7 @@ pub fn get_local_package_json_version_reqs(
let deps = package_json.dependencies.as_ref();
let dev_deps = package_json.dev_dependencies.as_ref();
- let mut result = HashMap::with_capacity(
- deps.map(|d| d.len()).unwrap_or(0) + dev_deps.map(|d| d.len()).unwrap_or(0),
- );
+ let mut result = BTreeMap::new();
// insert the dev dependencies first so the dependencies will
// take priority and overwrite any collisions
@@ -166,7 +165,7 @@ mod test {
let result = get_local_package_json_version_reqs(&package_json).unwrap();
assert_eq!(
result,
- HashMap::from([
+ BTreeMap::from([
(
"test".to_string(),
NpmPackageReq::from_str("test@^1.2").unwrap()