main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

260
node_modules/next/dist/esm/build/webpack-build/impl.js generated vendored Normal file
View File

@@ -0,0 +1,260 @@
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, PHASE_PRODUCTION_BUILD } from "../../shared/lib/constants";
import { runCompiler } from "../compiler";
import * as Log from "../output/log";
import getBaseWebpackConfig, { loadProjectInfo } from "../webpack-config";
import { TelemetryPlugin } from "../webpack/plugins/telemetry-plugin";
import { NextBuildContext, resumePluginState, getPluginState } from "../build-context";
import { createEntrypoints } from "../entries";
import loadConfig from "../../server/config";
import { trace } from "../../trace";
import { WEBPACK_LAYERS } from "../../lib/constants";
import { TraceEntryPointsPlugin } from "../webpack/plugins/next-trace-entrypoints-plugin";
import * as pagesPluginModule from "../webpack/plugins/pages-manifest-plugin";
import origDebug from "next/dist/compiled/debug";
const debug = origDebug("next:build:webpack-build");
function isTelemetryPlugin(plugin) {
return plugin instanceof TelemetryPlugin;
}
function isTraceEntryPointsPlugin(plugin) {
return plugin instanceof TraceEntryPointsPlugin;
}
export async function webpackBuildImpl(compilerName) {
var _clientConfig_plugins, _serverConfig_plugins;
let result = {
warnings: [],
errors: [],
stats: []
};
let webpackBuildStart;
const nextBuildSpan = NextBuildContext.nextBuildSpan;
const dir = NextBuildContext.dir;
const config = NextBuildContext.config;
const runWebpackSpan = nextBuildSpan.traceChild("run-webpack-compiler");
const entrypoints = await nextBuildSpan.traceChild("create-entrypoints").traceAsyncFn(()=>createEntrypoints({
buildId: NextBuildContext.buildId,
config: config,
envFiles: NextBuildContext.loadedEnvFiles,
isDev: false,
rootDir: dir,
pageExtensions: config.pageExtensions,
pagesDir: NextBuildContext.pagesDir,
appDir: NextBuildContext.appDir,
pages: NextBuildContext.mappedPages,
appPaths: NextBuildContext.mappedAppPages,
previewMode: NextBuildContext.previewProps,
rootPaths: NextBuildContext.mappedRootPaths,
hasInstrumentationHook: NextBuildContext.hasInstrumentationHook
}));
const commonWebpackOptions = {
isServer: false,
buildId: NextBuildContext.buildId,
config: config,
appDir: NextBuildContext.appDir,
pagesDir: NextBuildContext.pagesDir,
rewrites: NextBuildContext.rewrites,
originalRewrites: NextBuildContext.originalRewrites,
originalRedirects: NextBuildContext.originalRedirects,
reactProductionProfiling: NextBuildContext.reactProductionProfiling,
noMangling: NextBuildContext.noMangling,
clientRouterFilters: NextBuildContext.clientRouterFilters,
previewModeId: NextBuildContext.previewModeId,
allowedRevalidateHeaderKeys: NextBuildContext.allowedRevalidateHeaderKeys,
fetchCacheKeyPrefix: NextBuildContext.fetchCacheKeyPrefix
};
const configs = await runWebpackSpan.traceChild("generate-webpack-config").traceAsyncFn(async ()=>{
const info = await loadProjectInfo({
dir,
config: commonWebpackOptions.config,
dev: false
});
return Promise.all([
getBaseWebpackConfig(dir, {
...commonWebpackOptions,
middlewareMatchers: entrypoints.middlewareMatchers,
runWebpackSpan,
compilerType: COMPILER_NAMES.client,
entrypoints: entrypoints.client,
...info
}),
getBaseWebpackConfig(dir, {
...commonWebpackOptions,
runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.server,
entrypoints: entrypoints.server,
...info
}),
getBaseWebpackConfig(dir, {
...commonWebpackOptions,
runWebpackSpan,
middlewareMatchers: entrypoints.middlewareMatchers,
compilerType: COMPILER_NAMES.edgeServer,
entrypoints: entrypoints.edgeServer,
...info
})
]);
});
const clientConfig = configs[0];
const serverConfig = configs[1];
const edgeConfig = configs[2];
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();
debug(`starting compiler`, compilerName);
// 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 = null;
// During the server compilations, entries of client components will be
// injected to this set and then will be consumed by the client compiler.
let serverResult = null;
let edgeServerResult = null;
let inputFileSystem;
if (!compilerName || compilerName === "server") {
[serverResult, inputFileSystem] = await runCompiler(serverConfig, {
runWebpackSpan,
inputFileSystem
});
debug("server result", serverResult);
}
if (!compilerName || compilerName === "edge-server") {
[edgeServerResult, inputFileSystem] = edgeConfig ? await runCompiler(edgeConfig, {
runWebpackSpan,
inputFileSystem
}) : [
null
];
debug("edge server result", edgeServerResult);
}
// Only continue if there were no errors
if (!(serverResult == null ? void 0 : serverResult.errors.length) && !(edgeServerResult == null ? void 0 : edgeServerResult.errors.length)) {
const pluginState = getPluginState();
for(const key in pluginState.injectedClientEntries){
const value = pluginState.injectedClientEntries[key];
const clientEntry = clientConfig.entry;
if (key === APP_CLIENT_INTERNALS) {
clientEntry[CLIENT_STATIC_FILES_RUNTIME_MAIN_APP] = {
import: [
// 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
],
layer: WEBPACK_LAYERS.appPagesBrowser
};
} else {
clientEntry[key] = {
dependOn: [
CLIENT_STATIC_FILES_RUNTIME_MAIN_APP
],
import: value,
layer: WEBPACK_LAYERS.appPagesBrowser
};
}
}
if (!compilerName || compilerName === "client") {
[clientResult, inputFileSystem] = await runCompiler(clientConfig, {
runWebpackSpan,
inputFileSystem
});
debug("client result", clientResult);
}
}
inputFileSystem.purge();
result = {
warnings: [].concat(clientResult == null ? void 0 : clientResult.warnings, serverResult == null ? void 0 : serverResult.warnings, edgeServerResult == null ? void 0 : edgeServerResult.warnings).filter(nonNullable),
errors: [].concat(clientResult == null ? void 0 : clientResult.errors, serverResult == null ? void 0 : serverResult.errors, edgeServerResult == null ? void 0 : edgeServerResult.errors).filter(nonNullable),
stats: [
clientResult == null ? void 0 : clientResult.stats,
serverResult == null ? void 0 : serverResult.stats,
edgeServerResult == null ? void 0 : edgeServerResult.stats
]
};
});
result = nextBuildSpan.traceChild("format-webpack-messages").traceFn(()=>formatWebpackMessages(result, true));
NextBuildContext.telemetryPlugin = (_clientConfig_plugins = clientConfig.plugins) == null ? void 0 : _clientConfig_plugins.find(isTelemetryPlugin);
const traceEntryPointsPlugin = (_serverConfig_plugins = serverConfig.plugins) == null ? void 0 : _serverConfig_plugins.find(isTraceEntryPointsPlugin);
const webpackBuildEnd = process.hrtime(webpackBuildStart);
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\/(?<page_name>[^']*)'/;
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");
err.code = "INVALID_RESOLVE_ALIAS";
throw err;
}
const err = new Error("Build failed because of webpack errors");
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 if (!compilerName) {
var _NextBuildContext_buildSpinner;
(_NextBuildContext_buildSpinner = NextBuildContext.buildSpinner) == null ? void 0 : _NextBuildContext_buildSpinner.stopAndPersist();
Log.event("Compiled successfully");
}
return {
duration: webpackBuildEnd[0],
turbotraceContext: traceEntryPointsPlugin == null ? void 0 : traceEntryPointsPlugin.turbotraceContext,
pluginState: getPluginState(),
serializedPagesManifestEntries: {
edgeServerPages: pagesPluginModule.edgeServerPages,
edgeServerAppPaths: pagesPluginModule.edgeServerAppPaths,
nodeServerPages: pagesPluginModule.nodeServerPages,
nodeServerAppPaths: pagesPluginModule.nodeServerAppPaths
}
};
}
}
// the main function when this file is run as a worker
export async function workerMain(workerData) {
// setup new build context from the serialized data passed from the parent
Object.assign(NextBuildContext, workerData.buildContext);
// Resume plugin state
resumePluginState(NextBuildContext.pluginState);
// restore module scope maps for flight plugins
const { serializedPagesManifestEntries } = NextBuildContext;
for (const key of Object.keys(serializedPagesManifestEntries || {})){
Object.assign(pagesPluginModule[key], serializedPagesManifestEntries == null ? void 0 : serializedPagesManifestEntries[key]);
}
/// load the config because it's not serializable
NextBuildContext.config = await loadConfig(PHASE_PRODUCTION_BUILD, NextBuildContext.dir);
NextBuildContext.nextBuildSpan = trace("next-build");
const result = await webpackBuildImpl(workerData.compilerName);
const { entriesTrace } = result.turbotraceContext ?? {};
if (entriesTrace) {
const { entryNameMap, depModArray } = entriesTrace;
if (depModArray) {
result.turbotraceContext.entriesTrace.depModArray = depModArray;
}
if (entryNameMap) {
const entryEntries = Array.from((entryNameMap == null ? void 0 : entryNameMap.entries()) ?? []);
// @ts-expect-error
result.turbotraceContext.entriesTrace.entryNameMap = entryEntries;
}
}
return result;
}
//# sourceMappingURL=impl.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,87 @@
import * as Log from "../output/log";
import { NextBuildContext } from "../build-context";
import { Worker } from "next/dist/compiled/jest-worker";
import origDebug from "next/dist/compiled/debug";
import path from "path";
const debug = origDebug("next:build:webpack-build");
async function webpackBuildWithWorker() {
const { config, telemetryPlugin, buildSpinner, nextBuildSpan, ...prunedBuildContext } = NextBuildContext;
const getWorker = (compilerName)=>{
var _worker__workerPool;
const _worker = new Worker(path.join(__dirname, "impl.js"), {
exposedMethods: [
"workerMain"
],
numWorkers: 1,
maxRetries: 0,
forkOptions: {
env: {
...process.env,
NEXT_PRIVATE_BUILD_WORKER: "1"
}
}
});
_worker.getStderr().pipe(process.stderr);
_worker.getStdout().pipe(process.stdout);
for (const worker of ((_worker__workerPool = _worker._workerPool) == null ? void 0 : _worker__workerPool._workers) || []){
worker._child.on("exit", (code, signal)=>{
if (code || signal) {
console.error(`Compiler ${compilerName} unexpectedly exited with code: ${code} and signal: ${signal}`);
}
});
}
return _worker;
};
const combinedResult = {
duration: 0,
turbotraceContext: {}
};
// order matters here
const ORDERED_COMPILER_NAMES = [
"server",
"edge-server",
"client"
];
for (const compilerName of ORDERED_COMPILER_NAMES){
var _curResult_serializedPagesManifestEntries, _curResult_serializedPagesManifestEntries1, _curResult_serializedPagesManifestEntries2, _curResult_serializedPagesManifestEntries3, _curResult_turbotraceContext;
const worker = getWorker(compilerName);
const curResult = await worker.workerMain({
buildContext: prunedBuildContext,
compilerName
});
// destroy worker so it's not sticking around using memory
await worker.end();
// Update plugin state
prunedBuildContext.pluginState = curResult.pluginState;
prunedBuildContext.serializedPagesManifestEntries = {
edgeServerAppPaths: (_curResult_serializedPagesManifestEntries = curResult.serializedPagesManifestEntries) == null ? void 0 : _curResult_serializedPagesManifestEntries.edgeServerAppPaths,
edgeServerPages: (_curResult_serializedPagesManifestEntries1 = curResult.serializedPagesManifestEntries) == null ? void 0 : _curResult_serializedPagesManifestEntries1.edgeServerPages,
nodeServerAppPaths: (_curResult_serializedPagesManifestEntries2 = curResult.serializedPagesManifestEntries) == null ? void 0 : _curResult_serializedPagesManifestEntries2.nodeServerAppPaths,
nodeServerPages: (_curResult_serializedPagesManifestEntries3 = curResult.serializedPagesManifestEntries) == null ? void 0 : _curResult_serializedPagesManifestEntries3.nodeServerPages
};
combinedResult.duration += curResult.duration;
if ((_curResult_turbotraceContext = curResult.turbotraceContext) == null ? void 0 : _curResult_turbotraceContext.entriesTrace) {
combinedResult.turbotraceContext = curResult.turbotraceContext;
const { entryNameMap } = combinedResult.turbotraceContext.entriesTrace;
if (entryNameMap) {
combinedResult.turbotraceContext.entriesTrace.entryNameMap = new Map(entryNameMap);
}
}
}
buildSpinner == null ? void 0 : buildSpinner.stopAndPersist();
Log.event("Compiled successfully");
return combinedResult;
}
export async function webpackBuild() {
const config = NextBuildContext.config;
if (config.experimental.webpackBuildWorker) {
debug("using separate compiler workers");
return await webpackBuildWithWorker();
} else {
debug("building all compilers in same process");
const webpackBuildImpl = require("./impl").webpackBuildImpl;
return await webpackBuildImpl();
}
}
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"sources":["../../../src/build/webpack-build/index.ts"],"names":["Log","NextBuildContext","Worker","origDebug","path","debug","webpackBuildWithWorker","config","telemetryPlugin","buildSpinner","nextBuildSpan","prunedBuildContext","getWorker","compilerName","_worker","join","__dirname","exposedMethods","numWorkers","maxRetries","forkOptions","env","process","NEXT_PRIVATE_BUILD_WORKER","getStderr","pipe","stderr","getStdout","stdout","worker","_workerPool","_workers","_child","on","code","signal","console","error","combinedResult","duration","turbotraceContext","ORDERED_COMPILER_NAMES","curResult","workerMain","buildContext","end","pluginState","serializedPagesManifestEntries","edgeServerAppPaths","edgeServerPages","nodeServerAppPaths","nodeServerPages","entriesTrace","entryNameMap","Map","stopAndPersist","event","webpackBuild","experimental","webpackBuildWorker","webpackBuildImpl","require"],"mappings":"AACA,YAAYA,SAAS,gBAAe;AACpC,SAASC,gBAAgB,QAAQ,mBAAkB;AAEnD,SAASC,MAAM,QAAQ,iCAAgC;AACvD,OAAOC,eAAe,2BAA0B;AAEhD,OAAOC,UAAU,OAAM;AAEvB,MAAMC,QAAQF,UAAU;AAExB,eAAeG;IACb,MAAM,EACJC,MAAM,EACNC,eAAe,EACfC,YAAY,EACZC,aAAa,E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