Skip to content
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

Add runtime to PageConfig type #37453

Merged
merged 9 commits into from
Aug 7, 2022
Merged
Show file tree
Hide file tree
Changes from 8 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
3 changes: 2 additions & 1 deletion packages/next/build/analysis/get-page-static-info.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isServerRuntime, ServerRuntime } from '../../server/config-shared'
import { isServerRuntime } from '../../server/config-shared'
import type { NextConfig } from '../../server/config-shared'
import {
extractExportedConstValue,
Expand All @@ -10,6 +10,7 @@ import { promises as fs } from 'fs'
import { tryToParsePath } from '../../lib/try-to-parse-path'
import * as Log from '../output/log'
import { SERVER_RUNTIME } from '../../lib/constants'
import { ServerRuntime } from '../../types'

interface MiddlewareConfig {
pathMatcher: RegExp
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pag
import type { MiddlewareLoaderOptions } from './webpack/loaders/next-middleware-loader'
import type { EdgeSSRLoaderQuery } from './webpack/loaders/next-edge-ssr-loader'
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 { webpack5 } from 'next/dist/compiled/webpack/webpack'
import type { LoadedEnvFiles } from '@next/env'
Expand Down Expand Up @@ -38,6 +37,7 @@ import { getPageStaticInfo } from './analysis/get-page-static-info'
import { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep'
import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
import { serverComponentRegex } from './webpack/loaders/utils'
import { ServerRuntime } from '../types'

type ObjectValue<T> = T extends { [key: string]: infer V } ? V : never

Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { NextConfigComplete, ServerRuntime } from '../server/config-shared'
import type { NextConfigComplete } from '../server/config-shared'

import '../server/node-polyfill-fetch'
import chalk from 'next/dist/compiled/chalk'
Expand Down Expand Up @@ -27,7 +27,7 @@ import { getRouteMatcher } from '../shared/lib/router/utils/route-matcher'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import escapePathDelimiters from '../shared/lib/router/utils/escape-path-delimiters'
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 { removeTrailingSlash } from '../shared/lib/router/utils/remove-trailing-slash'
import { UnwrapPromise } from '../lib/coalesced-function'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ServerRuntime } from '../server/config-shared'
import type { ServerRuntime } from '../types'
import { join } from '../shared/lib/isomorphic/path'

export const NEXT_PROJECT_ROOT = join(__dirname, '..', '..')
Expand Down
2 changes: 1 addition & 1 deletion packages/next/server/app-render.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IncomingHttpHeaders, IncomingMessage, ServerResponse } from 'http'
import type { LoadComponentsReturnType } from './load-components'
import type { ServerRuntime } from './config-shared'
import type { ServerRuntime } from '../types'

import React from 'react'
import { ParsedUrlQuery, stringify as stringifyQuery } from 'querystring'
Expand Down
8 changes: 2 additions & 6 deletions packages/next/server/base-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import type { FontManifest } from './font-utils'
import type { LoadComponentsReturnType } from './load-components'
import type { RouteMatch } from '../shared/lib/router/utils/route-matcher'
import type { Params } from '../shared/lib/router/utils/route-matcher'
import type {
NextConfig,
NextConfigComplete,
ServerRuntime,
} from './config-shared'
import type { NextConfig, NextConfigComplete } from './config-shared'
import type { NextParsedUrlQuery, NextUrlWithParsedQuery } from './request-meta'
import type { ParsedUrlQuery } from 'querystring'
import type { RenderOpts, RenderOptsPartial } from './render'
Expand All @@ -23,7 +19,7 @@ import {
normalizeRepeatedSlashes,
MissingStaticPage,
} 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 { BaseNextRequest, BaseNextResponse } from './base-http'
import type { PayloadOptions } from './send-payload'
Expand Down
3 changes: 1 addition & 2 deletions packages/next/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ import {
imageConfigDefault,
RemotePattern,
} from '../shared/lib/image-config'

export type ServerRuntime = 'nodejs' | 'experimental-edge' | undefined
import { ServerRuntime } from '../types'

export type NextConfigComplete = Required<NextConfig> & {
images: Required<ImageConfigComplete>
Expand Down
8 changes: 6 additions & 2 deletions packages/next/server/render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ import type { Redirect } from '../lib/load-custom-routes'
import type { NextApiRequestCookies, __ApiPreviewProps } from './api-utils'
import type { FontManifest } from './font-utils'
import type { LoadComponentsReturnType, ManifestItem } from './load-components'
import type { GetServerSideProps, GetStaticProps, PreviewData } from '../types'
import type {
GetServerSideProps,
GetStaticProps,
PreviewData,
ServerRuntime,
} from '../types'
import type { UnwrapPromise } from '../lib/coalesced-function'
import type { ReactReadableStream } from './node-web-streams-helper'
import type { ServerRuntime } from './config-shared'

import React from 'react'
import { StyleRegistry, createStyleRegistry } from 'styled-jsx'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/shared/lib/html-context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BuildManifest } from '../../server/get-page-files'
import type { ServerRuntime } from '../../server/config-shared'
import type { ServerRuntime } from '../../types'
import type { NEXT_DATA } from './utils'

import { createContext } from 'react'
Expand Down
3 changes: 3 additions & 0 deletions packages/next/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import {
// @ts-ignore This path is generated at build time and conflicts otherwise
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
export { NextConfig } from '../dist/server/config'

Expand Down Expand Up @@ -81,6 +83,7 @@ export type PageConfig = {
externalResolver?: true
}
env?: Array<string>
runtime?: ServerRuntime
unstable_runtimeJS?: false
unstable_JsPreload?: false
unstable_includeFiles?: string[]
Expand Down
9 changes: 9 additions & 0 deletions test/production/typescript-basic/app/pages/api/hello.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { PageConfig } from 'next'

export const config: PageConfig = {
runtime: 'nodejs',
}

export default function handler(req, res) {
res.json({ hello: 'world' })
}