Unverified Commit 1e3a1cba authored by Jiachi Liu's avatar Jiachi Liu Committed by GitHub

Upgrade typescript to 5.3 (#64043)

Closes NEXT-2997

---------
Co-authored-by: 's avatareps1lon <sebastian.silbermann@vercel.com>
parent 1fd93eed
...@@ -103,10 +103,10 @@ ...@@ -103,10 +103,10 @@
"@types/html-validator": "5.0.3", "@types/html-validator": "5.0.3",
"@types/http-proxy": "1.17.3", "@types/http-proxy": "1.17.3",
"@types/jest": "29.5.5", "@types/jest": "29.5.5",
"@types/node": "20.2.5", "@types/node": "20.12.3",
"@types/node-fetch": "2.6.1", "@types/node-fetch": "2.6.1",
"@types/react": "18.2.37", "@types/react": "18.2.74",
"@types/react-dom": "18.2.15", "@types/react-dom": "18.2.23",
"@types/relay-runtime": "14.1.13", "@types/relay-runtime": "14.1.13",
"@types/selenium-webdriver": "4.0.15", "@types/selenium-webdriver": "4.0.15",
"@types/sharp": "0.29.3", "@types/sharp": "0.29.3",
...@@ -233,7 +233,7 @@ ...@@ -233,7 +233,7 @@
"tree-kill": "1.2.2", "tree-kill": "1.2.2",
"tsec": "0.2.1", "tsec": "0.2.1",
"turbo": "1.12.5", "turbo": "1.12.5",
"typescript": "5.2.2", "typescript": "5.3.3",
"unfetch": "4.2.0", "unfetch": "4.2.0",
"wait-port": "0.2.2", "wait-port": "0.2.2",
"webpack": "5.90.0", "webpack": "5.90.0",
...@@ -246,13 +246,13 @@ ...@@ -246,13 +246,13 @@
"webpack": "5.90.0", "webpack": "5.90.0",
"browserslist": "4.22.2", "browserslist": "4.22.2",
"caniuse-lite": "1.0.30001579", "caniuse-lite": "1.0.30001579",
"@types/node": "20.2.5", "@types/node": "20.12.3",
"@babel/core": "7.22.5", "@babel/core": "7.22.5",
"@babel/parser": "7.22.5", "@babel/parser": "7.22.5",
"@babel/types": "7.22.5", "@babel/types": "7.22.5",
"@babel/traverse": "7.22.5", "@babel/traverse": "7.22.5",
"@types/react": "18.2.37", "@types/react": "18.2.74",
"@types/react-dom": "18.2.15" "@types/react-dom": "18.2.23"
}, },
"engines": { "engines": {
"node": ">=18.17.0", "node": ">=18.17.0",
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
"@types/async-retry": "1.4.2", "@types/async-retry": "1.4.2",
"@types/ci-info": "2.0.0", "@types/ci-info": "2.0.0",
"@types/cross-spawn": "6.0.0", "@types/cross-spawn": "6.0.0",
"@types/node": "^20.2.5", "@types/node": "^20.12.3",
"@types/prompts": "2.4.2", "@types/prompts": "2.4.2",
"@types/tar": "6.1.5", "@types/tar": "6.1.5",
"@types/validate-npm-package-name": "3.0.0", "@types/validate-npm-package-name": "3.0.0",
......
/// <reference types="./types/global" /> /// <reference types="./types/global" />
/// <reference types="./types/compiled" />
/// <reference path="./dist/styled-jsx/types/global.d.ts" /> /// <reference path="./dist/styled-jsx/types/global.d.ts" />
/// <reference path="./amp.d.ts" /> /// <reference path="./amp.d.ts" />
/// <reference path="./app.d.ts" /> /// <reference path="./app.d.ts" />
......
...@@ -49,8 +49,9 @@ ...@@ -49,8 +49,9 @@
"amp.d.ts", "amp.d.ts",
"og.js", "og.js",
"og.d.ts", "og.d.ts",
"types.d.ts",
"types.js",
"index.d.ts", "index.d.ts",
"types/index.d.ts",
"types/global.d.ts", "types/global.d.ts",
"types/compiled.d.ts", "types/compiled.d.ts",
"image-types/global.d.ts", "image-types/global.d.ts",
...@@ -182,9 +183,9 @@ ...@@ -182,9 +183,9 @@
"@types/path-to-regexp": "1.7.0", "@types/path-to-regexp": "1.7.0",
"@types/picomatch": "2.3.3", "@types/picomatch": "2.3.3",
"@types/platform": "1.3.4", "@types/platform": "1.3.4",
"@types/react": "18.2.37", "@types/react": "18.2.74",
"@types/react-dom": "18.2.15", "@types/react-dom": "18.2.23",
"@types/react-is": "17.0.3", "@types/react-is": "18.2.4",
"@types/semver": "7.3.1", "@types/semver": "7.3.1",
"@types/send": "0.14.4", "@types/send": "0.14.4",
"@types/shell-quote": "1.7.1", "@types/shell-quote": "1.7.1",
......
...@@ -4,7 +4,7 @@ import type { Middleware, RouteHas } from '../../lib/load-custom-routes' ...@@ -4,7 +4,7 @@ import type { Middleware, RouteHas } from '../../lib/load-custom-routes'
import { promises as fs } from 'fs' import { promises as fs } from 'fs'
import LRUCache from 'next/dist/compiled/lru-cache' import LRUCache from 'next/dist/compiled/lru-cache'
import picomatch from 'next/dist/compiled/picomatch' import picomatch from 'next/dist/compiled/picomatch'
import type { ServerRuntime } from 'next/types' import type { ServerRuntime } from '../../types'
import { import {
extractExportedConstValue, extractExportedConstValue,
UnsupportedValueError, UnsupportedValueError,
......
...@@ -5,7 +5,7 @@ import type { ...@@ -5,7 +5,7 @@ import type {
Visitor, Visitor,
NodePath, NodePath,
} from 'next/dist/compiled/babel/core' } from 'next/dist/compiled/babel/core'
import type { PageConfig } from 'next/types' import type { PageConfig } from '../../../types'
import { STRING_LITERAL_DROP_BUNDLE } from '../../../shared/lib/constants' import { STRING_LITERAL_DROP_BUNDLE } from '../../../shared/lib/constants'
const CONFIG_KEY = 'config' const CONFIG_KEY = 'config'
......
...@@ -50,7 +50,7 @@ import { ...@@ -50,7 +50,7 @@ import {
import { getPageStaticInfo } from './analysis/get-page-static-info' 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 type { ServerRuntime } from '../../types' import type { ServerRuntime } from '../types'
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths' import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
import { encodeMatchers } from './webpack/loaders/next-middleware-loader' import { encodeMatchers } from './webpack/loaders/next-middleware-loader'
import type { EdgeFunctionLoaderOptions } from './webpack/loaders/next-edge-function-loader' import type { EdgeFunctionLoaderOptions } from './webpack/loaders/next-edge-function-loader'
......
...@@ -6,7 +6,7 @@ import type { ...@@ -6,7 +6,7 @@ import type {
GetStaticPathsResult, GetStaticPathsResult,
PageConfig, PageConfig,
ServerRuntime, ServerRuntime,
} from 'next/types' } from '../types'
import type { BuildManifest } from '../server/get-page-files' import type { BuildManifest } from '../server/get-page-files'
import type { import type {
Redirect, Redirect,
......
import type webpack from 'webpack' import type webpack from 'webpack'
import type { SizeLimit } from '../../../../../types' import type { SizeLimit } from '../../../../types'
import type { PagesRouteModuleOptions } from '../../../../server/future/route-modules/pages/module' import type { PagesRouteModuleOptions } from '../../../../server/future/route-modules/pages/module'
import type { MiddlewareConfig } from '../../../analysis/get-page-static-info' import type { MiddlewareConfig } from '../../../analysis/get-page-static-info'
......
...@@ -15,7 +15,7 @@ import { ...@@ -15,7 +15,7 @@ import {
import { SERVER_RUNTIME } from '../../../../lib/constants' import { SERVER_RUNTIME } from '../../../../lib/constants'
import type { ManifestRewriteRoute, PrerenderManifest } from '../../..' import type { ManifestRewriteRoute, PrerenderManifest } from '../../..'
import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths' import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths'
import type { SizeLimit } from '../../../../../types' import type { SizeLimit } from '../../../../types'
import { internal_getCurrentFunctionWaitUntil } from '../../../../server/web/internal-edge-wait-until' import { internal_getCurrentFunctionWaitUntil } from '../../../../server/web/internal-edge-wait-until'
import type { PAGE_TYPES } from '../../../../lib/page-types' import type { PAGE_TYPES } from '../../../../lib/page-types'
import type { NextRequestHint } from '../../../../server/web/adapter' import type { NextRequestHint } from '../../../../server/web/adapter'
......
...@@ -26,7 +26,7 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ...@@ -26,7 +26,7 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE. DEALINGS IN THE SOFTWARE.
*/ */
import type { NextConfig } from '../../../../types' import type { NextConfig } from '../../../types'
import type { WebpackLayerName } from '../../../lib/constants' import type { WebpackLayerName } from '../../../lib/constants'
import { isWasm, transform } from '../../swc' import { isWasm, transform } from '../../swc'
import { getLoaderSWCOptions } from '../../swc/options' import { getLoaderSWCOptions } from '../../swc/options'
......
...@@ -441,8 +441,8 @@ declare namespace __next_route_internal_types__ { ...@@ -441,8 +441,8 @@ declare namespace __next_route_internal_types__ {
} }
declare module 'next' { declare module 'next' {
export { default } from 'next/types/index.js' export { default } from 'next/types.js'
export * from 'next/types/index.js' export * from 'next/types.js'
export type Route<T extends string = string> = export type Route<T extends string = string> =
__next_route_internal_types__.RouteImpl<T> __next_route_internal_types__.RouteImpl<T>
......
...@@ -528,8 +528,8 @@ function createPendingCacheNode( ...@@ -528,8 +528,8 @@ function createPendingCacheNode(
// Create a deferred promise. This will be fulfilled once the dynamic // Create a deferred promise. This will be fulfilled once the dynamic
// response is received from the server. // response is received from the server.
rsc: createDeferredRsc(), rsc: createDeferredRsc() as React.ReactNode,
head: isLeafSegment ? createDeferredRsc() : null, head: isLeafSegment ? (createDeferredRsc() as React.ReactNode) : null,
lazyDataResolved: false, lazyDataResolved: false,
} }
} }
......
import type { ServerRuntime } from '../../types' import type { ServerRuntime } from '../types'
export const NEXT_QUERY_PARAM_PREFIX = 'nxtP' export const NEXT_QUERY_PARAM_PREFIX = 'nxtP'
......
import type { ServerRuntime } from '../../types' import type { ServerRuntime } from '../types'
import { SERVER_RUNTIME } from './constants' import { SERVER_RUNTIME } from './constants'
export function isEdgeRuntime(value?: string): value is ServerRuntime { export function isEdgeRuntime(value?: string): value is ServerRuntime {
......
...@@ -9,7 +9,6 @@ export function enableMemoryDebuggingMode(): void { ...@@ -9,7 +9,6 @@ export function enableMemoryDebuggingMode(): void {
// memory limit. It does not give any warning to the user though which // memory limit. It does not give any warning to the user though which
// can be jarring. If memory is large, this may take a long time. // can be jarring. If memory is large, this may take a long time.
if ('setHeapSnapshotNearHeapLimit' in v8) { if ('setHeapSnapshotNearHeapLimit' in v8) {
// @ts-expect-error - this method exists since Node 16.
v8.setHeapSnapshotNearHeapLimit(1) v8.setHeapSnapshotNearHeapLimit(1)
} }
......
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import type { NextApiRequest, NextApiResponse } from '../../../shared/lib/utils' import type { NextApiRequest, NextApiResponse } from '../../../shared/lib/utils'
import type { PageConfig, ResponseLimit } from 'next/types' import type { PageConfig, ResponseLimit } from '../../../types'
import type { __ApiPreviewProps } from '../.' import type { __ApiPreviewProps } from '../.'
import type { CookieSerializeOptions } from 'next/dist/compiled/cookie' import type { CookieSerializeOptions } from 'next/dist/compiled/cookie'
......
import type { IncomingMessage } from 'http' import type { IncomingMessage } from 'http'
import type { SizeLimit } from 'next/types'
import { parse } from 'next/dist/compiled/content-type' import { parse } from 'next/dist/compiled/content-type'
import isError from '../../../lib/is-error' import isError from '../../../lib/is-error'
import type { SizeLimit } from '../../../types'
import { ApiError } from '../index' import { ApiError } from '../index'
/** /**
......
...@@ -3,7 +3,7 @@ import type { NextApiResponse } from '../../../shared/lib/utils' ...@@ -3,7 +3,7 @@ import type { NextApiResponse } from '../../../shared/lib/utils'
import { checkIsOnDemandRevalidate } from '../.' import { checkIsOnDemandRevalidate } from '../.'
import type { __ApiPreviewProps } from '../.' import type { __ApiPreviewProps } from '../.'
import type { BaseNextRequest, BaseNextResponse } from '../../base-http' import type { BaseNextRequest, BaseNextResponse } from '../../base-http'
import type { PreviewData } from 'next/types' import type { PreviewData } from '../../../types'
import { import {
clearPreviewData, clearPreviewData,
......
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http' import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'
import type { SizeLimit } from '../../../types' import type { SizeLimit } from '../../types'
import type { RequestStore } from '../../client/components/request-async-storage.external' import type { RequestStore } from '../../client/components/request-async-storage.external'
import type { AppRenderContext, GenerateFlight } from './app-render' import type { AppRenderContext, GenerateFlight } from './app-render'
import type { AppPageModule } from '../../server/future/route-modules/app-page/module' import type { AppPageModule } from '../../server/future/route-modules/app-page/module'
......
import type { LoadComponentsReturnType } from '../load-components' import type { LoadComponentsReturnType } from '../load-components'
import type { ServerRuntime, SizeLimit } from '../../../types' import type { ServerRuntime, SizeLimit } from '../../types'
import type { NextConfigComplete } from '../../server/config-shared' import type { NextConfigComplete } from '../../server/config-shared'
import type { ClientReferenceManifest } from '../../build/webpack/plugins/flight-manifest-plugin' import type { ClientReferenceManifest } from '../../build/webpack/plugins/flight-manifest-plugin'
import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin' import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin'
......
...@@ -20,7 +20,7 @@ import { ...@@ -20,7 +20,7 @@ import {
normalizeRepeatedSlashes, normalizeRepeatedSlashes,
MissingStaticPage, MissingStaticPage,
} from '../shared/lib/utils' } from '../shared/lib/utils'
import type { PreviewData } from 'next/types' import type { PreviewData } from '../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 { import type {
......
...@@ -4,7 +4,7 @@ import { VALID_LOADERS } from '../shared/lib/image-config' ...@@ -4,7 +4,7 @@ import { VALID_LOADERS } from '../shared/lib/image-config'
import { z } from 'next/dist/compiled/zod' import { z } from 'next/dist/compiled/zod'
import type zod from 'next/dist/compiled/zod' import type zod from 'next/dist/compiled/zod'
import type { SizeLimit } from '../../types' import type { SizeLimit } from '../types'
import type { import type {
ExportPathMap, ExportPathMap,
TurboLoaderItem, TurboLoaderItem,
......
...@@ -9,7 +9,7 @@ import type { ...@@ -9,7 +9,7 @@ import type {
import type { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin' import type { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin'
import type { WEB_VITALS } from '../shared/lib/utils' import type { WEB_VITALS } from '../shared/lib/utils'
import type { NextParsedUrlQuery } from './request-meta' import type { NextParsedUrlQuery } from './request-meta'
import type { SizeLimit } from '../../types' import type { SizeLimit } from '../types'
import type { SwrDelta } from './lib/revalidate' import type { SwrDelta } from './lib/revalidate'
export type NextConfigComplete = Required<NextConfig> & { export type NextConfigComplete = Required<NextConfig> & {
......
...@@ -1014,7 +1014,7 @@ export default async function loadConfig( ...@@ -1014,7 +1014,7 @@ export default async function loadConfig(
require('./config-schema') as typeof import('./config-schema') require('./config-schema') as typeof import('./config-schema')
const state = configSchema.safeParse(userConfig) const state = configSchema.safeParse(userConfig)
if (!state.success) { if (state.success === false) {
// error message header // error message header
const messages = [`Invalid ${configFileName} options detected: `] const messages = [`Invalid ${configFileName} options detected: `]
......
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import type { PagesAPIRouteDefinition } from '../../route-definitions/pages-api-route-definition' import type { PagesAPIRouteDefinition } from '../../route-definitions/pages-api-route-definition'
import type { PageConfig } from '../../../../../types' import type { PageConfig } from '../../../../types'
import type { ParsedUrlQuery } from 'querystring' import type { ParsedUrlQuery } from 'querystring'
import { wrapApiHandler, type __ApiPreviewProps } from '../../../api-utils' import { wrapApiHandler, type __ApiPreviewProps } from '../../../api-utils'
import type { RouteModuleOptions } from '../route-module' import type { RouteModuleOptions } from '../route-module'
......
...@@ -5,7 +5,7 @@ import type { ...@@ -5,7 +5,7 @@ import type {
GetStaticProps, GetStaticProps,
NextComponentType, NextComponentType,
PageConfig, PageConfig,
} from '../../../../../types' } from '../../../../types'
import type { PagesRouteDefinition } from '../../route-definitions/pages-route-definition' import type { PagesRouteDefinition } from '../../route-definitions/pages-route-definition'
import type { NextParsedUrlQuery } from '../../../request-meta' import type { NextParsedUrlQuery } from '../../../request-meta'
import type { RenderOpts } from '../../../render' import type { RenderOpts } from '../../../render'
......
...@@ -3,7 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'http' ...@@ -3,7 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'http'
import type { NextConfigComplete } from '../../config-shared' import type { NextConfigComplete } from '../../config-shared'
import type { RenderServer, initialize } from '../router-server' import type { RenderServer, initialize } from '../router-server'
import type { PatchMatcher } from '../../../shared/lib/router/utils/path-match' import type { PatchMatcher } from '../../../shared/lib/router/utils/path-match'
import type { Redirect } from '../../../../types' import type { Redirect } from '../../../types'
import type { Header } from '../../../lib/load-custom-routes' import type { Header } from '../../../lib/load-custom-routes'
import type { UnwrapPromise } from '../../../lib/coalesced-function' import type { UnwrapPromise } from '../../../lib/coalesced-function'
import type { NextUrlWithParsedQuery } from '../../request-meta' import type { NextUrlWithParsedQuery } from '../../request-meta'
......
...@@ -9,7 +9,7 @@ import type { ...@@ -9,7 +9,7 @@ import type {
GetStaticPaths, GetStaticPaths,
GetServerSideProps, GetServerSideProps,
GetStaticProps, GetStaticProps,
} from 'next/types' } from '../types'
import type { RouteModule } from './future/route-modules/route-module' import type { RouteModule } from './future/route-modules/route-module'
import type { BuildManifest } from './get-page-files' import type { BuildManifest } from './get-page-files'
import type { ActionManifest } from '../build/webpack/plugins/flight-client-entry-plugin' import type { ActionManifest } from '../build/webpack/plugins/flight-client-entry-plugin'
......
...@@ -9,7 +9,7 @@ import type { ...@@ -9,7 +9,7 @@ import type {
GetStaticPaths, GetStaticPaths,
GetServerSideProps, GetServerSideProps,
GetStaticProps, GetStaticProps,
} from 'next/types' } from '../types'
import type { RouteModule } from './future/route-modules/route-module' import type { RouteModule } from './future/route-modules/route-module'
import type { BuildManifest } from './get-page-files' import type { BuildManifest } from './get-page-files'
......
...@@ -29,7 +29,7 @@ import type { ...@@ -29,7 +29,7 @@ import type {
PreviewData, PreviewData,
ServerRuntime, ServerRuntime,
SizeLimit, SizeLimit,
} from 'next/types' } from '../types'
import type { UnwrapPromise } from '../lib/coalesced-function' import type { UnwrapPromise } from '../lib/coalesced-function'
import type { ReactReadableStream } from './stream-utils/node-web-streams-helper' import type { ReactReadableStream } from './stream-utils/node-web-streams-helper'
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin' import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'
......
import type { NextConfig } from '../../types' import type { NextConfig } from '../types'
import { Agent as HttpAgent } from 'http' import { Agent as HttpAgent } from 'http'
import { Agent as HttpsAgent } from 'https' import { Agent as HttpsAgent } from 'https'
......
...@@ -26,14 +26,17 @@ describe('getHostname', () => { ...@@ -26,14 +26,17 @@ describe('getHostname', () => {
// With headers. // With headers.
expect(getHostname(parsed, { host: parsed.host })).toBe(hostname) expect(getHostname(parsed, { host: parsed.host })).toBe(hostname)
// With an empty headers array. // With an empty headers array.
// @ts-expect-error passing an array of strings is not allowed
expect(getHostname(parsed, { host: [] })).toBe(hostname) expect(getHostname(parsed, { host: [] })).toBe(hostname)
// With a headers array. // With a headers array.
// @ts-expect-error passing an array of strings is not allowed
expect(getHostname({}, { host: [parsed.host] })).toBe(undefined) expect(getHostname({}, { host: [parsed.host] })).toBe(undefined)
}) })
}) })
it('should return undefined for empty input', () => { it('should return undefined for empty input', () => {
expect(getHostname({})).toBe(undefined) expect(getHostname({})).toBe(undefined)
// @ts-expect-error passing an array of strings is not allowed
expect(getHostname({}, { host: [] })).toBe(undefined) expect(getHostname({}, { host: [] })).toBe(undefined)
}) })
}) })
import type { BuildManifest } from '../../server/get-page-files' import type { BuildManifest } from '../../server/get-page-files'
import type { ServerRuntime } from 'next/types' import type { ServerRuntime } from '../../types'
import type { NEXT_DATA } from './utils' import type { NEXT_DATA } from './utils'
import type { FontConfig } from '../../server/font-utils' import type { FontConfig } from '../../server/font-utils'
import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin' import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin'
......
...@@ -5,7 +5,7 @@ import type { Env } from '@next/env' ...@@ -5,7 +5,7 @@ import type { Env } from '@next/env'
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import type { NextRouter } from './router/router' import type { NextRouter } from './router/router'
import type { ParsedUrlQuery } from 'querystring' import type { ParsedUrlQuery } from 'querystring'
import type { PreviewData } from 'next/types' import type { PreviewData } from '../../types'
import type { COMPILER_NAMES } from './constants' import type { COMPILER_NAMES } from './constants'
import type fs from 'fs' import type fs from 'fs'
......
...@@ -11,27 +11,22 @@ import type React from 'react' ...@@ -11,27 +11,22 @@ import type React from 'react'
import type { ParsedUrlQuery } from 'querystring' import type { ParsedUrlQuery } from 'querystring'
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import { import type {
NextPageContext, NextPageContext,
NextComponentType, NextComponentType,
NextApiResponse, NextApiResponse,
NextApiRequest, NextApiRequest,
NextApiHandler, NextApiHandler,
// @ts-ignore This path is generated at build time and conflicts otherwise } from './shared/lib/utils'
} from '../dist/shared/lib/utils'
import type { import type { NextApiRequestCookies } from './server/api-utils'
NextApiRequestCookies,
// @ts-ignore This path is generated at build time and conflicts otherwise
} from '../dist/server/api-utils'
// @ts-ignore This path is generated at build time and conflicts otherwise import next from './server/next'
import next from '../dist/server/next'
export type ServerRuntime = 'nodejs' | 'experimental-edge' | 'edge' | undefined export type ServerRuntime = 'nodejs' | 'experimental-edge' | '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 './server/config'
export type { export type {
Metadata, Metadata,
...@@ -41,8 +36,7 @@ export type { ...@@ -41,8 +36,7 @@ export type {
Viewport, Viewport,
ResolvingViewport, ResolvingViewport,
ResolvedViewport, ResolvedViewport,
// @ts-ignore This path is generated at build time and conflicts otherwise } from './lib/metadata/types/metadata-interface'
} from '../dist/lib/metadata/types/metadata-interface'
/** /**
* Stub route type for typedRoutes before `next dev` or `next build` is run * Stub route type for typedRoutes before `next dev` or `next build` is run
...@@ -160,7 +154,7 @@ export type PageConfig = { ...@@ -160,7 +154,7 @@ export type PageConfig = {
unstable_excludeFiles?: string[] unstable_excludeFiles?: string[]
} }
export { export type {
NextPageContext, NextPageContext,
NextComponentType, NextComponentType,
NextApiResponse, NextApiResponse,
......
...@@ -2576,7 +2576,10 @@ export async function trace(task, opts) { ...@@ -2576,7 +2576,10 @@ export async function trace(task, opts) {
} }
export async function build(task, opts) { export async function build(task, opts) {
await task.serial(['precompile', 'compile', 'generate_types'], opts) await task.serial(
['precompile', 'compile', 'generate_types', 'rewrite_compiled_references'],
opts
)
} }
export async function generate_types(task, opts) { export async function generate_types(task, opts) {
...@@ -2585,6 +2588,37 @@ export async function generate_types(task, opts) { ...@@ -2585,6 +2588,37 @@ export async function generate_types(task, opts) {
}) })
} }
/**
* TypeScript will emit references to the compiled types used to type the implementation.
* The declarations however don't need such detailed types.
* We rewrite the references to reference a more lightweight solution instead.
* @param {import('taskr').Task} task
*/
export async function rewrite_compiled_references(task, opts) {
const declarationDirectory = join(__dirname, 'dist')
const declarationFiles = glob.sync('**/*.d.ts', { cwd: declarationDirectory })
for (const declarationFile of declarationFiles) {
const content = await fs.readFile(
join(declarationDirectory, declarationFile),
'utf8'
)
// Rewrite
// /// <reference path="../../../../types/$$compiled.internal.d.ts" />
// to
// /// <reference path="../../../../types/compiled.d.ts" />
if (content.indexOf('/types/$$compiled.internal.d.ts" />') !== -1) {
await fs.writeFile(
join(declarationDirectory, declarationFile),
content.replace(
/\/types\/\$\$compiled\.internal\.d\.ts" \/>/g,
'/types/compiled.d.ts" />'
)
)
}
}
}
export default async function (task) { export default async function (task) {
const opts = { dev: true } const opts = { dev: true }
await task.clear('dist') await task.clear('dist')
......
// Triple slash directives are copied from src/types.ts.
// TypeScript currently does not preserve the tripple-slash directives.
// Once https://github.com/microsoft/TypeScript/pull/57681 is released, we can remove the triple slash directives here.
/// <reference types="react" />
/// <reference types="react/experimental" />
/// <reference types="react-dom" />
/// <reference types="react-dom/experimental" />
export * from './dist/types'
export { default } from './dist/types'
...@@ -446,3 +446,33 @@ declare module 'next/dist/compiled/zod' { ...@@ -446,3 +446,33 @@ declare module 'next/dist/compiled/zod' {
import * as m from 'zod' import * as m from 'zod'
export = m export = m
} }
declare module 'mini-css-extract-plugin'
declare module 'next/dist/compiled/loader-utils3'
declare module 'next/dist/compiled/webpack/webpack' {
import type webpackSources from 'webpack-sources1'
export function init(): void
export let BasicEvaluatedExpression: any
export let GraphHelpers: any
export let sources: typeof webpackSources
export let StringXor: any
export {
default as webpack,
Compiler,
Compilation,
Module,
Stats,
Template,
RuntimeModule,
RuntimeGlobals,
NormalModule,
ResolvePluginInstance,
ModuleFilenameHelpers,
} from 'webpack'
export type {
LoaderDefinitionFunction,
LoaderContext,
ModuleGraph,
} from 'webpack'
}
/* eslint-disable import/no-extraneous-dependencies, @typescript-eslint/no-unused-vars , no-shadow */
// Type definitions for webpack 4.39
// Project: https://github.com/webpack/webpack
// Definitions by: Qubo <https://github.com/tkqubo>
// Benjamin Lim <https://github.com/bumbleblym>
// Boris Cherny <https://github.com/bcherny>
// Tommy Troy Lin <https://github.com/tommytroylin>
// Mohsen Azimi <https://github.com/mohsen1>
// Jonathan Creamer <https://github.com/jcreamer898>
// Alan Agius <https://github.com/alan-agius4>
// Spencer Elliott <https://github.com/elliottsj>
// Jason Cheatham <https://github.com/jason0x43>
// Dennis George <https://github.com/dennispg>
// Christophe Hurpeau <https://github.com/christophehurpeau>
// ZSkycat <https://github.com/ZSkycat>
// John Reilly <https://github.com/johnnyreilly>
// Ryan Waskiewicz <https://github.com/rwaskiewicz>
// Kyle Uehlein <https://github.com/kuehlein>
// Grgur Grisogono <https://github.com/grgur>
// Rubens Pinheiro Gonçalves Cavalcante <https://github.com/rubenspgcavalcante>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
declare module 'mini-css-extract-plugin'
declare module 'next/dist/compiled/loader-utils3'
declare module 'next/dist/compiled/webpack/webpack' {
import type webpackSources from 'webpack-sources1'
export function init(): void
export let BasicEvaluatedExpression: any
export let GraphHelpers: any
export let sources: typeof webpackSources
export let StringXor: any
export {
default as webpack,
Compiler,
Compilation,
Module,
Stats,
Template,
RuntimeModule,
RuntimeGlobals,
NormalModule,
ResolvePluginInstance,
ModuleFilenameHelpers,
} from 'webpack'
export type {
LoaderDefinitionFunction,
LoaderContext,
ModuleGraph,
} from 'webpack'
}
This diff is collapsed.
import { NextInstance, createNext } from 'e2e-utils' import { NextInstance, createNext } from 'e2e-utils'
import { trace } from 'next/src/trace' import { trace } from 'next/dist/trace'
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants' import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
import { import {
createDefineEnv, createDefineEnv,
...@@ -11,8 +11,8 @@ import { ...@@ -11,8 +11,8 @@ import {
StyledString, StyledString,
TurbopackResult, TurbopackResult,
UpdateInfo, UpdateInfo,
} from 'next/src/build/swc' } from 'next/dist/build/swc'
import loadConfig from 'next/src/server/config' import loadConfig from 'next/dist/server/config'
import path from 'path' import path from 'path'
function normalizePath(path: string) { function normalizePath(path: string) {
......
...@@ -4,7 +4,7 @@ import { NextInstance } from 'e2e-utils' ...@@ -4,7 +4,7 @@ import { NextInstance } from 'e2e-utils'
import { check, waitFor } from 'next-test-utils' import { check, waitFor } from 'next-test-utils'
import webdriver, { BrowserInterface } from 'next-webdriver' import webdriver, { BrowserInterface } from 'next-webdriver'
import type { HistoryState } from '../../../packages/next/src/shared/lib/router/router' import type { HistoryState } from 'next/dist/shared/lib/router/router'
const emitPopsStateEvent = (browser: BrowserInterface, state: HistoryState) => const emitPopsStateEvent = (browser: BrowserInterface, state: HistoryState) =>
browser.eval( browser.eval(
......
...@@ -4,7 +4,7 @@ import { NextInstance } from 'e2e-utils' ...@@ -4,7 +4,7 @@ import { NextInstance } from 'e2e-utils'
import { check, waitFor } from 'next-test-utils' import { check, waitFor } from 'next-test-utils'
import webdriver, { BrowserInterface } from 'next-webdriver' import webdriver, { BrowserInterface } from 'next-webdriver'
import type { HistoryState } from '../../../packages/next/src/shared/lib/router/router' import type { HistoryState } from 'next/dist/shared/lib/router/router'
const emitPopsStateEvent = (browser: BrowserInterface, state: HistoryState) => const emitPopsStateEvent = (browser: BrowserInterface, state: HistoryState) =>
browser.eval( browser.eval(
......
import path from 'path' import path from 'path'
import assert from 'assert' import assert from 'assert'
import { flushAllTraces, setGlobal, trace } from 'next/src/trace' import { flushAllTraces, setGlobal, trace } from 'next/dist/trace'
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants' import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
import { NextInstance, NextInstanceOpts } from './next-modes/base' import { NextInstance, NextInstanceOpts } from './next-modes/base'
import { NextDevInstance } from './next-modes/next-dev' import { NextDevInstance } from './next-modes/next-dev'
......
...@@ -6,7 +6,7 @@ import type { NextConfig } from 'next' ...@@ -6,7 +6,7 @@ import type { NextConfig } from 'next'
import { FileRef, isNextDeploy, isNextDev } from '../e2e-utils' import { FileRef, isNextDeploy, isNextDev } from '../e2e-utils'
import { ChildProcess } from 'child_process' import { ChildProcess } from 'child_process'
import { createNextInstall } from '../create-next-install' import { createNextInstall } from '../create-next-install'
import { Span } from 'next/src/trace' import { Span } from 'next/dist/trace'
import webdriver from '../next-webdriver' import webdriver from '../next-webdriver'
import { renderViaHTTP, fetchViaHTTP, waitFor } from 'next-test-utils' import { renderViaHTTP, fetchViaHTTP, waitFor } from 'next-test-utils'
import cheerio from 'cheerio' import cheerio from 'cheerio'
......
...@@ -9,7 +9,7 @@ import { ...@@ -9,7 +9,7 @@ import {
TEST_TOKEN, TEST_TOKEN,
} from '../../../scripts/reset-project.mjs' } from '../../../scripts/reset-project.mjs'
import fetch from 'node-fetch' import fetch from 'node-fetch'
import { Span } from 'next/src/trace' import { Span } from 'next/dist/trace'
export class NextDeployInstance extends NextInstance { export class NextDeployInstance extends NextInstance {
private _cliOutput: string private _cliOutput: string
......
import spawn from 'cross-spawn' import spawn from 'cross-spawn'
import { Span } from 'next/src/trace' import { Span } from 'next/dist/trace'
import { NextInstance } from './base' import { NextInstance } from './base'
import { getTurbopackFlag } from '../turbo' import { getTurbopackFlag } from '../turbo'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
......
...@@ -2,7 +2,7 @@ import path from 'path' ...@@ -2,7 +2,7 @@ import path from 'path'
import fs from 'fs-extra' import fs from 'fs-extra'
import { NextInstance } from './base' import { NextInstance } from './base'
import spawn from 'cross-spawn' import spawn from 'cross-spawn'
import { Span } from 'next/src/trace' import { Span } from 'next/dist/trace'
import stripAnsi from 'strip-ansi' import stripAnsi from 'strip-ansi'
export class NextStartInstance extends NextInstance { export class NextStartInstance extends NextInstance {
......
// Make development mode typescript module resolving and jsx parsing correct for all tests.
// We want to apply the compiler options to the testing app, but we don't want to do strict type checking for them.
// e.g. testing app could have import a from '3rd-lib-nextjs-ws-doesnt-have'
{
"extends": "../tsconfig.base.json"
}
import postcss from 'postcss' import postcss from 'postcss'
import mod from 'next/src/bundles/cssnano-simple/index' import mod from 'next/dist/compiled/cssnano-simple/index'
import css from '../noop-template' import css from '../noop-template'
describe('basic test', () => { describe('basic test', () => {
......
import postcss from 'postcss' import postcss from 'postcss'
import mod from 'next/src/bundles/cssnano-simple/index' import mod from 'next/dist/compiled/cssnano-simple/index'
import css from '../noop-template' import css from '../noop-template'
describe('exclude all test', () => { describe('exclude all test', () => {
......
import postcss from 'postcss' import postcss from 'postcss'
import mod from 'next/src/bundles/cssnano-simple/index' import mod from 'next/dist/compiled/cssnano-simple'
import css from '../noop-template' import css from '../noop-template'
describe('accepts plugin configuration', () => { describe('accepts plugin configuration', () => {
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
*/ */
import { expectTypeOf } from 'expect-type' import { expectTypeOf } from 'expect-type'
import { NextRequest } from 'next/src/server/web/spec-extension/request' import { NextRequest } from 'next/dist/server/web/spec-extension/request'
it('should have 1 required parameter for constructor', () => { it('should have 1 required parameter for constructor', () => {
expect(NextRequest.length).toBe(1) expect(NextRequest.length).toBe(1)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @jest-environment @edge-runtime/jest-environment * @jest-environment @edge-runtime/jest-environment
*/ */
import { NextResponse } from 'next/src/server/web/spec-extension/response' import { NextResponse } from 'next/dist/server/web/spec-extension/response'
it('reflect .set into `set-cookie`', async () => { it('reflect .set into `set-cookie`', async () => {
const response = new NextResponse() const response = new NextResponse()
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @jest-environment @edge-runtime/jest-environment * @jest-environment @edge-runtime/jest-environment
*/ */
import { NextResponse } from 'next/src/server/web/spec-extension/response' import { NextResponse } from 'next/dist/server/web/spec-extension/response'
const toJSON = async (response: Response) => ({ const toJSON = async (response: Response) => ({
body: await response.json(), body: await response.json(),
......
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