summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKiryl Dziamura <2wontem@gmail.com>2023-01-14 00:57:24 +0100
committerGitHub <noreply@github.com>2023-01-14 00:57:24 +0100
commit934ed8e7d1709927e2ab0f7e0716b320b3e575b1 (patch)
tree1c45039b5aa6f94b550575e297970a7c91a1096b
parentb23b4e231c5c6a4f500e69fd3e19955865b62141 (diff)
fix(npm): use original node regex in npm resolution (#17404)
Fixes regex for matching conditional exports in a package. Updated to the same regex Node.js uses.
-rw-r--r--cli/tests/testdata/npm/conditional_exports/main.js2
-rw-r--r--cli/tests/testdata/npm/conditional_exports/main.out1
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/foo.js3
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json3
-rw-r--r--ext/node/resolution.rs2
5 files changed, 9 insertions, 2 deletions
diff --git a/cli/tests/testdata/npm/conditional_exports/main.js b/cli/tests/testdata/npm/conditional_exports/main.js
index a40e2e689..eb243a52c 100644
--- a/cli/tests/testdata/npm/conditional_exports/main.js
+++ b/cli/tests/testdata/npm/conditional_exports/main.js
@@ -1,10 +1,12 @@
import mod from "npm:@denotest/conditional-exports";
+import foo from "npm:@denotest/conditional-exports/foo.js";
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";
import supportsESM from "npm:supports-esm";
console.log(mod);
+console.log(foo);
console.log(client);
console.log(clientFoo);
console.log(clientBar);
diff --git a/cli/tests/testdata/npm/conditional_exports/main.out b/cli/tests/testdata/npm/conditional_exports/main.out
index a24f456e3..b374d9f6c 100644
--- a/cli/tests/testdata/npm/conditional_exports/main.out
+++ b/cli/tests/testdata/npm/conditional_exports/main.out
@@ -7,6 +7,7 @@ Download http://localhost:4545/npm/registry/@ljharb/has-package-exports-patterns
Download http://localhost:4545/npm/registry/has-package-exports/has-package-exports-1.3.0.tgz
Download http://localhost:4545/npm/registry/supports-esm/supports-esm-1.0.0.tgz
{ hello: "from esm" }
+{ hello: "from foo" }
{ hello: "from esm client" }
{ hello: "from esm client foo" }
{ hello: "from esm client bar" }
diff --git a/cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/foo.js b/cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/foo.js
new file mode 100644
index 000000000..6060c8a67
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/foo.js
@@ -0,0 +1,3 @@
+export default {
+ hello: "from foo",
+}
diff --git a/cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json
index c02015835..5a2536aa0 100644
--- a/cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json
+++ b/cli/tests/testdata/npm/registry/@denotest/conditional-exports/1.0.0/package.json
@@ -15,6 +15,7 @@
"./client/*": {
"types": "./types/src/client/*.d.ts",
"import": "./esm/client/*.js"
- }
+ },
+ "./*": "./*"
}
}
diff --git a/ext/node/resolution.rs b/ext/node/resolution.rs
index e930215fd..81a2521b5 100644
--- a/ext/node/resolution.rs
+++ b/ext/node/resolution.rs
@@ -339,7 +339,7 @@ fn resolve_package_target_string(
));
}
let invalid_segment_re =
- Regex::new(r"(^|\|/)(..?|node_modules)(\|/|$)").expect("bad regex");
+ Regex::new(r"(^|\\|/)(\.\.?|node_modules)(\\|/|$)").expect("bad regex");
let pattern_re = Regex::new(r"\*").expect("bad regex");
if !target.starts_with("./") {
if internal && !target.starts_with("../") && !target.starts_with('/') {