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
package/dist/bin/next
CHANGED
@@ -79,7 +79,7 @@ const program = new NextRootCommand();
|
|
79
79
|
program.name('next').description('The Next.js CLI allows you to develop, build, start your application, and more.').configureHelp({
|
80
80
|
formatHelp: (cmd, helper)=>(0, _formatclihelpoutput.formatCliHelpOutput)(cmd, helper),
|
81
81
|
subcommandTerm: (cmd)=>`${cmd.name()} ${cmd.usage()}`
|
82
|
-
}).helpCommand(false).helpOption('-h, --help', 'Displays this message.').version(`Next.js v${"15.2.1-canary.
|
82
|
+
}).helpCommand(false).helpOption('-h, --help', 'Displays this message.').version(`Next.js v${"15.2.1-canary.2"}`, '-v, --version', 'Outputs the Next.js version.');
|
83
83
|
program.command('build').description('Creates an optimized production build of your application. The output displays information about each route.').argument('[directory]', `A directory on which to build the application. ${(0, _picocolors.italic)('If no directory is provided, the current directory will be used.')}`).option('-d, --debug', 'Enables a more verbose build output.').option('--no-lint', 'Disables linting.').option('--no-mangling', 'Disables mangling.').option('--profile', 'Enables production profiling for React.').option('--experimental-app-only', 'Builds only App Router routes.').addOption(new _commander.Option('--experimental-turbo').hideHelp()).addOption(new _commander.Option('--experimental-build-mode [mode]', 'Uses an experimental build mode.').choices([
|
84
84
|
'compile',
|
85
85
|
'generate'
|
@@ -2,7 +2,7 @@ import type { WebpackLayerName } from '../lib/constants';
|
|
2
2
|
import type { NextConfigComplete } from '../server/config-shared';
|
3
3
|
import type { ResolveOptions } from 'webpack';
|
4
4
|
export declare function isResourceInPackages(resource: string, packageNames?: string[], packageDirMapping?: Map<string, string>): boolean;
|
5
|
-
export declare function resolveExternal(dir: string, esmExternalsConfig: NextConfigComplete['experimental']['esmExternals'], context: string, request: string, isEsmRequested: boolean,
|
5
|
+
export declare function resolveExternal(dir: string, esmExternalsConfig: NextConfigComplete['experimental']['esmExternals'], context: string, request: string, isEsmRequested: boolean, getResolve: (options: ResolveOptions) => (resolveContext: string, resolveRequest: string) => Promise<[string | null, boolean]>, isLocalCallback?: (res: string) => any, baseResolveCheck?: boolean, esmResolveOptions?: any, nodeResolveOptions?: any, baseEsmResolveOptions?: any, baseResolveOptions?: any): Promise<{
|
6
6
|
localRes: any;
|
7
7
|
res?: undefined;
|
8
8
|
isEsm?: undefined;
|
@@ -11,9 +11,8 @@ export declare function resolveExternal(dir: string, esmExternalsConfig: NextCon
|
|
11
11
|
isEsm: boolean;
|
12
12
|
localRes?: undefined;
|
13
13
|
}>;
|
14
|
-
export declare function makeExternalHandler({ config,
|
14
|
+
export declare function makeExternalHandler({ config, optOutBundlingPackageRegex, transpiledPackages, dir, }: {
|
15
15
|
config: NextConfigComplete;
|
16
|
-
optOutBundlingPackages: string[];
|
17
16
|
optOutBundlingPackageRegex: RegExp;
|
18
17
|
transpiledPackages: string[];
|
19
18
|
dir: string;
|
@@ -46,7 +46,7 @@ function isResourceInPackages(resource, packageNames, packageDirMapping) {
|
|
46
46
|
if (!packageNames) return false;
|
47
47
|
return packageNames.some((p)=>packageDirMapping && packageDirMapping.has(p) ? resource.startsWith(packageDirMapping.get(p) + _path.default.sep) : resource.includes(_path.default.sep + _path.default.join('node_modules', p.replace(/\//g, _path.default.sep)) + _path.default.sep));
|
48
48
|
}
|
49
|
-
async function resolveExternal(dir, esmExternalsConfig, context, request, isEsmRequested,
|
49
|
+
async function resolveExternal(dir, esmExternalsConfig, context, request, isEsmRequested, getResolve, isLocalCallback, baseResolveCheck = true, esmResolveOptions = _webpackconfig.NODE_ESM_RESOLVE_OPTIONS, nodeResolveOptions = _webpackconfig.NODE_RESOLVE_OPTIONS, baseEsmResolveOptions = _webpackconfig.NODE_BASE_ESM_RESOLVE_OPTIONS, baseResolveOptions = _webpackconfig.NODE_BASE_RESOLVE_OPTIONS) {
|
50
50
|
const esmExternals = !!esmExternalsConfig;
|
51
51
|
const looseEsmExternals = esmExternalsConfig === 'loose';
|
52
52
|
let res = null;
|
@@ -113,7 +113,7 @@ async function resolveExternal(dir, esmExternalsConfig, context, request, isEsmR
|
|
113
113
|
isEsm
|
114
114
|
};
|
115
115
|
}
|
116
|
-
function makeExternalHandler({ config,
|
116
|
+
function makeExternalHandler({ config, optOutBundlingPackageRegex, transpiledPackages, dir }) {
|
117
117
|
var _config_experimental;
|
118
118
|
let resolvedExternalPackageDirs;
|
119
119
|
const looseEsmExternals = ((_config_experimental = config.experimental) == null ? void 0 : _config_experimental.esmExternals) === 'loose';
|
@@ -187,7 +187,7 @@ function makeExternalHandler({ config, optOutBundlingPackages, optOutBundlingPac
|
|
187
187
|
return resolveNextExternal(request);
|
188
188
|
}
|
189
189
|
// TODO-APP: Let's avoid this resolve call as much as possible, and eventually get rid of it.
|
190
|
-
const resolveResult = await resolveExternal(dir, config.experimental.esmExternals, context, request, isEsmRequested,
|
190
|
+
const resolveResult = await resolveExternal(dir, config.experimental.esmExternals, context, request, isEsmRequested, getResolve, isLocal ? resolveNextExternal : undefined);
|
191
191
|
if ('localRes' in resolveResult) {
|
192
192
|
return resolveResult.localRes;
|
193
193
|
}
|
@@ -233,7 +233,7 @@ function makeExternalHandler({ config, optOutBundlingPackages, optOutBundlingPac
|
|
233
233
|
resolvedExternalPackageDirs = new Map();
|
234
234
|
// We need to resolve all the external package dirs initially.
|
235
235
|
for (const pkg of transpiledPackages){
|
236
|
-
const pkgRes = await resolveExternal(dir, config.experimental.esmExternals, context, pkg + '/package.json', isEsmRequested,
|
236
|
+
const pkgRes = await resolveExternal(dir, config.experimental.esmExternals, context, pkg + '/package.json', isEsmRequested, getResolve, isLocal ? resolveNextExternal : undefined);
|
237
237
|
if (pkgRes.res) {
|
238
238
|
resolvedExternalPackageDirs.set(pkg, _path.default.dirname(pkgRes.res));
|
239
239
|
}
|
@@ -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":["isResourceInPackages","makeExternalHandler","resolveExternal","reactPackagesRegex","pathSeparators","optionalEsmPart","externalFileEnd","nextDist","externalPattern","RegExp","nodeModulesRegex","resource","packageNames","packageDirMapping","some","p","has","startsWith","get","path","sep","includes","join","replace","dir","esmExternalsConfig","context","request","isEsmRequested","_optOutBundlingPackages","getResolve","isLocalCallback","baseResolveCheck","esmResolveOptions","NODE_ESM_RESOLVE_OPTIONS","nodeResolveOptions","NODE_RESOLVE_OPTIONS","baseEsmResolveOptions","NODE_BASE_ESM_RESOLVE_OPTIONS","baseResolveOptions","NODE_BASE_RESOLVE_OPTIONS","esmExternals","looseEsmExternals","res","isEsm","preferEsmOptions","preferEsm","resolveOptions","resolve","err","localRes","baseRes","baseIsEsm","baseResolve","config","optOutBundlingPackages","optOutBundlingPackageRegex","transpiledPackages","resolvedExternalPackageDirs","experimental","handleExternals","dependencyType","layer","isLocal","posix","isAbsolute","process","platform","win32","isAppLayer","isWebpackBundledLayer","test","notExternalModules","BARREL_OPTIMIZATION_PREFIX","isWebpackServerOnlyLayer","resolveNextExternal","resolveResult","undefined","defaultOverrides","isOptOutBundling","Error","externalType","Map","pkg","pkgRes","set","dirname","resolvedBundlingOptOutRes","resolveBundlingOptOutPackages","resolvedRes","shouldBundlePages","bundlePagesRouterDependencies","shouldBeBundled","isExternal","normalizePathSep"],"mappings":";;;;;;;;;;;;;;;;IA2BgBA,oBAAoB;eAApBA;;IA0GAC,mBAAmB;eAAnBA;;IAzFMC,eAAe;eAAfA;;;6BAzCW;2BACU;6DAC1B;+BAMV;uBACyD;kCAC/B;;;;;;AACjC,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,eAA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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":["isResourceInPackages","makeExternalHandler","resolveExternal","reactPackagesRegex","pathSeparators","optionalEsmPart","externalFileEnd","nextDist","externalPattern","RegExp","nodeModulesRegex","resource","packageNames","packageDirMapping","some","p","has","startsWith","get","path","sep","includes","join","replace","dir","esmExternalsConfig","context","request","isEsmRequested","getResolve","isLocalCallback","baseResolveCheck","esmResolveOptions","NODE_ESM_RESOLVE_OPTIONS","nodeResolveOptions","NODE_RESOLVE_OPTIONS","baseEsmResolveOptions","NODE_BASE_ESM_RESOLVE_OPTIONS","baseResolveOptions","NODE_BASE_RESOLVE_OPTIONS","esmExternals","looseEsmExternals","res","isEsm","preferEsmOptions","preferEsm","resolveOptions","resolve","err","localRes","baseRes","baseIsEsm","baseResolve","config","optOutBundlingPackageRegex","transpiledPackages","resolvedExternalPackageDirs","experimental","handleExternals","dependencyType","layer","isLocal","posix","isAbsolute","process","platform","win32","isAppLayer","isWebpackBundledLayer","test","notExternalModules","BARREL_OPTIMIZATION_PREFIX","isWebpackServerOnlyLayer","resolveNextExternal","resolveResult","undefined","defaultOverrides","isOptOutBundling","Error","externalType","Map","pkg","pkgRes","set","dirname","resolvedBundlingOptOutRes","resolveBundlingOptOutPackages","resolvedRes","shouldBundlePages","bundlePagesRouterDependencies","shouldBeBundled","isExternal","normalizePathSep"],"mappings":";;;;;;;;;;;;;;;;IA2BgBA,oBAAoB;eAApBA;;IAyGAC,mBAAmB;eAAnBA;;IAxFMC,eAAe;eAAfA;;;6BAzCW;2BACU;6DAC1B;+BAMV;uBACyD;kCAC/B;;;;;;AACjC,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;AAElB,SAASV,qBACdW,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,KAAMI,aAAI,CAACC,GAAG,IACxDT,SAASU,QAAQ,CACfF,aAAI,CAACC,GAAG,GACND,aAAI,CAACG,IAAI,CAAC,gBAAgBP,EAAEQ,OAAO,CAAC,OAAOJ,aAAI,CAACC,GAAG,KACnDD,aAAI,CAACC,GAAG;AAGpB;AAEO,eAAelB,gBACpBsB,GAAW,EACXC,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ZF,gBAAgB,EAChBlD,OAAO,EACP4B,kBAAkB,EAUnB;IACC,IAAI7C,iBAAiB2D,IAAI,CAACkB,cAAc;QACtC,MAAMC,oBACJ,CAACrB,cAAcd,OAAOoC,6BAA6B,IAAI,CAACZ;QAE1D,MAAMa,kBACJF,qBACAxF,qBACEuF,aACAhC,oBACAC;QAGJ,IAAI,CAACkC,iBAAiB;YACpB,OAAO,GAAGX,aAAa,CAAC,EAAEpD,SAAS,CAAC,0CAA0C;;QAChF;IACF;AACF;AAEA;;;;;;CAMC,GACD,SAAS8C,oBAAoBxB,QAAgB;IAC3C,MAAM0C,aAAanF,gBAAgB6D,IAAI,CAACpB;IAExC,sFAAsF;IACtF,sGAAsG;IACtG,IAAI0C,YAAY;QACd,oGAAoG;QACpG,oCAAoC;QACpC,OAAO,CAAC,SAAS,EAAEC,IAAAA,kCAAgB,EACjC3C,SAAS1B,OAAO,CAAC,oBAAoB,eACpC;IACL;AACF"}
|
package/dist/build/index.js
CHANGED
@@ -364,7 +364,7 @@ async function build(dir, reactProductionProfiling = false, debugOutput = false,
|
|
364
364
|
const nextBuildSpan = (0, _trace.trace)('next-build', undefined, {
|
365
365
|
buildMode: experimentalBuildMode,
|
366
366
|
isTurboBuild: String(turboNextBuild),
|
367
|
-
version: "15.2.1-canary.
|
367
|
+
version: "15.2.1-canary.2"
|
368
368
|
});
|
369
369
|
_buildcontext.NextBuildContext.nextBuildSpan = nextBuildSpan;
|
370
370
|
_buildcontext.NextBuildContext.dir = dir;
|
@@ -723,7 +723,7 @@ async function build(dir, reactProductionProfiling = false, debugOutput = false,
|
|
723
723
|
// Files outside of the distDir can be "type": "module"
|
724
724
|
await writeFileUtf8(_path.default.join(distDir, 'package.json'), '{"type": "commonjs"}');
|
725
725
|
// These are written to distDir, so they need to come after creating and cleaning distDr.
|
726
|
-
await (0, _builddiagnostics.recordFrameworkVersion)("15.2.1-canary.
|
726
|
+
await (0, _builddiagnostics.recordFrameworkVersion)("15.2.1-canary.2");
|
727
727
|
await (0, _builddiagnostics.updateBuildDiagnostics)({
|
728
728
|
buildStage: 'start'
|
729
729
|
});
|
package/dist/build/swc/index.js
CHANGED
@@ -119,7 +119,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
119
119
|
}
|
120
120
|
return newObj;
|
121
121
|
}
|
122
|
-
const nextVersion = "15.2.1-canary.
|
122
|
+
const nextVersion = "15.2.1-canary.2";
|
123
123
|
const ArchName = (0, _os.arch)();
|
124
124
|
const PlatformName = (0, _os.platform)();
|
125
125
|
function infoLog(...args) {
|
@@ -44,15 +44,13 @@ const _constants = require("../../../shared/lib/constants");
|
|
44
44
|
const _getroutefromentrypoint = /*#__PURE__*/ _interop_require_default(require("../../../server/get-route-from-entrypoint"));
|
45
45
|
const _nextdropclientpageplugin = require("./next-drop-client-page-plugin");
|
46
46
|
const _utils = require("../../../shared/lib/router/utils");
|
47
|
-
const _profilingplugin = require("./profiling-plugin");
|
48
|
-
const _rspackprofilingplugin = require("./rspack-profiling-plugin");
|
49
47
|
const _trace = require("../../../trace");
|
48
|
+
const _utils1 = require("../utils");
|
50
49
|
function _interop_require_default(obj) {
|
51
50
|
return obj && obj.__esModule ? obj : {
|
52
51
|
default: obj
|
53
52
|
};
|
54
53
|
}
|
55
|
-
const compilationSpans = process.env.NEXT_RSPACK ? _rspackprofilingplugin.compilationSpans : _profilingplugin.spans;
|
56
54
|
const srcEmptySsgManifest = `self.__SSG_MANIFEST=new Set;self.__SSG_MANIFEST_CB&&self.__SSG_MANIFEST_CB()`;
|
57
55
|
// nodejs: '/static/<build id>/low-priority.js'
|
58
56
|
function buildNodejsLowPriorityPath(filename, buildId) {
|
@@ -93,7 +91,7 @@ function normalizeRewritesForBuildManifest(rewrites) {
|
|
93
91
|
};
|
94
92
|
}
|
95
93
|
function generateClientManifest(assetMap, rewrites, clientRouterFilters, compiler, compilation) {
|
96
|
-
const compilationSpan = compilation ?
|
94
|
+
const compilationSpan = compilation ? (0, _utils1.getCompilationSpan)(compilation) : compiler ? (0, _utils1.getCompilationSpan)(compiler) : new _trace.Span({
|
97
95
|
name: 'client-manifest'
|
98
96
|
});
|
99
97
|
const genClientManifestSpan = compilationSpan == null ? void 0 : compilationSpan.traceChild('NextJsBuildManifest-generateClientManifest');
|
@@ -156,7 +154,7 @@ class BuildManifestPlugin {
|
|
156
154
|
this.rewrites.fallback = options.rewrites.fallback.map(processRoute);
|
157
155
|
}
|
158
156
|
createAssets(compiler, compilation) {
|
159
|
-
const compilationSpan =
|
157
|
+
const compilationSpan = (0, _utils1.getCompilationSpan)(compilation) ?? (0, _utils1.getCompilationSpan)(compiler);
|
160
158
|
if (!compilationSpan) {
|
161
159
|
throw Object.defineProperty(new Error('No span found for compilation'), "__NEXT_ERROR_CODE", {
|
162
160
|
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":["BuildManifestPlugin","generateClientManifest","getEntrypointFiles","normalizeRewritesForBuildManifest","processRoute","srcEmptySsgManifest","compilationSpans","process","env","NEXT_RSPACK","rspackSpans","webpackSpans","buildNodejsLowPriorityPath","filename","buildId","CLIENT_STATIC_FILES_PATH","createEdgeRuntimeManifest","originAssetMap","manifestFilenames","assetMap","lowPriorityFiles","manifestDefCode","JSON","stringify","lowPriorityFilesCode","map","join","normalizeRewrite","item","has","source","destination","rewrites","afterFiles","beforeFiles","fallback","clientRouterFilters","compiler","compilation","compilationSpan","get","Span","name","genClientManifestSpan","traceChild","traceFn","clientManifest","__rewrites","__routerFilterStatic","staticFilter","__routerFilterDynamic","dynamicFilter","appDependencies","Set","pages","sortedPageKeys","getSortedRoutes","Object","keys","forEach","page","dependencies","filteredDeps","filter","dep","length","sortedPages","devalue","entrypoint","getFiles","file","test","replace","r","rewrite","startsWith","constructor","options","isDevFallback","appDirEnabled","createAssets","Error","createAssetsSpan","entrypoints","polyfillFiles","devFiles","ampDevFiles","rootMainFiles","rootMainFilesTree","ampFirstPages","ampFirstEntryNames","ampFirstEntryNamesMap","entryName","pagePath","getRouteFromEntrypoint","push","mainFiles","CLIENT_STATIC_FILES_RUNTIME_MAIN","CLIENT_STATIC_FILES_RUNTIME_MAIN_APP","compilationAssets","getAssets","p","endsWith","info","CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL","v","CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH","CLIENT_STATIC_FILES_RUNTIME_AMP","values","SYSTEM_ENTRYPOINTS","filesForPage","buildManifestPath","ssgManifestPath","emitAsset","sources","RawSource","sort","reduce","a","c","buildManifestName","BUILD_MANIFEST","MIDDLEWARE_BUILD_MANIFEST","apply","hooks","make","tap","processAssets","stage","webpack","Compilation","PROCESS_ASSETS_STAGE_ADDITIONS"],"mappings":";;;;;;;;;;;;;;;;;;;IA+KA,iFAAiF;IACjF,+GAA+G;IAC/G,OAgMC;eAhMoBA;;IA7ELC,sBAAsB;eAAtBA;;IAoDAC,kBAAkB;eAAlBA;;IAtEAC,iCAAiC;eAAjCA;;IAkFHC,YAAY;eAAZA;;IAlIAC,mBAAmB;eAAnBA;;;gEAhCO;yBACa;2BAW1B;+EAE4B;0CACG;uBACN;iCACM;uCACU;uBAC3B;;;;;;AAErB,MAAMC,mBAAmBC,QAAQC,GAAG,CAACC,WAAW,GAAGC,uCAAW,GAAGC,sBAAY;AAWtE,MAAMN,sBAAsB,CAAC,4EAA4E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AY2E,SAAS,CACnB,CAAC,OAAO,EAAES,oCAAyB,CAAC,GAAG,CAAC,EACxC,IAAIR,gBAAO,CAACC,SAAS,CAAC,GAAGnG,0BAA0BG,WAAW;YAGhE,IAAI,CAAC,IAAI,CAAC2D,aAAa,EAAE;gBACvBxC,YAAY2E,SAAS,CACnB,GAAGlG,mCAAwB,CAAC,CAAC,EAAE,IAAI,CAACD,OAAO,CAAC,kBAAkB,CAAC,EAC/D,IAAIoG,gBAAO,CAACC,SAAS,CACnB,CAAC,wBAAwB,EAAElH,uBACzBkB,UACA,IAAI,CAACa,QAAQ,EACb,IAAI,CAACI,mBAAmB,EACxBC,UACAC,aACA,uDAAuD,CAAC;YAGhE;QACF;IACF;IAEAqF,MAAMtF,QAA0B,EAAE;QAChCA,SAASuF,KAAK,CAACC,IAAI,CAACC,GAAG,CAAC,uBAAuB,CAACxF;YAC9CA,YAAYsF,KAAK,CAACG,aAAa,CAACD,GAAG,CACjC;gBACEpF,MAAM;gBACNsF,OAAOC,gBAAO,CAACC,WAAW,CAACC,8BAA8B;YAC3D,GACA;gBACE,IAAI,CAACnD,YAAY,CAAC3C,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":["BuildManifestPlugin","generateClientManifest","getEntrypointFiles","normalizeRewritesForBuildManifest","processRoute","srcEmptySsgManifest","buildNodejsLowPriorityPath","filename","buildId","CLIENT_STATIC_FILES_PATH","createEdgeRuntimeManifest","originAssetMap","manifestFilenames","assetMap","lowPriorityFiles","manifestDefCode","JSON","stringify","lowPriorityFilesCode","map","join","normalizeRewrite","item","has","source","destination","rewrites","afterFiles","beforeFiles","fallback","clientRouterFilters","compiler","compilation","compilationSpan","getCompilationSpan","Span","name","genClientManifestSpan","traceChild","traceFn","clientManifest","__rewrites","__routerFilterStatic","staticFilter","__routerFilterDynamic","dynamicFilter","appDependencies","Set","pages","sortedPageKeys","getSortedRoutes","Object","keys","forEach","page","dependencies","filteredDeps","filter","dep","length","sortedPages","devalue","entrypoint","getFiles","file","test","replace","r","rewrite","startsWith","constructor","options","isDevFallback","appDirEnabled","createAssets","Error","createAssetsSpan","entrypoints","polyfillFiles","devFiles","ampDevFiles","rootMainFiles","rootMainFilesTree","ampFirstPages","ampFirstEntryNames","ampFirstEntryNamesMap","get","entryName","pagePath","getRouteFromEntrypoint","push","mainFiles","CLIENT_STATIC_FILES_RUNTIME_MAIN","CLIENT_STATIC_FILES_RUNTIME_MAIN_APP","compilationAssets","getAssets","p","endsWith","info","CLIENT_STATIC_FILES_RUNTIME_POLYFILLS_SYMBOL","v","CLIENT_STATIC_FILES_RUNTIME_REACT_REFRESH","CLIENT_STATIC_FILES_RUNTIME_AMP","values","SYSTEM_ENTRYPOINTS","filesForPage","buildManifestPath","ssgManifestPath","emitAsset","sources","RawSource","sort","reduce","a","c","buildManifestName","BUILD_MANIFEST","MIDDLEWARE_BUILD_MANIFEST","apply","hooks","make","tap","processAssets","stage","webpack","Compilation","PROCESS_ASSETS_STAGE_ADDITIONS"],"mappings":";;;;;;;;;;;;;;;;;;;IA4KA,iFAAiF;IACjF,+GAA+G;IAC/G,OAgMC;eAhMoBA;;IA7ELC,sBAAsB;eAAtBA;;IAoDAC,kBAAkB;eAAlBA;;IAtEAC,iCAAiC;eAAjCA;;IAkFHC,YAAY;eAAZA;;IAlIAC,mBAAmB;eAAnBA;;;gEA7BO;yBACa;2BAW1B;+EAE4B;0CACG;uBACN;uBACX;wBACc;;;;;;AAW5B,MAA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AS,CACnB,CAAC,OAAO,EAAES,oCAAyB,CAAC,GAAG,CAAC,EACxC,IAAIR,gBAAO,CAACC,SAAS,CAAC,GAAGpG,0BAA0BG,WAAW;YAGhE,IAAI,CAAC,IAAI,CAAC2D,aAAa,EAAE;gBACvBxC,YAAY4E,SAAS,CACnB,GAAGnG,mCAAwB,CAAC,CAAC,EAAE,IAAI,CAACD,OAAO,CAAC,kBAAkB,CAAC,EAC/D,IAAIqG,gBAAO,CAACC,SAAS,CACnB,CAAC,wBAAwB,EAAE7G,uBACzBY,UACA,IAAI,CAACa,QAAQ,EACb,IAAI,CAACI,mBAAmB,EACxBC,UACAC,aACA,uDAAuD,CAAC;YAGhE;QACF;IACF;IAEAsF,MAAMvF,QAA0B,EAAE;QAChCA,SAASwF,KAAK,CAACC,IAAI,CAACC,GAAG,CAAC,uBAAuB,CAACzF;YAC9CA,YAAYuF,KAAK,CAACG,aAAa,CAACD,GAAG,CACjC;gBACErF,MAAM;gBACNuF,OAAOC,gBAAO,CAACC,WAAW,CAACC,8BAA8B;YAC3D,GACA;gBACE,IAAI,CAACpD,YAAY,CAAC3C,UAAUC;YAC9B;QAEJ;QACA;IACF;AACF"}
|
@@ -12,7 +12,7 @@ const _cssnanosimple = /*#__PURE__*/ _interop_require_default(require("next/dist
|
|
12
12
|
const _postcssscss = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/postcss-scss"));
|
13
13
|
const _postcss = /*#__PURE__*/ _interop_require_default(require("postcss"));
|
14
14
|
const _webpack = require("next/dist/compiled/webpack/webpack");
|
15
|
-
const
|
15
|
+
const _utils = require("../utils");
|
16
16
|
function _interop_require_default(obj) {
|
17
17
|
return obj && obj.__esModule ? obj : {
|
18
18
|
default: obj
|
@@ -62,7 +62,7 @@ class CssMinimizerPlugin {
|
|
62
62
|
name: 'CssMinimizerPlugin',
|
63
63
|
stage: _webpack.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE
|
64
64
|
}, async (assets)=>{
|
65
|
-
const compilationSpan =
|
65
|
+
const compilationSpan = (0, _utils.getCompilationSpan)(compilation) || (0, _utils.getCompilationSpan)(compiler);
|
66
66
|
const cssMinimizerSpan = compilationSpan.traceChild('css-minimizer-plugin');
|
67
67
|
return cssMinimizerSpan.traceAsyncFn(async ()=>{
|
68
68
|
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":["CssMinimizerPlugin","CSS_REGEX","constructor","options","__next_css_remove","optimizeAsset","file","asset","postcssOptions","to","from","parser","postcssScss","input","map","sourceAndMap","source","prev","postcss","cssnanoSimple","colormin","process","then","res","sources","SourceMapSource","css","toJSON","RawSource","apply","compiler","hooks","compilation","tap","cache","getCache","processAssets","tapPromise","name","stage","webpack","Compilation","PROCESS_ASSETS_STAGE_OPTIMIZE_SIZE","assets","compilationSpan","getCompilationSpan","cssMinimizerSpan","traceChild","traceAsyncFn","files","Object","keys","Promise","all","filter","test","assetSpan","setAttribute","assetSource","getAsset","etag","getLazyHashedEtag","cachedResult","getPromise","updateAsset","result","storePromise"],"mappings":";;;;+BAgBaA;;;eAAAA;;;sEAhBa;oEACF;gEACJ;yBAEa;uBACE;;;;;;AAEnC,4HAA4H;AAC5H,MAAMC,YAAY;AAQX,MAAMD;IAKXE,YAAYC,OAAkC,CAAE;aAJhDC,oBAAoB;QAKlB,IAAI,CAACD,OAAO,GAAGA;IACjB;IAEAE,cAAcC,IAAY,EAAEC,KAAU,EAAE;QACtC,MAAMC,iBAAiB;YACrB,GAAG,IAAI,CAACL,OAAO,CAACK,cAAc;YAC9BC,IAAIH;YACJI,MAAMJ;YAEN,yEAAyE;YACzE,8CAA8C;YAC9C,8FAA8F;YAC9FK,QAAQC,oBAAW;QACrB;QAEA,IAAIC;QACJ,IAAIL,eAAeM,GAAG,IAAIP,MAAMQ,YAAY,EAAE;YAC5C,MAAM,EAAEC,MAAM,EAAEF,GAAG,EAAE,GAAGP,MAAMQ,YAAY;YAC1CF,QAAQG;YACRR,eAAeM,GAAG,CAACG,IAAI,GAAGH,MAAMA,MAAM;QACxC,OAAO;YACLD,QAAQN,MAAMS,MAAM;QACtB;QAEA,OAAOE,IAAAA,gBAAO,EAAC;YAACC,IAAAA,sBAAa,EAAC;gBAAEC,UAAU;YAAM,GAAGF,gBAAO;SAAE,EACzDG,OAAO,CAACR,OAAOL,gBACfc,IAAI,CAAC,CAACC;YACL,IAAIA,IAAIT,GAAG,EAAE;gBACX,OAAO,IAAIU,gBAAO,CAACC,eAAe,CAACF,IAAIG,GAAG,EAAEpB,MAAMiB,IAAIT,GAAG,CAACa,MAAM;YAClE,OAAO;gBACL,OAAO,IAAIH,gBAAO,CAACI,SAAS,CAACL,IAAIG,GAAG;YACtC;QACF;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ifyPlugin", {
|
|
10
10
|
});
|
11
11
|
const _webpack = require("next/dist/compiled/webpack/webpack");
|
12
12
|
const _plimit = /*#__PURE__*/ _interop_require_default(require("next/dist/compiled/p-limit"));
|
13
|
-
const
|
13
|
+
const _utils = require("../../../utils");
|
14
14
|
function _interop_require_default(obj) {
|
15
15
|
return obj && obj.__esModule ? obj : {
|
16
16
|
default: obj
|
@@ -32,7 +32,7 @@ class MinifyPlugin {
|
|
32
32
|
}
|
33
33
|
async optimize(compiler, compilation, assets, cache, { SourceMapSource, RawSource }) {
|
34
34
|
const mangle = !this.options.noMangling;
|
35
|
-
const compilationSpan =
|
35
|
+
const compilationSpan = (0, _utils.getCompilationSpan)(compilation) || (0, _utils.getCompilationSpan)(compiler);
|
36
36
|
const MinifierSpan = compilationSpan.traceChild('minify-webpack-plugin-optimize');
|
37
37
|
if (compilation.name) {
|
38
38
|
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":["MinifyPlugin","buildError","error","file","line","WebpackError","message","col","stack","split","slice","join","debugMinify","process","env","NEXT_DEBUG_MINIFY","constructor","options","optimize","compiler","compilation","assets","cache","SourceMapSource","RawSource","mangle","noMangling","compilationSpan","spans","get","MinifierSpan","traceChild","name","setAttribute","String","traceAsyncFn","assetsList","Object","keys","assetsForMinify","Promise","all","filter","ModuleFilenameHelpers","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","pLimit","scheduledTasks","asset","push","minifySpan","sourceFromInputSource","sourceAndMap","Buffer","isBuffer","minifiedOutput","errors","code","storePromise","newInfo","updateAsset","end","apply","webpack","sources","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":";;;;+BAiCaA;;;eAAAA;;;yBA1BN;+DACY;iCACG;;;;;;AAEtB,SAASC,WAAWC,KAAU,EAAEC,IAAY;IAC1C,IAAID,MAA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ACdC,GAAG,CAAC,wBACJrB,GAAG,CACF,yBACA,CAAClD,WAAgB,EAAEwE,KAAK,EAAEC,UAAU,EAAO,GACzC,wCAAwC;oBACxCzE,YAAYwE,MAAMC,WAAW,gBAAgBhF;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":["MinifyPlugin","buildError","error","file","line","WebpackError","message","col","stack","split","slice","join","debugMinify","process","env","NEXT_DEBUG_MINIFY","constructor","options","optimize","compiler","compilation","assets","cache","SourceMapSource","RawSource","mangle","noMangling","compilationSpan","getCompilationSpan","MinifierSpan","traceChild","name","setAttribute","String","traceAsyncFn","assetsList","Object","keys","assetsForMinify","Promise","all","filter","ModuleFilenameHelpers","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","pLimit","scheduledTasks","asset","push","minifySpan","sourceFromInputSource","sourceAndMap","Buffer","isBuffer","minifiedOutput","errors","code","storePromise","newInfo","updateAsset","end","apply","webpack","sources","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":";;;;+BAiCaA;;;eAAAA;;;yBA1BN;+DACY;uBACgB;;;;;;AAEnC,SAASC,WAAWC,KAAU,EAAEC,IAAY;IAC1C,IAAID,MAAME,IAAI,EAAE;QACd,OAAO,IAAIC,qBAAY,CACrB,GAAGF,KAAK,gBAAgB,EAAED,MAAMI,OAAO,CAAC,EAAE,EAAEH,KAAK,CAAC,EAAED,MAAME,IAAI,CAAC,CAAC,EAC9DF,MAAMK,GAAG,CACV,CAAC,EACAL,MAAMM,KAAK,GAAG,CAAC,EAAE,EAAEN,MAAMM,KAAK,CAACC,KAAK,CAAC,MAAMC,KAAK,CAAC,GAAGC,IAAI,CAAC,OAAO,GAAG,IACnE;IAEN;IAEA,IAAIT,MAAMM,KAAK,EAAE;QACf,OAAO,IAAIH,qBAAY,CACrB,GAAGF,KAAK,gBAAgB,EA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9E,kBAAmB+E,OAAO,KAChEA,gBAAO;QAET,MAAMC,aAAa,IAAI,CAACnF,WAAW,CAACe,IAAI;QAExCZ,SAASiF,KAAK,CAACC,eAAe,CAACC,GAAG,CAChCH,YACA,CAAC/E;YACC,MAAME,QAAQF,YAAYmF,QAAQ,CAAC;YAEnC,MAAMC,qBAAqB,CAACC,MAAWC;gBACrC,oCAAoC;gBACpCD,KAAKE,MAAM,CAAC;YACd;YAEA,MAAMC,iBACJX,gBAAO,CAACY,UAAU,CAACC,uBAAuB,CAACC,mBAAmB,CAC5D3F;YAEJwF,eAAeI,SAAS,CAACV,GAAG,CAACH,YAAY,CAACc,OAAOR;gBAC/C,IAAI,CAACQ,MAAMC,UAAU,IAAI;gBACzB,OAAOV,mBAAmBC,MAAMQ;YAClC;YAEA7F,YAAYgF,KAAK,CAACe,aAAa,CAACC,UAAU,CACxC;gBACErF,MAAMoE;gBACNkB,OAAOpB,gBAAO,CAACqB,WAAW,CAACC,kCAAkC;YAC/D,GACA,CAAClG,SACC,IAAI,CAACH,QAAQ,CAACC,UAAUC,aAAaC,QAAQC,OAAO;oBAClDC;oBACAC;gBACF;YAGJJ,YAAYgF,KAAK,CAACoB,YAAY,CAAClB,GAAG,CAACH,YAAY,CAACsB;gBAC9CA,MAAMrB,KAAK,CAACsB,KAAK,CACdC,GAAG,CAAC,wBACJrB,GAAG,CACF,yBACA,CAAClD,WAAgB,EAAEwE,KAAK,EAAEC,UAAU,EAAO,GACzC,wCAAwC;oBACxCzE,YAAYwE,MAAMC,WAAW,gBAAgBhF;YAErD;QACF;IAEJ;AACF"}
|
@@ -35,19 +35,17 @@ export declare class TraceEntryPointsPlugin implements webpack.WebpackPluginInst
|
|
35
35
|
private rootDir;
|
36
36
|
private appDir;
|
37
37
|
private pagesDir;
|
38
|
-
private optOutBundlingPackages;
|
39
38
|
private appDirEnabled?;
|
40
39
|
private tracingRoot;
|
41
40
|
private entryTraces;
|
42
41
|
private traceIgnores;
|
43
42
|
private esmExternals?;
|
44
43
|
private compilerType;
|
45
|
-
constructor({ rootDir, appDir, pagesDir, compilerType,
|
44
|
+
constructor({ rootDir, appDir, pagesDir, compilerType, appDirEnabled, traceIgnores, esmExternals, outputFileTracingRoot, }: {
|
46
45
|
rootDir: string;
|
47
46
|
compilerType: CompilerNameValues;
|
48
47
|
appDir: string | undefined;
|
49
48
|
pagesDir: string | undefined;
|
50
|
-
optOutBundlingPackages: string[];
|
51
49
|
appDirEnabled?: boolean;
|
52
50
|
traceIgnores?: string[];
|
53
51
|
outputFileTracingRoot?: string;
|
@@ -25,7 +25,6 @@ _export(exports, {
|
|
25
25
|
}
|
26
26
|
});
|
27
27
|
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
28
|
-
const _profilingplugin = require("./profiling-plugin");
|
29
28
|
const _iserror = /*#__PURE__*/ _interop_require_default(require("../../../lib/is-error"));
|
30
29
|
const _nft = require("next/dist/compiled/@vercel/nft");
|
31
30
|
const _constants = require("../../../shared/lib/constants");
|
@@ -36,6 +35,7 @@ const _getmodulebuildinfo = require("../loaders/get-module-build-info");
|
|
36
35
|
const _entries = require("../../entries");
|
37
36
|
const _handleexternals = require("../../handle-externals");
|
38
37
|
const _ismetadataroute = require("../../../lib/metadata/is-metadata-route");
|
38
|
+
const _utils = require("../utils");
|
39
39
|
function _interop_require_default(obj) {
|
40
40
|
return obj && obj.__esModule ? obj : {
|
41
41
|
default: obj
|
@@ -97,7 +97,7 @@ function getFilesMapFromReasons(fileList, reasons, ignoreFn) {
|
|
97
97
|
return parentFilesMap;
|
98
98
|
}
|
99
99
|
class TraceEntryPointsPlugin {
|
100
|
-
constructor({ rootDir, appDir, pagesDir, compilerType,
|
100
|
+
constructor({ rootDir, appDir, pagesDir, compilerType, appDirEnabled, traceIgnores, esmExternals, outputFileTracingRoot }){
|
101
101
|
this.buildTraceContext = {};
|
102
102
|
this.rootDir = rootDir;
|
103
103
|
this.appDir = appDir;
|
@@ -107,7 +107,6 @@ class TraceEntryPointsPlugin {
|
|
107
107
|
this.appDirEnabled = appDirEnabled;
|
108
108
|
this.traceIgnores = traceIgnores || [];
|
109
109
|
this.tracingRoot = outputFileTracingRoot || rootDir;
|
110
|
-
this.optOutBundlingPackages = optOutBundlingPackages;
|
111
110
|
this.compilerType = compilerType;
|
112
111
|
}
|
113
112
|
// Here we output all traced assets and webpack chunks to a
|
@@ -397,6 +396,8 @@ class TraceEntryPointsPlugin {
|
|
397
396
|
}
|
398
397
|
apply(compiler) {
|
399
398
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation)=>{
|
399
|
+
const compilationSpan = (0, _utils.getCompilationSpan)(compilation) || (0, _utils.getCompilationSpan)(compiler);
|
400
|
+
const traceEntrypointsPluginSpan = compilationSpan.traceChild('next-trace-entrypoint-plugin');
|
400
401
|
compilation.hooks.processAssets.tapAsync({
|
401
402
|
name: PLUGIN_NAME,
|
402
403
|
stage: _webpack.webpack.Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
@@ -439,8 +440,6 @@ class TraceEntryPointsPlugin {
|
|
439
440
|
throw e;
|
440
441
|
}
|
441
442
|
};
|
442
|
-
const compilationSpan = _profilingplugin.spans.get(compilation) || _profilingplugin.spans.get(compiler);
|
443
|
-
const traceEntrypointsPluginSpan = compilationSpan.traceChild('next-trace-entrypoint-plugin');
|
444
443
|
traceEntrypointsPluginSpan.traceFn(()=>{
|
445
444
|
compilation.hooks.processAssets.tapAsync({
|
446
445
|
name: PLUGIN_NAME,
|
@@ -532,7 +531,7 @@ class TraceEntryPointsPlugin {
|
|
532
531
|
const context = _path.default.dirname(parent);
|
533
532
|
// When in esm externals mode, and using import, we resolve with
|
534
533
|
// ESM resolving options.
|
535
|
-
const { res } = await (0, _handleexternals.resolveExternal)(this.rootDir, this.esmExternals, context, request, isEsmRequested,
|
534
|
+
const { res } = await (0, _handleexternals.resolveExternal)(this.rootDir, this.esmExternals, context, request, isEsmRequested, (options)=>(_, resRequest)=>{
|
536
535
|
return getResolve(options)(parent, resRequest, job);
|
537
536
|
}, undefined, undefined, ESM_RESOLVE_OPTIONS, CJS_RESOLVE_OPTIONS, BASE_ESM_RESOLVE_OPTIONS, BASE_CJS_RESOLVE_OPTIONS);
|
538
537
|
if (!res) {
|