feat(textlint)!: convert textlint-rule-preset-alma to esm - #263
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Update the peer dependency range for the supported textlint v15 runtime or provide a CommonJS entry point.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Converts the Alma textlint preset from CommonJS to native ESM for textlint v15.
Changes:
- Enables ESM packaging and exports.
- Updates rule and test imports.
- Preserves CommonJS dependency interoperability.
File summaries
| File | Summary |
|---|---|
packages/textlint-rule-preset-alma/rules/terminology.js |
Converts terminology rule imports and exports to ESM. |
packages/textlint-rule-preset-alma/package.json |
Enables ESM; Critical: the textlint: ^12.2.2 peer range is incompatible with the v15 runtime. |
packages/textlint-rule-preset-alma/index.js |
Converts the preset entrypoint to ESM. |
packages/textlint-rule-preset-alma/__tests__/terminology.test.js |
Updates terminology tests for ESM. |
packages/textlint-rule-preset-alma/__tests__/comment-filtering.test.js |
Updates filtering tests for ESM. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
🔵 Needs a closer look
The ESM-only package is incompatible with its declared textlint ^12.2.2 peer range; update the metadata or provide a compatible entry point.
Review details
Suppressed comments (1)
packages/textlint-rule-preset-alma/package.json:14
- Adding
"type": "module"makes the package incompatible with its declaredtextlintpeer range:^12.2.2excludes the v15 runtime this PR targets, and the v12 CommonJS loading path cannot consume this new ESM-only entry point. Update the peer range to the supported v15 version (and the workspace metadata) or provide a v12-compatible entry point.
"type": "module",
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
The textlint peer dependency range remains at ^12.2.2 and should be updated for the ESM/textlint v15 requirement.
Review details
Suppressed comments (1)
packages/textlint-rule-preset-alma/package.json:14
- This makes the published package ESM-only, but
peerDependencies.textlintstill advertises^12.2.2(package.json:48-50). That range is inconsistent with the v15 dynamic-import resolver required to load this entry point: npm consumers using textlint 15 can receive an unsatisfied-peer error, while consumers on textlint 12 are still advertised as supported even though they cannot load the ESM package. Update the peer range (for example, to^15.0.0) as part of this breaking change.
"type": "module",
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🔵 Needs a closer look
Update the textlint peer dependency to accurately encode supported compatibility.
Review details
Suppressed comments (1)
packages/textlint-rule-preset-alma/package.json:14
- Making the package ESM-only means the textlint 12 CommonJS loading path advertised by
peerDependencies.textlint: ^12.2.2is no longer supported, while the v15 runtime used by this change is outside that range. Please update the peer dependency to the supported textlint v15 range (or otherwise encode the actual compatibility boundary) in the same breaking change.
"type": "module",
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Lite
* textlint v15 loads rules, filters, and presets via dynamic import(),
so the preset can now be authored as native esm instead of commonjs
* unwraps the two rule dependencies that ship a ts-compiled `exports.default`
wrapper (common-misspellings, write-good) the same way the old require()
calls did, so behavior is unchanged
* test files converted to esm import syntax to match `"type": "module"`
BREAKING CHANGE: the package is now esm-only (`"type": "module"`). It can no
longer be loaded with `require()` from a commonjs script — only consumption
via textlint's own preset resolution (`--preset` / .textlintrc `rules` key)
is supported, which is unaffected.
* aligns every import in the preset with `import { default as x } from '...'`
instead of mixing bare default imports with a manual `.default` unwrap
fd55470 to
a74af96
Compare
Description
textlint v15 loads rules, filters, and presets through dynamic
import()(see@textlint/config-loader/@textlint/resolver), so a preset package no longer has to be CommonJS. This converts@alma-oss/textlint-rule-preset-almato native ESM ("type": "module") to match, rather than carryingrequire()/module.exportsfor no reason now that the runtime supports better.Two of the preset's rule dependencies (
textlint-rule-common-misspellings,textlint-rule-write-good) ship a TS-compiled CJS module with a doubleexports.defaultwrapper; the ESMimportunwraps that the same way the oldrequire(...).defaultdid, so rule behavior is unchanged. Verified with the package's own test suite (node --test, 8/8 passing) and a realtextlint --preset @alma-oss/textlint-rule-preset-almarun against a sample file.Additional context
This is a breaking change: the package is now ESM-only and can no longer be
require()'d directly from a CommonJS script. Consumption via textlint's own preset resolution (--presetflag or theruleskey in.textlintrc.js) is unaffected, and no other file in this repo requires the package directly.Follow-up (out of scope here): the preset's own rule dependencies are still CommonJS upstream — converting those to ESM would be a separate change in each of their own repos.
Related issues
None.