fix(ts): prevent checking types twice in modern mode & use consola as logger (#4803)

This commit is contained in:
Kevin Marrec 2019-01-19 13:10:21 +01:00 committed by Pooya Parsa
parent a616c09b22
commit b202361a1b
2 changed files with 28 additions and 2 deletions

View File

@ -136,7 +136,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
// TypeScript type checker // TypeScript type checker
// Only performs once per client compilation and only if `ts-loader` checker is not used (transpileOnly: true) // Only performs once per client compilation and only if `ts-loader` checker is not used (transpileOnly: true)
if (this.loaders.ts.transpileOnly && this.options.build.useForkTsChecker) { if (!this.isModern && this.loaders.ts.transpileOnly && this.options.build.useForkTsChecker) {
const forkTsCheckerResolvedPath = this.nuxt.resolver.resolveModule('fork-ts-checker-webpack-plugin') const forkTsCheckerResolvedPath = this.nuxt.resolver.resolveModule('fork-ts-checker-webpack-plugin')
if (forkTsCheckerResolvedPath) { if (forkTsCheckerResolvedPath) {
const ForkTsCheckerWebpackPlugin = require(forkTsCheckerResolvedPath) const ForkTsCheckerWebpackPlugin = require(forkTsCheckerResolvedPath)
@ -145,7 +145,8 @@ export default class WebpackClientConfig extends WebpackBaseConfig {
tsconfig: path.resolve(this.options.rootDir, 'tsconfig.json'), tsconfig: path.resolve(this.options.rootDir, 'tsconfig.json'),
// https://github.com/Realytics/fork-ts-checker-webpack-plugin#options - tslint: boolean | string - So we set it false if file not found // https://github.com/Realytics/fork-ts-checker-webpack-plugin#options - tslint: boolean | string - So we set it false if file not found
tslint: (tslintPath => fs.existsSync(tslintPath) && tslintPath)(path.resolve(this.options.rootDir, 'tslint.json')), tslint: (tslintPath => fs.existsSync(tslintPath) && tslintPath)(path.resolve(this.options.rootDir, 'tslint.json')),
formatter: 'codeframe' formatter: 'codeframe',
logger: consola
}, this.options.build.useForkTsChecker))) }, this.options.build.useForkTsChecker)))
} else { } else {
consola.warn('You need to install `fork-ts-checker-webpack-plugin` as devDependency to enable TypeScript type checking !') consola.warn('You need to install `fork-ts-checker-webpack-plugin` as devDependency to enable TypeScript type checking !')

View File

@ -0,0 +1,25 @@
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin'
import { loadFixture, Nuxt, Builder, BundleBuilder } from '../utils'
jest.mock('fork-ts-checker-webpack-plugin')
describe('typescript modern', () => {
let nuxt
beforeAll(async () => {
process.env.NUXT_TS = 'true'
const options = await loadFixture('typescript')
nuxt = new Nuxt(Object.assign(options, { modern: true }))
await new Builder(nuxt, BundleBuilder).build()
delete process.env.NUXT_TS
})
test('fork-ts-checker-webpack-plugin', () => {
expect(ForkTsCheckerWebpackPlugin).toHaveBeenCalledTimes(1)
})
// Close server and ask nuxt to stop listening to file changes
afterAll(async () => {
await nuxt.close()
})
})