f5cab2f515
## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) Co-authored-by: Tim Neutkens <6324199+timneutkens@users.noreply.github.com> Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
27 lines
750 B
TypeScript
27 lines
750 B
TypeScript
import getAppRouteFromEntrypoint from './get-app-route-from-entrypoint'
|
|
import matchBundle from './match-bundle'
|
|
|
|
// matches pages/:page*.js
|
|
const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/
|
|
|
|
// matches static/pages/:page*.js
|
|
const BROWSER_ROUTE_NAME_REGEX = /^static[/\\]pages[/\\](.*)$/
|
|
|
|
export default function getRouteFromEntrypoint(
|
|
entryFile: string,
|
|
app?: boolean
|
|
): string | null {
|
|
let pagePath = matchBundle(SERVER_ROUTE_NAME_REGEX, entryFile)
|
|
|
|
if (pagePath) {
|
|
return pagePath
|
|
}
|
|
|
|
if (app) {
|
|
pagePath = getAppRouteFromEntrypoint(entryFile)
|
|
if (pagePath) return pagePath
|
|
}
|
|
|
|
// Potentially the passed item is a browser bundle so we try to match that also
|
|
return matchBundle(BROWSER_ROUTE_NAME_REGEX, entryFile)
|
|
}
|