1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(node): support wildcards in package.json imports (#24794)

This commit is contained in:
David Sherret 2024-07-30 13:14:07 -04:00 committed by GitHub
parent 1ba88a7892
commit 7a3810195d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 37 additions and 4 deletions

View file

@ -597,7 +597,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
for key in imports.keys() {
let pattern_index = key.find('*');
if let Some(pattern_index) = pattern_index {
let key_sub = &key[0..=pattern_index];
let key_sub = &key[0..pattern_index];
if name.starts_with(key_sub) {
let pattern_trailer = &key[pattern_index + 1..];
if name.len() > key.len()
@ -607,8 +607,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
{
best_match = key;
best_match_subpath = Some(
name[pattern_index..=(name.len() - pattern_trailer.len())]
.to_string(),
&name[pattern_index..(name.len() - pattern_trailer.len())],
);
}
}
@ -620,7 +619,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
let maybe_resolved = self.resolve_package_target(
package_json_path.as_ref().unwrap(),
target,
&best_match_subpath.unwrap(),
best_match_subpath.unwrap(),
best_match,
maybe_referrer,
referrer_kind,

View file

@ -0,0 +1,7 @@
{
"envs": {
"DENO_FUTURE": "1"
},
"args": "run main.mjs",
"output": "main.out"
}

View file

@ -0,0 +1,4 @@
import { add, subtract } from "package";
console.log(add(1, 2));
console.log(subtract(4, 2));

View file

@ -0,0 +1,2 @@
3
2

View file

@ -0,0 +1,2 @@
module.exports.add = require("#add");
module.exports.subtract = require("#native/subtract");

View file

@ -0,0 +1,3 @@
module.exports = function(a, b) {
return a + b;
};

View file

@ -0,0 +1,3 @@
module.exports = function(a, b) {
return a - b;
};

View file

@ -0,0 +1,11 @@
{
"name": "package",
"imports": {
"#*": {
"default": "./inner/*/index.js"
},
"#native/*": {
"default": "./native/*.js"
}
}
}

View file

@ -0,0 +1,2 @@
{
}