From e8535140bd92cd24dc01b2e28f3c57b08c1fd9bb Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Fri, 27 Jan 2023 14:18:00 +0100 Subject: [PATCH 1/9] refactor webpack build out of build/index --- packages/next/src/build/index.ts | 262 ++++------------------- packages/next/src/build/webpack-build.ts | 232 ++++++++++++++++++++ 2 files changed, 276 insertions(+), 218 deletions(-) create mode 100644 packages/next/src/build/webpack-build.ts diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 9fa7078aba25c..ce0261927f747 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -12,7 +12,6 @@ import findUp from 'next/dist/compiled/find-up' import { nanoid } from 'next/dist/compiled/nanoid/index.cjs' import { pathToRegexp } from 'next/dist/compiled/path-to-regexp' import path from 'path' -import formatWebpackMessages from '../client/dev/error-overlay/format-webpack-messages' import { STATIC_STATUS_PAGE_GET_INITIAL_PROPS_ERROR, PUBLIC_DIR_MIDDLEWARE_CONFLICT, @@ -53,13 +52,10 @@ import { MIDDLEWARE_MANIFEST, APP_PATHS_MANIFEST, APP_PATH_ROUTES_MANIFEST, - COMPILER_NAMES, APP_BUILD_MANIFEST, FLIGHT_SERVER_CSS_MANIFEST, RSC_MODULE_TYPES, FONT_LOADER_MANIFEST, - CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, - APP_CLIENT_INTERNALS, SUBRESOURCE_INTEGRITY_MANIFEST, MIDDLEWARE_BUILD_MANIFEST, MIDDLEWARE_REACT_LOADABLE_MANIFEST, @@ -72,7 +68,6 @@ import { normalizePagePath } from '../shared/lib/page-path/normalize-page-path' import { getPagePath } from '../server/require' import * as ciEnvironment from '../telemetry/ci-info' import { - eventBuildCompleted, eventBuildOptimize, eventCliSession, eventBuildFeatureUsage, @@ -81,16 +76,16 @@ import { EVENT_BUILD_FEATURE_USAGE, EventBuildFeatureUsage, eventPackageUsedInGetServerSideProps, + eventBuildCompleted, } from '../telemetry/events' import { Telemetry } from '../telemetry/storage' -import { runCompiler } from './compiler' import { getPageStaticInfo } from './analysis/get-page-static-info' import { createEntrypoints, createPagesMapping } from './entries' import { generateBuildId } from './generate-build-id' import { isWriteable } from './is-writeable' import * as Log from './output/log' import createSpinner from './spinner' -import { trace, flushAllTraces, setGlobal } from '../trace' +import { trace, flushAllTraces, setGlobal, Span } from '../trace' import { detectConflictingPaths, computeFromManifest, @@ -102,7 +97,6 @@ import { isReservedPage, AppConfig, } from './utils' -import getBaseWebpackConfig from './webpack-config' import { PagesManifest } from './webpack/plugins/pages-manifest-plugin' import { writeBuildId } from './write-build-id' import { normalizeLocalePath } from '../shared/lib/i18n/normalize-locale-path' @@ -119,7 +113,6 @@ import { teardownCrashReporter, loadBindings, } from './swc' -import { injectedClientEntries } from './webpack/plugins/flight-client-entry-plugin' import { getNamedRouteRegex } from '../shared/lib/router/utils/route-regex' import { flatReaddir } from '../lib/flat-readdir' import { RemotePattern } from '../shared/lib/image-config' @@ -127,6 +120,8 @@ import { eventSwcPlugins } from '../telemetry/events/swc-plugins' import { normalizeAppPath } from '../shared/lib/router/utils/app-paths' import { AppBuildManifest } from './webpack/plugins/app-build-manifest-plugin' import { RSC, RSC_VARY_HEADER } from '../client/components/app-router-headers' +import { webpackBuild } from './webpack-build' +import { Ora } from 'next/dist/compiled/ora' export type SsgRoute = { initialRevalidateSeconds: number | false @@ -149,17 +144,18 @@ export type PrerenderManifest = { preview: __ApiPreviewProps } -type CompilerResult = { - errors: webpack.StatsError[] - warnings: webpack.StatsError[] - stats: (webpack.Stats | undefined)[] -} - -type SingleCompilerResult = { - errors: webpack.StatsError[] - warnings: webpack.StatsError[] - stats: webpack.Stats | undefined -} +export const NextBuildContext: Partial<{ + telemetryPlugin: TelemetryPlugin + buildSpinner: Ora + nextBuildSpan: Span + entrypoints: { + client: webpack.EntryObject + server: webpack.EntryObject + edgeServer: webpack.EntryObject + middlewareMatchers: undefined + } + dir: string +}> = {} /** * typescript will be loaded in "next/lib/verifyTypeScriptSetup" and @@ -240,10 +236,6 @@ function generateClientSsgManifest( ) } -function isTelemetryPlugin(plugin: unknown): plugin is TelemetryPlugin { - return plugin instanceof TelemetryPlugin -} - function pageToRoute(page: string) { const routeRegex = getNamedRouteRegex(page) return { @@ -266,6 +258,8 @@ export default async function build( const nextBuildSpan = trace('next-build', undefined, { version: process.env.__NEXT_VERSION as string, }) + NextBuildContext.nextBuildSpan = nextBuildSpan + NextBuildContext.dir = dir const buildResult = await nextBuildSpan.traceAsyncFn(async () => { // attempt to load global env values so they are available in next.config.js @@ -306,6 +300,7 @@ export default async function build( } const telemetry = new Telemetry({ distDir }) + setGlobal('telemetry', telemetry) const publicDir = path.join(dir, 'public') @@ -481,6 +476,8 @@ export default async function build( prefixText: `${Log.prefixes.info} Creating an optimized production build`, }) + NextBuildContext.buildSpinner = buildSpinner + const pagesPaths = pagesDir ? await nextBuildSpan .traceChild('collect-pages') @@ -584,6 +581,7 @@ export default async function build( pageExtensions: config.pageExtensions, }) ) + NextBuildContext.entrypoints = entrypoints const pagesPageKeys = Object.keys(mappedPages) @@ -947,199 +945,24 @@ export default async function build( ignore: [] as string[], })) - let result: CompilerResult = { - warnings: [], - errors: [], - stats: [], - } - let webpackBuildStart - let telemetryPlugin - await (async () => { - // IIFE to isolate locals and avoid retaining memory too long - const runWebpackSpan = nextBuildSpan.traceChild('run-webpack-compiler') - - const commonWebpackOptions = { - buildId, - config, - pagesDir, - reactProductionProfiling, - rewrites, - runWebpackSpan, - target, - appDir, - noMangling, - middlewareMatchers: entrypoints.middlewareMatchers, - } - - const configs = await runWebpackSpan - .traceChild('generate-webpack-config') - .traceAsyncFn(() => - Promise.all([ - getBaseWebpackConfig(dir, { - ...commonWebpackOptions, - compilerType: COMPILER_NAMES.client, - entrypoints: entrypoints.client, - }), - getBaseWebpackConfig(dir, { - ...commonWebpackOptions, - compilerType: COMPILER_NAMES.server, - entrypoints: entrypoints.server, - }), - getBaseWebpackConfig(dir, { - ...commonWebpackOptions, - compilerType: COMPILER_NAMES.edgeServer, - entrypoints: entrypoints.edgeServer, - }), - ]) - ) - - const clientConfig = configs[0] - - if ( - clientConfig.optimization && - (clientConfig.optimization.minimize !== true || - (clientConfig.optimization.minimizer && - clientConfig.optimization.minimizer.length === 0)) - ) { - Log.warn( - `Production code optimization has been disabled in your project. Read more: https://nextjs.org/docs/messages/minification-disabled` - ) - } - - webpackBuildStart = process.hrtime() - - // We run client and server compilation separately to optimize for memory usage - await runWebpackSpan.traceAsyncFn(async () => { - // Run the server compilers first and then the client - // compiler to track the boundary of server/client components. - let clientResult: SingleCompilerResult | null = null - - // During the server compilations, entries of client components will be - // injected to this set and then will be consumed by the client compiler. - injectedClientEntries.clear() - - const serverResult = await runCompiler(configs[1], { - runWebpackSpan, - }) - const edgeServerResult = configs[2] - ? await runCompiler(configs[2], { runWebpackSpan }) - : null - - // Only continue if there were no errors - if (!serverResult.errors.length && !edgeServerResult?.errors.length) { - injectedClientEntries.forEach((value, key) => { - const clientEntry = clientConfig.entry as webpack.EntryObject - if (key === APP_CLIENT_INTERNALS) { - clientEntry[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP] = [ - // TODO-APP: cast clientEntry[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP] to type EntryDescription once it's available from webpack - // @ts-expect-error clientEntry['main-app'] is type EntryDescription { import: ... } - ...clientEntry[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP].import, - value, - ] - } else { - clientEntry[key] = { - dependOn: [CLIENT_STATIC_FILES_RUNTIME_MAIN_APP], - import: value, - } - } - }) - - clientResult = await runCompiler(clientConfig, { - runWebpackSpan, - }) - } + const webpackBuildDuration = await webpackBuild({ + buildId, + config, + pagesDir, + reactProductionProfiling, + rewrites, + target, + appDir, + noMangling, + middlewareMatchers: entrypoints.middlewareMatchers, + }) - result = { - warnings: ([] as any[]) - .concat( - clientResult?.warnings, - serverResult?.warnings, - edgeServerResult?.warnings - ) - .filter(nonNullable), - errors: ([] as any[]) - .concat( - clientResult?.errors, - serverResult?.errors, - edgeServerResult?.errors - ) - .filter(nonNullable), - stats: [ - clientResult?.stats, - serverResult?.stats, - edgeServerResult?.stats, - ], - } + telemetry.record( + eventBuildCompleted(pagesPaths, { + durationInSeconds: webpackBuildDuration, + totalAppPagesCount, }) - result = nextBuildSpan - .traceChild('format-webpack-messages') - .traceFn(() => formatWebpackMessages(result, true)) - - telemetryPlugin = (clientConfig as webpack.Configuration).plugins?.find( - isTelemetryPlugin - ) - })() - const webpackBuildEnd = process.hrtime(webpackBuildStart) - if (buildSpinner) { - buildSpinner.stopAndPersist() - } - - if (result.errors.length > 0) { - // Only keep the first few errors. Others are often indicative - // of the same problem, but confuse the reader with noise. - if (result.errors.length > 5) { - result.errors.length = 5 - } - let error = result.errors.filter(Boolean).join('\n\n') - - console.error(chalk.red('Failed to compile.\n')) - - if ( - error.indexOf('private-next-pages') > -1 && - error.indexOf('does not contain a default export') > -1 - ) { - const page_name_regex = /'private-next-pages\/(?[^']*)'/ - const parsed = page_name_regex.exec(error) - const page_name = parsed && parsed.groups && parsed.groups.page_name - throw new Error( - `webpack build failed: found page without a React Component as default export in pages/${page_name}\n\nSee https://nextjs.org/docs/messages/page-without-valid-component for more info.` - ) - } - - console.error(error) - console.error() - - if ( - error.indexOf('private-next-pages') > -1 || - error.indexOf('__next_polyfill__') > -1 - ) { - const err = new Error( - 'webpack config.resolve.alias was incorrectly overridden. https://nextjs.org/docs/messages/invalid-resolve-alias' - ) as NextError - err.code = 'INVALID_RESOLVE_ALIAS' - throw err - } - const err = new Error( - 'Build failed because of webpack errors' - ) as NextError - err.code = 'WEBPACK_ERRORS' - throw err - } else { - telemetry.record( - eventBuildCompleted(pagesPaths, { - durationInSeconds: webpackBuildEnd[0], - totalAppPagesCount, - }) - ) - - if (result.warnings.length > 0) { - Log.warn('Compiled with warnings\n') - console.warn(result.warnings.filter(Boolean).join('\n\n')) - console.warn() - } else { - Log.info('Compiled successfully') - } - } + ) // For app directory, we run type checking after build. if (appDir) { @@ -2735,10 +2558,12 @@ export default async function build( }) ) - if (telemetryPlugin) { - const events = eventBuildFeatureUsage(telemetryPlugin) + if (NextBuildContext.telemetryPlugin) { + const events = eventBuildFeatureUsage(NextBuildContext.telemetryPlugin) telemetry.record(events) - telemetry.record(eventPackageUsedInGetServerSideProps(telemetryPlugin)) + telemetry.record( + eventPackageUsedInGetServerSideProps(NextBuildContext.telemetryPlugin) + ) } if (ssgPages.size > 0 || appDir) { @@ -2935,6 +2760,7 @@ export default async function build( .traceChild('telemetry-flush') .traceAsyncFn(() => telemetry.flush()) }) + debugger return buildResult } finally { // Ensure we wait for lockfile patching if present diff --git a/packages/next/src/build/webpack-build.ts b/packages/next/src/build/webpack-build.ts new file mode 100644 index 0000000000000..3060199c9ad8b --- /dev/null +++ b/packages/next/src/build/webpack-build.ts @@ -0,0 +1,232 @@ +import type { webpack } from 'next/dist/compiled/webpack/webpack' +import chalk from 'next/dist/compiled/chalk' +import formatWebpackMessages from '../client/dev/error-overlay/format-webpack-messages' +import { nonNullable } from '../lib/non-nullable' +import { + COMPILER_NAMES, + CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, + APP_CLIENT_INTERNALS, +} from '../shared/lib/constants' +import { __ApiPreviewProps } from '../server/api-utils' +import { runCompiler } from './compiler' +import * as Log from './output/log' +import getBaseWebpackConfig from './webpack-config' +import { NextError } from '../lib/is-error' +import { injectedClientEntries } from './webpack/plugins/flight-client-entry-plugin' +import { TelemetryPlugin } from './webpack/plugins/telemetry-plugin' +import { Rewrite } from '../lib/load-custom-routes' +import { NextConfigComplete } from '../server/config-shared' +import { MiddlewareMatcher } from './analysis/get-page-static-info' +import { NextBuildContext } from '.' + +type CompilerResult = { + errors: webpack.StatsError[] + warnings: webpack.StatsError[] + stats: (webpack.Stats | undefined)[] +} + +type SingleCompilerResult = { + errors: webpack.StatsError[] + warnings: webpack.StatsError[] + stats: webpack.Stats | undefined +} + +function isTelemetryPlugin(plugin: unknown): plugin is TelemetryPlugin { + return plugin instanceof TelemetryPlugin +} + +export async function webpackBuild(commonWebpackOptions: { + buildId: string + config: NextConfigComplete + pagesDir: string | undefined + reactProductionProfiling: boolean + rewrites: { + fallback: Rewrite[] + afterFiles: Rewrite[] + beforeFiles: Rewrite[] + } + target: string + appDir: string | undefined + noMangling: boolean + middlewareMatchers: MiddlewareMatcher[] | undefined +}): Promise { + let result: CompilerResult | null = { + warnings: [], + errors: [], + stats: [], + } + let webpackBuildStart + const nextBuildSpan = NextBuildContext.nextBuildSpan! + const buildSpinner = NextBuildContext.buildSpinner + const dir = NextBuildContext.dir! + await (async () => { + // IIFE to isolate locals and avoid retaining memory too long + const runWebpackSpan = nextBuildSpan.traceChild('run-webpack-compiler') + + const entrypoints = NextBuildContext.entrypoints! + const configs = await runWebpackSpan + .traceChild('generate-webpack-config') + .traceAsyncFn(() => + Promise.all([ + getBaseWebpackConfig(dir, { + ...commonWebpackOptions, + runWebpackSpan, + compilerType: COMPILER_NAMES.client, + entrypoints: entrypoints.client, + }), + getBaseWebpackConfig(dir, { + ...commonWebpackOptions, + runWebpackSpan, + compilerType: COMPILER_NAMES.server, + entrypoints: entrypoints.server, + }), + getBaseWebpackConfig(dir, { + ...commonWebpackOptions, + runWebpackSpan, + compilerType: COMPILER_NAMES.edgeServer, + entrypoints: entrypoints.edgeServer, + }), + ]) + ) + + const clientConfig = configs[0] + + if ( + clientConfig.optimization && + (clientConfig.optimization.minimize !== true || + (clientConfig.optimization.minimizer && + clientConfig.optimization.minimizer.length === 0)) + ) { + Log.warn( + `Production code optimization has been disabled in your project. Read more: https://nextjs.org/docs/messages/minification-disabled` + ) + } + + webpackBuildStart = process.hrtime() + + // We run client and server compilation separately to optimize for memory usage + await runWebpackSpan.traceAsyncFn(async () => { + // Run the server compilers first and then the client + // compiler to track the boundary of server/client components. + let clientResult: SingleCompilerResult | null = null + + // During the server compilations, entries of client components will be + // injected to this set and then will be consumed by the client compiler. + injectedClientEntries.clear() + + const serverResult = await runCompiler(configs[1], { + runWebpackSpan, + }) + const edgeServerResult = configs[2] + ? await runCompiler(configs[2], { runWebpackSpan }) + : null + + // Only continue if there were no errors + if (!serverResult.errors.length && !edgeServerResult?.errors.length) { + injectedClientEntries.forEach((value, key) => { + const clientEntry = clientConfig.entry as webpack.EntryObject + if (key === APP_CLIENT_INTERNALS) { + clientEntry[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP] = [ + // TODO-APP: cast clientEntry[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP] to type EntryDescription once it's available from webpack + // @ts-expect-error clientEntry['main-app'] is type EntryDescription { import: ... } + ...clientEntry[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP].import, + value, + ] + } else { + clientEntry[key] = { + dependOn: [CLIENT_STATIC_FILES_RUNTIME_MAIN_APP], + import: value, + } + } + }) + + clientResult = await runCompiler(clientConfig, { + runWebpackSpan, + }) + } + + result = { + warnings: ([] as any[]) + .concat( + clientResult?.warnings, + serverResult?.warnings, + edgeServerResult?.warnings + ) + .filter(nonNullable), + errors: ([] as any[]) + .concat( + clientResult?.errors, + serverResult?.errors, + edgeServerResult?.errors + ) + .filter(nonNullable), + stats: [ + clientResult?.stats, + serverResult?.stats, + edgeServerResult?.stats, + ], + } + }) + result = nextBuildSpan + .traceChild('format-webpack-messages') + .traceFn(() => formatWebpackMessages(result, true)) + + NextBuildContext.telemetryPlugin = ( + clientConfig as webpack.Configuration + ).plugins?.find(isTelemetryPlugin) + })() + + const webpackBuildEnd = process.hrtime(webpackBuildStart) + if (buildSpinner) { + buildSpinner.stopAndPersist() + } + + if (result.errors.length > 0) { + // Only keep the first few errors. Others are often indicative + // of the same problem, but confuse the reader with noise. + if (result.errors.length > 5) { + result.errors.length = 5 + } + let error = result.errors.filter(Boolean).join('\n\n') + + console.error(chalk.red('Failed to compile.\n')) + + if ( + error.indexOf('private-next-pages') > -1 && + error.indexOf('does not contain a default export') > -1 + ) { + const page_name_regex = /'private-next-pages\/(?[^']*)'/ + const parsed = page_name_regex.exec(error) + const page_name = parsed && parsed.groups && parsed.groups.page_name + throw new Error( + `webpack build failed: found page without a React Component as default export in pages/${page_name}\n\nSee https://nextjs.org/docs/messages/page-without-valid-component for more info.` + ) + } + + console.error(error) + console.error() + + if ( + error.indexOf('private-next-pages') > -1 || + error.indexOf('__next_polyfill__') > -1 + ) { + const err = new Error( + 'webpack config.resolve.alias was incorrectly overridden. https://nextjs.org/docs/messages/invalid-resolve-alias' + ) as NextError + err.code = 'INVALID_RESOLVE_ALIAS' + throw err + } + const err = new Error('Build failed because of webpack errors') as NextError + err.code = 'WEBPACK_ERRORS' + throw err + } else { + if (result.warnings.length > 0) { + Log.warn('Compiled with warnings\n') + console.warn(result.warnings.filter(Boolean).join('\n\n')) + console.warn() + } else { + Log.info('Compiled successfully') + } + return webpackBuildEnd[0] + } +} From c36d40330d7ca40810985c5dc3561efd27e6d176 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Fri, 27 Jan 2023 14:52:56 +0100 Subject: [PATCH 2/9] remove debugger --- packages/next/src/build/index.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index ce0261927f747..bf23617b5bb0a 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -2760,7 +2760,6 @@ export default async function build( .traceChild('telemetry-flush') .traceAsyncFn(() => telemetry.flush()) }) - debugger return buildResult } finally { // Ensure we wait for lockfile patching if present From 25cb709288913bd7139063fe40188647ac859e49 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Fri, 27 Jan 2023 17:22:18 +0100 Subject: [PATCH 3/9] lint --- packages/next/src/build/webpack-build.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/next/src/build/webpack-build.ts b/packages/next/src/build/webpack-build.ts index 3060199c9ad8b..6ddc7d3594361 100644 --- a/packages/next/src/build/webpack-build.ts +++ b/packages/next/src/build/webpack-build.ts @@ -7,7 +7,6 @@ import { CLIENT_STATIC_FILES_RUNTIME_MAIN_APP, APP_CLIENT_INTERNALS, } from '../shared/lib/constants' -import { __ApiPreviewProps } from '../server/api-utils' import { runCompiler } from './compiler' import * as Log from './output/log' import getBaseWebpackConfig from './webpack-config' From 36afd0a643be066dda3d0046a645a6a91940717d Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Tue, 31 Jan 2023 19:25:55 +0100 Subject: [PATCH 4/9] fix merge artifact --- packages/next/src/build/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index a540377c22a35..115e049fc29ed 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -478,6 +478,8 @@ export default async function build( prefixText: `${Log.prefixes.info} Creating an optimized production build`, }) + NextBuildContext.buildSpinner = buildSpinner + const pagesPaths = !appDirOnly && pagesDir ? await nextBuildSpan From a067380f9a944fbe15a45458573d48aabe7b5590 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Tue, 31 Jan 2023 19:38:15 +0100 Subject: [PATCH 5/9] fix types --- packages/next/types/compiled.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/next/types/compiled.d.ts b/packages/next/types/compiled.d.ts index 1f5bf8303af88..6bd6c25af9861 100644 --- a/packages/next/types/compiled.d.ts +++ b/packages/next/types/compiled.d.ts @@ -19,3 +19,7 @@ declare module 'next/dist/compiled/webpack/webpack' { export const NormalModule: any export const ResolvePluginInstance: any } + +declare module 'next/dist/compiled/ora/ora' { + export const Ora: any +} From cd5783a26e04a804773a2ff1d14e8d080b8fbf10 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Wed, 1 Feb 2023 11:14:17 +0100 Subject: [PATCH 6/9] fix types --- packages/next/types/compiled.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/types/compiled.d.ts b/packages/next/types/compiled.d.ts index 6bd6c25af9861..8accf21c5e108 100644 --- a/packages/next/types/compiled.d.ts +++ b/packages/next/types/compiled.d.ts @@ -20,6 +20,6 @@ declare module 'next/dist/compiled/webpack/webpack' { export const ResolvePluginInstance: any } -declare module 'next/dist/compiled/ora/ora' { +declare module 'next/dist/compiled/ora' { export const Ora: any } From ee785940431903dc60064b5768888025b0b6b3fc Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Wed, 1 Feb 2023 11:40:42 +0100 Subject: [PATCH 7/9] fix types --- packages/next/types/compiled.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/types/compiled.d.ts b/packages/next/types/compiled.d.ts index 8accf21c5e108..73ab661cb79da 100644 --- a/packages/next/types/compiled.d.ts +++ b/packages/next/types/compiled.d.ts @@ -20,6 +20,6 @@ declare module 'next/dist/compiled/webpack/webpack' { export const ResolvePluginInstance: any } -declare module 'next/dist/compiled/ora' { +declare module 'next/dist/compiled/ora/index' { export const Ora: any } From c17cbd4e27268a781743bb9f6863446af1a4b990 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Wed, 1 Feb 2023 14:31:27 +0100 Subject: [PATCH 8/9] fix types (for real) --- packages/next/src/build/index.ts | 3 +-- packages/next/types/compiled.d.ts | 4 ---- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 115e049fc29ed..13fd429c6b9bc 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -122,7 +122,6 @@ import { normalizeAppPath } from '../shared/lib/router/utils/app-paths' import { AppBuildManifest } from './webpack/plugins/app-build-manifest-plugin' import { RSC, RSC_VARY_HEADER } from '../client/components/app-router-headers' import { webpackBuild } from './webpack-build' -import { Ora } from 'next/dist/compiled/ora' export type SsgRoute = { initialRevalidateSeconds: number | false @@ -147,7 +146,7 @@ export type PrerenderManifest = { export const NextBuildContext: Partial<{ telemetryPlugin: TelemetryPlugin - buildSpinner: Ora + buildSpinner: any nextBuildSpan: Span entrypoints: { client: webpack.EntryObject diff --git a/packages/next/types/compiled.d.ts b/packages/next/types/compiled.d.ts index 73ab661cb79da..1f5bf8303af88 100644 --- a/packages/next/types/compiled.d.ts +++ b/packages/next/types/compiled.d.ts @@ -19,7 +19,3 @@ declare module 'next/dist/compiled/webpack/webpack' { export const NormalModule: any export const ResolvePluginInstance: any } - -declare module 'next/dist/compiled/ora/index' { - export const Ora: any -} From 078fd21a3e452929ade1fa5e521bf246b5deb1b8 Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Mon, 30 Jan 2023 10:59:53 +0100 Subject: [PATCH 9/9] misc: deprecate custom config from being passed to next/build --- packages/next/src/build/index.ts | 3 +-- packages/next/src/cli/next-build.ts | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/next/src/build/index.ts b/packages/next/src/build/index.ts index 13fd429c6b9bc..cdaab4a01293f 100644 --- a/packages/next/src/build/index.ts +++ b/packages/next/src/build/index.ts @@ -248,7 +248,6 @@ function pageToRoute(page: string) { export default async function build( dir: string, - conf = null, reactProductionProfiling = false, debugOutput = false, runLint = true, @@ -270,7 +269,7 @@ export default async function build( const config: NextConfigComplete = await nextBuildSpan .traceChild('load-next-config') - .traceAsyncFn(() => loadConfig(PHASE_PRODUCTION_BUILD, dir, conf)) + .traceAsyncFn(() => loadConfig(PHASE_PRODUCTION_BUILD, dir)) const distDir = path.join(dir, config.distDir) setGlobal('phase', PHASE_PRODUCTION_BUILD) diff --git a/packages/next/src/cli/next-build.ts b/packages/next/src/cli/next-build.ts index 31f5b5bd01975..a2d5546ef2dec 100755 --- a/packages/next/src/cli/next-build.ts +++ b/packages/next/src/cli/next-build.ts @@ -72,7 +72,6 @@ const nextBuild: CliCommand = (argv) => { return build( dir, - null, args['--profile'], args['--debug'] || process.env.NEXT_DEBUG_BUILD, !args['--no-lint'],