Skip to content

Commit

Permalink
fix: typedroute routes for window (vercel#46099)
Browse files Browse the repository at this point in the history
This pr filters out `non-page` files for `pages` dir and fixes path for windows os

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/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`
- [ ] [e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs) tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
  • Loading branch information
imranbarbhuiya authored and vorcigernix committed Feb 19, 2023
1 parent a6a7463 commit f8c98ab
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/next/src/build/webpack/plugins/next-types-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,23 @@ export class NextTypesPlugin {
return
}

// Filter out non-page files in pages dir
if (
!isApp &&
/[/\\](?:_app|_document|_error|404|500)\.[^.]+$/.test(filePath)
) {
return
}

const page = isApp
? normalizeAppPath(path.relative(this.appDir, filePath))
: '/' + path.relative(this.pagesDir, filePath)

let route =
(isApp
? page.replace(/\/page\.[^./]+$/, '')
: page.replace(/\.[^./]+$/, '')
).replace(/\/index$/, '') || '/'
? page.replace(/[/\\]page\.[^./]+$/, '')
: page.replace(/\.[^./]+$/, '').replace(/[/\\]index$/, '')
).replace(/\\/g, '/') || '/'

if (isDynamicRoute(route)) {
route = route
Expand Down

0 comments on commit f8c98ab

Please sign in to comment.