Unverified Commit 136b7543 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Move code shared between server/client to "shared" folder (#26734)

parent f5958fdc
export * from './dist/next-server/lib/amp' export * from './dist/shared/lib/amp'
module.exports = require('./dist/next-server/lib/amp') module.exports = require('./dist/shared/lib/amp')
...@@ -118,7 +118,7 @@ commands[command]() ...@@ -118,7 +118,7 @@ commands[command]()
}) })
if (command === 'dev') { if (command === 'dev') {
const { CONFIG_FILE } = require('../next-server/lib/constants') const { CONFIG_FILE } = require('../shared/lib/constants')
const { watchFile } = require('fs') const { watchFile } = require('fs')
watchFile(`${process.cwd()}/${CONFIG_FILE}`, (cur: any, prev: any) => { watchFile(`${process.cwd()}/${CONFIG_FILE}`, (cur: any, prev: any) => {
if (cur.size > 0 || prev.size > 0) { if (cur.size > 0 || prev.size > 0) {
......
...@@ -8,7 +8,7 @@ import { NextBabelLoaderOptions, NextJsLoaderContext } from './types' ...@@ -8,7 +8,7 @@ import { NextBabelLoaderOptions, NextJsLoaderContext } from './types'
import { consumeIterator } from './util' import { consumeIterator } from './util'
import * as Log from '../../output/log' import * as Log from '../../output/log'
const nextDistPath = /(next[\\/]dist[\\/]next-server[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/ const nextDistPath = /(next[\\/]dist[\\/]shared[\\/]lib)|(next[\\/]dist[\\/]client)|(next[\\/]dist[\\/]pages)/
/** /**
* The properties defined here are the conditions with which subsets of inputs * The properties defined here are the conditions with which subsets of inputs
......
import { NodePath, PluginObj, types } from 'next/dist/compiled/babel/core' import { NodePath, PluginObj, types } from 'next/dist/compiled/babel/core'
import commonjsPlugin from 'next/dist/compiled/babel/plugin-transform-modules-commonjs' import commonjsPlugin from 'next/dist/compiled/babel/plugin-transform-modules-commonjs'
// Rewrite imports using next/<something> to next-server/<something> // Handle module.exports in user code
export default function NextToNextServer(...args: any): PluginObj { export default function CommonJSModulePlugin(...args: any): PluginObj {
const commonjs = commonjsPlugin(...args) const commonjs = commonjsPlugin(...args)
return { return {
visitor: { visitor: {
......
...@@ -6,7 +6,7 @@ import { ...@@ -6,7 +6,7 @@ import {
Visitor, Visitor,
} from 'next/dist/compiled/babel/core' } from 'next/dist/compiled/babel/core'
import { PageConfig } from 'next/types' import { PageConfig } from 'next/types'
import { STRING_LITERAL_DROP_BUNDLE } from '../../../next-server/lib/constants' import { STRING_LITERAL_DROP_BUNDLE } from '../../../shared/lib/constants'
const CONFIG_KEY = 'config' const CONFIG_KEY = 'config'
......
...@@ -4,10 +4,7 @@ import { ...@@ -4,10 +4,7 @@ import {
types as BabelTypes, types as BabelTypes,
} from 'next/dist/compiled/babel/core' } from 'next/dist/compiled/babel/core'
import { SERVER_PROPS_SSG_CONFLICT } from '../../../lib/constants' import { SERVER_PROPS_SSG_CONFLICT } from '../../../lib/constants'
import { import { SERVER_PROPS_ID, STATIC_PROPS_ID } from '../../../shared/lib/constants'
SERVER_PROPS_ID,
STATIC_PROPS_ID,
} from '../../../next-server/lib/constants'
export const EXPORT_NAME_GET_STATIC_PROPS = 'getStaticProps' export const EXPORT_NAME_GET_STATIC_PROPS = 'getStaticProps'
export const EXPORT_NAME_GET_STATIC_PATHS = 'getStaticPaths' export const EXPORT_NAME_GET_STATIC_PATHS = 'getStaticPaths'
......
...@@ -45,12 +45,12 @@ import { ...@@ -45,12 +45,12 @@ import {
SERVER_DIRECTORY, SERVER_DIRECTORY,
SERVER_FILES_MANIFEST, SERVER_FILES_MANIFEST,
STATIC_STATUS_PAGES, STATIC_STATUS_PAGES,
} from '../next-server/lib/constants' } from '../shared/lib/constants'
import { import {
getRouteRegex, getRouteRegex,
getSortedRoutes, getSortedRoutes,
isDynamicRoute, isDynamicRoute,
} from '../next-server/lib/router/utils' } from '../shared/lib/router/utils'
import { __ApiPreviewProps } from '../next-server/server/api-utils' import { __ApiPreviewProps } from '../next-server/server/api-utils'
import loadConfig, { import loadConfig, {
isTargetLikeServerless, isTargetLikeServerless,
...@@ -89,7 +89,7 @@ import { ...@@ -89,7 +89,7 @@ import {
import getBaseWebpackConfig from './webpack-config' import getBaseWebpackConfig from './webpack-config'
import { PagesManifest } from './webpack/plugins/pages-manifest-plugin' import { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
import { writeBuildId } from './write-build-id' import { writeBuildId } from './write-build-id'
import { normalizeLocalePath } from '../next-server/lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import { isWebpack5 } from 'next/dist/compiled/webpack/webpack' import { isWebpack5 } from 'next/dist/compiled/webpack/webpack'
const staticCheckWorker = require.resolve('./utils') const staticCheckWorker = require.resolve('./utils')
......
...@@ -19,16 +19,16 @@ import { ...@@ -19,16 +19,16 @@ import {
} from '../lib/constants' } from '../lib/constants'
import prettyBytes from '../lib/pretty-bytes' import prettyBytes from '../lib/pretty-bytes'
import { recursiveReadDir } from '../lib/recursive-readdir' import { recursiveReadDir } from '../lib/recursive-readdir'
import { getRouteMatcher, getRouteRegex } from '../next-server/lib/router/utils' import { getRouteMatcher, getRouteRegex } from '../shared/lib/router/utils'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import escapePathDelimiters from '../next-server/lib/router/utils/escape-path-delimiters' import escapePathDelimiters from '../shared/lib/router/utils/escape-path-delimiters'
import { findPageFile } from '../server/lib/find-page-file' import { findPageFile } from '../server/lib/find-page-file'
import { GetStaticPaths } from 'next/types' import { GetStaticPaths } from 'next/types'
import { denormalizePagePath } from '../next-server/server/normalize-page-path' import { denormalizePagePath } from '../next-server/server/normalize-page-path'
import { BuildManifest } from '../next-server/server/get-page-files' import { BuildManifest } from '../next-server/server/get-page-files'
import { removePathTrailingSlash } from '../client/normalize-trailing-slash' import { removePathTrailingSlash } from '../client/normalize-trailing-slash'
import { UnwrapPromise } from '../lib/coalesced-function' import { UnwrapPromise } from '../lib/coalesced-function'
import { normalizeLocalePath } from '../next-server/lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import * as Log from './output/log' import * as Log from './output/log'
import { loadComponents } from '../next-server/server/load-components' import { loadComponents } from '../next-server/server/load-components'
import { trace } from '../telemetry/trace' import { trace } from '../telemetry/trace'
...@@ -765,7 +765,7 @@ export async function isPageStatic( ...@@ -765,7 +765,7 @@ export async function isPageStatic(
const isPageStaticSpan = trace('is-page-static-utils', parentId) const isPageStaticSpan = trace('is-page-static-utils', parentId)
return isPageStaticSpan.traceAsyncFn(async () => { return isPageStaticSpan.traceAsyncFn(async () => {
try { try {
require('../next-server/lib/runtime-config').setConfig(runtimeEnvConfig) require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
const components = await loadComponents(distDir, page, serverless) const components = await loadComponents(distDir, page, serverless)
const mod = components.ComponentMod const mod = components.ComponentMod
const Comp = mod.default || mod const Comp = mod.default || mod
...@@ -880,7 +880,7 @@ export async function hasCustomGetInitialProps( ...@@ -880,7 +880,7 @@ export async function hasCustomGetInitialProps(
runtimeEnvConfig: any, runtimeEnvConfig: any,
checkingApp: boolean checkingApp: boolean
): Promise<boolean> { ): Promise<boolean> {
require('../next-server/lib/runtime-config').setConfig(runtimeEnvConfig) require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
const components = await loadComponents(distDir, page, isLikeServerless) const components = await loadComponents(distDir, page, isLikeServerless)
let mod = components.ComponentMod let mod = components.ComponentMod
...@@ -900,7 +900,7 @@ export async function getNamedExports( ...@@ -900,7 +900,7 @@ export async function getNamedExports(
isLikeServerless: boolean, isLikeServerless: boolean,
runtimeEnvConfig: any runtimeEnvConfig: any
): Promise<Array<string>> { ): Promise<Array<string>> {
require('../next-server/lib/runtime-config').setConfig(runtimeEnvConfig) require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
const components = await loadComponents(distDir, page, isLikeServerless) const components = await loadComponents(distDir, page, isLikeServerless)
let mod = components.ComponentMod let mod = components.ComponentMod
......
...@@ -25,8 +25,8 @@ import { ...@@ -25,8 +25,8 @@ import {
REACT_LOADABLE_MANIFEST, REACT_LOADABLE_MANIFEST,
SERVERLESS_DIRECTORY, SERVERLESS_DIRECTORY,
SERVER_DIRECTORY, SERVER_DIRECTORY,
} from '../next-server/lib/constants' } from '../shared/lib/constants'
import { execOnce } from '../next-server/lib/utils' import { execOnce } from '../shared/lib/utils'
import { NextConfig } from '../next-server/server/config' import { NextConfig } from '../next-server/server/config'
import { findPageFile } from '../server/lib/find-page-file' import { findPageFile } from '../server/lib/find-page-file'
import { WebpackEntrypoints } from './entries' import { WebpackEntrypoints } from './entries'
...@@ -305,7 +305,7 @@ export default async function getBaseWebpackConfig( ...@@ -305,7 +305,7 @@ export default async function getBaseWebpackConfig(
} }
const babelIncludeRegexes: RegExp[] = [ const babelIncludeRegexes: RegExp[] = [
/next[\\/]dist[\\/]next-server[\\/]lib/, /next[\\/]dist[\\/]shared[\\/]lib/,
/next[\\/]dist[\\/]client/, /next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/, /next[\\/]dist[\\/]pages/,
/[\\/](strip-ansi|ansi-regex)[\\/]/, /[\\/](strip-ansi|ansi-regex)[\\/]/,
...@@ -396,10 +396,10 @@ export default async function getBaseWebpackConfig( ...@@ -396,10 +396,10 @@ export default async function getBaseWebpackConfig(
} }
const clientResolveRewrites = require.resolve( const clientResolveRewrites = require.resolve(
'../next-server/lib/router/utils/resolve-rewrites' '../shared/lib/router/utils/resolve-rewrites'
) )
const clientResolveRewritesNoop = require.resolve( const clientResolveRewritesNoop = require.resolve(
'../next-server/lib/router/utils/resolve-rewrites-noop' '../shared/lib/router/utils/resolve-rewrites-noop'
) )
const resolveConfig = { const resolveConfig = {
...@@ -676,11 +676,7 @@ export default async function getBaseWebpackConfig( ...@@ -676,11 +676,7 @@ export default async function getBaseWebpackConfig(
// are relative to requests we've already resolved here. // are relative to requests we've already resolved here.
// Absolute requires (require('/foo')) are extremely uncommon, but // Absolute requires (require('/foo')) are extremely uncommon, but
// also have no need for customization as they're already resolved. // also have no need for customization as they're already resolved.
if (isLocal) { if (!isLocal) {
if (!/[/\\]next-server[/\\]/.test(request)) {
return
}
} else {
if (/^(?:next$|react(?:$|\/))/.test(request)) { if (/^(?:next$|react(?:$|\/))/.test(request)) {
return `commonjs ${request}` return `commonjs ${request}`
} }
...@@ -713,9 +709,10 @@ export default async function getBaseWebpackConfig( ...@@ -713,9 +709,10 @@ export default async function getBaseWebpackConfig(
} }
if (isLocal) { if (isLocal) {
// we need to process next-server/lib/router/router so that // Makes sure dist/shared and dist/next-server are not bundled
// we need to process shared/lib/router/router so that
// the DefinePlugin can inject process.env values // the DefinePlugin can inject process.env values
const isNextExternal = /next[/\\]dist[/\\]next-server[/\\](?!lib[/\\]router[/\\]router)/.test( const isNextExternal = /next[/\\]dist[/\\](shared|next-server)[/\\](?!lib[/\\]router[/\\]router)/.test(
res res
) )
...@@ -761,9 +758,7 @@ export default async function getBaseWebpackConfig( ...@@ -761,9 +758,7 @@ export default async function getBaseWebpackConfig(
} }
if ( if (
res.match( res.match(/next[/\\]dist[/\\]shared[/\\](?!lib[/\\]router[/\\]router)/)
/next[/\\]dist[/\\]next-server[/\\](?!lib[/\\]router[/\\]router)/
)
) { ) {
return `commonjs ${request}` return `commonjs ${request}`
} }
...@@ -1193,7 +1188,7 @@ export default async function getBaseWebpackConfig( ...@@ -1193,7 +1188,7 @@ export default async function getBaseWebpackConfig(
!dev && !dev &&
new webpack.IgnorePlugin({ new webpack.IgnorePlugin({
resourceRegExp: /react-is/, resourceRegExp: /react-is/,
contextRegExp: /(next-server|next)[\\/]dist[\\/]/, contextRegExp: /next[\\/]dist[\\/]/,
}), }),
isServerless && isServer && new ServerlessPlugin(), isServerless && isServer && new ServerlessPlugin(),
isServer && isServer &&
......
...@@ -171,12 +171,12 @@ const customBabelLoader = babelLoader((babel) => { ...@@ -171,12 +171,12 @@ const customBabelLoader = babelLoader((babel) => {
} }
} }
// As next-server/lib has stateful modules we have to transpile commonjs // As shared/lib has stateful modules we have to transpile commonjs
options.overrides = [ options.overrides = [
...(options.overrides || []), ...(options.overrides || []),
{ {
test: [ test: [
/next[\\/]dist[\\/]next-server[\\/]lib/, /next[\\/]dist[\\/]shared[\\/]lib/,
/next[\\/]dist[\\/]client/, /next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/, /next[\\/]dist[\\/]pages/,
], ],
......
...@@ -4,13 +4,13 @@ import { join } from 'path' ...@@ -4,13 +4,13 @@ import { join } from 'path'
import { parse } from 'querystring' import { parse } from 'querystring'
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
import { API_ROUTE } from '../../../../lib/constants' import { API_ROUTE } from '../../../../lib/constants'
import { isDynamicRoute } from '../../../../next-server/lib/router/utils' import { isDynamicRoute } from '../../../../shared/lib/router/utils'
import { __ApiPreviewProps } from '../../../../next-server/server/api-utils' import { __ApiPreviewProps } from '../../../../next-server/server/api-utils'
import { import {
BUILD_MANIFEST, BUILD_MANIFEST,
ROUTES_MANIFEST, ROUTES_MANIFEST,
REACT_LOADABLE_MANIFEST, REACT_LOADABLE_MANIFEST,
} from '../../../../next-server/lib/constants' } from '../../../../shared/lib/constants'
import { trace } from '../../../../telemetry/trace' import { trace } from '../../../../telemetry/trace'
export type ServerlessLoaderQuery = { export type ServerlessLoaderQuery = {
......
import { IncomingMessage, ServerResponse } from 'http' import { IncomingMessage, ServerResponse } from 'http'
import { parse as parseUrl, format as formatUrl, UrlWithParsedQuery } from 'url' import { parse as parseUrl, format as formatUrl, UrlWithParsedQuery } from 'url'
import { isResSent } from '../../../../next-server/lib/utils' import { isResSent } from '../../../../shared/lib/utils'
import { sendPayload } from '../../../../next-server/server/send-payload' import { sendPayload } from '../../../../next-server/server/send-payload'
import { getUtils, vercelHeader, ServerlessHandlerCtx } from './utils' import { getUtils, vercelHeader, ServerlessHandlerCtx } from './utils'
...@@ -12,8 +12,8 @@ import { ...@@ -12,8 +12,8 @@ import {
getCookieParser, getCookieParser,
} from '../../../../next-server/server/api-utils' } from '../../../../next-server/server/api-utils'
import { getRedirectStatus } from '../../../../lib/load-custom-routes' import { getRedirectStatus } from '../../../../lib/load-custom-routes'
import getRouteNoAssetPath from '../../../../next-server/lib/router/utils/get-route-from-asset-path' import getRouteNoAssetPath from '../../../../shared/lib/router/utils/get-route-from-asset-path'
import { PERMANENT_REDIRECT_STATUS } from '../../../../next-server/lib/constants' import { PERMANENT_REDIRECT_STATUS } from '../../../../shared/lib/constants'
export function getPageHandler(ctx: ServerlessHandlerCtx) { export function getPageHandler(ctx: ServerlessHandlerCtx) {
const { const {
......
...@@ -2,13 +2,13 @@ import { IncomingMessage, ServerResponse } from 'http' ...@@ -2,13 +2,13 @@ import { IncomingMessage, ServerResponse } from 'http'
import { format as formatUrl, UrlWithParsedQuery, parse as parseUrl } from 'url' import { format as formatUrl, UrlWithParsedQuery, parse as parseUrl } from 'url'
import { parse as parseQs, ParsedUrlQuery } from 'querystring' import { parse as parseQs, ParsedUrlQuery } from 'querystring'
import { Rewrite } from '../../../../lib/load-custom-routes' import { Rewrite } from '../../../../lib/load-custom-routes'
import { normalizeLocalePath } from '../../../../next-server/lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../../../../shared/lib/i18n/normalize-locale-path'
import pathMatch from '../../../../next-server/lib/router/utils/path-match' import pathMatch from '../../../../shared/lib/router/utils/path-match'
import { getRouteRegex } from '../../../../next-server/lib/router/utils/route-regex' import { getRouteRegex } from '../../../../shared/lib/router/utils/route-regex'
import { getRouteMatcher } from '../../../../next-server/lib/router/utils/route-matcher' import { getRouteMatcher } from '../../../../shared/lib/router/utils/route-matcher'
import prepareDestination, { import prepareDestination, {
matchHas, matchHas,
} from '../../../../next-server/lib/router/utils/prepare-destination' } from '../../../../shared/lib/router/utils/prepare-destination'
import { __ApiPreviewProps } from '../../../../next-server/server/api-utils' import { __ApiPreviewProps } from '../../../../next-server/server/api-utils'
import { BuildManifest } from '../../../../next-server/server/get-page-files' import { BuildManifest } from '../../../../next-server/server/get-page-files'
import { import {
...@@ -17,11 +17,11 @@ import { ...@@ -17,11 +17,11 @@ import {
GetStaticProps, GetStaticProps,
} from '../../../../types' } from '../../../../types'
import accept from '@hapi/accept' import accept from '@hapi/accept'
import { detectLocaleCookie } from '../../../../next-server/lib/i18n/detect-locale-cookie' import { detectLocaleCookie } from '../../../../shared/lib/i18n/detect-locale-cookie'
import { detectDomainLocale } from '../../../../next-server/lib/i18n/detect-domain-locale' import { detectDomainLocale } from '../../../../shared/lib/i18n/detect-domain-locale'
import { denormalizePagePath } from '../../../../next-server/server/denormalize-page-path' import { denormalizePagePath } from '../../../../next-server/server/denormalize-page-path'
import cookie from 'next/dist/compiled/cookie' import cookie from 'next/dist/compiled/cookie'
import { TEMPORARY_REDIRECT_STATUS } from '../../../../next-server/lib/constants' import { TEMPORARY_REDIRECT_STATUS } from '../../../../shared/lib/constants'
import { NextConfig } from '../../../../next-server/server/config' import { NextConfig } from '../../../../next-server/server/config'
const getCustomRouteMatcher = pathMatch(true) const getCustomRouteMatcher = pathMatch(true)
......
...@@ -11,12 +11,12 @@ import { ...@@ -11,12 +11,12 @@ import {
CLIENT_STATIC_FILES_RUNTIME_POLYFILLS, CLIENT_STATIC_FILES_RUNTIME_POLYFILLS,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH, CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP, CLIENT_STATIC_FILES_RUNTIME_AMP,
} from '../../../next-server/lib/constants' } from '../../../shared/lib/constants'
import { BuildManifest } from '../../../next-server/server/get-page-files' import { BuildManifest } from '../../../next-server/server/get-page-files'
import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint' import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint'
import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin' import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin'
import { Rewrite } from '../../../lib/load-custom-routes' import { Rewrite } from '../../../lib/load-custom-routes'
import { getSortedRoutes } from '../../../next-server/lib/router/utils' import { getSortedRoutes } from '../../../shared/lib/router/utils'
import { spans } from './profiling-plugin' import { spans } from './profiling-plugin'
import { CustomRoutes } from '../../../lib/load-custom-routes' import { CustomRoutes } from '../../../lib/load-custom-routes'
......
...@@ -14,7 +14,7 @@ import minifier from 'cssnano-simple' ...@@ -14,7 +14,7 @@ import minifier from 'cssnano-simple'
import { import {
FONT_MANIFEST, FONT_MANIFEST,
OPTIMIZED_FONT_PROVIDERS, OPTIMIZED_FONT_PROVIDERS,
} from '../../../next-server/lib/constants' } from '../../../shared/lib/constants'
function minifyCss(css: string): Promise<string> { function minifyCss(css: string): Promise<string> {
return postcss([ return postcss([
......
import { webpack } from 'next/dist/compiled/webpack/webpack' import { webpack } from 'next/dist/compiled/webpack/webpack'
import { isWebpack5 } from 'next/dist/compiled/webpack/webpack' import { isWebpack5 } from 'next/dist/compiled/webpack/webpack'
import { STRING_LITERAL_DROP_BUNDLE } from '../../../next-server/lib/constants' import { STRING_LITERAL_DROP_BUNDLE } from '../../../shared/lib/constants'
export const ampFirstEntryNamesMap: WeakMap< export const ampFirstEntryNamesMap: WeakMap<
webpack.compilation.Compilation, webpack.compilation.Compilation,
......
...@@ -3,7 +3,7 @@ import { ...@@ -3,7 +3,7 @@ import {
isWebpack5, isWebpack5,
sources, sources,
} from 'next/dist/compiled/webpack/webpack' } from 'next/dist/compiled/webpack/webpack'
import { PAGES_MANIFEST } from '../../../next-server/lib/constants' import { PAGES_MANIFEST } from '../../../shared/lib/constants'
import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint' import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint'
export type PagesManifest = { [page: string]: string } export type PagesManifest = { [page: string]: string }
......
import { promises } from 'fs' import { promises } from 'fs'
import { join } from 'path' import { join } from 'path'
import { BUILD_ID_FILE } from '../next-server/lib/constants' import { BUILD_ID_FILE } from '../shared/lib/constants'
export async function writeBuildId( export async function writeBuildId(
distDir: string, distDir: string,
......
...@@ -10,7 +10,7 @@ import { runLintCheck } from '../lib/eslint/runLintCheck' ...@@ -10,7 +10,7 @@ import { runLintCheck } from '../lib/eslint/runLintCheck'
import { printAndExit } from '../server/lib/utils' import { printAndExit } from '../server/lib/utils'
import { Telemetry } from '../telemetry/storage' import { Telemetry } from '../telemetry/storage'
import loadConfig from '../next-server/server/config' import loadConfig from '../next-server/server/config'
import { PHASE_PRODUCTION_BUILD } from '../next-server/lib/constants' import { PHASE_PRODUCTION_BUILD } from '../shared/lib/constants'
import { eventLintCheckCompleted } from '../telemetry/events' import { eventLintCheckCompleted } from '../telemetry/events'
import { CompileError } from '../lib/compile-error' import { CompileError } from '../lib/compile-error'
......
import React from 'react' import React from 'react'
import Head from '../next-server/lib/head' import Head from '../shared/lib/head'
import { toBase64 } from '../next-server/lib/to-base-64' import { toBase64 } from '../shared/lib/to-base-64'
import { import {
ImageConfig, ImageConfig,
imageConfigDefault, imageConfigDefault,
......
...@@ -2,25 +2,20 @@ ...@@ -2,25 +2,20 @@
import '@next/polyfill-module' import '@next/polyfill-module'
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
import { HeadManagerContext } from '../next-server/lib/head-manager-context' import { HeadManagerContext } from '../shared/lib/head-manager-context'
import mitt, { MittEmitter } from '../next-server/lib/mitt' import mitt, { MittEmitter } from '../shared/lib/mitt'
import { RouterContext } from '../next-server/lib/router-context' import { RouterContext } from '../shared/lib/router-context'
import Router, { import Router, {
AppComponent, AppComponent,
AppProps, AppProps,
delBasePath, delBasePath,
hasBasePath, hasBasePath,
PrivateRouteInfo, PrivateRouteInfo,
} from '../next-server/lib/router/router' } from '../shared/lib/router/router'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import * as querystring from '../next-server/lib/router/utils/querystring' import * as querystring from '../shared/lib/router/utils/querystring'
import * as envConfig from '../next-server/lib/runtime-config' import * as envConfig from '../shared/lib/runtime-config'
import { import { getURL, loadGetInitialProps, NEXT_DATA, ST } from '../shared/lib/utils'
getURL,
loadGetInitialProps,
NEXT_DATA,
ST,
} from '../next-server/lib/utils'
import { Portal } from './portal' import { Portal } from './portal'
import initHeadManager from './head-manager' import initHeadManager from './head-manager'
import PageLoader, { StyleSheetTuple } from './page-loader' import PageLoader, { StyleSheetTuple } from './page-loader'
...@@ -99,19 +94,19 @@ if (hasBasePath(asPath)) { ...@@ -99,19 +94,19 @@ if (hasBasePath(asPath)) {
if (process.env.__NEXT_I18N_SUPPORT) { if (process.env.__NEXT_I18N_SUPPORT) {
const { const {
normalizeLocalePath, normalizeLocalePath,
} = require('../next-server/lib/i18n/normalize-locale-path') as typeof import('../next-server/lib/i18n/normalize-locale-path') } = require('../shared/lib/i18n/normalize-locale-path') as typeof import('../shared/lib/i18n/normalize-locale-path')
const { const {
detectDomainLocale, detectDomainLocale,
} = require('../next-server/lib/i18n/detect-domain-locale') as typeof import('../next-server/lib/i18n/detect-domain-locale') } = require('../shared/lib/i18n/detect-domain-locale') as typeof import('../shared/lib/i18n/detect-domain-locale')
const { const {
parseRelativeUrl, parseRelativeUrl,
} = require('../next-server/lib/router/utils/parse-relative-url') as typeof import('../next-server/lib/router/utils/parse-relative-url') } = require('../shared/lib/router/utils/parse-relative-url') as typeof import('../shared/lib/router/utils/parse-relative-url')
const { const {
formatUrl, formatUrl,
} = require('../next-server/lib/router/utils/format-url') as typeof import('../next-server/lib/router/utils/format-url') } = require('../shared/lib/router/utils/format-url') as typeof import('../shared/lib/router/utils/format-url')
if (locales) { if (locales) {
const parsedAs = parseRelativeUrl(asPath) const parsedAs = parseRelativeUrl(asPath)
......
...@@ -8,7 +8,7 @@ import { ...@@ -8,7 +8,7 @@ import {
NextRouter, NextRouter,
PrefetchOptions, PrefetchOptions,
resolveHref, resolveHref,
} from '../next-server/lib/router/router' } from '../shared/lib/router/router'
import { useRouter } from './router' import { useRouter } from './router'
import { useIntersection } from './use-intersection' import { useIntersection } from './use-intersection'
......
...@@ -6,7 +6,7 @@ import initWebpackHMR from './dev/webpack-hot-middleware-client' ...@@ -6,7 +6,7 @@ import initWebpackHMR from './dev/webpack-hot-middleware-client'
import initializeBuildWatcher from './dev/dev-build-watcher' import initializeBuildWatcher from './dev/dev-build-watcher'
import { displayContent } from './dev/fouc' import { displayContent } from './dev/fouc'
import { addMessageListener } from './dev/error-overlay/eventsource' import { addMessageListener } from './dev/error-overlay/eventsource'
import * as querystring from '../next-server/lib/router/utils/querystring' import * as querystring from '../shared/lib/router/utils/querystring'
// Temporary workaround for the issue described here: // Temporary workaround for the issue described here:
// https://github.com/vercel/next.js/issues/3775#issuecomment-407438123 // https://github.com/vercel/next.js/issues/3775#issuecomment-407438123
......
...@@ -4,10 +4,10 @@ import { ...@@ -4,10 +4,10 @@ import {
addBasePath, addBasePath,
addLocale, addLocale,
interpolateAs, interpolateAs,
} from '../next-server/lib/router/router' } from '../shared/lib/router/router'
import getAssetPathFromRoute from '../next-server/lib/router/utils/get-asset-path-from-route' import getAssetPathFromRoute from '../shared/lib/router/utils/get-asset-path-from-route'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import { parseRelativeUrl } from '../next-server/lib/router/utils/parse-relative-url' import { parseRelativeUrl } from '../shared/lib/router/utils/parse-relative-url'
import { removePathTrailingSlash } from './normalize-trailing-slash' import { removePathTrailingSlash } from './normalize-trailing-slash'
import createRouteLoader, { import createRouteLoader, {
getClientBuildManifest, getClientBuildManifest,
......
import { ComponentType } from 'react' import { ComponentType } from 'react'
import { ClientBuildManifest } from '../build/webpack/plugins/build-manifest-plugin' import { ClientBuildManifest } from '../build/webpack/plugins/build-manifest-plugin'
import getAssetPathFromRoute from '../next-server/lib/router/utils/get-asset-path-from-route' import getAssetPathFromRoute from '../shared/lib/router/utils/get-asset-path-from-route'
import { requestIdleCallback } from './request-idle-callback' import { requestIdleCallback } from './request-idle-callback'
// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive // 3.8s was arbitrarily chosen as it's what https://web.dev/interactive
......
/* global window */ /* global window */
import React from 'react' import React from 'react'
import Router, { NextRouter } from '../next-server/lib/router/router' import Router, { NextRouter } from '../shared/lib/router/router'
import { RouterContext } from '../next-server/lib/router-context' import { RouterContext } from '../shared/lib/router-context'
type ClassArguments<T> = T extends new (...args: infer U) => any ? U : any type ClassArguments<T> = T extends new (...args: infer U) => any ? U : any
......
import React, { useEffect, useContext } from 'react' import React, { useEffect, useContext } from 'react'
import { ScriptHTMLAttributes } from 'react' import { ScriptHTMLAttributes } from 'react'
import { HeadManagerContext } from '../next-server/lib/head-manager-context' import { HeadManagerContext } from '../shared/lib/head-manager-context'
import { DOMAttributeNames } from './head-manager' import { DOMAttributeNames } from './head-manager'
import { requestIdleCallback } from './request-idle-callback' import { requestIdleCallback } from './request-idle-callback'
......
import React from 'react' import React from 'react'
import { NextComponentType, NextPageContext } from '../next-server/lib/utils' import { NextComponentType, NextPageContext } from '../shared/lib/utils'
import { NextRouter, useRouter } from './router' import { NextRouter, useRouter } from './router'
export type WithRouterProps = { export type WithRouterProps = {
......
export * from './dist/next-server/lib/runtime-config' export * from './dist/shared/lib/runtime-config'
export { default } from './dist/next-server/lib/runtime-config' export { default } from './dist/shared/lib/runtime-config'
module.exports = require('./dist/next-server/lib/runtime-config') module.exports = require('./dist/shared/lib/runtime-config')
export * from './dist/next-server/lib/constants' export * from './dist/shared/lib/constants'
module.exports = require('./dist/next-server/lib/constants') module.exports = require('./dist/shared/lib/constants')
export * from './dist/next-server/lib/dynamic' export * from './dist/shared/lib/dynamic'
export { default } from './dist/next-server/lib/dynamic' export { default } from './dist/shared/lib/dynamic'
module.exports = require('./dist/next-server/lib/dynamic') module.exports = require('./dist/shared/lib/dynamic')
...@@ -28,7 +28,7 @@ import { ...@@ -28,7 +28,7 @@ import {
PRERENDER_MANIFEST, PRERENDER_MANIFEST,
SERVERLESS_DIRECTORY, SERVERLESS_DIRECTORY,
SERVER_DIRECTORY, SERVER_DIRECTORY,
} from '../next-server/lib/constants' } from '../shared/lib/constants'
import loadConfig, { import loadConfig, {
isTargetLikeServerless, isTargetLikeServerless,
NextConfig, NextConfig,
......
...@@ -4,9 +4,9 @@ import { renderToHTML } from '../next-server/server/render' ...@@ -4,9 +4,9 @@ import { renderToHTML } from '../next-server/server/render'
import { promises } from 'fs' import { promises } from 'fs'
import AmpHtmlValidator from 'next/dist/compiled/amphtml-validator' import AmpHtmlValidator from 'next/dist/compiled/amphtml-validator'
import { loadComponents } from '../next-server/server/load-components' import { loadComponents } from '../next-server/server/load-components'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic' import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import { getRouteMatcher } from '../next-server/lib/router/utils/route-matcher' import { getRouteMatcher } from '../shared/lib/router/utils/route-matcher'
import { getRouteRegex } from '../next-server/lib/router/utils/route-regex' import { getRouteRegex } from '../shared/lib/router/utils/route-regex'
import { normalizePagePath } from '../next-server/server/normalize-page-path' import { normalizePagePath } from '../next-server/server/normalize-page-path'
import { SERVER_PROPS_EXPORT_ERROR } from '../lib/constants' import { SERVER_PROPS_EXPORT_ERROR } from '../lib/constants'
import 'next/dist/next-server/server/node-polyfill-fetch' import 'next/dist/next-server/server/node-polyfill-fetch'
...@@ -15,11 +15,11 @@ import { ComponentType } from 'react' ...@@ -15,11 +15,11 @@ import { ComponentType } from 'react'
import { GetStaticProps } from '../types' import { GetStaticProps } from '../types'
import { requireFontManifest } from '../next-server/server/require' import { requireFontManifest } from '../next-server/server/require'
import { FontManifest } from '../next-server/server/font-utils' import { FontManifest } from '../next-server/server/font-utils'
import { normalizeLocalePath } from '../next-server/lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path'
import { trace } from '../telemetry/trace' import { trace } from '../telemetry/trace'
import { isInAmpMode } from '../next-server/lib/amp' import { isInAmpMode } from '../shared/lib/amp'
const envConfig = require('../next-server/lib/runtime-config') const envConfig = require('../shared/lib/runtime-config')
;(global as any).__NEXT_DATA__ = { ;(global as any).__NEXT_DATA__ = {
nextExport: true, nextExport: true,
......
export * from './dist/next-server/lib/head' export * from './dist/shared/lib/head'
export { default } from './dist/next-server/lib/head' export { default } from './dist/shared/lib/head'
module.exports = require('./dist/next-server/lib/head') module.exports = require('./dist/shared/lib/head')
...@@ -5,7 +5,7 @@ import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp' ...@@ -5,7 +5,7 @@ import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import { import {
PERMANENT_REDIRECT_STATUS, PERMANENT_REDIRECT_STATUS,
TEMPORARY_REDIRECT_STATUS, TEMPORARY_REDIRECT_STATUS,
} from '../next-server/lib/constants' } from '../shared/lib/constants'
export type RouteHas = export type RouteHas =
| { | {
......
...@@ -4,7 +4,11 @@ import { CookieSerializeOptions } from 'next/dist/compiled/cookie' ...@@ -4,7 +4,11 @@ import { CookieSerializeOptions } from 'next/dist/compiled/cookie'
import getRawBody from 'raw-body' import getRawBody from 'raw-body'
import { PageConfig, PreviewData } from 'next/types' import { PageConfig, PreviewData } from 'next/types'
import { Stream } from 'stream' import { Stream } from 'stream'
import { isResSent, NextApiRequest, NextApiResponse } from '../lib/utils' import {
isResSent,
NextApiRequest,
NextApiResponse,
} from '../../shared/lib/utils'
import { decryptWithSecret, encryptWithSecret } from './crypto-utils' import { decryptWithSecret, encryptWithSecret } from './crypto-utils'
import { interopDefault } from './load-components' import { interopDefault } from './load-components'
import { sendEtagResponse } from './send-payload' import { sendEtagResponse } from './send-payload'
......
import { loadEnvConfig } from '@next/env' import { loadEnvConfig } from '@next/env'
import findUp from 'next/dist/compiled/find-up' import findUp from 'next/dist/compiled/find-up'
import { init as initWebpack } from 'next/dist/compiled/webpack/webpack' import { init as initWebpack } from 'next/dist/compiled/webpack/webpack'
import { CONFIG_FILE, PHASE_DEVELOPMENT_SERVER } from '../lib/constants' import {
CONFIG_FILE,
PHASE_DEVELOPMENT_SERVER,
} from '../../shared/lib/constants'
import { NextConfig, normalizeConfig } from './config-shared' import { NextConfig, normalizeConfig } from './config-shared'
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
......
...@@ -3,7 +3,7 @@ import { Worker } from 'jest-worker' ...@@ -3,7 +3,7 @@ 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 { CheckReasons, CheckResult } from './config-utils-worker'
import { install, shouldLoadWithWebpack5 } from './config-utils-worker' import { install, shouldLoadWithWebpack5 } from './config-utils-worker'
import { PHASE_PRODUCTION_SERVER } from '../lib/constants' import { PHASE_PRODUCTION_SERVER } from '../../shared/lib/constants'
export { install, shouldLoadWithWebpack5 } export { install, shouldLoadWithWebpack5 }
......
...@@ -3,8 +3,11 @@ import findUp from 'next/dist/compiled/find-up' ...@@ -3,8 +3,11 @@ import findUp from 'next/dist/compiled/find-up'
import { basename, extname } from 'path' import { basename, extname } from 'path'
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
import { hasNextSupport } from '../../telemetry/ci-info' import { hasNextSupport } from '../../telemetry/ci-info'
import { CONFIG_FILE, PHASE_DEVELOPMENT_SERVER } from '../lib/constants' import {
import { execOnce } from '../lib/utils' CONFIG_FILE,
PHASE_DEVELOPMENT_SERVER,
} from '../../shared/lib/constants'
import { execOnce } from '../../shared/lib/utils'
import { defaultConfig, normalizeConfig } from './config-shared' import { defaultConfig, normalizeConfig } from './config-shared'
import { loadWebpackHook } from './config-utils' import { loadWebpackHook } from './config-utils'
import { ImageConfig, imageConfigDefault, VALID_LOADERS } from './image-config' import { ImageConfig, imageConfigDefault, VALID_LOADERS } from './image-config'
......
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
import { GOOGLE_FONT_PROVIDER } from '../lib/constants' import { GOOGLE_FONT_PROVIDER } from '../../shared/lib/constants'
const https = require('https') const https = require('https')
const CHROME_UA = const CHROME_UA =
......
import getRouteFromAssetPath from '../lib/router/utils/get-route-from-asset-path' import getRouteFromAssetPath from '../../shared/lib/router/utils/get-route-from-asset-path'
// matches pages/:page*.js // matches pages/:page*.js
const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/ const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/
......
...@@ -2,7 +2,7 @@ import { promises, readFileSync } from 'fs' ...@@ -2,7 +2,7 @@ import { promises, readFileSync } from 'fs'
import LRUCache from 'next/dist/compiled/lru-cache' import LRUCache from 'next/dist/compiled/lru-cache'
import path from 'path' import path from 'path'
import { PrerenderManifest } from '../../build' import { PrerenderManifest } from '../../build'
import { PRERENDER_MANIFEST } from '../lib/constants' import { PRERENDER_MANIFEST } from '../../shared/lib/constants'
import { normalizePagePath } from './normalize-page-path' import { normalizePagePath } from './normalize-page-path'
function toRoute(pathname: string): string { function toRoute(pathname: string): string {
......
import { Worker } from 'jest-worker' import { Worker } from 'jest-worker'
import * as path from 'path' import * as path from 'path'
import { execOnce } from '../../../lib/utils' import { execOnce } from '../../../../shared/lib/utils'
import { cpus } from 'os' import { cpus } from 'os'
type RotateOperation = { type RotateOperation = {
......
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from '../lib/constants' import {
BUILD_MANIFEST,
REACT_LOADABLE_MANIFEST,
} from '../../shared/lib/constants'
import { join } from 'path' import { join } from 'path'
import { requirePage } from './require' import { requirePage } from './require'
import { BuildManifest } from './get-page-files' import { BuildManifest } from './get-page-files'
import { AppType, DocumentType } from '../lib/utils' import { AppType, DocumentType } from '../../shared/lib/utils'
import { import {
PageConfig, PageConfig,
GetStaticPaths, GetStaticPaths,
......
...@@ -33,15 +33,19 @@ import { ...@@ -33,15 +33,19 @@ import {
SERVER_DIRECTORY, SERVER_DIRECTORY,
STATIC_STATUS_PAGES, STATIC_STATUS_PAGES,
TEMPORARY_REDIRECT_STATUS, TEMPORARY_REDIRECT_STATUS,
} from '../lib/constants' } from '../../shared/lib/constants'
import { import {
getRouteMatcher, getRouteMatcher,
getRouteRegex, getRouteRegex,
getSortedRoutes, getSortedRoutes,
isDynamicRoute, isDynamicRoute,
} from '../lib/router/utils' } from '../../shared/lib/router/utils'
import * as envConfig from '../lib/runtime-config' import * as envConfig from '../../shared/lib/runtime-config'
import { isResSent, NextApiRequest, NextApiResponse } from '../lib/utils' import {
isResSent,
NextApiRequest,
NextApiResponse,
} from '../../shared/lib/utils'
import { import {
apiResolver, apiResolver,
setLazyProp, setLazyProp,
...@@ -50,7 +54,7 @@ import { ...@@ -50,7 +54,7 @@ import {
__ApiPreviewProps, __ApiPreviewProps,
} from './api-utils' } from './api-utils'
import { DomainLocales, isTargetLikeServerless, NextConfig } from './config' import { DomainLocales, isTargetLikeServerless, NextConfig } from './config'
import pathMatch from '../lib/router/utils/path-match' import pathMatch from '../../shared/lib/router/utils/path-match'
import { recursiveReadDirSync } from './lib/recursive-readdir-sync' import { recursiveReadDirSync } from './lib/recursive-readdir-sync'
import { loadComponents, LoadComponentsReturnType } from './load-components' import { loadComponents, LoadComponentsReturnType } from './load-components'
import { normalizePagePath } from './normalize-page-path' import { normalizePagePath } from './normalize-page-path'
...@@ -65,27 +69,27 @@ import Router, { ...@@ -65,27 +69,27 @@ import Router, {
} from './router' } from './router'
import prepareDestination, { import prepareDestination, {
compileNonPath, compileNonPath,
} from '../lib/router/utils/prepare-destination' } from '../../shared/lib/router/utils/prepare-destination'
import { sendPayload, setRevalidateHeaders } from './send-payload' import { sendPayload, setRevalidateHeaders } from './send-payload'
import { serveStatic } from './serve-static' import { serveStatic } from './serve-static'
import { IncrementalCache } from './incremental-cache' import { IncrementalCache } from './incremental-cache'
import { execOnce } from '../lib/utils' import { execOnce } from '../../shared/lib/utils'
import { isBlockedPage } from './utils' import { isBlockedPage } from './utils'
import { loadEnvConfig } from '@next/env' import { loadEnvConfig } from '@next/env'
import './node-polyfill-fetch' import './node-polyfill-fetch'
import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin' import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin'
import { removePathTrailingSlash } from '../../client/normalize-trailing-slash' import { removePathTrailingSlash } from '../../client/normalize-trailing-slash'
import getRouteFromAssetPath from '../lib/router/utils/get-route-from-asset-path' import getRouteFromAssetPath from '../../shared/lib/router/utils/get-route-from-asset-path'
import { FontManifest } from './font-utils' import { FontManifest } from './font-utils'
import { denormalizePagePath } from './denormalize-page-path' import { denormalizePagePath } from './denormalize-page-path'
import accept from '@hapi/accept' import accept from '@hapi/accept'
import { normalizeLocalePath } from '../lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
import { detectLocaleCookie } from '../lib/i18n/detect-locale-cookie' import { detectLocaleCookie } from '../../shared/lib/i18n/detect-locale-cookie'
import * as Log from '../../build/output/log' import * as Log from '../../build/output/log'
import { imageOptimizer } from './image-optimizer' import { imageOptimizer } from './image-optimizer'
import { detectDomainLocale } from '../lib/i18n/detect-domain-locale' import { detectDomainLocale } from '../../shared/lib/i18n/detect-domain-locale'
import cookie from 'next/dist/compiled/cookie' import cookie from 'next/dist/compiled/cookie'
import escapePathDelimiters from '../lib/router/utils/escape-path-delimiters' import escapePathDelimiters from '../../shared/lib/router/utils/escape-path-delimiters'
import { getUtils } from '../../build/webpack/loaders/next-serverless-loader/utils' import { getUtils } from '../../build/webpack/loaders/next-serverless-loader/utils'
import { PreviewData } from 'next/types' import { PreviewData } from 'next/types'
......
...@@ -16,22 +16,22 @@ import { ...@@ -16,22 +16,22 @@ import {
} from '../../lib/constants' } from '../../lib/constants'
import { isSerializableProps } from '../../lib/is-serializable-props' import { isSerializableProps } from '../../lib/is-serializable-props'
import { GetServerSideProps, GetStaticProps, PreviewData } from '../../types' import { GetServerSideProps, GetStaticProps, PreviewData } from '../../types'
import { isInAmpMode } from '../lib/amp' import { isInAmpMode } from '../../shared/lib/amp'
import { AmpStateContext } from '../lib/amp-context' import { AmpStateContext } from '../../shared/lib/amp-context'
import { import {
AMP_RENDER_TARGET, AMP_RENDER_TARGET,
SERVER_PROPS_ID, SERVER_PROPS_ID,
STATIC_PROPS_ID, STATIC_PROPS_ID,
STATIC_STATUS_PAGES, STATIC_STATUS_PAGES,
} from '../lib/constants' } from '../../shared/lib/constants'
import { defaultHead } from '../lib/head' import { defaultHead } from '../../shared/lib/head'
import { HeadManagerContext } from '../lib/head-manager-context' import { HeadManagerContext } from '../../shared/lib/head-manager-context'
import Loadable from '../lib/loadable' import Loadable from '../../shared/lib/loadable'
import { LoadableContext } from '../lib/loadable-context' import { LoadableContext } from '../../shared/lib/loadable-context'
import postProcess from '../lib/post-process' import postProcess from '../../shared/lib/post-process'
import { RouterContext } from '../lib/router-context' import { RouterContext } from '../../shared/lib/router-context'
import { NextRouter } from '../lib/router/router' import { NextRouter } from '../../shared/lib/router/router'
import { isDynamicRoute } from '../lib/router/utils/is-dynamic' import { isDynamicRoute } from '../../shared/lib/router/utils/is-dynamic'
import { import {
AppType, AppType,
ComponentsEnhancer, ComponentsEnhancer,
...@@ -43,7 +43,7 @@ import { ...@@ -43,7 +43,7 @@ import {
loadGetInitialProps, loadGetInitialProps,
NextComponentType, NextComponentType,
RenderPage, RenderPage,
} from '../lib/utils' } from '../../shared/lib/utils'
import { import {
tryGetPreviewData, tryGetPreviewData,
NextApiRequestCookies, NextApiRequestCookies,
......
...@@ -5,10 +5,10 @@ import { ...@@ -5,10 +5,10 @@ import {
SERVER_DIRECTORY, SERVER_DIRECTORY,
SERVERLESS_DIRECTORY, SERVERLESS_DIRECTORY,
FONT_MANIFEST, FONT_MANIFEST,
} from '../lib/constants' } from '../../shared/lib/constants'
import { normalizePagePath, denormalizePagePath } from './normalize-page-path' import { normalizePagePath, denormalizePagePath } from './normalize-page-path'
import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin' import { PagesManifest } from '../../build/webpack/plugins/pages-manifest-plugin'
import { normalizeLocalePath } from '../lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
export function pageNotFoundError(page: string): Error { export function pageNotFoundError(page: string): Error {
const err: any = new Error(`Cannot find module for page: ${page}`) const err: any = new Error(`Cannot find module for page: ${page}`)
......
import { IncomingMessage, ServerResponse } from 'http' import { IncomingMessage, ServerResponse } from 'http'
import { UrlWithParsedQuery } from 'url' import { UrlWithParsedQuery } from 'url'
import pathMatch from '../lib/router/utils/path-match' import pathMatch from '../../shared/lib/router/utils/path-match'
import { removePathTrailingSlash } from '../../client/normalize-trailing-slash' import { removePathTrailingSlash } from '../../client/normalize-trailing-slash'
import { normalizeLocalePath } from '../lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
import { RouteHas } from '../../lib/load-custom-routes' import { RouteHas } from '../../lib/load-custom-routes'
import { matchHas } from '../lib/router/utils/prepare-destination' import { matchHas } from '../../shared/lib/router/utils/prepare-destination'
export const route = pathMatch() export const route = pathMatch()
......
import { IncomingMessage, ServerResponse } from 'http' import { IncomingMessage, ServerResponse } from 'http'
import { isResSent } from '../lib/utils' import { isResSent } from '../../shared/lib/utils'
import generateETag from 'etag' import generateETag from 'etag'
import fresh from 'next/dist/compiled/fresh' import fresh from 'next/dist/compiled/fresh'
......
import { BLOCKED_PAGES } from '../lib/constants' import { BLOCKED_PAGES } from '../../shared/lib/constants'
export function isBlockedPage(pathname: string): boolean { export function isBlockedPage(pathname: string): boolean {
return BLOCKED_PAGES.includes(pathname) return BLOCKED_PAGES.includes(pathname)
......
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
AppInitialProps, AppInitialProps,
AppPropsType, AppPropsType,
NextWebVitalsMetric, NextWebVitalsMetric,
} from '../next-server/lib/utils' } from '../shared/lib/utils'
import { Router } from '../client/router' import { Router } from '../client/router'
export { AppInitialProps } export { AppInitialProps }
......
...@@ -4,13 +4,13 @@ import flush from 'styled-jsx/server' ...@@ -4,13 +4,13 @@ import flush from 'styled-jsx/server'
import { import {
AMP_RENDER_TARGET, AMP_RENDER_TARGET,
OPTIMIZED_FONT_PROVIDERS, OPTIMIZED_FONT_PROVIDERS,
} from '../next-server/lib/constants' } from '../shared/lib/constants'
import { DocumentContext as DocumentComponentContext } from '../next-server/lib/document-context' import { DocumentContext as DocumentComponentContext } from '../shared/lib/document-context'
import { import {
DocumentContext, DocumentContext,
DocumentInitialProps, DocumentInitialProps,
DocumentProps, DocumentProps,
} from '../next-server/lib/utils' } from '../shared/lib/utils'
import { import {
BuildManifest, BuildManifest,
getPageFiles, getPageFiles,
......
import React from 'react' import React from 'react'
import Head from '../next-server/lib/head' import Head from '../shared/lib/head'
import { NextPageContext } from '../next-server/lib/utils' import { NextPageContext } from '../shared/lib/utils'
const statusCodes: { [code: number]: string } = { const statusCodes: { [code: number]: string } = {
400: 'Bad Request', 400: 'Bad Request',
......
...@@ -10,7 +10,7 @@ import { watchCompilers } from '../build/output' ...@@ -10,7 +10,7 @@ import { watchCompilers } from '../build/output'
import getBaseWebpackConfig from '../build/webpack-config' import getBaseWebpackConfig from '../build/webpack-config'
import { API_ROUTE } from '../lib/constants' import { API_ROUTE } from '../lib/constants'
import { recursiveDelete } from '../lib/recursive-delete' import { recursiveDelete } from '../lib/recursive-delete'
import { BLOCKED_PAGES } from '../next-server/lib/constants' import { BLOCKED_PAGES } from '../shared/lib/constants'
import { __ApiPreviewProps } from '../next-server/server/api-utils' import { __ApiPreviewProps } from '../next-server/server/api-utils'
import { route } from '../next-server/server/router' import { route } from '../next-server/server/router'
import { findPageFile } from './lib/find-page-file' import { findPageFile } from './lib/find-page-file'
......
...@@ -18,13 +18,13 @@ import { ...@@ -18,13 +18,13 @@ import {
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
CLIENT_STATIC_FILES_PATH, CLIENT_STATIC_FILES_PATH,
DEV_CLIENT_PAGES_MANIFEST, DEV_CLIENT_PAGES_MANIFEST,
} from '../next-server/lib/constants' } from '../shared/lib/constants'
import { import {
getRouteMatcher, getRouteMatcher,
getRouteRegex, getRouteRegex,
getSortedRoutes, getSortedRoutes,
isDynamicRoute, isDynamicRoute,
} from '../next-server/lib/router/utils' } from '../shared/lib/router/utils'
import { __ApiPreviewProps } from '../next-server/server/api-utils' import { __ApiPreviewProps } from '../next-server/server/api-utils'
import Server, { import Server, {
WrappedBuildError, WrappedBuildError,
......
...@@ -10,7 +10,7 @@ import { resolve } from 'path' ...@@ -10,7 +10,7 @@ import { resolve } from 'path'
import { import {
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_SERVER, PHASE_PRODUCTION_SERVER,
} from '../next-server/lib/constants' } from '../shared/lib/constants'
import { IncomingMessage, ServerResponse } from 'http' import { IncomingMessage, ServerResponse } from 'http'
import { UrlWithParsedQuery } from 'url' import { UrlWithParsedQuery } from 'url'
......
...@@ -24,7 +24,7 @@ export async function loadStaticPaths( ...@@ -24,7 +24,7 @@ export async function loadStaticPaths(
} }
// update work memory runtime-config // update work memory runtime-config
require('./../next-server/lib/runtime-config').setConfig(config) require('../shared/lib/runtime-config').setConfig(config)
const components = await loadComponents(distDir, pathname, serverless) const components = await loadComponents(distDir, pathname, serverless)
......
...@@ -13,8 +13,8 @@ import { ...@@ -13,8 +13,8 @@ import {
markAssetError, markAssetError,
} from '../../../client/route-loader' } from '../../../client/route-loader'
import { RouterEvent } from '../../../client/router' import { RouterEvent } from '../../../client/router'
import { DomainLocales } from '../../server/config' import { DomainLocales } from '../../../next-server/server/config'
import { denormalizePagePath } from '../../server/denormalize-page-path' import { denormalizePagePath } from '../../../next-server/server/denormalize-page-path'
import { normalizeLocalePath } from '../i18n/normalize-locale-path' import { normalizeLocalePath } from '../i18n/normalize-locale-path'
import mitt, { MittEmitter } from '../mitt' import mitt, { MittEmitter } from '../mitt'
import { import {
......
...@@ -5,14 +5,10 @@ import { UrlObject } from 'url' ...@@ -5,14 +5,10 @@ import { UrlObject } from 'url'
import { formatUrl } from './router/utils/format-url' import { formatUrl } from './router/utils/format-url'
import { NextRouter } from './router/router' import { NextRouter } from './router/router'
import { Env } from '@next/env' import { Env } from '@next/env'
import { BuildManifest } from '../server/get-page-files' import { BuildManifest } from '../../next-server/server/get-page-files'
import { DomainLocales } from '../server/config' import { DomainLocales } from '../../next-server/server/config'
import { PreviewData } from 'next/types' import { PreviewData } from 'next/types'
/**
* Types used by both next and next-server
*/
export type NextComponentType< export type NextComponentType<
C extends BaseContext = NextPageContext, C extends BaseContext = NextPageContext,
IP = {}, IP = {},
......
...@@ -809,6 +809,7 @@ export async function compile(task, opts) { ...@@ -809,6 +809,7 @@ export async function compile(task, opts) {
'client', 'client',
'telemetry', 'telemetry',
'nextserver', 'nextserver',
'shared',
'nextserver_wasm', 'nextserver_wasm',
// we compile this each time so that fresh runtime data is pulled // we compile this each time so that fresh runtime data is pulled
// before each publish // before each publish
...@@ -926,6 +927,7 @@ export default async function (task) { ...@@ -926,6 +927,7 @@ export default async function (task) {
await task.watch('cli/**/*.+(js|ts|tsx)', 'cli', opts) await task.watch('cli/**/*.+(js|ts|tsx)', 'cli', opts)
await task.watch('telemetry/**/*.+(js|ts|tsx)', 'telemetry', opts) await task.watch('telemetry/**/*.+(js|ts|tsx)', 'telemetry', opts)
await task.watch('next-server/**/*.+(js|ts|tsx)', 'nextserver', 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) await task.watch('next-server/**/*.+(wasm)', 'nextserver_wasm', opts)
} }
...@@ -937,6 +939,14 @@ export async function nextserver(task, opts) { ...@@ -937,6 +939,14 @@ export async function nextserver(task, opts) {
notify('Compiled server files') notify('Compiled server files')
} }
export async function shared(task, opts) {
await task
.source(opts.src || 'shared/**/*.+(js|ts|tsx)')
.babel('server', { dev: opts.dev })
.target('dist/shared')
notify('Compiled shared files')
}
export async function nextserver_wasm(task, opts) { export async function nextserver_wasm(task, opts) {
await task await task
.source(opts.src || 'next-server/**/*.+(wasm)') .source(opts.src || 'next-server/**/*.+(wasm)')
......
...@@ -5,7 +5,7 @@ import { ...@@ -5,7 +5,7 @@ import {
PHASE_DEVELOPMENT_SERVER, PHASE_DEVELOPMENT_SERVER,
PHASE_EXPORT, PHASE_EXPORT,
PHASE_PRODUCTION_BUILD, PHASE_PRODUCTION_BUILD,
} from '../../next-server/lib/constants' } from '../../shared/lib/constants'
import { normalizeConfig } from '../../next-server/server/config' import { normalizeConfig } from '../../next-server/server/config'
const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED' const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED'
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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