From 64e3aa7ceaa04632139ec46273243929d1c46522 Mon Sep 17 00:00:00 2001 From: Yamagishi Kazutoshi Date: Sun, 5 Jun 2022 08:36:11 +0900 Subject: [PATCH 1/6] Add runtime to PageConfig type --- packages/next/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/next/types/index.d.ts b/packages/next/types/index.d.ts index 2bee2fba94fc..3d4dee7431c5 100644 --- a/packages/next/types/index.d.ts +++ b/packages/next/types/index.d.ts @@ -82,6 +82,7 @@ export type PageConfig = { externalResolver?: true } env?: Array + runtime?: 'nodejs' | 'edge' unstable_runtimeJS?: false unstable_JsPreload?: false unstable_includeFiles?: string[] From 8a44fef8b45d499c42494cfc9b8f017b8a21a744 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 7 Aug 2022 12:03:59 -0500 Subject: [PATCH 2/6] Add test case for runtime type --- test/production/typescript-basic/app/pages/api/hello.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 test/production/typescript-basic/app/pages/api/hello.ts diff --git a/test/production/typescript-basic/app/pages/api/hello.ts b/test/production/typescript-basic/app/pages/api/hello.ts new file mode 100644 index 000000000000..9f0688e3c58e --- /dev/null +++ b/test/production/typescript-basic/app/pages/api/hello.ts @@ -0,0 +1,9 @@ +import { PageConfig } from 'next' + +export const config: PageConfig = { + runtime: 'nodejs', +} + +export default function handler(req, res) { + res.json({ hello: 'world' }) +} From 66bf5288d09bae0b2d27a1597257454ee5b9452f Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 7 Aug 2022 12:08:10 -0500 Subject: [PATCH 3/6] Apply suggestions from code review --- packages/next/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/types/index.d.ts b/packages/next/types/index.d.ts index e11b1c19ff5c..6d2566f97337 100644 --- a/packages/next/types/index.d.ts +++ b/packages/next/types/index.d.ts @@ -81,7 +81,7 @@ export type PageConfig = { externalResolver?: true } env?: Array - runtime?: 'nodejs' | 'edge' + runtime?: 'nodejs' | 'experimental-edge' unstable_runtimeJS?: false unstable_JsPreload?: false unstable_includeFiles?: string[] From 91466587526eb9156b7ae32827b95a149b41a4f7 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 7 Aug 2022 12:09:29 -0500 Subject: [PATCH 4/6] dedupe type --- packages/next/types/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/types/index.d.ts b/packages/next/types/index.d.ts index 6d2566f97337..77afa804317d 100644 --- a/packages/next/types/index.d.ts +++ b/packages/next/types/index.d.ts @@ -22,6 +22,7 @@ import { // @ts-ignore This path is generated at build time and conflicts otherwise import next from '../dist/server/next' +import { ServerRuntime } from '../server/config-shared' // @ts-ignore This path is generated at build time and conflicts otherwise export { NextConfig } from '../dist/server/config' @@ -81,7 +82,7 @@ export type PageConfig = { externalResolver?: true } env?: Array - runtime?: 'nodejs' | 'experimental-edge' + runtime?: ServerRuntime unstable_runtimeJS?: false unstable_JsPreload?: false unstable_includeFiles?: string[] From e2a9e08535f03c21197e7b300e34527e39c682ba Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 7 Aug 2022 13:42:32 -0500 Subject: [PATCH 5/6] fix import --- packages/next/build/analysis/get-page-static-info.ts | 3 ++- packages/next/build/entries.ts | 2 +- packages/next/build/utils.ts | 4 ++-- packages/next/lib/constants.ts | 2 +- packages/next/server/app-render.tsx | 2 +- packages/next/server/base-server.ts | 8 ++------ packages/next/server/config-shared.ts | 3 +-- packages/next/server/render.tsx | 8 ++++++-- packages/next/shared/lib/html-context.ts | 2 +- packages/next/types/index.d.ts | 3 ++- 10 files changed, 19 insertions(+), 18 deletions(-) diff --git a/packages/next/build/analysis/get-page-static-info.ts b/packages/next/build/analysis/get-page-static-info.ts index 8d7353e74e4d..d27ef9057b1b 100644 --- a/packages/next/build/analysis/get-page-static-info.ts +++ b/packages/next/build/analysis/get-page-static-info.ts @@ -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, @@ -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 diff --git a/packages/next/build/entries.ts b/packages/next/build/entries.ts index 1e17ff961053..5d757be91e85 100644 --- a/packages/next/build/entries.ts +++ b/packages/next/build/entries.ts @@ -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' @@ -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 extends { [key: string]: infer V } ? V : never diff --git a/packages/next/build/utils.ts b/packages/next/build/utils.ts index 95f8d413a000..e1c1a85900a0 100644 --- a/packages/next/build/utils.ts +++ b/packages/next/build/utils.ts @@ -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' @@ -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' diff --git a/packages/next/lib/constants.ts b/packages/next/lib/constants.ts index 6571d0fc6254..a7f0d8018b0c 100644 --- a/packages/next/lib/constants.ts +++ b/packages/next/lib/constants.ts @@ -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, '..', '..') diff --git a/packages/next/server/app-render.tsx b/packages/next/server/app-render.tsx index e947063a7e82..a659a9218954 100644 --- a/packages/next/server/app-render.tsx +++ b/packages/next/server/app-render.tsx @@ -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' diff --git a/packages/next/server/base-server.ts b/packages/next/server/base-server.ts index 78e51f1e708a..072d714c3161 100644 --- a/packages/next/server/base-server.ts +++ b/packages/next/server/base-server.ts @@ -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' @@ -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' diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index e0999cba59b5..9c4279f8a69a 100644 --- a/packages/next/server/config-shared.ts +++ b/packages/next/server/config-shared.ts @@ -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 & { images: Required diff --git a/packages/next/server/render.tsx b/packages/next/server/render.tsx index 5cbb709c52b4..a58aaae33715 100644 --- a/packages/next/server/render.tsx +++ b/packages/next/server/render.tsx @@ -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' diff --git a/packages/next/shared/lib/html-context.ts b/packages/next/shared/lib/html-context.ts index 7770988c9271..f0ee0901ab9f 100644 --- a/packages/next/shared/lib/html-context.ts +++ b/packages/next/shared/lib/html-context.ts @@ -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' diff --git a/packages/next/types/index.d.ts b/packages/next/types/index.d.ts index 77afa804317d..25b63fe25533 100644 --- a/packages/next/types/index.d.ts +++ b/packages/next/types/index.d.ts @@ -22,7 +22,8 @@ import { // @ts-ignore This path is generated at build time and conflicts otherwise import next from '../dist/server/next' -import { ServerRuntime } from '../server/config-shared' + +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' From 10a6f67cb4cf04f09be5f75c5e36425ec800cdf2 Mon Sep 17 00:00:00 2001 From: JJ Kasper Date: Sun, 7 Aug 2022 13:52:45 -0500 Subject: [PATCH 6/6] fix lint --- packages/next/server/config-shared.ts | 2 +- packages/next/server/render.tsx | 2 +- packages/next/shared/lib/html-context.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/next/server/config-shared.ts b/packages/next/server/config-shared.ts index 9c4279f8a69a..416fc7cb01da 100644 --- a/packages/next/server/config-shared.ts +++ b/packages/next/server/config-shared.ts @@ -7,7 +7,7 @@ import { imageConfigDefault, RemotePattern, } from '../shared/lib/image-config' -import { ServerRuntime } from '../types' +import { ServerRuntime } from 'next/types' export type NextConfigComplete = Required & { images: Required diff --git a/packages/next/server/render.tsx b/packages/next/server/render.tsx index a58aaae33715..f770e6e6a9bf 100644 --- a/packages/next/server/render.tsx +++ b/packages/next/server/render.tsx @@ -23,7 +23,7 @@ import type { GetStaticProps, PreviewData, ServerRuntime, -} from '../types' +} from 'next/types' import type { UnwrapPromise } from '../lib/coalesced-function' import type { ReactReadableStream } from './node-web-streams-helper' diff --git a/packages/next/shared/lib/html-context.ts b/packages/next/shared/lib/html-context.ts index f0ee0901ab9f..88fb551a9711 100644 --- a/packages/next/shared/lib/html-context.ts +++ b/packages/next/shared/lib/html-context.ts @@ -1,5 +1,5 @@ import type { BuildManifest } from '../../server/get-page-files' -import type { ServerRuntime } from '../../types' +import type { ServerRuntime } from 'next/types' import type { NEXT_DATA } from './utils' import { createContext } from 'react'