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

This commit is contained in:
Tim Neutkens 2021-06-30 11:43:31 +02:00 committed by GitHub
parent f5958fdc4f
commit 136b754396
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
110 changed files with 192 additions and 182 deletions

View file

@ -1 +1 @@
export * from './dist/next-server/lib/amp'
export * from './dist/shared/lib/amp'

View file

@ -1 +1 @@
module.exports = require('./dist/next-server/lib/amp')
module.exports = require('./dist/shared/lib/amp')

View file

@ -118,7 +118,7 @@ commands[command]()
})
if (command === 'dev') {
const { CONFIG_FILE } = require('../next-server/lib/constants')
const { CONFIG_FILE } = require('../shared/lib/constants')
const { watchFile } = require('fs')
watchFile(`${process.cwd()}/${CONFIG_FILE}`, (cur: any, prev: any) => {
if (cur.size > 0 || prev.size > 0) {

View file

@ -8,7 +8,7 @@ import { NextBabelLoaderOptions, NextJsLoaderContext } from './types'
import { consumeIterator } from './util'
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

View file

@ -1,8 +1,8 @@
import { NodePath, PluginObj, types } from 'next/dist/compiled/babel/core'
import commonjsPlugin from 'next/dist/compiled/babel/plugin-transform-modules-commonjs'
// Rewrite imports using next/<something> to next-server/<something>
export default function NextToNextServer(...args: any): PluginObj {
// Handle module.exports in user code
export default function CommonJSModulePlugin(...args: any): PluginObj {
const commonjs = commonjsPlugin(...args)
return {
visitor: {

View file

@ -6,7 +6,7 @@ import {
Visitor,
} from 'next/dist/compiled/babel/core'
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'

View file

@ -4,10 +4,7 @@ import {
types as BabelTypes,
} from 'next/dist/compiled/babel/core'
import { SERVER_PROPS_SSG_CONFLICT } from '../../../lib/constants'
import {
SERVER_PROPS_ID,
STATIC_PROPS_ID,
} from '../../../next-server/lib/constants'
import { SERVER_PROPS_ID, STATIC_PROPS_ID } from '../../../shared/lib/constants'
export const EXPORT_NAME_GET_STATIC_PROPS = 'getStaticProps'
export const EXPORT_NAME_GET_STATIC_PATHS = 'getStaticPaths'

View file

@ -45,12 +45,12 @@ import {
SERVER_DIRECTORY,
SERVER_FILES_MANIFEST,
STATIC_STATUS_PAGES,
} from '../next-server/lib/constants'
} from '../shared/lib/constants'
import {
getRouteRegex,
getSortedRoutes,
isDynamicRoute,
} from '../next-server/lib/router/utils'
} from '../shared/lib/router/utils'
import { __ApiPreviewProps } from '../next-server/server/api-utils'
import loadConfig, {
isTargetLikeServerless,
@ -89,7 +89,7 @@ import {
import getBaseWebpackConfig from './webpack-config'
import { PagesManifest } from './webpack/plugins/pages-manifest-plugin'
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'
const staticCheckWorker = require.resolve('./utils')

View file

@ -19,16 +19,16 @@ import {
} from '../lib/constants'
import prettyBytes from '../lib/pretty-bytes'
import { recursiveReadDir } from '../lib/recursive-readdir'
import { getRouteMatcher, getRouteRegex } from '../next-server/lib/router/utils'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
import escapePathDelimiters from '../next-server/lib/router/utils/escape-path-delimiters'
import { getRouteMatcher, getRouteRegex } from '../shared/lib/router/utils'
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 { removePathTrailingSlash } from '../client/normalize-trailing-slash'
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 { loadComponents } from '../next-server/server/load-components'
import { trace } from '../telemetry/trace'
@ -765,7 +765,7 @@ export async function isPageStatic(
const isPageStaticSpan = trace('is-page-static-utils', parentId)
return isPageStaticSpan.traceAsyncFn(async () => {
try {
require('../next-server/lib/runtime-config').setConfig(runtimeEnvConfig)
require('../shared/lib/runtime-config').setConfig(runtimeEnvConfig)
const components = await loadComponents(distDir, page, serverless)
const mod = components.ComponentMod
const Comp = mod.default || mod
@ -880,7 +880,7 @@ export async function hasCustomGetInitialProps(
runtimeEnvConfig: any,
checkingApp: 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)
let mod = components.ComponentMod
@ -900,7 +900,7 @@ export async function getNamedExports(
isLikeServerless: boolean,
runtimeEnvConfig: any
): 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)
let mod = components.ComponentMod

View file

@ -25,8 +25,8 @@ import {
REACT_LOADABLE_MANIFEST,
SERVERLESS_DIRECTORY,
SERVER_DIRECTORY,
} from '../next-server/lib/constants'
import { execOnce } from '../next-server/lib/utils'
} from '../shared/lib/constants'
import { execOnce } from '../shared/lib/utils'
import { NextConfig } from '../next-server/server/config'
import { findPageFile } from '../server/lib/find-page-file'
import { WebpackEntrypoints } from './entries'
@ -305,7 +305,7 @@ export default async function getBaseWebpackConfig(
}
const babelIncludeRegexes: RegExp[] = [
/next[\\/]dist[\\/]next-server[\\/]lib/,
/next[\\/]dist[\\/]shared[\\/]lib/,
/next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/,
/[\\/](strip-ansi|ansi-regex)[\\/]/,
@ -396,10 +396,10 @@ export default async function getBaseWebpackConfig(
}
const clientResolveRewrites = require.resolve(
'../next-server/lib/router/utils/resolve-rewrites'
'../shared/lib/router/utils/resolve-rewrites'
)
const clientResolveRewritesNoop = require.resolve(
'../next-server/lib/router/utils/resolve-rewrites-noop'
'../shared/lib/router/utils/resolve-rewrites-noop'
)
const resolveConfig = {
@ -676,11 +676,7 @@ export default async function getBaseWebpackConfig(
// are relative to requests we've already resolved here.
// Absolute requires (require('/foo')) are extremely uncommon, but
// also have no need for customization as they're already resolved.
if (isLocal) {
if (!/[/\\]next-server[/\\]/.test(request)) {
return
}
} else {
if (!isLocal) {
if (/^(?:next$|react(?:$|\/))/.test(request)) {
return `commonjs ${request}`
}
@ -713,9 +709,10 @@ export default async function getBaseWebpackConfig(
}
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
const isNextExternal = /next[/\\]dist[/\\]next-server[/\\](?!lib[/\\]router[/\\]router)/.test(
const isNextExternal = /next[/\\]dist[/\\](shared|next-server)[/\\](?!lib[/\\]router[/\\]router)/.test(
res
)
@ -761,9 +758,7 @@ export default async function getBaseWebpackConfig(
}
if (
res.match(
/next[/\\]dist[/\\]next-server[/\\](?!lib[/\\]router[/\\]router)/
)
res.match(/next[/\\]dist[/\\]shared[/\\](?!lib[/\\]router[/\\]router)/)
) {
return `commonjs ${request}`
}
@ -1193,7 +1188,7 @@ export default async function getBaseWebpackConfig(
!dev &&
new webpack.IgnorePlugin({
resourceRegExp: /react-is/,
contextRegExp: /(next-server|next)[\\/]dist[\\/]/,
contextRegExp: /next[\\/]dist[\\/]/,
}),
isServerless && isServer && new ServerlessPlugin(),
isServer &&

View file

@ -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 || []),
{
test: [
/next[\\/]dist[\\/]next-server[\\/]lib/,
/next[\\/]dist[\\/]shared[\\/]lib/,
/next[\\/]dist[\\/]client/,
/next[\\/]dist[\\/]pages/,
],

View file

@ -4,13 +4,13 @@ import { join } from 'path'
import { parse } from 'querystring'
import { webpack } from 'next/dist/compiled/webpack/webpack'
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 {
BUILD_MANIFEST,
ROUTES_MANIFEST,
REACT_LOADABLE_MANIFEST,
} from '../../../../next-server/lib/constants'
} from '../../../../shared/lib/constants'
import { trace } from '../../../../telemetry/trace'
export type ServerlessLoaderQuery = {

View file

@ -1,6 +1,6 @@
import { IncomingMessage, ServerResponse } from 'http'
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 { getUtils, vercelHeader, ServerlessHandlerCtx } from './utils'
@ -12,8 +12,8 @@ import {
getCookieParser,
} from '../../../../next-server/server/api-utils'
import { getRedirectStatus } from '../../../../lib/load-custom-routes'
import getRouteNoAssetPath from '../../../../next-server/lib/router/utils/get-route-from-asset-path'
import { PERMANENT_REDIRECT_STATUS } from '../../../../next-server/lib/constants'
import getRouteNoAssetPath from '../../../../shared/lib/router/utils/get-route-from-asset-path'
import { PERMANENT_REDIRECT_STATUS } from '../../../../shared/lib/constants'
export function getPageHandler(ctx: ServerlessHandlerCtx) {
const {

View file

@ -2,13 +2,13 @@ import { IncomingMessage, ServerResponse } from 'http'
import { format as formatUrl, UrlWithParsedQuery, parse as parseUrl } from 'url'
import { parse as parseQs, ParsedUrlQuery } from 'querystring'
import { Rewrite } from '../../../../lib/load-custom-routes'
import { normalizeLocalePath } from '../../../../next-server/lib/i18n/normalize-locale-path'
import pathMatch from '../../../../next-server/lib/router/utils/path-match'
import { getRouteRegex } from '../../../../next-server/lib/router/utils/route-regex'
import { getRouteMatcher } from '../../../../next-server/lib/router/utils/route-matcher'
import { normalizeLocalePath } from '../../../../shared/lib/i18n/normalize-locale-path'
import pathMatch from '../../../../shared/lib/router/utils/path-match'
import { getRouteRegex } from '../../../../shared/lib/router/utils/route-regex'
import { getRouteMatcher } from '../../../../shared/lib/router/utils/route-matcher'
import prepareDestination, {
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 { BuildManifest } from '../../../../next-server/server/get-page-files'
import {
@ -17,11 +17,11 @@ import {
GetStaticProps,
} from '../../../../types'
import accept from '@hapi/accept'
import { detectLocaleCookie } from '../../../../next-server/lib/i18n/detect-locale-cookie'
import { detectDomainLocale } from '../../../../next-server/lib/i18n/detect-domain-locale'
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 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'
const getCustomRouteMatcher = pathMatch(true)

View file

@ -11,12 +11,12 @@ import {
CLIENT_STATIC_FILES_RUNTIME_POLYFILLS,
CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,
CLIENT_STATIC_FILES_RUNTIME_AMP,
} from '../../../next-server/lib/constants'
} from '../../../shared/lib/constants'
import { BuildManifest } from '../../../next-server/server/get-page-files'
import getRouteFromEntrypoint from '../../../next-server/server/get-route-from-entrypoint'
import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin'
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 { CustomRoutes } from '../../../lib/load-custom-routes'

View file

@ -14,7 +14,7 @@ import minifier from 'cssnano-simple'
import {
FONT_MANIFEST,
OPTIMIZED_FONT_PROVIDERS,
} from '../../../next-server/lib/constants'
} from '../../../shared/lib/constants'
function minifyCss(css: string): Promise<string> {
return postcss([

View file

@ -1,6 +1,6 @@
import { webpack } 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<
webpack.compilation.Compilation,

View file

@ -3,7 +3,7 @@ import {
isWebpack5,
sources,
} 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'
export type PagesManifest = { [page: string]: string }

View file

@ -1,6 +1,6 @@
import { promises } from 'fs'
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(
distDir: string,

View file

@ -10,7 +10,7 @@ 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 { PHASE_PRODUCTION_BUILD } from '../next-server/lib/constants'
import { PHASE_PRODUCTION_BUILD } from '../shared/lib/constants'
import { eventLintCheckCompleted } from '../telemetry/events'
import { CompileError } from '../lib/compile-error'

View file

@ -1,6 +1,6 @@
import React from 'react'
import Head from '../next-server/lib/head'
import { toBase64 } from '../next-server/lib/to-base-64'
import Head from '../shared/lib/head'
import { toBase64 } from '../shared/lib/to-base-64'
import {
ImageConfig,
imageConfigDefault,

View file

@ -2,25 +2,20 @@
import '@next/polyfill-module'
import React from 'react'
import ReactDOM from 'react-dom'
import { HeadManagerContext } from '../next-server/lib/head-manager-context'
import mitt, { MittEmitter } from '../next-server/lib/mitt'
import { RouterContext } from '../next-server/lib/router-context'
import { HeadManagerContext } from '../shared/lib/head-manager-context'
import mitt, { MittEmitter } from '../shared/lib/mitt'
import { RouterContext } from '../shared/lib/router-context'
import Router, {
AppComponent,
AppProps,
delBasePath,
hasBasePath,
PrivateRouteInfo,
} from '../next-server/lib/router/router'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
import * as querystring from '../next-server/lib/router/utils/querystring'
import * as envConfig from '../next-server/lib/runtime-config'
import {
getURL,
loadGetInitialProps,
NEXT_DATA,
ST,
} from '../next-server/lib/utils'
} from '../shared/lib/router/router'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import * as querystring from '../shared/lib/router/utils/querystring'
import * as envConfig from '../shared/lib/runtime-config'
import { getURL, loadGetInitialProps, NEXT_DATA, ST } from '../shared/lib/utils'
import { Portal } from './portal'
import initHeadManager from './head-manager'
import PageLoader, { StyleSheetTuple } from './page-loader'
@ -99,19 +94,19 @@ if (hasBasePath(asPath)) {
if (process.env.__NEXT_I18N_SUPPORT) {
const {
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 {
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 {
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 {
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) {
const parsedAs = parseRelativeUrl(asPath)

View file

@ -8,7 +8,7 @@ import {
NextRouter,
PrefetchOptions,
resolveHref,
} from '../next-server/lib/router/router'
} from '../shared/lib/router/router'
import { useRouter } from './router'
import { useIntersection } from './use-intersection'

View file

@ -6,7 +6,7 @@ import initWebpackHMR from './dev/webpack-hot-middleware-client'
import initializeBuildWatcher from './dev/dev-build-watcher'
import { displayContent } from './dev/fouc'
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:
// https://github.com/vercel/next.js/issues/3775#issuecomment-407438123

View file

@ -4,10 +4,10 @@ import {
addBasePath,
addLocale,
interpolateAs,
} from '../next-server/lib/router/router'
import getAssetPathFromRoute from '../next-server/lib/router/utils/get-asset-path-from-route'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
import { parseRelativeUrl } from '../next-server/lib/router/utils/parse-relative-url'
} from '../shared/lib/router/router'
import getAssetPathFromRoute from '../shared/lib/router/utils/get-asset-path-from-route'
import { isDynamicRoute } from '../shared/lib/router/utils/is-dynamic'
import { parseRelativeUrl } from '../shared/lib/router/utils/parse-relative-url'
import { removePathTrailingSlash } from './normalize-trailing-slash'
import createRouteLoader, {
getClientBuildManifest,

View file

@ -1,6 +1,6 @@
import { ComponentType } from 'react'
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'
// 3.8s was arbitrarily chosen as it's what https://web.dev/interactive

View file

@ -1,7 +1,7 @@
/* global window */
import React from 'react'
import Router, { NextRouter } from '../next-server/lib/router/router'
import { RouterContext } from '../next-server/lib/router-context'
import Router, { NextRouter } from '../shared/lib/router/router'
import { RouterContext } from '../shared/lib/router-context'
type ClassArguments<T> = T extends new (...args: infer U) => any ? U : any

View file

@ -1,6 +1,6 @@
import React, { useEffect, useContext } 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 { requestIdleCallback } from './request-idle-callback'

View file

@ -1,5 +1,5 @@
import React from 'react'
import { NextComponentType, NextPageContext } from '../next-server/lib/utils'
import { NextComponentType, NextPageContext } from '../shared/lib/utils'
import { NextRouter, useRouter } from './router'
export type WithRouterProps = {

View file

@ -1,2 +1,2 @@
export * from './dist/next-server/lib/runtime-config'
export { default } from './dist/next-server/lib/runtime-config'
export * from './dist/shared/lib/runtime-config'
export { default } from './dist/shared/lib/runtime-config'

View file

@ -1 +1 @@
module.exports = require('./dist/next-server/lib/runtime-config')
module.exports = require('./dist/shared/lib/runtime-config')

View file

@ -1 +1 @@
export * from './dist/next-server/lib/constants'
export * from './dist/shared/lib/constants'

View file

@ -1 +1 @@
module.exports = require('./dist/next-server/lib/constants')
module.exports = require('./dist/shared/lib/constants')

View file

@ -1,2 +1,2 @@
export * from './dist/next-server/lib/dynamic'
export { default } from './dist/next-server/lib/dynamic'
export * from './dist/shared/lib/dynamic'
export { default } from './dist/shared/lib/dynamic'

View file

@ -1 +1 @@
module.exports = require('./dist/next-server/lib/dynamic')
module.exports = require('./dist/shared/lib/dynamic')

View file

@ -28,7 +28,7 @@ import {
PRERENDER_MANIFEST,
SERVERLESS_DIRECTORY,
SERVER_DIRECTORY,
} from '../next-server/lib/constants'
} from '../shared/lib/constants'
import loadConfig, {
isTargetLikeServerless,
NextConfig,

View file

@ -4,9 +4,9 @@ import { renderToHTML } from '../next-server/server/render'
import { promises } from 'fs'
import AmpHtmlValidator from 'next/dist/compiled/amphtml-validator'
import { loadComponents } from '../next-server/server/load-components'
import { isDynamicRoute } from '../next-server/lib/router/utils/is-dynamic'
import { getRouteMatcher } from '../next-server/lib/router/utils/route-matcher'
import { getRouteRegex } from '../next-server/lib/router/utils/route-regex'
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 { SERVER_PROPS_EXPORT_ERROR } from '../lib/constants'
import 'next/dist/next-server/server/node-polyfill-fetch'
@ -15,11 +15,11 @@ import { ComponentType } from 'react'
import { GetStaticProps } from '../types'
import { requireFontManifest } from '../next-server/server/require'
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 { 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__ = {
nextExport: true,

View file

@ -1,2 +1,2 @@
export * from './dist/next-server/lib/head'
export { default } from './dist/next-server/lib/head'
export * from './dist/shared/lib/head'
export { default } from './dist/shared/lib/head'

View file

@ -1 +1 @@
module.exports = require('./dist/next-server/lib/head')
module.exports = require('./dist/shared/lib/head')

View file

@ -5,7 +5,7 @@ import escapeStringRegexp from 'next/dist/compiled/escape-string-regexp'
import {
PERMANENT_REDIRECT_STATUS,
TEMPORARY_REDIRECT_STATUS,
} from '../next-server/lib/constants'
} from '../shared/lib/constants'
export type RouteHas =
| {

View file

@ -4,7 +4,11 @@ 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 '../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'

View file

@ -1,7 +1,10 @@
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 '../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'

View file

@ -3,7 +3,7 @@ import { Worker } from 'jest-worker'
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 '../lib/constants'
import { PHASE_PRODUCTION_SERVER } from '../../shared/lib/constants'
export { install, shouldLoadWithWebpack5 }

View file

@ -3,8 +3,11 @@ 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 '../lib/constants'
import { execOnce } from '../lib/utils'
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'

View file

@ -1,5 +1,5 @@
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 CHROME_UA =

View file

@ -1,4 +1,4 @@
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
const SERVER_ROUTE_NAME_REGEX = /^pages[/\\](.*)$/

View file

@ -2,7 +2,7 @@ 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 '../lib/constants'
import { PRERENDER_MANIFEST } from '../../shared/lib/constants'
import { normalizePagePath } from './normalize-page-path'
function toRoute(pathname: string): string {

View file

@ -1,6 +1,6 @@
import { Worker } from 'jest-worker'
import * as path from 'path'
import { execOnce } from '../../../lib/utils'
import { execOnce } from '../../../../shared/lib/utils'
import { cpus } from 'os'
type RotateOperation = {

View file

@ -1,8 +1,11 @@
import { BUILD_MANIFEST, REACT_LOADABLE_MANIFEST } from '../lib/constants'
import {
BUILD_MANIFEST,
REACT_LOADABLE_MANIFEST,
} from '../../shared/lib/constants'
import { join } from 'path'
import { requirePage } from './require'
import { BuildManifest } from './get-page-files'
import { AppType, DocumentType } from '../lib/utils'
import { AppType, DocumentType } from '../../shared/lib/utils'
import {
PageConfig,
GetStaticPaths,

View file

@ -33,15 +33,19 @@ import {
SERVER_DIRECTORY,
STATIC_STATUS_PAGES,
TEMPORARY_REDIRECT_STATUS,
} from '../lib/constants'
} from '../../shared/lib/constants'
import {
getRouteMatcher,
getRouteRegex,
getSortedRoutes,
isDynamicRoute,
} from '../lib/router/utils'
import * as envConfig from '../lib/runtime-config'
import { isResSent, NextApiRequest, NextApiResponse } from '../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,
@ -50,7 +54,7 @@ import {
__ApiPreviewProps,
} from './api-utils'
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 { loadComponents, LoadComponentsReturnType } from './load-components'
import { normalizePagePath } from './normalize-page-path'
@ -65,27 +69,27 @@ import Router, {
} from './router'
import prepareDestination, {
compileNonPath,
} from '../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 '../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 '../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 { denormalizePagePath } from './denormalize-page-path'
import accept from '@hapi/accept'
import { normalizeLocalePath } from '../lib/i18n/normalize-locale-path'
import { detectLocaleCookie } from '../lib/i18n/detect-locale-cookie'
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 '../lib/i18n/detect-domain-locale'
import { detectDomainLocale } from '../../shared/lib/i18n/detect-domain-locale'
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 { PreviewData } from 'next/types'

View file

@ -16,22 +16,22 @@ import {
} from '../../lib/constants'
import { isSerializableProps } from '../../lib/is-serializable-props'
import { GetServerSideProps, GetStaticProps, PreviewData } from '../../types'
import { isInAmpMode } from '../lib/amp'
import { AmpStateContext } from '../lib/amp-context'
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 '../lib/constants'
import { defaultHead } from '../lib/head'
import { HeadManagerContext } from '../lib/head-manager-context'
import Loadable from '../lib/loadable'
import { LoadableContext } from '../lib/loadable-context'
import postProcess from '../lib/post-process'
import { RouterContext } from '../lib/router-context'
import { NextRouter } from '../lib/router/router'
import { isDynamicRoute } from '../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 '../lib/utils'
} from '../../shared/lib/utils'
import {
tryGetPreviewData,
NextApiRequestCookies,

View file

@ -5,10 +5,10 @@ import {
SERVER_DIRECTORY,
SERVERLESS_DIRECTORY,
FONT_MANIFEST,
} from '../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 '../lib/i18n/normalize-locale-path'
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}`)

View file

@ -1,11 +1,11 @@
import { IncomingMessage, ServerResponse } from 'http'
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 { normalizeLocalePath } from '../lib/i18n/normalize-locale-path'
import { normalizeLocalePath } from '../../shared/lib/i18n/normalize-locale-path'
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()

View file

@ -1,5 +1,5 @@
import { IncomingMessage, ServerResponse } from 'http'
import { isResSent } from '../lib/utils'
import { isResSent } from '../../shared/lib/utils'
import generateETag from 'etag'
import fresh from 'next/dist/compiled/fresh'

View file

@ -1,4 +1,4 @@
import { BLOCKED_PAGES } from '../lib/constants'
import { BLOCKED_PAGES } from '../../shared/lib/constants'
export function isBlockedPage(pathname: string): boolean {
return BLOCKED_PAGES.includes(pathname)

View file

@ -5,7 +5,7 @@ import {
AppInitialProps,
AppPropsType,
NextWebVitalsMetric,
} from '../next-server/lib/utils'
} from '../shared/lib/utils'
import { Router } from '../client/router'
export { AppInitialProps }

View file

@ -4,13 +4,13 @@ import flush from 'styled-jsx/server'
import {
AMP_RENDER_TARGET,
OPTIMIZED_FONT_PROVIDERS,
} from '../next-server/lib/constants'
import { DocumentContext as DocumentComponentContext } from '../next-server/lib/document-context'
} from '../shared/lib/constants'
import { DocumentContext as DocumentComponentContext } from '../shared/lib/document-context'
import {
DocumentContext,
DocumentInitialProps,
DocumentProps,
} from '../next-server/lib/utils'
} from '../shared/lib/utils'
import {
BuildManifest,
getPageFiles,

View file

@ -1,6 +1,6 @@
import React from 'react'
import Head from '../next-server/lib/head'
import { NextPageContext } from '../next-server/lib/utils'
import Head from '../shared/lib/head'
import { NextPageContext } from '../shared/lib/utils'
const statusCodes: { [code: number]: string } = {
400: 'Bad Request',

View file

@ -10,7 +10,7 @@ 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 '../next-server/lib/constants'
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'

View file

@ -18,13 +18,13 @@ import {
PHASE_DEVELOPMENT_SERVER,
CLIENT_STATIC_FILES_PATH,
DEV_CLIENT_PAGES_MANIFEST,
} from '../next-server/lib/constants'
} from '../shared/lib/constants'
import {
getRouteMatcher,
getRouteRegex,
getSortedRoutes,
isDynamicRoute,
} from '../next-server/lib/router/utils'
} from '../shared/lib/router/utils'
import { __ApiPreviewProps } from '../next-server/server/api-utils'
import Server, {
WrappedBuildError,

View file

@ -10,7 +10,7 @@ import { resolve } from 'path'
import {
PHASE_DEVELOPMENT_SERVER,
PHASE_PRODUCTION_SERVER,
} from '../next-server/lib/constants'
} from '../shared/lib/constants'
import { IncomingMessage, ServerResponse } from 'http'
import { UrlWithParsedQuery } from 'url'

View file

@ -24,7 +24,7 @@ export async function loadStaticPaths(
}
// 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)

View file

@ -13,8 +13,8 @@ import {
markAssetError,
} from '../../../client/route-loader'
import { RouterEvent } from '../../../client/router'
import { DomainLocales } from '../../server/config'
import { denormalizePagePath } from '../../server/denormalize-page-path'
import { DomainLocales } from '../../../next-server/server/config'
import { denormalizePagePath } from '../../../next-server/server/denormalize-page-path'
import { normalizeLocalePath } from '../i18n/normalize-locale-path'
import mitt, { MittEmitter } from '../mitt'
import {

View file

@ -5,14 +5,10 @@ import { UrlObject } from 'url'
import { formatUrl } from './router/utils/format-url'
import { NextRouter } from './router/router'
import { Env } from '@next/env'
import { BuildManifest } from '../server/get-page-files'
import { DomainLocales } from '../server/config'
import { BuildManifest } from '../../next-server/server/get-page-files'
import { DomainLocales } from '../../next-server/server/config'
import { PreviewData } from 'next/types'
/**
* Types used by both next and next-server
*/
export type NextComponentType<
C extends BaseContext = NextPageContext,
IP = {},

View file

@ -809,6 +809,7 @@ export async function compile(task, opts) {
'client',
'telemetry',
'nextserver',
'shared',
'nextserver_wasm',
// we compile this each time so that fresh runtime data is pulled
// before each publish
@ -926,6 +927,7 @@ export default async function (task) {
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)
}
@ -937,6 +939,14 @@ export async function nextserver(task, opts) {
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) {
await task
.source(opts.src || 'next-server/**/*.+(wasm)')

View file

@ -5,7 +5,7 @@ import {
PHASE_DEVELOPMENT_SERVER,
PHASE_EXPORT,
PHASE_PRODUCTION_BUILD,
} from '../../next-server/lib/constants'
} from '../../shared/lib/constants'
import { normalizeConfig } from '../../next-server/server/config'
const EVENT_VERSION = 'NEXT_CLI_SESSION_STARTED'

Some files were not shown because too many files have changed in this diff Show more