Skip to content

Commit 781be0c

Browse files
committed
chore: support jsx
1 parent a190160 commit 781be0c

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/runtime/src/helpers/analysis.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import fs from 'fs'
1+
import fs, { existsSync } from 'fs'
22

33
import { extractExportedConstValue, UnsupportedValueError } from 'next/dist/build/analysis/extract-const-value'
44
import { parseModule } from 'next/dist/build/analysis/parse-module'
@@ -85,6 +85,9 @@ export const validateConfigValue = (config: ApiConfig, apiFilePath: string): con
8585
* Uses Next's swc static analysis to extract the config values from a file.
8686
*/
8787
export const extractConfigFromFile = async (apiFilePath: string): Promise<ApiConfig> => {
88+
if (!apiFilePath || !existsSync(apiFilePath)) {
89+
return {}
90+
}
8891
const fileContent = await fs.promises.readFile(apiFilePath, 'utf8')
8992
// No need to parse if there's no "config"
9093
if (!fileContent.includes('config')) {

packages/runtime/src/helpers/files.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { Rewrites, RoutesManifest } from './types'
1818
import { findModuleFromBase } from './utils'
1919

2020
const TEST_ROUTE = /(|\/)\[[^/]+?](\/|\.html|$)/
21+
const SOURCE_FILE_EXTENSIONS = ['js', 'jsx', 'ts', 'tsx']
2122

2223
export const isDynamicRoute = (route) => TEST_ROUTE.test(route)
2324

@@ -337,12 +338,13 @@ const getServerFile = (root: string, includeBase = true) => {
337338
* Find the source file for a given page route
338339
*/
339340
export const getSourceFileForPage = (page: string, root: string) => {
340-
for (const extension of ['ts', 'js']) {
341+
for (const extension of SOURCE_FILE_EXTENSIONS) {
341342
const file = join(root, `${page}.${extension}`)
342343
if (existsSync(file)) {
343344
return file
344345
}
345346
}
347+
console.log('Could not find source file for page', page)
346348
}
347349

348350
/**

0 commit comments

Comments
 (0)