mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
feat(webpack): suppress not found typescript warnings (#5635)
This commit is contained in:
parent
cc00469409
commit
1e4708e90f
@ -55,7 +55,8 @@ export default () => ({
|
||||
vueStyle: {}
|
||||
},
|
||||
typescript: {
|
||||
typeCheck: true
|
||||
typeCheck: true,
|
||||
ignoreNotFoundWarnings: false
|
||||
},
|
||||
styleResources: {},
|
||||
plugins: [],
|
||||
|
@ -144,6 +144,7 @@ Object {
|
||||
"terser": Object {},
|
||||
"transpile": Array [],
|
||||
"typescript": Object {
|
||||
"ignoreNotFoundWarnings": false,
|
||||
"typeCheck": true,
|
||||
},
|
||||
"watch": Array [],
|
||||
|
@ -124,6 +124,7 @@ Object {
|
||||
"terser": Object {},
|
||||
"transpile": Array [],
|
||||
"typescript": Object {
|
||||
"ignoreNotFoundWarnings": false,
|
||||
"typeCheck": true,
|
||||
},
|
||||
"watch": Array [],
|
||||
@ -457,6 +458,7 @@ Object {
|
||||
"terser": Object {},
|
||||
"transpile": Array [],
|
||||
"typescript": Object {
|
||||
"ignoreNotFoundWarnings": false,
|
||||
"typeCheck": true,
|
||||
},
|
||||
"watch": Array [],
|
||||
|
3
packages/config/types/build.d.ts
vendored
3
packages/config/types/build.d.ts
vendored
@ -60,7 +60,8 @@ export interface NuxtConfigurationBuild {
|
||||
terser?: TerserPluginOptions | boolean
|
||||
transpile?: (string | RegExp)[]
|
||||
typescript?: {
|
||||
typeCheck?: { [key: string]: any } | boolean // TBD - Couldn't find typedefs for the forkTsCheckerWebpackPlugin options
|
||||
typeCheck?: { [key: string]: any } | boolean, // TBD - Couldn't find typedefs for the forkTsCheckerWebpackPlugin options
|
||||
ignoreNotFoundWarnings?: boolean
|
||||
}
|
||||
watch?: string[]
|
||||
}
|
||||
|
@ -368,8 +368,7 @@ export default class WebpackBaseConfig {
|
||||
|
||||
plugins.push(...(buildOptions.plugins || []))
|
||||
|
||||
// Hide warnings about plugins without a default export (#1179)
|
||||
plugins.push(new WarnFixPlugin())
|
||||
plugins.push(new WarnFixPlugin(this.warningFixFilter()))
|
||||
|
||||
// Build progress indicator
|
||||
plugins.push(new WebpackBar({
|
||||
@ -418,6 +417,25 @@ export default class WebpackBaseConfig {
|
||||
return plugins
|
||||
}
|
||||
|
||||
warningFixFilter() {
|
||||
const { buildOptions, options: { _typescript = {} } } = this.buildContext
|
||||
const filters = [
|
||||
// Hide warnings about plugins without a default export (#1179)
|
||||
warn => warn.name === 'ModuleDependencyWarning' &&
|
||||
warn.message.includes(`export 'default'`) &&
|
||||
warn.message.includes('nuxt_plugin_')
|
||||
]
|
||||
|
||||
if (_typescript.build && buildOptions.typescript && buildOptions.typescript.ignoreNotFoundWarnings) {
|
||||
filters.push(
|
||||
warn => warn.name === 'ModuleDependencyWarning' &&
|
||||
/export .* was not found in /.test(warn.message)
|
||||
)
|
||||
}
|
||||
|
||||
return warn => !filters.some(ignoreFilter => ignoreFilter(warn))
|
||||
}
|
||||
|
||||
extendConfig(config) {
|
||||
const { extend } = this.buildContext.buildOptions
|
||||
if (typeof extend === 'function') {
|
||||
|
@ -1,10 +1,11 @@
|
||||
export default class WarnFixPlugin {
|
||||
constructor(filter) {
|
||||
this.filter = filter
|
||||
}
|
||||
|
||||
apply(compiler) /* istanbul ignore next */ {
|
||||
compiler.hooks.done.tap('warnfix-plugin', (stats) => {
|
||||
stats.compilation.warnings = stats.compilation.warnings.filter(warn =>
|
||||
!(warn.name === 'ModuleDependencyWarning' &&
|
||||
warn.message.includes(`export 'default'`) &&
|
||||
warn.message.includes('nuxt_plugin_')))
|
||||
stats.compilation.warnings = stats.compilation.warnings.filter(this.filter)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
44
test/unit/typescript-build.test.js
Normal file
44
test/unit/typescript-build.test.js
Normal file
@ -0,0 +1,44 @@
|
||||
import WebpackBaseConfig from '../../packages/webpack/src/config/base'
|
||||
|
||||
const createWebpackBaseConfig = (typescriptBuild, ignoreNotFoundWarnings) => {
|
||||
const builder = {
|
||||
buildContext: {
|
||||
buildOptions: {
|
||||
typescript: { ignoreNotFoundWarnings },
|
||||
transpile: []
|
||||
},
|
||||
options: {
|
||||
_typescript: { build: typescriptBuild }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new WebpackBaseConfig(builder)
|
||||
}
|
||||
|
||||
describe('warningFixFilter', () => {
|
||||
let filters
|
||||
const name = 'ModuleDependencyWarning'
|
||||
|
||||
describe('disabled ignoreNotFoundWarnings', () => {
|
||||
beforeEach(() => {
|
||||
filters = createWebpackBaseConfig(true, false).warningFixFilter()
|
||||
})
|
||||
|
||||
test('should be true', () => expect(filters({})).toBe(true))
|
||||
test('should be true', () => expect(filters({ name, message: 'error!' })).toBe(true))
|
||||
test('should be false', () => expect(filters({ name, message: `export 'default' nuxt_plugin_xxxx` })).toBe(false))
|
||||
test('should be true', () => expect(filters({ name, message: `export 'xxx' was not found in ` })).toBe(true))
|
||||
})
|
||||
|
||||
describe('enabled ignoreNotFoundWarnings', () => {
|
||||
beforeEach(() => {
|
||||
filters = createWebpackBaseConfig(true, true).warningFixFilter()
|
||||
})
|
||||
|
||||
test('should be true', () => expect(filters({})).toBe(true))
|
||||
test('should be true', () => expect(filters({ name, message: 'error!' })).toBe(true))
|
||||
test('should be false', () => expect(filters({ name, message: `export 'default' nuxt_plugin_xxxx` })).toBe(false))
|
||||
test('should be false', () => expect(filters({ name, message: `export 'xxx' was not found in ` })).toBe(false))
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user