mirror of
https://github.com/denoland/deno.git
synced 2025-09-27 04:39:10 +00:00
fix(npm): conditional exports with wildcards (#15652)
This commit is contained in:
parent
ea838d27a2
commit
2851a98072
10 changed files with 59 additions and 2 deletions
|
@ -68,6 +68,13 @@ itest!(compare_globals {
|
||||||
http_server: true,
|
http_server: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
itest!(conditional_exports {
|
||||||
|
args: "run --allow-read --unstable npm/conditional_exports/main.js",
|
||||||
|
output: "npm/conditional_exports/main.out",
|
||||||
|
envs: env_vars(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(dynamic_import {
|
itest!(dynamic_import {
|
||||||
args: "run --allow-read --allow-env --unstable npm/dynamic_import/main.ts",
|
args: "run --allow-read --allow-env --unstable npm/dynamic_import/main.ts",
|
||||||
output: "npm/dynamic_import/main.out",
|
output: "npm/dynamic_import/main.out",
|
||||||
|
|
9
cli/tests/testdata/npm/conditional_exports/main.js
vendored
Normal file
9
cli/tests/testdata/npm/conditional_exports/main.js
vendored
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
import mod from "npm:@denotest/conditional-exports";
|
||||||
|
import client from "npm:@denotest/conditional-exports/client";
|
||||||
|
import clientFoo from "npm:@denotest/conditional-exports/client/foo";
|
||||||
|
import clientBar from "npm:@denotest/conditional-exports/client/bar";
|
||||||
|
|
||||||
|
console.log(mod);
|
||||||
|
console.log(client);
|
||||||
|
console.log(clientFoo);
|
||||||
|
console.log(clientBar);
|
6
cli/tests/testdata/npm/conditional_exports/main.out
vendored
Normal file
6
cli/tests/testdata/npm/conditional_exports/main.out
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/conditional-exports
|
||||||
|
Download http://localhost:4545/npm/registry/@denotest/conditional-exports/1.0.0.tgz
|
||||||
|
{ hello: "from esm" }
|
||||||
|
{ hello: "from esm client" }
|
||||||
|
{ hello: "from esm client foo" }
|
||||||
|
{ hello: "from esm client bar" }
|
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/cjs/index.cjs
vendored
Normal file
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/cjs/index.cjs
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
module.exports = {
|
||||||
|
hello: "from cjs"
|
||||||
|
};
|
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/client/bar.js
vendored
Normal file
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/client/bar.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default {
|
||||||
|
hello: "from esm client bar",
|
||||||
|
}
|
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/client/foo.js
vendored
Normal file
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/client/foo.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default {
|
||||||
|
hello: "from esm client foo",
|
||||||
|
}
|
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/client/index.js
vendored
Normal file
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/client/index.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default {
|
||||||
|
hello: "from esm client",
|
||||||
|
}
|
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/index.js
vendored
Normal file
3
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/esm/index.js
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export default {
|
||||||
|
hello: "from esm",
|
||||||
|
}
|
20
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json
vendored
Normal file
20
cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json
vendored
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
{
|
||||||
|
"name": "@denotest/conditional-exports",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"type": "module",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"types": "./types/src/index.d.ts",
|
||||||
|
"require": "./cjs/index.cjs",
|
||||||
|
"import": "./esm/index.js"
|
||||||
|
},
|
||||||
|
"./client": {
|
||||||
|
"types": "./types/src/client/index.d.ts",
|
||||||
|
"import": "./esm/client/index.js"
|
||||||
|
},
|
||||||
|
"./client/*": {
|
||||||
|
"types": "./types/src/client/*.d.ts",
|
||||||
|
"import": "./esm/client/*.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -451,7 +451,7 @@ pub fn package_exports_resolve(
|
||||||
for key in package_exports.keys() {
|
for key in package_exports.keys() {
|
||||||
let pattern_index = key.find('*');
|
let pattern_index = key.find('*');
|
||||||
if let Some(pattern_index) = pattern_index {
|
if let Some(pattern_index) = pattern_index {
|
||||||
let key_sub = &key[0..=pattern_index];
|
let key_sub = &key[0..pattern_index];
|
||||||
if package_subpath.starts_with(key_sub) {
|
if package_subpath.starts_with(key_sub) {
|
||||||
// When this reaches EOL, this can throw at the top of the whole function:
|
// When this reaches EOL, this can throw at the top of the whole function:
|
||||||
//
|
//
|
||||||
|
@ -472,7 +472,7 @@ pub fn package_exports_resolve(
|
||||||
best_match = key;
|
best_match = key;
|
||||||
best_match_subpath = Some(
|
best_match_subpath = Some(
|
||||||
package_subpath
|
package_subpath
|
||||||
[pattern_index..=(package_subpath.len() - pattern_trailer.len())]
|
[pattern_index..(package_subpath.len() - pattern_trailer.len())]
|
||||||
.to_string(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue