rsnext/packages/next/server/lib/find-page-file.ts
Connor Davis 5514949df0 Remove glob package (#6415)
We don't use a lot of the features of `glob`, so let's remove it in favor of a leaner approach using regex.

It's failing on windows and I have no idea why and don't own a windows machine 🤦🏼‍♂️

(Ignore some of the commits in here, I forgot to create the new branch before I started working)
2019-02-24 22:08:35 +01:00

21 lines
722 B
TypeScript

import { join } from 'path'
import {isWriteable} from '../../build/is-writeable'
export async function findPageFile(rootDir: string, normalizedPagePath: string, pageExtensions: string[]): Promise<string|null> {
for (const extension of pageExtensions) {
const relativePagePath = `${normalizedPagePath}.${extension}`
const pagePath = join(rootDir, relativePagePath)
if (await isWriteable(pagePath)) {
return relativePagePath
}
const relativePagePathWithIndex = join(normalizedPagePath, `index.${extension}`)
const pagePathWithIndex = join(rootDir, relativePagePathWithIndex)
if (await isWriteable(pagePathWithIndex)) {
return relativePagePathWithIndex
}
}
return null
}