-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
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
chore: emit .d.cts files #10945
chore: emit .d.cts files #10945
Conversation
c9c53cf
to
7fef940
Compare
This comment was marked as outdated.
This comment was marked as outdated.
47a699f
to
3a369fb
Compare
I think we'll want to run this script in |
3a369fb
to
4f8e39f
Compare
packages/vite/rollup.config.ts
Outdated
name: 'cjs-types', | ||
async generateBundle() { | ||
const promisedSpawn = promisify(spawn) | ||
await promisedSpawn('pnpm', ['build-emit-cjs-types'], { |
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.
So I'm spawning pnpm build-emit-cjs-types
in development mode 😆
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.
Works like a charm ✨
} | ||
|
||
const outFile = file | ||
.replace('/node/', '/node-cjs/') |
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 suppose we should relativize file
before doing this replacement
This will allow CJS projects using "moduleResolution: node16" to import Vite.
faee34b
to
cbd0842
Compare
plugins: [ | ||
...createNodePlugins(false, false, false), | ||
!isProduction && cjsTypesPlugin(), | ||
bundleSizeLimit(160) |
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.
Bumped size limit from 120 to 160
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 not a fan of another new file for CJS only, especially that our CJS API already doesn't have full coverage, and we're pushing towards ESM. Maybe it would be fine to use patch-package if they really want to use in CJS?
const cjsModuleSpec = id + '.cjs' | ||
text = text.slice(0, i.s) + cjsModuleSpec + text.slice(i.e) |
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.
So this adds .cjs
to all file imports, do we need to do the same for node/index.d.ts
to with .js
only. I've seen this need in the past with node16, but i've also heard that it's not exactly needed.
I also wonder if adding .js
is enough to get CJS support? so we avoid another file.
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've tested explicit .js
in node/index.d.ts
before taking this route. It doesn't work, unfortunately.
Is this still needed with Even then, I also think that the added complexity is too high, and we should start pushing a bit more toward ESM. My vote goes to avoid the extra files here. |
Thanks for the PR Alec. We discussed this PR in today's team meeting and we decided it is better to keep the types as is. We're thinking we should start to push folks to use |
Description
This will allow CJS projects using
moduleResolution: node16
to import Vite.It copies the types from
dist/node
intodist/node-cjs
, changing file extension from.d.ts
to.d.cts
and rewriting relative imports to include.cjs
suffix.It only does this onpnpm build
.What is the purpose of this pull request?