feat(builder): ignore option to function the same as .nuxtignore (#7132)

This commit is contained in:
Jt Whissel 2020-03-27 06:53:23 -04:00 committed by GitHub
parent f18e241f70
commit 51b5bf565b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

View File

@ -82,7 +82,8 @@ export default class Builder {
this.bundleBuilder = this.getBundleBuilder(bundleBuilder)
this.ignore = new Ignore({
rootDir: this.options.srcDir
rootDir: this.options.srcDir,
ignoreArray: this.options.ignore
})
}
@ -312,7 +313,6 @@ export default class Builder {
async resolveFiles (dir, cwd = this.options.srcDir) {
return this.ignore.filter(await glob(this.globPathWithExtensions(dir), {
cwd,
ignore: this.options.ignore,
follow: this.options.build.followSymlinks
}))
}

View File

@ -6,6 +6,7 @@ export default class Ignore {
constructor (options) {
this.rootDir = options.rootDir
this.ignoreOptions = options.ignoreOptions
this.ignoreArray = options.ignoreArray
this.addIgnoresRules()
}
@ -35,6 +36,12 @@ export default class Ignore {
if (content) {
this.ignore.add(content)
}
if (this.ignoreArray && this.ignoreArray.length > 0) {
if (!this.ignore) {
this.ignore = ignore(this.ignoreOptions)
}
this.ignore.add(this.ignoreArray)
}
}
filter (paths) {

View File

@ -102,7 +102,7 @@ describe('builder: builder generate', () => {
expect(Glob).toBeCalledTimes(1)
expect(Glob).toBeCalledWith(
'/var/nuxt/dir/**/*.{vue,js}',
{ cwd: '/var/nuxt/src', ignore: '/var/nuxt/ignore' }
{ cwd: '/var/nuxt/src' }
)
expect(builder.ignore.filter).toBeCalledTimes(1)
expect(builder.ignore.filter).toBeCalledWith('matched files')