Merge pull request #2594 from nuxt/feat/glob-ignore

options.ignore support
This commit is contained in:
Sébastien Chopin 2018-01-15 11:43:27 +01:00 committed by GitHub
commit d90102e469
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 6 deletions

View File

@ -274,7 +274,7 @@ module.exports = class Builder {
if (existsSync(resolve(this.options.srcDir, 'layouts'))) {
const layoutsFiles = await glob('layouts/**/*.{vue,js}', {
cwd: this.options.srcDir,
ignore: [`layouts/**/${this.options.ignorePrefix}*.{vue,js}`]
ignore: this.options.ignore
})
let hasErrorLayout = false
layoutsFiles.forEach(file => {
@ -316,7 +316,7 @@ module.exports = class Builder {
const files = {}
;(await glob('pages/**/*.{vue,js}', {
cwd: this.options.srcDir,
ignore: [`pages/**/${this.options.ignorePrefix}*.{vue,js}`]
ignore: this.options.ignore
})).forEach(f => {
const key = f.replace(/\.(js|vue)$/, '')
if (/\.vue$/.test(f) || !files[key]) {

View File

@ -119,6 +119,14 @@ Options.from = function (_options) {
options.debug = options.dev
}
// Normalize ignore
options.ignore = options.ignore ? [].concat(options.ignore) : []
// Append ignorePrefix glob to ignore
if (typeof options.ignorePrefix === 'string') {
options.ignore.push(`**/${options.ignorePrefix}*.*`)
}
// Apply mode preset
let modePreset =
Options.modes[options.mode || 'universal'] || Options.modes['universal']
@ -167,6 +175,9 @@ Options.defaults = {
nuxtAppDir: resolve(__dirname, '../app'),
modulesDir: ['node_modules'], // ~> relative to options.rootDir
ignorePrefix: '-',
ignore: [
'**/*.test.*'
],
extensions: [],
build: {
analyze: false,

View File

@ -173,6 +173,12 @@ test.serial('/-ignored', async t => {
t.true(error.response.body.includes('Cannot GET /-ignored'))
})
test.serial('/ignored.test', async t => {
const error = await t.throws(rp(url('/ignored.test')))
t.true(error.statusCode === 404)
t.true(error.response.body.includes('Cannot GET /ignored.test'))
})
// Close server and ask nuxt to stop listening to file changes
test.after.always('Closing server', async t => {
await server.close()

View File

@ -252,10 +252,7 @@ test('Content-Security-Policy Header', async t => {
resolveWithFullResponse: true
})
// Verify functionality
t.is(
headers['content-security-policy'],
"script-src 'self' 'sha256-BBvfKxDOoRM/gnFwke9u60HBZX3HUss/0lSI1sBRvOU='"
)
t.regex(headers['content-security-policy'], /script-src 'self' 'sha256-.*'/)
})
test('/_nuxt/server-bundle.json should return 404', async t => {

View File

@ -0,0 +1,3 @@
export default function () {
throw new Error('Should be ignored')
}

View File

@ -0,0 +1,13 @@
<template lang="html">
<div class="error">
Should be ignored
</div>
</template>
<script>
export default {
}
</script>
<style lang="css">
</style>

View File

@ -0,0 +1,3 @@
export const state = () => ({
error: 'Should be ignored'
})