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
fix(#38743): config.runtime support template literal #38750
Changes from 4 commits
5bc2585
f35478e
dcbfbde
754c515
83f753f
6dc3e28
f55f103
d7a713c
e34ba69
1858c1a
3615bd9
edd4b40
adfe7b1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
import { isServerRuntime, ServerRuntime } from '../../server/config-shared' | ||
import type { NextConfig } from '../../server/config-shared' | ||
import { tryToExtractExportedConstValue } from './extract-const-value' | ||
import { | ||
extractExportedConstValue, | ||
UnsupportedValueError, | ||
} from './extract-const-value' | ||
import { escapeStringRegexp } from '../../shared/lib/escape-regexp' | ||
import { parseModule } from './parse-module' | ||
import { promises as fs } from 'fs' | ||
|
@@ -32,13 +35,28 @@ export async function getPageStaticInfo(params: { | |
isDev?: boolean | ||
page?: string | ||
}): Promise<PageStaticInfo> { | ||
const { isDev, pageFilePath, nextConfig } = params | ||
const { isDev, pageFilePath, nextConfig, page } = params | ||
|
||
const fileContent = (await tryToReadFile(pageFilePath, !isDev)) || '' | ||
if (/runtime|getStaticProps|getServerSideProps|matcher/.test(fileContent)) { | ||
const swcAST = await parseModule(pageFilePath, fileContent) | ||
const { ssg, ssr } = checkExports(swcAST) | ||
const config = tryToExtractExportedConstValue(swcAST, 'config') || {} | ||
|
||
// default / failsafe value for config | ||
let config: any = {} | ||
try { | ||
config = extractExportedConstValue(swcAST, 'config') | ||
} catch (e) { | ||
if (e instanceof UnsupportedValueError) { | ||
// `export config` is found, but can't extract its value | ||
Log.warn( | ||
SukkaW marked this conversation as resolved.
Show resolved
Hide resolved
|
||
`You have exported a \`config\` field in "${ | ||
page || pageFilePath | ||
}" that Next.js can't recognize, so it will be ignored` | ||
) | ||
} | ||
// `export config` doesn't exist, or other unknown error throw by swc, silence them | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion(blocker): rather than discontinuing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have thought about adding the logging in So I just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. Let's get rid of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! I have removed it in |
||
|
||
if ( | ||
typeof config.runtime !== 'string' && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default (req) => { | ||
return new Response(`Returned by Edge API Route ${req.url}`) | ||
} | ||
|
||
export const config = { | ||
runtime: `experimental-edge`, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought: It is fair to not support real interpolation.
The best option would be to load the file and check the exported value. However, that's not an option, so we can go with this tradeoff.