From 5e08832fabe80ddc839907d13c7279a091ddfee5 Mon Sep 17 00:00:00 2001 From: Kael Date: Wed, 10 May 2023 22:54:43 +1000 Subject: [PATCH] feat(types): emit declarations as .d.mts closes #15885 BREAKING CHANGE: .d.ts imports have to be changed to .d.mts BREAKING CHANGE: minimum typescript version 4.7 --- .../api-generator/templates/composables.d.ts | 2 +- .../api-generator/templates/directives.d.ts | 2 +- packages/api-generator/tsconfig.json | 2 +- .../vuetify/build/rollup.types.config.mjs | 22 +++++++++---------- packages/vuetify/package.json | 14 +++++++----- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/packages/api-generator/templates/composables.d.ts b/packages/api-generator/templates/composables.d.ts index b7ee20d8009..47228fdda3f 100644 --- a/packages/api-generator/templates/composables.d.ts +++ b/packages/api-generator/templates/composables.d.ts @@ -1,4 +1,4 @@ -import type vuetify from '../../vuetify/lib/index' +import type vuetify from '../../vuetify/lib/index.d.mts' type IsComposable = T extends `use${Capitalize}` ? T : never; diff --git a/packages/api-generator/templates/directives.d.ts b/packages/api-generator/templates/directives.d.ts index 83e344a4fa6..94eb580b2a5 100644 --- a/packages/api-generator/templates/directives.d.ts +++ b/packages/api-generator/templates/directives.d.ts @@ -1,5 +1,5 @@ import type { DirectiveBinding } from 'vue' -import type * as directives from '../../vuetify/lib/directives/index' +import type * as directives from '../../vuetify/lib/directives/index.d.mts' type ExtractDirectiveBindings = T extends object ? { diff --git a/packages/api-generator/tsconfig.json b/packages/api-generator/tsconfig.json index 43f31f4e0f2..18765929d3d 100644 --- a/packages/api-generator/tsconfig.json +++ b/packages/api-generator/tsconfig.json @@ -4,7 +4,7 @@ "strict": false, "noUnusedLocals": false, "module": "ESNext", - "moduleResolution": "NodeNext", + "moduleResolution": "bundler", "noEmitOnError": false, "resolveJsonModule": true, "paths": { diff --git a/packages/vuetify/build/rollup.types.config.mjs b/packages/vuetify/build/rollup.types.config.mjs index 4f1f968c904..dcba7eab132 100644 --- a/packages/vuetify/build/rollup.types.config.mjs +++ b/packages/vuetify/build/rollup.types.config.mjs @@ -78,7 +78,7 @@ async function getShims () { } export default [ - createTypesConfig('framework.d.ts', 'lib/index.d.ts', async code => { + createTypesConfig('framework.d.ts', 'lib/index.d.mts', async code => { code.append('\n\n') code.append(await getShims()) }), @@ -87,9 +87,9 @@ export default [ code.append('\n\n') code.append((await getShims()).replace(', VNodeChild } from \'vue\'', ' } from \'vue\'')) }), - createTypesConfig('blueprints/*.d.ts', 'lib/blueprints/*.d.ts'), - createTypesConfig('components/index.d.ts', 'lib/components/index.d.ts'), - createTypesConfig('components/*/index.d.ts', 'lib/components/*/index.d.ts', undefined, files => { + createTypesConfig('blueprints/*.d.ts', 'lib/blueprints/*.d.mts'), + createTypesConfig('components/index.d.ts', 'lib/components/index.d.mts'), + createTypesConfig('components/*/index.d.ts', 'lib/components/*/index.d.mts', undefined, files => { const index = readFileSync(fileURLToPath(new URL('../src/components/index.ts', import.meta.url)), { encoding: 'utf8' }) const block = Array.from(index.matchAll(/^\/\/ export \* from '\.\/(.*)'$/gm), m => m[1]) return files.filter(file => !block.some(name => file.includes(`/${name}/`))) @@ -97,11 +97,11 @@ export default [ createTypesConfig('labs/entry-bundler.d.ts', 'dist/vuetify-labs.d.ts', code => { code.replaceAll(/type allComponents_d_V(\w+) = V(\w+);/gm, 'declare const allComponents_d_V$1: typeof V$2;') }), - createTypesConfig('labs/components.d.ts', 'lib/labs/components.d.ts'), - createTypesConfig('labs/*/index.d.ts', 'lib/labs/*/index.d.ts'), - createTypesConfig('labs/date/adapters/*.d.ts', 'lib/labs/date/adapters/*.d.ts'), - createTypesConfig('directives/index.d.ts', 'lib/directives/index.d.ts'), - createTypesConfig('locale/index.d.ts', 'lib/locale/index.d.ts'), - createTypesConfig('locale/adapters/*.d.ts', 'lib/locale/adapters/*.d.ts'), - createTypesConfig('iconsets/*.d.ts', 'lib/iconsets/*.d.ts'), + createTypesConfig('labs/components.d.ts', 'lib/labs/components.d.mts'), + createTypesConfig('labs/*/index.d.ts', 'lib/labs/*/index.d.mts'), + createTypesConfig('labs/date/adapters/*.d.ts', 'lib/labs/date/adapters/*.d.mts'), + createTypesConfig('directives/index.d.ts', 'lib/directives/index.d.mts'), + createTypesConfig('locale/index.d.ts', 'lib/locale/index.d.mts'), + createTypesConfig('locale/adapters/*.d.ts', 'lib/locale/adapters/*.d.mts'), + createTypesConfig('iconsets/*.d.ts', 'lib/iconsets/*.d.mts'), ].flat() diff --git a/packages/vuetify/package.json b/packages/vuetify/package.json index 977f3f57ecd..f5c23467a78 100755 --- a/packages/vuetify/package.json +++ b/packages/vuetify/package.json @@ -33,7 +33,7 @@ "module": "lib/framework.mjs", "jsdelivr": "dist/vuetify.js", "unpkg": "dist/vuetify.js", - "types": "lib/index.d.ts", + "types": "lib/index.d.mts", "sass": "lib/styles/main.sass", "styles": "lib/styles/main.css", "sideEffects": [ @@ -79,17 +79,17 @@ "typesVersions": { "*": { "lib/framework.mjs": [ - "lib/index.d.ts" + "lib/index.d.mts" ], "framework": [ - "lib/index.d.ts" + "lib/index.d.mts" ], "*": [ "*", "dist/*", "lib/*", - "lib/*.d.ts", - "lib/*/index.d.ts" + "lib/*.d.mts", + "lib/*/index.d.mts" ] } }, @@ -167,12 +167,16 @@ "vue-router": "^4.1.6" }, "peerDependencies": { + "typescript": ">=4.7", "vite-plugin-vuetify": "^1.0.0-alpha.12", "vue": "^3.2.0", "vue-i18n": "^9.0.0", "webpack-plugin-vuetify": "^2.0.0-alpha.11" }, "peerDependenciesMeta": { + "typescript": { + "optional": true + }, "vue-i18n": { "optional": true },