2022-02-28 16:11:46 +00:00
|
|
|
import { existsSync, readFileSync } from 'fs'
|
|
|
|
import ignore from 'ignore'
|
|
|
|
import { join, relative } from 'pathe'
|
2022-04-04 09:41:48 +00:00
|
|
|
import { tryUseNuxt } from './context'
|
2022-02-28 16:11:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a filter function to filter an array of paths
|
|
|
|
*/
|
|
|
|
export function isIgnored (pathname: string): boolean {
|
2022-04-04 09:41:48 +00:00
|
|
|
const nuxt = tryUseNuxt()
|
|
|
|
|
|
|
|
// Happens with CLI reloads
|
|
|
|
if (!nuxt) {
|
|
|
|
return null
|
|
|
|
}
|
2022-02-28 16:11:46 +00:00
|
|
|
|
|
|
|
if (!nuxt._ignore) {
|
|
|
|
nuxt._ignore = ignore(nuxt.options.ignoreOptions)
|
|
|
|
nuxt._ignore.add(nuxt.options.ignore)
|
|
|
|
|
|
|
|
const nuxtignoreFile = join(nuxt.options.rootDir, '.nuxtignore')
|
|
|
|
if (existsSync(nuxtignoreFile)) {
|
|
|
|
nuxt._ignore.add(readFileSync(nuxtignoreFile, 'utf-8'))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const relativePath = relative(nuxt.options.rootDir, pathname)
|
|
|
|
if (relativePath.startsWith('..')) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return relativePath && nuxt._ignore.ignores(relativePath)
|
|
|
|
}
|