Skip to content

Commit

Permalink
Fix variables in parseUrlForAppDir
Browse files Browse the repository at this point in the history
  • Loading branch information
DerTimonius committed Jul 29, 2023
1 parent f697f77 commit 4eac63d
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/eslint-plugin-next/src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,23 @@ function parseUrlForPages(urlprefix: string, directory: string) {
* Recursively parse app directory for URLs.
*/
function parseUrlForAppDir(urlprefix: string, directory: string) {
fsReadDirSyncCache[directory] =
fsReadDirSyncCache[directory] || fs.readdirSync(directory)
fsReadDirSyncCache[directory] ??= fs.readdirSync(directory, {
withFileTypes: true,
})
const res = []
fsReadDirSyncCache[directory].forEach((fname) => {
// TODO: this should account for all page extensions
// not just js(x) and ts(x)
if (/(\.(j|t)sx?)$/.test(fname)) {
if (/^page(\.(j|t)sx?)$/.test(fname)) {
res.push(`${urlprefix}${fname.replace(/^page(\.(j|t)sx?)$/, '')}`)
} else if (!/^layout(\.(j|t)sx?)$/.test(fname)) {
res.push(`${urlprefix}${fname.replace(/(\.(j|t)sx?)$/, '')}`)
if (/(\.(j|t)sx?)$/.test(fname.name)) {
if (/^page(\.(j|t)sx?)$/.test(fname.name)) {
res.push(`${urlprefix}${fname.name.replace(/^page(\.(j|t)sx?)$/, '')}`)
} else if (!/^layout(\.(j|t)sx?)$/.test(fname.name)) {
res.push(`${urlprefix}${fname.name.replace(/(\.(j|t)sx?)$/, '')}`)
}
} else {
const dirPath = path.join(directory, fname)
if (isDirectory(dirPath) && !isSymlink(dirPath)) {
res.push(...parseUrlForPages(urlprefix + fname + '/', dirPath))
if (fname.isDirectory(dirPath) && !fname.isSymlink(dirPath)) {
res.push(...parseUrlForPages(urlprefix + fname.name + '/', dirPath))
}
}
})
Expand Down

0 comments on commit 4eac63d

Please sign in to comment.