File size: 804 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import { globSync } from 'fast-glob'
import type { Rule } from 'eslint'
/**
* Process a Next.js root directory glob.
*/
const processRootDir = (rootDir: string): string[] => {
return globSync(rootDir.replace(/\\/g, '/'), {
onlyDirectories: true,
})
}
/**
* Gets one or more Root, returns an array of root directories.
*/
export const getRootDirs = (context: Rule.RuleContext) => {
let rootDirs = [context.cwd]
const nextSettings: { rootDir?: string | string[] } =
context.settings.next || {}
let rootDir = nextSettings.rootDir
if (typeof rootDir === 'string') {
rootDirs = processRootDir(rootDir)
} else if (Array.isArray(rootDir)) {
rootDirs = rootDir
.map((dir) => (typeof dir === 'string' ? processRootDir(dir) : []))
.flat()
}
return rootDirs
}
|