@@ -13,2 +13,4 @@ /* | ||
const PLUGIN_NAME = "InferAsyncModulesPlugin"; | ||
class InferAsyncModulesPlugin { | ||
@@ -21,33 +23,30 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("InferAsyncModulesPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const { moduleGraph } = compilation; | ||
compilation.hooks.finishModules.tap( | ||
"InferAsyncModulesPlugin", | ||
modules => { | ||
/** @type {Set<Module>} */ | ||
const queue = new Set(); | ||
for (const module of modules) { | ||
if (module.buildMeta && module.buildMeta.async) { | ||
queue.add(module); | ||
} | ||
compilation.hooks.finishModules.tap(PLUGIN_NAME, modules => { | ||
/** @type {Set<Module>} */ | ||
const queue = new Set(); | ||
for (const module of modules) { | ||
if (module.buildMeta && module.buildMeta.async) { | ||
queue.add(module); | ||
} | ||
for (const module of queue) { | ||
moduleGraph.setAsync(module); | ||
for (const [ | ||
originModule, | ||
connections | ||
] of moduleGraph.getIncomingConnectionsByOriginModule(module)) { | ||
if ( | ||
connections.some( | ||
c => | ||
c.dependency instanceof HarmonyImportDependency && | ||
c.isTargetActive(undefined) | ||
) | ||
) { | ||
queue.add(/** @type {Module} */ (originModule)); | ||
} | ||
} | ||
for (const module of queue) { | ||
moduleGraph.setAsync(module); | ||
for (const [ | ||
originModule, | ||
connections | ||
] of moduleGraph.getIncomingConnectionsByOriginModule(module)) { | ||
if ( | ||
connections.some( | ||
c => | ||
c.dependency instanceof HarmonyImportDependency && | ||
c.isTargetActive(undefined) | ||
) | ||
) { | ||
queue.add(/** @type {Module} */ (originModule)); | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -54,0 +53,0 @@ } |
@@ -14,2 +14,4 @@ /* | ||
const PLUGIN_NAME = "AutomaticPrefetchPlugin"; | ||
class AutomaticPrefetchPlugin { | ||
@@ -23,3 +25,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"AutomaticPrefetchPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -34,3 +36,3 @@ compilation.dependencyFactories.set( | ||
let lastModules = null; | ||
compiler.hooks.afterCompile.tap("AutomaticPrefetchPlugin", compilation => { | ||
compiler.hooks.afterCompile.tap(PLUGIN_NAME, compilation => { | ||
lastModules = []; | ||
@@ -47,24 +49,21 @@ | ||
}); | ||
compiler.hooks.make.tapAsync( | ||
"AutomaticPrefetchPlugin", | ||
(compilation, callback) => { | ||
if (!lastModules) return callback(); | ||
asyncLib.each( | ||
lastModules, | ||
(m, callback) => { | ||
compilation.addModuleChain( | ||
m.context || compiler.context, | ||
new PrefetchDependency(`!!${m.request}`), | ||
callback | ||
); | ||
}, | ||
err => { | ||
lastModules = null; | ||
callback(err); | ||
} | ||
); | ||
} | ||
); | ||
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => { | ||
if (!lastModules) return callback(); | ||
asyncLib.each( | ||
lastModules, | ||
(m, callback) => { | ||
compilation.addModuleChain( | ||
m.context || compiler.context, | ||
new PrefetchDependency(`!!${m.request}`), | ||
callback | ||
); | ||
}, | ||
err => { | ||
lastModules = null; | ||
callback(err); | ||
} | ||
); | ||
}); | ||
} | ||
} | ||
module.exports = AutomaticPrefetchPlugin; |
@@ -47,2 +47,4 @@ /* | ||
const PLUGIN_NAME = "BannerPlugin"; | ||
class BannerPlugin { | ||
@@ -95,43 +97,37 @@ /** | ||
compiler.hooks.compilation.tap("BannerPlugin", compilation => { | ||
compilation.hooks.processAssets.tap( | ||
{ | ||
name: "BannerPlugin", | ||
stage | ||
}, | ||
() => { | ||
for (const chunk of compilation.chunks) { | ||
if (options.entryOnly && !chunk.canBeInitial()) { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.processAssets.tap({ name: PLUGIN_NAME, stage }, () => { | ||
for (const chunk of compilation.chunks) { | ||
if (options.entryOnly && !chunk.canBeInitial()) { | ||
continue; | ||
} | ||
for (const file of chunk.files) { | ||
if (!matchObject(file)) { | ||
continue; | ||
} | ||
for (const file of chunk.files) { | ||
if (!matchObject(file)) { | ||
continue; | ||
} | ||
/** @type {PathData} */ | ||
const data = { chunk, filename: file }; | ||
/** @type {PathData} */ | ||
const data = { chunk, filename: file }; | ||
const comment = compilation.getPath( | ||
/** @type {TemplatePath} */ | ||
(banner), | ||
data | ||
); | ||
const comment = compilation.getPath( | ||
/** @type {TemplatePath} */ | ||
(banner), | ||
data | ||
); | ||
compilation.updateAsset(file, old => { | ||
const cached = cache.get(old); | ||
if (!cached || cached.comment !== comment) { | ||
const source = options.footer | ||
? new ConcatSource(old, "\n", comment) | ||
: new ConcatSource(comment, "\n", old); | ||
cache.set(old, { source, comment }); | ||
return source; | ||
} | ||
return cached.source; | ||
}); | ||
} | ||
compilation.updateAsset(file, old => { | ||
const cached = cache.get(old); | ||
if (!cached || cached.comment !== comment) { | ||
const source = options.footer | ||
? new ConcatSource(old, "\n", comment) | ||
: new ConcatSource(comment, "\n", old); | ||
cache.set(old, { source, comment }); | ||
return source; | ||
} | ||
return cached.source; | ||
}); | ||
} | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -138,0 +134,0 @@ } |
@@ -15,2 +15,3 @@ /* | ||
const BUILD_DEPENDENCIES_KEY = Symbol("build dependencies key"); | ||
const PLUGIN_NAME = "IdleFileCachePlugin"; | ||
@@ -59,3 +60,3 @@ class IdleFileCachePlugin { | ||
compiler.cache.hooks.store.tap( | ||
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK }, | ||
(identifier, etag, data) => { | ||
@@ -69,3 +70,3 @@ pendingIdleTasks.set(identifier, () => | ||
compiler.cache.hooks.get.tapPromise( | ||
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK }, | ||
(identifier, etag, gotHandlers) => { | ||
@@ -97,3 +98,3 @@ const restore = () => | ||
compiler.cache.hooks.storeBuildDependencies.tap( | ||
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK }, | ||
dependencies => { | ||
@@ -109,3 +110,3 @@ pendingIdleTasks.set(BUILD_DEPENDENCIES_KEY, () => | ||
compiler.cache.hooks.shutdown.tapPromise( | ||
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK }, | ||
() => { | ||
@@ -173,5 +174,3 @@ if (idleTimer) { | ||
.catch(err => { | ||
const logger = compiler.getInfrastructureLogger( | ||
"IdleFileCachePlugin" | ||
); | ||
const logger = compiler.getInfrastructureLogger(PLUGIN_NAME); | ||
logger.warn(`Background tasks during idle failed: ${err.message}`); | ||
@@ -186,3 +185,3 @@ logger.debug(err.stack); | ||
compiler.cache.hooks.beginIdle.tap( | ||
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK }, | ||
() => { | ||
@@ -192,3 +191,3 @@ const isLargeChange = timeSpendInBuild > avgTimeSpendInStore * 2; | ||
compiler | ||
.getInfrastructureLogger("IdleFileCachePlugin") | ||
.getInfrastructureLogger(PLUGIN_NAME) | ||
.log( | ||
@@ -204,3 +203,3 @@ `Initial cache was generated and cache will be persisted in ${ | ||
compiler | ||
.getInfrastructureLogger("IdleFileCachePlugin") | ||
.getInfrastructureLogger(PLUGIN_NAME) | ||
.log( | ||
@@ -230,3 +229,3 @@ `Spend ${Math.round(timeSpendInBuild) / 1000}s in build and ${ | ||
compiler.cache.hooks.endIdle.tap( | ||
{ name: "IdleFileCachePlugin", stage: Cache.STAGE_DISK }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_DISK }, | ||
() => { | ||
@@ -240,3 +239,3 @@ if (idleTimer) { | ||
); | ||
compiler.hooks.done.tap("IdleFileCachePlugin", stats => { | ||
compiler.hooks.done.tap(PLUGIN_NAME, stats => { | ||
// 10% build overhead is ignored, as it's not cacheable | ||
@@ -243,0 +242,0 @@ timeSpendInBuild *= 0.9; |
@@ -21,2 +21,4 @@ /* | ||
const PLUGIN_NAME = "MemoryWithGcCachePlugin"; | ||
class MemoryWithGcCachePlugin { | ||
@@ -43,4 +45,4 @@ /** | ||
let cachePosition = 0; | ||
const logger = compiler.getInfrastructureLogger("MemoryWithGcCachePlugin"); | ||
compiler.hooks.afterDone.tap("MemoryWithGcCachePlugin", () => { | ||
const logger = compiler.getInfrastructureLogger(PLUGIN_NAME); | ||
compiler.hooks.afterDone.tap(PLUGIN_NAME, () => { | ||
generation++; | ||
@@ -96,3 +98,3 @@ let clearedEntries = 0; | ||
compiler.cache.hooks.store.tap( | ||
{ name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY }, | ||
(identifier, etag, data) => { | ||
@@ -103,3 +105,3 @@ cache.set(identifier, { etag, data }); | ||
compiler.cache.hooks.get.tap( | ||
{ name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY }, | ||
(identifier, etag, gotHandlers) => { | ||
@@ -136,3 +138,3 @@ const cacheEntry = cache.get(identifier); | ||
compiler.cache.hooks.shutdown.tap( | ||
{ name: "MemoryWithGcCachePlugin", stage: Cache.STAGE_MEMORY }, | ||
{ name: PLUGIN_NAME, stage: Cache.STAGE_MEMORY }, | ||
() => { | ||
@@ -139,0 +141,0 @@ cache.clear(); |
@@ -100,2 +100,4 @@ /* | ||
const PLUGIN_NAME = "ResolverCachePlugin"; | ||
class ResolverCachePlugin { | ||
@@ -108,3 +110,3 @@ /** | ||
apply(compiler) { | ||
const cache = compiler.getCache("ResolverCachePlugin"); | ||
const cache = compiler.getCache(PLUGIN_NAME); | ||
/** @type {FileSystemInfo} */ | ||
@@ -118,8 +120,8 @@ let fileSystemInfo; | ||
let concurrentResolves = 0; | ||
compiler.hooks.thisCompilation.tap("ResolverCachePlugin", compilation => { | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
snapshotOptions = compilation.options.snapshot.resolve; | ||
fileSystemInfo = compilation.fileSystemInfo; | ||
compilation.hooks.finishModules.tap("ResolverCachePlugin", () => { | ||
compilation.hooks.finishModules.tap(PLUGIN_NAME, () => { | ||
if (realResolves + cachedResolves > 0) { | ||
const logger = compilation.getLogger("webpack.ResolverCachePlugin"); | ||
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`); | ||
logger.log( | ||
@@ -266,3 +268,3 @@ `${Math.round( | ||
(_hook); | ||
hook.tap("ResolverCachePlugin", (resolver, options, userOptions) => { | ||
hook.tap(PLUGIN_NAME, (resolver, options, userOptions) => { | ||
if ( | ||
@@ -280,3 +282,3 @@ /** @type {ResolveOptions & { cache: boolean }} */ | ||
{ | ||
name: "ResolverCachePlugin", | ||
name: PLUGIN_NAME, | ||
stage: -100 | ||
@@ -283,0 +285,0 @@ }, |
@@ -299,2 +299,4 @@ /* | ||
const PLUGIN_NAME = "CleanPlugin"; | ||
class CleanPlugin { | ||
@@ -353,3 +355,3 @@ /** | ||
{ | ||
name: "CleanPlugin", | ||
name: PLUGIN_NAME, | ||
stage: 100 | ||
@@ -359,3 +361,3 @@ }, | ||
const hooks = CleanPlugin.getCompilationHooks(compilation); | ||
const logger = compilation.getLogger("webpack.CleanPlugin"); | ||
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`); | ||
const fs = /** @type {OutputFileSystem} */ (compiler.outputFileSystem); | ||
@@ -366,3 +368,3 @@ | ||
new Error( | ||
"CleanPlugin: Output filesystem doesn't support listing directories (readdir)" | ||
`${PLUGIN_NAME}: Output filesystem doesn't support listing directories (readdir)` | ||
) | ||
@@ -369,0 +371,0 @@ ); |
@@ -11,3 +11,7 @@ /* | ||
/** @typedef {Parameters<import("schema-utils").validate>[0] & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean, description?: string, negatedDescription?: string, resetDescription?: string } }} Schema */ | ||
/** @typedef {import("json-schema").JSONSchema4} JSONSchema4 */ | ||
/** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */ | ||
/** @typedef {import("json-schema").JSONSchema7} JSONSchema7 */ | ||
/** @typedef {JSONSchema4 | JSONSchema6 | JSONSchema7} JSONSchema */ | ||
/** @typedef {JSONSchema & { absolutePath: boolean, instanceof: string, cli: { helper?: boolean, exclude?: boolean, description?: string, negatedDescription?: string, resetDescription?: string } }} Schema */ | ||
@@ -14,0 +18,0 @@ // TODO add originPath to PathItem for better errors |
@@ -628,3 +628,4 @@ /* | ||
const err = new WebpackError( | ||
`compiler.runAsChild callback error: ${runAsChildErr}` | ||
`compiler.runAsChild callback error: ${runAsChildErr}`, | ||
{ cause: runAsChildErr } | ||
); | ||
@@ -631,0 +632,0 @@ err.details = /** @type {Error} */ (runAsChildErr).stack; |
@@ -25,2 +25,3 @@ /* | ||
/** @typedef {import("../Entrypoint")} Entrypoint */ | ||
/** @typedef {import("../WebpackError")} WebpackError */ | ||
@@ -214,5 +215,6 @@ const handledDeprecatedNoEmitOnErrors = util.deprecate( | ||
i.module && | ||
(!warning.module || | ||
(!(/** @type {WebpackError} */ (warning).module) || | ||
!i.module.test( | ||
warning.module.readableIdentifier(requestShortener) | ||
/** @type {WebpackError} */ | ||
(warning).module.readableIdentifier(requestShortener) | ||
)) | ||
@@ -222,3 +224,7 @@ ) { | ||
} | ||
if (i.file && (!warning.file || !i.file.test(warning.file))) { | ||
if ( | ||
i.file && | ||
(!(/** @type {WebpackError} */ (warning).file) || | ||
!i.file.test(/** @type {WebpackError} */ (warning).file)) | ||
) { | ||
return false; | ||
@@ -225,0 +231,0 @@ } |
@@ -34,2 +34,3 @@ /* | ||
const slashCode = "/".charCodeAt(0); | ||
const PLUGIN_NAME = "ContainerReferencePlugin"; | ||
@@ -83,3 +84,3 @@ class ContainerReferencePlugin { | ||
compiler.hooks.compilation.tap( | ||
"ContainerReferencePlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -101,33 +102,30 @@ compilation.dependencyFactories.set( | ||
normalModuleFactory.hooks.factorize.tap( | ||
"ContainerReferencePlugin", | ||
data => { | ||
if (!data.request.includes("!")) { | ||
for (const [key, config] of remotes) { | ||
if ( | ||
data.request.startsWith(`${key}`) && | ||
(data.request.length === key.length || | ||
data.request.charCodeAt(key.length) === slashCode) | ||
) { | ||
return new RemoteModule( | ||
data.request, | ||
config.external.map((external, i) => | ||
external.startsWith("internal ") | ||
? external.slice(9) | ||
: `webpack/container/reference/${key}${ | ||
i ? `/fallback-${i}` : "" | ||
}` | ||
), | ||
`.${data.request.slice(key.length)}`, | ||
config.shareScope | ||
); | ||
} | ||
normalModuleFactory.hooks.factorize.tap(PLUGIN_NAME, data => { | ||
if (!data.request.includes("!")) { | ||
for (const [key, config] of remotes) { | ||
if ( | ||
data.request.startsWith(`${key}`) && | ||
(data.request.length === key.length || | ||
data.request.charCodeAt(key.length) === slashCode) | ||
) { | ||
return new RemoteModule( | ||
data.request, | ||
config.external.map((external, i) => | ||
external.startsWith("internal ") | ||
? external.slice(9) | ||
: `webpack/container/reference/${key}${ | ||
i ? `/fallback-${i}` : "" | ||
}` | ||
), | ||
`.${data.request.slice(key.length)}`, | ||
config.shareScope | ||
); | ||
} | ||
} | ||
} | ||
); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("ContainerReferencePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
set.add(RuntimeGlobals.module); | ||
@@ -134,0 +132,0 @@ set.add(RuntimeGlobals.moduleFactoriesAddOnly); |
@@ -40,2 +40,3 @@ /* | ||
const compilationHooksMap = new WeakMap(); | ||
const PLUGIN_NAME = "ModuleFederationPlugin"; | ||
@@ -93,3 +94,3 @@ class ModuleFederationPlugin { | ||
} | ||
compiler.hooks.afterPlugins.tap("ModuleFederationPlugin", () => { | ||
compiler.hooks.afterPlugins.tap(PLUGIN_NAME, () => { | ||
if ( | ||
@@ -96,0 +97,0 @@ options.exposes && |
@@ -10,2 +10,4 @@ /* | ||
const PLUGIN_NAME = "ContextExclusionPlugin"; | ||
class ContextExclusionPlugin { | ||
@@ -25,4 +27,4 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.contextModuleFactory.tap("ContextExclusionPlugin", cmf => { | ||
cmf.hooks.contextModuleFiles.tap("ContextExclusionPlugin", files => | ||
compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, cmf => { | ||
cmf.hooks.contextModuleFiles.tap(PLUGIN_NAME, files => | ||
files.filter(filePath => !this.negativeMatcher.test(filePath)) | ||
@@ -29,0 +31,0 @@ ); |
@@ -17,2 +17,4 @@ /* | ||
const PLUGIN_NAME = "ContextReplacementPlugin"; | ||
class ContextReplacementPlugin { | ||
@@ -99,4 +101,4 @@ /** | ||
compiler.hooks.contextModuleFactory.tap("ContextReplacementPlugin", cmf => { | ||
cmf.hooks.beforeResolve.tap("ContextReplacementPlugin", result => { | ||
compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, cmf => { | ||
cmf.hooks.beforeResolve.tap(PLUGIN_NAME, result => { | ||
if (!result) return; | ||
@@ -123,3 +125,3 @@ if (resourceRegExp.test(result.request)) { | ||
}); | ||
cmf.hooks.afterResolve.tap("ContextReplacementPlugin", result => { | ||
cmf.hooks.afterResolve.tap(PLUGIN_NAME, result => { | ||
if (!result) return; | ||
@@ -126,0 +128,0 @@ if (resourceRegExp.test(result.resource)) { |
@@ -295,3 +295,3 @@ /* | ||
return obj; | ||
}, {}) | ||
}, /** @type {Record<string, string>} */ ({})) | ||
); | ||
@@ -298,0 +298,0 @@ |
@@ -388,5 +388,7 @@ /* | ||
if (module instanceof CssModule && module.hot) { | ||
const exports = | ||
/** @type {BuildInfo} */ | ||
(module.buildInfo).cssData.exports; | ||
const cssData = /** @type {BuildInfo} */ (module.buildInfo).cssData; | ||
if (!cssData) { | ||
return source; | ||
} | ||
const exports = cssData.exports; | ||
const stringifiedExports = JSON.stringify( | ||
@@ -397,3 +399,3 @@ JSON.stringify( | ||
return obj; | ||
}, {}) | ||
}, /** @type {Record<string, string>} */ ({})) | ||
) | ||
@@ -400,0 +402,0 @@ ); |
@@ -14,2 +14,4 @@ /* | ||
const PLUGIN_NAME = "DelegatedPlugin"; | ||
class DelegatedPlugin { | ||
@@ -30,3 +32,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"DelegatedPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -40,3 +42,3 @@ compilation.dependencyFactories.set( | ||
compiler.hooks.compile.tap("DelegatedPlugin", ({ normalModuleFactory }) => { | ||
compiler.hooks.compile.tap(PLUGIN_NAME, ({ normalModuleFactory }) => { | ||
new DelegatedModuleFactoryPlugin({ | ||
@@ -43,0 +45,0 @@ associatedObjectForCache: compiler.root, |
@@ -18,2 +18,4 @@ /* | ||
const PLUGIN_NAME = "HarmonyDetectionParserPlugin"; | ||
module.exports = class HarmonyDetectionParserPlugin { | ||
@@ -33,3 +35,3 @@ /** | ||
apply(parser) { | ||
parser.hooks.program.tap("HarmonyDetectionParserPlugin", ast => { | ||
parser.hooks.program.tap(PLUGIN_NAME, ast => { | ||
const isStrictHarmony = | ||
@@ -67,3 +69,3 @@ parser.state.module.type === JAVASCRIPT_MODULE_TYPE_ESM; | ||
parser.hooks.topLevelAwait.tap("HarmonyDetectionParserPlugin", () => { | ||
parser.hooks.topLevelAwait.tap(PLUGIN_NAME, () => { | ||
const module = parser.state.module; | ||
@@ -111,17 +113,9 @@ if (!this.topLevelAwait) { | ||
.for(identifier) | ||
.tap("HarmonyDetectionParserPlugin", nullInHarmony); | ||
parser.hooks.typeof | ||
.for(identifier) | ||
.tap("HarmonyDetectionParserPlugin", skipInHarmony); | ||
parser.hooks.evaluate | ||
.for(identifier) | ||
.tap("HarmonyDetectionParserPlugin", nullInHarmony); | ||
parser.hooks.expression | ||
.for(identifier) | ||
.tap("HarmonyDetectionParserPlugin", skipInHarmony); | ||
parser.hooks.call | ||
.for(identifier) | ||
.tap("HarmonyDetectionParserPlugin", skipInHarmony); | ||
.tap(PLUGIN_NAME, nullInHarmony); | ||
parser.hooks.typeof.for(identifier).tap(PLUGIN_NAME, skipInHarmony); | ||
parser.hooks.evaluate.for(identifier).tap(PLUGIN_NAME, nullInHarmony); | ||
parser.hooks.expression.for(identifier).tap(PLUGIN_NAME, skipInHarmony); | ||
parser.hooks.call.for(identifier).tap(PLUGIN_NAME, skipInHarmony); | ||
} | ||
} | ||
}; |
@@ -15,2 +15,4 @@ /* | ||
const PLUGIN_NAME = "HarmonyTopLevelThisParserPlugin"; | ||
class HarmonyTopLevelThisParserPlugin { | ||
@@ -22,17 +24,15 @@ /** | ||
apply(parser) { | ||
parser.hooks.expression | ||
.for("this") | ||
.tap("HarmonyTopLevelThisParserPlugin", node => { | ||
if (!parser.scope.topLevelScope) return; | ||
if (HarmonyExports.isEnabled(parser.state)) { | ||
const dep = new ConstDependency( | ||
"undefined", | ||
/** @type {Range} */ (node.range), | ||
null | ||
); | ||
dep.loc = /** @type {DependencyLocation} */ (node.loc); | ||
parser.state.module.addPresentationalDependency(dep); | ||
return true; | ||
} | ||
}); | ||
parser.hooks.expression.for("this").tap(PLUGIN_NAME, node => { | ||
if (!parser.scope.topLevelScope) return; | ||
if (HarmonyExports.isEnabled(parser.state)) { | ||
const dep = new ConstDependency( | ||
"undefined", | ||
/** @type {Range} */ (node.range), | ||
null | ||
); | ||
dep.loc = /** @type {DependencyLocation} */ (node.loc); | ||
parser.state.module.addPresentationalDependency(dep); | ||
return true; | ||
} | ||
}); | ||
} | ||
@@ -39,0 +39,0 @@ } |
@@ -55,2 +55,4 @@ /* | ||
const PLUGIN_NAME = "ImportMetaContextDependencyParserPlugin"; | ||
module.exports = class ImportMetaContextDependencyParserPlugin { | ||
@@ -64,3 +66,3 @@ /** | ||
.for("import.meta.webpackContext") | ||
.tap("ImportMetaContextDependencyParserPlugin", expr => | ||
.tap(PLUGIN_NAME, expr => | ||
evaluateToIdentifier( | ||
@@ -75,3 +77,3 @@ "import.meta.webpackContext", | ||
.for("import.meta.webpackContext") | ||
.tap("ImportMetaContextDependencyParserPlugin", expr => { | ||
.tap(PLUGIN_NAME, expr => { | ||
if (expr.arguments.length < 1 || expr.arguments.length > 2) return; | ||
@@ -78,0 +80,0 @@ const [directoryNode, optionsNode] = expr.arguments; |
@@ -34,2 +34,4 @@ /* | ||
const PLUGIN_NAME = "LoaderPlugin"; | ||
class LoaderPlugin { | ||
@@ -43,3 +45,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"LoaderPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -57,6 +59,6 @@ compilation.dependencyFactories.set( | ||
compiler.hooks.compilation.tap("LoaderPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const moduleGraph = compilation.moduleGraph; | ||
NormalModule.getCompilationHooks(compilation).loader.tap( | ||
"LoaderPlugin", | ||
PLUGIN_NAME, | ||
loaderContext => { | ||
@@ -63,0 +65,0 @@ loaderContext.loadModule = (request, callback) => { |
@@ -15,2 +15,4 @@ /* | ||
const PLUGIN_NAME = "RequireContextDependencyParserPlugin"; | ||
module.exports = class RequireContextDependencyParserPlugin { | ||
@@ -22,50 +24,48 @@ /** | ||
apply(parser) { | ||
parser.hooks.call | ||
.for("require.context") | ||
.tap("RequireContextDependencyParserPlugin", expr => { | ||
let regExp = /^\.\/.*$/; | ||
let recursive = true; | ||
/** @type {ContextMode} */ | ||
let mode = "sync"; | ||
switch (expr.arguments.length) { | ||
case 4: { | ||
const modeExpr = parser.evaluateExpression(expr.arguments[3]); | ||
if (!modeExpr.isString()) return; | ||
mode = /** @type {ContextMode} */ (modeExpr.string); | ||
} | ||
// falls through | ||
case 3: { | ||
const regExpExpr = parser.evaluateExpression(expr.arguments[2]); | ||
if (!regExpExpr.isRegExp()) return; | ||
regExp = /** @type {RegExp} */ (regExpExpr.regExp); | ||
} | ||
// falls through | ||
case 2: { | ||
const recursiveExpr = parser.evaluateExpression(expr.arguments[1]); | ||
if (!recursiveExpr.isBoolean()) return; | ||
recursive = /** @type {boolean} */ (recursiveExpr.bool); | ||
} | ||
// falls through | ||
case 1: { | ||
const requestExpr = parser.evaluateExpression(expr.arguments[0]); | ||
if (!requestExpr.isString()) return; | ||
const dep = new RequireContextDependency( | ||
{ | ||
request: /** @type {string} */ (requestExpr.string), | ||
recursive, | ||
regExp, | ||
mode, | ||
category: "commonjs" | ||
}, | ||
/** @type {Range} */ | ||
(expr.range) | ||
); | ||
dep.loc = /** @type {DependencyLocation} */ (expr.loc); | ||
dep.optional = Boolean(parser.scope.inTry); | ||
parser.state.current.addDependency(dep); | ||
return true; | ||
} | ||
parser.hooks.call.for("require.context").tap(PLUGIN_NAME, expr => { | ||
let regExp = /^\.\/.*$/; | ||
let recursive = true; | ||
/** @type {ContextMode} */ | ||
let mode = "sync"; | ||
switch (expr.arguments.length) { | ||
case 4: { | ||
const modeExpr = parser.evaluateExpression(expr.arguments[3]); | ||
if (!modeExpr.isString()) return; | ||
mode = /** @type {ContextMode} */ (modeExpr.string); | ||
} | ||
}); | ||
// falls through | ||
case 3: { | ||
const regExpExpr = parser.evaluateExpression(expr.arguments[2]); | ||
if (!regExpExpr.isRegExp()) return; | ||
regExp = /** @type {RegExp} */ (regExpExpr.regExp); | ||
} | ||
// falls through | ||
case 2: { | ||
const recursiveExpr = parser.evaluateExpression(expr.arguments[1]); | ||
if (!recursiveExpr.isBoolean()) return; | ||
recursive = /** @type {boolean} */ (recursiveExpr.bool); | ||
} | ||
// falls through | ||
case 1: { | ||
const requestExpr = parser.evaluateExpression(expr.arguments[0]); | ||
if (!requestExpr.isString()) return; | ||
const dep = new RequireContextDependency( | ||
{ | ||
request: /** @type {string} */ (requestExpr.string), | ||
recursive, | ||
regExp, | ||
mode, | ||
category: "commonjs" | ||
}, | ||
/** @type {Range} */ | ||
(expr.range) | ||
); | ||
dep.loc = /** @type {DependencyLocation} */ (expr.loc); | ||
dep.optional = Boolean(parser.scope.inTry); | ||
parser.state.current.addDependency(dep); | ||
return true; | ||
} | ||
} | ||
}); | ||
} | ||
}; |
@@ -20,2 +20,4 @@ /* | ||
const PLUGIN_NAME = "RequireEnsureDependenciesBlockParserPlugin"; | ||
module.exports = class RequireEnsureDependenciesBlockParserPlugin { | ||
@@ -27,12 +29,22 @@ /** | ||
apply(parser) { | ||
parser.hooks.call | ||
.for("require.ensure") | ||
.tap("RequireEnsureDependenciesBlockParserPlugin", expr => { | ||
/** @type {string | GroupOptions | null} */ | ||
let chunkName = null; | ||
let errorExpressionArg = null; | ||
let errorExpression = null; | ||
switch (expr.arguments.length) { | ||
case 4: { | ||
const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]); | ||
parser.hooks.call.for("require.ensure").tap(PLUGIN_NAME, expr => { | ||
/** @type {string | GroupOptions | null} */ | ||
let chunkName = null; | ||
let errorExpressionArg = null; | ||
let errorExpression = null; | ||
switch (expr.arguments.length) { | ||
case 4: { | ||
const chunkNameExpr = parser.evaluateExpression(expr.arguments[3]); | ||
if (!chunkNameExpr.isString()) return; | ||
chunkName = | ||
/** @type {string} */ | ||
(chunkNameExpr.string); | ||
} | ||
// falls through | ||
case 3: { | ||
errorExpressionArg = expr.arguments[2]; | ||
errorExpression = getFunctionExpression(errorExpressionArg); | ||
if (!errorExpression && !chunkName) { | ||
const chunkNameExpr = parser.evaluateExpression(expr.arguments[2]); | ||
if (!chunkNameExpr.isString()) return; | ||
@@ -43,105 +55,87 @@ chunkName = | ||
} | ||
// falls through | ||
case 3: { | ||
errorExpressionArg = expr.arguments[2]; | ||
errorExpression = getFunctionExpression(errorExpressionArg); | ||
} | ||
// falls through | ||
case 2: { | ||
const dependenciesExpr = parser.evaluateExpression(expr.arguments[0]); | ||
const dependenciesItems = /** @type {BasicEvaluatedExpression[]} */ ( | ||
dependenciesExpr.isArray() | ||
? dependenciesExpr.items | ||
: [dependenciesExpr] | ||
); | ||
const successExpressionArg = expr.arguments[1]; | ||
const successExpression = getFunctionExpression(successExpressionArg); | ||
if (!errorExpression && !chunkName) { | ||
const chunkNameExpr = parser.evaluateExpression( | ||
expr.arguments[2] | ||
); | ||
if (!chunkNameExpr.isString()) return; | ||
chunkName = | ||
/** @type {string} */ | ||
(chunkNameExpr.string); | ||
} | ||
if (successExpression) { | ||
parser.walkExpressions(successExpression.expressions); | ||
} | ||
// falls through | ||
case 2: { | ||
const dependenciesExpr = parser.evaluateExpression( | ||
expr.arguments[0] | ||
); | ||
const dependenciesItems = | ||
/** @type {BasicEvaluatedExpression[]} */ ( | ||
dependenciesExpr.isArray() | ||
? dependenciesExpr.items | ||
: [dependenciesExpr] | ||
); | ||
const successExpressionArg = expr.arguments[1]; | ||
const successExpression = | ||
getFunctionExpression(successExpressionArg); | ||
if (errorExpression) { | ||
parser.walkExpressions(errorExpression.expressions); | ||
} | ||
if (successExpression) { | ||
parser.walkExpressions(successExpression.expressions); | ||
} | ||
if (errorExpression) { | ||
parser.walkExpressions(errorExpression.expressions); | ||
} | ||
const depBlock = new RequireEnsureDependenciesBlock( | ||
chunkName, | ||
/** @type {DependencyLocation} */ | ||
(expr.loc) | ||
); | ||
const errorCallbackExists = | ||
expr.arguments.length === 4 || | ||
(!chunkName && expr.arguments.length === 3); | ||
const dep = new RequireEnsureDependency( | ||
/** @type {Range} */ (expr.range), | ||
/** @type {Range} */ (expr.arguments[1].range), | ||
errorCallbackExists && | ||
/** @type {Range} */ (expr.arguments[2].range) | ||
); | ||
dep.loc = /** @type {DependencyLocation} */ (expr.loc); | ||
depBlock.addDependency(dep); | ||
const old = parser.state.current; | ||
parser.state.current = /** @type {TODO} */ (depBlock); | ||
try { | ||
let failed = false; | ||
parser.inScope([], () => { | ||
for (const ee of dependenciesItems) { | ||
if (ee.isString()) { | ||
const ensureDependency = new RequireEnsureItemDependency( | ||
/** @type {string} */ (ee.string) | ||
); | ||
ensureDependency.loc = | ||
/** @type {DependencyLocation} */ | ||
(expr.loc); | ||
depBlock.addDependency(ensureDependency); | ||
} else { | ||
failed = true; | ||
} | ||
} | ||
}); | ||
if (failed) { | ||
return; | ||
} | ||
if (successExpression) { | ||
if (successExpression.fn.body.type === "BlockStatement") { | ||
parser.walkStatement(successExpression.fn.body); | ||
const depBlock = new RequireEnsureDependenciesBlock( | ||
chunkName, | ||
/** @type {DependencyLocation} */ | ||
(expr.loc) | ||
); | ||
const errorCallbackExists = | ||
expr.arguments.length === 4 || | ||
(!chunkName && expr.arguments.length === 3); | ||
const dep = new RequireEnsureDependency( | ||
/** @type {Range} */ (expr.range), | ||
/** @type {Range} */ (expr.arguments[1].range), | ||
errorCallbackExists && | ||
/** @type {Range} */ (expr.arguments[2].range) | ||
); | ||
dep.loc = /** @type {DependencyLocation} */ (expr.loc); | ||
depBlock.addDependency(dep); | ||
const old = parser.state.current; | ||
parser.state.current = /** @type {TODO} */ (depBlock); | ||
try { | ||
let failed = false; | ||
parser.inScope([], () => { | ||
for (const ee of dependenciesItems) { | ||
if (ee.isString()) { | ||
const ensureDependency = new RequireEnsureItemDependency( | ||
/** @type {string} */ (ee.string) | ||
); | ||
ensureDependency.loc = | ||
/** @type {DependencyLocation} */ | ||
(expr.loc); | ||
depBlock.addDependency(ensureDependency); | ||
} else { | ||
parser.walkExpression(successExpression.fn.body); | ||
failed = true; | ||
} | ||
} | ||
old.addBlock(depBlock); | ||
} finally { | ||
parser.state.current = old; | ||
}); | ||
if (failed) { | ||
return; | ||
} | ||
if (!successExpression) { | ||
parser.walkExpression(successExpressionArg); | ||
} | ||
if (errorExpression) { | ||
if (errorExpression.fn.body.type === "BlockStatement") { | ||
parser.walkStatement(errorExpression.fn.body); | ||
if (successExpression) { | ||
if (successExpression.fn.body.type === "BlockStatement") { | ||
parser.walkStatement(successExpression.fn.body); | ||
} else { | ||
parser.walkExpression(errorExpression.fn.body); | ||
parser.walkExpression(successExpression.fn.body); | ||
} | ||
} else if (errorExpressionArg) { | ||
parser.walkExpression(errorExpressionArg); | ||
} | ||
return true; | ||
old.addBlock(depBlock); | ||
} finally { | ||
parser.state.current = old; | ||
} | ||
if (!successExpression) { | ||
parser.walkExpression(successExpressionArg); | ||
} | ||
if (errorExpression) { | ||
if (errorExpression.fn.body.type === "BlockStatement") { | ||
parser.walkStatement(errorExpression.fn.body); | ||
} else { | ||
parser.walkExpression(errorExpression.fn.body); | ||
} | ||
} else if (errorExpressionArg) { | ||
parser.walkExpression(errorExpressionArg); | ||
} | ||
return true; | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
}; |
@@ -16,2 +16,4 @@ /* | ||
const PLUGIN_NAME = "DllEntryPlugin"; | ||
class DllEntryPlugin { | ||
@@ -36,3 +38,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"DllEntryPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -50,3 +52,3 @@ const dllModuleFactory = new DllModuleFactory(); | ||
); | ||
compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => { | ||
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => { | ||
compilation.addEntry( | ||
@@ -53,0 +55,0 @@ this.context, |
@@ -27,2 +27,4 @@ /* | ||
const PLUGIN_NAME = "DllPlugin"; | ||
class DllPlugin { | ||
@@ -46,3 +48,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.entryOption.tap("DllPlugin", (context, entry) => { | ||
compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => { | ||
if (typeof entry !== "function") { | ||
@@ -60,3 +62,3 @@ for (const name of Object.keys(entry)) { | ||
throw new Error( | ||
"DllPlugin doesn't support dynamic entry (function) yet" | ||
`${PLUGIN_NAME} doesn't support dynamic entry (function) yet` | ||
); | ||
@@ -68,3 +70,3 @@ } | ||
if (!this.options.entryOnly) { | ||
new FlagAllModulesAsUsedPlugin("DllPlugin").apply(compiler); | ||
new FlagAllModulesAsUsedPlugin(PLUGIN_NAME).apply(compiler); | ||
} | ||
@@ -71,0 +73,0 @@ } |
@@ -35,2 +35,4 @@ /* | ||
const PLUGIN_NAME = "DllReferencePlugin"; | ||
class DllReferencePlugin { | ||
@@ -54,3 +56,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"DllReferencePlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -64,47 +66,44 @@ compilation.dependencyFactories.set( | ||
compiler.hooks.beforeCompile.tapAsync( | ||
"DllReferencePlugin", | ||
(params, callback) => { | ||
if ("manifest" in this.options) { | ||
const manifest = this.options.manifest; | ||
if (typeof manifest === "string") { | ||
/** @type {InputFileSystem} */ | ||
(compiler.inputFileSystem).readFile(manifest, (err, result) => { | ||
if (err) return callback(err); | ||
/** @type {CompilationDataItem} */ | ||
const data = { | ||
path: manifest, | ||
data: undefined, | ||
error: undefined | ||
}; | ||
// Catch errors parsing the manifest so that blank | ||
// or malformed manifest files don't kill the process. | ||
try { | ||
data.data = parseJson( | ||
/** @type {Buffer} */ (result).toString("utf-8") | ||
); | ||
} catch (parseErr) { | ||
// Store the error in the params so that it can | ||
// be added as a compilation error later on. | ||
const manifestPath = makePathsRelative( | ||
/** @type {string} */ (compiler.options.context), | ||
manifest, | ||
compiler.root | ||
); | ||
data.error = new DllManifestError( | ||
manifestPath, | ||
/** @type {Error} */ (parseErr).message | ||
); | ||
} | ||
this._compilationData.set(params, data); | ||
return callback(); | ||
}); | ||
return; | ||
} | ||
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => { | ||
if ("manifest" in this.options) { | ||
const manifest = this.options.manifest; | ||
if (typeof manifest === "string") { | ||
/** @type {InputFileSystem} */ | ||
(compiler.inputFileSystem).readFile(manifest, (err, result) => { | ||
if (err) return callback(err); | ||
/** @type {CompilationDataItem} */ | ||
const data = { | ||
path: manifest, | ||
data: undefined, | ||
error: undefined | ||
}; | ||
// Catch errors parsing the manifest so that blank | ||
// or malformed manifest files don't kill the process. | ||
try { | ||
data.data = parseJson( | ||
/** @type {Buffer} */ (result).toString("utf-8") | ||
); | ||
} catch (parseErr) { | ||
// Store the error in the params so that it can | ||
// be added as a compilation error later on. | ||
const manifestPath = makePathsRelative( | ||
/** @type {string} */ (compiler.options.context), | ||
manifest, | ||
compiler.root | ||
); | ||
data.error = new DllManifestError( | ||
manifestPath, | ||
/** @type {Error} */ (parseErr).message | ||
); | ||
} | ||
this._compilationData.set(params, data); | ||
return callback(); | ||
}); | ||
return; | ||
} | ||
return callback(); | ||
} | ||
); | ||
return callback(); | ||
}); | ||
compiler.hooks.compile.tap("DllReferencePlugin", params => { | ||
compiler.hooks.compile.tap(PLUGIN_NAME, params => { | ||
let name = this.options.name; | ||
@@ -160,23 +159,20 @@ let sourceType = this.options.sourceType; | ||
compiler.hooks.compilation.tap( | ||
"DllReferencePlugin", | ||
(compilation, params) => { | ||
if ("manifest" in this.options) { | ||
const manifest = this.options.manifest; | ||
if (typeof manifest === "string") { | ||
const data = /** @type {CompilationDataItem} */ ( | ||
this._compilationData.get(params) | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation, params) => { | ||
if ("manifest" in this.options) { | ||
const manifest = this.options.manifest; | ||
if (typeof manifest === "string") { | ||
const data = /** @type {CompilationDataItem} */ ( | ||
this._compilationData.get(params) | ||
); | ||
// If there was an error parsing the manifest file, add the | ||
// error as a compilation error to make the compilation fail. | ||
if (data.error) { | ||
compilation.errors.push( | ||
/** @type {DllManifestError} */ (data.error) | ||
); | ||
// If there was an error parsing the manifest file, add the | ||
// error as a compilation error to make the compilation fail. | ||
if (data.error) { | ||
compilation.errors.push( | ||
/** @type {DllManifestError} */ (data.error) | ||
); | ||
} | ||
compilation.fileDependencies.add(manifest); | ||
} | ||
compilation.fileDependencies.add(manifest); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
@@ -183,0 +179,0 @@ } |
@@ -18,2 +18,4 @@ /* | ||
const PLUGIN_NAME = "DynamicEntryPlugin"; | ||
class DynamicEntryPlugin { | ||
@@ -36,3 +38,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"DynamicEntryPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -46,3 +48,3 @@ compilation.dependencyFactories.set( | ||
compiler.hooks.make.tapPromise("DynamicEntryPlugin", compilation => | ||
compiler.hooks.make.tapPromise(PLUGIN_NAME, compilation => | ||
Promise.resolve(this.entry()) | ||
@@ -49,0 +51,0 @@ .then(entry => { |
@@ -13,2 +13,4 @@ /* | ||
const PLUGIN_NAME = "EntryOptionPlugin"; | ||
class EntryOptionPlugin { | ||
@@ -20,3 +22,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.entryOption.tap("EntryOptionPlugin", (context, entry) => { | ||
compiler.hooks.entryOption.tap(PLUGIN_NAME, (context, entry) => { | ||
EntryOptionPlugin.applyEntryOption(compiler, context, entry); | ||
@@ -23,0 +25,0 @@ return true; |
@@ -13,2 +13,4 @@ /* | ||
const PLUGIN_NAME = "EntryPlugin"; | ||
class EntryPlugin { | ||
@@ -34,3 +36,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"EntryPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -47,3 +49,3 @@ compilation.dependencyFactories.set( | ||
compiler.hooks.make.tapAsync("EntryPlugin", (compilation, callback) => { | ||
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => { | ||
compilation.addEntry(context, dep, options, err => { | ||
@@ -50,0 +52,0 @@ callback(err); |
@@ -14,2 +14,4 @@ /* | ||
const PLUGIN_NAME = "EnvironmentPlugin"; | ||
class EnvironmentPlugin { | ||
@@ -50,5 +52,5 @@ /** | ||
if (value === undefined) { | ||
compiler.hooks.thisCompilation.tap("EnvironmentPlugin", compilation => { | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const error = new WebpackError( | ||
`EnvironmentPlugin - ${key} environment variable is undefined.\n\n` + | ||
`${PLUGIN_NAME} - ${key} environment variable is undefined.\n\n` + | ||
"You can pass an object with default values to suppress this warning.\n" + | ||
@@ -55,0 +57,0 @@ "See https://webpack.js.org/plugins/environment-plugin for example." |
@@ -15,2 +15,4 @@ /* | ||
const PLUGIN_NAME = "ModuleChunkLoadingPlugin"; | ||
class ModuleChunkLoadingPlugin { | ||
@@ -23,84 +25,81 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.thisCompilation.tap( | ||
"ModuleChunkLoadingPlugin", | ||
compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk to check | ||
* @returns {boolean} true, when the plugin is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === "import"; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk to check | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk to check | ||
* @returns {boolean} true, when the plugin is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === "import"; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk to check | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ModuleChunkLoadingRuntimeModule(set) | ||
); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.externalInstallChunk) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.externalInstallChunk) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ModuleChunkLoadingRuntimeModule(set) | ||
new ExportWebpackRequireRuntimeModule() | ||
); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("ModuleChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap("ModuleChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.externalInstallChunk) | ||
.tap("ModuleChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap("ModuleChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.externalInstallChunk) | ||
.tap("ModuleChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ExportWebpackRequireRuntimeModule() | ||
); | ||
}); | ||
}); | ||
// We need public path only when we prefetch/preload chunk or public path is not `auto` | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.prefetchChunkHandlers) | ||
.tap("ModuleChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
}); | ||
// We need public path only when we prefetch/preload chunk or public path is not `auto` | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.prefetchChunkHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.preloadChunkHandlers) | ||
.tap("ModuleChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.preloadChunkHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("ModuleChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
if (compilation.outputOptions.publicPath !== "auto") { | ||
set.add(RuntimeGlobals.publicPath); | ||
} | ||
if (compilation.outputOptions.publicPath !== "auto") { | ||
set.add(RuntimeGlobals.publicPath); | ||
} | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
} | ||
); | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
}); | ||
} | ||
@@ -107,0 +106,0 @@ } |
@@ -38,2 +38,4 @@ /* | ||
const PLUGIN_NAME = "EvalDevToolModulePlugin"; | ||
class EvalDevToolModulePlugin { | ||
@@ -57,6 +59,6 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("EvalDevToolModulePlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); | ||
hooks.renderModuleContent.tap( | ||
"EvalDevToolModulePlugin", | ||
PLUGIN_NAME, | ||
(source, module, { chunk, runtimeTemplate, chunkGraph }) => { | ||
@@ -108,11 +110,11 @@ const cacheEntry = cache.get(source); | ||
hooks.inlineInRuntimeBailout.tap( | ||
"EvalDevToolModulePlugin", | ||
PLUGIN_NAME, | ||
() => "the eval devtool is used." | ||
); | ||
hooks.render.tap( | ||
"EvalDevToolModulePlugin", | ||
PLUGIN_NAME, | ||
source => new ConcatSource(devtoolWarning, source) | ||
); | ||
hooks.chunkHash.tap("EvalDevToolModulePlugin", (chunk, hash) => { | ||
hash.update("EvalDevToolModulePlugin"); | ||
hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => { | ||
hash.update(PLUGIN_NAME); | ||
hash.update("2"); | ||
@@ -122,3 +124,3 @@ }); | ||
compilation.hooks.additionalModuleRuntimeRequirements.tap( | ||
"EvalDevToolModulePlugin", | ||
PLUGIN_NAME, | ||
(module, set, context) => { | ||
@@ -125,0 +127,0 @@ set.add(RuntimeGlobals.createScript); |
@@ -38,2 +38,4 @@ /* | ||
const PLUGIN_NAME = "EvalSourceMapDevToolPlugin"; | ||
class EvalSourceMapDevToolPlugin { | ||
@@ -71,156 +73,153 @@ /** | ||
const options = this.options; | ||
compiler.hooks.compilation.tap( | ||
"EvalSourceMapDevToolPlugin", | ||
compilation => { | ||
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); | ||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation); | ||
const matchModule = ModuleFilenameHelpers.matchObject.bind( | ||
ModuleFilenameHelpers, | ||
options | ||
); | ||
hooks.renderModuleContent.tap( | ||
"EvalSourceMapDevToolPlugin", | ||
(source, m, { chunk, runtimeTemplate, chunkGraph }) => { | ||
const cachedSource = cache.get(source); | ||
if (cachedSource !== undefined) { | ||
return cachedSource; | ||
} | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation); | ||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation); | ||
const matchModule = ModuleFilenameHelpers.matchObject.bind( | ||
ModuleFilenameHelpers, | ||
options | ||
); | ||
hooks.renderModuleContent.tap( | ||
PLUGIN_NAME, | ||
(source, m, { chunk, runtimeTemplate, chunkGraph }) => { | ||
const cachedSource = cache.get(source); | ||
if (cachedSource !== undefined) { | ||
return cachedSource; | ||
} | ||
/** | ||
* @param {Source} r result | ||
* @returns {Source} result | ||
*/ | ||
const result = r => { | ||
cache.set(source, r); | ||
return r; | ||
}; | ||
/** | ||
* @param {Source} r result | ||
* @returns {Source} result | ||
*/ | ||
const result = r => { | ||
cache.set(source, r); | ||
return r; | ||
}; | ||
if (m instanceof NormalModule) { | ||
const module = /** @type {NormalModule} */ (m); | ||
if (m instanceof NormalModule) { | ||
const module = /** @type {NormalModule} */ (m); | ||
if (!matchModule(module.resource)) { | ||
return result(source); | ||
} | ||
} else if (m instanceof ConcatenatedModule) { | ||
const concatModule = /** @type {ConcatenatedModule} */ (m); | ||
if (concatModule.rootModule instanceof NormalModule) { | ||
const module = /** @type {NormalModule} */ ( | ||
concatModule.rootModule | ||
); | ||
if (!matchModule(module.resource)) { | ||
return result(source); | ||
} | ||
} else if (m instanceof ConcatenatedModule) { | ||
const concatModule = /** @type {ConcatenatedModule} */ (m); | ||
if (concatModule.rootModule instanceof NormalModule) { | ||
const module = /** @type {NormalModule} */ ( | ||
concatModule.rootModule | ||
); | ||
if (!matchModule(module.resource)) { | ||
return result(source); | ||
} | ||
} else { | ||
return result(source); | ||
} | ||
} else { | ||
return result(source); | ||
} | ||
} else { | ||
return result(source); | ||
} | ||
const namespace = compilation.getPath(this.namespace, { | ||
chunk | ||
}); | ||
/** @type {SourceMap} */ | ||
let sourceMap; | ||
let content; | ||
if (source.sourceAndMap) { | ||
const sourceAndMap = source.sourceAndMap(options); | ||
sourceMap = /** @type {SourceMap} */ (sourceAndMap.map); | ||
content = sourceAndMap.source; | ||
} else { | ||
sourceMap = /** @type {SourceMap} */ (source.map(options)); | ||
content = source.source(); | ||
} | ||
if (!sourceMap) { | ||
return result(source); | ||
} | ||
const namespace = compilation.getPath(this.namespace, { | ||
chunk | ||
}); | ||
/** @type {SourceMap} */ | ||
let sourceMap; | ||
let content; | ||
if (source.sourceAndMap) { | ||
const sourceAndMap = source.sourceAndMap(options); | ||
sourceMap = /** @type {SourceMap} */ (sourceAndMap.map); | ||
content = sourceAndMap.source; | ||
} else { | ||
sourceMap = /** @type {SourceMap} */ (source.map(options)); | ||
content = source.source(); | ||
} | ||
if (!sourceMap) { | ||
return result(source); | ||
} | ||
// Clone (flat) the sourcemap to ensure that the mutations below do not persist. | ||
sourceMap = { ...sourceMap }; | ||
const context = /** @type {string} */ (compiler.options.context); | ||
const root = compiler.root; | ||
const modules = sourceMap.sources.map(source => { | ||
if (!source.startsWith("webpack://")) return source; | ||
source = makePathsAbsolute(context, source.slice(10), root); | ||
const module = compilation.findModule(source); | ||
return module || source; | ||
}); | ||
let moduleFilenames = modules.map(module => | ||
ModuleFilenameHelpers.createFilename( | ||
module, | ||
{ | ||
moduleFilenameTemplate: this.moduleFilenameTemplate, | ||
namespace | ||
}, | ||
{ | ||
requestShortener: runtimeTemplate.requestShortener, | ||
chunkGraph, | ||
hashFunction: compilation.outputOptions.hashFunction | ||
} | ||
) | ||
); | ||
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates( | ||
moduleFilenames, | ||
(filename, i, n) => { | ||
for (let j = 0; j < n; j++) filename += "*"; | ||
return filename; | ||
// Clone (flat) the sourcemap to ensure that the mutations below do not persist. | ||
sourceMap = { ...sourceMap }; | ||
const context = /** @type {string} */ (compiler.options.context); | ||
const root = compiler.root; | ||
const modules = sourceMap.sources.map(source => { | ||
if (!source.startsWith("webpack://")) return source; | ||
source = makePathsAbsolute(context, source.slice(10), root); | ||
const module = compilation.findModule(source); | ||
return module || source; | ||
}); | ||
let moduleFilenames = modules.map(module => | ||
ModuleFilenameHelpers.createFilename( | ||
module, | ||
{ | ||
moduleFilenameTemplate: this.moduleFilenameTemplate, | ||
namespace | ||
}, | ||
{ | ||
requestShortener: runtimeTemplate.requestShortener, | ||
chunkGraph, | ||
hashFunction: compilation.outputOptions.hashFunction | ||
} | ||
); | ||
sourceMap.sources = moduleFilenames; | ||
if (options.noSources) { | ||
sourceMap.sourcesContent = undefined; | ||
) | ||
); | ||
moduleFilenames = ModuleFilenameHelpers.replaceDuplicates( | ||
moduleFilenames, | ||
(filename, i, n) => { | ||
for (let j = 0; j < n; j++) filename += "*"; | ||
return filename; | ||
} | ||
sourceMap.sourceRoot = options.sourceRoot || ""; | ||
const moduleId = | ||
/** @type {ModuleId} */ | ||
(chunkGraph.getModuleId(m)); | ||
sourceMap.file = | ||
typeof moduleId === "number" ? `${moduleId}.js` : moduleId; | ||
); | ||
sourceMap.sources = moduleFilenames; | ||
if (options.noSources) { | ||
sourceMap.sourcesContent = undefined; | ||
} | ||
sourceMap.sourceRoot = options.sourceRoot || ""; | ||
const moduleId = | ||
/** @type {ModuleId} */ | ||
(chunkGraph.getModuleId(m)); | ||
sourceMap.file = | ||
typeof moduleId === "number" ? `${moduleId}.js` : moduleId; | ||
if (options.debugIds) { | ||
sourceMap.debugId = generateDebugId(content, sourceMap.file); | ||
} | ||
if (options.debugIds) { | ||
sourceMap.debugId = generateDebugId(content, sourceMap.file); | ||
} | ||
const footer = `${this.sourceMapComment.replace( | ||
/\[url\]/g, | ||
`data:application/json;charset=utf-8;base64,${Buffer.from( | ||
JSON.stringify(sourceMap), | ||
"utf8" | ||
).toString("base64")}` | ||
)}\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug | ||
const footer = `${this.sourceMapComment.replace( | ||
/\[url\]/g, | ||
`data:application/json;charset=utf-8;base64,${Buffer.from( | ||
JSON.stringify(sourceMap), | ||
"utf8" | ||
).toString("base64")}` | ||
)}\n//# sourceURL=webpack-internal:///${moduleId}\n`; // workaround for chrome bug | ||
return result( | ||
new RawSource( | ||
`eval(${ | ||
compilation.outputOptions.trustedTypes | ||
? `${RuntimeGlobals.createScript}(${JSON.stringify( | ||
content + footer | ||
)})` | ||
: JSON.stringify(content + footer) | ||
});` | ||
) | ||
); | ||
return result( | ||
new RawSource( | ||
`eval(${ | ||
compilation.outputOptions.trustedTypes | ||
? `${RuntimeGlobals.createScript}(${JSON.stringify( | ||
content + footer | ||
)})` | ||
: JSON.stringify(content + footer) | ||
});` | ||
) | ||
); | ||
} | ||
); | ||
hooks.inlineInRuntimeBailout.tap( | ||
"EvalDevToolModulePlugin", | ||
() => "the eval-source-map devtool is used." | ||
); | ||
hooks.render.tap( | ||
PLUGIN_NAME, | ||
source => new ConcatSource(devtoolWarning, source) | ||
); | ||
hooks.chunkHash.tap(PLUGIN_NAME, (chunk, hash) => { | ||
hash.update(PLUGIN_NAME); | ||
hash.update("2"); | ||
}); | ||
if (compilation.outputOptions.trustedTypes) { | ||
compilation.hooks.additionalModuleRuntimeRequirements.tap( | ||
PLUGIN_NAME, | ||
(module, set, context) => { | ||
set.add(RuntimeGlobals.createScript); | ||
} | ||
); | ||
hooks.inlineInRuntimeBailout.tap( | ||
"EvalDevToolModulePlugin", | ||
() => "the eval-source-map devtool is used." | ||
); | ||
hooks.render.tap( | ||
"EvalSourceMapDevToolPlugin", | ||
source => new ConcatSource(devtoolWarning, source) | ||
); | ||
hooks.chunkHash.tap("EvalSourceMapDevToolPlugin", (chunk, hash) => { | ||
hash.update("EvalSourceMapDevToolPlugin"); | ||
hash.update("2"); | ||
}); | ||
if (compilation.outputOptions.trustedTypes) { | ||
compilation.hooks.additionalModuleRuntimeRequirements.tap( | ||
"EvalSourceMapDevToolPlugin", | ||
(module, set, context) => { | ||
set.add(RuntimeGlobals.createScript); | ||
} | ||
); | ||
} | ||
} | ||
); | ||
}); | ||
} | ||
@@ -227,0 +226,0 @@ } |
@@ -13,2 +13,4 @@ /* | ||
const PLUGIN_NAME = "ExternalsPlugin"; | ||
class ExternalsPlugin { | ||
@@ -30,3 +32,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compile.tap("ExternalsPlugin", ({ normalModuleFactory }) => { | ||
compiler.hooks.compile.tap(PLUGIN_NAME, ({ normalModuleFactory }) => { | ||
new ExternalModuleFactoryPlugin(this.type, this.externals).apply( | ||
@@ -33,0 +35,0 @@ normalModuleFactory |
@@ -372,3 +372,4 @@ /* | ||
typeof ( | ||
/** @type {BuildInfo} */ (module.buildInfo).hash | ||
/** @type {BuildInfo} */ | ||
(module.buildInfo).hash | ||
) !== "string" | ||
@@ -375,0 +376,0 @@ ) { |
@@ -72,3 +72,2 @@ // @ts-nocheck | ||
} else { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
@@ -75,0 +74,0 @@ "[HMR] unexpected require(" + |
@@ -112,3 +112,2 @@ // @ts-nocheck | ||
var warnUnexpectedRequire = function warnUnexpectedRequire(module) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
@@ -115,0 +114,0 @@ "[HMR] unexpected require(" + module.id + ") to disposed module" |
@@ -356,2 +356,4 @@ /* | ||
const PLUGIN_NAME = "LazyCompilationPlugin"; | ||
class LazyCompilationPlugin { | ||
@@ -376,24 +378,21 @@ /** | ||
let backend; | ||
compiler.hooks.beforeCompile.tapAsync( | ||
"LazyCompilationPlugin", | ||
(params, callback) => { | ||
if (backend !== undefined) return callback(); | ||
const promise = this.backend(compiler, (err, result) => { | ||
if (err) return callback(err); | ||
backend = /** @type {BackendApi} */ (result); | ||
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (params, callback) => { | ||
if (backend !== undefined) return callback(); | ||
const promise = this.backend(compiler, (err, result) => { | ||
if (err) return callback(err); | ||
backend = /** @type {BackendApi} */ (result); | ||
callback(); | ||
}); | ||
if (promise && promise.then) { | ||
promise.then(b => { | ||
backend = b; | ||
callback(); | ||
}); | ||
if (promise && promise.then) { | ||
promise.then(b => { | ||
backend = b; | ||
callback(); | ||
}, callback); | ||
} | ||
}, callback); | ||
} | ||
); | ||
}); | ||
compiler.hooks.thisCompilation.tap( | ||
"LazyCompilationPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
normalModuleFactory.hooks.module.tap( | ||
"LazyCompilationPlugin", | ||
PLUGIN_NAME, | ||
(module, createData, resolveData) => { | ||
@@ -459,3 +458,3 @@ if ( | ||
); | ||
compiler.hooks.shutdown.tapAsync("LazyCompilationPlugin", callback => { | ||
compiler.hooks.shutdown.tapAsync(PLUGIN_NAME, callback => { | ||
backend.dispose(callback); | ||
@@ -462,0 +461,0 @@ }); |
@@ -24,2 +24,4 @@ /* | ||
const PLUGIN_NAME = "ChunkModuleIdRangePlugin"; | ||
class ChunkModuleIdRangePlugin { | ||
@@ -40,5 +42,5 @@ /** | ||
const options = this.options; | ||
compiler.hooks.compilation.tap("ChunkModuleIdRangePlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const moduleGraph = compilation.moduleGraph; | ||
compilation.hooks.moduleIds.tap("ChunkModuleIdRangePlugin", modules => { | ||
compilation.hooks.moduleIds.tap(PLUGIN_NAME, modules => { | ||
const chunkGraph = compilation.chunkGraph; | ||
@@ -51,3 +53,3 @@ const chunk = find( | ||
throw new Error( | ||
`ChunkModuleIdRangePlugin: Chunk with name '${options.name}"' was not found` | ||
`${PLUGIN_NAME}: Chunk with name '${options.name}"' was not found` | ||
); | ||
@@ -69,5 +71,3 @@ } | ||
default: | ||
throw new Error( | ||
"ChunkModuleIdRangePlugin: unexpected value of order" | ||
); | ||
throw new Error(`${PLUGIN_NAME}: unexpected value of order`); | ||
} | ||
@@ -74,0 +74,0 @@ chunkModules = chunkGraph.getOrderedChunkModules(chunk, cmpFn); |
@@ -30,2 +30,4 @@ /* | ||
const PLUGIN_NAME = "DeterministicModuleIdsPlugin"; | ||
class DeterministicModuleIdsPlugin { | ||
@@ -45,52 +47,49 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap( | ||
"DeterministicModuleIdsPlugin", | ||
compilation => { | ||
compilation.hooks.moduleIds.tap("DeterministicModuleIdsPlugin", () => { | ||
const chunkGraph = compilation.chunkGraph; | ||
const context = this.options.context | ||
? this.options.context | ||
: compiler.context; | ||
const maxLength = this.options.maxLength || 3; | ||
const failOnConflict = this.options.failOnConflict || false; | ||
const fixedLength = this.options.fixedLength || false; | ||
const salt = this.options.salt || 0; | ||
let conflicts = 0; | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => { | ||
const chunkGraph = compilation.chunkGraph; | ||
const context = this.options.context | ||
? this.options.context | ||
: compiler.context; | ||
const maxLength = this.options.maxLength || 3; | ||
const failOnConflict = this.options.failOnConflict || false; | ||
const fixedLength = this.options.fixedLength || false; | ||
const salt = this.options.salt || 0; | ||
let conflicts = 0; | ||
const [usedIds, modules] = getUsedModuleIdsAndModules( | ||
compilation, | ||
this.options.test | ||
const [usedIds, modules] = getUsedModuleIdsAndModules( | ||
compilation, | ||
this.options.test | ||
); | ||
assignDeterministicIds( | ||
modules, | ||
module => getFullModuleName(module, context, compiler.root), | ||
failOnConflict | ||
? () => 0 | ||
: compareModulesByPreOrderIndexOrIdentifier( | ||
compilation.moduleGraph | ||
), | ||
(module, id) => { | ||
const size = usedIds.size; | ||
usedIds.add(`${id}`); | ||
if (size === usedIds.size) { | ||
conflicts++; | ||
return false; | ||
} | ||
chunkGraph.setModuleId(module, id); | ||
return true; | ||
}, | ||
[10 ** maxLength], | ||
fixedLength ? 0 : 10, | ||
usedIds.size, | ||
salt | ||
); | ||
if (failOnConflict && conflicts) | ||
throw new Error( | ||
`Assigning deterministic module ids has lead to ${conflicts} conflict${ | ||
conflicts > 1 ? "s" : "" | ||
}.\nIncrease the 'maxLength' to increase the id space and make conflicts less likely (recommended when there are many conflicts or application is expected to grow), or add an 'salt' number to try another hash starting value in the same id space (recommended when there is only a single conflict).` | ||
); | ||
assignDeterministicIds( | ||
modules, | ||
module => getFullModuleName(module, context, compiler.root), | ||
failOnConflict | ||
? () => 0 | ||
: compareModulesByPreOrderIndexOrIdentifier( | ||
compilation.moduleGraph | ||
), | ||
(module, id) => { | ||
const size = usedIds.size; | ||
usedIds.add(`${id}`); | ||
if (size === usedIds.size) { | ||
conflicts++; | ||
return false; | ||
} | ||
chunkGraph.setModuleId(module, id); | ||
return true; | ||
}, | ||
[10 ** maxLength], | ||
fixedLength ? 0 : 10, | ||
usedIds.size, | ||
salt | ||
); | ||
if (failOnConflict && conflicts) | ||
throw new Error( | ||
`Assigning deterministic module ids has lead to ${conflicts} conflict${ | ||
conflicts > 1 ? "s" : "" | ||
}.\nIncrease the 'maxLength' to increase the id space and make conflicts less likely (recommended when there are many conflicts or application is expected to grow), or add an 'salt' number to try another hash starting value in the same id space (recommended when there is only a single conflict).` | ||
); | ||
}); | ||
} | ||
); | ||
}); | ||
}); | ||
} | ||
@@ -97,0 +96,0 @@ } |
@@ -31,2 +31,4 @@ /* | ||
const PLUGIN_NAME = "HashedModuleIdsPlugin"; | ||
class HashedModuleIdsPlugin { | ||
@@ -56,4 +58,4 @@ /** | ||
const options = this.options; | ||
compiler.hooks.compilation.tap("HashedModuleIdsPlugin", compilation => { | ||
compilation.hooks.moduleIds.tap("HashedModuleIdsPlugin", () => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => { | ||
const chunkGraph = compilation.chunkGraph; | ||
@@ -60,0 +62,0 @@ const context = this.options.context |
@@ -28,2 +28,4 @@ /* | ||
const PLUGIN_NAME = "NamedChunkIdsPlugin"; | ||
class NamedChunkIdsPlugin { | ||
@@ -44,7 +46,7 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("NamedChunkIdsPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const hashFunction = | ||
/** @type {NonNullable<Output["hashFunction"]>} */ | ||
(compilation.outputOptions.hashFunction); | ||
compilation.hooks.chunkIds.tap("NamedChunkIdsPlugin", chunks => { | ||
compilation.hooks.chunkIds.tap(PLUGIN_NAME, chunks => { | ||
const chunkGraph = compilation.chunkGraph; | ||
@@ -51,0 +53,0 @@ const context = this.context ? this.context : compiler.context; |
@@ -26,2 +26,4 @@ /* | ||
const PLUGIN_NAME = "NamedModuleIdsPlugin"; | ||
class NamedModuleIdsPlugin { | ||
@@ -42,7 +44,7 @@ /** | ||
const { root } = compiler; | ||
compiler.hooks.compilation.tap("NamedModuleIdsPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const hashFunction = | ||
/** @type {NonNullable<Output["hashFunction"]>} */ | ||
(compilation.outputOptions.hashFunction); | ||
compilation.hooks.moduleIds.tap("NamedModuleIdsPlugin", () => { | ||
compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => { | ||
const chunkGraph = compilation.chunkGraph; | ||
@@ -49,0 +51,0 @@ const context = this.options.context |
@@ -15,2 +15,4 @@ /* | ||
const PLUGIN_NAME = "NaturalChunkIdsPlugin"; | ||
class NaturalChunkIdsPlugin { | ||
@@ -23,4 +25,4 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("NaturalChunkIdsPlugin", compilation => { | ||
compilation.hooks.chunkIds.tap("NaturalChunkIdsPlugin", chunks => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.chunkIds.tap(PLUGIN_NAME, chunks => { | ||
const chunkGraph = compilation.chunkGraph; | ||
@@ -27,0 +29,0 @@ const compareNatural = compareChunksNatural(chunkGraph); |
@@ -19,2 +19,4 @@ /* | ||
const PLUGIN_NAME = "NaturalModuleIdsPlugin"; | ||
class NaturalModuleIdsPlugin { | ||
@@ -27,4 +29,4 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("NaturalModuleIdsPlugin", compilation => { | ||
compilation.hooks.moduleIds.tap("NaturalModuleIdsPlugin", modules => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.moduleIds.tap(PLUGIN_NAME, modules => { | ||
const [usedIds, modulesInNaturalOrder] = | ||
@@ -31,0 +33,0 @@ getUsedModuleIdsAndModules(compilation); |
@@ -26,2 +26,4 @@ /* | ||
const PLUGIN_NAME = "OccurrenceChunkIdsPlugin"; | ||
class OccurrenceChunkIdsPlugin { | ||
@@ -43,4 +45,4 @@ /** | ||
const prioritiseInitial = this.options.prioritiseInitial; | ||
compiler.hooks.compilation.tap("OccurrenceChunkIdsPlugin", compilation => { | ||
compilation.hooks.chunkIds.tap("OccurrenceChunkIdsPlugin", chunks => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.chunkIds.tap(PLUGIN_NAME, chunks => { | ||
const chunkGraph = compilation.chunkGraph; | ||
@@ -47,0 +49,0 @@ |
@@ -31,2 +31,4 @@ /* | ||
const PLUGIN_NAME = "OccurrenceModuleIdsPlugin"; | ||
class OccurrenceModuleIdsPlugin { | ||
@@ -48,6 +50,6 @@ /** | ||
const prioritiseInitial = this.options.prioritiseInitial; | ||
compiler.hooks.compilation.tap("OccurrenceModuleIdsPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const moduleGraph = compilation.moduleGraph; | ||
compilation.hooks.moduleIds.tap("OccurrenceModuleIdsPlugin", () => { | ||
compilation.hooks.moduleIds.tap(PLUGIN_NAME, () => { | ||
const chunkGraph = compilation.chunkGraph; | ||
@@ -54,0 +56,0 @@ |
@@ -25,2 +25,4 @@ /* | ||
const PLUGIN_NAME = "IgnorePlugin"; | ||
class IgnorePlugin { | ||
@@ -73,4 +75,4 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => { | ||
nmf.hooks.beforeResolve.tap("IgnorePlugin", resolveData => { | ||
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, nmf => { | ||
nmf.hooks.beforeResolve.tap(PLUGIN_NAME, resolveData => { | ||
const result = this.checkIgnore(resolveData); | ||
@@ -93,4 +95,4 @@ | ||
}); | ||
compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => { | ||
cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore); | ||
compiler.hooks.contextModuleFactory.tap(PLUGIN_NAME, cmf => { | ||
cmf.hooks.beforeResolve.tap(PLUGIN_NAME, this.checkIgnore); | ||
}); | ||
@@ -97,0 +99,0 @@ } |
@@ -11,2 +11,4 @@ /* | ||
const PLUGIN_NAME = "IgnoreWarningsPlugin"; | ||
class IgnoreWarningsPlugin { | ||
@@ -26,4 +28,4 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("IgnoreWarningsPlugin", compilation => { | ||
compilation.hooks.processWarnings.tap("IgnoreWarningsPlugin", warnings => | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.processWarnings.tap(PLUGIN_NAME, warnings => | ||
warnings.filter( | ||
@@ -30,0 +32,0 @@ warning => |
@@ -36,2 +36,4 @@ /* | ||
const PLUGIN_NAME = "LibManifestPlugin"; | ||
class LibManifestPlugin { | ||
@@ -52,6 +54,3 @@ /** | ||
compiler.hooks.emit.tapAsync( | ||
{ | ||
name: "LibManifestPlugin", | ||
stage: 110 | ||
}, | ||
{ name: PLUGIN_NAME, stage: 110 }, | ||
(compilation, callback) => { | ||
@@ -58,0 +57,0 @@ const moduleGraph = compilation.moduleGraph; |
@@ -42,2 +42,4 @@ /* | ||
const PLUGIN_NAME = "ModuleLibraryPlugin"; | ||
/** | ||
@@ -66,30 +68,27 @@ * @typedef {ModuleLibraryPluginParsed} T | ||
compiler.hooks.compilation.tap("ModernModuleLibraryPlugin", compilation => { | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const { exportsDefinitions } = | ||
ConcatenatedModule.getCompilationHooks(compilation); | ||
exportsDefinitions.tap( | ||
"ModernModuleLibraryPlugin", | ||
(definitions, module) => { | ||
// If we have connections not all modules were concatenated, so we need the wrapper | ||
const connections = | ||
compilation.moduleGraph.getIncomingConnections(module); | ||
exportsDefinitions.tap(PLUGIN_NAME, (definitions, module) => { | ||
// If we have connections not all modules were concatenated, so we need the wrapper | ||
const connections = | ||
compilation.moduleGraph.getIncomingConnections(module); | ||
for (const connection of connections) { | ||
if (connection.originModule) { | ||
return false; | ||
} | ||
for (const connection of connections) { | ||
if (connection.originModule) { | ||
return false; | ||
} | ||
} | ||
// Runtime and splitting chunks now requires the wrapper too | ||
for (const chunk of compilation.chunkGraph.getModuleChunksIterable( | ||
module | ||
)) { | ||
if (!chunk.hasRuntime()) { | ||
return false; | ||
} | ||
// Runtime and splitting chunks now requires the wrapper too | ||
for (const chunk of compilation.chunkGraph.getModuleChunksIterable( | ||
module | ||
)) { | ||
if (!chunk.hasRuntime()) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} | ||
); | ||
return true; | ||
}); | ||
}); | ||
@@ -126,7 +125,7 @@ } | ||
module, | ||
{ moduleGraph, chunk }, | ||
{ moduleGraph, chunk, codeGenerationResults }, | ||
{ options, compilation } | ||
) { | ||
const result = new ConcatSource(source); | ||
const exportsInfos = options.export | ||
const exportsInfo = options.export | ||
? [ | ||
@@ -142,3 +141,5 @@ moduleGraph.getExportInfo( | ||
(module.buildMeta).exportsFinalName || {}; | ||
/** @type {string[]} */ | ||
const shortHandedExports = []; | ||
/** @type {[string, string][]} */ | ||
const exports = []; | ||
@@ -153,3 +154,7 @@ const isAsync = moduleGraph.isAsync(module); | ||
for (const exportInfo of exportsInfos) { | ||
const varType = compilation.outputOptions.environment.const | ||
? "const" | ||
: "var"; | ||
for (const exportInfo of exportsInfo) { | ||
if (!exportInfo.provided) continue; | ||
@@ -167,2 +172,3 @@ | ||
reexportInfo.provided === false && | ||
reexportInfo.name !== "default" && | ||
reexportInfo.name === /** @type {string[]} */ (reexport.export)[0] | ||
@@ -177,18 +183,17 @@ ) { | ||
const webpackExportsProperty = exportInfo.getUsedName( | ||
exportInfo.name, | ||
chunk.runtime | ||
); | ||
const definition = | ||
definitions[/** @type {string} */ (webpackExportsProperty)]; | ||
const originalName = exportInfo.name; | ||
const usedName = | ||
/** @type {string} */ | ||
(exportInfo.getUsedName(originalName, chunk.runtime)); | ||
/** @type {string | undefined} */ | ||
const definition = definitions[usedName]; | ||
const finalName = | ||
definition || | ||
`${RuntimeGlobals.exports}${Template.toIdentifier(exportInfo.name)}`; | ||
`${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`; | ||
if (!definition) { | ||
result.add( | ||
`var ${finalName} = ${RuntimeGlobals.exports}${propertyAccess([ | ||
/** @type {string} */ | ||
(exportInfo.getUsedName(exportInfo.name, chunk.runtime)) | ||
])}\n` | ||
`${varType} ${finalName} = ${RuntimeGlobals.exports}${propertyAccess([ | ||
usedName | ||
])};\n` | ||
); | ||
@@ -203,8 +208,23 @@ } | ||
) { | ||
exports.push([exportInfo.name, finalName]); | ||
if (exportInfo.isReexport()) { | ||
const { data } = codeGenerationResults.get(module, chunk.runtime); | ||
const topLevelDeclarations = | ||
(data && data.get("topLevelDeclarations")) || | ||
(module.buildInfo && module.buildInfo.topLevelDeclarations); | ||
if (topLevelDeclarations && topLevelDeclarations.has(originalName)) { | ||
const name = `${RuntimeGlobals.exports}${Template.toIdentifier(originalName)}`; | ||
result.add(`${varType} ${name} = ${finalName};\n`); | ||
shortHandedExports.push(`${name} as ${originalName}`); | ||
} else { | ||
exports.push([originalName, finalName]); | ||
} | ||
} else { | ||
exports.push([originalName, finalName]); | ||
} | ||
} else { | ||
shortHandedExports.push( | ||
definition && finalName === exportInfo.name | ||
definition && finalName === originalName | ||
? finalName | ||
: `${finalName} as ${exportInfo.name}` | ||
: `${finalName} as ${originalName}` | ||
); | ||
@@ -219,5 +239,3 @@ } | ||
for (const [exportName, final] of exports) { | ||
result.add( | ||
`export ${compilation.outputOptions.environment.const ? "const" : "var"} ${exportName} = ${final};\n` | ||
); | ||
result.add(`export ${varType} ${exportName} = ${final};\n`); | ||
} | ||
@@ -224,0 +242,0 @@ |
@@ -31,2 +31,4 @@ /* | ||
const PLUGIN_NAME = "LoaderOptionsPlugin"; | ||
class LoaderOptionsPlugin { | ||
@@ -59,5 +61,5 @@ /** | ||
const options = this.options; | ||
compiler.hooks.compilation.tap("LoaderOptionsPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
NormalModule.getCompilationHooks(compilation).loader.tap( | ||
"LoaderOptionsPlugin", | ||
PLUGIN_NAME, | ||
(context, module) => { | ||
@@ -64,0 +66,0 @@ const resource = module.resource; |
@@ -12,2 +12,4 @@ /* | ||
const PLUGIN_NAME = "LoaderTargetPlugin"; | ||
class LoaderTargetPlugin { | ||
@@ -27,5 +29,5 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("LoaderTargetPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
NormalModule.getCompilationHooks(compilation).loader.tap( | ||
"LoaderTargetPlugin", | ||
PLUGIN_NAME, | ||
loaderContext => { | ||
@@ -32,0 +34,0 @@ loaderContext.target = this.target; |
@@ -31,2 +31,3 @@ /* | ||
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */ | ||
/** @typedef {import("./DependencyTemplate").CssData} CssData */ | ||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */ | ||
@@ -124,15 +125,21 @@ /** @typedef {import("./ExportsInfo").UsageStateType} UsageStateType */ | ||
* @property {boolean=} parsed | ||
* @property {string=} moduleArgument | ||
* @property {string=} exportsArgument | ||
* @property {boolean=} strict | ||
* @property {string=} moduleConcatenationBailout | ||
* @property {LazySet<string>=} fileDependencies | ||
* @property {LazySet<string>=} contextDependencies | ||
* @property {LazySet<string>=} missingDependencies | ||
* @property {LazySet<string>=} buildDependencies | ||
* @property {ValueCacheVersions=} valueDependencies | ||
* @property {TODO=} hash | ||
* @property {Record<string, Source>=} assets | ||
* @property {Map<string, AssetInfo | undefined>=} assetsInfo | ||
* @property {(Snapshot | null)=} snapshot | ||
* @property {string=} moduleArgument using in AMD | ||
* @property {string=} exportsArgument using in AMD | ||
* @property {string=} moduleConcatenationBailout using in CommonJs | ||
* @property {boolean=} needCreateRequire using in APIPlugin | ||
* @property {string=} resourceIntegrity using in HttpUriPlugin | ||
* @property {LazySet<string>=} fileDependencies using in NormalModule | ||
* @property {LazySet<string>=} contextDependencies using in NormalModule | ||
* @property {LazySet<string>=} missingDependencies using in NormalModule | ||
* @property {LazySet<string>=} buildDependencies using in NormalModule | ||
* @property {ValueCacheVersions=} valueDependencies using in NormalModule | ||
* @property {Record<string, Source>=} assets using in NormalModule | ||
* @property {string=} hash using in NormalModule | ||
* @property {(Snapshot | null)=} snapshot using in ContextModule | ||
* @property {string=} fullContentHash for assets modules | ||
* @property {string=} filename for assets modules | ||
* @property {Map<string, AssetInfo | undefined>=} assetsInfo for assets modules | ||
* @property {boolean=} dataUrl for assets modules | ||
* @property {CssData=} cssData for css modules | ||
*/ | ||
@@ -139,0 +146,0 @@ |
@@ -152,2 +152,4 @@ /* | ||
const PLUGIN_NAME = "ModuleInfoHeaderPlugin"; | ||
class ModuleInfoHeaderPlugin { | ||
@@ -167,7 +169,7 @@ /** | ||
const { _verbose: verbose } = this; | ||
compiler.hooks.compilation.tap("ModuleInfoHeaderPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const javascriptHooks = | ||
JavascriptModulesPlugin.getCompilationHooks(compilation); | ||
javascriptHooks.renderModulePackage.tap( | ||
"ModuleInfoHeaderPlugin", | ||
PLUGIN_NAME, | ||
( | ||
@@ -251,12 +253,9 @@ moduleSource, | ||
); | ||
javascriptHooks.chunkHash.tap( | ||
"ModuleInfoHeaderPlugin", | ||
(_chunk, hash) => { | ||
hash.update("ModuleInfoHeaderPlugin"); | ||
hash.update("1"); | ||
} | ||
); | ||
javascriptHooks.chunkHash.tap(PLUGIN_NAME, (_chunk, hash) => { | ||
hash.update(PLUGIN_NAME); | ||
hash.update("1"); | ||
}); | ||
const cssHooks = CssModulesPlugin.getCompilationHooks(compilation); | ||
cssHooks.renderModulePackage.tap( | ||
"ModuleInfoHeaderPlugin", | ||
PLUGIN_NAME, | ||
(moduleSource, module, { runtimeTemplate }) => { | ||
@@ -297,4 +296,4 @@ const { requestShortener } = runtimeTemplate; | ||
); | ||
cssHooks.chunkHash.tap("ModuleInfoHeaderPlugin", (_chunk, hash) => { | ||
hash.update("ModuleInfoHeaderPlugin"); | ||
cssHooks.chunkHash.tap(PLUGIN_NAME, (_chunk, hash) => { | ||
hash.update(PLUGIN_NAME); | ||
hash.update("1"); | ||
@@ -301,0 +300,0 @@ }); |
@@ -47,2 +47,4 @@ /* | ||
const CLASS_NAME = "MultiCompiler"; | ||
module.exports = class MultiCompiler { | ||
@@ -96,3 +98,3 @@ /** | ||
// eslint-disable-next-line no-loop-func | ||
compiler.hooks.done.tap("MultiCompiler", stats => { | ||
compiler.hooks.done.tap(CLASS_NAME, stats => { | ||
if (!compilerDone) { | ||
@@ -110,3 +112,3 @@ compilerDone = true; | ||
// eslint-disable-next-line no-loop-func | ||
compiler.hooks.invalid.tap("MultiCompiler", () => { | ||
compiler.hooks.invalid.tap(CLASS_NAME, () => { | ||
if (compilerDone) { | ||
@@ -128,3 +130,3 @@ compilerDone = false; | ||
const addWarning = (compiler, warning) => { | ||
compiler.hooks.thisCompilation.tap("MultiCompiler", compilation => { | ||
compiler.hooks.thisCompilation.tap(CLASS_NAME, compilation => { | ||
compilation.warnings.push(warning); | ||
@@ -131,0 +133,0 @@ }); |
@@ -19,2 +19,4 @@ /* | ||
const PLUGIN_NAME = "CommonJsChunkLoadingPlugin"; | ||
class CommonJsChunkLoadingPlugin { | ||
@@ -44,77 +46,71 @@ /** | ||
}).apply(compiler); | ||
compiler.hooks.thisCompilation.tap( | ||
"CommonJsChunkLoadingPlugin", | ||
compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @returns {boolean} true, if wasm loading is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === chunkLoadingValue; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @returns {boolean} true, if wasm loading is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === chunkLoadingValue; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
compilation.addRuntimeModule(chunk, new ChunkLoadingRuntimeModule(set)); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.externalInstallChunk) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.getChunkUpdateScriptFilename); | ||
set.add(RuntimeGlobals.moduleCache); | ||
set.add(RuntimeGlobals.hmrModuleData); | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkLoadingRuntimeModule(set) | ||
); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("CommonJsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap("CommonJsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap("CommonJsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap("CommonJsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.externalInstallChunk) | ||
.tap("CommonJsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap("CommonJsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("CommonJsChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap("CommonJsChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.getChunkUpdateScriptFilename); | ||
set.add(RuntimeGlobals.moduleCache); | ||
set.add(RuntimeGlobals.hmrModuleData); | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap("CommonJsChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.getUpdateManifestFilename); | ||
}); | ||
} | ||
); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.getUpdateManifestFilename); | ||
}); | ||
}); | ||
} | ||
@@ -121,0 +117,0 @@ } |
@@ -23,2 +23,4 @@ /* | ||
const PLUGIN_NAME = "NodeEnvironmentPlugin"; | ||
class NodeEnvironmentPlugin { | ||
@@ -59,3 +61,3 @@ /** | ||
compiler.watchFileSystem = new NodeWatchFileSystem(inputFileSystem); | ||
compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => { | ||
compiler.hooks.beforeRun.tap(PLUGIN_NAME, compiler => { | ||
if ( | ||
@@ -62,0 +64,0 @@ compiler.inputFileSystem === inputFileSystem && |
@@ -10,2 +10,4 @@ /* | ||
const PLUGIN_NAME = "NoEmitOnErrorsPlugin"; | ||
class NoEmitOnErrorsPlugin { | ||
@@ -18,7 +20,7 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.shouldEmit.tap("NoEmitOnErrorsPlugin", compilation => { | ||
compiler.hooks.shouldEmit.tap(PLUGIN_NAME, compilation => { | ||
if (compilation.getStats().hasErrors()) return false; | ||
}); | ||
compiler.hooks.compilation.tap("NoEmitOnErrorsPlugin", compilation => { | ||
compilation.hooks.shouldRecord.tap("NoEmitOnErrorsPlugin", () => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.shouldRecord.tap(PLUGIN_NAME, () => { | ||
if (compilation.getStats().hasErrors()) return false; | ||
@@ -25,0 +27,0 @@ }); |
@@ -1635,3 +1635,7 @@ /* | ||
updateHash(hash, context) { | ||
hash.update(/** @type {BuildInfo} */ (this.buildInfo).hash); | ||
const buildInfo = /** @type {BuildInfo} */ (this.buildInfo); | ||
hash.update( | ||
/** @type {string} */ | ||
(buildInfo.hash) | ||
); | ||
/** @type {Generator} */ | ||
@@ -1638,0 +1642,0 @@ (this.generator).updateHash(hash, { |
@@ -16,2 +16,4 @@ /* | ||
const PLUGIN_NAME = "NormalModuleReplacementPlugin"; | ||
class NormalModuleReplacementPlugin { | ||
@@ -36,42 +38,37 @@ /** | ||
const newResource = this.newResource; | ||
compiler.hooks.normalModuleFactory.tap( | ||
"NormalModuleReplacementPlugin", | ||
nmf => { | ||
nmf.hooks.beforeResolve.tap("NormalModuleReplacementPlugin", result => { | ||
if (resourceRegExp.test(result.request)) { | ||
if (typeof newResource === "function") { | ||
newResource(result); | ||
} else { | ||
result.request = newResource; | ||
} | ||
compiler.hooks.normalModuleFactory.tap(PLUGIN_NAME, nmf => { | ||
nmf.hooks.beforeResolve.tap(PLUGIN_NAME, result => { | ||
if (resourceRegExp.test(result.request)) { | ||
if (typeof newResource === "function") { | ||
newResource(result); | ||
} else { | ||
result.request = newResource; | ||
} | ||
}); | ||
nmf.hooks.afterResolve.tap("NormalModuleReplacementPlugin", result => { | ||
const createData = result.createData; | ||
if ( | ||
resourceRegExp.test(/** @type {string} */ (createData.resource)) | ||
) { | ||
if (typeof newResource === "function") { | ||
newResource(result); | ||
} | ||
}); | ||
nmf.hooks.afterResolve.tap(PLUGIN_NAME, result => { | ||
const createData = result.createData; | ||
if (resourceRegExp.test(/** @type {string} */ (createData.resource))) { | ||
if (typeof newResource === "function") { | ||
newResource(result); | ||
} else { | ||
const fs = | ||
/** @type {InputFileSystem} */ | ||
(compiler.inputFileSystem); | ||
if ( | ||
newResource.startsWith("/") || | ||
(newResource.length > 1 && newResource[1] === ":") | ||
) { | ||
createData.resource = newResource; | ||
} else { | ||
const fs = | ||
/** @type {InputFileSystem} */ | ||
(compiler.inputFileSystem); | ||
if ( | ||
newResource.startsWith("/") || | ||
(newResource.length > 1 && newResource[1] === ":") | ||
) { | ||
createData.resource = newResource; | ||
} else { | ||
createData.resource = join( | ||
fs, | ||
dirname(fs, /** @type {string} */ (createData.resource)), | ||
newResource | ||
); | ||
} | ||
createData.resource = join( | ||
fs, | ||
dirname(fs, /** @type {string} */ (createData.resource)), | ||
newResource | ||
); | ||
} | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -78,0 +75,0 @@ } |
@@ -55,2 +55,4 @@ /* | ||
const PLUGIN_NAME = "AggressiveSplittingPlugin"; | ||
class AggressiveSplittingPlugin { | ||
@@ -92,259 +94,249 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.thisCompilation.tap( | ||
"AggressiveSplittingPlugin", | ||
compilation => { | ||
let needAdditionalSeal = false; | ||
/** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: Module[], size: number }} SplitData */ | ||
/** @type {SplitData[]} */ | ||
let newSplits; | ||
/** @type {Set<Chunk>} */ | ||
let fromAggressiveSplittingSet; | ||
/** @type {Map<Chunk, SplitData>} */ | ||
let chunkSplitDataMap; | ||
compilation.hooks.optimize.tap("AggressiveSplittingPlugin", () => { | ||
newSplits = []; | ||
fromAggressiveSplittingSet = new Set(); | ||
chunkSplitDataMap = new Map(); | ||
}); | ||
compilation.hooks.optimizeChunks.tap( | ||
{ | ||
name: "AggressiveSplittingPlugin", | ||
stage: STAGE_ADVANCED | ||
}, | ||
chunks => { | ||
const chunkGraph = compilation.chunkGraph; | ||
// Precompute stuff | ||
const nameToModuleMap = new Map(); | ||
const moduleToNameMap = new Map(); | ||
const makePathsRelative = | ||
identifierUtils.makePathsRelative.bindContextCache( | ||
compiler.context, | ||
compiler.root | ||
); | ||
for (const m of compilation.modules) { | ||
const name = makePathsRelative(m.identifier()); | ||
nameToModuleMap.set(name, m); | ||
moduleToNameMap.set(m, name); | ||
} | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
let needAdditionalSeal = false; | ||
/** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: Module[], size: number }} SplitData */ | ||
/** @type {SplitData[]} */ | ||
let newSplits; | ||
/** @type {Set<Chunk>} */ | ||
let fromAggressiveSplittingSet; | ||
/** @type {Map<Chunk, SplitData>} */ | ||
let chunkSplitDataMap; | ||
compilation.hooks.optimize.tap(PLUGIN_NAME, () => { | ||
newSplits = []; | ||
fromAggressiveSplittingSet = new Set(); | ||
chunkSplitDataMap = new Map(); | ||
}); | ||
compilation.hooks.optimizeChunks.tap( | ||
{ | ||
name: PLUGIN_NAME, | ||
stage: STAGE_ADVANCED | ||
}, | ||
chunks => { | ||
const chunkGraph = compilation.chunkGraph; | ||
// Precompute stuff | ||
const nameToModuleMap = new Map(); | ||
const moduleToNameMap = new Map(); | ||
const makePathsRelative = | ||
identifierUtils.makePathsRelative.bindContextCache( | ||
compiler.context, | ||
compiler.root | ||
); | ||
for (const m of compilation.modules) { | ||
const name = makePathsRelative(m.identifier()); | ||
nameToModuleMap.set(name, m); | ||
moduleToNameMap.set(m, name); | ||
} | ||
// Check used chunk ids | ||
const usedIds = new Set(); | ||
for (const chunk of chunks) { | ||
usedIds.add(chunk.id); | ||
} | ||
// Check used chunk ids | ||
const usedIds = new Set(); | ||
for (const chunk of chunks) { | ||
usedIds.add(chunk.id); | ||
} | ||
const recordedSplits = | ||
(compilation.records && compilation.records.aggressiveSplits) || | ||
[]; | ||
const usedSplits = newSplits | ||
? recordedSplits.concat(newSplits) | ||
: recordedSplits; | ||
const recordedSplits = | ||
(compilation.records && compilation.records.aggressiveSplits) || []; | ||
const usedSplits = newSplits | ||
? recordedSplits.concat(newSplits) | ||
: recordedSplits; | ||
const minSize = /** @type {number} */ (this.options.minSize); | ||
const maxSize = /** @type {number} */ (this.options.maxSize); | ||
const minSize = /** @type {number} */ (this.options.minSize); | ||
const maxSize = /** @type {number} */ (this.options.maxSize); | ||
/** | ||
* @param {SplitData} splitData split data | ||
* @returns {boolean} true when applied, otherwise false | ||
*/ | ||
const applySplit = splitData => { | ||
// Cannot split if id is already taken | ||
if (splitData.id !== undefined && usedIds.has(splitData.id)) { | ||
return false; | ||
} | ||
/** | ||
* @param {SplitData} splitData split data | ||
* @returns {boolean} true when applied, otherwise false | ||
*/ | ||
const applySplit = splitData => { | ||
// Cannot split if id is already taken | ||
if (splitData.id !== undefined && usedIds.has(splitData.id)) { | ||
return false; | ||
} | ||
// Get module objects from names | ||
const selectedModules = splitData.modules.map(name => | ||
nameToModuleMap.get(name) | ||
); | ||
// Get module objects from names | ||
const selectedModules = splitData.modules.map(name => | ||
nameToModuleMap.get(name) | ||
); | ||
// Does the modules exist at all? | ||
if (!selectedModules.every(Boolean)) return false; | ||
// Does the modules exist at all? | ||
if (!selectedModules.every(Boolean)) return false; | ||
// Check if size matches (faster than waiting for hash) | ||
let size = 0; | ||
for (const m of selectedModules) size += m.size(); | ||
if (size !== splitData.size) return false; | ||
// Check if size matches (faster than waiting for hash) | ||
let size = 0; | ||
for (const m of selectedModules) size += m.size(); | ||
if (size !== splitData.size) return false; | ||
// get chunks with all modules | ||
const selectedChunks = intersect( | ||
selectedModules.map( | ||
m => new Set(chunkGraph.getModuleChunksIterable(m)) | ||
) | ||
); | ||
// get chunks with all modules | ||
const selectedChunks = intersect( | ||
selectedModules.map( | ||
m => new Set(chunkGraph.getModuleChunksIterable(m)) | ||
) | ||
); | ||
// No relevant chunks found | ||
if (selectedChunks.size === 0) return false; | ||
// No relevant chunks found | ||
if (selectedChunks.size === 0) return false; | ||
// The found chunk is already the split or similar | ||
if ( | ||
selectedChunks.size === 1 && | ||
chunkGraph.getNumberOfChunkModules( | ||
Array.from(selectedChunks)[0] | ||
) === selectedModules.length | ||
) { | ||
const chunk = Array.from(selectedChunks)[0]; | ||
if (fromAggressiveSplittingSet.has(chunk)) return false; | ||
fromAggressiveSplittingSet.add(chunk); | ||
chunkSplitDataMap.set(chunk, splitData); | ||
return true; | ||
} | ||
// split the chunk into two parts | ||
const newChunk = compilation.addChunk(); | ||
newChunk.chunkReason = "aggressive splitted"; | ||
for (const chunk of selectedChunks) { | ||
for (const module of selectedModules) { | ||
moveModuleBetween(chunkGraph, chunk, newChunk)(module); | ||
} | ||
chunk.split(newChunk); | ||
chunk.name = /** @type {TODO} */ (null); | ||
} | ||
fromAggressiveSplittingSet.add(newChunk); | ||
chunkSplitDataMap.set(newChunk, splitData); | ||
if (splitData.id !== null && splitData.id !== undefined) { | ||
newChunk.id = splitData.id; | ||
newChunk.ids = [splitData.id]; | ||
} | ||
// The found chunk is already the split or similar | ||
if ( | ||
selectedChunks.size === 1 && | ||
chunkGraph.getNumberOfChunkModules( | ||
Array.from(selectedChunks)[0] | ||
) === selectedModules.length | ||
) { | ||
const chunk = Array.from(selectedChunks)[0]; | ||
if (fromAggressiveSplittingSet.has(chunk)) return false; | ||
fromAggressiveSplittingSet.add(chunk); | ||
chunkSplitDataMap.set(chunk, splitData); | ||
return true; | ||
}; | ||
// try to restore to recorded splitting | ||
let changed = false; | ||
for (let j = 0; j < usedSplits.length; j++) { | ||
const splitData = usedSplits[j]; | ||
if (applySplit(splitData)) changed = true; | ||
} | ||
// for any chunk which isn't splitted yet, split it and create a new entry | ||
// start with the biggest chunk | ||
const cmpFn = compareChunks(chunkGraph); | ||
const sortedChunks = Array.from(chunks).sort((a, b) => { | ||
const diff1 = | ||
chunkGraph.getChunkModulesSize(b) - | ||
chunkGraph.getChunkModulesSize(a); | ||
if (diff1) return diff1; | ||
const diff2 = | ||
chunkGraph.getNumberOfChunkModules(a) - | ||
chunkGraph.getNumberOfChunkModules(b); | ||
if (diff2) return diff2; | ||
return cmpFn(a, b); | ||
}); | ||
for (const chunk of sortedChunks) { | ||
if (fromAggressiveSplittingSet.has(chunk)) continue; | ||
const size = chunkGraph.getChunkModulesSize(chunk); | ||
if ( | ||
size > maxSize && | ||
chunkGraph.getNumberOfChunkModules(chunk) > 1 | ||
) { | ||
const modules = chunkGraph | ||
.getOrderedChunkModules(chunk, compareModulesByIdentifier) | ||
.filter(isNotAEntryModule(chunkGraph, chunk)); | ||
const selectedModules = []; | ||
let selectedModulesSize = 0; | ||
for (let k = 0; k < modules.length; k++) { | ||
const module = modules[k]; | ||
const newSize = selectedModulesSize + module.size(); | ||
if (newSize > maxSize && selectedModulesSize >= minSize) { | ||
break; | ||
} | ||
selectedModulesSize = newSize; | ||
selectedModules.push(module); | ||
} | ||
if (selectedModules.length === 0) continue; | ||
/** @type {SplitData} */ | ||
const splitData = { | ||
modules: selectedModules | ||
.map(m => moduleToNameMap.get(m)) | ||
.sort(), | ||
size: selectedModulesSize | ||
}; | ||
if (applySplit(splitData)) { | ||
newSplits = (newSplits || []).concat(splitData); | ||
changed = true; | ||
} | ||
// split the chunk into two parts | ||
const newChunk = compilation.addChunk(); | ||
newChunk.chunkReason = "aggressive splitted"; | ||
for (const chunk of selectedChunks) { | ||
for (const module of selectedModules) { | ||
moveModuleBetween(chunkGraph, chunk, newChunk)(module); | ||
} | ||
chunk.split(newChunk); | ||
chunk.name = /** @type {TODO} */ (null); | ||
} | ||
if (changed) return true; | ||
} | ||
); | ||
compilation.hooks.recordHash.tap( | ||
"AggressiveSplittingPlugin", | ||
records => { | ||
// 4. save made splittings to records | ||
const allSplits = new Set(); | ||
/** @type {Set<SplitData>} */ | ||
const invalidSplits = new Set(); | ||
fromAggressiveSplittingSet.add(newChunk); | ||
chunkSplitDataMap.set(newChunk, splitData); | ||
// Check if some splittings are invalid | ||
// We remove invalid splittings and try again | ||
for (const chunk of compilation.chunks) { | ||
const splitData = chunkSplitDataMap.get(chunk); | ||
if ( | ||
splitData !== undefined && | ||
splitData.hash && | ||
chunk.hash !== splitData.hash | ||
) { | ||
// Split was successful, but hash doesn't equal | ||
// We can throw away the split since it's useless now | ||
invalidSplits.add(splitData); | ||
} | ||
if (splitData.id !== null && splitData.id !== undefined) { | ||
newChunk.id = splitData.id; | ||
newChunk.ids = [splitData.id]; | ||
} | ||
return true; | ||
}; | ||
if (invalidSplits.size > 0) { | ||
records.aggressiveSplits = | ||
/** @type {SplitData[]} */ | ||
(records.aggressiveSplits).filter( | ||
splitData => !invalidSplits.has(splitData) | ||
); | ||
needAdditionalSeal = true; | ||
} else { | ||
// set hash and id values on all (new) splittings | ||
for (const chunk of compilation.chunks) { | ||
const splitData = chunkSplitDataMap.get(chunk); | ||
if (splitData !== undefined) { | ||
splitData.hash = | ||
/** @type {NonNullable<Chunk["hash"]>} */ | ||
(chunk.hash); | ||
splitData.id = | ||
/** @type {NonNullable<Chunk["id"]>} */ | ||
(chunk.id); | ||
allSplits.add(splitData); | ||
// set flag for stats | ||
recordedChunks.add(chunk); | ||
// try to restore to recorded splitting | ||
let changed = false; | ||
for (let j = 0; j < usedSplits.length; j++) { | ||
const splitData = usedSplits[j]; | ||
if (applySplit(splitData)) changed = true; | ||
} | ||
// for any chunk which isn't splitted yet, split it and create a new entry | ||
// start with the biggest chunk | ||
const cmpFn = compareChunks(chunkGraph); | ||
const sortedChunks = Array.from(chunks).sort((a, b) => { | ||
const diff1 = | ||
chunkGraph.getChunkModulesSize(b) - | ||
chunkGraph.getChunkModulesSize(a); | ||
if (diff1) return diff1; | ||
const diff2 = | ||
chunkGraph.getNumberOfChunkModules(a) - | ||
chunkGraph.getNumberOfChunkModules(b); | ||
if (diff2) return diff2; | ||
return cmpFn(a, b); | ||
}); | ||
for (const chunk of sortedChunks) { | ||
if (fromAggressiveSplittingSet.has(chunk)) continue; | ||
const size = chunkGraph.getChunkModulesSize(chunk); | ||
if ( | ||
size > maxSize && | ||
chunkGraph.getNumberOfChunkModules(chunk) > 1 | ||
) { | ||
const modules = chunkGraph | ||
.getOrderedChunkModules(chunk, compareModulesByIdentifier) | ||
.filter(isNotAEntryModule(chunkGraph, chunk)); | ||
const selectedModules = []; | ||
let selectedModulesSize = 0; | ||
for (let k = 0; k < modules.length; k++) { | ||
const module = modules[k]; | ||
const newSize = selectedModulesSize + module.size(); | ||
if (newSize > maxSize && selectedModulesSize >= minSize) { | ||
break; | ||
} | ||
selectedModulesSize = newSize; | ||
selectedModules.push(module); | ||
} | ||
if (selectedModules.length === 0) continue; | ||
/** @type {SplitData} */ | ||
const splitData = { | ||
modules: selectedModules | ||
.map(m => moduleToNameMap.get(m)) | ||
.sort(), | ||
size: selectedModulesSize | ||
}; | ||
// Also add all unused historical splits (after the used ones) | ||
// They can still be used in some future compilation | ||
const recordedSplits = | ||
compilation.records && compilation.records.aggressiveSplits; | ||
if (recordedSplits) { | ||
for (const splitData of recordedSplits) { | ||
if (!invalidSplits.has(splitData)) allSplits.add(splitData); | ||
} | ||
if (applySplit(splitData)) { | ||
newSplits = (newSplits || []).concat(splitData); | ||
changed = true; | ||
} | ||
} | ||
} | ||
if (changed) return true; | ||
} | ||
); | ||
compilation.hooks.recordHash.tap(PLUGIN_NAME, records => { | ||
// 4. save made splittings to records | ||
const allSplits = new Set(); | ||
/** @type {Set<SplitData>} */ | ||
const invalidSplits = new Set(); | ||
// record all splits | ||
records.aggressiveSplits = Array.from(allSplits); | ||
// Check if some splittings are invalid | ||
// We remove invalid splittings and try again | ||
for (const chunk of compilation.chunks) { | ||
const splitData = chunkSplitDataMap.get(chunk); | ||
if ( | ||
splitData !== undefined && | ||
splitData.hash && | ||
chunk.hash !== splitData.hash | ||
) { | ||
// Split was successful, but hash doesn't equal | ||
// We can throw away the split since it's useless now | ||
invalidSplits.add(splitData); | ||
} | ||
} | ||
needAdditionalSeal = false; | ||
if (invalidSplits.size > 0) { | ||
records.aggressiveSplits = | ||
/** @type {SplitData[]} */ | ||
(records.aggressiveSplits).filter( | ||
splitData => !invalidSplits.has(splitData) | ||
); | ||
needAdditionalSeal = true; | ||
} else { | ||
// set hash and id values on all (new) splittings | ||
for (const chunk of compilation.chunks) { | ||
const splitData = chunkSplitDataMap.get(chunk); | ||
if (splitData !== undefined) { | ||
splitData.hash = | ||
/** @type {NonNullable<Chunk["hash"]>} */ | ||
(chunk.hash); | ||
splitData.id = | ||
/** @type {NonNullable<Chunk["id"]>} */ | ||
(chunk.id); | ||
allSplits.add(splitData); | ||
// set flag for stats | ||
recordedChunks.add(chunk); | ||
} | ||
} | ||
); | ||
compilation.hooks.needAdditionalSeal.tap( | ||
"AggressiveSplittingPlugin", | ||
() => { | ||
if (needAdditionalSeal) { | ||
needAdditionalSeal = false; | ||
return true; | ||
// Also add all unused historical splits (after the used ones) | ||
// They can still be used in some future compilation | ||
const recordedSplits = | ||
compilation.records && compilation.records.aggressiveSplits; | ||
if (recordedSplits) { | ||
for (const splitData of recordedSplits) { | ||
if (!invalidSplits.has(splitData)) allSplits.add(splitData); | ||
} | ||
} | ||
); | ||
} | ||
); | ||
// record all splits | ||
records.aggressiveSplits = Array.from(allSplits); | ||
needAdditionalSeal = false; | ||
} | ||
}); | ||
compilation.hooks.needAdditionalSeal.tap(PLUGIN_NAME, () => { | ||
if (needAdditionalSeal) { | ||
needAdditionalSeal = false; | ||
return true; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
module.exports = AggressiveSplittingPlugin; |
@@ -87,2 +87,3 @@ /* | ||
/** @typedef {typeof import("../util/Hash")} HashConstructor */ | ||
/** @typedef {import("../util/concatenate").ScopeInfo} ScopeInfo */ | ||
/** @typedef {import("../util/concatenate").UsedNames} UsedNames */ | ||
@@ -1142,9 +1143,4 @@ /** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */ | ||
// List of additional names in scope for module references | ||
/** @type {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }>} */ | ||
/** @type {Map<string, ScopeInfo>} */ | ||
const usedNamesInScopeInfo = new Map(); | ||
/** | ||
* @param {string} module module identifier | ||
* @param {string} id export id | ||
* @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info | ||
*/ | ||
@@ -1168,3 +1164,3 @@ // Set of already checked scopes | ||
* @param {Scope} scope scope | ||
* @returns {TODO} result | ||
* @returns {{ range: Range, variables: Variable[] }[]} result | ||
*/ | ||
@@ -1184,3 +1180,3 @@ const getSuperClassExpressions = scope => { | ||
superClassExpressions.push({ | ||
range: block.superClass.range, | ||
range: /** @type {Range} */ (block.superClass.range), | ||
variables: childScope.variables | ||
@@ -1435,5 +1431,5 @@ }); | ||
const rootInfo = /** @type {ConcatenatedModuleInfo} */ ( | ||
moduleToInfoMap.get(this.rootModule) | ||
); | ||
const rootInfo = | ||
/** @type {ConcatenatedModuleInfo} */ | ||
(moduleToInfoMap.get(this.rootModule)); | ||
const strictHarmonyModule = | ||
@@ -1640,3 +1636,4 @@ /** @type {BuildMeta} */ | ||
const { runtimeCondition } = | ||
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ (rawInfo); | ||
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */ | ||
(rawInfo); | ||
const condition = runtimeTemplate.runtimeConditionExpression({ | ||
@@ -1739,5 +1736,5 @@ chunkGraph, | ||
}); | ||
const source = /** @type {Source} */ ( | ||
codeGenResult.sources.get("javascript") | ||
); | ||
const source = | ||
/** @type {Source} */ | ||
(codeGenResult.sources.get("javascript")); | ||
const data = codeGenResult.data; | ||
@@ -1744,0 +1741,0 @@ const chunkInitFragments = data && data.get("chunkInitFragments"); |
@@ -15,2 +15,4 @@ /* | ||
const PLUGIN_NAME = "FlagIncludedChunksPlugin"; | ||
class FlagIncludedChunksPlugin { | ||
@@ -23,107 +25,100 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", compilation => { | ||
compilation.hooks.optimizeChunkIds.tap( | ||
"FlagIncludedChunksPlugin", | ||
chunks => { | ||
const chunkGraph = compilation.chunkGraph; | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.optimizeChunkIds.tap(PLUGIN_NAME, chunks => { | ||
const chunkGraph = compilation.chunkGraph; | ||
// prepare two bit integers for each module | ||
// 2^31 is the max number represented as SMI in v8 | ||
// we want the bits distributed this way: | ||
// the bit 2^31 is pretty rar and only one module should get it | ||
// so it has a probability of 1 / modulesCount | ||
// the first bit (2^0) is the easiest and every module could get it | ||
// if it doesn't get a better bit | ||
// from bit 2^n to 2^(n+1) there is a probability of p | ||
// so 1 / modulesCount == p^31 | ||
// <=> p = sqrt31(1 / modulesCount) | ||
// so we use a modulo of 1 / sqrt31(1 / modulesCount) | ||
/** @type {WeakMap<Module, number>} */ | ||
const moduleBits = new WeakMap(); | ||
const modulesCount = compilation.modules.size; | ||
// prepare two bit integers for each module | ||
// 2^31 is the max number represented as SMI in v8 | ||
// we want the bits distributed this way: | ||
// the bit 2^31 is pretty rar and only one module should get it | ||
// so it has a probability of 1 / modulesCount | ||
// the first bit (2^0) is the easiest and every module could get it | ||
// if it doesn't get a better bit | ||
// from bit 2^n to 2^(n+1) there is a probability of p | ||
// so 1 / modulesCount == p^31 | ||
// <=> p = sqrt31(1 / modulesCount) | ||
// so we use a modulo of 1 / sqrt31(1 / modulesCount) | ||
/** @type {WeakMap<Module, number>} */ | ||
const moduleBits = new WeakMap(); | ||
const modulesCount = compilation.modules.size; | ||
// precalculate the modulo values for each bit | ||
const modulo = 1 / (1 / modulesCount) ** (1 / 31); | ||
const modulos = Array.from( | ||
{ length: 31 }, | ||
(x, i) => (modulo ** i) | 0 | ||
); | ||
// precalculate the modulo values for each bit | ||
const modulo = 1 / (1 / modulesCount) ** (1 / 31); | ||
const modulos = Array.from({ length: 31 }, (x, i) => (modulo ** i) | 0); | ||
// iterate all modules to generate bit values | ||
let i = 0; | ||
for (const module of compilation.modules) { | ||
let bit = 30; | ||
while (i % modulos[bit] !== 0) { | ||
bit--; | ||
} | ||
moduleBits.set(module, 1 << bit); | ||
i++; | ||
// iterate all modules to generate bit values | ||
let i = 0; | ||
for (const module of compilation.modules) { | ||
let bit = 30; | ||
while (i % modulos[bit] !== 0) { | ||
bit--; | ||
} | ||
moduleBits.set(module, 1 << bit); | ||
i++; | ||
} | ||
// iterate all chunks to generate bitmaps | ||
/** @type {WeakMap<Chunk, number>} */ | ||
const chunkModulesHash = new WeakMap(); | ||
for (const chunk of chunks) { | ||
let hash = 0; | ||
for (const module of chunkGraph.getChunkModulesIterable(chunk)) { | ||
hash |= /** @type {number} */ (moduleBits.get(module)); | ||
} | ||
chunkModulesHash.set(chunk, hash); | ||
// iterate all chunks to generate bitmaps | ||
/** @type {WeakMap<Chunk, number>} */ | ||
const chunkModulesHash = new WeakMap(); | ||
for (const chunk of chunks) { | ||
let hash = 0; | ||
for (const module of chunkGraph.getChunkModulesIterable(chunk)) { | ||
hash |= /** @type {number} */ (moduleBits.get(module)); | ||
} | ||
chunkModulesHash.set(chunk, hash); | ||
} | ||
for (const chunkA of chunks) { | ||
const chunkAHash = | ||
/** @type {number} */ | ||
(chunkModulesHash.get(chunkA)); | ||
const chunkAModulesCount = | ||
chunkGraph.getNumberOfChunkModules(chunkA); | ||
if (chunkAModulesCount === 0) continue; | ||
let bestModule; | ||
for (const module of chunkGraph.getChunkModulesIterable(chunkA)) { | ||
if ( | ||
bestModule === undefined || | ||
chunkGraph.getNumberOfModuleChunks(bestModule) > | ||
chunkGraph.getNumberOfModuleChunks(module) | ||
) | ||
bestModule = module; | ||
} | ||
loopB: for (const chunkB of chunkGraph.getModuleChunksIterable( | ||
/** @type {Module} */ (bestModule) | ||
)) { | ||
// as we iterate the same iterables twice | ||
// skip if we find ourselves | ||
if (chunkA === chunkB) continue; | ||
for (const chunkA of chunks) { | ||
const chunkAHash = | ||
/** @type {number} */ | ||
(chunkModulesHash.get(chunkA)); | ||
const chunkAModulesCount = chunkGraph.getNumberOfChunkModules(chunkA); | ||
if (chunkAModulesCount === 0) continue; | ||
let bestModule; | ||
for (const module of chunkGraph.getChunkModulesIterable(chunkA)) { | ||
if ( | ||
bestModule === undefined || | ||
chunkGraph.getNumberOfModuleChunks(bestModule) > | ||
chunkGraph.getNumberOfModuleChunks(module) | ||
) | ||
bestModule = module; | ||
} | ||
loopB: for (const chunkB of chunkGraph.getModuleChunksIterable( | ||
/** @type {Module} */ (bestModule) | ||
)) { | ||
// as we iterate the same iterables twice | ||
// skip if we find ourselves | ||
if (chunkA === chunkB) continue; | ||
const chunkBModulesCount = | ||
chunkGraph.getNumberOfChunkModules(chunkB); | ||
const chunkBModulesCount = | ||
chunkGraph.getNumberOfChunkModules(chunkB); | ||
// ids for empty chunks are not included | ||
if (chunkBModulesCount === 0) continue; | ||
// ids for empty chunks are not included | ||
if (chunkBModulesCount === 0) continue; | ||
// instead of swapping A and B just bail | ||
// as we loop twice the current A will be B and B then A | ||
if (chunkAModulesCount > chunkBModulesCount) continue; | ||
// instead of swapping A and B just bail | ||
// as we loop twice the current A will be B and B then A | ||
if (chunkAModulesCount > chunkBModulesCount) continue; | ||
// is chunkA in chunkB? | ||
// is chunkA in chunkB? | ||
// we do a cheap check for the hash value | ||
const chunkBHash = | ||
/** @type {number} */ | ||
(chunkModulesHash.get(chunkB)); | ||
if ((chunkBHash & chunkAHash) !== chunkAHash) continue; | ||
// we do a cheap check for the hash value | ||
const chunkBHash = | ||
/** @type {number} */ | ||
(chunkModulesHash.get(chunkB)); | ||
if ((chunkBHash & chunkAHash) !== chunkAHash) continue; | ||
// compare all modules | ||
for (const m of chunkGraph.getChunkModulesIterable(chunkA)) { | ||
if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB; | ||
} | ||
// compare all modules | ||
for (const m of chunkGraph.getChunkModulesIterable(chunkA)) { | ||
if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB; | ||
} | ||
/** @type {ChunkId[]} */ | ||
(chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id)); | ||
// https://github.com/webpack/webpack/issues/18837 | ||
/** @type {ChunkId[]} */ | ||
(chunkB.ids).sort(compareIds); | ||
} | ||
/** @type {ChunkId[]} */ | ||
(chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id)); | ||
// https://github.com/webpack/webpack/issues/18837 | ||
/** @type {ChunkId[]} */ | ||
(chunkB.ids).sort(compareIds); | ||
} | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -130,0 +125,0 @@ } |
@@ -54,2 +54,4 @@ /* | ||
const PLUGIN_NAME = "LimitChunkCountPlugin"; | ||
class LimitChunkCountPlugin { | ||
@@ -70,6 +72,6 @@ /** | ||
const options = this.options; | ||
compiler.hooks.compilation.tap("LimitChunkCountPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.optimizeChunks.tap( | ||
{ | ||
name: "LimitChunkCountPlugin", | ||
name: PLUGIN_NAME, | ||
stage: STAGE_ADVANCED | ||
@@ -76,0 +78,0 @@ }, |
@@ -145,2 +145,4 @@ /* | ||
const PLUGIN_NAME = "MangleExportsPlugin"; | ||
class MangleExportsPlugin { | ||
@@ -161,20 +163,17 @@ /** | ||
const { _deterministic: deterministic } = this; | ||
compiler.hooks.compilation.tap("MangleExportsPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const moduleGraph = compilation.moduleGraph; | ||
compilation.hooks.optimizeCodeGeneration.tap( | ||
"MangleExportsPlugin", | ||
modules => { | ||
if (compilation.moduleMemCaches) { | ||
throw new Error( | ||
"optimization.mangleExports can't be used with cacheUnaffected as export mangling is a global effect" | ||
); | ||
} | ||
for (const module of modules) { | ||
const isNamespace = | ||
module.buildMeta && module.buildMeta.exportsType === "namespace"; | ||
const exportsInfo = moduleGraph.getExportsInfo(module); | ||
mangleExportsInfo(deterministic, exportsInfo, isNamespace); | ||
} | ||
compilation.hooks.optimizeCodeGeneration.tap(PLUGIN_NAME, modules => { | ||
if (compilation.moduleMemCaches) { | ||
throw new Error( | ||
"optimization.mangleExports can't be used with cacheUnaffected as export mangling is a global effect" | ||
); | ||
} | ||
); | ||
for (const module of modules) { | ||
const isNamespace = | ||
module.buildMeta && module.buildMeta.exportsType === "namespace"; | ||
const exportsInfo = moduleGraph.getExportsInfo(module); | ||
mangleExportsInfo(deterministic, exportsInfo, isNamespace); | ||
} | ||
}); | ||
}); | ||
@@ -181,0 +180,0 @@ } |
@@ -24,2 +24,4 @@ /* | ||
const PLUGIN_NAME = "MinChunkSizePlugin"; | ||
class MinChunkSizePlugin { | ||
@@ -42,6 +44,6 @@ /** | ||
const minChunkSize = options.minChunkSize; | ||
compiler.hooks.compilation.tap("MinChunkSizePlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.optimizeChunks.tap( | ||
{ | ||
name: "MinChunkSizePlugin", | ||
name: PLUGIN_NAME, | ||
stage: STAGE_ADVANCED | ||
@@ -48,0 +50,0 @@ }, |
@@ -51,2 +51,4 @@ /* | ||
const PLUGIN_NAME = "ModuleConcatenationPlugin"; | ||
class ModuleConcatenationPlugin { | ||
@@ -60,3 +62,3 @@ /** | ||
const { _backCompat: backCompat } = compiler; | ||
compiler.hooks.compilation.tap("ModuleConcatenationPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
if (compilation.moduleMemCaches) { | ||
@@ -138,3 +140,3 @@ throw new Error( | ||
{ | ||
name: "ModuleConcatenationPlugin", | ||
name: PLUGIN_NAME, | ||
stage: STAGE_DEFAULT | ||
@@ -141,0 +143,0 @@ }, |
@@ -116,2 +116,4 @@ /* | ||
const PLUGIN_NAME = "RealContentHashPlugin"; | ||
class RealContentHashPlugin { | ||
@@ -152,3 +154,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("RealContentHashPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const cacheAnalyse = compilation.getCache( | ||
@@ -163,3 +165,3 @@ "RealContentHashPlugin|analyse" | ||
{ | ||
name: "RealContentHashPlugin", | ||
name: PLUGIN_NAME, | ||
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH | ||
@@ -166,0 +168,0 @@ }, |
@@ -13,2 +13,4 @@ /* | ||
const PLUGIN_NAME = "RemoveEmptyChunksPlugin"; | ||
class RemoveEmptyChunksPlugin { | ||
@@ -21,3 +23,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("RemoveEmptyChunksPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
/** | ||
@@ -44,3 +46,3 @@ * @param {Iterable<Chunk>} chunks the chunks array | ||
{ | ||
name: "RemoveEmptyChunksPlugin", | ||
name: PLUGIN_NAME, | ||
stage: STAGE_BASIC | ||
@@ -52,3 +54,3 @@ }, | ||
{ | ||
name: "RemoveEmptyChunksPlugin", | ||
name: PLUGIN_NAME, | ||
stage: STAGE_ADVANCED | ||
@@ -55,0 +57,0 @@ }, |
@@ -62,2 +62,4 @@ /* | ||
const PLUGIN_NAME = "RemoveParentModulesPlugin"; | ||
class RemoveParentModulesPlugin { | ||
@@ -69,3 +71,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("RemoveParentModulesPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
/** | ||
@@ -198,3 +200,3 @@ * @param {Iterable<Chunk>} chunks the chunks | ||
{ | ||
name: "RemoveParentModulesPlugin", | ||
name: PLUGIN_NAME, | ||
stage: STAGE_BASIC | ||
@@ -201,0 +203,0 @@ }, |
@@ -12,2 +12,4 @@ /* | ||
const PLUGIN_NAME = "RuntimeChunkPlugin"; | ||
class RuntimeChunkPlugin { | ||
@@ -34,22 +36,19 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => { | ||
compilation.hooks.addEntry.tap( | ||
"RuntimeChunkPlugin", | ||
(_, { name: entryName }) => { | ||
if (entryName === undefined) return; | ||
const data = | ||
/** @type {EntryData} */ | ||
(compilation.entries.get(entryName)); | ||
if (data.options.runtime === undefined && !data.options.dependOn) { | ||
// Determine runtime chunk name | ||
let name = | ||
/** @type {string | ((entrypoint: { name: string }) => string)} */ | ||
(this.options.name); | ||
if (typeof name === "function") { | ||
name = name({ name: entryName }); | ||
} | ||
data.options.runtime = name; | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.addEntry.tap(PLUGIN_NAME, (_, { name: entryName }) => { | ||
if (entryName === undefined) return; | ||
const data = | ||
/** @type {EntryData} */ | ||
(compilation.entries.get(entryName)); | ||
if (data.options.runtime === undefined && !data.options.dependOn) { | ||
// Determine runtime chunk name | ||
let name = | ||
/** @type {string | ((entrypoint: { name: string }) => string)} */ | ||
(this.options.name); | ||
if (typeof name === "function") { | ||
name = name({ name: entryName }); | ||
} | ||
data.options.runtime = name; | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -56,0 +55,0 @@ } |
@@ -634,2 +634,4 @@ /* | ||
const PLUGIN_NAME = "SplitChunksPlugin"; | ||
module.exports = class SplitChunksPlugin { | ||
@@ -826,6 +828,6 @@ /** | ||
); | ||
compiler.hooks.thisCompilation.tap("SplitChunksPlugin", compilation => { | ||
const logger = compilation.getLogger("webpack.SplitChunksPlugin"); | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`); | ||
let alreadyOptimized = false; | ||
compilation.hooks.unseal.tap("SplitChunksPlugin", () => { | ||
compilation.hooks.unseal.tap(PLUGIN_NAME, () => { | ||
alreadyOptimized = false; | ||
@@ -835,3 +837,3 @@ }); | ||
{ | ||
name: "SplitChunksPlugin", | ||
name: PLUGIN_NAME, | ||
stage: STAGE_ADVANCED | ||
@@ -1177,3 +1179,3 @@ }, | ||
new WebpackError( | ||
"SplitChunksPlugin\n" + | ||
`${PLUGIN_NAME}\n` + | ||
`Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` + | ||
@@ -1180,0 +1182,0 @@ `Both have the same name "${name}" and existing chunk is not a parent of the selected modules.\n` + |
@@ -44,2 +44,4 @@ /* | ||
const PLUGIN_NAME = "SizeLimitsPlugin"; | ||
module.exports = class SizeLimitsPlugin { | ||
@@ -75,3 +77,3 @@ /** | ||
compiler.hooks.afterEmit.tap("SizeLimitsPlugin", compilation => { | ||
compiler.hooks.afterEmit.tap(PLUGIN_NAME, compilation => { | ||
/** @type {WebpackError[]} */ | ||
@@ -78,0 +80,0 @@ const warnings = []; |
@@ -11,2 +11,4 @@ /* | ||
const PLUGIN_NAME = "PlatformPlugin"; | ||
/** | ||
@@ -31,3 +33,3 @@ * Should be used only for "target === false" or | ||
apply(compiler) { | ||
compiler.hooks.environment.tap("PlatformPlugin", () => { | ||
compiler.hooks.environment.tap(PLUGIN_NAME, () => { | ||
compiler.platform = { | ||
@@ -34,0 +36,0 @@ ...compiler.platform, |
@@ -18,2 +18,4 @@ /* | ||
const PLUGIN_NAME = "ChunkPrefetchPreloadPlugin"; | ||
class ChunkPrefetchPreloadPlugin { | ||
@@ -25,73 +27,70 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap( | ||
"ChunkPrefetchPreloadPlugin", | ||
compilation => { | ||
compilation.hooks.additionalChunkRuntimeRequirements.tap( | ||
"ChunkPrefetchPreloadPlugin", | ||
(chunk, set, { chunkGraph }) => { | ||
if (chunkGraph.getNumberOfEntryModules(chunk) === 0) return; | ||
const startupChildChunks = chunk.getChildrenOfTypeInOrder( | ||
chunkGraph, | ||
"prefetchOrder" | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.additionalChunkRuntimeRequirements.tap( | ||
PLUGIN_NAME, | ||
(chunk, set, { chunkGraph }) => { | ||
if (chunkGraph.getNumberOfEntryModules(chunk) === 0) return; | ||
const startupChildChunks = chunk.getChildrenOfTypeInOrder( | ||
chunkGraph, | ||
"prefetchOrder" | ||
); | ||
if (startupChildChunks) { | ||
set.add(RuntimeGlobals.prefetchChunk); | ||
set.add(RuntimeGlobals.onChunksLoaded); | ||
set.add(RuntimeGlobals.exports); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPrefetchStartupRuntimeModule(startupChildChunks) | ||
); | ||
if (startupChildChunks) { | ||
set.add(RuntimeGlobals.prefetchChunk); | ||
set.add(RuntimeGlobals.onChunksLoaded); | ||
set.add(RuntimeGlobals.exports); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPrefetchStartupRuntimeModule(startupChildChunks) | ||
); | ||
} | ||
} | ||
); | ||
compilation.hooks.additionalTreeRuntimeRequirements.tap( | ||
"ChunkPrefetchPreloadPlugin", | ||
(chunk, set, { chunkGraph }) => { | ||
const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph); | ||
} | ||
); | ||
compilation.hooks.additionalTreeRuntimeRequirements.tap( | ||
PLUGIN_NAME, | ||
(chunk, set, { chunkGraph }) => { | ||
const chunkMap = chunk.getChildIdsByOrdersMap(chunkGraph); | ||
if (chunkMap.prefetch) { | ||
set.add(RuntimeGlobals.prefetchChunk); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch) | ||
); | ||
} | ||
if (chunkMap.preload) { | ||
set.add(RuntimeGlobals.preloadChunk); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPreloadTriggerRuntimeModule(chunkMap.preload) | ||
); | ||
} | ||
} | ||
); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.prefetchChunk) | ||
.tap("ChunkPrefetchPreloadPlugin", (chunk, set) => { | ||
if (chunkMap.prefetch) { | ||
set.add(RuntimeGlobals.prefetchChunk); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPrefetchFunctionRuntimeModule( | ||
"prefetch", | ||
RuntimeGlobals.prefetchChunk, | ||
RuntimeGlobals.prefetchChunkHandlers | ||
) | ||
new ChunkPrefetchTriggerRuntimeModule(chunkMap.prefetch) | ||
); | ||
set.add(RuntimeGlobals.prefetchChunkHandlers); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.preloadChunk) | ||
.tap("ChunkPrefetchPreloadPlugin", (chunk, set) => { | ||
} | ||
if (chunkMap.preload) { | ||
set.add(RuntimeGlobals.preloadChunk); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPrefetchFunctionRuntimeModule( | ||
"preload", | ||
RuntimeGlobals.preloadChunk, | ||
RuntimeGlobals.preloadChunkHandlers | ||
) | ||
new ChunkPreloadTriggerRuntimeModule(chunkMap.preload) | ||
); | ||
set.add(RuntimeGlobals.preloadChunkHandlers); | ||
}); | ||
} | ||
); | ||
} | ||
} | ||
); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.prefetchChunk) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPrefetchFunctionRuntimeModule( | ||
"prefetch", | ||
RuntimeGlobals.prefetchChunk, | ||
RuntimeGlobals.prefetchChunkHandlers | ||
) | ||
); | ||
set.add(RuntimeGlobals.prefetchChunkHandlers); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.preloadChunk) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ChunkPrefetchFunctionRuntimeModule( | ||
"preload", | ||
RuntimeGlobals.preloadChunk, | ||
RuntimeGlobals.preloadChunkHandlers | ||
) | ||
); | ||
set.add(RuntimeGlobals.preloadChunkHandlers); | ||
}); | ||
}); | ||
} | ||
@@ -98,0 +97,0 @@ } |
@@ -12,2 +12,4 @@ /* | ||
const PLUGIN_NAME = "PrefetchPlugin"; | ||
class PrefetchPlugin { | ||
@@ -35,3 +37,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"PrefetchPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -44,3 +46,3 @@ compilation.dependencyFactories.set( | ||
); | ||
compiler.hooks.make.tapAsync("PrefetchPlugin", (compilation, callback) => { | ||
compiler.hooks.make.tapAsync(PLUGIN_NAME, (compilation, callback) => { | ||
compilation.addModuleChain( | ||
@@ -47,0 +49,0 @@ this.context || compiler.context, |
@@ -143,2 +143,4 @@ /* | ||
const PLUGIN_NAME = "ProgressPlugin"; | ||
class ProgressPlugin { | ||
@@ -399,5 +401,3 @@ /** | ||
const cache = compiler | ||
.getCache("ProgressPlugin") | ||
.getItemCache("counts", null); | ||
const cache = compiler.getCache(PLUGIN_NAME).getItemCache("counts", null); | ||
@@ -407,3 +407,3 @@ /** @type {Promise<CountsData> | undefined} */ | ||
compiler.hooks.beforeCompile.tap("ProgressPlugin", () => { | ||
compiler.hooks.beforeCompile.tap(PLUGIN_NAME, () => { | ||
if (!cacheGetPromise) { | ||
@@ -426,3 +426,3 @@ cacheGetPromise = cache.getPromise().then( | ||
compiler.hooks.afterCompile.tapPromise("ProgressPlugin", compilation => { | ||
compiler.hooks.afterCompile.tapPromise(PLUGIN_NAME, compilation => { | ||
if (compilation.compiler.isChild()) return Promise.resolve(); | ||
@@ -449,3 +449,3 @@ return /** @type {Promise<CountsData>} */ (cacheGetPromise).then( | ||
compiler.hooks.compilation.tap("ProgressPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
if (compilation.compiler.isChild()) return; | ||
@@ -463,15 +463,12 @@ lastModulesCount = modulesCount; | ||
compilation.factorizeQueue.hooks.added.tap("ProgressPlugin", item => | ||
compilation.factorizeQueue.hooks.added.tap(PLUGIN_NAME, item => | ||
factorizeAdd(compilation.factorizeQueue, item) | ||
); | ||
compilation.factorizeQueue.hooks.result.tap( | ||
"ProgressPlugin", | ||
factorizeDone | ||
); | ||
compilation.factorizeQueue.hooks.result.tap(PLUGIN_NAME, factorizeDone); | ||
compilation.addModuleQueue.hooks.added.tap("ProgressPlugin", item => | ||
compilation.addModuleQueue.hooks.added.tap(PLUGIN_NAME, item => | ||
moduleAdd(compilation.addModuleQueue, item) | ||
); | ||
compilation.processDependenciesQueue.hooks.result.tap( | ||
"ProgressPlugin", | ||
PLUGIN_NAME, | ||
moduleDone | ||
@@ -481,8 +478,8 @@ ); | ||
if (showActiveModules) { | ||
compilation.hooks.buildModule.tap("ProgressPlugin", moduleBuild); | ||
compilation.hooks.buildModule.tap(PLUGIN_NAME, moduleBuild); | ||
} | ||
compilation.hooks.addEntry.tap("ProgressPlugin", entryAdd); | ||
compilation.hooks.failedEntry.tap("ProgressPlugin", entryDone); | ||
compilation.hooks.succeedEntry.tap("ProgressPlugin", entryDone); | ||
compilation.hooks.addEntry.tap(PLUGIN_NAME, entryAdd); | ||
compilation.hooks.failedEntry.tap(PLUGIN_NAME, entryDone); | ||
compilation.hooks.succeedEntry.tap(PLUGIN_NAME, entryDone); | ||
@@ -493,3 +490,3 @@ // @ts-expect-error avoid dynamic require if bundled with webpack | ||
NormalModule.getCompilationHooks(compilation).beforeLoaders.tap( | ||
"ProgressPlugin", | ||
PLUGIN_NAME, | ||
loaders => { | ||
@@ -561,3 +558,3 @@ for (const loader of loaders) { | ||
compilation.hooks[/** @type {keyof typeof hooks} */ (name)].intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
call() { | ||
@@ -588,3 +585,3 @@ handler(percentage, "sealing", title); | ||
compiler.hooks.make.intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
call() { | ||
@@ -605,3 +602,3 @@ handler(0.1, "building"); | ||
hook.intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
call() { | ||
@@ -632,3 +629,3 @@ handler(progress, category, name); | ||
compiler.cache.hooks.endIdle.intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
call() { | ||
@@ -640,3 +637,3 @@ handler(0, ""); | ||
compiler.hooks.beforeRun.intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
call() { | ||
@@ -675,3 +672,3 @@ handler(0, ""); | ||
compiler.hooks.done.intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
done() { | ||
@@ -696,3 +693,3 @@ handler(0.99, ""); | ||
compiler.cache.hooks.beginIdle.intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
done() { | ||
@@ -703,3 +700,3 @@ handler(1, ""); | ||
compiler.cache.hooks.shutdown.intercept({ | ||
name: "ProgressPlugin", | ||
name: PLUGIN_NAME, | ||
done() { | ||
@@ -706,0 +703,0 @@ handler(1, ""); |
@@ -40,2 +40,4 @@ /* | ||
const PLUGIN_NAME = "RecordIdsPlugin"; | ||
class RecordIdsPlugin { | ||
@@ -73,14 +75,22 @@ /** | ||
compiler.hooks.compilation.tap("RecordIdsPlugin", compilation => { | ||
compilation.hooks.recordModules.tap( | ||
"RecordIdsPlugin", | ||
/** | ||
* @param {Iterable<Module>} modules the modules array | ||
* @param {Records} records the records object | ||
* @returns {void} | ||
*/ | ||
(modules, records) => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.recordModules.tap(PLUGIN_NAME, (modules, records) => { | ||
const chunkGraph = compilation.chunkGraph; | ||
if (!records.modules) records.modules = {}; | ||
if (!records.modules.byIdentifier) records.modules.byIdentifier = {}; | ||
/** @type {Set<number>} */ | ||
const usedIds = new Set(); | ||
for (const module of modules) { | ||
const moduleId = chunkGraph.getModuleId(module); | ||
if (typeof moduleId !== "number") continue; | ||
const identifier = getModuleIdentifier(module); | ||
records.modules.byIdentifier[identifier] = moduleId; | ||
usedIds.add(moduleId); | ||
} | ||
records.modules.usedIds = Array.from(usedIds).sort(compareNumbers); | ||
}); | ||
compilation.hooks.reviveModules.tap(PLUGIN_NAME, (modules, records) => { | ||
if (!records.modules) return; | ||
if (records.modules.byIdentifier) { | ||
const chunkGraph = compilation.chunkGraph; | ||
if (!records.modules) records.modules = {}; | ||
if (!records.modules.byIdentifier) records.modules.byIdentifier = {}; | ||
/** @type {Set<number>} */ | ||
@@ -90,39 +100,15 @@ const usedIds = new Set(); | ||
const moduleId = chunkGraph.getModuleId(module); | ||
if (typeof moduleId !== "number") continue; | ||
if (moduleId !== null) continue; | ||
const identifier = getModuleIdentifier(module); | ||
records.modules.byIdentifier[identifier] = moduleId; | ||
usedIds.add(moduleId); | ||
const id = records.modules.byIdentifier[identifier]; | ||
if (id === undefined) continue; | ||
if (usedIds.has(id)) continue; | ||
usedIds.add(id); | ||
chunkGraph.setModuleId(module, id); | ||
} | ||
records.modules.usedIds = Array.from(usedIds).sort(compareNumbers); | ||
} | ||
); | ||
compilation.hooks.reviveModules.tap( | ||
"RecordIdsPlugin", | ||
/** | ||
* @param {Iterable<Module>} modules the modules array | ||
* @param {Records} records the records object | ||
* @returns {void} | ||
*/ | ||
(modules, records) => { | ||
if (!records.modules) return; | ||
if (records.modules.byIdentifier) { | ||
const chunkGraph = compilation.chunkGraph; | ||
/** @type {Set<number>} */ | ||
const usedIds = new Set(); | ||
for (const module of modules) { | ||
const moduleId = chunkGraph.getModuleId(module); | ||
if (moduleId !== null) continue; | ||
const identifier = getModuleIdentifier(module); | ||
const id = records.modules.byIdentifier[identifier]; | ||
if (id === undefined) continue; | ||
if (usedIds.has(id)) continue; | ||
usedIds.add(id); | ||
chunkGraph.setModuleId(module, id); | ||
} | ||
} | ||
if (Array.isArray(records.modules.usedIds)) { | ||
compilation.usedModuleIds = new Set(records.modules.usedIds); | ||
} | ||
if (Array.isArray(records.modules.usedIds)) { | ||
compilation.usedModuleIds = new Set(records.modules.usedIds); | ||
} | ||
); | ||
}); | ||
@@ -173,44 +159,42 @@ /** | ||
compilation.hooks.recordChunks.tap( | ||
"RecordIdsPlugin", | ||
/** | ||
* @param {Iterable<Chunk>} chunks the chunks array | ||
* @param {Records} records the records object | ||
* @returns {void} | ||
*/ | ||
(chunks, records) => { | ||
if (!records.chunks) records.chunks = {}; | ||
if (!records.chunks.byName) records.chunks.byName = {}; | ||
if (!records.chunks.bySource) records.chunks.bySource = {}; | ||
/** @type {Set<number>} */ | ||
const usedIds = new Set(); | ||
compilation.hooks.recordChunks.tap(PLUGIN_NAME, (chunks, records) => { | ||
if (!records.chunks) records.chunks = {}; | ||
if (!records.chunks.byName) records.chunks.byName = {}; | ||
if (!records.chunks.bySource) records.chunks.bySource = {}; | ||
/** @type {Set<number>} */ | ||
const usedIds = new Set(); | ||
for (const chunk of chunks) { | ||
if (typeof chunk.id !== "number") continue; | ||
const name = chunk.name; | ||
if (name) records.chunks.byName[name] = chunk.id; | ||
const sources = getChunkSources(chunk); | ||
for (const source of sources) { | ||
records.chunks.bySource[source] = chunk.id; | ||
} | ||
usedIds.add(chunk.id); | ||
} | ||
records.chunks.usedIds = Array.from(usedIds).sort(compareNumbers); | ||
}); | ||
compilation.hooks.reviveChunks.tap(PLUGIN_NAME, (chunks, records) => { | ||
if (!records.chunks) return; | ||
/** @type {Set<number>} */ | ||
const usedIds = new Set(); | ||
if (records.chunks.byName) { | ||
for (const chunk of chunks) { | ||
if (typeof chunk.id !== "number") continue; | ||
const name = chunk.name; | ||
if (name) records.chunks.byName[name] = chunk.id; | ||
if (chunk.id !== null) continue; | ||
if (!chunk.name) continue; | ||
const id = records.chunks.byName[chunk.name]; | ||
if (id === undefined) continue; | ||
if (usedIds.has(id)) continue; | ||
usedIds.add(id); | ||
chunk.id = id; | ||
chunk.ids = [id]; | ||
} | ||
} | ||
if (records.chunks.bySource) { | ||
for (const chunk of chunks) { | ||
if (chunk.id !== null) continue; | ||
const sources = getChunkSources(chunk); | ||
for (const source of sources) { | ||
records.chunks.bySource[source] = chunk.id; | ||
} | ||
usedIds.add(chunk.id); | ||
} | ||
records.chunks.usedIds = Array.from(usedIds).sort(compareNumbers); | ||
} | ||
); | ||
compilation.hooks.reviveChunks.tap( | ||
"RecordIdsPlugin", | ||
/** | ||
* @param {Iterable<Chunk>} chunks the chunks array | ||
* @param {Records} records the records object | ||
* @returns {void} | ||
*/ | ||
(chunks, records) => { | ||
if (!records.chunks) return; | ||
/** @type {Set<number>} */ | ||
const usedIds = new Set(); | ||
if (records.chunks.byName) { | ||
for (const chunk of chunks) { | ||
if (chunk.id !== null) continue; | ||
if (!chunk.name) continue; | ||
const id = records.chunks.byName[chunk.name]; | ||
const id = records.chunks.bySource[source]; | ||
if (id === undefined) continue; | ||
@@ -221,24 +205,10 @@ if (usedIds.has(id)) continue; | ||
chunk.ids = [id]; | ||
break; | ||
} | ||
} | ||
if (records.chunks.bySource) { | ||
for (const chunk of chunks) { | ||
if (chunk.id !== null) continue; | ||
const sources = getChunkSources(chunk); | ||
for (const source of sources) { | ||
const id = records.chunks.bySource[source]; | ||
if (id === undefined) continue; | ||
if (usedIds.has(id)) continue; | ||
usedIds.add(id); | ||
chunk.id = id; | ||
chunk.ids = [id]; | ||
break; | ||
} | ||
} | ||
} | ||
if (Array.isArray(records.chunks.usedIds)) { | ||
compilation.usedChunkIds = new Set(records.chunks.usedIds); | ||
} | ||
} | ||
); | ||
if (Array.isArray(records.chunks.usedIds)) { | ||
compilation.usedChunkIds = new Set(records.chunks.usedIds); | ||
} | ||
}); | ||
}); | ||
@@ -245,0 +215,0 @@ } |
@@ -21,2 +21,4 @@ /* | ||
const PLUGIN_NAME = "StartupChunkDependenciesPlugin"; | ||
class StartupChunkDependenciesPlugin { | ||
@@ -40,40 +42,22 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.thisCompilation.tap( | ||
"StartupChunkDependenciesPlugin", | ||
compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk to check | ||
* @returns {boolean} true, when the plugin is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === this.chunkLoading; | ||
}; | ||
compilation.hooks.additionalTreeRuntimeRequirements.tap( | ||
"StartupChunkDependenciesPlugin", | ||
(chunk, set, { chunkGraph }) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) { | ||
set.add(RuntimeGlobals.startup); | ||
set.add(RuntimeGlobals.ensureChunk); | ||
set.add(RuntimeGlobals.ensureChunkIncludeEntries); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new StartupChunkDependenciesRuntimeModule( | ||
this.asyncChunkLoading | ||
) | ||
); | ||
} | ||
} | ||
); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.startupEntrypoint) | ||
.tap("StartupChunkDependenciesPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.require); | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk to check | ||
* @returns {boolean} true, when the plugin is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === this.chunkLoading; | ||
}; | ||
compilation.hooks.additionalTreeRuntimeRequirements.tap( | ||
PLUGIN_NAME, | ||
(chunk, set, { chunkGraph }) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
if (chunkGraph.hasChunkEntryDependentChunks(chunk)) { | ||
set.add(RuntimeGlobals.startup); | ||
set.add(RuntimeGlobals.ensureChunk); | ||
@@ -83,7 +67,20 @@ set.add(RuntimeGlobals.ensureChunkIncludeEntries); | ||
chunk, | ||
new StartupEntrypointRuntimeModule(this.asyncChunkLoading) | ||
new StartupChunkDependenciesRuntimeModule(this.asyncChunkLoading) | ||
); | ||
}); | ||
} | ||
); | ||
} | ||
} | ||
); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.startupEntrypoint) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.require); | ||
set.add(RuntimeGlobals.ensureChunk); | ||
set.add(RuntimeGlobals.ensureChunkIncludeEntries); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new StartupEntrypointRuntimeModule(this.asyncChunkLoading) | ||
); | ||
}); | ||
}); | ||
} | ||
@@ -90,0 +87,0 @@ } |
@@ -104,2 +104,4 @@ /* | ||
const PLUGIN_NAME = "RuntimePlugin"; | ||
class RuntimePlugin { | ||
@@ -111,3 +113,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("RuntimePlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
@@ -133,3 +135,3 @@ /** | ||
.for(req) | ||
.tap("RuntimePlugin", (module, set) => { | ||
.tap(PLUGIN_NAME, (module, set) => { | ||
set.add(RuntimeGlobals.requireScope); | ||
@@ -139,3 +141,3 @@ }); | ||
.for(req) | ||
.tap("RuntimePlugin", (module, set) => { | ||
.tap(PLUGIN_NAME, (module, set) => { | ||
set.add(RuntimeGlobals.requireScope); | ||
@@ -149,3 +151,3 @@ }); | ||
.for(req) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
for (const dep of deps) set.add(dep); | ||
@@ -159,3 +161,3 @@ }); | ||
.for(req) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
for (const dep of deps) set.add(dep); | ||
@@ -166,3 +168,3 @@ }); | ||
.for(RuntimeGlobals.definePropertyGetters) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule( | ||
@@ -176,3 +178,3 @@ chunk, | ||
.for(RuntimeGlobals.makeNamespaceObject) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule( | ||
@@ -186,3 +188,3 @@ chunk, | ||
.for(RuntimeGlobals.createFakeNamespaceObject) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule( | ||
@@ -196,3 +198,3 @@ chunk, | ||
.for(RuntimeGlobals.hasOwnProperty) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule( | ||
@@ -206,3 +208,3 @@ chunk, | ||
.for(RuntimeGlobals.compatGetDefaultExport) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule( | ||
@@ -216,3 +218,3 @@ chunk, | ||
.for(RuntimeGlobals.runtimeId) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule(chunk, new RuntimeIdRuntimeModule()); | ||
@@ -223,3 +225,3 @@ return true; | ||
.for(RuntimeGlobals.publicPath) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
const { outputOptions } = compilation; | ||
@@ -253,3 +255,3 @@ const { publicPath: globalPublicPath, scriptType } = outputOptions; | ||
.for(RuntimeGlobals.global) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule(chunk, new GlobalRuntimeModule()); | ||
@@ -260,3 +262,3 @@ return true; | ||
.for(RuntimeGlobals.asyncModule) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule(chunk, new AsyncModuleRuntimeModule()); | ||
@@ -267,3 +269,3 @@ return true; | ||
.for(RuntimeGlobals.systemContext) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
const entryOptions = chunk.getEntryOptions(); | ||
@@ -286,3 +288,3 @@ const libraryType = | ||
.for(RuntimeGlobals.getChunkScriptFilename) | ||
.tap("RuntimePlugin", (chunk, set, { chunkGraph }) => { | ||
.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => { | ||
if ( | ||
@@ -317,3 +319,3 @@ typeof compilation.outputOptions.chunkFilename === "string" && | ||
.for(RuntimeGlobals.getChunkCssFilename) | ||
.tap("RuntimePlugin", (chunk, set, { chunkGraph }) => { | ||
.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => { | ||
if ( | ||
@@ -343,3 +345,3 @@ typeof compilation.outputOptions.cssChunkFilename === "string" && | ||
.for(RuntimeGlobals.getChunkUpdateScriptFilename) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if ( | ||
@@ -368,3 +370,3 @@ /\[(full)?hash(:\d+)?\]/.test( | ||
.for(RuntimeGlobals.getUpdateManifestFilename) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if ( | ||
@@ -391,3 +393,3 @@ /\[(full)?hash(:\d+)?\]/.test( | ||
.for(RuntimeGlobals.ensureChunk) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
const hasAsyncChunks = chunk.hasAsyncChunks(); | ||
@@ -405,3 +407,3 @@ if (hasAsyncChunks) { | ||
.for(RuntimeGlobals.ensureChunkIncludeEntries) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
set.add(RuntimeGlobals.ensureChunkHandlers); | ||
@@ -411,3 +413,3 @@ }); | ||
.for(RuntimeGlobals.shareScopeMap) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
compilation.addRuntimeModule(chunk, new ShareRuntimeModule()); | ||
@@ -418,3 +420,3 @@ return true; | ||
.for(RuntimeGlobals.loadScript) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
const withCreateScriptUrl = Boolean( | ||
@@ -435,3 +437,3 @@ compilation.outputOptions.trustedTypes | ||
.for(RuntimeGlobals.createScript) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (compilation.outputOptions.trustedTypes) { | ||
@@ -445,3 +447,3 @@ set.add(RuntimeGlobals.getTrustedTypesPolicy); | ||
.for(RuntimeGlobals.createScriptUrl) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (compilation.outputOptions.trustedTypes) { | ||
@@ -458,3 +460,3 @@ set.add(RuntimeGlobals.getTrustedTypesPolicy); | ||
.for(RuntimeGlobals.getTrustedTypesPolicy) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
compilation.addRuntimeModule( | ||
@@ -468,3 +470,3 @@ chunk, | ||
.for(RuntimeGlobals.relativeUrl) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
compilation.addRuntimeModule(chunk, new RelativeUrlRuntimeModule()); | ||
@@ -475,3 +477,3 @@ return true; | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap("RuntimePlugin", (chunk, set) => { | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
compilation.addRuntimeModule( | ||
@@ -485,3 +487,3 @@ chunk, | ||
.for(RuntimeGlobals.baseURI) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
if (isChunkLoadingDisabledForChunk(chunk)) { | ||
@@ -494,3 +496,3 @@ compilation.addRuntimeModule(chunk, new BaseUriRuntimeModule()); | ||
.for(RuntimeGlobals.scriptNonce) | ||
.tap("RuntimePlugin", chunk => { | ||
.tap(PLUGIN_NAME, chunk => { | ||
compilation.addRuntimeModule(chunk, new NonceRuntimeModule()); | ||
@@ -501,3 +503,3 @@ return true; | ||
compilation.hooks.additionalTreeRuntimeRequirements.tap( | ||
"RuntimePlugin", | ||
PLUGIN_NAME, | ||
(chunk, set) => { | ||
@@ -516,3 +518,3 @@ const { mainTemplate } = compilation; | ||
JavascriptModulesPlugin.getCompilationHooks(compilation).chunkHash.tap( | ||
"RuntimePlugin", | ||
PLUGIN_NAME, | ||
(chunk, hash, { chunkGraph }) => { | ||
@@ -519,0 +521,0 @@ const xor = new StringXor(); |
@@ -40,2 +40,4 @@ /* | ||
const PLUGIN_NAME = "DataUriPlugin"; | ||
class DataUriPlugin { | ||
@@ -49,7 +51,7 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"DataUriPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
normalModuleFactory.hooks.resolveForScheme | ||
.for("data") | ||
.tap("DataUriPlugin", resourceData => { | ||
.tap(PLUGIN_NAME, resourceData => { | ||
const match = URIRegEx.exec(resourceData.resource); | ||
@@ -65,3 +67,3 @@ if (match) { | ||
.readResourceForScheme.for("data") | ||
.tap("DataUriPlugin", resource => decodeDataURI(resource)); | ||
.tap(PLUGIN_NAME, resource => decodeDataURI(resource)); | ||
} | ||
@@ -68,0 +70,0 @@ ); |
@@ -13,2 +13,4 @@ /* | ||
const PLUGIN_NAME = "FileUriPlugin"; | ||
class FileUriPlugin { | ||
@@ -22,7 +24,7 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"FileUriPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
normalModuleFactory.hooks.resolveForScheme | ||
.for("file") | ||
.tap("FileUriPlugin", resourceData => { | ||
.tap(PLUGIN_NAME, resourceData => { | ||
const url = new URL(resourceData.resource); | ||
@@ -41,3 +43,3 @@ const path = fileURLToPath(url); | ||
.for(undefined) | ||
.tapAsync("FileUriPlugin", (loaderContext, callback) => { | ||
.tapAsync(PLUGIN_NAME, (loaderContext, callback) => { | ||
const { resourcePath } = loaderContext; | ||
@@ -44,0 +46,0 @@ loaderContext.addDependency(resourcePath); |
@@ -408,2 +408,4 @@ /* | ||
const PLUGIN_NAME = "HttpUriPlugin"; | ||
class HttpUriPlugin { | ||
@@ -444,3 +446,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"HttpUriPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -451,4 +453,4 @@ const intermediateFs = | ||
const fs = compilation.inputFileSystem; | ||
const cache = compilation.getCache("webpack.HttpUriPlugin"); | ||
const logger = compilation.getLogger("webpack.HttpUriPlugin"); | ||
const cache = compilation.getCache(`webpack.${PLUGIN_NAME}`); | ||
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`); | ||
/** @type {string} */ | ||
@@ -1160,15 +1162,12 @@ const lockfileLocation = | ||
.for(scheme) | ||
.tapAsync( | ||
"HttpUriPlugin", | ||
(resourceData, resolveData, callback) => { | ||
respondWithUrlModule( | ||
new URL(resourceData.resource), | ||
resourceData, | ||
callback | ||
); | ||
} | ||
); | ||
.tapAsync(PLUGIN_NAME, (resourceData, resolveData, callback) => { | ||
respondWithUrlModule( | ||
new URL(resourceData.resource), | ||
resourceData, | ||
callback | ||
); | ||
}); | ||
normalModuleFactory.hooks.resolveInScheme | ||
.for(scheme) | ||
.tapAsync("HttpUriPlugin", (resourceData, data, callback) => { | ||
.tapAsync(PLUGIN_NAME, (resourceData, data, callback) => { | ||
// Only handle relative urls (./xxx, ../xxx, /xxx, //xxx) | ||
@@ -1190,3 +1189,3 @@ if ( | ||
.for(scheme) | ||
.tapAsync("HttpUriPlugin", (resource, module, callback) => | ||
.tapAsync(PLUGIN_NAME, (resource, module, callback) => | ||
getInfo(resource, (err, _result) => { | ||
@@ -1200,29 +1199,23 @@ if (err) return callback(err); | ||
); | ||
hooks.needBuild.tapAsync( | ||
"HttpUriPlugin", | ||
(module, context, callback) => { | ||
if ( | ||
module.resource && | ||
module.resource.startsWith(`${scheme}://`) | ||
) { | ||
getInfo(module.resource, (err, _result) => { | ||
if (err) return callback(err); | ||
const result = /** @type {Info} */ (_result); | ||
if ( | ||
result.entry.integrity !== | ||
/** @type {BuildInfo} */ | ||
(module.buildInfo).resourceIntegrity | ||
) { | ||
return callback(null, true); | ||
} | ||
callback(); | ||
}); | ||
} else { | ||
return callback(); | ||
} | ||
hooks.needBuild.tapAsync(PLUGIN_NAME, (module, context, callback) => { | ||
if (module.resource && module.resource.startsWith(`${scheme}://`)) { | ||
getInfo(module.resource, (err, _result) => { | ||
if (err) return callback(err); | ||
const result = /** @type {Info} */ (_result); | ||
if ( | ||
result.entry.integrity !== | ||
/** @type {BuildInfo} */ | ||
(module.buildInfo).resourceIntegrity | ||
) { | ||
return callback(null, true); | ||
} | ||
callback(); | ||
}); | ||
} else { | ||
return callback(); | ||
} | ||
); | ||
}); | ||
} | ||
compilation.hooks.finishModules.tapAsync( | ||
"HttpUriPlugin", | ||
PLUGIN_NAME, | ||
(modules, callback) => { | ||
@@ -1229,0 +1222,0 @@ if (!lockfileUpdates) return callback(); |
@@ -10,2 +10,4 @@ /* | ||
/** @typedef {Error & { cause?: unknown }} ErrorWithCause */ | ||
class ErrorObjectSerializer { | ||
@@ -26,3 +28,6 @@ /** | ||
context.write(obj.stack); | ||
context.write(/** @type {Error & { cause: "unknown" }} */ (obj).cause); | ||
context.write( | ||
/** @type {ErrorWithCause} */ | ||
(obj).cause | ||
); | ||
} | ||
@@ -39,3 +44,3 @@ | ||
err.stack = context.read(); | ||
/** @type {Error & { cause: "unknown" }} */ | ||
/** @type {ErrorWithCause} */ | ||
(err).cause = context.read(); | ||
@@ -42,0 +47,0 @@ |
@@ -9,2 +9,3 @@ /* | ||
const createHash = require("../util/createHash"); | ||
const AggregateErrorSerializer = require("./AggregateErrorSerializer"); | ||
const ArraySerializer = require("./ArraySerializer"); | ||
@@ -144,2 +145,3 @@ const DateObjectSerializer = require("./DateObjectSerializer"); | ||
const jsTypes = new Map(); | ||
jsTypes.set(Object, new PlainObjectSerializer()); | ||
@@ -159,2 +161,13 @@ jsTypes.set(Array, new ArraySerializer()); | ||
// @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers | ||
// eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax | ||
if (typeof AggregateError !== "undefined") { | ||
jsTypes.set( | ||
// @ts-expect-error ES2018 doesn't `AggregateError`, but it can be used by developers | ||
// eslint-disable-next-line n/no-unsupported-features/es-builtins, n/no-unsupported-features/es-syntax | ||
AggregateError, | ||
new AggregateErrorSerializer() | ||
); | ||
} | ||
// If in a sandboxed environment (e.g. jest), this escapes the sandbox and registers | ||
@@ -161,0 +174,0 @@ // real Object and Array types to. These types may occur in the wild too, e.g. when |
@@ -39,2 +39,4 @@ /* | ||
const PLUGIN_NAME = "ProvideSharedPlugin"; | ||
class ProvideSharedPlugin { | ||
@@ -87,3 +89,3 @@ /** | ||
compiler.hooks.compilation.tap( | ||
"ProvideSharedPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -161,3 +163,3 @@ /** @type {ResolvedProvideMap} */ | ||
normalModuleFactory.hooks.module.tap( | ||
"ProvideSharedPlugin", | ||
PLUGIN_NAME, | ||
(module, { resource, resourceResolveData }, resolveData) => { | ||
@@ -200,3 +202,3 @@ if (resolvedProvideMap.has(/** @type {string} */ (resource))) { | ||
); | ||
compiler.hooks.finishMake.tapPromise("ProvideSharedPlugin", compilation => { | ||
compiler.hooks.finishMake.tapPromise(PLUGIN_NAME, compilation => { | ||
const resolvedProvideMap = compilationData.get(compilation); | ||
@@ -232,3 +234,3 @@ if (!resolvedProvideMap) return Promise.resolve(); | ||
compiler.hooks.compilation.tap( | ||
"ProvideSharedPlugin", | ||
PLUGIN_NAME, | ||
(compilation, { normalModuleFactory }) => { | ||
@@ -235,0 +237,0 @@ compilation.dependencyFactories.set( |
@@ -134,2 +134,4 @@ /* | ||
const PLUGIN_NAME = "SourceMapDevToolPlugin"; | ||
class SourceMapDevToolPlugin { | ||
@@ -182,3 +184,3 @@ /** | ||
compiler.hooks.compilation.tap("SourceMapDevToolPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
new SourceMapDevToolModuleOptionsPlugin(options).apply(compilation); | ||
@@ -188,3 +190,3 @@ | ||
{ | ||
name: "SourceMapDevToolPlugin", | ||
name: PLUGIN_NAME, | ||
stage: Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING, | ||
@@ -195,3 +197,3 @@ additionalAssets: true | ||
const chunkGraph = compilation.chunkGraph; | ||
const cache = compilation.getCache("SourceMapDevToolPlugin"); | ||
const cache = compilation.getCache(PLUGIN_NAME); | ||
/** @type {Map<string | Module, string>} */ | ||
@@ -559,3 +561,3 @@ const moduleToSourceNameMapping = new Map(); | ||
throw new Error( | ||
"SourceMapDevToolPlugin: append can't be false when no filename is provided" | ||
`${PLUGIN_NAME}: append can't be false when no filename is provided` | ||
); | ||
@@ -565,3 +567,3 @@ } | ||
throw new Error( | ||
"SourceMapDevToolPlugin: append can't be a function when no filename is provided" | ||
`${PLUGIN_NAME}: append can't be a function when no filename is provided` | ||
); | ||
@@ -568,0 +570,0 @@ } |
@@ -58,2 +58,4 @@ /* | ||
errorStack: true, | ||
errorCause: true, | ||
errorErrors: true, | ||
publicPath: true, | ||
@@ -88,2 +90,4 @@ logging: "verbose", | ||
errorDetails: true, | ||
errorCause: true, | ||
errorErrors: true, | ||
publicPath: true, | ||
@@ -265,2 +269,4 @@ logging: true, | ||
errorStack: OFF_FOR_TO_STRING, | ||
errorCause: AUTO_FOR_TO_STRING, | ||
errorErrors: AUTO_FOR_TO_STRING, | ||
warnings: NORMAL_ON, | ||
@@ -370,2 +376,4 @@ warningsCount: NORMAL_ON, | ||
const PLUGIN_NAME = "DefaultStatsPresetPlugin"; | ||
class DefaultStatsPresetPlugin { | ||
@@ -378,3 +386,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("DefaultStatsPresetPlugin", compilation => { | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
for (const key of Object.keys(NAMED_PRESETS)) { | ||
@@ -384,26 +392,23 @@ const defaults = NAMED_PRESETS[/** @type {keyof NamedPresets} */ (key)]; | ||
.for(key) | ||
.tap("DefaultStatsPresetPlugin", (options, context) => { | ||
.tap(PLUGIN_NAME, (options, context) => { | ||
applyDefaults(options, defaults); | ||
}); | ||
} | ||
compilation.hooks.statsNormalize.tap( | ||
"DefaultStatsPresetPlugin", | ||
(options, context) => { | ||
for (const key of Object.keys(DEFAULTS)) { | ||
if (options[key] === undefined) | ||
options[key] = | ||
/** @type {Defaults[DefaultsKeys]} */ | ||
(DEFAULTS[/** @type {DefaultsKeys} */ (key)])( | ||
options, | ||
context, | ||
compilation | ||
); | ||
} | ||
for (const key of Object.keys(NORMALIZER)) { | ||
compilation.hooks.statsNormalize.tap(PLUGIN_NAME, (options, context) => { | ||
for (const key of Object.keys(DEFAULTS)) { | ||
if (options[key] === undefined) | ||
options[key] = | ||
/** @type {TODO} */ | ||
(NORMALIZER[/** @type {NormalizerKeys} */ (key)])(options[key]); | ||
} | ||
/** @type {Defaults[DefaultsKeys]} */ | ||
(DEFAULTS[/** @type {DefaultsKeys} */ (key)])( | ||
options, | ||
context, | ||
compilation | ||
); | ||
} | ||
); | ||
for (const key of Object.keys(NORMALIZER)) { | ||
options[key] = | ||
/** @type {TODO} */ | ||
(NORMALIZER[/** @type {NormalizerKeys} */ (key)])(options[key]); | ||
} | ||
}); | ||
}); | ||
@@ -410,0 +415,0 @@ } |
@@ -822,2 +822,12 @@ /* | ||
"error.stack": stack => stack, | ||
"error.cause": (cause, context, printer) => | ||
cause | ||
? indent( | ||
`[cause]: ${ | ||
/** @type {string} */ | ||
(printer.print(`${context.type}.error`, cause, context)) | ||
}`, | ||
" " | ||
) | ||
: undefined, | ||
"error.moduleTrace": moduleTrace => undefined, | ||
@@ -929,2 +939,3 @@ "error.separator!": () => "\n" | ||
"error.moduleTrace[]": "moduleTraceItem", | ||
"error.errors[]": "error", | ||
"moduleTraceItem.dependencies[]": "moduleTraceDependency" | ||
@@ -951,2 +962,4 @@ }; | ||
"separator!", | ||
"cause", | ||
"separator!", | ||
"missing", | ||
@@ -1394,24 +1407,2 @@ "separator!", | ||
chunkGroupChild: joinOneLine, | ||
// moduleReason: (items, { moduleReason }) => { | ||
// let hasName = false; | ||
// return joinOneLine( | ||
// items.filter(item => { | ||
// switch (item.element) { | ||
// case "moduleId": | ||
// if (moduleReason.moduleId === moduleReason.module && item.content) | ||
// hasName = true; | ||
// break; | ||
// case "module": | ||
// if (hasName) return false; | ||
// break; | ||
// case "resolvedModule": | ||
// return ( | ||
// moduleReason.module !== moduleReason.resolvedModule && | ||
// item.content | ||
// ); | ||
// } | ||
// return true; | ||
// }) | ||
// ); | ||
// }, | ||
moduleReason: (items, { moduleReason }) => { | ||
@@ -1452,2 +1443,5 @@ let hasName = false; | ||
"warnings[].error": joinError(false), | ||
error: items => joinExplicitNewLine(items, ""), | ||
"error.errors[].error": items => | ||
indent(`[errors]: ${joinExplicitNewLine(items, "")}`, " "), | ||
loggingGroup: items => joinExplicitNewLine(items, "").trimEnd(), | ||
@@ -1593,2 +1587,4 @@ moduleTraceItem: items => ` @ ${joinOneLine(items)}`, | ||
const PLUGIN_NAME = "DefaultStatsPrinterPlugin"; | ||
class DefaultStatsPrinterPlugin { | ||
@@ -1601,328 +1597,297 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("DefaultStatsPrinterPlugin", compilation => { | ||
compilation.hooks.statsPrinter.tap( | ||
"DefaultStatsPrinterPlugin", | ||
(stats, options) => { | ||
// Put colors into context | ||
stats.hooks.print | ||
.for("compilation") | ||
.tap("DefaultStatsPrinterPlugin", (compilation, context) => { | ||
for (const color of Object.keys(AVAILABLE_COLORS)) { | ||
const name = | ||
/** @type {keyof KnownStatsPrinterColorFunctions} */ | ||
(color); | ||
/** @type {string | undefined} */ | ||
let start; | ||
if (options.colors) { | ||
if ( | ||
typeof options.colors === "object" && | ||
typeof options.colors[name] === "string" | ||
) { | ||
start = options.colors[name]; | ||
} else { | ||
start = AVAILABLE_COLORS[name]; | ||
} | ||
} | ||
if (start) { | ||
/** @type {ColorFunction} */ | ||
context[color] = str => | ||
`${start}${ | ||
typeof str === "string" | ||
? str.replace( | ||
/((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g, | ||
`$1${start}` | ||
) | ||
: str | ||
}\u001B[39m\u001B[22m`; | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.statsPrinter.tap(PLUGIN_NAME, (stats, options) => { | ||
// Put colors into context | ||
stats.hooks.print | ||
.for("compilation") | ||
.tap(PLUGIN_NAME, (compilation, context) => { | ||
for (const color of Object.keys(AVAILABLE_COLORS)) { | ||
const name = | ||
/** @type {keyof KnownStatsPrinterColorFunctions} */ | ||
(color); | ||
/** @type {string | undefined} */ | ||
let start; | ||
if (options.colors) { | ||
if ( | ||
typeof options.colors === "object" && | ||
typeof options.colors[name] === "string" | ||
) { | ||
start = options.colors[name]; | ||
} else { | ||
/** | ||
* @param {string} str string | ||
* @returns {string} str string | ||
*/ | ||
context[color] = str => str; | ||
start = AVAILABLE_COLORS[name]; | ||
} | ||
} | ||
for (const format of Object.keys(AVAILABLE_FORMATS)) { | ||
context[format] = | ||
/** | ||
* @param {string | number} content content | ||
* @param {...TODO} args args | ||
* @returns {string} result | ||
*/ | ||
(content, ...args) => | ||
/** @type {TODO} */ | ||
( | ||
AVAILABLE_FORMATS[ | ||
/** @type {keyof AvailableFormats} */ | ||
(format) | ||
] | ||
)( | ||
content, | ||
/** @type {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions>} */ | ||
(context), | ||
...args | ||
); | ||
if (start) { | ||
/** @type {ColorFunction} */ | ||
context[color] = str => | ||
`${start}${ | ||
typeof str === "string" | ||
? str.replace( | ||
/((\u001B\[39m|\u001B\[22m|\u001B\[0m)+)/g, | ||
`$1${start}` | ||
) | ||
: str | ||
}\u001B[39m\u001B[22m`; | ||
} else { | ||
/** | ||
* @param {string} str string | ||
* @returns {string} str string | ||
*/ | ||
context[color] = str => str; | ||
} | ||
context.timeReference = compilation.time; | ||
}); | ||
} | ||
for (const format of Object.keys(AVAILABLE_FORMATS)) { | ||
context[format] = | ||
/** | ||
* @param {string | number} content content | ||
* @param {...TODO} args args | ||
* @returns {string} result | ||
*/ | ||
(content, ...args) => | ||
/** @type {TODO} */ | ||
( | ||
AVAILABLE_FORMATS[ | ||
/** @type {keyof AvailableFormats} */ | ||
(format) | ||
] | ||
)( | ||
content, | ||
/** @type {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions>} */ | ||
(context), | ||
...args | ||
); | ||
} | ||
context.timeReference = compilation.time; | ||
}); | ||
for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
COMPILATION_SIMPLE_PRINTERS[ | ||
/** @type {keyof CompilationSimplePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"compilation">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(COMPILATION_SIMPLE_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
COMPILATION_SIMPLE_PRINTERS[ | ||
/** @type {keyof CompilationSimplePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"compilation">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(ASSET_SIMPLE_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {NonNullable<AssetSimplePrinters[keyof AssetSimplePrinters]>} */ | ||
( | ||
ASSET_SIMPLE_PRINTERS[ | ||
/** @type {keyof AssetSimplePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"asset" | "asset.info">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(ASSET_SIMPLE_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {NonNullable<AssetSimplePrinters[keyof AssetSimplePrinters]>} */ | ||
( | ||
ASSET_SIMPLE_PRINTERS[ | ||
/** @type {keyof AssetSimplePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"asset" | "asset.info">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_SIMPLE_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
MODULE_SIMPLE_PRINTERS[ | ||
/** @type {keyof ModuleSimplePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"module">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_SIMPLE_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
MODULE_SIMPLE_PRINTERS[ | ||
/** @type {keyof ModuleSimplePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"module">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_ISSUER_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {NonNullable<ModuleIssuerPrinters[keyof ModuleIssuerPrinters]>} */ | ||
( | ||
MODULE_ISSUER_PRINTERS[ | ||
/** @type {keyof ModuleIssuerPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleIssuer">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_ISSUER_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {NonNullable<ModuleIssuerPrinters[keyof ModuleIssuerPrinters]>} */ | ||
( | ||
MODULE_ISSUER_PRINTERS[ | ||
/** @type {keyof ModuleIssuerPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleIssuer">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_REASON_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
MODULE_REASON_PRINTERS[ | ||
/** @type {keyof ModuleReasonsPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleReason">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_REASON_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
MODULE_REASON_PRINTERS[ | ||
/** @type {keyof ModuleReasonsPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleReason">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_PROFILE_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {NonNullable<ModuleProfilePrinters[keyof ModuleProfilePrinters]>} */ | ||
( | ||
MODULE_PROFILE_PRINTERS[ | ||
/** @type {keyof ModuleProfilePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"profile">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_PROFILE_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {NonNullable<ModuleProfilePrinters[keyof ModuleProfilePrinters]>} */ | ||
( | ||
MODULE_PROFILE_PRINTERS[ | ||
/** @type {keyof ModuleProfilePrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"profile">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(CHUNK_GROUP_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
CHUNK_GROUP_PRINTERS[ | ||
/** @type {keyof ChunkGroupPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(CHUNK_GROUP_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
CHUNK_GROUP_PRINTERS[ | ||
/** @type {keyof ChunkGroupPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"chunkGroupKind" | "chunkGroup">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(CHUNK_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {TODO} */ | ||
(CHUNK_PRINTERS[/** @type {keyof ChunkPrinters} */ (key)])( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"chunk">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(CHUNK_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {TODO} */ | ||
(CHUNK_PRINTERS[/** @type {keyof ChunkPrinters} */ (key)])( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"chunk">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(ERROR_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {TODO} */ | ||
(ERROR_PRINTERS[/** @type {keyof ErrorPrinters} */ (key)])( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"error">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(ERROR_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {TODO} */ | ||
(ERROR_PRINTERS[/** @type {keyof ErrorPrinters} */ (key)])( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"error">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(LOG_ENTRY_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
LOG_ENTRY_PRINTERS[ | ||
/** @type {keyof LogEntryPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"logging">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(LOG_ENTRY_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {TODO} */ | ||
( | ||
LOG_ENTRY_PRINTERS[ | ||
/** @type {keyof LogEntryPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"logging">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {NonNullable<ModuleTraceDependencyPrinters[keyof ModuleTraceDependencyPrinters]>} */ | ||
( | ||
MODULE_TRACE_DEPENDENCY_PRINTERS[ | ||
/** @type {keyof ModuleTraceDependencyPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleTraceDependency">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_TRACE_DEPENDENCY_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {NonNullable<ModuleTraceDependencyPrinters[keyof ModuleTraceDependencyPrinters]>} */ | ||
( | ||
MODULE_TRACE_DEPENDENCY_PRINTERS[ | ||
/** @type {keyof ModuleTraceDependencyPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleTraceDependency">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_TRACE_ITEM_PRINTERS)) { | ||
stats.hooks.print | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (obj, ctx) => | ||
/** @type {NonNullable<ModuleTraceItemPrinters[keyof ModuleTraceItemPrinters]>} */ | ||
( | ||
MODULE_TRACE_ITEM_PRINTERS[ | ||
/** @type {keyof ModuleTraceItemPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleTraceItem">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(MODULE_TRACE_ITEM_PRINTERS)) { | ||
stats.hooks.print.for(key).tap(PLUGIN_NAME, (obj, ctx) => | ||
/** @type {NonNullable<ModuleTraceItemPrinters[keyof ModuleTraceItemPrinters]>} */ | ||
( | ||
MODULE_TRACE_ITEM_PRINTERS[ | ||
/** @type {keyof ModuleTraceItemPrinters} */ | ||
(key) | ||
] | ||
)( | ||
obj, | ||
/** @type {DefineStatsPrinterContext<"moduleTraceItem">} */ | ||
(ctx), | ||
stats | ||
) | ||
); | ||
} | ||
for (const key of Object.keys(PREFERRED_ORDERS)) { | ||
const preferredOrder = PREFERRED_ORDERS[key]; | ||
stats.hooks.sortElements | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", (elements, context) => { | ||
createOrder(elements, preferredOrder); | ||
}); | ||
} | ||
for (const key of Object.keys(PREFERRED_ORDERS)) { | ||
const preferredOrder = PREFERRED_ORDERS[key]; | ||
stats.hooks.sortElements | ||
.for(key) | ||
.tap(PLUGIN_NAME, (elements, context) => { | ||
createOrder(elements, preferredOrder); | ||
}); | ||
} | ||
for (const key of Object.keys(ITEM_NAMES)) { | ||
const itemName = ITEM_NAMES[key]; | ||
stats.hooks.getItemName | ||
.for(key) | ||
.tap( | ||
"DefaultStatsPrinterPlugin", | ||
typeof itemName === "string" ? () => itemName : itemName | ||
); | ||
} | ||
for (const key of Object.keys(ITEM_NAMES)) { | ||
const itemName = ITEM_NAMES[key]; | ||
stats.hooks.getItemName | ||
.for(key) | ||
.tap( | ||
PLUGIN_NAME, | ||
typeof itemName === "string" ? () => itemName : itemName | ||
); | ||
} | ||
for (const key of Object.keys(SIMPLE_ITEMS_JOINER)) { | ||
const joiner = SIMPLE_ITEMS_JOINER[key]; | ||
stats.hooks.printItems | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", joiner); | ||
} | ||
for (const key of Object.keys(SIMPLE_ITEMS_JOINER)) { | ||
const joiner = SIMPLE_ITEMS_JOINER[key]; | ||
stats.hooks.printItems.for(key).tap(PLUGIN_NAME, joiner); | ||
} | ||
for (const key of Object.keys(SIMPLE_ELEMENT_JOINERS)) { | ||
const joiner = SIMPLE_ELEMENT_JOINERS[key]; | ||
stats.hooks.printElements | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", /** @type {TODO} */ (joiner)); | ||
} | ||
for (const key of Object.keys(SIMPLE_ELEMENT_JOINERS)) { | ||
const joiner = SIMPLE_ELEMENT_JOINERS[key]; | ||
stats.hooks.printElements | ||
.for(key) | ||
.tap(PLUGIN_NAME, /** @type {TODO} */ (joiner)); | ||
} | ||
for (const key of Object.keys(RESULT_MODIFIER)) { | ||
const modifier = RESULT_MODIFIER[key]; | ||
stats.hooks.result | ||
.for(key) | ||
.tap("DefaultStatsPrinterPlugin", modifier); | ||
} | ||
for (const key of Object.keys(RESULT_MODIFIER)) { | ||
const modifier = RESULT_MODIFIER[key]; | ||
stats.hooks.result.for(key).tap(PLUGIN_NAME, modifier); | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -1929,0 +1894,0 @@ } |
@@ -201,7 +201,9 @@ /* | ||
/** @typedef {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} ScopeInfo */ | ||
/** | ||
* @param {Map<string, { usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }>} usedNamesInScopeInfo used names in scope info | ||
* @param {Map<string, ScopeInfo>} usedNamesInScopeInfo used names in scope info | ||
* @param {string} module module identifier | ||
* @param {string} id export id | ||
* @returns {{ usedNames: UsedNames, alreadyCheckedScopes: ScopeSet }} info | ||
* @returns {ScopeInfo} info | ||
*/ | ||
@@ -208,0 +210,0 @@ const getUsedNamesInScopeInfo = (usedNamesInScopeInfo, module, id) => { |
@@ -14,2 +14,4 @@ /* | ||
const PLUGIN_NAME = "WarnCaseSensitiveModulesPlugin"; | ||
class WarnCaseSensitiveModulesPlugin { | ||
@@ -22,43 +24,40 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap( | ||
"WarnCaseSensitiveModulesPlugin", | ||
compilation => { | ||
compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => { | ||
/** @type {Map<string, Map<string, Module>>} */ | ||
const moduleWithoutCase = new Map(); | ||
for (const module of compilation.modules) { | ||
const identifier = module.identifier(); | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.seal.tap(PLUGIN_NAME, () => { | ||
/** @type {Map<string, Map<string, Module>>} */ | ||
const moduleWithoutCase = new Map(); | ||
for (const module of compilation.modules) { | ||
const identifier = module.identifier(); | ||
// Ignore `data:` URLs, because it's not a real path | ||
if ( | ||
/** @type {NormalModule} */ | ||
(module).resourceResolveData !== undefined && | ||
/** @type {NormalModule} */ | ||
(module).resourceResolveData.encodedContent !== undefined | ||
) { | ||
continue; | ||
} | ||
// Ignore `data:` URLs, because it's not a real path | ||
if ( | ||
/** @type {NormalModule} */ | ||
(module).resourceResolveData !== undefined && | ||
/** @type {NormalModule} */ | ||
(module).resourceResolveData.encodedContent !== undefined | ||
) { | ||
continue; | ||
} | ||
const lowerIdentifier = identifier.toLowerCase(); | ||
let map = moduleWithoutCase.get(lowerIdentifier); | ||
if (map === undefined) { | ||
map = new Map(); | ||
moduleWithoutCase.set(lowerIdentifier, map); | ||
} | ||
map.set(identifier, module); | ||
const lowerIdentifier = identifier.toLowerCase(); | ||
let map = moduleWithoutCase.get(lowerIdentifier); | ||
if (map === undefined) { | ||
map = new Map(); | ||
moduleWithoutCase.set(lowerIdentifier, map); | ||
} | ||
for (const pair of moduleWithoutCase) { | ||
const map = pair[1]; | ||
if (map.size > 1) { | ||
compilation.warnings.push( | ||
new CaseSensitiveModulesWarning( | ||
map.values(), | ||
compilation.moduleGraph | ||
) | ||
); | ||
} | ||
map.set(identifier, module); | ||
} | ||
for (const pair of moduleWithoutCase) { | ||
const map = pair[1]; | ||
if (map.size > 1) { | ||
compilation.warnings.push( | ||
new CaseSensitiveModulesWarning( | ||
map.values(), | ||
compilation.moduleGraph | ||
) | ||
); | ||
} | ||
}); | ||
} | ||
); | ||
} | ||
}); | ||
}); | ||
} | ||
@@ -65,0 +64,0 @@ } |
@@ -12,2 +12,4 @@ /* | ||
const PLUGIN_NAME = "WarnNoModeSetPlugin"; | ||
class WarnNoModeSetPlugin { | ||
@@ -20,3 +22,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.thisCompilation.tap("WarnNoModeSetPlugin", compilation => { | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.warnings.push(new NoModeWarning()); | ||
@@ -23,0 +25,0 @@ }); |
@@ -16,2 +16,4 @@ /* | ||
const PLUGIN_NAME = "WasmFinalizeExportsPlugin"; | ||
class WasmFinalizeExportsPlugin { | ||
@@ -24,61 +26,57 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.compilation.tap("WasmFinalizeExportsPlugin", compilation => { | ||
compilation.hooks.finishModules.tap( | ||
"WasmFinalizeExportsPlugin", | ||
modules => { | ||
for (const module of modules) { | ||
// 1. if a WebAssembly module | ||
if (module.type.startsWith("webassembly") === true) { | ||
const jsIncompatibleExports = | ||
/** @type {BuildMeta} */ | ||
(module.buildMeta).jsIncompatibleExports; | ||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => { | ||
compilation.hooks.finishModules.tap(PLUGIN_NAME, modules => { | ||
for (const module of modules) { | ||
// 1. if a WebAssembly module | ||
if (module.type.startsWith("webassembly") === true) { | ||
const jsIncompatibleExports = | ||
/** @type {BuildMeta} */ | ||
(module.buildMeta).jsIncompatibleExports; | ||
if (jsIncompatibleExports === undefined) { | ||
continue; | ||
} | ||
if (jsIncompatibleExports === undefined) { | ||
continue; | ||
} | ||
for (const connection of compilation.moduleGraph.getIncomingConnections( | ||
module | ||
)) { | ||
// 2. is active and referenced by a non-WebAssembly module | ||
if ( | ||
connection.isTargetActive(undefined) && | ||
/** @type {Module} */ | ||
(connection.originModule).type.startsWith("webassembly") === | ||
false | ||
) { | ||
const referencedExports = | ||
compilation.getDependencyReferencedExports( | ||
/** @type {Dependency} */ (connection.dependency), | ||
undefined | ||
for (const connection of compilation.moduleGraph.getIncomingConnections( | ||
module | ||
)) { | ||
// 2. is active and referenced by a non-WebAssembly module | ||
if ( | ||
connection.isTargetActive(undefined) && | ||
/** @type {Module} */ | ||
(connection.originModule).type.startsWith("webassembly") === | ||
false | ||
) { | ||
const referencedExports = | ||
compilation.getDependencyReferencedExports( | ||
/** @type {Dependency} */ (connection.dependency), | ||
undefined | ||
); | ||
for (const info of referencedExports) { | ||
const names = Array.isArray(info) ? info : info.name; | ||
if (names.length === 0) continue; | ||
const name = names[0]; | ||
if (typeof name === "object") continue; | ||
// 3. and uses a func with an incompatible JS signature | ||
if ( | ||
Object.prototype.hasOwnProperty.call( | ||
jsIncompatibleExports, | ||
name | ||
) | ||
) { | ||
// 4. error | ||
const error = new UnsupportedWebAssemblyFeatureError( | ||
`Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` + | ||
`It's used from ${ | ||
/** @type {Module} */ | ||
(connection.originModule).readableIdentifier( | ||
compilation.requestShortener | ||
) | ||
} at ${formatLocation( | ||
/** @type {Dependency} */ (connection.dependency).loc | ||
)}.` | ||
); | ||
for (const info of referencedExports) { | ||
const names = Array.isArray(info) ? info : info.name; | ||
if (names.length === 0) continue; | ||
const name = names[0]; | ||
if (typeof name === "object") continue; | ||
// 3. and uses a func with an incompatible JS signature | ||
if ( | ||
Object.prototype.hasOwnProperty.call( | ||
jsIncompatibleExports, | ||
name | ||
) | ||
) { | ||
// 4. error | ||
const error = new UnsupportedWebAssemblyFeatureError( | ||
`Export "${name}" with ${jsIncompatibleExports[name]} can only be used for direct wasm to wasm dependencies\n` + | ||
`It's used from ${ | ||
/** @type {Module} */ | ||
(connection.originModule).readableIdentifier( | ||
compilation.requestShortener | ||
) | ||
} at ${formatLocation( | ||
/** @type {Dependency} */ (connection.dependency) | ||
.loc | ||
)}.` | ||
); | ||
error.module = module; | ||
compilation.errors.push(error); | ||
} | ||
error.module = module; | ||
compilation.errors.push(error); | ||
} | ||
@@ -90,3 +88,3 @@ } | ||
} | ||
); | ||
}); | ||
}); | ||
@@ -93,0 +91,0 @@ } |
@@ -128,2 +128,4 @@ /* | ||
const PLUGIN_NAME = "WatchIgnorePlugin"; | ||
class WatchIgnorePlugin { | ||
@@ -144,3 +146,3 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => { | ||
compiler.hooks.afterEnvironment.tap(PLUGIN_NAME, () => { | ||
compiler.watchFileSystem = new IgnoringWatchFileSystem( | ||
@@ -147,0 +149,0 @@ /** @type {WatchFileSystem} */ |
@@ -14,2 +14,4 @@ /* | ||
const PLUGIN_NAME = "JsonpChunkLoadingPlugin"; | ||
class JsonpChunkLoadingPlugin { | ||
@@ -22,78 +24,75 @@ /** | ||
apply(compiler) { | ||
compiler.hooks.thisCompilation.tap( | ||
"JsonpChunkLoadingPlugin", | ||
compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @returns {boolean} true, if wasm loading is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === "jsonp"; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @returns {boolean} true, if wasm loading is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === "jsonp"; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new JsonpChunkLoadingRuntimeModule(set) | ||
); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.loadScript); | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.loadScript); | ||
set.add(RuntimeGlobals.getChunkUpdateScriptFilename); | ||
set.add(RuntimeGlobals.moduleCache); | ||
set.add(RuntimeGlobals.hmrModuleData); | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new JsonpChunkLoadingRuntimeModule(set) | ||
); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("JsonpChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap("JsonpChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap("JsonpChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap("JsonpChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap("JsonpChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("JsonpChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.loadScript); | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap("JsonpChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.loadScript); | ||
set.add(RuntimeGlobals.getChunkUpdateScriptFilename); | ||
set.add(RuntimeGlobals.moduleCache); | ||
set.add(RuntimeGlobals.hmrModuleData); | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap("JsonpChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getUpdateManifestFilename); | ||
}); | ||
} | ||
); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getUpdateManifestFilename); | ||
}); | ||
}); | ||
} | ||
@@ -100,0 +99,0 @@ } |
@@ -21,5 +21,7 @@ /* | ||
* @param {string=} message error message | ||
* @param {{ cause?: unknown }} options error options | ||
*/ | ||
constructor(message) { | ||
super(message); | ||
constructor(message, options = {}) { | ||
// @ts-expect-error ES2018 doesn't `Error.cause`, but it can be used by developers | ||
super(message, options); | ||
@@ -41,3 +43,7 @@ /** @type {string=} */ | ||
[inspect]() { | ||
return this.stack + (this.details ? `\n${this.details}` : ""); | ||
return ( | ||
this.stack + | ||
(this.details ? `\n${this.details}` : "") + | ||
(this.cause ? `\n${this.cause}` : "") | ||
); | ||
} | ||
@@ -52,2 +58,3 @@ | ||
write(this.stack); | ||
write(this.cause); | ||
write(this.details); | ||
@@ -65,2 +72,3 @@ write(this.loc); | ||
this.stack = read(); | ||
this.cause = read(); | ||
this.details = read(); | ||
@@ -67,0 +75,0 @@ this.loc = read(); |
@@ -66,2 +66,4 @@ /* | ||
const CLASS_NAME = "WebpackOptionsApply"; | ||
class WebpackOptionsApply extends OptionsApply { | ||
@@ -768,3 +770,3 @@ constructor() { | ||
.for("normal") | ||
.tap("WebpackOptionsApply", resolveOptions => { | ||
.tap(CLASS_NAME, resolveOptions => { | ||
resolveOptions = cleverMerge(options.resolve, resolveOptions); | ||
@@ -778,3 +780,3 @@ resolveOptions.fileSystem = | ||
.for("context") | ||
.tap("WebpackOptionsApply", resolveOptions => { | ||
.tap(CLASS_NAME, resolveOptions => { | ||
resolveOptions = cleverMerge(options.resolve, resolveOptions); | ||
@@ -789,3 +791,3 @@ resolveOptions.fileSystem = | ||
.for("loader") | ||
.tap("WebpackOptionsApply", resolveOptions => { | ||
.tap(CLASS_NAME, resolveOptions => { | ||
resolveOptions = cleverMerge(options.resolveLoader, resolveOptions); | ||
@@ -792,0 +794,0 @@ resolveOptions.fileSystem = |
@@ -15,2 +15,4 @@ /* | ||
const PLUGIN_NAME = "ImportScriptsChunkLoadingPlugin"; | ||
class ImportScriptsChunkLoadingPlugin { | ||
@@ -27,84 +29,81 @@ /** | ||
}).apply(compiler); | ||
compiler.hooks.thisCompilation.tap( | ||
"ImportScriptsChunkLoadingPlugin", | ||
compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @returns {boolean} true, if wasm loading is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === "import-scripts"; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => { | ||
const globalChunkLoading = compilation.outputOptions.chunkLoading; | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @returns {boolean} true, if wasm loading is enabled for the chunk | ||
*/ | ||
const isEnabledForChunk = chunk => { | ||
const options = chunk.getEntryOptions(); | ||
const chunkLoading = | ||
options && options.chunkLoading !== undefined | ||
? options.chunkLoading | ||
: globalChunkLoading; | ||
return chunkLoading === "import-scripts"; | ||
}; | ||
const onceForChunkSet = new WeakSet(); | ||
/** | ||
* @param {Chunk} chunk chunk | ||
* @param {Set<string>} set runtime requirements | ||
*/ | ||
const handler = (chunk, set) => { | ||
if (onceForChunkSet.has(chunk)) return; | ||
onceForChunkSet.add(chunk); | ||
if (!isEnabledForChunk(chunk)) return; | ||
const withCreateScriptUrl = Boolean( | ||
compilation.outputOptions.trustedTypes | ||
); | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
if (withCreateScriptUrl) { | ||
set.add(RuntimeGlobals.createScriptUrl); | ||
} | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ImportScriptsChunkLoadingRuntimeModule(set, withCreateScriptUrl) | ||
); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap(PLUGIN_NAME, handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
const withCreateScriptUrl = Boolean( | ||
compilation.outputOptions.trustedTypes | ||
); | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getChunkUpdateScriptFilename); | ||
set.add(RuntimeGlobals.moduleCache); | ||
set.add(RuntimeGlobals.hmrModuleData); | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
set.add(RuntimeGlobals.hasOwnProperty); | ||
if (withCreateScriptUrl) { | ||
set.add(RuntimeGlobals.createScriptUrl); | ||
} | ||
compilation.addRuntimeModule( | ||
chunk, | ||
new ImportScriptsChunkLoadingRuntimeModule(set, withCreateScriptUrl) | ||
); | ||
}; | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("ImportScriptsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap("ImportScriptsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap("ImportScriptsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.baseURI) | ||
.tap("ImportScriptsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.onChunksLoaded) | ||
.tap("ImportScriptsChunkLoadingPlugin", handler); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.ensureChunkHandlers) | ||
.tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getChunkScriptFilename); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadUpdateHandlers) | ||
.tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getChunkUpdateScriptFilename); | ||
set.add(RuntimeGlobals.moduleCache); | ||
set.add(RuntimeGlobals.hmrModuleData); | ||
set.add(RuntimeGlobals.moduleFactoriesAddOnly); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap("ImportScriptsChunkLoadingPlugin", (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getUpdateManifestFilename); | ||
}); | ||
} | ||
); | ||
}); | ||
compilation.hooks.runtimeRequirementInTree | ||
.for(RuntimeGlobals.hmrDownloadManifest) | ||
.tap(PLUGIN_NAME, (chunk, set) => { | ||
if (!isEnabledForChunk(chunk)) return; | ||
set.add(RuntimeGlobals.publicPath); | ||
set.add(RuntimeGlobals.getUpdateManifestFilename); | ||
}); | ||
}); | ||
} | ||
} | ||
module.exports = ImportScriptsChunkLoadingPlugin; |
{ | ||
"name": "webpack", | ||
"version": "5.99.6", | ||
"version": "5.99.7", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -10,2 +10,3 @@ "description": "Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.", | ||
"@types/estree": "^1.0.6", | ||
"@types/json-schema": "^7.0.15", | ||
"@webassemblyjs/ast": "^1.14.1", | ||
@@ -27,3 +28,3 @@ "@webassemblyjs/wasm-edit": "^1.14.1", | ||
"neo-async": "^2.6.2", | ||
"schema-utils": "^4.3.0", | ||
"schema-utils": "^4.3.2", | ||
"tapable": "^2.1.1", | ||
@@ -172,3 +173,3 @@ "terser-webpack-plugin": "^5.3.11", | ||
"yarn-lint-fix": "yarn-deduplicate -s highest yarn.lock", | ||
"benchmark": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.js\" --runInBand", | ||
"benchmark": "node --max-old-space-size=4096 --experimental-vm-modules --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.mjs\" --runInBand", | ||
"cover": "yarn cover:all && yarn cover:report", | ||
@@ -175,0 +176,0 @@ "cover:clean": "rimraf .nyc_output coverage", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
5305518
0.07%691
0.14%151461
0.06%27
-3.57%24
4.35%