1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 21:50:00 -05:00

fix(npm): conditional exports with wildcards (#15652)

This commit is contained in:
Bartek Iwańczuk 2022-08-29 19:15:20 +02:00 committed by GitHub
parent ea838d27a2
commit 2851a98072
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 59 additions and 2 deletions

View file

@ -68,6 +68,13 @@ itest!(compare_globals {
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 {
args: "run --allow-read --allow-env --unstable npm/dynamic_import/main.ts",
output: "npm/dynamic_import/main.out",

View 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);

View 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" }

View file

@ -0,0 +1,3 @@
module.exports = {
hello: "from cjs"
};

View file

@ -0,0 +1,3 @@
export default {
hello: "from esm client bar",
}

View file

@ -0,0 +1,3 @@
export default {
hello: "from esm client foo",
}

View file

@ -0,0 +1,3 @@
export default {
hello: "from esm client",
}

View file

@ -0,0 +1,3 @@
export default {
hello: "from esm",
}

View 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"
}
}
}

View file

@ -451,7 +451,7 @@ pub fn package_exports_resolve(
for key in package_exports.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 package_subpath.starts_with(key_sub) {
// 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_subpath = Some(
package_subpath
[pattern_index..=(package_subpath.len() - pattern_trailer.len())]
[pattern_index..(package_subpath.len() - pattern_trailer.len())]
.to_string(),
);
}