Skip to content

Commit

Permalink
Move next-server directory files to server directory (#26756)
Browse files Browse the repository at this point in the history
* Move next-server directory files to server directory

* Update tests

* Update paths in other places
  • Loading branch information
timneutkens authored Jun 30, 2021
1 parent 136b754 commit 5b9ad8d
Show file tree
Hide file tree
Showing 89 changed files with 199 additions and 235 deletions.
4 changes: 2 additions & 2 deletions docs/api-reference/next.config.js/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = (phase, { defaultConfig }) => {
}
```

`phase` is the current context in which the configuration is loaded. You can see the [available phases](https://github.com/vercel/next.js/blob/canary/packages/next/next-server/lib/constants.ts#L1-L4). Phases can be imported from `next/constants`:
`phase` is the current context in which the configuration is loaded. You can see the [available phases](https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/constants.ts#L1-L4). Phases can be imported from `next/constants`:

```js
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')
Expand All @@ -44,7 +44,7 @@ module.exports = (phase, { defaultConfig }) => {
}
```

The commented lines are the place where you can put the configs allowed by `next.config.js`, which are [defined in this file](https://github.com/vercel/next.js/blob/canary/packages/next/next-server/server/config-shared.ts#L68).
The commented lines are the place where you can put the configs allowed by `next.config.js`, which are [defined in this file](https://github.com/vercel/next.js/blob/canary/packages/next/server/config-shared.ts#L68).

However, none of the configs are required, and it's not necessary to understand what each config does. Instead, search for the features you need to enable or modify in this section and they will show you what to do.

Expand Down
2 changes: 1 addition & 1 deletion docs/basic-features/typescript.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ The `next.config.js` file must be a JavaScript file as it does not get parsed by
// @ts-check

/**
* @type {import('next/dist/next-server/server/config').NextConfig}
* @type {import('next').NextConfig}
**/
const nextConfig = {
/* config options here */
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/preset.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
const { findPagesDir } = require('next/dist/lib/find-pages-dir')
const loadConfig = require('next/dist/next-server/server/config').default
const loadConfig = require('next/dist/server/config').default
const getWebpackConfig = require('next/dist/build/webpack-config').default

const CWD = process.cwd()
Expand Down
8 changes: 4 additions & 4 deletions packages/next/build/entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import chalk from 'chalk'
import { posix, join } from 'path'
import { stringify } from 'querystring'
import { API_ROUTE, DOT_NEXT_ALIAS, PAGES_DIR_ALIAS } from '../lib/constants'
import { __ApiPreviewProps } from '../next-server/server/api-utils'
import { isTargetLikeServerless } from '../next-server/server/config'
import { normalizePagePath } from '../next-server/server/normalize-page-path'
import { __ApiPreviewProps } from '../server/api-utils'
import { isTargetLikeServerless } from '../server/config'
import { normalizePagePath } from '../server/normalize-page-path'
import { warn } from './output/log'
import { ClientPagesLoaderOptions } from './webpack/loaders/next-client-pages-loader'
import { ServerlessLoaderQuery } from './webpack/loaders/next-serverless-loader'
import { LoadedEnvFiles } from '@next/env'
import { NextConfig } from '../next-server/server/config'
import { NextConfig } from '../server/config'

type PagesMapping = {
[page: string]: string
Expand Down
12 changes: 6 additions & 6 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ import {
getSortedRoutes,
isDynamicRoute,
} from '../shared/lib/router/utils'
import { __ApiPreviewProps } from '../next-server/server/api-utils'
import { __ApiPreviewProps } from '../server/api-utils'
import loadConfig, {
isTargetLikeServerless,
NextConfig,
} from '../next-server/server/config'
import { BuildManifest } from '../next-server/server/get-page-files'
import '../next-server/server/node-polyfill-fetch'
import { normalizePagePath } from '../next-server/server/normalize-page-path'
import { getPagePath } from '../next-server/server/require'
} from '../server/config'
import { BuildManifest } from '../server/get-page-files'
import '../server/node-polyfill-fetch'
import { normalizePagePath } from '../server/normalize-page-path'
import { getPagePath } from '../server/require'
import * as ciEnvironment from '../telemetry/ci-info'
import {
eventBuildCompleted,
Expand Down
8 changes: 4 additions & 4 deletions packages/next/build/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import '../next-server/server/node-polyfill-fetch'
import '../server/node-polyfill-fetch'
import chalk from 'chalk'
import getGzipSize from 'next/dist/compiled/gzip-size'
import textTable from 'next/dist/compiled/text-table'
Expand All @@ -24,13 +24,13 @@ 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 } from 'next/types'
import { denormalizePagePath } from '../next-server/server/normalize-page-path'
import { BuildManifest } from '../next-server/server/get-page-files'
import { denormalizePagePath } from '../server/normalize-page-path'
import { BuildManifest } from '../server/get-page-files'
import { removePathTrailingSlash } from '../client/normalize-trailing-slash'
import { UnwrapPromise } from '../lib/coalesced-function'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import * as Log from './output/log'
import { loadComponents } from '../next-server/server/load-components'
import { loadComponents } from '../server/load-components'
import { trace } from '../telemetry/trace'

const fileGzipStats: { [k: string]: Promise<number> | undefined } = {}
Expand Down
6 changes: 3 additions & 3 deletions packages/next/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
SERVER_DIRECTORY,
} from '../shared/lib/constants'
import { execOnce } from '../shared/lib/utils'
import { NextConfig } from '../next-server/server/config'
import { NextConfig } from '../server/config'
import { findPageFile } from '../server/lib/find-page-file'
import { WebpackEntrypoints } from './entries'
import * as Log from './output/log'
Expand Down Expand Up @@ -709,10 +709,10 @@ export default async function getBaseWebpackConfig(
}

if (isLocal) {
// Makes sure dist/shared and dist/next-server are not bundled
// Makes sure dist/shared and dist/server are not bundled
// we need to process shared/lib/router/router so that
// the DefinePlugin can inject process.env values
const isNextExternal = /next[/\\]dist[/\\](shared|next-server)[/\\](?!lib[/\\]router[/\\]router)/.test(
const isNextExternal = /next[/\\]dist[/\\](shared|server)[/\\](?!lib[/\\]router[/\\]router)/.test(
res
)

Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { NextConfig } from '../../../next-server/server/config'
import { NextConfig } from '../../../server/config'
import { base } from './blocks/base'
import { css } from './blocks/css'
import { ConfigurationContext, pipe } from './utils'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/config/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { NextConfig } from '../../../next-server/server/config'
import { NextConfig } from '../../../server/config'

export type ConfigurationContext = {
rootDirectory: string
Expand Down
2 changes: 1 addition & 1 deletion packages/next/build/webpack/loaders/next-image-loader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import loaderUtils from 'next/dist/compiled/loader-utils'
import sizeOf from 'image-size'
import { processBuffer } from '../../../next-server/server/lib/squoosh/main'
import { processBuffer } from '../../../server/lib/squoosh/main'

const BLUR_IMG_SIZE = 8
const BLUR_QUALITY = 70
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { parse as parseUrl } from 'url'
import { IncomingMessage, ServerResponse } from 'http'
import { apiResolver } from '../../../../next-server/server/api-utils'
import { apiResolver } from '../../../../server/api-utils'
import { getUtils, vercelHeader, ServerlessHandlerCtx } from './utils'

export function getApiHandler(ctx: ServerlessHandlerCtx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { parse } from 'querystring'
import { webpack } from 'next/dist/compiled/webpack/webpack'
import { API_ROUTE } from '../../../../lib/constants'
import { isDynamicRoute } from '../../../../shared/lib/router/utils'
import { __ApiPreviewProps } from '../../../../next-server/server/api-utils'
import { __ApiPreviewProps } from '../../../../server/api-utils'
import {
BUILD_MANIFEST,
ROUTES_MANIFEST,
Expand Down Expand Up @@ -99,7 +99,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
*/
runtimeConfigSetter
}
import 'next/dist/next-server/server/node-polyfill-fetch'
import 'next/dist/server/node-polyfill-fetch'
import routesManifest from '${routesManifest}'
import { getApiHandler } from 'next/dist/build/webpack/loaders/next-serverless-loader/api-handler'
Expand Down Expand Up @@ -127,7 +127,7 @@ const nextServerlessLoader: webpack.loader.Loader = function () {
`
} else {
return `
import 'next/dist/next-server/server/node-polyfill-fetch'
import 'next/dist/server/node-polyfill-fetch'
import routesManifest from '${routesManifest}'
import buildManifest from '${buildManifest}'
import reactLoadableManifest from '${reactLoadableManifest}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { IncomingMessage, ServerResponse } from 'http'
import { parse as parseUrl, format as formatUrl, UrlWithParsedQuery } from 'url'
import { isResSent } from '../../../../shared/lib/utils'
import { sendPayload } from '../../../../next-server/server/send-payload'
import { sendPayload } from '../../../../server/send-payload'
import { getUtils, vercelHeader, ServerlessHandlerCtx } from './utils'

import { renderToHTML } from '../../../../next-server/server/render'
import { tryGetPreviewData } from '../../../../next-server/server/api-utils'
import { denormalizePagePath } from '../../../../next-server/server/denormalize-page-path'
import {
setLazyProp,
getCookieParser,
} from '../../../../next-server/server/api-utils'
import { renderToHTML } from '../../../../server/render'
import { tryGetPreviewData } from '../../../../server/api-utils'
import { denormalizePagePath } from '../../../../server/denormalize-page-path'
import { setLazyProp, getCookieParser } from '../../../../server/api-utils'
import { getRedirectStatus } from '../../../../lib/load-custom-routes'
import getRouteNoAssetPath from '../../../../shared/lib/router/utils/get-route-from-asset-path'
import { PERMANENT_REDIRECT_STATUS } from '../../../../shared/lib/constants'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { getRouteMatcher } from '../../../../shared/lib/router/utils/route-match
import prepareDestination, {
matchHas,
} from '../../../../shared/lib/router/utils/prepare-destination'
import { __ApiPreviewProps } from '../../../../next-server/server/api-utils'
import { BuildManifest } from '../../../../next-server/server/get-page-files'
import { __ApiPreviewProps } from '../../../../server/api-utils'
import { BuildManifest } from '../../../../server/get-page-files'
import {
GetServerSideProps,
GetStaticPaths,
Expand All @@ -19,10 +19,10 @@ import {
import accept from '@hapi/accept'
import { detectLocaleCookie } from '../../../../shared/lib/i18n/detect-locale-cookie'
import { detectDomainLocale } from '../../../../shared/lib/i18n/detect-domain-locale'
import { denormalizePagePath } from '../../../../next-server/server/denormalize-page-path'
import { denormalizePagePath } from '../../../../server/denormalize-page-path'
import cookie from 'next/dist/compiled/cookie'
import { TEMPORARY_REDIRECT_STATUS } from '../../../../shared/lib/constants'
import { NextConfig } from '../../../../next-server/server/config'
import { NextConfig } from '../../../../server/config'

const getCustomRouteMatcher = pathMatch(true)

Expand Down
4 changes: 2 additions & 2 deletions packages/next/build/webpack/plugins/build-manifest-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP,
} from '../../../shared/lib/constants'
import { BuildManifest } from '../../../next-server/server/get-page-files'
import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint'
import { BuildManifest } from '../../../server/get-page-files'
import getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint'
import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin'
import { Rewrite } from '../../../lib/load-custom-routes'
import { getSortedRoutes } from '../../../shared/lib/router/utils'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { namedTypes } from 'ast-types'
import {
getFontDefinitionFromNetwork,
FontManifest,
} from '../../../next-server/server/font-utils'
} from '../../../server/font-utils'
import postcss from 'postcss'
import minifier from 'cssnano-simple'
import {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { realpathSync } from 'fs'
import path from 'path'

const originModules = [
require.resolve('../../../next-server/server/require'),
require.resolve('../../../next-server/server/load-components'),
require.resolve('../../../server/require'),
require.resolve('../../../server/load-components'),
]

function deleteCache(filePath: string) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { webpack, sources } from 'next/dist/compiled/webpack/webpack'
import { join, relative, dirname } from 'path'
import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint'
import getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint'
const SSR_MODULE_CACHE_FILENAME = 'ssr-module-cache.js'

// By default webpack keeps initialized modules per-module.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
sources,
} from 'next/dist/compiled/webpack/webpack'
import { PAGES_MANIFEST } from '../../../shared/lib/constants'
import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint'
import getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint'

export type PagesManifest = { [page: string]: string }

Expand Down
2 changes: 1 addition & 1 deletion packages/next/cli/next-lint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ESLINT_DEFAULT_DIRS } from '../lib/constants'
import { runLintCheck } from '../lib/eslint/runLintCheck'
import { printAndExit } from '../server/lib/utils'
import { Telemetry } from '../telemetry/storage'
import loadConfig from '../next-server/server/config'
import loadConfig from '../server/config'
import { PHASE_PRODUCTION_BUILD } from '../shared/lib/constants'
import { eventLintCheckCompleted } from '../telemetry/events'
import { CompileError } from '../lib/compile-error'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/client/image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
imageConfigDefault,
LoaderValue,
VALID_LOADERS,
} from '../next-server/server/image-config'
} from '../server/image-config'
import { useIntersection } from './use-intersection'

if (typeof window === 'undefined') {
Expand Down
6 changes: 3 additions & 3 deletions packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ import {
import loadConfig, {
isTargetLikeServerless,
NextConfig,
} from '../next-server/server/config'
} from '../server/config'
import { eventCliSession } from '../telemetry/events'
import { hasNextSupport } from '../telemetry/ci-info'
import { Telemetry } from '../telemetry/storage'
import {
normalizePagePath,
denormalizePagePath,
} from '../next-server/server/normalize-page-path'
} from '../server/normalize-page-path'
import { loadEnvConfig } from '@next/env'
import { PrerenderManifest } from '../build'
import exportPage from './worker'
import { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
import { getPagePath } from '../next-server/server/require'
import { getPagePath } from '../server/require'
import { trace } from '../telemetry/trace'

const exists = promisify(existsOrig)
Expand Down
12 changes: 6 additions & 6 deletions packages/next/export/worker.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import url from 'url'
import { extname, join, dirname, sep } from 'path'
import { renderToHTML } from '../next-server/server/render'
import { renderToHTML } from '../server/render'
import { promises } from 'fs'
import AmpHtmlValidator from 'next/dist/compiled/amphtml-validator'
import { loadComponents } from '../next-server/server/load-components'
import { loadComponents } from '../server/load-components'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import { getRouteMatcher } from '../shared/lib/router/utils/route-matcher'
import { getRouteRegex } from '../shared/lib/router/utils/route-regex'
import { normalizePagePath } from '../next-server/server/normalize-page-path'
import { normalizePagePath } from '../server/normalize-page-path'
import { SERVER_PROPS_EXPORT_ERROR } from '../lib/constants'
import 'next/dist/next-server/server/node-polyfill-fetch'
import '../server/node-polyfill-fetch'
import { IncomingMessage, ServerResponse } from 'http'
import { ComponentType } from 'react'
import { GetStaticProps } from '../types'
import { requireFontManifest } from '../next-server/server/require'
import { FontManifest } from '../next-server/server/font-utils'
import { requireFontManifest } from '../server/require'
import { FontManifest } from '../server/font-utils'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import { trace } from '../telemetry/trace'
import { isInAmpMode } from '../shared/lib/amp'
Expand Down
2 changes: 1 addition & 1 deletion packages/next/lib/load-custom-routes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parse as parseUrl } from 'url'
import { NextConfig } from '../next-server/server/config'
import { NextConfig } from '../server/config'
import * as pathToRegexp from 'next/dist/compiled/path-to-regexp'
import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import {
Expand Down
7 changes: 2 additions & 5 deletions packages/next/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import {
DocumentInitialProps,
DocumentProps,
} from '../shared/lib/utils'
import {
BuildManifest,
getPageFiles,
} from '../next-server/server/get-page-files'
import { cleanAmpPath } from '../next-server/server/utils'
import { BuildManifest, getPageFiles } from '../server/get-page-files'
import { cleanAmpPath } from '../server/utils'
import { htmlEscapeJsonString } from '../server/htmlescape'
import Script, { Props as ScriptLoaderProps } from '../client/script'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import { CookieSerializeOptions } from 'next/dist/compiled/cookie'
import getRawBody from 'raw-body'
import { PageConfig, PreviewData } from 'next/types'
import { Stream } from 'stream'
import {
isResSent,
NextApiRequest,
NextApiResponse,
} from '../../shared/lib/utils'
import { isResSent, NextApiRequest, NextApiResponse } from '../shared/lib/utils'
import { decryptWithSecret, encryptWithSecret } from './crypto-utils'
import { interopDefault } from './load-components'
import { sendEtagResponse } from './send-payload'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os from 'os'
import { Header, Redirect, Rewrite } from '../../lib/load-custom-routes'
import { Header, Redirect, Rewrite } from '../lib/load-custom-routes'
import { imageConfigDefault } from './image-config'

export type DomainLocales = Array<{
Expand Down
Loading

0 comments on commit 5b9ad8d

Please sign in to comment.