next 15.2.1-canary.1 → 15.2.1-canary.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of next might be problematic. Click here for more details.
- package/dist/bin/next +1 -1
- package/dist/build/handle-externals.d.ts +2 -3
- package/dist/build/handle-externals.js +4 -4
- package/dist/build/handle-externals.js.map +1 -1
- package/dist/build/index.js +2 -2
- package/dist/build/swc/index.js +1 -1
- package/dist/build/webpack/plugins/build-manifest-plugin.js +3 -5
- package/dist/build/webpack/plugins/build-manifest-plugin.js.map +1 -1
- package/dist/build/webpack/plugins/css-minimizer-plugin.js +2 -2
- package/dist/build/webpack/plugins/css-minimizer-plugin.js.map +1 -1
- package/dist/build/webpack/plugins/minify-webpack-plugin/src/index.js +2 -2
- package/dist/build/webpack/plugins/minify-webpack-plugin/src/index.js.map +1 -1
- package/dist/build/webpack/plugins/next-trace-entrypoints-plugin.d.ts +1 -3
- package/dist/build/webpack/plugins/next-trace-entrypoints-plugin.js +5 -6
- package/dist/build/webpack/plugins/next-trace-entrypoints-plugin.js.map +1 -1
- package/dist/build/webpack/utils.d.ts +3 -1
- package/dist/build/webpack/utils.js +10 -0
- package/dist/build/webpack/utils.js.map +1 -1
- package/dist/build/webpack-config.js +2 -4
- package/dist/build/webpack-config.js.map +1 -1
- package/dist/client/app-bootstrap.js +1 -1
- package/dist/client/components/react-dev-overlay/server/shared.d.ts +0 -3
- package/dist/client/components/react-dev-overlay/server/shared.js.map +1 -1
- package/dist/client/components/react-dev-overlay/ui/styles/colors.js +1 -1
- package/dist/client/components/react-dev-overlay/ui/styles/colors.js.map +1 -1
- package/dist/client/components/react-dev-overlay/utils/stack-frame.d.ts +11 -3
- package/dist/client/components/react-dev-overlay/utils/stack-frame.js +2 -5
- package/dist/client/components/react-dev-overlay/utils/stack-frame.js.map +1 -1
- package/dist/client/components/router-reducer/reducers/navigate-reducer.js +29 -9
- package/dist/client/components/router-reducer/reducers/navigate-reducer.js.map +1 -1
- package/dist/client/components/segment-cache/navigation.d.ts +5 -1
- package/dist/client/components/segment-cache/navigation.js +28 -19
- package/dist/client/components/segment-cache/navigation.js.map +1 -1
- package/dist/client/index.js +1 -1
- package/dist/compiled/next-server/app-page-experimental.runtime.dev.js +2 -2
- package/dist/compiled/next-server/app-page-experimental.runtime.dev.js.map +1 -1
- package/dist/compiled/next-server/app-page.runtime.dev.js +2 -2
- package/dist/compiled/next-server/app-page.runtime.dev.js.map +1 -1
- package/dist/esm/build/handle-externals.js +4 -4
- package/dist/esm/build/handle-externals.js.map +1 -1
- package/dist/esm/build/index.js +2 -2
- package/dist/esm/build/swc/index.js +1 -1
- package/dist/esm/build/webpack/plugins/build-manifest-plugin.js +3 -5
- package/dist/esm/build/webpack/plugins/build-manifest-plugin.js.map +1 -1
- package/dist/esm/build/webpack/plugins/css-minimizer-plugin.js +2 -2
- package/dist/esm/build/webpack/plugins/css-minimizer-plugin.js.map +1 -1
- package/dist/esm/build/webpack/plugins/minify-webpack-plugin/src/index.js +2 -2
- package/dist/esm/build/webpack/plugins/minify-webpack-plugin/src/index.js.map +1 -1
- package/dist/esm/build/webpack/plugins/next-trace-entrypoints-plugin.js +5 -6
- package/dist/esm/build/webpack/plugins/next-trace-entrypoints-plugin.js.map +1 -1
- package/dist/esm/build/webpack/utils.js +6 -0
- package/dist/esm/build/webpack/utils.js.map +1 -1
- package/dist/esm/build/webpack-config.js +2 -4
- package/dist/esm/build/webpack-config.js.map +1 -1
- package/dist/esm/client/app-bootstrap.js +1 -1
- package/dist/esm/client/components/react-dev-overlay/server/shared.js.map +1 -1
- package/dist/esm/client/components/react-dev-overlay/ui/styles/colors.js +1 -1
- package/dist/esm/client/components/react-dev-overlay/ui/styles/colors.js.map +1 -1
- package/dist/esm/client/components/react-dev-overlay/utils/stack-frame.js +2 -5
- package/dist/esm/client/components/react-dev-overlay/utils/stack-frame.js.map +1 -1
- package/dist/esm/client/components/router-reducer/reducers/navigate-reducer.js +29 -9
- package/dist/esm/client/components/router-reducer/reducers/navigate-reducer.js.map +1 -1
- package/dist/esm/client/components/segment-cache/navigation.js +28 -19
- package/dist/esm/client/components/segment-cache/navigation.js.map +1 -1
- package/dist/esm/client/index.js +1 -1
- package/dist/esm/lib/server-external-packages.json +4 -0
- package/dist/esm/server/config.js +1 -1
- package/dist/esm/server/dev/hot-reloader-turbopack.js +1 -1
- package/dist/esm/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/esm/server/lib/app-info-log.js +1 -1
- package/dist/esm/server/lib/start-server.js +1 -1
- package/dist/lib/server-external-packages.json +4 -0
- package/dist/server/config.js +1 -1
- package/dist/server/dev/hot-reloader-turbopack.js +1 -1
- package/dist/server/dev/hot-reloader-webpack.js +1 -1
- package/dist/server/lib/app-info-log.js +1 -1
- package/dist/server/lib/start-server.js +1 -1
- package/dist/telemetry/anonymous-meta.js +1 -1
- package/dist/telemetry/events/session-stopped.js +2 -2
- package/dist/telemetry/events/version.js +2 -2
- package/package.json +15 -15
@@ -15,7 +15,7 @@ export function isResourceInPackages(resource, packageNames, packageDirMapping)
|
|
15
15
|
if (!packageNames) return false;
|
16
16
|
return packageNames.some((p)=>packageDirMapping && packageDirMapping.has(p) ? resource.startsWith(packageDirMapping.get(p) + path.sep) : resource.includes(path.sep + path.join('node_modules', p.replace(/\//g, path.sep)) + path.sep));
|
17
17
|
}
|
18
|
-
export async function resolveExternal(dir, esmExternalsConfig, context, request, isEsmRequested,
|
18
|
+
export async function resolveExternal(dir, esmExternalsConfig, context, request, isEsmRequested, getResolve, isLocalCallback, baseResolveCheck = true, esmResolveOptions = NODE_ESM_RESOLVE_OPTIONS, nodeResolveOptions = NODE_RESOLVE_OPTIONS, baseEsmResolveOptions = NODE_BASE_ESM_RESOLVE_OPTIONS, baseResolveOptions = NODE_BASE_RESOLVE_OPTIONS) {
|
19
19
|
const esmExternals = !!esmExternalsConfig;
|
20
20
|
const looseEsmExternals = esmExternalsConfig === 'loose';
|
21
21
|
let res = null;
|
@@ -82,7 +82,7 @@ export async function resolveExternal(dir, esmExternalsConfig, context, request,
|
|
82
82
|
isEsm
|
83
83
|
};
|
84
84
|
}
|
85
|
-
export function makeExternalHandler({ config,
|
85
|
+
export function makeExternalHandler({ config, optOutBundlingPackageRegex, transpiledPackages, dir }) {
|
86
86
|
var _config_experimental;
|
87
87
|
let resolvedExternalPackageDirs;
|
88
88
|
const looseEsmExternals = ((_config_experimental = config.experimental) == null ? void 0 : _config_experimental.esmExternals) === 'loose';
|
@@ -156,7 +156,7 @@ export function makeExternalHandler({ config, optOutBundlingPackages, optOutBund
|
|
156
156
|
return resolveNextExternal(request);
|
157
157
|
}
|
158
158
|
// TODO-APP: Let's avoid this resolve call as much as possible, and eventually get rid of it.
|
159
|
-
const resolveResult = await resolveExternal(dir, config.experimental.esmExternals, context, request, isEsmRequested,
|
159
|
+
const resolveResult = await resolveExternal(dir, config.experimental.esmExternals, context, request, isEsmRequested, getResolve, isLocal ? resolveNextExternal : undefined);
|
160
160
|
if ('localRes' in resolveResult) {
|
161
161
|
return resolveResult.localRes;
|
162
162
|
}
|
@@ -202,7 +202,7 @@ export function makeExternalHandler({ config, optOutBundlingPackages, optOutBund
|
|
202
202
|
resolvedExternalPackageDirs = new Map();
|
203
203
|
// We need to resolve all the external package dirs initially.
|
204
204
|
for (const pkg of transpiledPackages){
|
205
|
-
const pkgRes = await resolveExternal(dir, config.experimental.esmExternals, context, pkg + '/package.json', isEsmRequested,
|
205
|
+
const pkgRes = await resolveExternal(dir, config.experimental.esmExternals, context, pkg + '/package.json', isEsmRequested, getResolve, isLocal ? resolveNextExternal : undefined);
|
206
206
|
if (pkgRes.res) {
|
207
207
|
resolvedExternalPackageDirs.set(pkg, path.dirname(pkgRes.res));
|
208
208
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../src/build/handle-externals.ts"],"sourcesContent":["import type { WebpackLayerName } from '../lib/constants'\nimport type { NextConfigComplete } from '../server/config-shared'\nimport type { ResolveOptions } from 'webpack'\nimport { defaultOverrides } from '../server/require-hook'\nimport { BARREL_OPTIMIZATION_PREFIX } from '../shared/lib/constants'\nimport path from '../shared/lib/isomorphic/path'\nimport {\n NODE_BASE_ESM_RESOLVE_OPTIONS,\n NODE_BASE_RESOLVE_OPTIONS,\n NODE_ESM_RESOLVE_OPTIONS,\n NODE_RESOLVE_OPTIONS,\n} from './webpack-config'\nimport { isWebpackBundledLayer, isWebpackServerOnlyLayer } from './utils'\nimport { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep'\nconst reactPackagesRegex = /^(react|react-dom|react-server-dom-webpack)($|\\/)/\n\nconst pathSeparators = '[/\\\\\\\\]'\nconst optionalEsmPart = `((${pathSeparators}esm)?${pathSeparators})`\nconst externalFileEnd = '(\\\\.external(\\\\.js)?)$'\nconst nextDist = `next${pathSeparators}dist`\n\nconst externalPattern = new RegExp(\n `${nextDist}${optionalEsmPart}.*${externalFileEnd}`\n)\n\nconst nodeModulesRegex = /node_modules[/\\\\].*\\.[mc]?js$/\n\nexport function isResourceInPackages(\n resource: string,\n packageNames?: string[],\n packageDirMapping?: Map<string, string>\n): boolean {\n if (!packageNames) return false\n return packageNames.some((p: string) =>\n packageDirMapping && packageDirMapping.has(p)\n ? resource.startsWith(packageDirMapping.get(p)! + path.sep)\n : resource.includes(\n path.sep +\n path.join('node_modules', p.replace(/\\//g, path.sep)) +\n path.sep\n )\n )\n}\n\nexport async function resolveExternal(\n dir: string,\n esmExternalsConfig: NextConfigComplete['experimental']['esmExternals'],\n context: string,\n request: string,\n isEsmRequested: boolean,\n _optOutBundlingPackages: string[],\n getResolve: (\n options: ResolveOptions\n ) => (\n resolveContext: string,\n resolveRequest: string\n ) => Promise<[string | null, boolean]>,\n isLocalCallback?: (res: string) => any,\n baseResolveCheck = true,\n esmResolveOptions: any = NODE_ESM_RESOLVE_OPTIONS,\n nodeResolveOptions: any = NODE_RESOLVE_OPTIONS,\n baseEsmResolveOptions: any = NODE_BASE_ESM_RESOLVE_OPTIONS,\n baseResolveOptions: any = NODE_BASE_RESOLVE_OPTIONS\n) {\n const esmExternals = !!esmExternalsConfig\n const looseEsmExternals = esmExternalsConfig === 'loose'\n\n let res: string | null = null\n let isEsm: boolean = false\n\n const preferEsmOptions =\n esmExternals && isEsmRequested ? [true, false] : [false]\n\n for (const preferEsm of preferEsmOptions) {\n const resolveOptions = preferEsm ? esmResolveOptions : nodeResolveOptions\n\n const resolve = getResolve(resolveOptions)\n\n // Resolve the import with the webpack provided context, this\n // ensures we're resolving the correct version when multiple\n // exist.\n try {\n ;[res, isEsm] = await resolve(context, request)\n } catch (err) {\n res = null\n }\n\n if (!res) {\n continue\n }\n\n // ESM externals can only be imported (and not required).\n // Make an exception in loose mode.\n if (!isEsmRequested && isEsm && !looseEsmExternals) {\n continue\n }\n\n if (isLocalCallback) {\n return { localRes: isLocalCallback(res) }\n }\n\n // Bundled Node.js code is relocated without its node_modules tree.\n // This means we need to make sure its request resolves to the same\n // package that'll be available at runtime. If it's not identical,\n // we need to bundle the code (even if it _should_ be external).\n if (baseResolveCheck) {\n let baseRes: string | null\n let baseIsEsm: boolean\n try {\n const baseResolve = getResolve(\n isEsm ? baseEsmResolveOptions : baseResolveOptions\n )\n ;[baseRes, baseIsEsm] = await baseResolve(dir, request)\n } catch (err) {\n baseRes = null\n baseIsEsm = false\n }\n\n // Same as above: if the package, when required from the root,\n // would be different from what the real resolution would use, we\n // cannot externalize it.\n // if request is pointing to a symlink it could point to the same file,\n // the resolver will resolve symlinks so this is handled\n if (baseRes !== res || isEsm !== baseIsEsm) {\n res = null\n continue\n }\n }\n break\n }\n return { res, isEsm }\n}\n\nexport function makeExternalHandler({\n config,\n optOutBundlingPackages,\n optOutBundlingPackageRegex,\n transpiledPackages,\n dir,\n}: {\n config: NextConfigComplete\n optOutBundlingPackages: string[]\n optOutBundlingPackageRegex: RegExp\n transpiledPackages: string[]\n dir: string\n}) {\n let resolvedExternalPackageDirs: Map<string, string>\n const looseEsmExternals = config.experimental?.esmExternals === 'loose'\n\n return async function handleExternals(\n context: string,\n request: string,\n dependencyType: string,\n layer: WebpackLayerName | null,\n getResolve: (\n options: any\n ) => (\n resolveContext: string,\n resolveRequest: string\n ) => Promise<[string | null, boolean]>\n ) {\n // We need to externalize internal requests for files intended to\n // not be bundled.\n const isLocal: boolean =\n request.startsWith('.') ||\n // Always check for unix-style path, as webpack sometimes\n // normalizes as posix.\n path.posix.isAbsolute(request) ||\n // When on Windows, we also want to check for Windows-specific\n // absolute paths.\n (process.platform === 'win32' && path.win32.isAbsolute(request))\n\n // make sure import \"next\" shows a warning when imported\n // in pages/components\n if (request === 'next') {\n return `commonjs next/dist/lib/import-next-warning`\n }\n\n const isAppLayer = isWebpackBundledLayer(layer)\n\n // Relative requires don't need custom resolution, because they\n // are relative to requests we've already resolved here.\n // Absolute requires (require('/foo')) are extremely uncommon, but\n // also have no need for customization as they're already resolved.\n if (!isLocal) {\n if (/^next$/.test(request)) {\n return `commonjs ${request}`\n }\n\n if (reactPackagesRegex.test(request) && !isAppLayer) {\n return `commonjs ${request}`\n }\n\n const notExternalModules =\n /^(?:private-next-pages\\/|next\\/(?:dist\\/pages\\/|(?:app|document|link|form|image|legacy\\/image|constants|dynamic|script|navigation|headers|router)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-server-reference|private-next-rsc-cache-wrapper$)/\n if (notExternalModules.test(request)) {\n return\n }\n }\n\n // @swc/helpers should not be external as it would\n // require hoisting the package which we can't rely on\n if (request.includes('@swc/helpers')) {\n return\n }\n\n // BARREL_OPTIMIZATION_PREFIX is a special marker that tells Next.js to\n // optimize the import by removing unused exports. This has to be compiled.\n if (request.startsWith(BARREL_OPTIMIZATION_PREFIX)) {\n return\n }\n\n // When in esm externals mode, and using import, we resolve with\n // ESM resolving options.\n // Also disable esm request when appDir is enabled\n const isEsmRequested = dependencyType === 'esm'\n\n // Don't bundle @vercel/og nodejs bundle for nodejs runtime.\n // TODO-APP: bundle route.js with different layer that externals common node_module deps.\n // Make sure @vercel/og is loaded as ESM for Node.js runtime\n if (\n isWebpackServerOnlyLayer(layer) &&\n request === 'next/dist/compiled/@vercel/og/index.node.js'\n ) {\n return `module ${request}`\n }\n\n // Specific Next.js imports that should remain external\n // TODO-APP: Investigate if we can remove this.\n if (request.startsWith('next/dist/')) {\n // Non external that needs to be transpiled\n // Image loader needs to be transpiled\n if (/^next[\\\\/]dist[\\\\/]shared[\\\\/]lib[\\\\/]image-loader/.test(request)) {\n return\n }\n\n if (/^next[\\\\/]dist[\\\\/]compiled[\\\\/]next-server/.test(request)) {\n return `commonjs ${request}`\n }\n\n if (\n /^next[\\\\/]dist[\\\\/]shared[\\\\/](?!lib[\\\\/]router[\\\\/]router)/.test(\n request\n ) ||\n /^next[\\\\/]dist[\\\\/]compiled[\\\\/].*\\.c?js$/.test(request)\n ) {\n return `commonjs ${request}`\n }\n\n if (\n /^next[\\\\/]dist[\\\\/]esm[\\\\/]shared[\\\\/](?!lib[\\\\/]router[\\\\/]router)/.test(\n request\n ) ||\n /^next[\\\\/]dist[\\\\/]compiled[\\\\/].*\\.mjs$/.test(request)\n ) {\n return `module ${request}`\n }\n\n return resolveNextExternal(request)\n }\n\n // TODO-APP: Let's avoid this resolve call as much as possible, and eventually get rid of it.\n const resolveResult = await resolveExternal(\n dir,\n config.experimental.esmExternals,\n context,\n request,\n isEsmRequested,\n optOutBundlingPackages,\n getResolve,\n isLocal ? resolveNextExternal : undefined\n )\n\n if ('localRes' in resolveResult) {\n return resolveResult.localRes\n }\n\n // Forcedly resolve the styled-jsx installed by next.js,\n // since `resolveExternal` cannot find the styled-jsx dep with pnpm\n if (request === 'styled-jsx/style') {\n resolveResult.res = defaultOverrides['styled-jsx/style']\n }\n\n const { res, isEsm } = resolveResult\n\n // If the request cannot be resolved we need to have\n // webpack \"bundle\" it so it surfaces the not found error.\n if (!res) {\n return\n }\n\n const isOptOutBundling = optOutBundlingPackageRegex.test(res)\n // Apply bundling rules to all app layers.\n // Since handleExternals only handle the server layers, we don't need to exclude client here\n if (!isOptOutBundling && isAppLayer) {\n return\n }\n\n // ESM externals can only be imported (and not required).\n // Make an exception in loose mode.\n if (!isEsmRequested && isEsm && !looseEsmExternals && !isLocal) {\n throw new Error(\n `ESM packages (${request}) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals`\n )\n }\n\n const externalType = isEsm ? 'module' : 'commonjs'\n\n // Default pages have to be transpiled\n if (\n // This is the @babel/plugin-transform-runtime \"helpers: true\" option\n /node_modules[/\\\\]@babel[/\\\\]runtime[/\\\\]/.test(res)\n ) {\n return\n }\n\n // Webpack itself has to be compiled because it doesn't always use module relative paths\n if (\n /node_modules[/\\\\]webpack/.test(res) ||\n /node_modules[/\\\\]css-loader/.test(res)\n ) {\n return\n }\n\n // If a package should be transpiled by Next.js, we skip making it external.\n // It doesn't matter what the extension is, as we'll transpile it anyway.\n if (transpiledPackages && !resolvedExternalPackageDirs) {\n resolvedExternalPackageDirs = new Map()\n // We need to resolve all the external package dirs initially.\n for (const pkg of transpiledPackages) {\n const pkgRes = await resolveExternal(\n dir,\n config.experimental.esmExternals,\n context,\n pkg + '/package.json',\n isEsmRequested,\n optOutBundlingPackages,\n getResolve,\n isLocal ? resolveNextExternal : undefined\n )\n if (pkgRes.res) {\n resolvedExternalPackageDirs.set(pkg, path.dirname(pkgRes.res))\n }\n }\n }\n\n const resolvedBundlingOptOutRes = resolveBundlingOptOutPackages({\n resolvedRes: res,\n config,\n resolvedExternalPackageDirs,\n isAppLayer,\n externalType,\n isOptOutBundling,\n request,\n transpiledPackages,\n })\n if (resolvedBundlingOptOutRes) {\n return resolvedBundlingOptOutRes\n }\n\n // if here, we default to bundling the file\n return\n }\n}\n\nfunction resolveBundlingOptOutPackages({\n resolvedRes,\n config,\n resolvedExternalPackageDirs,\n isAppLayer,\n externalType,\n isOptOutBundling,\n request,\n transpiledPackages,\n}: {\n resolvedRes: string\n config: NextConfigComplete\n resolvedExternalPackageDirs: Map<string, string>\n isAppLayer: boolean\n externalType: string\n isOptOutBundling: boolean\n request: string\n transpiledPackages: string[]\n}) {\n if (nodeModulesRegex.test(resolvedRes)) {\n const shouldBundlePages =\n !isAppLayer && config.bundlePagesRouterDependencies && !isOptOutBundling\n\n const shouldBeBundled =\n shouldBundlePages ||\n isResourceInPackages(\n resolvedRes,\n transpiledPackages,\n resolvedExternalPackageDirs\n )\n\n if (!shouldBeBundled) {\n return `${externalType} ${request}` // Externalize if not bundled or opted out\n }\n }\n}\n\n/**\n * @param localRes the full path to the file\n * @returns the externalized path\n * @description returns an externalized path if the file is a Next.js file and ends with either `.shared-runtime.js` or `.external.js`\n * This is used to ensure that files used across the rendering runtime(s) and the user code are one and the same. The logic in this function\n * will rewrite the require to the correct bundle location depending on the layer at which the file is being used.\n */\nfunction resolveNextExternal(localRes: string) {\n const isExternal = externalPattern.test(localRes)\n\n // if the file ends with .external, we need to make it a commonjs require in all cases\n // this is used mainly to share the async local storage across the routing, rendering and user layers.\n if (isExternal) {\n // it's important we return the path that starts with `next/dist/` here instead of the absolute path\n // otherwise NFT will get tripped up\n return `commonjs ${normalizePathSep(\n localRes.replace(/.*?next[/\\\\]dist/, 'next/dist')\n )}`\n }\n}\n"],"names":["defaultOverrides","BARREL_OPTIMIZATION_PREFIX","path","NODE_BASE_ESM_RESOLVE_OPTIONS","NODE_BASE_RESOLVE_OPTIONS","NODE_ESM_RESOLVE_OPTIONS","NODE_RESOLVE_OPTIONS","isWebpackBundledLayer","isWebpackServerOnlyLayer","normalizePathSep","reactPackagesRegex","pathSeparators","optionalEsmPart","externalFileEnd","nextDist","externalPattern","RegExp","nodeModulesRegex","isResourceInPackages","resource","packageNames","packageDirMapping","some","p","has","startsWith","get","sep","includes","join","replace","resolveExternal","dir","esmExternalsConfig","context","request","isEsmRequested","_optOutBundlingPackages","getResolve","isLocalCallback","baseResolveCheck","esmResolveOptions","nodeResolveOptions","baseEsmResolveOptions","baseResolveOptions","esmExternals","looseEsmExternals","res","isEsm","preferEsmOptions","preferEsm","resolveOptions","resolve","err","localRes","baseRes","baseIsEsm","baseResolve","makeExternalHandler","config","optOutBundlingPackages","optOutBundlingPackageRegex","transpiledPackages","resolvedExternalPackageDirs","experimental","handleExternals","dependencyType","layer","isLocal","posix","isAbsolute","process","platform","win32","isAppLayer","test","notExternalModules","resolveNextExternal","resolveResult","undefined","isOptOutBundling","Error","externalType","Map","pkg","pkgRes","set","dirname","resolvedBundlingOptOutRes","resolveBundlingOptOutPackages","resolvedRes","shouldBundlePages","bundlePagesRouterDependencies","shouldBeBundled","isExternal"],"mappings":"AAGA,SAASA,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,0BAA0B,QAAQ,0BAAyB;AACpE,OAAOC,UAAU,gCAA+B;AAChD,SACEC,6BAA6B,EAC7BC,yBAAyB,EACzBC,wBAAwB,EACxBC,oBAAoB,QACf,mBAAkB;AACzB,SAASC,qBAAqB,EAAEC,wBAAwB,QAAQ,UAAS;AACzE,SAASC,gBAAgB,QAAQ,6CAA4C;AAC7E,MAAMC,qBAAqB;AAE3B,MAAMC,iBAAiB;AACvB,MAAMC,kBAAkB,CAAC,EAAE,EAAED,eAAe,KAAK,EAAEA,eAAe,CAAC,CAAC;AACpE,MAAME,kBAAkB;AACxB,MAAMC,WAAW,CAAC,IAAI,EAAEH,eAAe,IAAI,CAAC;AAE5C,MAAMI,kBAAkB,IAAIC,OAC1B,GAAGF,WAAWF,gBAAgB,EAAE,EAAEC,iBAAiB;AAGrD,MAAMI,mBAAmB;AAEzB,OAAO,SAASC,qBACdC,QAAgB,EAChBC,YAAuB,EACvBC,iBAAuC;IAEvC,IAAI,CAACD,cAAc,OAAO;IAC1B,OAAOA,aAAaE,IAAI,CAAC,CAACC,IACxBF,qBAAqBA,kBAAkBG,GAAG,CAACD,KACvCJ,SAASM,UAAU,CAACJ,kBAAkBK,GAAG,CAACH,KAAMrB,KAAKyB,GAAG,IACxDR,SAASS,QAAQ,CACf1B,KAAKyB,GAAG,GACNzB,K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A2B;YAC7B,OAAOA;QACT;QAEA,2CAA2C;QAC3C;IACF;AACF;AAEA,SAASC,8BAA8B,EACrCC,WAAW,EACX/B,MAAM,EACNI,2BAA2B,EAC3BW,UAAU,EACVQ,YAAY,EACZF,gBAAgB,EAChB7C,OAAO,EACP2B,kBAAkB,EAUnB;IACC,IAAI7C,iBAAiB0D,IAAI,CAACe,cAAc;QACtC,MAAMC,oBACJ,CAACjB,cAAcf,OAAOiC,6BAA6B,IAAI,CAACZ;QAE1D,MAAMa,kBACJF,qBACAzE,qBACEwE,aACA5B,oBACAC;QAGJ,IAAI,CAAC8B,iBAAiB;YACpB,OAAO,GAAGX,aAAa,CAAC,EAAE/C,SAAS,CAAC,0CAA0C;;QAChF;IACF;AACF;AAEA;;;;;;CAMC,GACD,SAAS0C,oBAAoBvB,QAAgB;IAC3C,MAAMwC,aAAa/E,gBAAgB4D,IAAI,CAACrB;IAExC,sFAAsF;IACtF,sGAAsG;IACtG,IAAIwC,YAAY;QACd,oGAAoG;QACpG,oCAAoC;QACpC,OAAO,CAAC,SAAS,EAAErF,iBACjB6C,SAASxB,OAAO,CAAC,oBAAoB,eACpC;IACL;AACF"}
|
1
|
+
{"version":3,"sources":["../../src/build/handle-externals.ts"],"sourcesContent":["import type { WebpackLayerName } from '../lib/constants'\nimport type { NextConfigComplete } from '../server/config-shared'\nimport type { ResolveOptions } from 'webpack'\nimport { defaultOverrides } from '../server/require-hook'\nimport { BARREL_OPTIMIZATION_PREFIX } from '../shared/lib/constants'\nimport path from '../shared/lib/isomorphic/path'\nimport {\n NODE_BASE_ESM_RESOLVE_OPTIONS,\n NODE_BASE_RESOLVE_OPTIONS,\n NODE_ESM_RESOLVE_OPTIONS,\n NODE_RESOLVE_OPTIONS,\n} from './webpack-config'\nimport { isWebpackBundledLayer, isWebpackServerOnlyLayer } from './utils'\nimport { normalizePathSep } from '../shared/lib/page-path/normalize-path-sep'\nconst reactPackagesRegex = /^(react|react-dom|react-server-dom-webpack)($|\\/)/\n\nconst pathSeparators = '[/\\\\\\\\]'\nconst optionalEsmPart = `((${pathSeparators}esm)?${pathSeparators})`\nconst externalFileEnd = '(\\\\.external(\\\\.js)?)$'\nconst nextDist = `next${pathSeparators}dist`\n\nconst externalPattern = new RegExp(\n `${nextDist}${optionalEsmPart}.*${externalFileEnd}`\n)\n\nconst nodeModulesRegex = /node_modules[/\\\\].*\\.[mc]?js$/\n\nexport function isResourceInPackages(\n resource: string,\n packageNames?: string[],\n packageDirMapping?: Map<string, string>\n): boolean {\n if (!packageNames) return false\n return packageNames.some((p: string) =>\n packageDirMapping && packageDirMapping.has(p)\n ? resource.startsWith(packageDirMapping.get(p)! + path.sep)\n : resource.includes(\n path.sep +\n path.join('node_modules', p.replace(/\\//g, path.sep)) +\n path.sep\n )\n )\n}\n\nexport async function resolveExternal(\n dir: string,\n esmExternalsConfig: NextConfigComplete['experimental']['esmExternals'],\n context: string,\n request: string,\n isEsmRequested: boolean,\n getResolve: (\n options: ResolveOptions\n ) => (\n resolveContext: string,\n resolveRequest: string\n ) => Promise<[string | null, boolean]>,\n isLocalCallback?: (res: string) => any,\n baseResolveCheck = true,\n esmResolveOptions: any = NODE_ESM_RESOLVE_OPTIONS,\n nodeResolveOptions: any = NODE_RESOLVE_OPTIONS,\n baseEsmResolveOptions: any = NODE_BASE_ESM_RESOLVE_OPTIONS,\n baseResolveOptions: any = NODE_BASE_RESOLVE_OPTIONS\n) {\n const esmExternals = !!esmExternalsConfig\n const looseEsmExternals = esmExternalsConfig === 'loose'\n\n let res: string | null = null\n let isEsm: boolean = false\n\n const preferEsmOptions =\n esmExternals && isEsmRequested ? [true, false] : [false]\n\n for (const preferEsm of preferEsmOptions) {\n const resolveOptions = preferEsm ? esmResolveOptions : nodeResolveOptions\n\n const resolve = getResolve(resolveOptions)\n\n // Resolve the import with the webpack provided context, this\n // ensures we're resolving the correct version when multiple\n // exist.\n try {\n ;[res, isEsm] = await resolve(context, request)\n } catch (err) {\n res = null\n }\n\n if (!res) {\n continue\n }\n\n // ESM externals can only be imported (and not required).\n // Make an exception in loose mode.\n if (!isEsmRequested && isEsm && !looseEsmExternals) {\n continue\n }\n\n if (isLocalCallback) {\n return { localRes: isLocalCallback(res) }\n }\n\n // Bundled Node.js code is relocated without its node_modules tree.\n // This means we need to make sure its request resolves to the same\n // package that'll be available at runtime. If it's not identical,\n // we need to bundle the code (even if it _should_ be external).\n if (baseResolveCheck) {\n let baseRes: string | null\n let baseIsEsm: boolean\n try {\n const baseResolve = getResolve(\n isEsm ? baseEsmResolveOptions : baseResolveOptions\n )\n ;[baseRes, baseIsEsm] = await baseResolve(dir, request)\n } catch (err) {\n baseRes = null\n baseIsEsm = false\n }\n\n // Same as above: if the package, when required from the root,\n // would be different from what the real resolution would use, we\n // cannot externalize it.\n // if request is pointing to a symlink it could point to the same file,\n // the resolver will resolve symlinks so this is handled\n if (baseRes !== res || isEsm !== baseIsEsm) {\n res = null\n continue\n }\n }\n break\n }\n return { res, isEsm }\n}\n\nexport function makeExternalHandler({\n config,\n optOutBundlingPackageRegex,\n transpiledPackages,\n dir,\n}: {\n config: NextConfigComplete\n optOutBundlingPackageRegex: RegExp\n transpiledPackages: string[]\n dir: string\n}) {\n let resolvedExternalPackageDirs: Map<string, string>\n const looseEsmExternals = config.experimental?.esmExternals === 'loose'\n\n return async function handleExternals(\n context: string,\n request: string,\n dependencyType: string,\n layer: WebpackLayerName | null,\n getResolve: (\n options: any\n ) => (\n resolveContext: string,\n resolveRequest: string\n ) => Promise<[string | null, boolean]>\n ) {\n // We need to externalize internal requests for files intended to\n // not be bundled.\n const isLocal: boolean =\n request.startsWith('.') ||\n // Always check for unix-style path, as webpack sometimes\n // normalizes as posix.\n path.posix.isAbsolute(request) ||\n // When on Windows, we also want to check for Windows-specific\n // absolute paths.\n (process.platform === 'win32' && path.win32.isAbsolute(request))\n\n // make sure import \"next\" shows a warning when imported\n // in pages/components\n if (request === 'next') {\n return `commonjs next/dist/lib/import-next-warning`\n }\n\n const isAppLayer = isWebpackBundledLayer(layer)\n\n // Relative requires don't need custom resolution, because they\n // are relative to requests we've already resolved here.\n // Absolute requires (require('/foo')) are extremely uncommon, but\n // also have no need for customization as they're already resolved.\n if (!isLocal) {\n if (/^next$/.test(request)) {\n return `commonjs ${request}`\n }\n\n if (reactPackagesRegex.test(request) && !isAppLayer) {\n return `commonjs ${request}`\n }\n\n const notExternalModules =\n /^(?:private-next-pages\\/|next\\/(?:dist\\/pages\\/|(?:app|document|link|form|image|legacy\\/image|constants|dynamic|script|navigation|headers|router)$)|string-hash|private-next-rsc-action-validate|private-next-rsc-action-client-wrapper|private-next-rsc-server-reference|private-next-rsc-cache-wrapper$)/\n if (notExternalModules.test(request)) {\n return\n }\n }\n\n // @swc/helpers should not be external as it would\n // require hoisting the package which we can't rely on\n if (request.includes('@swc/helpers')) {\n return\n }\n\n // BARREL_OPTIMIZATION_PREFIX is a special marker that tells Next.js to\n // optimize the import by removing unused exports. This has to be compiled.\n if (request.startsWith(BARREL_OPTIMIZATION_PREFIX)) {\n return\n }\n\n // When in esm externals mode, and using import, we resolve with\n // ESM resolving options.\n // Also disable esm request when appDir is enabled\n const isEsmRequested = dependencyType === 'esm'\n\n // Don't bundle @vercel/og nodejs bundle for nodejs runtime.\n // TODO-APP: bundle route.js with different layer that externals common node_module deps.\n // Make sure @vercel/og is loaded as ESM for Node.js runtime\n if (\n isWebpackServerOnlyLayer(layer) &&\n request === 'next/dist/compiled/@vercel/og/index.node.js'\n ) {\n return `module ${request}`\n }\n\n // Specific Next.js imports that should remain external\n // TODO-APP: Investigate if we can remove this.\n if (request.startsWith('next/dist/')) {\n // Non external that needs to be transpiled\n // Image loader needs to be transpiled\n if (/^next[\\\\/]dist[\\\\/]shared[\\\\/]lib[\\\\/]image-loader/.test(request)) {\n return\n }\n\n if (/^next[\\\\/]dist[\\\\/]compiled[\\\\/]next-server/.test(request)) {\n return `commonjs ${request}`\n }\n\n if (\n /^next[\\\\/]dist[\\\\/]shared[\\\\/](?!lib[\\\\/]router[\\\\/]router)/.test(\n request\n ) ||\n /^next[\\\\/]dist[\\\\/]compiled[\\\\/].*\\.c?js$/.test(request)\n ) {\n return `commonjs ${request}`\n }\n\n if (\n /^next[\\\\/]dist[\\\\/]esm[\\\\/]shared[\\\\/](?!lib[\\\\/]router[\\\\/]router)/.test(\n request\n ) ||\n /^next[\\\\/]dist[\\\\/]compiled[\\\\/].*\\.mjs$/.test(request)\n ) {\n return `module ${request}`\n }\n\n return resolveNextExternal(request)\n }\n\n // TODO-APP: Let's avoid this resolve call as much as possible, and eventually get rid of it.\n const resolveResult = await resolveExternal(\n dir,\n config.experimental.esmExternals,\n context,\n request,\n isEsmRequested,\n getResolve,\n isLocal ? resolveNextExternal : undefined\n )\n\n if ('localRes' in resolveResult) {\n return resolveResult.localRes\n }\n\n // Forcedly resolve the styled-jsx installed by next.js,\n // since `resolveExternal` cannot find the styled-jsx dep with pnpm\n if (request === 'styled-jsx/style') {\n resolveResult.res = defaultOverrides['styled-jsx/style']\n }\n\n const { res, isEsm } = resolveResult\n\n // If the request cannot be resolved we need to have\n // webpack \"bundle\" it so it surfaces the not found error.\n if (!res) {\n return\n }\n\n const isOptOutBundling = optOutBundlingPackageRegex.test(res)\n // Apply bundling rules to all app layers.\n // Since handleExternals only handle the server layers, we don't need to exclude client here\n if (!isOptOutBundling && isAppLayer) {\n return\n }\n\n // ESM externals can only be imported (and not required).\n // Make an exception in loose mode.\n if (!isEsmRequested && isEsm && !looseEsmExternals && !isLocal) {\n throw new Error(\n `ESM packages (${request}) need to be imported. Use 'import' to reference the package instead. https://nextjs.org/docs/messages/import-esm-externals`\n )\n }\n\n const externalType = isEsm ? 'module' : 'commonjs'\n\n // Default pages have to be transpiled\n if (\n // This is the @babel/plugin-transform-runtime \"helpers: true\" option\n /node_modules[/\\\\]@babel[/\\\\]runtime[/\\\\]/.test(res)\n ) {\n return\n }\n\n // Webpack itself has to be compiled because it doesn't always use module relative paths\n if (\n /node_modules[/\\\\]webpack/.test(res) ||\n /node_modules[/\\\\]css-loader/.test(res)\n ) {\n return\n }\n\n // If a package should be transpiled by Next.js, we skip making it external.\n // It doesn't matter what the extension is, as we'll transpile it anyway.\n if (transpiledPackages && !resolvedExternalPackageDirs) {\n resolvedExternalPackageDirs = new Map()\n // We need to resolve all the external package dirs initially.\n for (const pkg of transpiledPackages) {\n const pkgRes = await resolveExternal(\n dir,\n config.experimental.esmExternals,\n context,\n pkg + '/package.json',\n isEsmRequested,\n getResolve,\n isLocal ? resolveNextExternal : undefined\n )\n if (pkgRes.res) {\n resolvedExternalPackageDirs.set(pkg, path.dirname(pkgRes.res))\n }\n }\n }\n\n const resolvedBundlingOptOutRes = resolveBundlingOptOutPackages({\n resolvedRes: res,\n config,\n resolvedExternalPackageDirs,\n isAppLayer,\n externalType,\n isOptOutBundling,\n request,\n transpiledPackages,\n })\n if (resolvedBundlingOptOutRes) {\n return resolvedBundlingOptOutRes\n }\n\n // if here, we default to bundling the file\n return\n }\n}\n\nfunction resolveBundlingOptOutPackages({\n resolvedRes,\n config,\n resolvedExternalPackageDirs,\n isAppLayer,\n externalType,\n isOptOutBundling,\n request,\n transpiledPackages,\n}: {\n resolvedRes: string\n config: NextConfigComplete\n resolvedExternalPackageDirs: Map<string, string>\n isAppLayer: boolean\n externalType: string\n isOptOutBundling: boolean\n request: string\n transpiledPackages: string[]\n}) {\n if (nodeModulesRegex.test(resolvedRes)) {\n const shouldBundlePages =\n !isAppLayer && config.bundlePagesRouterDependencies && !isOptOutBundling\n\n const shouldBeBundled =\n shouldBundlePages ||\n isResourceInPackages(\n resolvedRes,\n transpiledPackages,\n resolvedExternalPackageDirs\n )\n\n if (!shouldBeBundled) {\n return `${externalType} ${request}` // Externalize if not bundled or opted out\n }\n }\n}\n\n/**\n * @param localRes the full path to the file\n * @returns the externalized path\n * @description returns an externalized path if the file is a Next.js file and ends with either `.shared-runtime.js` or `.external.js`\n * This is used to ensure that files used across the rendering runtime(s) and the user code are one and the same. The logic in this function\n * will rewrite the require to the correct bundle location depending on the layer at which the file is being used.\n */\nfunction resolveNextExternal(localRes: string) {\n const isExternal = externalPattern.test(localRes)\n\n // if the file ends with .external, we need to make it a commonjs require in all cases\n // this is used mainly to share the async local storage across the routing, rendering and user layers.\n if (isExternal) {\n // it's important we return the path that starts with `next/dist/` here instead of the absolute path\n // otherwise NFT will get tripped up\n return `commonjs ${normalizePathSep(\n localRes.replace(/.*?next[/\\\\]dist/, 'next/dist')\n )}`\n }\n}\n"],"names":["defaultOverrides","BARREL_OPTIMIZATION_PREFIX","path","NODE_BASE_ESM_RESOLVE_OPTIONS","NODE_BASE_RESOLVE_OPTIONS","NODE_ESM_RESOLVE_OPTIONS","NODE_RESOLVE_OPTIONS","isWebpackBundledLayer","isWebpackServerOnlyLayer","normalizePathSep","reactPackagesRegex","pathSeparators","optionalEsmPart","externalFileEnd","nextDist","externalPattern","RegExp","nodeModulesRegex","isResourceInPackages","resource","packageNames","packageDirMapping","some","p","has","startsWith","get","sep","includes","join","replace","resolveExternal","dir","esmExternalsConfig","context","request","isEsmRequested","getResolve","isLocalCallback","baseResolveCheck","esmResolveOptions","nodeResolveOptions","baseEsmResolveOptions","baseResolveOptions","esmExternals","looseEsmExternals","res","isEsm","preferEsmOptions","preferEsm","resolveOptions","resolve","err","localRes","baseRes","baseIsEsm","baseResolve","makeExternalHandler","config","optOutBundlingPackageRegex","transpiledPackages","resolvedExternalPackageDirs","experimental","handleExternals","dependencyType","layer","isLocal","posix","isAbsolute","process","platform","win32","isAppLayer","test","notExternalModules","resolveNextExternal","resolveResult","undefined","isOptOutBundling","Error","externalType","Map","pkg","pkgRes","set","dirname","resolvedBundlingOptOutRes","resolveBundlingOptOutPackages","resolvedRes","shouldBundlePages","bundlePagesRouterDependencies","shouldBeBundled","isExternal"],"mappings":"AAGA,SAASA,gBAAgB,QAAQ,yBAAwB;AACzD,SAASC,0BAA0B,QAAQ,0BAAyB;AACpE,OAAOC,UAAU,gCAA+B;AAChD,SACEC,6BAA6B,EAC7BC,yBAA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AI,CAACpB;IAExC,sFAAsF;IACtF,sGAAsG;IACtG,IAAIuC,YAAY;QACd,oGAAoG;QACpG,oCAAoC;QACpC,OAAO,CAAC,SAAS,EAAEnF,iBACjB4C,SAASvB,OAAO,CAAC,oBAAoB,eACpC;IACL;AACF"}
|
package/dist/esm/build/index.js
CHANGED
@@ -296,7 +296,7 @@ export default async function build(dir, reactProductionProfiling = false, debug
|
|
296
296
|
const nextBuildSpan = trace('next-build', undefined, {
|
297
297
|
buildMode: experimentalBuildMode,
|
298
298
|
isTurboBuild: String(turboNextBuild),
|
299
|
-
version: "15.2.1-canary.
|
299
|
+
version: "15.2.1-canary.2"
|
300
300
|
});
|
301
301
|
NextBuildContext.nextBuildSpan = nextBuildSpan;
|
302
302
|
NextBuildContext.dir = dir;
|
@@ -655,7 +655,7 @@ export default async function build(dir, reactProductionProfiling = false, debug
|
|
655
655
|
// Files outside of the distDir can be "type": "module"
|
656
656
|
await writeFileUtf8(path.join(distDir, 'package.json'), '{"type": "commonjs"}');
|
657
657
|
// These are written to distDir, so they need to come after creating and cleaning distDr.
|
658
|
-
await recordFrameworkVersion("15.2.1-canary.
|
658
|
+
await recordFrameworkVersion("15.2.1-canary.2");
|
659
659
|
await updateBuildDiagnostics({
|
660
660
|
buildStage: 'start'
|
661
661
|
});
|
@@ -11,7 +11,7 @@ import { isDeepStrictEqual } from 'util';
|
|
11
11
|
import { getDefineEnv } from '../webpack/plugins/define-env-plugin';
|
12
12
|
import { getReactCompilerLoader } from '../get-babel-loader-config';
|
13
13
|
import { TurbopackInternalError } from '../../shared/lib/turbopack/utils';
|
14
|
-
const nextVersion = "15.2.1-canary.
|
14
|
+
const nextVersion = "15.2.1-canary.2";
|
15
15
|
const ArchName = arch();
|
16
16
|
const PlatformName = platform();
|
17
17
|
function infoLog(...args) {
|
@@ -4,10 +4,8 @@ import { BUILD_MANIFEST, MIDDLEWARE_BUILD_MANIFEST, CLIENT_STATIC_FILES_PATH, CL
|
|
4
4
|
import getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint';
|
5
5
|
import { ampFirstEntryNamesMap } from './next-drop-client-page-plugin';
|
6
6
|
import { getSortedRoutes } from '../../../shared/lib/router/utils';
|
7
|
-
import { spans as webpackSpans } from './profiling-plugin';
|
8
|
-
import { compilationSpans as rspackSpans } from './rspack-profiling-plugin';
|
9
7
|
import { Span } from '../../../trace';
|
10
|
-
|
8
|
+
import { getCompilationSpan } from '../utils';
|
11
9
|
// Add the runtime ssg manifest file as a lazy-loaded file dependency.
|
12
10
|
// We also stub this file out for development mode (when it is not
|
13
11
|
// generated).
|
@@ -53,7 +51,7 @@ export function normalizeRewritesForBuildManifest(rewrites) {
|
|
53
51
|
// This function takes the asset map generated in BuildManifestPlugin and creates a
|
54
52
|
// reduced version to send to the client.
|
55
53
|
export function generateClientManifest(assetMap, rewrites, clientRouterFilters, compiler, compilation) {
|
56
|
-
const compilationSpan = compilation ?
|
54
|
+
const compilationSpan = compilation ? getCompilationSpan(compilation) : compiler ? getCompilationSpan(compiler) : new Span({
|
57
55
|
name: 'client-manifest'
|
58
56
|
});
|
59
57
|
const genClientManifestSpan = compilationSpan == null ? void 0 : compilationSpan.traceChild('NextJsBuildManifest-generateClientManifest');
|
@@ -118,7 +116,7 @@ export default class BuildManifestPlugin {
|
|
118
116
|
this.rewrites.fallback = options.rewrites.fallback.map(processRoute);
|
119
117
|
}
|
120
118
|
createAssets(compiler, compilation) {
|
121
|
-
const compilationSpan =
|
119
|
+
const compilationSpan = getCompilationSpan(compilation) ?? getCompilationSpan(compiler);
|
122
120
|
if (!compilationSpan) {
|
123
121
|
throw Object.defineProperty(new Error('No span found for compilation'), "__NEXT_ERROR_CODE", {
|
124
122
|
value: "E646",
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/build/webpack/plugins/build-manifest-plugin.ts"],"sourcesContent":["import type { BloomFilter } from '../../../shared/lib/bloom-filter'\nimport type { Rewrite, CustomRoutes } from '../../../lib/load-custom-routes'\nimport devalue from 'next/dist/compiled/devalue'\nimport { webpack, sources } from 'next/dist/compiled/webpack/webpack'\nimport {\n BUILD_MANIFEST,\n MIDDLEWARE_BUILD_MANIFEST,\n CLIENT_STATIC_FILES_PATH,\n CLIENT_STATIC_FILES_RUNTIME_MAIN,\n CLIENT_STATIC_FILES_RUNTIME_MAIN_APP,\n CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL,\n CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,\n CLIENT_STATIC_FILES_RUNTIME_AMP,\n SYSTEM_ENTRYPOINTS,\n} from '../../../shared/lib/constants'\nimport type { BuildManifest } from '../../../server/get-page-files'\nimport getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint'\nimport { ampFirstEntryNamesMap } from './next-drop-client-page-plugin'\nimport { getSortedRoutes } from '../../../shared/lib/router/utils'\nimport { spans as webpackSpans } from './profiling-plugin'\nimport { compilationSpans as rspackSpans } from './rspack-profiling-plugin'\nimport { Span } from '../../../trace'\n\nconst compilationSpans = process.env.NEXT_RSPACK ? rspackSpans : webpackSpans\n\ntype DeepMutable<T> = { -readonly [P in keyof T]: DeepMutable<T[P]> }\n\nexport type ClientBuildManifest = {\n [key: string]: string[]\n}\n\n// Add the runtime ssg manifest file as a lazy-loaded file dependency.\n// We also stub this file out for development mode (when it is not\n// generated).\nexport const srcEmptySsgManifest = `self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()`\n\n// nodejs: '/static/<build id>/low-priority.js'\nfunction buildNodejsLowPriorityPath(filename: string, buildId: string) {\n return `${CLIENT_STATIC_FILES_PATH}/${buildId}/${filename}`\n}\n\nfunction createEdgeRuntimeManifest(originAssetMap: BuildManifest): string {\n const manifestFilenames = ['_buildManifest.js', '_ssgManifest.js']\n\n const assetMap: BuildManifest = {\n ...originAssetMap,\n lowPriorityFiles: [],\n }\n\n // we use globalThis here because middleware can be node\n // which doesn't have \"self\"\n const manifestDefCode = `globalThis.__BUILD_MANIFEST = ${JSON.stringify(\n assetMap,\n null,\n 2\n )};\\n`\n // edge lowPriorityFiles item: '\"/static/\" + process.env.__NEXT_BUILD_ID + \"/low-priority.js\"'.\n // Since lowPriorityFiles is not fixed and relying on `process.env.__NEXT_BUILD_ID`, we'll produce code creating it dynamically.\n const lowPriorityFilesCode =\n `globalThis.__BUILD_MANIFEST.lowPriorityFiles = [\\n` +\n manifestFilenames\n .map((filename) => {\n return `\"/static/\" + process.env.__NEXT_BUILD_ID + \"/${filename}\",\\n`\n })\n .join(',') +\n `\\n];`\n\n return manifestDefCode + lowPriorityFilesCode\n}\n\nfunction normalizeRewrite(item: {\n source: string\n destination: string\n has?: any\n}): CustomRoutes['rewrites']['beforeFiles'][0] {\n return {\n has: item.has,\n source: item.source,\n destination: item.destination,\n }\n}\n\nexport function normalizeRewritesForBuildManifest(\n rewrites: CustomRoutes['rewrites']\n): CustomRoutes['rewrites'] {\n return {\n afterFiles: rewrites.afterFiles\n ?.map(processRoute)\n ?.map((item) => normalizeRewrite(item)),\n beforeFiles: rewrites.beforeFiles\n ?.map(processRoute)\n ?.map((item) => normalizeRewrite(item)),\n fallback: rewrites.fallback\n ?.map(processRoute)\n ?.map((item) => normalizeRewrite(item)),\n }\n}\n\n// This function takes the asset map generated in BuildManifestPlugin and creates a\n// reduced version to send to the client.\nexport function generateClientManifest(\n assetMap: BuildManifest,\n rewrites: CustomRoutes['rewrites'],\n clientRouterFilters?: {\n staticFilter: ReturnType<BloomFilter['export']>\n dynamicFilter: ReturnType<BloomFilter['export']>\n },\n compiler?: any,\n compilation?: any\n): string | undefined {\n const compilationSpan = compilation\n ? compilationSpans.get(compilation)\n : compiler\n ? compilationSpans.get(compiler)\n : new Span({ name: 'client-manifest' })\n\n const genClientManifestSpan = compilationSpan?.traceChild(\n 'NextJsBuildManifest-generateClientManifest'\n )\n\n return genClientManifestSpan?.traceFn(() => {\n const clientManifest: ClientBuildManifest = {\n __rewrites: normalizeRewritesForBuildManifest(rewrites) as any,\n __routerFilterStatic: clientRouterFilters?.staticFilter as any,\n __routerFilterDynamic: clientRouterFilters?.dynamicFilter as any,\n }\n const appDependencies = new Set(assetMap.pages['/_app'])\n const sortedPageKeys = getSortedRoutes(Object.keys(assetMap.pages))\n\n sortedPageKeys.forEach((page) => {\n const dependencies = assetMap.pages[page]\n\n if (page === '/_app') return\n // Filter out dependencies in the _app entry, because those will have already\n // been loaded by the client prior to a navigation event\n const filteredDeps = dependencies.filter(\n (dep) => !appDependencies.has(dep)\n )\n\n // The manifest can omit the page if it has no requirements\n if (filteredDeps.length) {\n clientManifest[page] = filteredDeps\n }\n })\n // provide the sorted pages as an array so we don't rely on the object's keys\n // being in order and we don't slow down look-up time for page assets\n clientManifest.sortedPages = sortedPageKeys\n\n return devalue(clientManifest)\n })\n}\n\nexport function getEntrypointFiles(entrypoint: any): string[] {\n return (\n entrypoint\n ?.getFiles()\n .filter((file: string) => {\n // We don't want to include `.hot-update.js` files into the initial page\n return /(?<!\\.hot-update)\\.(js|css)($|\\?)/.test(file)\n })\n .map((file: string) => file.replace(/\\\\/g, '/')) ?? []\n )\n}\n\nexport const processRoute = (r: Rewrite) => {\n const rewrite = { ...r }\n\n // omit external rewrite destinations since these aren't\n // handled client-side\n if (!rewrite?.destination?.startsWith('/')) {\n delete (rewrite as any).destination\n }\n return rewrite\n}\n\n// This plugin creates a build-manifest.json for all assets that are being output\n// It has a mapping of \"entry\" filename to real filename. Because the real filename can be hashed in production\nexport default class BuildManifestPlugin {\n private buildId: string\n private rewrites: CustomRoutes['rewrites']\n private isDevFallback: boolean\n private appDirEnabled: boolean\n private clientRouterFilters?: Parameters<typeof generateClientManifest>[2]\n\n constructor(options: {\n buildId: string\n rewrites: CustomRoutes['rewrites']\n isDevFallback?: boolean\n appDirEnabled: boolean\n clientRouterFilters?: Parameters<typeof generateClientManifest>[2]\n }) {\n this.buildId = options.buildId\n this.isDevFallback = !!options.isDevFallback\n this.rewrites = {\n beforeFiles: [],\n afterFiles: [],\n fallback: [],\n }\n this.appDirEnabled = options.appDirEnabled\n this.clientRouterFilters = options.clientRouterFilters\n this.rewrites.beforeFiles = options.rewrites.beforeFiles.map(processRoute)\n this.rewrites.afterFiles = options.rewrites.afterFiles.map(processRoute)\n this.rewrites.fallback = options.rewrites.fallback.map(processRoute)\n }\n\n createAssets(compiler: any, compilation: any) {\n const compilationSpan =\n compilationSpans.get(compilation) ?? compilationSpans.get(compiler)\n if (!compilationSpan) {\n throw new Error('No span found for compilation')\n }\n\n const createAssetsSpan = compilationSpan.traceChild(\n 'NextJsBuildManifest-createassets'\n )\n\n return createAssetsSpan.traceFn(() => {\n const entrypoints: Map<string, any> = compilation.entrypoints\n const assetMap: DeepMutable<BuildManifest> = {\n polyfillFiles: [],\n devFiles: [],\n ampDevFiles: [],\n lowPriorityFiles: [],\n rootMainFiles: [],\n rootMainFilesTree: {},\n pages: { '/_app': [] },\n ampFirstPages: [],\n }\n\n const ampFirstEntryNames = ampFirstEntryNamesMap.get(compilation)\n if (ampFirstEntryNames) {\n for (const entryName of ampFirstEntryNames) {\n const pagePath = getRouteFromEntrypoint(entryName)\n if (!pagePath) {\n continue\n }\n\n assetMap.ampFirstPages.push(pagePath)\n }\n }\n\n const mainFiles = new Set(\n getEntrypointFiles(entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_MAIN))\n )\n\n if (this.appDirEnabled) {\n assetMap.rootMainFiles = [\n ...new Set(\n getEntrypointFiles(\n entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_MAIN_APP)\n )\n ),\n ]\n }\n\n const compilationAssets: {\n name: string\n source: typeof sources.RawSource\n info: object\n }[] = compilation.getAssets()\n\n assetMap.polyfillFiles = compilationAssets\n .filter((p) => {\n // Ensure only .js files are passed through\n if (!p.name.endsWith('.js')) {\n return false\n }\n\n return (\n p.info && CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL in p.info\n )\n })\n .map((v) => v.name)\n\n assetMap.devFiles = getEntrypointFiles(\n entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH)\n ).filter((file) => !mainFiles.has(file))\n\n assetMap.ampDevFiles = getEntrypointFiles(\n entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_AMP)\n )\n\n for (const entrypoint of compilation.entrypoints.values()) {\n if (SYSTEM_ENTRYPOINTS.has(entrypoint.name)) continue\n const pagePath = getRouteFromEntrypoint(entrypoint.name)\n\n if (!pagePath) {\n continue\n }\n\n const filesForPage = getEntrypointFiles(entrypoint)\n\n assetMap.pages[pagePath] = [...new Set([...mainFiles, ...filesForPage])]\n }\n\n if (!this.isDevFallback) {\n // Add the runtime build manifest file (generated later in this file)\n // as a dependency for the app. If the flag is false, the file won't be\n // downloaded by the client.\n const buildManifestPath = buildNodejsLowPriorityPath(\n '_buildManifest.js',\n this.buildId\n )\n const ssgManifestPath = buildNodejsLowPriorityPath(\n '_ssgManifest.js',\n this.buildId\n )\n assetMap.lowPriorityFiles.push(buildManifestPath, ssgManifestPath)\n compilation.emitAsset(\n ssgManifestPath,\n new sources.RawSource(srcEmptySsgManifest)\n )\n }\n\n assetMap.pages = Object.keys(assetMap.pages)\n .sort()\n .reduce(\n // eslint-disable-next-line\n (a, c) => ((a[c] = assetMap.pages[c]), a),\n {} as typeof assetMap.pages\n )\n\n let buildManifestName = BUILD_MANIFEST\n\n if (this.isDevFallback) {\n buildManifestName = `fallback-${BUILD_MANIFEST}`\n }\n\n compilation.emitAsset(\n buildManifestName,\n new sources.RawSource(JSON.stringify(assetMap, null, 2))\n )\n\n compilation.emitAsset(\n `server/${MIDDLEWARE_BUILD_MANIFEST}.js`,\n new sources.RawSource(`${createEdgeRuntimeManifest(assetMap)}`)\n )\n\n if (!this.isDevFallback) {\n compilation.emitAsset(\n `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js`,\n new sources.RawSource(\n `self.__BUILD_MANIFEST = ${generateClientManifest(\n assetMap,\n this.rewrites,\n this.clientRouterFilters,\n compiler,\n compilation\n )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()`\n )\n )\n }\n })\n }\n\n apply(compiler: webpack.Compiler) {\n compiler.hooks.make.tap('NextJsBuildManifest', (compilation: any) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'NextJsBuildManifest',\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n () => {\n this.createAssets(compiler, compilation)\n }\n )\n })\n return\n }\n}\n"],"names":["devalue","webpack","sources","BUILD_MANIFEST","MIDDLEWARE_BUILD_MANIFEST","CLIENT_STATIC_FILES_PATH","CLIENT_STATIC_FILES_RUNTIME_MAIN","CLIENT_STATIC_FILES_RUNTIME_MAIN_APP","CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL","CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH","CLIENT_STATIC_FILES_RUNTIME_AMP","SYSTEM_ENTRYPOINTS","getRouteFromEntrypoint","ampFirstEntryNamesMap","getSortedRoutes","spans","webpackSpans","compilationSpans","rspackSpans","Span","process","env","NEXT_RSPACK","srcEmptySsgManifest","buildNodejsLowPriorityPath","filename","buildId","createEdgeRuntimeManifest","originAssetMap","manifestFilenames","assetMap","lowPriorityFiles","manifestDefCode","JSON","stringify","lowPriorityFilesCode","map","join","normalizeRewrite","item","has","source","destination","normalizeRewritesForBuildManifest","rewrites","afterFiles","processRoute","beforeFiles","fallback","generateClientManifest","clientRouterFilters","compiler","compilation","compilationSpan","get","name","genClientManifestSpan","traceChild","traceFn","clientManifest","__rewrites","__routerFilterStatic","staticFilter","__routerFilterDynamic","dynamicFilter","appDependencies","Set","pages","sortedPageKeys","Object","keys","forEach","page","dependencies","filteredDeps","filter","dep","length","sortedPages","getEntrypointFiles","entrypoint","getFiles","file","test","replace","r","rewrite","startsWith","BuildManifestPlugin","constructor","options","isDevFallback","appDirEnabled","createAssets","Error","createAssetsSpan","entrypoints","polyfillFiles","devFiles","ampDevFiles","rootMainFiles","rootMainFilesTree","ampFirstPages","ampFirstEntryNames","entryName","pagePath","push","mainFiles","compilationAssets","getAssets","p","endsWith","info","v","values","filesForPage","buildManifestPath","ssgManifestPath","emitAsset","RawSource","sort","reduce","a","c","buildManifestName","apply","hooks","make","tap","processAssets","stage","Compilation","PROCESS_ASSETS_STAGE_ADDITIONS"],"mappings":"AAEA,OAAOA,aAAa,6BAA4B;AAChD,SAASC,OAAO,EAAEC,OAAO,QAAQ,qCAAoC;AACrE,SACEC,cAAc,EACdC,yBAAyB,EACzBC,wBAAwB,EACxBC,gCAAgC,EAChCC,oCAAoC,EACpCC,4CAA4C,EAC5CC,yCAAyC,EACzCC,+BAA+B,EAC/BC,kBAAkB,QACb,gCAA+B;AAEtC,OAAOC,4BAA4B,4CAA2C;AAC9E,SAASC,qBAAqB,QAAQ,iCAAgC;AACtE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,SAASC,YAAY,QAAQ,qBAAoB;AAC1D,SAASC,oBAAoBC,WAAW,QAAQ,4BAA2B;AAC3E,SAASC,IAAI,QAAQ,iBAAgB;AAErC,MAAMF,mBAAmBG,QAAQC,GAAG,CAACC,WAAW,GAAGJ,cAAcF;AAQjE,sEAAsE;AACtE,kEAAkE;AAClE,cAAc;AACd,OAAO,MAAMO,sBAAsB,CAAC,4EAA4E,CAAC,CAAA;AAEjH,+CAA+C;AAC/C,SAASC,2BAA2BC,QAAgB,EAAEC,OAAe;IACnE,OAAO,GAAGrB,yBAAyB,CAAC,EAAEqB,QAAQ,CAAC,EAAED,UAAU;AAC7D;AAEA,SAASE,0BAA0BC,cAA6B;IAC9D,MAAMC,oBAAoB;QAAC;QAAqB;KAAkB;IAElE,MAAMC,WAA0B;QAC9B,GAAGF,cAAc;QACjBG,kBAAkB,EAAE;IACtB;IAEA,wDAAwD;IACxD,4BAA4B;IAC5B,MAAMC,kBAAkB,CAAC,8BAA8B,EAAEC,KAAKC,SAAS,CACrEJ,UACA,MACA,GACA,GAAG,CAAC;IACN,+FAA+F;IAC/F,gIAAgI;IAChI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AAG,CAAC,uBAAuB,CAAC5E;YAC9CA,YAAY0E,KAAK,CAACG,aAAa,CAACD,GAAG,CACjC;gBACEzE,MAAM;gBACN2E,OAAOjI,QAAQkI,WAAW,CAACC,8BAA8B;YAC3D,GACA;gBACE,IAAI,CAACvC,YAAY,CAAC1C,UAAUC;YAC9B;QAEJ;QACA;IACF;AACF"}
|
1
|
+
{"version":3,"sources":["../../../../src/build/webpack/plugins/build-manifest-plugin.ts"],"sourcesContent":["import type { BloomFilter } from '../../../shared/lib/bloom-filter'\nimport type { Rewrite, CustomRoutes } from '../../../lib/load-custom-routes'\nimport devalue from 'next/dist/compiled/devalue'\nimport { webpack, sources } from 'next/dist/compiled/webpack/webpack'\nimport {\n BUILD_MANIFEST,\n MIDDLEWARE_BUILD_MANIFEST,\n CLIENT_STATIC_FILES_PATH,\n CLIENT_STATIC_FILES_RUNTIME_MAIN,\n CLIENT_STATIC_FILES_RUNTIME_MAIN_APP,\n CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL,\n CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH,\n CLIENT_STATIC_FILES_RUNTIME_AMP,\n SYSTEM_ENTRYPOINTS,\n} from '../../../shared/lib/constants'\nimport type { BuildManifest } from '../../../server/get-page-files'\nimport getRouteFromEntrypoint from '../../../server/get-route-from-entrypoint'\nimport { ampFirstEntryNamesMap } from './next-drop-client-page-plugin'\nimport { getSortedRoutes } from '../../../shared/lib/router/utils'\nimport { Span } from '../../../trace'\nimport { getCompilationSpan } from '../utils'\n\ntype DeepMutable<T> = { -readonly [P in keyof T]: DeepMutable<T[P]> }\n\nexport type ClientBuildManifest = {\n [key: string]: string[]\n}\n\n// Add the runtime ssg manifest file as a lazy-loaded file dependency.\n// We also stub this file out for development mode (when it is not\n// generated).\nexport const srcEmptySsgManifest = `self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()`\n\n// nodejs: '/static/<build id>/low-priority.js'\nfunction buildNodejsLowPriorityPath(filename: string, buildId: string) {\n return `${CLIENT_STATIC_FILES_PATH}/${buildId}/${filename}`\n}\n\nfunction createEdgeRuntimeManifest(originAssetMap: BuildManifest): string {\n const manifestFilenames = ['_buildManifest.js', '_ssgManifest.js']\n\n const assetMap: BuildManifest = {\n ...originAssetMap,\n lowPriorityFiles: [],\n }\n\n // we use globalThis here because middleware can be node\n // which doesn't have \"self\"\n const manifestDefCode = `globalThis.__BUILD_MANIFEST = ${JSON.stringify(\n assetMap,\n null,\n 2\n )};\\n`\n // edge lowPriorityFiles item: '\"/static/\" + process.env.__NEXT_BUILD_ID + \"/low-priority.js\"'.\n // Since lowPriorityFiles is not fixed and relying on `process.env.__NEXT_BUILD_ID`, we'll produce code creating it dynamically.\n const lowPriorityFilesCode =\n `globalThis.__BUILD_MANIFEST.lowPriorityFiles = [\\n` +\n manifestFilenames\n .map((filename) => {\n return `\"/static/\" + process.env.__NEXT_BUILD_ID + \"/${filename}\",\\n`\n })\n .join(',') +\n `\\n];`\n\n return manifestDefCode + lowPriorityFilesCode\n}\n\nfunction normalizeRewrite(item: {\n source: string\n destination: string\n has?: any\n}): CustomRoutes['rewrites']['beforeFiles'][0] {\n return {\n has: item.has,\n source: item.source,\n destination: item.destination,\n }\n}\n\nexport function normalizeRewritesForBuildManifest(\n rewrites: CustomRoutes['rewrites']\n): CustomRoutes['rewrites'] {\n return {\n afterFiles: rewrites.afterFiles\n ?.map(processRoute)\n ?.map((item) => normalizeRewrite(item)),\n beforeFiles: rewrites.beforeFiles\n ?.map(processRoute)\n ?.map((item) => normalizeRewrite(item)),\n fallback: rewrites.fallback\n ?.map(processRoute)\n ?.map((item) => normalizeRewrite(item)),\n }\n}\n\n// This function takes the asset map generated in BuildManifestPlugin and creates a\n// reduced version to send to the client.\nexport function generateClientManifest(\n assetMap: BuildManifest,\n rewrites: CustomRoutes['rewrites'],\n clientRouterFilters?: {\n staticFilter: ReturnType<BloomFilter['export']>\n dynamicFilter: ReturnType<BloomFilter['export']>\n },\n compiler?: any,\n compilation?: any\n): string | undefined {\n const compilationSpan = compilation\n ? getCompilationSpan(compilation)\n : compiler\n ? getCompilationSpan(compiler)\n : new Span({ name: 'client-manifest' })\n\n const genClientManifestSpan = compilationSpan?.traceChild(\n 'NextJsBuildManifest-generateClientManifest'\n )\n\n return genClientManifestSpan?.traceFn(() => {\n const clientManifest: ClientBuildManifest = {\n __rewrites: normalizeRewritesForBuildManifest(rewrites) as any,\n __routerFilterStatic: clientRouterFilters?.staticFilter as any,\n __routerFilterDynamic: clientRouterFilters?.dynamicFilter as any,\n }\n const appDependencies = new Set(assetMap.pages['/_app'])\n const sortedPageKeys = getSortedRoutes(Object.keys(assetMap.pages))\n\n sortedPageKeys.forEach((page) => {\n const dependencies = assetMap.pages[page]\n\n if (page === '/_app') return\n // Filter out dependencies in the _app entry, because those will have already\n // been loaded by the client prior to a navigation event\n const filteredDeps = dependencies.filter(\n (dep) => !appDependencies.has(dep)\n )\n\n // The manifest can omit the page if it has no requirements\n if (filteredDeps.length) {\n clientManifest[page] = filteredDeps\n }\n })\n // provide the sorted pages as an array so we don't rely on the object's keys\n // being in order and we don't slow down look-up time for page assets\n clientManifest.sortedPages = sortedPageKeys\n\n return devalue(clientManifest)\n })\n}\n\nexport function getEntrypointFiles(entrypoint: any): string[] {\n return (\n entrypoint\n ?.getFiles()\n .filter((file: string) => {\n // We don't want to include `.hot-update.js` files into the initial page\n return /(?<!\\.hot-update)\\.(js|css)($|\\?)/.test(file)\n })\n .map((file: string) => file.replace(/\\\\/g, '/')) ?? []\n )\n}\n\nexport const processRoute = (r: Rewrite) => {\n const rewrite = { ...r }\n\n // omit external rewrite destinations since these aren't\n // handled client-side\n if (!rewrite?.destination?.startsWith('/')) {\n delete (rewrite as any).destination\n }\n return rewrite\n}\n\n// This plugin creates a build-manifest.json for all assets that are being output\n// It has a mapping of \"entry\" filename to real filename. Because the real filename can be hashed in production\nexport default class BuildManifestPlugin {\n private buildId: string\n private rewrites: CustomRoutes['rewrites']\n private isDevFallback: boolean\n private appDirEnabled: boolean\n private clientRouterFilters?: Parameters<typeof generateClientManifest>[2]\n\n constructor(options: {\n buildId: string\n rewrites: CustomRoutes['rewrites']\n isDevFallback?: boolean\n appDirEnabled: boolean\n clientRouterFilters?: Parameters<typeof generateClientManifest>[2]\n }) {\n this.buildId = options.buildId\n this.isDevFallback = !!options.isDevFallback\n this.rewrites = {\n beforeFiles: [],\n afterFiles: [],\n fallback: [],\n }\n this.appDirEnabled = options.appDirEnabled\n this.clientRouterFilters = options.clientRouterFilters\n this.rewrites.beforeFiles = options.rewrites.beforeFiles.map(processRoute)\n this.rewrites.afterFiles = options.rewrites.afterFiles.map(processRoute)\n this.rewrites.fallback = options.rewrites.fallback.map(processRoute)\n }\n\n createAssets(compiler: any, compilation: any) {\n const compilationSpan =\n getCompilationSpan(compilation) ?? getCompilationSpan(compiler)\n if (!compilationSpan) {\n throw new Error('No span found for compilation')\n }\n\n const createAssetsSpan = compilationSpan.traceChild(\n 'NextJsBuildManifest-createassets'\n )\n\n return createAssetsSpan.traceFn(() => {\n const entrypoints: Map<string, any> = compilation.entrypoints\n const assetMap: DeepMutable<BuildManifest> = {\n polyfillFiles: [],\n devFiles: [],\n ampDevFiles: [],\n lowPriorityFiles: [],\n rootMainFiles: [],\n rootMainFilesTree: {},\n pages: { '/_app': [] },\n ampFirstPages: [],\n }\n\n const ampFirstEntryNames = ampFirstEntryNamesMap.get(compilation)\n if (ampFirstEntryNames) {\n for (const entryName of ampFirstEntryNames) {\n const pagePath = getRouteFromEntrypoint(entryName)\n if (!pagePath) {\n continue\n }\n\n assetMap.ampFirstPages.push(pagePath)\n }\n }\n\n const mainFiles = new Set(\n getEntrypointFiles(entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_MAIN))\n )\n\n if (this.appDirEnabled) {\n assetMap.rootMainFiles = [\n ...new Set(\n getEntrypointFiles(\n entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_MAIN_APP)\n )\n ),\n ]\n }\n\n const compilationAssets: {\n name: string\n source: typeof sources.RawSource\n info: object\n }[] = compilation.getAssets()\n\n assetMap.polyfillFiles = compilationAssets\n .filter((p) => {\n // Ensure only .js files are passed through\n if (!p.name.endsWith('.js')) {\n return false\n }\n\n return (\n p.info && CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL in p.info\n )\n })\n .map((v) => v.name)\n\n assetMap.devFiles = getEntrypointFiles(\n entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH)\n ).filter((file) => !mainFiles.has(file))\n\n assetMap.ampDevFiles = getEntrypointFiles(\n entrypoints.get(CLIENT_STATIC_FILES_RUNTIME_AMP)\n )\n\n for (const entrypoint of compilation.entrypoints.values()) {\n if (SYSTEM_ENTRYPOINTS.has(entrypoint.name)) continue\n const pagePath = getRouteFromEntrypoint(entrypoint.name)\n\n if (!pagePath) {\n continue\n }\n\n const filesForPage = getEntrypointFiles(entrypoint)\n\n assetMap.pages[pagePath] = [...new Set([...mainFiles, ...filesForPage])]\n }\n\n if (!this.isDevFallback) {\n // Add the runtime build manifest file (generated later in this file)\n // as a dependency for the app. If the flag is false, the file won't be\n // downloaded by the client.\n const buildManifestPath = buildNodejsLowPriorityPath(\n '_buildManifest.js',\n this.buildId\n )\n const ssgManifestPath = buildNodejsLowPriorityPath(\n '_ssgManifest.js',\n this.buildId\n )\n assetMap.lowPriorityFiles.push(buildManifestPath, ssgManifestPath)\n compilation.emitAsset(\n ssgManifestPath,\n new sources.RawSource(srcEmptySsgManifest)\n )\n }\n\n assetMap.pages = Object.keys(assetMap.pages)\n .sort()\n .reduce(\n // eslint-disable-next-line\n (a, c) => ((a[c] = assetMap.pages[c]), a),\n {} as typeof assetMap.pages\n )\n\n let buildManifestName = BUILD_MANIFEST\n\n if (this.isDevFallback) {\n buildManifestName = `fallback-${BUILD_MANIFEST}`\n }\n\n compilation.emitAsset(\n buildManifestName,\n new sources.RawSource(JSON.stringify(assetMap, null, 2))\n )\n\n compilation.emitAsset(\n `server/${MIDDLEWARE_BUILD_MANIFEST}.js`,\n new sources.RawSource(`${createEdgeRuntimeManifest(assetMap)}`)\n )\n\n if (!this.isDevFallback) {\n compilation.emitAsset(\n `${CLIENT_STATIC_FILES_PATH}/${this.buildId}/_buildManifest.js`,\n new sources.RawSource(\n `self.__BUILD_MANIFEST = ${generateClientManifest(\n assetMap,\n this.rewrites,\n this.clientRouterFilters,\n compiler,\n compilation\n )};self.__BUILD_MANIFEST_CB && self.__BUILD_MANIFEST_CB()`\n )\n )\n }\n })\n }\n\n apply(compiler: webpack.Compiler) {\n compiler.hooks.make.tap('NextJsBuildManifest', (compilation: any) => {\n compilation.hooks.processAssets.tap(\n {\n name: 'NextJsBuildManifest',\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,\n },\n () => {\n this.createAssets(compiler, compilation)\n }\n )\n })\n return\n }\n}\n"],"names":["devalue","webpack","sources","BUILD_MANIFEST","MIDDLEWARE_BUILD_MANIFEST","CLIENT_STATIC_FILES_PATH","CLIENT_STATIC_FILES_RUNTIME_MAIN","CLIENT_STATIC_FILES_RUNTIME_MAIN_APP","CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL","CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH","CLIENT_STATIC_FILES_RUNTIME_AMP","SYSTEM_ENTRYPOINTS","getRouteFromEntrypoint","ampFirstEntryNamesMap","getSortedRoutes","Span","getCompilationSpan","srcEmptySsgManifest","buildNodejsLowPriorityPath","filename","buildId","createEdgeRuntimeManifest","originAssetMap","manifestFilenames","assetMap","lowPriorityFiles","manifestDefCode","JSON","stringify","lowPriorityFilesCode","map","join","normalizeRewrite","item","has","source","destination","normalizeRewritesForBuildManifest","rewrites","afterFiles","processRoute","beforeFiles","fallback","generateClientManifest","clientRouterFilters","compiler","compilation","compilationSpan","name","genClientManifestSpan","traceChild","traceFn","clientManifest","__rewrites","__routerFilterStatic","staticFilter","__routerFilterDynamic","dynamicFilter","appDependencies","Set","pages","sortedPageKeys","Object","keys","forEach","page","dependencies","filteredDeps","filter","dep","length","sortedPages","getEntrypointFiles","entrypoint","getFiles","file","test","replace","r","rewrite","startsWith","BuildManifestPlugin","constructor","options","isDevFallback","appDirEnabled","createAssets","Error","createAssetsSpan","entrypoints","polyfillFiles","devFiles","ampDevFiles","rootMainFiles","rootMainFilesTree","ampFirstPages","ampFirstEntryNames","get","entryName","pagePath","push","mainFiles","compilationAssets","getAssets","p","endsWith","info","v","values","filesForPage","buildManifestPath","ssgManifestPath","emitAsset","RawSource","sort","reduce","a","c","buildManifestName","apply","hooks","make","tap","processAssets","stage","Compilation","PROCESS_ASSETS_STAGE_ADDITIONS"],"mappings":"AAEA,OAAOA,aAAa,6BAA4B;AAChD,SAASC,OAAO,EAAEC,OAAO,QAAQ,qCAAoC;AACrE,SACEC,cAAc,EACdC,yBAAyB,EACzBC,wBAAwB,EACxBC,gCAAgC,EAChCC,oCAAoC,EACpCC,4CAA4C,EAC5CC,yCAAyC,EACzCC,+BAA+B,EAC/BC,kBAAkB,QACb,gCAA+B;AAEtC,OAAOC,4BAA4B,4CAA2C;AAC9E,SAASC,qBAAqB,QAAQ,iCAAgC;AACtE,SAASC,eAAe,QAAQ,mCAAkC;AAClE,SAASC,IAAI,QAAQ,iBAAgB;AACrC,SAASC,kBAAkB,QAAQ,WAAU;AAQ7C,sEAAsE;AACtE,kEAAkE;AAClE,cAAc;AACd,OAAO,MAAMC,sBAAsB,CAAC,4EAA4E,CAAC,CAAA;AAEjH,+CAA+C;AAC/C,SAASC,2BAA2BC,QAAgB,EAAEC,OAAe;IACnE,OAAO,GAAGf,yBAAyB,CAAC,EAAEe,QAAQ,CAAC,EAAED,UAAU;AAC7D;AAEA,SAASE,0BAA0BC,cAA6B;IAC9D,MAAMC,oBAAoB;QAAC;QAAqB;KAAkB;IAElE,MAAMC,WAA0B;QAC9B,GAAGF,cAAc;QACjBG,kBAAkB,EAAE;IACtB;IAEA,wDAAwD;IACxD,4BAA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AC;YAGhE;QACF;IACF;IAEAyE,MAAM1E,QAA0B,EAAE;QAChCA,SAAS2E,KAAK,CAACC,IAAI,CAACC,GAAG,CAAC,uBAAuB,CAAC5E;YAC9CA,YAAY0E,KAAK,CAACG,aAAa,CAACD,GAAG,CACjC;gBACE1E,MAAM;gBACN4E,OAAO3H,QAAQ4H,WAAW,CAACC,8BAA8B;YAC3D,GACA;gBACE,IAAI,CAACxC,YAAY,CAACzC,UAAUC;YAC9B;QAEJ;QACA;IACF;AACF"}
|
@@ -2,7 +2,7 @@ import cssnanoSimple from 'next/dist/compiled/cssnano-simple';
|
|
2
2
|
import postcssScss from 'next/dist/compiled/postcss-scss';
|
3
3
|
import postcss from 'postcss';
|
4
4
|
import { webpack, sources } from 'next/dist/compiled/webpack/webpack';
|
5
|
-
import {
|
5
|
+
import { getCompilationSpan } from '../utils';
|
6
6
|
// https://github.com/NMFR/optimize-css-assets-webpack-plugin/blob/0a410a9bf28c7b0e81a3470a13748e68ca2f50aa/src/index.js#L20
|
7
7
|
const CSS_REGEX = /\.css(\?.*)?$/i;
|
8
8
|
export class CssMinimizerPlugin {
|
@@ -47,7 +47,7 @@ export class CssMinimizerPlugin {
|
|
47
47
|
name: 'CssMinimizerPlugin',
|
48
48
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
49
49
|
}, async (assets)=>{
|
50
|
-
const compilationSpan =
|
50
|
+
const compilationSpan = getCompilationSpan(compilation) || getCompilationSpan(compiler);
|
51
51
|
const cssMinimizerSpan = compilationSpan.traceChild('css-minimizer-plugin');
|
52
52
|
return cssMinimizerSpan.traceAsyncFn(async ()=>{
|
53
53
|
const files = Object.keys(assets);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../src/build/webpack/plugins/css-minimizer-plugin.ts"],"sourcesContent":["import cssnanoSimple from 'next/dist/compiled/cssnano-simple'\nimport postcssScss from 'next/dist/compiled/postcss-scss'\nimport postcss from 'postcss'\nimport type { Parser } from 'postcss'\nimport { webpack, sources } from 'next/dist/compiled/webpack/webpack'\nimport {
|
1
|
+
{"version":3,"sources":["../../../../src/build/webpack/plugins/css-minimizer-plugin.ts"],"sourcesContent":["import cssnanoSimple from 'next/dist/compiled/cssnano-simple'\nimport postcssScss from 'next/dist/compiled/postcss-scss'\nimport postcss from 'postcss'\nimport type { Parser } from 'postcss'\nimport { webpack, sources } from 'next/dist/compiled/webpack/webpack'\nimport { getCompilationSpan } from '../utils'\n\n// https://github.com/NMFR/optimize-css-assets-webpack-plugin/blob/0a410a9bf28c7b0e81a3470a13748e68ca2f50aa/src/index.js#L20\nconst CSS_REGEX = /\\.css(\\?.*)?$/i\n\ntype CssMinimizerPluginOptions = {\n postcssOptions: {\n map: false | { prev?: string | false; inline: boolean; annotation: boolean }\n }\n}\n\nexport class CssMinimizerPlugin {\n __next_css_remove = true\n\n private options: CssMinimizerPluginOptions\n\n constructor(options: CssMinimizerPluginOptions) {\n this.options = options\n }\n\n optimizeAsset(file: string, asset: any) {\n const postcssOptions = {\n ...this.options.postcssOptions,\n to: file,\n from: file,\n\n // We don't actually add this parser to support Sass. It can also be used\n // for inline comment support. See the README:\n // https://github.com/postcss/postcss-scss/blob/master/README.md#2-inline-comments-for-postcss\n parser: postcssScss as any as Parser,\n }\n\n let input: string\n if (postcssOptions.map && asset.sourceAndMap) {\n const { source, map } = asset.sourceAndMap()\n input = source\n postcssOptions.map.prev = map ? map : false\n } else {\n input = asset.source()\n }\n\n return postcss([cssnanoSimple({ colormin: false }, postcss)])\n .process(input, postcssOptions)\n .then((res) => {\n if (res.map) {\n return new sources.SourceMapSource(res.css, file, res.map.toJSON())\n } else {\n return new sources.RawSource(res.css)\n }\n })\n }\n\n apply(compiler: webpack.Compiler) {\n compiler.hooks.compilation.tap('CssMinimizerPlugin', (compilation: any) => {\n const cache = compilation.getCache('CssMinimizerPlugin')\n compilation.hooks.processAssets.tapPromise(\n {\n name: 'CssMinimizerPlugin',\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,\n },\n async (assets: any) => {\n const compilationSpan =\n getCompilationSpan(compilation) || getCompilationSpan(compiler)\n const cssMinimizerSpan = compilationSpan!.traceChild(\n 'css-minimizer-plugin'\n )\n\n return cssMinimizerSpan.traceAsyncFn(async () => {\n const files = Object.keys(assets)\n await Promise.all(\n files\n .filter((file) => CSS_REGEX.test(file))\n .map(async (file) => {\n const assetSpan = cssMinimizerSpan.traceChild('minify-css')\n assetSpan.setAttribute('file', file)\n\n return assetSpan.traceAsyncFn(async () => {\n const assetSource = compilation.getAsset(file).source\n const etag = cache.getLazyHashedEtag(assetSource)\n const cachedResult = await cache.getPromise(file, etag)\n\n assetSpan.setAttribute(\n 'cache',\n cachedResult ? 'HIT' : 'MISS'\n )\n if (cachedResult) {\n compilation.updateAsset(file, cachedResult)\n return\n }\n\n const result = await this.optimizeAsset(file, assetSource)\n await cache.storePromise(file, etag, result)\n compilation.updateAsset(file, result)\n })\n })\n )\n })\n }\n )\n })\n }\n}\n"],"names":["cssnanoSimple","postcssScss","postcss","webpack","sources","getCompilationSpan","CSS_REGEX","CssMinimizerPlugin","constructor","options","__next_css_remove","optimizeAsset","file","asset","postcssOptions","to","from","parser","input","map","sourceAndMap","source","prev","colormin","process","then","res","SourceMapSource","css","toJSON","RawSource","apply","compiler","hooks","compilation","tap","cache","getCache","processAssets","tapPromise","name","stage","Compilation","PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE","assets","compilationSpan","cssMinimizerSpan","traceChild","traceAsyncFn","files","Object","keys","Promise","all","filter","test","assetSpan","setAttribute","assetSource","getAsset","etag","getLazyHashedEtag","cachedResult","getPromise","updateAsset","result","storePromise"],"mappings":"AAAA,OAAOA,mBAAmB,oCAAmC;AAC7D,OAAOC,iBAAiB,kCAAiC;AACzD,OAAOC,aAAa,UAAS;AAE7B,SAASC,OAAO,EAAEC,OAAO,QAAQ,qCAAoC;AACrE,SAASC,kBAAkB,QAAQ,WAAU;AAE7C,4HA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AAMc,mBAAmBD,gBAAiBE,UAAU,CAClD;gBAGF,OAAOD,iBAAiBE,YAAY,CAAC;oBACnC,MAAMC,QAAQC,OAAOC,IAAI,CAACP;oBAC1B,MAAMQ,QAAQC,GAAG,CACfJ,MACGK,MAAM,CAAC,CAAC1C,OAASN,UAAUiD,IAAI,CAAC3C,OAChCO,GAAG,CAAC,OAAOP;wBACV,MAAM4C,YAAYV,iBAAiBC,UAAU,CAAC;wBAC9CS,UAAUC,YAAY,CAAC,QAAQ7C;wBAE/B,OAAO4C,UAAUR,YAAY,CAAC;4BAC5B,MAAMU,cAAcxB,YAAYyB,QAAQ,CAAC/C,MAAMS,MAAM;4BACrD,MAAMuC,OAAOxB,MAAMyB,iBAAiB,CAACH;4BACrC,MAAMI,eAAe,MAAM1B,MAAM2B,UAAU,CAACnD,MAAMgD;4BAElDJ,UAAUC,YAAY,CACpB,SACAK,eAAe,QAAQ;4BAEzB,IAAIA,cAAc;gCAChB5B,YAAY8B,WAAW,CAACpD,MAAMkD;gCAC9B;4BACF;4BAEA,MAAMG,SAAS,MAAM,IAAI,CAACtD,aAAa,CAACC,MAAM8C;4BAC9C,MAAMtB,MAAM8B,YAAY,CAACtD,MAAMgD,MAAMK;4BACrC/B,YAAY8B,WAAW,CAACpD,MAAMqD;wBAChC;oBACF;gBAEN;YACF;QAEJ;IACF;AACF"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { webpack, ModuleFilenameHelpers, sources, WebpackError } from 'next/dist/compiled/webpack/webpack';
|
2
2
|
import pLimit from 'next/dist/compiled/p-limit';
|
3
|
-
import {
|
3
|
+
import { getCompilationSpan } from '../../../utils';
|
4
4
|
function buildError(error, file) {
|
5
5
|
if (error.line) {
|
6
6
|
return new WebpackError(`${file} from Minifier\n${error.message} [${file}:${error.line},${error.col}]${error.stack ? `\n${error.stack.split('\n').slice(1).join('\n')}` : ''}`);
|
@@ -17,7 +17,7 @@ export class MinifyPlugin {
|
|
17
17
|
}
|
18
18
|
async optimize(compiler, compilation, assets, cache, { SourceMapSource, RawSource }) {
|
19
19
|
const mangle = !this.options.noMangling;
|
20
|
-
const compilationSpan =
|
20
|
+
const compilationSpan = getCompilationSpan(compilation) || getCompilationSpan(compiler);
|
21
21
|
const MinifierSpan = compilationSpan.traceChild('minify-webpack-plugin-optimize');
|
22
22
|
if (compilation.name) {
|
23
23
|
MinifierSpan.setAttribute('compilationName', compilation.name);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/build/webpack/plugins/minify-webpack-plugin/src/index.ts"],"sourcesContent":["import {\n webpack,\n ModuleFilenameHelpers,\n sources,\n WebpackError,\n type CacheFacade,\n type Compilation,\n} from 'next/dist/compiled/webpack/webpack'\nimport pLimit from 'next/dist/compiled/p-limit'\nimport { spans } from '../../profiling-plugin'\n\nfunction buildError(error: any, file: string) {\n if (error.line) {\n return new WebpackError(\n `${file} from Minifier\\n${error.message} [${file}:${error.line},${\n error.col\n }]${\n error.stack ? `\\n${error.stack.split('\\n').slice(1).join('\\n')}` : ''\n }`\n )\n }\n\n if (error.stack) {\n return new WebpackError(\n `${file} from Minifier\\n${error.message}\\n${error.stack}`\n )\n }\n\n return new WebpackError(`${file} from Minifier\\n${error.message}`)\n}\n\nconst debugMinify = process.env.NEXT_DEBUG_MINIFY\n\nexport class MinifyPlugin {\n constructor(private options: { noMangling?: boolean }) {}\n\n async optimize(\n compiler: any,\n compilation: Compilation,\n assets: any,\n cache: CacheFacade,\n {\n SourceMapSource,\n RawSource,\n }: {\n SourceMapSource: typeof sources.SourceMapSource\n RawSource: typeof sources.RawSource\n }\n ) {\n const mangle = !this.options.noMangling\n const compilationSpan = spans.get(compilation)! || spans.get(compiler)\n\n const MinifierSpan = compilationSpan.traceChild(\n 'minify-webpack-plugin-optimize'\n )\n\n if (compilation.name) {\n MinifierSpan.setAttribute('compilationName', compilation.name)\n }\n\n MinifierSpan.setAttribute('mangle', String(mangle))\n\n return MinifierSpan.traceAsyncFn(async () => {\n const assetsList = Object.keys(assets)\n\n const assetsForMinify = await Promise.all(\n assetsList\n .filter((name) => {\n if (\n !ModuleFilenameHelpers.matchObject.bind(\n // eslint-disable-next-line no-undefined\n undefined,\n { test: /\\.[cm]?js(\\?.*)?$/i }\n )(name)\n ) {\n return false\n }\n\n const res = compilation.getAsset(name)\n if (!res) {\n console.log(name)\n return false\n }\n\n const { info } = res\n\n // Skip double minimize assets from child compilation\n if (info.minimized) {\n return false\n }\n\n return true\n })\n .map(async (name) => {\n const { info, source } = compilation.getAsset(name)!\n\n const eTag = cache.mergeEtags(\n cache.getLazyHashedEtag(source),\n JSON.stringify(this.options)\n )\n\n const output = await cache.getPromise<\n { source: sources.Source } | undefined\n >(name, eTag)\n\n if (debugMinify && debugMinify === '1') {\n console.log(\n JSON.stringify({ name, source: source.source().toString() }),\n { breakLength: Infinity, maxStringLength: Infinity }\n )\n }\n return { name, info, inputSource: source, output, eTag }\n })\n )\n\n let initializedWorker: any\n\n // eslint-disable-next-line consistent-return\n const getWorker = () => {\n return {\n minify: async (options: {\n input: string\n inputSourceMap: Object\n }) => {\n const result = await (\n require('../../../../swc') as typeof import('../../../../swc')\n ).minify(options.input, {\n ...(options.inputSourceMap\n ? {\n sourceMap: {\n content: JSON.stringify(options.inputSourceMap),\n },\n }\n : {}),\n // Compress options are defined in crates/napi/src/minify.rs.\n compress: false,\n // Mangle options may be amended in crates/napi/src/minify.rs.\n mangle,\n module: 'unknown',\n output: {\n comments: false,\n },\n })\n\n return result\n },\n }\n }\n\n // The limit in the SWC minifier will be handled by Node.js\n const limit = pLimit(Infinity)\n const scheduledTasks = []\n\n for (const asset of assetsForMinify) {\n scheduledTasks.push(\n limit(async () => {\n const { name, inputSource, eTag } = asset\n let { output } = asset\n\n const minifySpan = MinifierSpan.traceChild('minify-js')\n minifySpan.setAttribute('name', name)\n minifySpan.setAttribute(\n 'cache',\n typeof output === 'undefined' ? 'MISS' : 'HIT'\n )\n\n return minifySpan.traceAsyncFn(async () => {\n if (!output) {\n const { source: sourceFromInputSource, map: inputSourceMap } =\n inputSource.sourceAndMap()\n\n const input = Buffer.isBuffer(sourceFromInputSource)\n ? sourceFromInputSource.toString()\n : sourceFromInputSource\n\n let minifiedOutput: { code: string; map: any } | undefined\n\n try {\n minifiedOutput = await getWorker().minify({\n input,\n inputSourceMap,\n })\n } catch (error) {\n compilation.errors.push(buildError(error, name))\n\n return\n }\n\n const source = minifiedOutput.map\n ? new SourceMapSource(\n minifiedOutput.code,\n name,\n minifiedOutput.map,\n input,\n inputSourceMap,\n true\n )\n : new RawSource(minifiedOutput.code)\n\n await cache.storePromise(name, eTag, { source })\n\n output = { source }\n }\n\n const newInfo = { minimized: true }\n\n compilation.updateAsset(name, output.source, newInfo)\n })\n })\n )\n }\n\n await Promise.all(scheduledTasks)\n\n if (initializedWorker) {\n await initializedWorker.end()\n }\n })\n }\n\n apply(compiler: any) {\n const { SourceMapSource, RawSource } = (compiler?.webpack?.sources ||\n sources) as typeof sources\n\n const pluginName = this.constructor.name\n\n compiler.hooks.thisCompilation.tap(\n pluginName,\n (compilation: Compilation) => {\n const cache = compilation.getCache('MinifierWebpackPlugin')\n\n const handleHashForChunk = (hash: any, _chunk: any) => {\n // increment 'c' to invalidate cache\n hash.update('c')\n }\n\n const JSModulesHooks =\n webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation\n )\n JSModulesHooks.chunkHash.tap(pluginName, (chunk, hash) => {\n if (!chunk.hasRuntime()) return\n return handleHashForChunk(hash, chunk)\n })\n\n compilation.hooks.processAssets.tapPromise(\n {\n name: pluginName,\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,\n },\n (assets: any) =>\n this.optimize(compiler, compilation, assets, cache, {\n SourceMapSource,\n RawSource,\n })\n )\n\n compilation.hooks.statsPrinter.tap(pluginName, (stats: any) => {\n stats.hooks.print\n .for('asset.info.minimized')\n .tap(\n 'minify-webpack-plugin',\n (minimized: any, { green, formatFlag }: any) =>\n // eslint-disable-next-line no-undefined\n minimized ? green(formatFlag('minimized')) : undefined\n )\n })\n }\n )\n }\n}\n"],"names":["webpack","ModuleFilenameHelpers","sources","WebpackError","pLimit","spans","buildError","error","file","line","message","col","stack","split","slice","join","debugMinify","process","env","NEXT_DEBUG_MINIFY","MinifyPlugin","constructor","options","optimize","compiler","compilation","assets","cache","SourceMapSource","RawSource","mangle","noMangling","compilationSpan","get","MinifierSpan","traceChild","name","setAttribute","String","traceAsyncFn","assetsList","Object","keys","assetsForMinify","Promise","all","filter","matchObject","bind","undefined","test","res","getAsset","console","log","info","minimized","map","source","eTag","mergeEtags","getLazyHashedEtag","JSON","stringify","output","getPromise","toString","breakLength","Infinity","maxStringLength","inputSource","initializedWorker","getWorker","minify","result","require","input","inputSourceMap","sourceMap","content","compress","module","comments","limit","scheduledTasks","asset","push","minifySpan","sourceFromInputSource","sourceAndMap","Buffer","isBuffer","minifiedOutput","errors","code","storePromise","newInfo","updateAsset","end","apply","pluginName","hooks","thisCompilation","tap","getCache","handleHashForChunk","hash","_chunk","update","JSModulesHooks","javascript","JavascriptModulesPlugin","getCompilationHooks","chunkHash","chunk","hasRuntime","processAssets","tapPromise","stage","Compilation","PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE","statsPrinter","stats","print","for","green","formatFlag"],"mappings":"AAAA,SACEA,OAAO,EACPC,qBAAqB,EACrBC,OAAO,EACPC,YAAY,QAGP,qCAAoC;AAC3C,OAAOC,YAAY,6BAA4B;AAC/C,SAASC,KAAK,QAAQ,yBAAwB;AAE9C,SAASC,WAAWC,KAAU,EAAEC,IAAY;IAC1C,IAAID,MAAME,IAAI,EAAE;QACd,OAAO,IAAIN,aACT,GAAGK,KAAK,gBAAgB,EAAED,MAAMG,OAAO,CAAC,EAAE,EAAEF,KAAK,CAAC,EAAED,MAAME,IAAI,CAAC,CAAC,EAC9DF,MAAMI,GAAG,CACV,CAAC,EACAJ,MAAMK,KAAK,GAAG,CAAC,EAAE,EAAEL,MAAMK,KAAK,CAACC,KA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C,MAAM3E,QAAa,EAAE;YACqBA;QAAxC,MAAM,EAAEI,eAAe,EAAEC,SAAS,EAAE,GAAIL,CAAAA,6BAAAA,oBAAAA,SAAUxB,OAAO,qBAAjBwB,kBAAmBtB,OAAO,KAChEA;QAEF,MAAMkG,aAAa,IAAI,CAAC/E,WAAW,CAACe,IAAI;QAExCZ,SAAS6E,KAAK,CAACC,eAAe,CAACC,GAAG,CAChCH,YACA,CAAC3E;YACC,MAAME,QAAQF,YAAY+E,QAAQ,CAAC;YAEnC,MAAMC,qBAAqB,CAACC,MAAWC;gBACrC,oCAAoC;gBACpCD,KAAKE,MAAM,CAAC;YACd;YAEA,MAAMC,iBACJ7G,QAAQ8G,UAAU,CAACC,uBAAuB,CAACC,mBAAmB,CAC5DvF;YAEJoF,eAAeI,SAAS,CAACV,GAAG,CAACH,YAAY,CAACc,OAAOR;gBAC/C,IAAI,CAACQ,MAAMC,UAAU,IAAI;gBACzB,OAAOV,mBAAmBC,MAAMQ;YAClC;YAEAzF,YAAY4E,KAAK,CAACe,aAAa,CAACC,UAAU,CACxC;gBACEjF,MAAMgE;gBACNkB,OAAOtH,QAAQuH,WAAW,CAACC,kCAAkC;YAC/D,GACA,CAAC9F,SACC,IAAI,CAACH,QAAQ,CAACC,UAAUC,aAAaC,QAAQC,OAAO;oBAClDC;oBACAC;gBACF;YAGJJ,YAAY4E,KAAK,CAACoB,YAAY,CAAClB,GAAG,CAACH,YAAY,CAACsB;gBAC9CA,MAAMrB,KAAK,CAACsB,KAAK,CACdC,GAAG,CAAC,wBACJrB,GAAG,CACF,yBACA,CAAC/C,WAAgB,EAAEqE,KAAK,EAAEC,UAAU,EAAO,GACzC,wCAAwC;oBACxCtE,YAAYqE,MAAMC,WAAW,gBAAgB7E;YAErD;QACF;IAEJ;AACF"}
|
1
|
+
{"version":3,"sources":["../../../../../../src/build/webpack/plugins/minify-webpack-plugin/src/index.ts"],"sourcesContent":["import {\n webpack,\n ModuleFilenameHelpers,\n sources,\n WebpackError,\n type CacheFacade,\n type Compilation,\n} from 'next/dist/compiled/webpack/webpack'\nimport pLimit from 'next/dist/compiled/p-limit'\nimport { getCompilationSpan } from '../../../utils'\n\nfunction buildError(error: any, file: string) {\n if (error.line) {\n return new WebpackError(\n `${file} from Minifier\\n${error.message} [${file}:${error.line},${\n error.col\n }]${\n error.stack ? `\\n${error.stack.split('\\n').slice(1).join('\\n')}` : ''\n }`\n )\n }\n\n if (error.stack) {\n return new WebpackError(\n `${file} from Minifier\\n${error.message}\\n${error.stack}`\n )\n }\n\n return new WebpackError(`${file} from Minifier\\n${error.message}`)\n}\n\nconst debugMinify = process.env.NEXT_DEBUG_MINIFY\n\nexport class MinifyPlugin {\n constructor(private options: { noMangling?: boolean }) {}\n\n async optimize(\n compiler: any,\n compilation: Compilation,\n assets: any,\n cache: CacheFacade,\n {\n SourceMapSource,\n RawSource,\n }: {\n SourceMapSource: typeof sources.SourceMapSource\n RawSource: typeof sources.RawSource\n }\n ) {\n const mangle = !this.options.noMangling\n const compilationSpan =\n getCompilationSpan(compilation)! || getCompilationSpan(compiler)\n\n const MinifierSpan = compilationSpan.traceChild(\n 'minify-webpack-plugin-optimize'\n )\n\n if (compilation.name) {\n MinifierSpan.setAttribute('compilationName', compilation.name)\n }\n\n MinifierSpan.setAttribute('mangle', String(mangle))\n\n return MinifierSpan.traceAsyncFn(async () => {\n const assetsList = Object.keys(assets)\n\n const assetsForMinify = await Promise.all(\n assetsList\n .filter((name) => {\n if (\n !ModuleFilenameHelpers.matchObject.bind(\n // eslint-disable-next-line no-undefined\n undefined,\n { test: /\\.[cm]?js(\\?.*)?$/i }\n )(name)\n ) {\n return false\n }\n\n const res = compilation.getAsset(name)\n if (!res) {\n console.log(name)\n return false\n }\n\n const { info } = res\n\n // Skip double minimize assets from child compilation\n if (info.minimized) {\n return false\n }\n\n return true\n })\n .map(async (name) => {\n const { info, source } = compilation.getAsset(name)!\n\n const eTag = cache.mergeEtags(\n cache.getLazyHashedEtag(source),\n JSON.stringify(this.options)\n )\n\n const output = await cache.getPromise<\n { source: sources.Source } | undefined\n >(name, eTag)\n\n if (debugMinify && debugMinify === '1') {\n console.log(\n JSON.stringify({ name, source: source.source().toString() }),\n { breakLength: Infinity, maxStringLength: Infinity }\n )\n }\n return { name, info, inputSource: source, output, eTag }\n })\n )\n\n let initializedWorker: any\n\n // eslint-disable-next-line consistent-return\n const getWorker = () => {\n return {\n minify: async (options: {\n input: string\n inputSourceMap: Object\n }) => {\n const result = await (\n require('../../../../swc') as typeof import('../../../../swc')\n ).minify(options.input, {\n ...(options.inputSourceMap\n ? {\n sourceMap: {\n content: JSON.stringify(options.inputSourceMap),\n },\n }\n : {}),\n // Compress options are defined in crates/napi/src/minify.rs.\n compress: false,\n // Mangle options may be amended in crates/napi/src/minify.rs.\n mangle,\n module: 'unknown',\n output: {\n comments: false,\n },\n })\n\n return result\n },\n }\n }\n\n // The limit in the SWC minifier will be handled by Node.js\n const limit = pLimit(Infinity)\n const scheduledTasks = []\n\n for (const asset of assetsForMinify) {\n scheduledTasks.push(\n limit(async () => {\n const { name, inputSource, eTag } = asset\n let { output } = asset\n\n const minifySpan = MinifierSpan.traceChild('minify-js')\n minifySpan.setAttribute('name', name)\n minifySpan.setAttribute(\n 'cache',\n typeof output === 'undefined' ? 'MISS' : 'HIT'\n )\n\n return minifySpan.traceAsyncFn(async () => {\n if (!output) {\n const { source: sourceFromInputSource, map: inputSourceMap } =\n inputSource.sourceAndMap()\n\n const input = Buffer.isBuffer(sourceFromInputSource)\n ? sourceFromInputSource.toString()\n : sourceFromInputSource\n\n let minifiedOutput: { code: string; map: any } | undefined\n\n try {\n minifiedOutput = await getWorker().minify({\n input,\n inputSourceMap,\n })\n } catch (error) {\n compilation.errors.push(buildError(error, name))\n\n return\n }\n\n const source = minifiedOutput.map\n ? new SourceMapSource(\n minifiedOutput.code,\n name,\n minifiedOutput.map,\n input,\n inputSourceMap,\n true\n )\n : new RawSource(minifiedOutput.code)\n\n await cache.storePromise(name, eTag, { source })\n\n output = { source }\n }\n\n const newInfo = { minimized: true }\n\n compilation.updateAsset(name, output.source, newInfo)\n })\n })\n )\n }\n\n await Promise.all(scheduledTasks)\n\n if (initializedWorker) {\n await initializedWorker.end()\n }\n })\n }\n\n apply(compiler: any) {\n const { SourceMapSource, RawSource } = (compiler?.webpack?.sources ||\n sources) as typeof sources\n\n const pluginName = this.constructor.name\n\n compiler.hooks.thisCompilation.tap(\n pluginName,\n (compilation: Compilation) => {\n const cache = compilation.getCache('MinifierWebpackPlugin')\n\n const handleHashForChunk = (hash: any, _chunk: any) => {\n // increment 'c' to invalidate cache\n hash.update('c')\n }\n\n const JSModulesHooks =\n webpack.javascript.JavascriptModulesPlugin.getCompilationHooks(\n compilation\n )\n JSModulesHooks.chunkHash.tap(pluginName, (chunk, hash) => {\n if (!chunk.hasRuntime()) return\n return handleHashForChunk(hash, chunk)\n })\n\n compilation.hooks.processAssets.tapPromise(\n {\n name: pluginName,\n stage: webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE,\n },\n (assets: any) =>\n this.optimize(compiler, compilation, assets, cache, {\n SourceMapSource,\n RawSource,\n })\n )\n\n compilation.hooks.statsPrinter.tap(pluginName, (stats: any) => {\n stats.hooks.print\n .for('asset.info.minimized')\n .tap(\n 'minify-webpack-plugin',\n (minimized: any, { green, formatFlag }: any) =>\n // eslint-disable-next-line no-undefined\n minimized ? green(formatFlag('minimized')) : undefined\n )\n })\n }\n )\n }\n}\n"],"names":["webpack","ModuleFilenameHelpers","sources","WebpackError","pLimit","getCompilationSpan","buildError","error","file","line","message","col","stack","split","slice","join","debugMinify","process","env","NEXT_DEBUG_MINIFY","MinifyPlugin","constructor","options","optimize","compiler","compilation","assets","cache","SourceMapSource","RawSource","mangle","noMangling","compilationSpan","MinifierSpan","traceChild","name","setAttribute","String","traceAsyncFn","assetsList","Object","keys","assetsForMinify","Promise","all","filter","matchObject","bind","undefined","test","res","getAsset","console","log","info","minimized","map","source","eTag","mergeEtags","getLazyHashedEtag","JSON","stringify","output","getPromise","toString","breakLength","Infinity","maxStringLength","inputSource","initializedWorker","getWorker","minify","result","require","input","inputSourceMap","sourceMap","content","compress","module","comments","limit","scheduledTasks","asset","push","minifySpan","sourceFromInputSource","sourceAndMap","Buffer","isBuffer","minifiedOutput","errors","code","storePromise","newInfo","updateAsset","end","apply","pluginName","hooks","thisCompilation","tap","getCache","handleHashForChunk","hash","_chunk","update","JSModulesHooks","javascript","JavascriptModulesPlugin","getCompilationHooks","chunkHash","chunk","hasRuntime","processAssets","tapPromise","stage","Compilation","PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE","statsPrinter","stats","print","for","green","formatFlag"],"mappings":"AAAA,SACEA,OAAO,EACPC,qBAAqB,EACrBC,OAAO,EACPC,YAAY,QAGP,qCAAoC;AAC3C,OAAOC,YAAY,6BAA4B;AAC/C,SAASC,kBAAkB,QAAQ,iBAAgB;AAEnD,SAASC,WAAWC,KAAU,EAAEC,IAAY;IAC1C,IAAID,MAAME,IAAI,EAAE;QACd,OAAO,IAAIN,aACT,GAAGK,KAAK,gBAAgB,EAAED,MAAMG,OAAO,CAAC,EAAE,EAAEF,KAAK,CAAC,EAAED,MAAME,IAAI,CAAC,CAAC,EAC9DF,MAAMI,GAAG,CACV,CAAC,EACAJ,MAAMK,KAAK,GAAG,CAAC,EAAE,EAAEL,MAAMK,KAAK,CAACC,KAAK,CAAC,MAAMC,KAAK,CAAC,GAAGC,IAAI,CAAC,OAAO,GAAG,IACnE;IAEN;IAEA,IAAIR,MAAMK,KAAK,EAAE;QACf,OAAO,IAAIT,aACT,GAAGK,KAAK,gBAAgB,EAAED,MAAMG,OAAO,CAAC,EAAE,EAAEH,MAAMK,KAAK,EAAE;IAE7D;IAEA,OAAO,IAAIT,aAAa,GAAGK,KAAK,gBAAgB,EAAED,MAAMG,OAAO,EAAE;AACnE;AAEA,MAAMM,cAAcC,QAAQC,GAAG,CAACC,iBAAiB;AAEjD,OAAO,MAAMC;IACXC,YAAY,A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YACd;YAEA,MAAMC,iBACJ5G,QAAQ6G,UAAU,CAACC,uBAAuB,CAACC,mBAAmB,CAC5DtF;YAEJmF,eAAeI,SAAS,CAACV,GAAG,CAACH,YAAY,CAACc,OAAOR;gBAC/C,IAAI,CAACQ,MAAMC,UAAU,IAAI;gBACzB,OAAOV,mBAAmBC,MAAMQ;YAClC;YAEAxF,YAAY2E,KAAK,CAACe,aAAa,CAACC,UAAU,CACxC;gBACEjF,MAAMgE;gBACNkB,OAAOrH,QAAQsH,WAAW,CAACC,kCAAkC;YAC/D,GACA,CAAC7F,SACC,IAAI,CAACH,QAAQ,CAACC,UAAUC,aAAaC,QAAQC,OAAO;oBAClDC;oBACAC;gBACF;YAGJJ,YAAY2E,KAAK,CAACoB,YAAY,CAAClB,GAAG,CAACH,YAAY,CAACsB;gBAC9CA,MAAMrB,KAAK,CAACsB,KAAK,CACdC,GAAG,CAAC,wBACJrB,GAAG,CACF,yBACA,CAAC/C,WAAgB,EAAEqE,KAAK,EAAEC,UAAU,EAAO,GACzC,wCAAwC;oBACxCtE,YAAYqE,MAAMC,WAAW,gBAAgB7E;YAErD;QACF;IAEJ;AACF"}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import nodePath from 'path';
|
2
|
-
import { spans } from './profiling-plugin';
|
3
2
|
import isError from '../../../lib/is-error';
|
4
3
|
import { nodeFileTrace } from 'next/dist/compiled/@vercel/nft';
|
5
4
|
import { CLIENT_REFERENCE_MANIFEST, TRACE_OUTPUT_VERSION } from '../../../shared/lib/constants';
|
@@ -10,6 +9,7 @@ import { getModuleBuildInfo } from '../loaders/get-module-build-info';
|
|
10
9
|
import { getPageFilePath } from '../../entries';
|
11
10
|
import { resolveExternal } from '../../handle-externals';
|
12
11
|
import { isStaticMetadataRoute } from '../../../lib/metadata/is-metadata-route';
|
12
|
+
import { getCompilationSpan } from '../utils';
|
13
13
|
const PLUGIN_NAME = 'TraceEntryPointsPlugin';
|
14
14
|
export const TRACE_IGNORES = [
|
15
15
|
'**/*/next/dist/server/next.js',
|
@@ -66,7 +66,7 @@ export function getFilesMapFromReasons(fileList, reasons, ignoreFn) {
|
|
66
66
|
return parentFilesMap;
|
67
67
|
}
|
68
68
|
export class TraceEntryPointsPlugin {
|
69
|
-
constructor({ rootDir, appDir, pagesDir, compilerType,
|
69
|
+
constructor({ rootDir, appDir, pagesDir, compilerType, appDirEnabled, traceIgnores, esmExternals, outputFileTracingRoot }){
|
70
70
|
this.buildTraceContext = {};
|
71
71
|
this.rootDir = rootDir;
|
72
72
|
this.appDir = appDir;
|
@@ -76,7 +76,6 @@ export class TraceEntryPointsPlugin {
|
|
76
76
|
this.appDirEnabled = appDirEnabled;
|
77
77
|
this.traceIgnores = traceIgnores || [];
|
78
78
|
this.tracingRoot = outputFileTracingRoot || rootDir;
|
79
|
-
this.optOutBundlingPackages = optOutBundlingPackages;
|
80
79
|
this.compilerType = compilerType;
|
81
80
|
}
|
82
81
|
// Here we output all traced assets and webpack chunks to a
|
@@ -366,6 +365,8 @@ export class TraceEntryPointsPlugin {
|
|
366
365
|
}
|
367
366
|
apply(compiler) {
|
368
367
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
|
368
|
+
const compilationSpan = getCompilationSpan(compilation) || getCompilationSpan(compiler);
|
369
|
+
const traceEntrypointsPluginSpan = compilationSpan.traceChild('next-trace-entrypoint-plugin');
|
369
370
|
compilation.hooks.processAssets.tapAsync({
|
370
371
|
name: PLUGIN_NAME,
|
371
372
|
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
@@ -408,8 +409,6 @@ export class TraceEntryPointsPlugin {
|
|
408
409
|
throw e;
|
409
410
|
}
|
410
411
|
};
|
411
|
-
const compilationSpan = spans.get(compilation) || spans.get(compiler);
|
412
|
-
const traceEntrypointsPluginSpan = compilationSpan.traceChild('next-trace-entrypoint-plugin');
|
413
412
|
traceEntrypointsPluginSpan.traceFn(()=>{
|
414
413
|
compilation.hooks.processAssets.tapAsync({
|
415
414
|
name: PLUGIN_NAME,
|
@@ -501,7 +500,7 @@ export class TraceEntryPointsPlugin {
|
|
501
500
|
const context = nodePath.dirname(parent);
|
502
501
|
// When in esm externals mode, and using import, we resolve with
|
503
502
|
// ESM resolving options.
|
504
|
-
const { res } = await resolveExternal(this.rootDir, this.esmExternals, context, request, isEsmRequested,
|
503
|
+
const { res } = await resolveExternal(this.rootDir, this.esmExternals, context, request, isEsmRequested, (options)=>(_, resRequest)=>{
|
505
504
|
return getResolve(options)(parent, resRequest, job);
|
506
505
|
}, undefined, undefined, ESM_RESOLVE_OPTIONS, CJS_RESOLVE_OPTIONS, BASE_ESM_RESOLVE_OPTIONS, BASE_CJS_RESOLVE_OPTIONS);
|
507
506
|
if (!res) {
|