feat: add stylelint v17 support#377
Conversation
53245f9 to
9a3eadf
Compare
Use dynamic import() to load stylelint, enabling support for ESM-only stylelint v17 while maintaining backward compatibility with v13-v16. - Switch from require() to dynamic import() for loading stylelint - Update formatter loading to handle promise-based formatters (v16+) - Add module: node16 to tsconfig for dynamic import support - Bump minimum Node.js version to 20.19.0 (required by stylelint v17) - Update tests to use stylelintPath option for mocking Closes webpack#376 BREAKING CHANGE: Minimum Node.js version is now 20.19.0
a98426c to
4744f0e
Compare
tsconfig.json
Outdated
| "types": ["node"], | ||
| "resolveJsonModule": true | ||
| "resolveJsonModule": true, | ||
| "skipLibCheck": true |
There was a problem hiding this comment.
@alexander-akait How should we handle this error?
Error: node_modules/stylelint/types/stylelint/index.d.ts(2,15): error TS2305: Module '"globby"' has no exported member 'GlobbyOptions'.
Error: node_modules/stylelint/types/stylelint/index.d.ts(2,36): error TS1541: Type-only import of an ECMAScript module from a CommonJS module must have a 'resolution-mode' attribute.
ERROR: "build:types" exited with 1.```
There was a problem hiding this comment.
Note that stylelint itself uses skipLibCheck: true in their tsconfig as of stylelint/stylelint#8875
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. Thanks for integrating Codecov - We've got you covered ☂️ |
|
@ricardogobbosouza Can you look at this too? |
It seems good.. |
|
Waiting for this typing problem in styelint version 17 |
|
Yeah, let's wait a fix from stylelint team |
|
@ricardogobbosouza @alexander-akait stylelint/stylelint#9007 Updated the |
|
@ricardogobbosouza Can you review code and make a release when you will have time, thank you |
|
Previously, Now, with Load errors are still managed as they propagate through the |
|
Should we also add Stylelint 17 to the CI matrix for Node.js 20/22/24? |
|
Thanks @zalishchuk |
Note
This PR was created with assistance from Claude. Please review thoroughly.
Summary
Add support for stylelint v17, which removed CommonJS support and is now ESM-only.
This PR uses dynamic
import()to load stylelint, enabling support for ESM-only stylelint v17 while maintaining backward compatibility with v13-v16.Closes #376
Technical notes
tsconfig.jsonaddsskipLibCheck: truebecause stylelint v17's type definitions importGlobbyOptionsfrom globby, but globby v16 exportsOptionsinsteadstylelintPathoption instead ofjest.mock()because Jest's module mocking doesn't intercept dynamicimport()calls in CommonJS context. I investigatedjest.unstable_mockModule()which does work, but it requires running Jest in native ESM mode (--experimental-vm-modules) which would require adding.jsextensions to all test utility imports. UsingstylelintPathis more practical - it uses stable APIs and tests a real plugin feature.What kind of change does this PR introduce?
feat (new feature)
Did you add tests for your changes?
Yes. All 55 existing tests pass. Tests were updated to use the
stylelintPathoption for mocking instead ofjest.mock(), since Jest's module mocking doesn't work reliably with dynamicimport().Does this PR introduce a breaking change?
Yes. Minimum Node.js version is now 20.19.0 (required by stylelint v17).
If relevant, what needs to be documented once your changes are merged or what have you already documented?
stylelint ^17.0.0node >= 20.19.0