diff --git a/.gitignore b/.gitignore index 401eb54f..0e421eb9 100755 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,6 @@ coverage .DS_Store .AppleDouble .LSOverride + +GEMINI.md +commit_message.txt \ No newline at end of file diff --git a/babel.config.js b/babel.config.js index d5c9eacc..083856d7 100644 --- a/babel.config.js +++ b/babel.config.js @@ -11,6 +11,9 @@ module.exports = function (api) { node: 'current' } }] + ], + plugins: [ + '@babel/plugin-transform-runtime' ] } } diff --git a/examples/class-api/minimal/pages/index.vue b/examples/class-api/minimal/pages/index.vue index 413ffdfe..673edb43 100644 --- a/examples/class-api/minimal/pages/index.vue +++ b/examples/class-api/minimal/pages/index.vue @@ -9,7 +9,6 @@ import { Component, Vue } from 'vue-property-decorator' @Component export default class PageIndex extends Vue { - // eslint-disable-next-line @typescript-eslint/no-inferrable-types message: string = 'This is a message' } diff --git a/examples/options-api/minimal/pages/index.vue b/examples/options-api/minimal/pages/index.vue index 9d6dbaec..5ec5c30c 100644 --- a/examples/options-api/minimal/pages/index.vue +++ b/examples/options-api/minimal/pages/index.vue @@ -9,7 +9,6 @@ import { defineComponent } from 'vue' export default defineComponent({ data () { - // eslint-disable-next-line @typescript-eslint/no-inferrable-types const message: string = 'This is a message' return { diff --git a/packages/typescript-build/src/index.ts b/packages/typescript-build/src/index.ts index 716fd24b..4dacad1a 100644 --- a/packages/typescript-build/src/index.ts +++ b/packages/typescript-build/src/index.ts @@ -4,21 +4,20 @@ import consola from 'consola' import type { Module } from '@nuxt/types' import type { Options as TsLoaderOptions } from 'ts-loader' import type { ForkTsCheckerWebpackPluginOptions as TsCheckerOptions } from 'fork-ts-checker-webpack-plugin/lib/ForkTsCheckerWebpackPluginOptions' -import type TsCheckerLogger from 'fork-ts-checker-webpack-plugin/lib/logger/Logger' import type { RuleSetUseItem } from 'webpack' export interface Options { - ignoreNotFoundWarnings?: boolean + ignoreNotFoundWarnings?: boolean; loaders?: { - ts?: Partial - tsx?: Partial - } - typeCheck?: TsCheckerOptions | boolean + ts?: Partial; + tsx?: Partial; + }; + typeCheck?: TsCheckerOptions | boolean; } declare module '@nuxt/types' { interface NuxtOptions { - typescript: Options + typescript: Options; } } @@ -42,55 +41,68 @@ const tsModule: Module = function (moduleOptions) { this.options.build.additionalExtensions = ['ts', 'tsx'] if (options.ignoreNotFoundWarnings) { - this.options.build.warningIgnoreFilters!.push(warn => - warn.name === 'ModuleDependencyWarning' && /export .* was not found in /.test(warn.message) + this.options.build.warningIgnoreFilters!.push( + warn => + warn.name === 'ModuleDependencyWarning' && + /export .* was not found in /.test(warn.message) ) } this.extendBuild((config, { isClient, isModern }) => { config.resolve!.extensions!.push('.ts', '.tsx') - const jsxRuleLoaders = config.module!.rules.find(r => (r.test as RegExp).test('.jsx'))!.use as RuleSetUseItem[] + // Add alias for @babel/runtime/helpers + // https://github.com/nuxt/typescript/issues/645 + try { + config.resolve!.alias = { + ...config.resolve!.alias, + '@babel/runtime/helpers': path.resolve( + this.options.rootDir!, + 'node_modules/@babel/runtime/helpers' + ) + } + } catch (e) { + // @babel/runtime may not be present + } + + const jsxRuleLoaders = config.module!.rules.find(r => + (r.test as RegExp).test('.jsx') + )!.use as RuleSetUseItem[] const babelLoader = jsxRuleLoaders[jsxRuleLoaders.length - 1] - config.module!.rules.push(...(['ts', 'tsx'] as const).map(ext => - ({ - test: new RegExp(`\\.${ext}$`, 'i'), + config.module!.rules.push( + ...(['ts', 'tsx'] as const).map(ext => ({ + test: new RegExp(`\\.${ext}$`), use: [ babelLoader, { loader: 'ts-loader', options: { transpileOnly: true, - appendTsxSuffixTo: ext === 'tsx' ? [/\.vue$/] : [], + appendTsxSuffixTo: ext === 'tsx' ? [/.vue$/] : [], ...(options.loaders && options.loaders[ext]) } } ] - }) - )) + })) + ) if (options.typeCheck && isClient && !isModern) { // eslint-disable-next-line @typescript-eslint/no-var-requires const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin') - const logger = consola.withTag('nuxt:typescript') - /* istanbul ignore next */ - const loggerInterface: TsCheckerLogger = { - log (message) { logger.log(message) }, - info (message) { logger.info(message) }, - error (message) { logger.error(message) } - } - config.plugins!.push(new ForkTsCheckerWebpackPlugin(defu(options.typeCheck, { - typescript: { - configFile: path.resolve(this.options.rootDir!, 'tsconfig.json'), - extensions: { - vue: true - } - }, - logger: { - issues: loggerInterface - } - } as TsCheckerOptions))) + config.plugins!.push( + new ForkTsCheckerWebpackPlugin( + defu(options.typeCheck, { + typescript: { + configFile: path.resolve(this.options.rootDir!, 'tsconfig.json'), + extensions: { + vue: true + } + }, + logger: consola + } as TsCheckerOptions) + ) + ) } }) } diff --git a/packages/typescript-build/test/fixture/pages/about.ts b/packages/typescript-build/test/fixture/pages/about.ts index a93f5bc2..35f8fbb4 100644 --- a/packages/typescript-build/test/fixture/pages/about.ts +++ b/packages/typescript-build/test/fixture/pages/about.ts @@ -3,7 +3,6 @@ import { defineComponent } from 'vue' export default defineComponent({ name: 'About', render (h) { - // eslint-disable-next-line @typescript-eslint/no-inferrable-types const text: string = 'About Page' return h('div', text) } diff --git a/packages/typescript-build/test/fixture/pages/contact.tsx b/packages/typescript-build/test/fixture/pages/contact.tsx index 9a245d08..57b704e9 100644 --- a/packages/typescript-build/test/fixture/pages/contact.tsx +++ b/packages/typescript-build/test/fixture/pages/contact.tsx @@ -3,7 +3,6 @@ import { defineComponent } from 'vue' export default defineComponent({ name: 'Contact', data () { - // eslint-disable-next-line @typescript-eslint/no-inferrable-types const text: string = 'Contact Page' return { text } }, diff --git a/packages/typescript-build/test/fixture/pages/index.vue b/packages/typescript-build/test/fixture/pages/index.vue index d69417b4..1b48c288 100644 --- a/packages/typescript-build/test/fixture/pages/index.vue +++ b/packages/typescript-build/test/fixture/pages/index.vue @@ -7,7 +7,6 @@ import { defineComponent } from 'vue' export default defineComponent({ data () { - // eslint-disable-next-line @typescript-eslint/no-inferrable-types const text: string = 'Index Page' return { text } }