11// @ts -check
22import { parse } from '@babel/parser'
3- import { existsSync , readdirSync , readFileSync } from 'fs'
3+ import { existsSync , readdirSync , readFileSync , writeFileSync } from 'fs'
44import MagicString from 'magic-string'
55import dts from 'rollup-plugin-dts'
66import { walk } from 'estree-walker'
@@ -25,7 +25,7 @@ export default targetPackages.map(pkg => {
2525 file : `packages/${ pkg } /dist/${ pkg } .d.ts` ,
2626 format : 'es'
2727 } ,
28- plugins : [ dts ( ) , patchTypes ( pkg ) ] ,
28+ plugins : [ dts ( ) , patchTypes ( pkg ) , ... ( pkg === 'vue' ? [ copyMts ( ) ] : [ ] ) ] ,
2929 onwarn ( warning , warn ) {
3030 // during dts rollup, everything is externalized by default
3131 if (
@@ -232,3 +232,24 @@ function patchTypes(pkg) {
232232 }
233233 }
234234}
235+
236+ /**
237+ * According to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-4-7.html#packagejson-exports-imports-and-self-referencing
238+ * the only way to correct provide types for both Node ESM and CJS is to have
239+ * two separate declaration files, so we need to copy vue.d.ts to vue.d.mts
240+ * upon build.
241+ *
242+ * @returns {import('rollup').Plugin }
243+ */
244+ function copyMts ( ) {
245+ return {
246+ name : 'copy-vue-mts' ,
247+ writeBundle ( _ , bundle ) {
248+ writeFileSync (
249+ 'packages/vue/dist/vue.d.mts' ,
250+ // @ts -ignore
251+ bundle [ 'vue.d.ts' ] . code
252+ )
253+ }
254+ }
255+ }
0 commit comments