Conversation
|
Will this also solve problems we had in eslint/eslint#19843, since both ESM and CJS entry points of |
mdjermanovic
left a comment
There was a problem hiding this comment.
LGTM, thanks! Would like @nzakas to verify before merging.
If this solves eslint/eslint#19843 and generally unifies types for different entry points, perhaps we should tag it as feat or at least fix?
Now that you mention it, it seems so! I can see that with this change, interface augmentation for rules and settings works also in ESM. For example, currently this config is not producing any errors: But if the CJS types are patched like in this PR, TypeScript recognizes the type mismatches and reports the expected errors: That means we could resume working on eslint/eslint#19843 once this change is released. |
|
Great! Then, I think we can consider this a fix since it unifies exported types so I'm changing the tag to |
Prerequisites checklist
AI acknowledgment
What is the purpose of this pull request?
This PR simplifies CommonJS types by re-exporting ESM types.
Most packages in this repo export types both in CommonJS and ESM format, which is necessary for compatibility with both module systems. Today, the CommonJS declarations duplicate the ESM declarations with only small replacements to match import paths. For example, these are the ESM type declarations for
@eslint/[email protected]:And these are the corresponding, very similar CommonJS declarations:
To avoid the duplication and reduce the published package size, this PR changes the CommonJS type declarations to one single file that just re-exports the ESM types:
This is now possible thanks to the
resolution-modeimport attribute, which has been supported since TypeScript 5.3, the earliest TypeScript version supported by ESLint.This change affects all packages that use the
build:ctsscript, i.e.:compatconfig-arrayconfig-helperscoreobject-schemaplugin-kitWhat changes did you make? (Give an overview)
tools/build-cts.jsscript re-exports ESM type declarations instead of duplicating them.dist/cjs/types.ctsfiles are no longer created.build:ctsscript incorepackage to use the new script.Related Issues
refs eslint/eslint#19920
Is there anything you'd like reviewers to focus on?