|
|
@@ -1,6 +1,6 @@
|
|
|
// @ts-check
|
|
|
import { parse } from '@babel/parser'
|
|
|
-import { existsSync, readdirSync, readFileSync } from 'fs'
|
|
|
+import { existsSync, readdirSync, readFileSync, writeFileSync } from 'fs'
|
|
|
import MagicString from 'magic-string'
|
|
|
import dts from 'rollup-plugin-dts'
|
|
|
import { walk } from 'estree-walker'
|
|
|
@@ -25,7 +25,7 @@ export default targetPackages.map(pkg => {
|
|
|
file: `packages/${pkg}/dist/${pkg}.d.ts`,
|
|
|
format: 'es'
|
|
|
},
|
|
|
- plugins: [dts(), patchTypes(pkg)],
|
|
|
+ plugins: [dts(), patchTypes(pkg), ...(pkg === 'vue' ? [copyMts()] : [])],
|
|
|
onwarn(warning, warn) {
|
|
|
// during dts rollup, everything is externalized by default
|
|
|
if (
|
|
|
@@ -232,3 +232,24 @@ function patchTypes(pkg) {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 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 copy vue.d.ts to vue.d.mts
|
|
|
+ * upon build.
|
|
|
+ *
|
|
|
+ * @returns {import('rollup').Plugin}
|
|
|
+ */
|
|
|
+function copyMts() {
|
|
|
+ return {
|
|
|
+ name: 'copy-vue-mts',
|
|
|
+ writeBundle(_, bundle) {
|
|
|
+ writeFileSync(
|
|
|
+ 'packages/vue/dist/vue.d.mts',
|
|
|
+ // @ts-ignore
|
|
|
+ bundle['vue.d.ts'].code
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|