Skip to content

Commit a910bc7

Browse files
dsherretcrowlKats
authored andcommitted
fix(node): support wildcards in package.json imports (#24794)
(cherry picked from commit 7a38101)
1 parent 98ecb56 commit a910bc7

File tree

9 files changed

+37
-4
lines changed

9 files changed

+37
-4
lines changed

ext/node_resolver/resolution.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
597597
for key in imports.keys() {
598598
let pattern_index = key.find('*');
599599
if let Some(pattern_index) = pattern_index {
600-
let key_sub = &key[0..=pattern_index];
600+
let key_sub = &key[0..pattern_index];
601601
if name.starts_with(key_sub) {
602602
let pattern_trailer = &key[pattern_index + 1..];
603603
if name.len() > key.len()
@@ -607,8 +607,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
607607
{
608608
best_match = key;
609609
best_match_subpath = Some(
610-
name[pattern_index..=(name.len() - pattern_trailer.len())]
611-
.to_string(),
610+
&name[pattern_index..(name.len() - pattern_trailer.len())],
612611
);
613612
}
614613
}
@@ -620,7 +619,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
620619
let maybe_resolved = self.resolve_package_target(
621620
package_json_path.as_ref().unwrap(),
622621
target,
623-
&best_match_subpath.unwrap(),
622+
best_match_subpath.unwrap(),
624623
best_match,
625624
maybe_referrer,
626625
referrer_kind,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"envs": {
3+
"DENO_FUTURE": "1"
4+
},
5+
"args": "run main.mjs",
6+
"output": "main.out"
7+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { add, subtract } from "package";
2+
3+
console.log(add(1, 2));
4+
console.log(subtract(4, 2));
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
3
2+
2

tests/specs/node/imports_wildcard/node_modules/package/index.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/specs/node/imports_wildcard/node_modules/package/inner/add/index.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/specs/node/imports_wildcard/node_modules/package/native/subtract.js

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/specs/node/imports_wildcard/node_modules/package/package.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

0 commit comments

Comments
 (0)