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:
parent
1ba88a7892
commit
7a3810195d
9 changed files with 37 additions and 4 deletions
|
@ -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,
|
||||
|
|
7
tests/specs/node/imports_wildcard/__test__.jsonc
Normal file
7
tests/specs/node/imports_wildcard/__test__.jsonc
Normal file
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"envs": {
|
||||
"DENO_FUTURE": "1"
|
||||
},
|
||||
"args": "run main.mjs",
|
||||
"output": "main.out"
|
||||
}
|
4
tests/specs/node/imports_wildcard/main.mjs
Normal file
4
tests/specs/node/imports_wildcard/main.mjs
Normal file
|
@ -0,0 +1,4 @@
|
|||
import { add, subtract } from "package";
|
||||
|
||||
console.log(add(1, 2));
|
||||
console.log(subtract(4, 2));
|
2
tests/specs/node/imports_wildcard/main.out
Normal file
2
tests/specs/node/imports_wildcard/main.out
Normal file
|
@ -0,0 +1,2 @@
|
|||
3
|
||||
2
|
2
tests/specs/node/imports_wildcard/node_modules/package/index.js
generated
vendored
Normal file
2
tests/specs/node/imports_wildcard/node_modules/package/index.js
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
module.exports.add = require("#add");
|
||||
module.exports.subtract = require("#native/subtract");
|
3
tests/specs/node/imports_wildcard/node_modules/package/inner/add/index.js
generated
vendored
Normal file
3
tests/specs/node/imports_wildcard/node_modules/package/inner/add/index.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
module.exports = function(a, b) {
|
||||
return a + b;
|
||||
};
|
3
tests/specs/node/imports_wildcard/node_modules/package/native/subtract.js
generated
vendored
Normal file
3
tests/specs/node/imports_wildcard/node_modules/package/native/subtract.js
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
module.exports = function(a, b) {
|
||||
return a - b;
|
||||
};
|
11
tests/specs/node/imports_wildcard/node_modules/package/package.json
generated
vendored
Normal file
11
tests/specs/node/imports_wildcard/node_modules/package/package.json
generated
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"name": "package",
|
||||
"imports": {
|
||||
"#*": {
|
||||
"default": "./inner/*/index.js"
|
||||
},
|
||||
"#native/*": {
|
||||
"default": "./native/*.js"
|
||||
}
|
||||
}
|
||||
}
|
2
tests/specs/node/imports_wildcard/package.json
Normal file
2
tests/specs/node/imports_wildcard/package.json
Normal file
|
@ -0,0 +1,2 @@
|
|||
{
|
||||
}
|
Loading…
Reference in a new issue