feat(webpack): suppress not found typescript warnings (#5635)

This commit is contained in:
Yama-Tomo 2019-05-10 19:18:44 +09:00 committed by Pooya Parsa
parent cc00469409
commit 1e4708e90f
7 changed files with 76 additions and 8 deletions

View File

@ -55,7 +55,8 @@ export default () => ({
vueStyle: {} vueStyle: {}
}, },
typescript: { typescript: {
typeCheck: true typeCheck: true,
ignoreNotFoundWarnings: false
}, },
styleResources: {}, styleResources: {},
plugins: [], plugins: [],

View File

@ -144,6 +144,7 @@ Object {
"terser": Object {}, "terser": Object {},
"transpile": Array [], "transpile": Array [],
"typescript": Object { "typescript": Object {
"ignoreNotFoundWarnings": false,
"typeCheck": true, "typeCheck": true,
}, },
"watch": Array [], "watch": Array [],

View File

@ -124,6 +124,7 @@ Object {
"terser": Object {}, "terser": Object {},
"transpile": Array [], "transpile": Array [],
"typescript": Object { "typescript": Object {
"ignoreNotFoundWarnings": false,
"typeCheck": true, "typeCheck": true,
}, },
"watch": Array [], "watch": Array [],
@ -457,6 +458,7 @@ Object {
"terser": Object {}, "terser": Object {},
"transpile": Array [], "transpile": Array [],
"typescript": Object { "typescript": Object {
"ignoreNotFoundWarnings": false,
"typeCheck": true, "typeCheck": true,
}, },
"watch": Array [], "watch": Array [],

View File

@ -60,7 +60,8 @@ export interface NuxtConfigurationBuild {
terser?: TerserPluginOptions | boolean terser?: TerserPluginOptions | boolean
transpile?: (string | RegExp)[] transpile?: (string | RegExp)[]
typescript?: { 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[] watch?: string[]
} }

View File

@ -368,8 +368,7 @@ export default class WebpackBaseConfig {
plugins.push(...(buildOptions.plugins || [])) plugins.push(...(buildOptions.plugins || []))
// Hide warnings about plugins without a default export (#1179) plugins.push(new WarnFixPlugin(this.warningFixFilter()))
plugins.push(new WarnFixPlugin())
// Build progress indicator // Build progress indicator
plugins.push(new WebpackBar({ plugins.push(new WebpackBar({
@ -418,6 +417,25 @@ export default class WebpackBaseConfig {
return plugins 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) { extendConfig(config) {
const { extend } = this.buildContext.buildOptions const { extend } = this.buildContext.buildOptions
if (typeof extend === 'function') { if (typeof extend === 'function') {

View File

@ -1,10 +1,11 @@
export default class WarnFixPlugin { export default class WarnFixPlugin {
constructor(filter) {
this.filter = filter
}
apply(compiler) /* istanbul ignore next */ { apply(compiler) /* istanbul ignore next */ {
compiler.hooks.done.tap('warnfix-plugin', (stats) => { compiler.hooks.done.tap('warnfix-plugin', (stats) => {
stats.compilation.warnings = stats.compilation.warnings.filter(warn => stats.compilation.warnings = stats.compilation.warnings.filter(this.filter)
!(warn.name === 'ModuleDependencyWarning' &&
warn.message.includes(`export 'default'`) &&
warn.message.includes('nuxt_plugin_')))
}) })
} }
} }

View 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))
})
})