Skip to content
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(plugin-legacy): ensure correct typing for node esm #13892

Merged
merged 1 commit into from Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -82,7 +82,7 @@
"tslib": "^2.6.2",
"tsx": "^3.12.10",
"typescript": "^5.0.2",
"unbuild": "^1.2.1",
"unbuild": "^2.0.0",
"vite": "workspace:*",
"vitepress": "1.0.0-rc.14",
"vitest": "^0.34.4",
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-legacy/package.json
Expand Up @@ -17,7 +17,6 @@
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reasoning behind removing this entry? We have the same setup on all other plugins: https://github.com/vitejs/vite-plugin-vue/blob/93c444cb99d64c65b71050d0f6a5e3016f7046a1/packages/plugin-vue/package.json#L14

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TypeScript is able to pick up the adjacent .ts by removing this, .e.g ./dist/index.mjs -> ./dist/index.d.mts. What this PR does is that it emits two dts files for the two formats :(

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unjs/unbuild#273

Because of .d.mts and .d.cts, removing it will allow TS to find correct one by itself

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing , the only way to correct provide types for both Node ESM and CJS is to have two separate declaration files, so we need to generate index.d.cts and index.d.mts.

unbuild@2 could generate index.d.cts and index.d.mts standing for types of index.cjs and index.mjs, and could generate index.d.ts for legacy typescript usage.

releated commit:
vuejs/core@d621d4c

releated PRs:
unjs/unbuild#273
vitejs/vite-plugin-vue#179

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR is good for plugins given our current setup. We could release it in a minor for the plugin. I added it to the 5.0 milestone (that we're going to start working on soon) because there is a parallel discussion about moving vite core and the plugins to ESM only. I still don't know if Vite 5 is the right major to do this, so if we don't move forward with that, we should merge this PR instead.
Polls that @bluwy started for reference:

"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
Expand Down