Unverified Commit 0796b6fa authored by Yamagishi Kazutoshi's avatar Yamagishi Kazutoshi Committed by GitHub

Add runtime to PageConfig type (#37453)

* Add runtime to PageConfig type

* Add test case for runtime type

* Apply suggestions from code review

* dedupe type

* fix import

* fix lint
Co-authored-by: 's avatarJJ Kasper <jj@jjsweb.site>
parent a720dbdc
import { isServerRuntime, ServerRuntime } from '../../server/config-shared' import { isServerRuntime } from '../../server/config-shared'
import type { NextConfig } from '../../server/config-shared' import type { NextConfig } from '../../server/config-shared'
import { import {
extractExportedConstValue, extractExportedConstValue,
...@@ -10,6 +10,7 @@ import { promises as fs } from 'fs' ...@@ -10,6 +10,7 @@ import { promises as fs } from 'fs'
import { tryToParsePath } from '../../lib/try-to-parse-path' import { tryToParsePath } from '../../lib/try-to-parse-path'
import * as Log from '../output/log' import * as Log from '../output/log'
import { SERVER_RUNTIME } from '../../lib/constants' import { SERVER_RUNTIME } from '../../lib/constants'
import { ServerRuntime } from '../../types'
interface MiddlewareConfig { interface MiddlewareConfig {
pathMatcher: RegExp pathMatcher: RegExp
......
...@@ -2,7 +2,6 @@ import type { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pag ...@@ -2,7 +2,6 @@ import type { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pag
import type { MiddlewareLoaderOptions } from './webpack/loaders/next-middleware-loader' import type { MiddlewareLoaderOptions } from './webpack/loaders/next-middleware-loader'
import type { EdgeSSRLoaderQuery } from './webpack/loaders/next-edge-ssr-loader' import type { EdgeSSRLoaderQuery } from './webpack/loaders/next-edge-ssr-loader'
import type { NextConfigComplete } from '../server/config-shared' import type { NextConfigComplete } from '../server/config-shared'
import type { ServerRuntime } from '../server/config-shared'
import type { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader' import type { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
import type { webpack5 } from 'next/dist/compiled/webpack/webpack' import type { webpack5 } from 'next/dist/compiled/webpack/webpack'
import type { LoadedEnvFiles } from '@next/env' import type { LoadedEnvFiles } from '@next/env'
...@@ -38,6 +37,7 @@ import { getPageStaticInfo } from './analysis/get-page-static-info' ...@@ -38,6 +37,7 @@ import { getPageStaticInfo } from './analysis/get-page-static-info'
import { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep' import { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep'
import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path' import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
import { serverComponentRegex } from './webpack/loaders/utils' import { serverComponentRegex } from './webpack/loaders/utils'
import { ServerRuntime } from '../types'
type ObjectValue<T> = T extends { [key: string]: infer V } ? V : never type ObjectValue<T> = T extends { [key: string]: infer V } ? V : never
......
import type { NextConfigComplete, ServerRuntime } from '../server/config-shared' import type { NextConfigComplete } from '../server/config-shared'
import '../server/node-polyfill-fetch' import '../server/node-polyfill-fetch'
import chalk from 'next/dist/compiled/chalk' import chalk from 'next/dist/compiled/chalk'
...@@ -27,7 +27,7 @@ import { getRouteMatcher } from '../shared/lib/router/utils/route-matcher' ...@@ -27,7 +27,7 @@ import { getRouteMatcher } from '../shared/lib/router/utils/route-matcher'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import escapePathDelimiters from '../shared/lib/router/utils/escape-path-delimiters' import escapePathDelimiters from '../shared/lib/router/utils/escape-path-delimiters'
import { findPageFile } from '../server/lib/find-page-file' import { findPageFile } from '../server/lib/find-page-file'
import { GetStaticPaths, PageConfig } from 'next/types' import { GetStaticPaths, PageConfig, ServerRuntime } from 'next/types'
import { BuildManifest } from '../server/get-page-files' import { BuildManifest } from '../server/get-page-files'
import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash' import { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash'
import { UnwrapPromise } from '../lib/coalesced-function' import { UnwrapPromise } from '../lib/coalesced-function'
......
import type { ServerRuntime } from '../server/config-shared' import type { ServerRuntime } from '../types'
import { join } from '../shared/lib/isomorphic/path' import { join } from '../shared/lib/isomorphic/path'
export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..') export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..')
......
import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http' import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http'
import type { LoadComponentsReturnType } from './load-components' import type { LoadComponentsReturnType } from './load-components'
import type { ServerRuntime } from './config-shared' import type { ServerRuntime } from '../types'
import React from 'react' import React from 'react'
import { ParsedUrlQuery, stringify as stringifyQuery } from 'querystring' import { ParsedUrlQuery, stringify as stringifyQuery } from 'querystring'
......
...@@ -6,11 +6,7 @@ import type { FontManifest } from './font-utils' ...@@ -6,11 +6,7 @@ import type { FontManifest } from './font-utils'
import type { LoadComponentsReturnType } from './load-components' import type { LoadComponentsReturnType } from './load-components'
import type { RouteMatch } from '../shared/lib/router/utils/route-matcher' import type { RouteMatch } from '../shared/lib/router/utils/route-matcher'
import type { Params } from '../shared/lib/router/utils/route-matcher' import type { Params } from '../shared/lib/router/utils/route-matcher'
import type { import type { NextConfig, NextConfigComplete } from './config-shared'
NextConfig,
NextConfigComplete,
ServerRuntime,
} from './config-shared'
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta' import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta'
import type { ParsedUrlQuery } from 'querystring' import type { ParsedUrlQuery } from 'querystring'
import type { RenderOpts, RenderOptsPartial } from './render' import type { RenderOpts, RenderOptsPartial } from './render'
...@@ -23,7 +19,7 @@ import { ...@@ -23,7 +19,7 @@ import {
normalizeRepeatedSlashes, normalizeRepeatedSlashes,
MissingStaticPage, MissingStaticPage,
} from '../shared/lib/utils' } from '../shared/lib/utils'
import type { PreviewData } from 'next/types' import type { PreviewData, ServerRuntime } from 'next/types'
import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin' import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
import type { BaseNextRequest, BaseNextResponse } from './base-http' import type { BaseNextRequest, BaseNextResponse } from './base-http'
import type { PayloadOptions } from './send-payload' import type { PayloadOptions } from './send-payload'
......
...@@ -7,8 +7,7 @@ import { ...@@ -7,8 +7,7 @@ import {
imageConfigDefault, imageConfigDefault,
RemotePattern, RemotePattern,
} from '../shared/lib/image-config' } from '../shared/lib/image-config'
import { ServerRuntime } from 'next/types'
export type ServerRuntime = 'nodejs' | 'experimental-edge' | undefined
export type NextConfigComplete = Required<NextConfig> & { export type NextConfigComplete = Required<NextConfig> & {
images: Required<ImageConfigComplete> images: Required<ImageConfigComplete>
......
...@@ -18,10 +18,14 @@ import type { Redirect } from '../lib/load-custom-routes' ...@@ -18,10 +18,14 @@ import type { Redirect } from '../lib/load-custom-routes'
import type { NextApiRequestCookies, __ApiPreviewProps } from './api-utils' import type { NextApiRequestCookies, __ApiPreviewProps } from './api-utils'
import type { FontManifest } from './font-utils' import type { FontManifest } from './font-utils'
import type { LoadComponentsReturnType, ManifestItem } from './load-components' import type { LoadComponentsReturnType, ManifestItem } from './load-components'
import type { GetServerSideProps, GetStaticProps, PreviewData } from '../types' import type {
GetServerSideProps,
GetStaticProps,
PreviewData,
ServerRuntime,
} from 'next/types'
import type { UnwrapPromise } from '../lib/coalesced-function' import type { UnwrapPromise } from '../lib/coalesced-function'
import type { ReactReadableStream } from './node-web-streams-helper' import type { ReactReadableStream } from './node-web-streams-helper'
import type { ServerRuntime } from './config-shared'
import React from 'react' import React from 'react'
import { StyleRegistry, createStyleRegistry } from 'styled-jsx' import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
......
import type { BuildManifest } from '../../server/get-page-files' import type { BuildManifest } from '../../server/get-page-files'
import type { ServerRuntime } from '../../server/config-shared' import type { ServerRuntime } from 'next/types'
import type { NEXT_DATA } from './utils' import type { NEXT_DATA } from './utils'
import { createContext } from 'react' import { createContext } from 'react'
......
...@@ -23,6 +23,8 @@ import { ...@@ -23,6 +23,8 @@ import {
// @ts-ignore This path is generated at build time and conflicts otherwise // @ts-ignore This path is generated at build time and conflicts otherwise
import next from '../dist/server/next' import next from '../dist/server/next'
export type ServerRuntime = 'nodejs' | 'experimental-edge' | undefined
// @ts-ignore This path is generated at build time and conflicts otherwise // @ts-ignore This path is generated at build time and conflicts otherwise
export { NextConfig } from '../dist/server/config' export { NextConfig } from '../dist/server/config'
...@@ -81,6 +83,7 @@ export type PageConfig = { ...@@ -81,6 +83,7 @@ export type PageConfig = {
externalResolver?: true externalResolver?: true
} }
env?: Array<string> env?: Array<string>
runtime?: ServerRuntime
unstable_runtimeJS?: false unstable_runtimeJS?: false
unstable_JsPreload?: false unstable_JsPreload?: false
unstable_includeFiles?: string[] unstable_includeFiles?: string[]
......
import { PageConfig } from 'next'
export const config: PageConfig = {
runtime: 'nodejs',
}
export default function handler(req, res) {
res.json({ hello: 'world' })
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment