-
-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: make plugin-kit
types usable in CommonJS
#143
base: main
Are you sure you want to change the base?
Conversation
const oldSourceText = await readFile("dist/esm/index.d.ts", "utf-8"); | ||
const newSourceText = oldSourceText.replaceAll( | ||
'import("./types.ts")', | ||
'import("./types.ts", { with: { "resolution-mode": "import" } })', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm curious: Will this work with TypeScript 4? And if not, does it matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will not work because TypeScript 4 doesn't support import attributes. The alternative would be renaming types.ts
to types.cts
in dist/cjs
and updating the imports in index.d.cts
accordingly.
Update:
- It works with TypeScript 5.0: https://stackblitz.com/edit/1bf6yn8t-pnhhhn5w
- It doesn't works with TypeScript 4.9: https://stackblitz.com/edit/1bf6yn8t-xqthsa6o
Prerequisites checklist
What is the purpose of this pull request?
This PR ensures that the
plugin-kit
types can be imported from a CommonJS module whenmoduleResolution
is one of'node16'
or'nodenext'
. This is currently not possible because of the way TypeScript handles imports of ESM modules in CommonJS.Repro
What changes did you make? (Give an overview)
Made sure that
packages/plugin/dist/cjs/index.d.cts
uses the"resolution-mode": "import"
import attribute to import./types.ts
.It's not possible to add the import attribute directly to the source code in
packages/plugin-kit/src/config-comment-parser.js
because then the same import attribute would appear also in the generated ESM types, and jsr does not like that (maybe because import attributes are not supported in TypeScript < 5.0).This is not the only possible fix, see also: eslint/json#66 (comment).
Other changes included in this PR:
@eslint/core
a runtime dependency of@eslint/plugin-kit
.@eslint/core
and@eslint/plugin-kit
can be imported from a.cts
file.@eslint/plugin-kit
.Related Issues
Is there anything you'd like reviewers to focus on?