Skip to content

Commit 9db4419

Browse files
committed
Create separate entrypoint for next/types
Removes a bunch of `@ts-ignore` and is more in line with our existing entrypoints. Required to entangle the public/internal types plit
1 parent 0a29438 commit 9db4419

31 files changed

+39
-42
lines changed

packages/next/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,9 @@
4949
"amp.d.ts",
5050
"og.js",
5151
"og.d.ts",
52+
"types.d.ts",
53+
"types.js",
5254
"index.d.ts",
53-
"types/index.d.ts",
5455
"types/global.d.ts",
5556
"types/compiled.d.ts",
5657
"image-types/global.d.ts",

packages/next/src/build/analysis/get-page-static-info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { Middleware, RouteHas } from '../../lib/load-custom-routes'
44
import { promises as fs } from 'fs'
55
import LRUCache from 'next/dist/compiled/lru-cache'
66
import picomatch from 'next/dist/compiled/picomatch'
7-
import type { ServerRuntime } from 'next/types'
7+
import type { ServerRuntime } from '../../types'
88
import {
99
extractExportedConstValue,
1010
UnsupportedValueError,

packages/next/src/build/babel/plugins/next-page-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
Visitor,
66
NodePath,
77
} from 'next/dist/compiled/babel/core'
8-
import type { PageConfig } from 'next/types'
8+
import type { PageConfig } from '../../../types'
99
import { STRING_LITERAL_DROP_BUNDLE } from '../../../shared/lib/constants'
1010

1111
const CONFIG_KEY = 'config'

packages/next/src/build/entries.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ import {
5050
import { getPageStaticInfo } from './analysis/get-page-static-info'
5151
import { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep'
5252
import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path'
53-
import type { ServerRuntime } from '../../types'
53+
import type { ServerRuntime } from '../types'
5454
import { normalizeAppPath } from '../shared/lib/router/utils/app-paths'
5555
import { encodeMatchers } from './webpack/loaders/next-middleware-loader'
5656
import type { EdgeFunctionLoaderOptions } from './webpack/loaders/next-edge-function-loader'

packages/next/src/build/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
GetStaticPathsResult,
77
PageConfig,
88
ServerRuntime,
9-
} from 'next/types'
9+
} from '../types'
1010
import type { BuildManifest } from '../server/get-page-files'
1111
import type {
1212
Redirect,

packages/next/src/build/webpack/loaders/next-edge-ssr-loader/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type webpack from 'webpack'
2-
import type { SizeLimit } from '../../../../../types'
2+
import type { SizeLimit } from '../../../../types'
33
import type { PagesRouteModuleOptions } from '../../../../server/future/route-modules/pages/module'
44
import type { MiddlewareConfig } from '../../../analysis/get-page-static-info'
55

packages/next/src/build/webpack/loaders/next-edge-ssr-loader/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
import { SERVER_RUNTIME } from '../../../../lib/constants'
1616
import type { ManifestRewriteRoute, PrerenderManifest } from '../../..'
1717
import { normalizeAppPath } from '../../../../shared/lib/router/utils/app-paths'
18-
import type { SizeLimit } from '../../../../../types'
18+
import type { SizeLimit } from '../../../../types'
1919
import { internal_getCurrentFunctionWaitUntil } from '../../../../server/web/internal-edge-wait-until'
2020
import type { PAGE_TYPES } from '../../../../lib/page-types'
2121
import type { NextRequestHint } from '../../../../server/web/adapter'

packages/next/src/build/webpack/loaders/next-swc-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2626
DEALINGS IN THE SOFTWARE.
2727
*/
2828

29-
import type { NextConfig } from '../../../../types'
29+
import type { NextConfig } from '../../../types'
3030
import type { WebpackLayerName } from '../../../lib/constants'
3131
import { isWasm, transform } from '../../swc'
3232
import { getLoaderSWCOptions } from '../../swc/options'

packages/next/src/build/webpack/plugins/next-types-plugin/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,8 @@ declare namespace __next_route_internal_types__ {
441441
}
442442
443443
declare module 'next' {
444-
export { default } from 'next/types/index.js'
445-
export * from 'next/types/index.js'
444+
export { default } from 'next/types.js'
445+
export * from 'next/types.js'
446446
447447
export type Route<T extends string = string> =
448448
__next_route_internal_types__.RouteImpl<T>

packages/next/src/lib/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ServerRuntime } from '../../types'
1+
import type { ServerRuntime } from '../types'
22

33
export const NEXT_QUERY_PARAM_PREFIX = 'nxtP'
44

packages/next/src/lib/is-edge-runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { ServerRuntime } from '../../types'
1+
import type { ServerRuntime } from '../types'
22
import { SERVER_RUNTIME } from './constants'
33

44
export function isEdgeRuntime(value?: string): value is ServerRuntime {

packages/next/src/server/api-utils/node/api-resolver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IncomingMessage, ServerResponse } from 'http'
22
import type { NextApiRequest, NextApiResponse } from '../../../shared/lib/utils'
3-
import type { PageConfig, ResponseLimit } from 'next/types'
3+
import type { PageConfig, ResponseLimit } from '../../../types'
44
import type { __ApiPreviewProps } from '../.'
55
import type { CookieSerializeOptions } from 'next/dist/compiled/cookie'
66

packages/next/src/server/api-utils/node/parse-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { IncomingMessage } from 'http'
2-
import type { SizeLimit } from 'next/types'
32

43
import { parse } from 'next/dist/compiled/content-type'
54
import isError from '../../../lib/is-error'
5+
import type { SizeLimit } from '../../../types'
66
import { ApiError } from '../index'
77

88
/**

packages/next/src/server/api-utils/node/try-get-preview-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { NextApiResponse } from '../../../shared/lib/utils'
33
import { checkIsOnDemandRevalidate } from '../.'
44
import type { __ApiPreviewProps } from '../.'
55
import type { BaseNextRequest, BaseNextResponse } from '../../base-http'
6-
import type { PreviewData } from 'next/types'
6+
import type { PreviewData } from '../../../types'
77

88
import {
99
clearPreviewData,

packages/next/src/server/app-render/action-handler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { IncomingHttpHeaders, OutgoingHttpHeaders } from 'http'
2-
import type { SizeLimit } from '../../../types'
2+
import type { SizeLimit } from '../../types'
33
import type { RequestStore } from '../../client/components/request-async-storage.external'
44
import type { AppRenderContext, GenerateFlight } from './app-render'
55
import type { AppPageModule } from '../../server/future/route-modules/app-page/module'

packages/next/src/server/app-render/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { LoadComponentsReturnType } from '../load-components'
2-
import type { ServerRuntime, SizeLimit } from '../../../types'
2+
import type { ServerRuntime, SizeLimit } from '../../types'
33
import type { NextConfigComplete } from '../../server/config-shared'
44
import type { ClientReferenceManifest } from '../../build/webpack/plugins/flight-manifest-plugin'
55
import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin'

packages/next/src/server/base-server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import {
2020
normalizeRepeatedSlashes,
2121
MissingStaticPage,
2222
} from '../shared/lib/utils'
23-
import type { PreviewData } from 'next/types'
23+
import type { PreviewData } from '../types'
2424
import type { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
2525
import type { BaseNextRequest, BaseNextResponse } from './base-http'
2626
import type {

packages/next/src/server/config-schema.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { VALID_LOADERS } from '../shared/lib/image-config'
44
import { z } from 'next/dist/compiled/zod'
55
import type zod from 'next/dist/compiled/zod'
66

7-
import type { SizeLimit } from '../../types'
7+
import type { SizeLimit } from '../types'
88
import type {
99
ExportPathMap,
1010
TurboLoaderItem,

packages/next/src/server/config-shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
import type { SubresourceIntegrityAlgorithm } from '../build/webpack/plugins/subresource-integrity-plugin'
1010
import type { WEB_VITALS } from '../shared/lib/utils'
1111
import type { NextParsedUrlQuery } from './request-meta'
12-
import type { SizeLimit } from '../../types'
12+
import type { SizeLimit } from '../types'
1313
import type { SwrDelta } from './lib/revalidate'
1414

1515
export type NextConfigComplete = Required<NextConfig> & {

packages/next/src/server/future/route-modules/pages-api/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { IncomingMessage, ServerResponse } from 'http'
22
import type { PagesAPIRouteDefinition } from '../../route-definitions/pages-api-route-definition'
3-
import type { PageConfig } from '../../../../../types'
3+
import type { PageConfig } from '../../../../types'
44
import type { ParsedUrlQuery } from 'querystring'
55
import { wrapApiHandler, type __ApiPreviewProps } from '../../../api-utils'
66
import type { RouteModuleOptions } from '../route-module'

packages/next/src/server/future/route-modules/pages/module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type {
55
GetStaticProps,
66
NextComponentType,
77
PageConfig,
8-
} from '../../../../../types'
8+
} from '../../../../types'
99
import type { PagesRouteDefinition } from '../../route-definitions/pages-route-definition'
1010
import type { NextParsedUrlQuery } from '../../../request-meta'
1111
import type { RenderOpts } from '../../../render'

packages/next/src/server/lib/router-utils/resolve-routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { IncomingMessage, ServerResponse } from 'http'
33
import type { NextConfigComplete } from '../../config-shared'
44
import type { RenderServer, initialize } from '../router-server'
55
import type { PatchMatcher } from '../../../shared/lib/router/utils/path-match'
6-
import type { Redirect } from '../../../../types'
6+
import type { Redirect } from '../../../types'
77
import type { Header } from '../../../lib/load-custom-routes'
88
import type { UnwrapPromise } from '../../../lib/coalesced-function'
99
import type { NextUrlWithParsedQuery } from '../../request-meta'

packages/next/src/server/load-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
GetStaticPaths,
1010
GetServerSideProps,
1111
GetStaticProps,
12-
} from 'next/types'
12+
} from '../types'
1313
import type { RouteModule } from './future/route-modules/route-module'
1414
import type { BuildManifest } from './get-page-files'
1515
import type { ActionManifest } from '../build/webpack/plugins/flight-client-entry-plugin'

packages/next/src/server/load-default-error-components.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import type {
99
GetStaticPaths,
1010
GetServerSideProps,
1111
GetStaticProps,
12-
} from 'next/types'
12+
} from '../types'
1313
import type { RouteModule } from './future/route-modules/route-module'
1414
import type { BuildManifest } from './get-page-files'
1515

packages/next/src/server/render.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import type {
2929
PreviewData,
3030
ServerRuntime,
3131
SizeLimit,
32-
} from 'next/types'
32+
} from '../types'
3333
import type { UnwrapPromise } from '../lib/coalesced-function'
3434
import type { ReactReadableStream } from './stream-utils/node-web-streams-helper'
3535
import type { ClientReferenceManifest } from '../build/webpack/plugins/flight-manifest-plugin'

packages/next/src/server/setup-http-agent-env.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { NextConfig } from '../../types'
1+
import type { NextConfig } from '../types'
22
import { Agent as HttpAgent } from 'http'
33
import { Agent as HttpsAgent } from 'https'
44

packages/next/src/shared/lib/html-context.shared-runtime.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { BuildManifest } from '../../server/get-page-files'
2-
import type { ServerRuntime } from 'next/types'
2+
import type { ServerRuntime } from '../../types'
33
import type { NEXT_DATA } from './utils'
44
import type { FontConfig } from '../../server/font-utils'
55
import type { NextFontManifest } from '../../build/webpack/plugins/next-font-manifest-plugin'

packages/next/src/shared/lib/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { Env } from '@next/env'
55
import type { IncomingMessage, ServerResponse } from 'http'
66
import type { NextRouter } from './router/router'
77
import type { ParsedUrlQuery } from 'querystring'
8-
import type { PreviewData } from 'next/types'
8+
import type { PreviewData } from '../../types'
99
import type { COMPILER_NAMES } from './constants'
1010
import type fs from 'fs'
1111

packages/next/types/index.d.ts renamed to packages/next/src/types.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,22 @@ import type React from 'react'
1111
import type { ParsedUrlQuery } from 'querystring'
1212
import type { IncomingMessage, ServerResponse } from 'http'
1313

14-
import {
14+
import type {
1515
NextPageContext,
1616
NextComponentType,
1717
NextApiResponse,
1818
NextApiRequest,
1919
NextApiHandler,
20-
// @ts-ignore This path is generated at build time and conflicts otherwise
21-
} from '../dist/shared/lib/utils'
20+
} from './shared/lib/utils'
2221

23-
import type {
24-
NextApiRequestCookies,
25-
// @ts-ignore This path is generated at build time and conflicts otherwise
26-
} from '../dist/server/api-utils'
22+
import type { NextApiRequestCookies } from './server/api-utils'
2723

28-
// @ts-ignore This path is generated at build time and conflicts otherwise
29-
import next from '../dist/server/next'
24+
import next from './server/next'
3025

3126
export type ServerRuntime = 'nodejs' | 'experimental-edge' | 'edge' | undefined
3227

3328
// @ts-ignore This path is generated at build time and conflicts otherwise
34-
export { NextConfig } from '../dist/server/config'
29+
export { NextConfig } from './server/config'
3530

3631
export type {
3732
Metadata,
@@ -41,8 +36,7 @@ export type {
4136
Viewport,
4237
ResolvingViewport,
4338
ResolvedViewport,
44-
// @ts-ignore This path is generated at build time and conflicts otherwise
45-
} from '../dist/lib/metadata/types/metadata-interface'
39+
} from './lib/metadata/types/metadata-interface'
4640

4741
/**
4842
* Stub route type for typedRoutes before `next dev` or `next build` is run
@@ -160,7 +154,7 @@ export type PageConfig = {
160154
unstable_excludeFiles?: string[]
161155
}
162156

163-
export {
157+
export type {
164158
NextPageContext,
165159
NextComponentType,
166160
NextApiResponse,

packages/next/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './dist/types'

packages/next/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// types-only

0 commit comments

Comments
 (0)