Skip to content

Commit 56c6627

Browse files
committed
fix(linter/plugins): resolve JS plugins only with conditions Node.js supports (#15248)
Fixes the `require` related error described in #14862 (comment). This was happening because Node.js does not use `module` condition but the plugin resolver used that. I aligned the conditions to what Node.js uses (I didn't include `node-addon` because it's not popular and requires detecting `--no-addons` to do it properly). https://nodejs.org/docs/v24.11.0/api/packages.html#conditional-exports I'm not sure why, but the test snapshot doesn't seem stable on my machine. cc @TheAlexLichter refs #14541
1 parent 84ef5ab commit 56c6627

File tree

8 files changed

+98
-5
lines changed

8 files changed

+98
-5
lines changed

apps/oxlint/test/fixtures/load_paths/.oxlintrc.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"plugin11",
1414
"plugin12",
1515
"plugin13",
16-
"plugin14"
16+
"plugin14",
17+
"plugin15",
18+
"plugin16"
1719
],
1820
"rules": {
1921
"plugin1/no-debugger": "error",
@@ -29,6 +31,8 @@
2931
"plugin11/no-debugger": "error",
3032
"plugin12/no-debugger": "error",
3133
"plugin13/no-debugger": "error",
32-
"plugin14/no-debugger": "error"
34+
"plugin14/no-debugger": "error",
35+
"plugin15/no-debugger": "error",
36+
"plugin16/no-debugger": "error"
3337
}
3438
}

apps/oxlint/test/fixtures/load_paths/node_modules/plugin15/index.esm.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/node_modules/plugin15/index.mjs

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/node_modules/plugin15/package.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/node_modules/plugin16/index.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/node_modules/plugin16/package.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/oxlint/test/fixtures/load_paths/output.snap.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,18 @@
4646
: ^^^^^^^^^
4747
`----
4848
49+
x plugin15(no-debugger): Unexpected Debugger Statement
50+
,-[files/index.js:1:1]
51+
1 | debugger;
52+
: ^^^^^^^^^
53+
`----
54+
55+
x plugin16(no-debugger): Unexpected Debugger Statement
56+
,-[files/index.js:1:1]
57+
1 | debugger;
58+
: ^^^^^^^^^
59+
`----
60+
4961
x plugin2(no-debugger): Unexpected Debugger Statement
5062
,-[files/index.js:1:1]
5163
1 | debugger;
@@ -94,7 +106,7 @@
94106
: ^^^^^^^^^
95107
`----
96108
97-
Found 1 warning and 14 errors.
109+
Found 1 warning and 16 errors.
98110
Finished in Xms on 1 file using X threads.
99111
```
100112

crates/oxc_linter/src/config/config_builder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ impl ConfigStoreBuilder {
173173
};
174174

175175
let resolver = Resolver::new(ResolveOptions {
176-
main_fields: vec!["module".into(), "main".into()],
177-
condition_names: vec!["module".into(), "import".into()],
176+
condition_names: vec!["module-sync".into(), "node".into(), "import".into()],
178177
..Default::default()
179178
});
180179

0 commit comments

Comments
 (0)