Skip to content

Commit

Permalink
Support experimental-edge, but allow edge too
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz committed Jun 12, 2022
1 parent 1b930c5 commit 75daab1
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions packages/next/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { parseModule } from './parse-module'
import { promises as fs } from 'fs'
import { tryToParsePath } from '../../lib/try-to-parse-path'
import { isMiddlewareFile } from '../utils'
import * as Log from '../output/log'

interface MiddlewareConfig {
pathMatcher: RegExp
Expand Down Expand Up @@ -38,12 +39,16 @@ export async function getPageStaticInfo(params: {
const { ssg, ssr } = checkExports(swcAST)
const config = tryToExtractExportedConstValue(swcAST, 'config') || {}

const runtime =
config?.runtime === 'edge'
? 'edge'
: ssr || ssg
? config?.runtime || nextConfig.experimental?.runtime
: undefined
let runtime = ['experimental-edge', 'edge'].includes(config?.runtime)
? 'edge'
: ssr || ssg
? config?.runtime || nextConfig.experimental?.runtime
: undefined

if (runtime === 'experimental-edge' || runtime === 'edge') {
warnAboutExperimentalEdgeApiFunctions()
runtime = 'edge'
}

const middlewareConfig =
isMiddlewareFile(params.page!) && getMiddlewareConfig(config)
Expand Down Expand Up @@ -174,3 +179,13 @@ function getMiddlewareRegExpStrings(matcherOrMatchers: unknown): string[] {
return regexes
}
}

function warnAboutExperimentalEdgeApiFunctions() {
if (warnedAboutExperimentalEdgeApiFunctions) {
return
}
Log.warn(`You are using an experimental edge runtime, the API might change.`)
warnedAboutExperimentalEdgeApiFunctions = true
}

let warnedAboutExperimentalEdgeApiFunctions = false

0 comments on commit 75daab1

Please sign in to comment.