mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +00:00
28 lines
782 B
TypeScript
28 lines
782 B
TypeScript
|
import { existsSync, readFileSync } from 'fs'
|
||
|
import ignore from 'ignore'
|
||
|
import { join, relative } from 'pathe'
|
||
|
import { useNuxt } from './context'
|
||
|
|
||
|
/**
|
||
|
* Return a filter function to filter an array of paths
|
||
|
*/
|
||
|
export function isIgnored (pathname: string): boolean {
|
||
|
const nuxt = useNuxt()
|
||
|
|
||
|
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)
|
||
|
}
|