Unverified Commit 5b9ad8da authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Move next-server directory files to server directory (#26756)

* Move next-server directory files to server directory

* Update tests

* Update paths in other places
parent 136b7543
......@@ -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')
......@@ -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.
......
......@@ -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 */
......
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()
......
......@@ -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
......
......@@ -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,
......
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'
......@@ -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 } = {}
......
......@@ -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'
......@@ -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
)
......
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'
......
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
......
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
......
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) {
......
......@@ -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,
......@@ -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'
......@@ -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}'
......
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'
......
......@@ -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,
......@@ -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)
......
......@@ -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'
......
......@@ -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 {
......
......@@ -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) {
......
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.
......
......@@ -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 }
......
......@@ -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'
......
......@@ -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') {
......
......@@ -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)
......
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'
......
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 {
......
......@@ -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'
......
......@@ -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'
......
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<{
......
import { loadEnvConfig } from '@next/env'
import findUp from 'next/dist/compiled/find-up'
import { init as initWebpack } from 'next/dist/compiled/webpack/webpack'
import {
CONFIG_FILE,
PHASE_DEVELOPMENT_SERVER,
} from '../../shared/lib/constants'
import { CONFIG_FILE, PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants'
import { NextConfig, normalizeConfig } from './config-shared'
import * as Log from '../../build/output/log'
import * as Log from '../build/output/log'
let installed: boolean = false
......@@ -20,7 +17,7 @@ export function install(useWebpack5: boolean) {
// hook the Node.js require so that webpack requires are
// routed to the bundled and now initialized webpack version
require('../../build/webpack/require-hook')
require('../build/webpack/require-hook')
}
export type CheckReasons =
......
import path from 'path'
import { Worker } from 'jest-worker'
import * as Log from '../../build/output/log'
import * as Log from '../build/output/log'
import { CheckReasons, CheckResult } from './config-utils-worker'
import { install, shouldLoadWithWebpack5 } from './config-utils-worker'
import { PHASE_PRODUCTION_SERVER } from '../../shared/lib/constants'
import { PHASE_PRODUCTION_SERVER } from '../shared/lib/constants'
export { install, shouldLoadWithWebpack5 }
......
import chalk from 'chalk'
import findUp from 'next/dist/compiled/find-up'
import { basename, extname } from 'path'
import * as Log from '../../build/output/log'
import { hasNextSupport } from '../../telemetry/ci-info'
import {
CONFIG_FILE,
PHASE_DEVELOPMENT_SERVER,
} from '../../shared/lib/constants'
import { execOnce } from '../../shared/lib/utils'
import * as Log from '../build/output/log'
import { hasNextSupport } from '../telemetry/ci-info'
import { CONFIG_FILE, PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants'
import { execOnce } from '../shared/lib/utils'
import { defaultConfig, normalizeConfig } from './config-shared'
import { loadWebpackHook } from './config-utils'
import { ImageConfig, imageConfigDefault, VALID_LOADERS } from './image-config'
......
......@@ -5,30 +5,27 @@ import { WebpackHotMiddleware } from './hot-middleware'
import { join } from 'path'
import { UrlObject } from 'url'
import { webpack, isWebpack5 } from 'next/dist/compiled/webpack/webpack'
import { createEntrypoints, createPagesMapping } from '../build/entries'
import { watchCompilers } from '../build/output'
import getBaseWebpackConfig from '../build/webpack-config'
import { API_ROUTE } from '../lib/constants'
import { recursiveDelete } from '../lib/recursive-delete'
import { BLOCKED_PAGES } from '../shared/lib/constants'
import { __ApiPreviewProps } from '../next-server/server/api-utils'
import { route } from '../next-server/server/router'
import { findPageFile } from './lib/find-page-file'
import { createEntrypoints, createPagesMapping } from '../../build/entries'
import { watchCompilers } from '../../build/output'
import getBaseWebpackConfig from '../../build/webpack-config'
import { API_ROUTE } from '../../lib/constants'
import { recursiveDelete } from '../../lib/recursive-delete'
import { BLOCKED_PAGES } from '../../shared/lib/constants'
import { __ApiPreviewProps } from '../api-utils'
import { route } from '../router'
import { findPageFile } from '../lib/find-page-file'
import onDemandEntryHandler, {
entries,
BUILDING,
} from './on-demand-entry-handler'
import {
denormalizePagePath,
normalizePathSep,
} from '../next-server/server/normalize-page-path'
import getRouteFromEntrypoint from '../next-server/server/get-route-from-entrypoint'
import { isWriteable } from '../build/is-writeable'
import { ClientPagesLoaderOptions } from '../build/webpack/loaders/next-client-pages-loader'
import { denormalizePagePath, normalizePathSep } from '../normalize-page-path'
import getRouteFromEntrypoint from '../get-route-from-entrypoint'
import { isWriteable } from '../../build/is-writeable'
import { ClientPagesLoaderOptions } from '../../build/webpack/loaders/next-client-pages-loader'
import { stringify } from 'querystring'
import { difference } from '../build/utils'
import { NextConfig } from '../next-server/server/config'
import { CustomRoutes } from '../lib/load-custom-routes'
import { difference } from '../../build/utils'
import { NextConfig } from '../config'
import { CustomRoutes } from '../../lib/load-custom-routes'
export async function renderScriptError(
res: ServerResponse,
......
......@@ -8,44 +8,44 @@ import { join as pathJoin, relative, resolve as pathResolve, sep } from 'path'
import React from 'react'
import { UrlWithParsedQuery } from 'url'
import Watchpack from 'watchpack'
import { ampValidation } from '../build/output/index'
import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../lib/constants'
import { fileExists } from '../lib/file-exists'
import { findPagesDir } from '../lib/find-pages-dir'
import loadCustomRoutes, { CustomRoutes } from '../lib/load-custom-routes'
import { verifyTypeScriptSetup } from '../lib/verifyTypeScriptSetup'
import { ampValidation } from '../../build/output'
import { PUBLIC_DIR_MIDDLEWARE_CONFLICT } from '../../lib/constants'
import { fileExists } from '../../lib/file-exists'
import { findPagesDir } from '../../lib/find-pages-dir'
import loadCustomRoutes, { CustomRoutes } from '../../lib/load-custom-routes'
import { verifyTypeScriptSetup } from '../../lib/verifyTypeScriptSetup'
import {
PHASE_DEVELOPMENT_SERVER,
CLIENT_STATIC_FILES_PATH,
DEV_CLIENT_PAGES_MANIFEST,
} from '../shared/lib/constants'
} from '../../shared/lib/constants'
import {
getRouteMatcher,
getRouteRegex,
getSortedRoutes,
isDynamicRoute,
} from '../shared/lib/router/utils'
import { __ApiPreviewProps } from '../next-server/server/api-utils'
} from '../../shared/lib/router/utils'
import { __ApiPreviewProps } from '../api-utils'
import Server, {
WrappedBuildError,
ServerConstructor,
FindComponentsResult,
} from '../next-server/server/next-server'
import { normalizePagePath } from '../next-server/server/normalize-page-path'
import Router, { Params, route } from '../next-server/server/router'
import { eventCliSession } from '../telemetry/events'
import { Telemetry } from '../telemetry/storage'
import { setGlobal } from '../telemetry/trace'
} from '../next-server'
import { normalizePagePath } from '../normalize-page-path'
import Router, { Params, route } from '../router'
import { eventCliSession } from '../../telemetry/events'
import { Telemetry } from '../../telemetry/storage'
import { setGlobal } from '../../telemetry/trace'
import HotReloader from './hot-reloader'
import { findPageFile } from './lib/find-page-file'
import { getNodeOptionsWithoutInspect } from './lib/utils'
import { withCoalescedInvoke } from '../lib/coalesced-function'
import { NextConfig } from '../next-server/server/config'
import { findPageFile } from '../lib/find-page-file'
import { getNodeOptionsWithoutInspect } from '../lib/utils'
import { withCoalescedInvoke } from '../../lib/coalesced-function'
import { NextConfig } from '../config'
import { ParsedUrlQuery } from 'querystring'
import {
LoadComponentsReturnType,
loadDefaultErrorComponents,
} from '../next-server/server/load-components'
} from '../load-components'
if (typeof React.Suspense === 'undefined') {
throw new Error(
......@@ -704,7 +704,7 @@ export default class DevServer extends Server {
// During development mode, files can be added while the server is running.
// Checks for .next/static, .next/server, static and public.
// Note that in development .next/server is available for error reporting purposes.
// see `packages/next/next-server/server/next-server.ts` for more details.
// see `packages/next/server/next-server.ts` for more details.
if (
untrustedFilePath.startsWith(pathJoin(this.distDir, 'static') + sep) ||
untrustedFilePath.startsWith(pathJoin(this.distDir, 'server') + sep) ||
......
......@@ -3,14 +3,11 @@ import { IncomingMessage, ServerResponse } from 'http'
import { join, posix } from 'path'
import { parse } from 'url'
import { webpack, isWebpack5 } from 'next/dist/compiled/webpack/webpack'
import * as Log from '../build/output/log'
import {
normalizePagePath,
normalizePathSep,
} from '../next-server/server/normalize-page-path'
import { pageNotFoundError } from '../next-server/server/require'
import { findPageFile } from './lib/find-page-file'
import getRouteFromEntrypoint from '../next-server/server/get-route-from-entrypoint'
import * as Log from '../../build/output/log'
import { normalizePagePath, normalizePathSep } from '../normalize-page-path'
import { pageNotFoundError } from '../require'
import { findPageFile } from '../lib/find-page-file'
import getRouteFromEntrypoint from '../get-route-from-entrypoint'
export const ADDED = Symbol('added')
export const BUILDING = Symbol('building')
......
import { buildStaticPaths } from '../build/utils'
import { loadComponents } from '../next-server/server/load-components'
import '../next-server/server/node-polyfill-fetch'
import { buildStaticPaths } from '../../build/utils'
import { loadComponents } from '../load-components'
import '../node-polyfill-fetch'
type RuntimeConfig = any
......@@ -24,7 +24,7 @@ export async function loadStaticPaths(
}
// update work memory runtime-config
require('../shared/lib/runtime-config').setConfig(config)
require('../../shared/lib/runtime-config').setConfig(config)
const components = await loadComponents(distDir, pathname, serverless)
......
import * as Log from '../../build/output/log'
import { GOOGLE_FONT_PROVIDER } from '../../shared/lib/constants'
import * as Log from '../build/output/log'
import { GOOGLE_FONT_PROVIDER } from '../shared/lib/constants'
const https = require('https')
const CHROME_UA =
......
import getRouteFromAssetPath from '../../shared/lib/router/utils/get-route-from-asset-path'
import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-asset-path'
// matches pages/:page*.js
const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/
......
......@@ -8,8 +8,8 @@ import isAnimated from 'next/dist/compiled/is-animated'
import { join } from 'path'
import Stream from 'stream'
import nodeUrl, { UrlWithParsedQuery } from 'url'
import { NextConfig } from '../../next-server/server/config-shared'
import { fileExists } from '../../lib/file-exists'
import { NextConfig } from './config-shared'
import { fileExists } from '../lib/file-exists'
import { ImageConfig, imageConfigDefault } from './image-config'
import { processBuffer, Operation } from './lib/squoosh/main'
import Server from './next-server'
......
import { promises, readFileSync } from 'fs'
import LRUCache from 'next/dist/compiled/lru-cache'
import path from 'path'
import { PrerenderManifest } from '../../build'
import { PRERENDER_MANIFEST } from '../../shared/lib/constants'
import { PrerenderManifest } from '../build'
import { PRERENDER_MANIFEST } from '../shared/lib/constants'
import { normalizePagePath } from './normalize-page-path'
function toRoute(pathname: string): string {
......
......@@ -2,7 +2,7 @@ import { join, sep as pathSeparator, normalize } from 'path'
import chalk from 'chalk'
import { warn } from '../../build/output/log'
import { promises } from 'fs'
import { denormalizePagePath } from '../../next-server/server/normalize-page-path'
import { denormalizePagePath } from '../normalize-page-path'
import { fileExists } from '../../lib/file-exists'
async function isTrueCasePagePath(pagePath: string, pagesDir: string) {
......
import { Worker } from 'jest-worker'
import * as path from 'path'
import { execOnce } from '../../../../shared/lib/utils'
import { execOnce } from '../../../shared/lib/utils'
import { cpus } from 'os'
type RotateOperation = {
......
import {
BUILD_MANIFEST,
REACT_LOADABLE_MANIFEST,
} from '../../shared/lib/constants'
} from '../shared/lib/constants'
import { join } from 'path'
import { requirePage } from './require'
import { BuildManifest } from './get-page-files'
import { AppType, DocumentType } from '../../shared/lib/utils'
import { AppType, DocumentType } from '../shared/lib/utils'
import {
PageConfig,
GetStaticPaths,
......
......@@ -10,7 +10,7 @@ import {
ParsedUrlQuery,
} from 'querystring'
import { format as formatUrl, parse as parseUrl, UrlWithParsedQuery } from 'url'
import { PrerenderManifest } from '../../build'
import { PrerenderManifest } from '../build'
import {
getRedirectStatus,
Header,
......@@ -18,8 +18,8 @@ import {
Rewrite,
RouteType,
CustomRoutes,
} from '../../lib/load-custom-routes'
import { withCoalescedInvoke } from '../../lib/coalesced-function'
} from '../lib/load-custom-routes'
import { withCoalescedInvoke } from '../lib/coalesced-function'
import {
BUILD_ID_FILE,
CLIENT_PUBLIC_FILES_PATH,
......@@ -33,19 +33,15 @@ import {
SERVER_DIRECTORY,
STATIC_STATUS_PAGES,
TEMPORARY_REDIRECT_STATUS,
} from '../../shared/lib/constants'
} from '../shared/lib/constants'
import {
getRouteMatcher,
getRouteRegex,
getSortedRoutes,
isDynamicRoute,
} from '../../shared/lib/router/utils'
import * as envConfig from '../../shared/lib/runtime-config'
import {
isResSent,
NextApiRequest,
NextApiResponse,
} from '../../shared/lib/utils'
} from '../shared/lib/router/utils'
import * as envConfig from '../shared/lib/runtime-config'
import { isResSent, NextApiRequest, NextApiResponse } from '../shared/lib/utils'
import {
apiResolver,
setLazyProp,
......@@ -54,7 +50,7 @@ import {
__ApiPreviewProps,
} from './api-utils'
import { DomainLocales, isTargetLikeServerless, NextConfig } from './config'
import pathMatch from '../../shared/lib/router/utils/path-match'
import pathMatch from '../shared/lib/router/utils/path-match'
import { recursiveReadDirSync } from './lib/recursive-readdir-sync'
import { loadComponents, LoadComponentsReturnType } from './load-components'
import { normalizePagePath } from './normalize-page-path'
......@@ -69,28 +65,28 @@ import Router, {
} from './router'
import prepareDestination, {
compileNonPath,
} from '../../shared/lib/router/utils/prepare-destination'
} from '../shared/lib/router/utils/prepare-destination'
import { sendPayload, setRevalidateHeaders } from './send-payload'
import { serveStatic } from './serve-static'
import { IncrementalCache } from './incremental-cache'
import { execOnce } from '../../shared/lib/utils'
import { execOnce } from '../shared/lib/utils'
import { isBlockedPage } from './utils'
import { loadEnvConfig } from '@next/env'
import './node-polyfill-fetch'
import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin'
import { removePathTrailingSlash } from '../../client/normalize-trailing-slash'
import getRouteFromAssetPath from '../../shared/lib/router/utils/get-route-from-asset-path'
import { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
import { removePathTrailingSlash } from '../client/normalize-trailing-slash'
import getRouteFromAssetPath from '../shared/lib/router/utils/get-route-from-asset-path'
import { FontManifest } from './font-utils'
import { denormalizePagePath } from './denormalize-page-path'
import accept from '@hapi/accept'
import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
import { detectLocaleCookie } from '../../shared/lib/i18n/detect-locale-cookie'
import * as Log from '../../build/output/log'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import { detectLocaleCookie } from '../shared/lib/i18n/detect-locale-cookie'
import * as Log from '../build/output/log'
import { imageOptimizer } from './image-optimizer'
import { detectDomainLocale } from '../../shared/lib/i18n/detect-domain-locale'
import { detectDomainLocale } from '../shared/lib/i18n/detect-domain-locale'
import cookie from 'next/dist/compiled/cookie'
import escapePathDelimiters from '../../shared/lib/router/utils/escape-path-delimiters'
import { getUtils } from '../../build/webpack/loaders/next-serverless-loader/utils'
import escapePathDelimiters from '../shared/lib/router/utils/escape-path-delimiters'
import { getUtils } from '../build/webpack/loaders/next-serverless-loader/utils'
import { PreviewData } from 'next/types'
const getCustomRouteMatcher = pathMatch(true)
......
import '../next-server/server/node-polyfill-fetch'
import {
default as Server,
ServerConstructor,
} from '../next-server/server/next-server'
import './node-polyfill-fetch'
import { default as Server, ServerConstructor } from './next-server'
import { NON_STANDARD_NODE_ENV } from '../lib/constants'
import * as log from '../build/output/log'
import loadConfig, { NextConfig } from '../next-server/server/config'
import loadConfig, { NextConfig } from './config'
import { resolve } from 'path'
import {
PHASE_DEVELOPMENT_SERVER,
......@@ -25,7 +22,7 @@ let ServerImpl: typeof Server
const getServerImpl = async () => {
if (ServerImpl === undefined)
ServerImpl = (await import('../next-server/server/next-server')).default
ServerImpl = (await import('./next-server')).default
return ServerImpl
}
......@@ -112,7 +109,7 @@ export class NextServer {
}
): Promise<Server> {
if (options.dev) {
const DevServer = require('./next-dev-server').default
const DevServer = require('./dev/next-dev-server').default
return new DevServer(options)
}
return new (await getServerImpl())(options)
......
......@@ -2,8 +2,8 @@ import { IncomingMessage, ServerResponse } from 'http'
import { ParsedUrlQuery } from 'querystring'
import React from 'react'
import { renderToStaticMarkup, renderToString } from 'react-dom/server'
import { warn } from '../../build/output/log'
import { UnwrapPromise } from '../../lib/coalesced-function'
import { warn } from '../build/output/log'
import { UnwrapPromise } from '../lib/coalesced-function'
import {
GSP_NO_RETURNED_VALUE,
GSSP_COMPONENT_MEMBER_ERROR,
......@@ -13,25 +13,25 @@ import {
SERVER_PROPS_SSG_CONFLICT,
SSG_GET_INITIAL_PROPS_CONFLICT,
UNSTABLE_REVALIDATE_RENAME_ERROR,
} from '../../lib/constants'
import { isSerializableProps } from '../../lib/is-serializable-props'
import { GetServerSideProps, GetStaticProps, PreviewData } from '../../types'
import { isInAmpMode } from '../../shared/lib/amp'
import { AmpStateContext } from '../../shared/lib/amp-context'
} from '../lib/constants'
import { isSerializableProps } from '../lib/is-serializable-props'
import { GetServerSideProps, GetStaticProps, PreviewData } from '../types'
import { isInAmpMode } from '../shared/lib/amp'
import { AmpStateContext } from '../shared/lib/amp-context'
import {
AMP_RENDER_TARGET,
SERVER_PROPS_ID,
STATIC_PROPS_ID,
STATIC_STATUS_PAGES,
} from '../../shared/lib/constants'
import { defaultHead } from '../../shared/lib/head'
import { HeadManagerContext } from '../../shared/lib/head-manager-context'
import Loadable from '../../shared/lib/loadable'
import { LoadableContext } from '../../shared/lib/loadable-context'
import postProcess from '../../shared/lib/post-process'
import { RouterContext } from '../../shared/lib/router-context'
import { NextRouter } from '../../shared/lib/router/router'
import { isDynamicRoute } from '../../shared/lib/router/utils/is-dynamic'
} from '../shared/lib/constants'
import { defaultHead } from '../shared/lib/head'
import { HeadManagerContext } from '../shared/lib/head-manager-context'
import Loadable from '../shared/lib/loadable'
import { LoadableContext } from '../shared/lib/loadable-context'
import postProcess from '../shared/lib/post-process'
import { RouterContext } from '../shared/lib/router-context'
import { NextRouter } from '../shared/lib/router/router'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import {
AppType,
ComponentsEnhancer,
......@@ -43,7 +43,7 @@ import {
loadGetInitialProps,
NextComponentType,
RenderPage,
} from '../../shared/lib/utils'
} from '../shared/lib/utils'
import {
tryGetPreviewData,
NextApiRequestCookies,
......@@ -58,7 +58,7 @@ import {
allowedStatusCodes,
getRedirectStatus,
Redirect,
} from '../../lib/load-custom-routes'
} from '../lib/load-custom-routes'
import { DomainLocales } from './config'
function noRouter() {
......
......@@ -5,10 +5,10 @@ import {
SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
FONT_MANIFEST,
} from '../../shared/lib/constants'
} from '../shared/lib/constants'
import { normalizePagePath, denormalizePagePath } from './normalize-page-path'
import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin'
import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
import { PagesManifest } from '../build/webpack/plugins/pages-manifest-plugin'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
export function pageNotFoundError(page: string): Error {
const err: any = new Error(`Cannot find module for page: ${page}`)
......
import { IncomingMessage, ServerResponse } from 'http'
import { UrlWithParsedQuery } from 'url'
import pathMatch from '../../shared/lib/router/utils/path-match'
import { removePathTrailingSlash } from '../../client/normalize-trailing-slash'
import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
import { RouteHas } from '../../lib/load-custom-routes'
import { matchHas } from '../../shared/lib/router/utils/prepare-destination'
import pathMatch from '../shared/lib/router/utils/path-match'
import { removePathTrailingSlash } from '../client/normalize-trailing-slash'
import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import { RouteHas } from '../lib/load-custom-routes'
import { matchHas } from '../shared/lib/router/utils/prepare-destination'
export const route = pathMatch()
......
import { IncomingMessage, ServerResponse } from 'http'
import { isResSent } from '../../shared/lib/utils'
import { isResSent } from '../shared/lib/utils'
import generateETag from 'etag'
import fresh from 'next/dist/compiled/fresh'
......
import { BLOCKED_PAGES } from '../../shared/lib/constants'
import { BLOCKED_PAGES } from '../shared/lib/constants'
export function isBlockedPage(pathname: string): boolean {
return BLOCKED_PAGES.includes(pathname)
......
......@@ -13,8 +13,8 @@ import {
markAssetError,
} from '../../../client/route-loader'
import { RouterEvent } from '../../../client/router'
import { DomainLocales } from '../../../next-server/server/config'
import { denormalizePagePath } from '../../../next-server/server/denormalize-page-path'
import { DomainLocales } from '../../../server/config'
import { denormalizePagePath } from '../../../server/denormalize-page-path'
import { normalizeLocalePath } from '../i18n/normalize-locale-path'
import mitt, { MittEmitter } from '../mitt'
import {
......
......@@ -5,8 +5,8 @@ import { UrlObject } from 'url'
import { formatUrl } from './router/utils/format-url'
import { NextRouter } from './router/router'
import { Env } from '@next/env'
import { BuildManifest } from '../../next-server/server/get-page-files'
import { DomainLocales } from '../../next-server/server/config'
import { BuildManifest } from '../../server/get-page-files'
import { DomainLocales } from '../../server/config'
import { PreviewData } from 'next/types'
export type NextComponentType<
......
......@@ -808,9 +808,8 @@ export async function compile(task, opts) {
'lib',
'client',
'telemetry',
'nextserver',
'shared',
'nextserver_wasm',
'server_wasm',
// we compile this each time so that fresh runtime data is pulled
// before each publish
'ncc_amp_optimizer',
......@@ -926,17 +925,8 @@ export default async function (task) {
await task.watch('lib/**/*.+(js|ts|tsx)', 'lib', opts)
await task.watch('cli/**/*.+(js|ts|tsx)', 'cli', opts)
await task.watch('telemetry/**/*.+(js|ts|tsx)', 'telemetry', opts)
await task.watch('next-server/**/*.+(js|ts|tsx)', 'nextserver', opts)
await task.watch('shared/**/*.+(js|ts|tsx)', 'shared', opts)
await task.watch('next-server/**/*.+(wasm)', 'nextserver_wasm', opts)
}
export async function nextserver(task, opts) {
await task
.source(opts.src || 'next-server/**/*.+(js|ts|tsx)')
.babel('server', { dev: opts.dev })
.target('dist/next-server')
notify('Compiled server files')
await task.watch('server/**/*.+(wasm)', 'server_wasm', opts)
}
export async function shared(task, opts) {
......@@ -947,10 +937,8 @@ export async function shared(task, opts) {
notify('Compiled shared files')
}
export async function nextserver_wasm(task, opts) {
await task
.source(opts.src || 'next-server/**/*.+(wasm)')
.target('dist/next-server')
export async function server_wasm(task, opts) {
await task.source(opts.src || 'server/**/*.+(wasm)').target('dist/server')
notify('Moved server wasm files')
}
......
......@@ -6,7 +6,7 @@ import {
PHASE_EXPORT,
PHASE_PRODUCTION_BUILD,
} from '../../shared/lib/constants'
import { normalizeConfig } from '../../next-server/server/config'
import { normalizeConfig } from '../../server/config'
const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED'
......
......@@ -18,11 +18,16 @@ import {
import {
NextApiRequestCookies,
// @ts-ignore This path is generated at build time and conflicts otherwise
} from '../dist/next-server/server/api-utils'
} from '../dist/server/api-utils'
// @ts-ignore This path is generated at build time and conflicts otherwise
import next from '../dist/server/next'
// @ts-ignore This path is generated at build time and conflicts otherwise
import { NextConfig as NextConfigType } from '../dist/server/config'
export type NextConfig = NextConfigType
// Extend the React types with missing properties
declare module 'react' {
// <html amp=""> support
......
/* eslint-env jest */
import { getMaxAge } from '../../../../packages/next/dist/next-server/server/image-optimizer.js'
import { getMaxAge } from '../../../../packages/next/dist/server/image-optimizer.js'
describe('getMaxAge', () => {
it('should return default when no cache-control provided', () => {
......
/* eslint-env jest */
import { join } from 'path'
import loadConfig from 'next/dist/next-server/server/config'
import loadConfig from 'next/dist/server/config'
import { PHASE_DEVELOPMENT_SERVER } from 'next/constants'
const pathToConfig = join(__dirname, '_resolvedata', 'without-function')
......
......@@ -6,8 +6,8 @@ import {
requirePage,
getPagePath,
pageNotFoundError,
} from 'next/dist/next-server/server/require'
import { normalizePagePath } from 'next/dist/next-server/server/normalize-page-path'
} from 'next/dist/server/require'
import { normalizePagePath } from 'next/dist/server/normalize-page-path'
const sep = '/'
const distDir = join(__dirname, '_resolvedata')
......
/* eslint-env jest */
import { findPageFile } from 'next/dist/server/lib/find-page-file'
import { normalizePagePath } from 'next/dist/next-server/server/normalize-page-path'
import { normalizePagePath } from 'next/dist/server/normalize-page-path'
import { join } from 'path'
......
/* eslint-env jest */
import { cleanAmpPath } from 'next/dist/next-server/server/utils'
import { cleanAmpPath } from 'next/dist/server/utils'
// convenience function so tests can be aligned neatly
// and easy to eyeball
......
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