mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(kit): resolve group syntax of ignore
(#15884)
This commit is contained in:
parent
7c1712013c
commit
fa2672485a
26
packages/kit/src/ignore.test.ts
Normal file
26
packages/kit/src/ignore.test.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { expect, it, describe } from 'vitest'
|
||||||
|
import { resolveGroupSyntax } from './ignore.js'
|
||||||
|
|
||||||
|
describe('resolveGroupSyntax', () => {
|
||||||
|
it('should resolve single group syntax', () => {
|
||||||
|
expect(resolveGroupSyntax('**/*.{spec}.{js,ts}')).toStrictEqual([
|
||||||
|
'**/*.spec.js',
|
||||||
|
'**/*.spec.ts'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should resolve multi-group syntax', () => {
|
||||||
|
expect(resolveGroupSyntax('**/*.{spec,test}.{js,ts}')).toStrictEqual([
|
||||||
|
'**/*.spec.js',
|
||||||
|
'**/*.spec.ts',
|
||||||
|
'**/*.test.js',
|
||||||
|
'**/*.test.ts'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it('should do nothing with normal globs', () => {
|
||||||
|
expect(resolveGroupSyntax('**/*.spec.js')).toStrictEqual([
|
||||||
|
'**/*.spec.js'
|
||||||
|
])
|
||||||
|
})
|
||||||
|
})
|
@ -16,7 +16,9 @@ export function isIgnored (pathname: string): boolean {
|
|||||||
|
|
||||||
if (!nuxt._ignore) {
|
if (!nuxt._ignore) {
|
||||||
nuxt._ignore = ignore(nuxt.options.ignoreOptions)
|
nuxt._ignore = ignore(nuxt.options.ignoreOptions)
|
||||||
nuxt._ignore.add(nuxt.options.ignore)
|
const resolvedIgnore = nuxt.options.ignore.flatMap(s => resolveGroupSyntax(s))
|
||||||
|
|
||||||
|
nuxt._ignore.add(resolvedIgnore)
|
||||||
|
|
||||||
const nuxtignoreFile = join(nuxt.options.rootDir, '.nuxtignore')
|
const nuxtignoreFile = join(nuxt.options.rootDir, '.nuxtignore')
|
||||||
if (existsSync(nuxtignoreFile)) {
|
if (existsSync(nuxtignoreFile)) {
|
||||||
@ -32,3 +34,27 @@ export function isIgnored (pathname: string): boolean {
|
|||||||
}
|
}
|
||||||
return !!(relativePath && nuxt._ignore.ignores(relativePath))
|
return !!(relativePath && nuxt._ignore.ignores(relativePath))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function turns string containing groups '**\/*.{spec,test}.{js,ts}' into an array of strings.
|
||||||
|
* For example will '**\/*.{spec,test}.{js,ts}' be resolved to:
|
||||||
|
* ['**\/*.spec.js', '**\/*.spec.ts', '**\/*.test.js', '**\/*.test.ts']
|
||||||
|
*
|
||||||
|
* @param group string containing the group syntax
|
||||||
|
* @returns {string[]} array of strings without the group syntax
|
||||||
|
*/
|
||||||
|
export function resolveGroupSyntax (group: string): string[] {
|
||||||
|
let groups = [group]
|
||||||
|
while (groups.some(group => group.includes('{'))) {
|
||||||
|
groups = groups.flatMap((group) => {
|
||||||
|
const [head, ...tail] = group.split('{')
|
||||||
|
if (tail.length) {
|
||||||
|
const [body, ...rest] = tail.join('{').split('}')
|
||||||
|
return body.split(',').map(part => `${head}${part}${rest.join('')}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return group
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return groups
|
||||||
|
}
|
||||||
|
@ -12,7 +12,7 @@ export * from './build'
|
|||||||
export * from './compatibility'
|
export * from './compatibility'
|
||||||
export * from './components'
|
export * from './components'
|
||||||
export * from './context'
|
export * from './context'
|
||||||
export * from './ignore'
|
export { isIgnored } from './ignore'
|
||||||
export * from './layout'
|
export * from './layout'
|
||||||
export * from './pages'
|
export * from './pages'
|
||||||
export * from './plugin'
|
export * from './plugin'
|
||||||
|
1
test/fixtures/basic/plugins/this-should-not-load.spec.js
vendored
Normal file
1
test/fixtures/basic/plugins/this-should-not-load.spec.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
throw new Error('this-should-not-load.spec.js should not be loaded')
|
@ -1,5 +1,6 @@
|
|||||||
import { resolve } from 'node:path'
|
import { resolve } from 'node:path'
|
||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
|
import { configDefaults } from 'vitest/config'
|
||||||
import { isWindows } from 'std-env'
|
import { isWindows } from 'std-env'
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
@ -13,6 +14,8 @@ export default defineConfig({
|
|||||||
tsconfigRaw: '{}'
|
tsconfigRaw: '{}'
|
||||||
},
|
},
|
||||||
test: {
|
test: {
|
||||||
testTimeout: isWindows ? 60000 : 10000
|
testTimeout: isWindows ? 60000 : 10000,
|
||||||
|
// Excluded plugin because it should throw an error when accidentally loaded via Nuxt
|
||||||
|
exclude: [...configDefaults.exclude, '**/this-should-not-load.spec.js']
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user