Replace editorconfig with editorconfig-without-wasm (#18452)

This commit is contained in:
fisker Cheung authored and GitHub committed 2025-12-09 23:21:27 +08:00
1 parent f2ce657254
commit a9c0ce927b
9 files changed
+61 -79

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
#### Fix crashes on formatting directory names that have special characters (#18452 by @fisker)
<!-- prettier-ignore -->
```sh
prettier . --check
# Prettier stable
[error] Invalid configuration for file "<CWD>\test\username[repo-name]\.editorconfig":
[error] Invalid regular expression: /^(?=.)username[repo-name]$/: Range out of order in character class
# Prettier main
Checking formatting...
[warn] test/username[repo-name]/test.js
[warn] Code style issues found in the above file. Run Prettier with --write to fix.
```
+1 -1
View File
@@ -65,7 +65,7 @@
"dashify": "2.0.0",
"deno-path-from-file-url": "0.0.4",
"diff": "8.0.2",
"editorconfig": "0.15.3",
"editorconfig-without-wasm": "0.0.4",
"emoji-regex": "10.6.0",
"escape-string-regexp": "5.0.0",
"espree": "11.0.0",
@@ -159,7 +159,7 @@ function setupOnLoadListener(build, { concepts, replacements, processors }) {
let text = original;
for (const process of processFunctions) {
text = process(text, file);
text = await process(text, file);
}
// For files not JavaScript, we need add correct `loader` to the result,
+7 -10
View File
@@ -42,17 +42,14 @@ const mainModule = {
createNodejsFileConfig({
input: "src/index.js",
replaceModule: [
// `editorconfig` use a older version of `semver` and only uses `semver.gte`
// We don't need semver since we don't use `options.version`
{
module: require.resolve("editorconfig"),
find: 'var semver = __importStar(require("semver"));',
replacement: outdent`
var semver = {
gte: require(${JSON.stringify(
require.resolve("semver/functions/gte"),
)})
};
`,
module: require.resolve("editorconfig-without-wasm"),
process(text) {
text = text.replace("import * as semver from 'semver';", "");
text = text.replace("semver.gte(version, '0.10.0')", "true");
return text;
},
},
{
module: require.resolve("n-readlines"),
+2 -2
View File
@@ -1,5 +1,5 @@
import path from "node:path";
import editorconfig from "editorconfig";
import { parse as parseEditorconfig } from "editorconfig-without-wasm";
import {
clearFindProjectRootCache,
findProjectRoot,
@@ -23,7 +23,7 @@ function clearEditorconfigCache() {
async function loadEditorconfigInternal(file, { shouldCache }) {
const directory = path.dirname(file);
const root = await findProjectRoot(directory, { shouldCache });
const editorConfig = await editorconfig.parse(file, { root });
const editorConfig = await parseEditorconfig(file, { root });
const config = editorConfigToPrettier(editorConfig);
return config;
}
@@ -10,10 +10,11 @@ exports[`ignores file name contains emoji 1`] = `
exports[`square-brackets-and-dash 1`] = `
{
"status": 2,
"stderr": "[error] Invalid configuration for file "<cli>/special-characters-in-path/square-brackets-and-dash/test/username[repo-name]/.editorconfig":
[error] Invalid regular expression: /^(?=.)username[repo-name]$/: Range out of order in character class",
"stdout": "",
"status": 0,
"stderr": "",
"stdout": "function a() {
const foo = "bar";
}",
"write": [],
}
`;
@@ -22,7 +22,6 @@ describe("stdin", () => {
});
});
// This is a failed test for #15188
describe("square-brackets-and-dash", () => {
runCli("cli/special-characters-in-path/square-brackets-and-dash", [
"test",
@@ -1,11 +1,19 @@
This is a test fixture for an existing issue.
This is a test fixture for the following issue.
Issue link:
https://github.com/prettier/prettier/issues/15188
Can debug with this command
Can debug with
Development version
```sh
node ../../../../../bin/prettier test
node ../../../../../bin/prettier test --check
```
Stable version
```sh
node ../../../../../node_modules/prettier/bin/prettier.cjs test test --check
```
+19 -57
View File
@@ -3532,20 +3532,13 @@ __metadata:
languageName: node
linkType: hard
"commander@npm:^14.0.2":
"commander@npm:^14.0.0, commander@npm:^14.0.2":
version: 14.0.2
resolution: "commander@npm:14.0.2"
checksum: 10/2d202db5e5f9bb770112a3c1579b893d17ac6f6d932183077308bdd96d0f87f0bbe6a68b5b9ed2cf3b2514be6bb7de637480703c0e2db9741ee1b383237deb26
languageName: node
linkType: hard
"commander@npm:^2.19.0":
version: 2.20.3
resolution: "commander@npm:2.20.3"
checksum: 10/90c5b6898610cd075984c58c4f88418a4fb44af08c1b1415e9854c03171bec31b336b7f3e4cefe33de994b3f12b03c5e2d638da4316df83593b9e82554e7e95b
languageName: node
linkType: hard
"comment-json@npm:^4.4.1":
version: 4.4.1
resolution: "comment-json@npm:4.4.1"
@@ -3912,17 +3905,17 @@ __metadata:
languageName: node
linkType: hard
"editorconfig@npm:0.15.3":
version: 0.15.3
resolution: "editorconfig@npm:0.15.3"
"editorconfig-without-wasm@npm:0.0.4":
version: 0.0.4
resolution: "editorconfig-without-wasm@npm:0.0.4"
dependencies:
commander: "npm:^2.19.0"
lru-cache: "npm:^4.1.5"
semver: "npm:^5.6.0"
sigmund: "npm:^1.0.1"
commander: "npm:^14.0.0"
ini-simple-parser: "npm:^1.0.1"
minimatch: "npm:10.0.1"
semver: "npm:^7.7.2"
bin:
editorconfig: bin/editorconfig
checksum: 10/d82b32cc4e8f5a873b868aedd07056d62afb00c1453a3214bcef7799ff045c4c13146731c7648e5b8397b9efc71c1896733ad97a211d05cc8933364273321295
checksum: 10/ee2dbe40e330ff8cef6a8136dd2dd831e4f1524e2313f7e0856194a38a6bde1b576f7fe0ce4d644281eef154b5cfbe1e63db0b6e7786b273935b43f19f252e2f
languageName: node
linkType: hard
@@ -6564,16 +6557,6 @@ __metadata:
languageName: node
linkType: hard
"lru-cache@npm:^4.1.5":
version: 4.1.5
resolution: "lru-cache@npm:4.1.5"
dependencies:
pseudomap: "npm:^1.0.2"
yallist: "npm:^2.1.2"
checksum: 10/9ec7d73f11a32cba0e80b7a58fdf29970814c0c795acaee1a6451ddfd609bae6ef9df0837f5bbeabb571ecd49c1e2d79e10e9b4ed422cfba17a0cb6145b018a9
languageName: node
linkType: hard
"lru-cache@npm:^5.1.1":
version: 5.1.1
resolution: "lru-cache@npm:5.1.1"
@@ -6695,6 +6678,15 @@ __metadata:
languageName: node
linkType: hard
"minimatch@npm:10.0.1":
version: 10.0.1
resolution: "minimatch@npm:10.0.1"
dependencies:
brace-expansion: "npm:^2.0.1"
checksum: 10/082e7ccbc090d5f8c4e4e029255d5a1d1e3af37bda837da2b8b0085b1503a1210c91ac90d9ebfe741d8a5f286ece820a1abb4f61dc1f82ce602a055d461d93f3
languageName: node
linkType: hard
"minimatch@npm:^10.1.1":
version: 10.1.1
resolution: "minimatch@npm:10.1.1"
@@ -7555,7 +7547,7 @@ __metadata:
dashify: "npm:2.0.0"
deno-path-from-file-url: "npm:0.0.4"
diff: "npm:8.0.2"
editorconfig: "npm:0.15.3"
editorconfig-without-wasm: "npm:0.0.4"
emoji-regex: "npm:10.6.0"
enquirer: "npm:2.4.1"
esbuild: "npm:0.27.0"
@@ -7722,13 +7714,6 @@ __metadata:
languageName: node
linkType: hard
"pseudomap@npm:^1.0.2":
version: 1.0.2
resolution: "pseudomap@npm:1.0.2"
checksum: 10/856c0aae0ff2ad60881168334448e898ad7a0e45fe7386d114b150084254c01e200c957cf378378025df4e052c7890c5bd933939b0e0d2ecfcc1dc2f0b2991f5
languageName: node
linkType: hard
"punycode@npm:^2.1.0":
version: 2.3.1
resolution: "punycode@npm:2.3.1"
@@ -8003,15 +7988,6 @@ __metadata:
languageName: node
linkType: hard
"semver@npm:^5.6.0":
version: 5.7.2
resolution: "semver@npm:5.7.2"
bin:
semver: bin/semver
checksum: 10/fca14418a174d4b4ef1fecb32c5941e3412d52a4d3d85165924ce3a47fbc7073372c26faf7484ceb4bbc2bde25880c6b97e492473dc7e9708fdfb1c6a02d546e
languageName: node
linkType: hard
"semver@npm:^6.3.1":
version: 6.3.1
resolution: "semver@npm:6.3.1"
@@ -8051,13 +8027,6 @@ __metadata:
languageName: node
linkType: hard
"sigmund@npm:^1.0.1":
version: 1.0.1
resolution: "sigmund@npm:1.0.1"
checksum: 10/5c199a9f7b24483bec8289dcaf72a0280382fc6ece47a19ddb3c8599b2f9126d4e113710a69fba2c70e22a7f2eadcd8adefb142700164ef19699f4ea1c02cbaa
languageName: node
linkType: hard
"signal-exit@npm:^3.0.3":
version: 3.0.7
resolution: "signal-exit@npm:3.0.7"
@@ -9259,13 +9228,6 @@ __metadata:
languageName: node
linkType: hard
"yallist@npm:^2.1.2":
version: 2.1.2
resolution: "yallist@npm:2.1.2"
checksum: 10/75fc7bee4821f52d1c6e6021b91b3e079276f1a9ce0ad58da3c76b79a7e47d6f276d35e206a96ac16c1cf48daee38a8bb3af0b1522a3d11c8ffe18f898828832
languageName: node
linkType: hard
"yallist@npm:^3.0.2":
version: 3.1.1
resolution: "yallist@npm:3.1.1"