Skip to content

[do-not-merge] just trying to run PR#2101 not through fork #2103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/runtime/src/helpers/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,11 @@ export const getSourceFileForPage = (page: string, roots: string[], pageExtensio
if (existsSync(file)) {
return file
}

const fileAtFolderIndex = join(root, page, `index.${extension}`)
if (existsSync(fileAtFolderIndex)) {
return fileAtFolderIndex
}
}
}
console.log('Could not find source file for page', page)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// noop
9 changes: 9 additions & 0 deletions test/helpers/files.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,13 @@ describe('getSourceFileForPage', () => {

expect(filePath.replace(TEST_DIR, '')).toBe('/fixtures/page-extensions/custom/pages/api/custom.api.js')
})

it('handles getting file when index of folder', () => {
const pagesDir = resolve(__dirname, '../fixtures/page-extensions/index/pages')
const apiRoute = '/api/index'

const filePath = getSourceFileForPage(apiRoute, [pagesDir])

expect(filePath.replace(TEST_DIR, '')).toBe('/fixtures/page-extensions/index/pages/api/index/index.js')
})
})