Reimplement tapable types
This commit is contained in:
parent
ef27840f94
commit
fc17a59f5e
|
@ -71,12 +71,15 @@ class AmdMainTemplatePlugin {
|
|||
}
|
||||
};
|
||||
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.renderWithEntry.tap(
|
||||
"AmdMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
}
|
||||
mainTemplate.hooks.renderWithEntry.tap(
|
||||
"AmdMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
chunkTemplate.hooks.renderWithEntry.tap(
|
||||
"AmdMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
mainTemplate.hooks.globalHashPaths.tap("AmdMainTemplatePlugin", paths => {
|
||||
if (this.name) {
|
||||
|
|
|
@ -7,36 +7,39 @@
|
|||
|
||||
const { SyncWaterfallHook, SyncHook } = require("tapable");
|
||||
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Module")} Module} */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash} */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates} */
|
||||
/** @typedef {import("webpack-sources").Source} Source} */
|
||||
/** @typedef {import("./ModuleTemplate").RenderContext} RenderContext} */
|
||||
/** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions} */
|
||||
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry} */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
/** @typedef {import("./ModuleTemplate").RenderContext} RenderContext */
|
||||
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
|
||||
/** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
module.exports = class ChunkTemplate {
|
||||
constructor(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
|
||||
/** @type {SyncWaterfallHook<[TODO[], RenderManifestOptions]>} */
|
||||
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
||||
/** @type {SyncWaterfallHook<Source, ModuleTemplate, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, ModuleTemplate, RenderContext]>} */
|
||||
modules: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleTemplate",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<Source, ModuleTemplate, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, ModuleTemplate, RenderContext]>} */
|
||||
render: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleTemplate",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<[Source, Chunk]>} */
|
||||
renderWithEntry: new SyncWaterfallHook(["source", "chunk"]),
|
||||
/** @type {SyncHook<[Hash]>} */
|
||||
hash: new SyncHook(["hash"]),
|
||||
/** @type {SyncHook<[Hash, Chunk]>} */
|
||||
hashForChunk: new SyncHook(["hash", "chunk"])
|
||||
});
|
||||
}
|
||||
|
|
|
@ -211,25 +211,25 @@ class Compilation {
|
|||
*/
|
||||
constructor(compiler) {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncHook<Module>} */
|
||||
/** @type {SyncHook<[Module]>} */
|
||||
buildModule: new SyncHook(["module"]),
|
||||
/** @type {SyncHook<Module>} */
|
||||
/** @type {SyncHook<[Module]>} */
|
||||
rebuildModule: new SyncHook(["module"]),
|
||||
/** @type {SyncHook<Module, Error>} */
|
||||
/** @type {SyncHook<[Module, Error]>} */
|
||||
failedModule: new SyncHook(["module", "error"]),
|
||||
/** @type {SyncHook<Module>} */
|
||||
/** @type {SyncHook<[Module]>} */
|
||||
succeedModule: new SyncHook(["module"]),
|
||||
|
||||
/** @type {SyncWaterfallHook<DependencyReference, Dependency, Module>} */
|
||||
/** @type {SyncWaterfallHook<[DependencyReference, Dependency, Module]>} */
|
||||
dependencyReference: new SyncWaterfallHook([
|
||||
"dependencyReference",
|
||||
"dependency",
|
||||
"module"
|
||||
]),
|
||||
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
finishModules: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module>} */
|
||||
/** @type {SyncHook<[Module]>} */
|
||||
finishRebuildingModule: new SyncHook(["module"]),
|
||||
/** @type {SyncHook} */
|
||||
unseal: new SyncHook([]),
|
||||
|
@ -238,78 +238,78 @@ class Compilation {
|
|||
|
||||
/** @type {SyncHook} */
|
||||
beforeChunks: new SyncHook([]),
|
||||
/** @type {SyncHook<Chunk[]>} */
|
||||
/** @type {SyncHook<[Chunk[]]>} */
|
||||
afterChunks: new SyncHook(["chunks"]),
|
||||
|
||||
/** @type {SyncBailHook<Module[]>} */
|
||||
/** @type {SyncBailHook<[Module[]]>} */
|
||||
optimizeDependencies: new SyncBailHook(["modules"]),
|
||||
/** @type {SyncBailHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
afterOptimizeDependencies: new SyncHook(["modules"]),
|
||||
|
||||
/** @type {SyncHook} */
|
||||
optimize: new SyncHook([]),
|
||||
/** @type {SyncBailHook<Module[]>} */
|
||||
/** @type {SyncBailHook<[Module[]]>} */
|
||||
optimizeModules: new SyncBailHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
afterOptimizeModules: new SyncHook(["modules"]),
|
||||
|
||||
/** @type {SyncBailHook<Chunk[], ChunkGroup[]>} */
|
||||
/** @type {SyncBailHook<[Chunk[], ChunkGroup[]]>} */
|
||||
optimizeChunks: new SyncBailHook(["chunks", "chunkGroups"]),
|
||||
/** @type {SyncHook<Chunk[], ChunkGroup[]>} */
|
||||
/** @type {SyncHook<[Chunk[], ChunkGroup[]]>} */
|
||||
afterOptimizeChunks: new SyncHook(["chunks", "chunkGroups"]),
|
||||
|
||||
/** @type {AsyncSeriesHook<Chunk[], Module[]>} */
|
||||
/** @type {AsyncSeriesHook<[Chunk[], Module[]]>} */
|
||||
optimizeTree: new AsyncSeriesHook(["chunks", "modules"]),
|
||||
/** @type {SyncHook<Chunk[], Module[]>} */
|
||||
/** @type {SyncHook<[Chunk[], Module[]]>} */
|
||||
afterOptimizeTree: new SyncHook(["chunks", "modules"]),
|
||||
|
||||
/** @type {SyncBailHook<Chunk[], Module[]>} */
|
||||
/** @type {SyncBailHook<[Chunk[], Module[]]>} */
|
||||
optimizeChunkModules: new SyncBailHook(["chunks", "modules"]),
|
||||
/** @type {SyncHook<Chunk[], Module[]>} */
|
||||
/** @type {SyncHook<[Chunk[], Module[]]>} */
|
||||
afterOptimizeChunkModules: new SyncHook(["chunks", "modules"]),
|
||||
/** @type {SyncBailHook} */
|
||||
shouldRecord: new SyncBailHook([]),
|
||||
|
||||
/** @type {SyncHook<Module[], any>} */
|
||||
/** @type {SyncHook<[Module[], any]>} */
|
||||
reviveModules: new SyncHook(["modules", "records"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
optimizeModuleOrder: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
advancedOptimizeModuleOrder: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
beforeModuleIds: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
moduleIds: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
optimizeModuleIds: new SyncHook(["modules"]),
|
||||
/** @type {SyncHook<Module[]>} */
|
||||
/** @type {SyncHook<[Module[]]>} */
|
||||
afterOptimizeModuleIds: new SyncHook(["modules"]),
|
||||
|
||||
/** @type {SyncHook<Chunk[], any>} */
|
||||
/** @type {SyncHook<[Chunk[], any]>} */
|
||||
reviveChunks: new SyncHook(["chunks", "records"]),
|
||||
/** @type {SyncHook<Chunk[]>} */
|
||||
/** @type {SyncHook<[Chunk[]]>} */
|
||||
optimizeChunkOrder: new SyncHook(["chunks"]),
|
||||
/** @type {SyncHook<Chunk[]>} */
|
||||
/** @type {SyncHook<[Chunk[]]>} */
|
||||
beforeChunkIds: new SyncHook(["chunks"]),
|
||||
/** @type {SyncHook<Chunk[]>} */
|
||||
/** @type {SyncHook<[Chunk[]]>} */
|
||||
optimizeChunkIds: new SyncHook(["chunks"]),
|
||||
/** @type {SyncHook<Chunk[]>} */
|
||||
/** @type {SyncHook<[Chunk[]]>} */
|
||||
afterOptimizeChunkIds: new SyncHook(["chunks"]),
|
||||
|
||||
/** @type {SyncHook<Module[], any>} */
|
||||
/** @type {SyncHook<[Module[], any]>} */
|
||||
recordModules: new SyncHook(["modules", "records"]),
|
||||
/** @type {SyncHook<Chunk[], any>} */
|
||||
/** @type {SyncHook<[Chunk[], any]>} */
|
||||
recordChunks: new SyncHook(["chunks", "records"]),
|
||||
|
||||
/** @type {SyncHook} */
|
||||
beforeHash: new SyncHook([]),
|
||||
/** @type {SyncHook<Chunk>} */
|
||||
/** @type {SyncHook<[Chunk]>} */
|
||||
contentHash: new SyncHook(["chunk"]),
|
||||
/** @type {SyncHook} */
|
||||
afterHash: new SyncHook([]),
|
||||
/** @type {SyncHook<any>} */
|
||||
/** @type {SyncHook<[any]>} */
|
||||
recordHash: new SyncHook(["records"]),
|
||||
/** @type {SyncHook<Compilation, any>} */
|
||||
/** @type {SyncHook<[Compilation, any]>} */
|
||||
record: new SyncHook(["compilation", "records"]),
|
||||
|
||||
/** @type {SyncHook} */
|
||||
|
@ -318,18 +318,18 @@ class Compilation {
|
|||
shouldGenerateChunkAssets: new SyncBailHook([]),
|
||||
/** @type {SyncHook} */
|
||||
beforeChunkAssets: new SyncHook([]),
|
||||
/** @type {SyncHook<Chunk[]>} */
|
||||
/** @type {SyncHook<[Chunk[]]>} */
|
||||
additionalChunkAssets: new SyncHook(["chunks"]),
|
||||
|
||||
/** @type {AsyncSeriesHook} */
|
||||
additionalAssets: new AsyncSeriesHook([]),
|
||||
/** @type {AsyncSeriesHook<Chunk[]>} */
|
||||
/** @type {AsyncSeriesHook<[Chunk[]]>} */
|
||||
optimizeChunkAssets: new AsyncSeriesHook(["chunks"]),
|
||||
/** @type {SyncHook<Chunk[]>} */
|
||||
/** @type {SyncHook<[Chunk[]]>} */
|
||||
afterOptimizeChunkAssets: new SyncHook(["chunks"]),
|
||||
/** @type {AsyncSeriesHook<CompilationAssets>} */
|
||||
/** @type {AsyncSeriesHook<[CompilationAssets]>} */
|
||||
optimizeAssets: new AsyncSeriesHook(["assets"]),
|
||||
/** @type {SyncHook<CompilationAssets>} */
|
||||
/** @type {SyncHook<[CompilationAssets]>} */
|
||||
afterOptimizeAssets: new SyncHook(["assets"]),
|
||||
|
||||
/** @type {SyncBailHook} */
|
||||
|
@ -337,20 +337,20 @@ class Compilation {
|
|||
/** @type {AsyncSeriesHook} */
|
||||
afterSeal: new AsyncSeriesHook([]),
|
||||
|
||||
/** @type {SyncHook<Chunk, Hash>} */
|
||||
/** @type {SyncHook<[Chunk, Hash]>} */
|
||||
chunkHash: new SyncHook(["chunk", "chunkHash"]),
|
||||
/** @type {SyncHook<Module, string>} */
|
||||
/** @type {SyncHook<[Module, string]>} */
|
||||
moduleAsset: new SyncHook(["module", "filename"]),
|
||||
/** @type {SyncHook<Chunk, string>} */
|
||||
/** @type {SyncHook<[Chunk, string]>} */
|
||||
chunkAsset: new SyncHook(["chunk", "filename"]),
|
||||
|
||||
/** @type {SyncWaterfallHook<string, TODO>} */
|
||||
/** @type {SyncWaterfallHook<[string, TODO]>} */
|
||||
assetPath: new SyncWaterfallHook(["filename", "data"]), // TODO MainTemplate
|
||||
|
||||
/** @type {SyncBailHook} */
|
||||
needAdditionalPass: new SyncBailHook([]),
|
||||
|
||||
/** @type {SyncHook<Compiler, string, number>} */
|
||||
/** @type {SyncHook<[Compiler, string, number]>} */
|
||||
childCompiler: new SyncHook([
|
||||
"childCompiler",
|
||||
"compilerName",
|
||||
|
@ -359,7 +359,7 @@ class Compilation {
|
|||
|
||||
// TODO the following hooks are weirdly located here
|
||||
// TODO move them for webpack 5
|
||||
/** @type {SyncHook<object, Module>} */
|
||||
/** @type {SyncHook<[object, Module]>} */
|
||||
normalModuleLoader: new SyncHook(["loaderContext", "module"])
|
||||
});
|
||||
/** @type {string=} */
|
||||
|
|
|
@ -46,44 +46,44 @@ const { makePathsRelative } = require("./util/identifier");
|
|||
class Compiler {
|
||||
constructor(context) {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncBailHook<Compilation>} */
|
||||
/** @type {SyncBailHook<[Compilation]>} */
|
||||
shouldEmit: new SyncBailHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<Stats>} */
|
||||
/** @type {AsyncSeriesHook<[Stats]>} */
|
||||
done: new AsyncSeriesHook(["stats"]),
|
||||
/** @type {AsyncSeriesHook<>} */
|
||||
additionalPass: new AsyncSeriesHook([]),
|
||||
/** @type {AsyncSeriesHook<Compiler>} */
|
||||
/** @type {AsyncSeriesHook<[Compiler]>} */
|
||||
beforeRun: new AsyncSeriesHook(["compiler"]),
|
||||
/** @type {AsyncSeriesHook<Compiler>} */
|
||||
/** @type {AsyncSeriesHook<[Compiler]>} */
|
||||
run: new AsyncSeriesHook(["compiler"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
/** @type {AsyncSeriesHook<[Compilation]>} */
|
||||
emit: new AsyncSeriesHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
/** @type {AsyncSeriesHook<[Compilation]>} */
|
||||
afterEmit: new AsyncSeriesHook(["compilation"]),
|
||||
|
||||
/** @type {SyncHook<Compilation, CompilationParams>} */
|
||||
/** @type {SyncHook<[Compilation, CompilationParams]>} */
|
||||
thisCompilation: new SyncHook(["compilation", "params"]),
|
||||
/** @type {SyncHook<Compilation, CompilationParams>} */
|
||||
/** @type {SyncHook<[Compilation, CompilationParams]>} */
|
||||
compilation: new SyncHook(["compilation", "params"]),
|
||||
/** @type {SyncHook<NormalModuleFactory>} */
|
||||
/** @type {SyncHook<[NormalModuleFactory]>} */
|
||||
normalModuleFactory: new SyncHook(["normalModuleFactory"]),
|
||||
/** @type {SyncHook<ContextModuleFactory>} */
|
||||
/** @type {SyncHook<[ContextModuleFactory]>} */
|
||||
contextModuleFactory: new SyncHook(["contextModulefactory"]),
|
||||
|
||||
/** @type {AsyncSeriesHook<CompilationParams>} */
|
||||
/** @type {AsyncSeriesHook<[CompilationParams]>} */
|
||||
beforeCompile: new AsyncSeriesHook(["params"]),
|
||||
/** @type {SyncHook<CompilationParams>} */
|
||||
/** @type {SyncHook<[CompilationParams]>} */
|
||||
compile: new SyncHook(["params"]),
|
||||
/** @type {AsyncParallelHook<Compilation>} */
|
||||
/** @type {AsyncParallelHook<[Compilation]>} */
|
||||
make: new AsyncParallelHook(["compilation"]),
|
||||
/** @type {AsyncSeriesHook<Compilation>} */
|
||||
/** @type {AsyncSeriesHook<[Compilation]>} */
|
||||
afterCompile: new AsyncSeriesHook(["compilation"]),
|
||||
|
||||
/** @type {AsyncSeriesHook<Compiler>} */
|
||||
/** @type {AsyncSeriesHook<[Compiler]>} */
|
||||
watchRun: new AsyncSeriesHook(["compiler"]),
|
||||
/** @type {SyncHook<Error>} */
|
||||
/** @type {SyncHook<[Error]>} */
|
||||
failed: new SyncHook(["error"]),
|
||||
/** @type {SyncHook<string, string>} */
|
||||
/** @type {SyncHook<[string, string]>} */
|
||||
invalid: new SyncHook(["filename", "changeTime"]),
|
||||
/** @type {SyncHook} */
|
||||
watchClose: new SyncHook([]),
|
||||
|
@ -94,11 +94,11 @@ class Compiler {
|
|||
environment: new SyncHook([]),
|
||||
/** @type {SyncHook} */
|
||||
afterEnvironment: new SyncHook([]),
|
||||
/** @type {SyncHook<Compiler>} */
|
||||
/** @type {SyncHook<[Compiler]>} */
|
||||
afterPlugins: new SyncHook(["compiler"]),
|
||||
/** @type {SyncHook<Compiler>} */
|
||||
/** @type {SyncHook<[Compiler]>} */
|
||||
afterResolvers: new SyncHook(["compiler"]),
|
||||
/** @type {SyncBailHook<string, EntryOptions>} */
|
||||
/** @type {SyncBailHook<[string, EntryOptions]>} */
|
||||
entryOption: new SyncBailHook(["context", "entry"])
|
||||
});
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@ const EMPTY_RESOLVE_OPTIONS = {};
|
|||
module.exports = class ContextModuleFactory {
|
||||
constructor(resolverFactory) {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {AsyncSeriesWaterfallHook<TODO>} */
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO]>} */
|
||||
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {AsyncSeriesWaterfallHook<TODO>} */
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO]>} */
|
||||
afterResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {SyncWaterfallHook<string[]>} */
|
||||
/** @type {SyncWaterfallHook<[string[]]>} */
|
||||
contextModuleFiles: new SyncWaterfallHook(["files"]),
|
||||
/** @type {SyncWaterfallHook<TODO[]>} */
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO[]]>} */
|
||||
alternatives: new AsyncSeriesWaterfallHook(["modules"])
|
||||
});
|
||||
this.resolverFactory = resolverFactory;
|
||||
|
|
|
@ -37,12 +37,15 @@ class ExportPropertyMainTemplatePlugin {
|
|||
return new ConcatSource(source, postfix);
|
||||
};
|
||||
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.renderWithEntry.tap(
|
||||
"ExportPropertyMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
}
|
||||
mainTemplate.hooks.renderWithEntry.tap(
|
||||
"ExportPropertyMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
chunkTemplate.hooks.renderWithEntry.tap(
|
||||
"ExportPropertyMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
mainTemplate.hooks.hash.tap("ExportPropertyMainTemplatePlugin", hash => {
|
||||
hash.update("export property");
|
||||
|
|
|
@ -29,9 +29,20 @@ const hotInitCode = Template.getFunctionContent(
|
|||
require("./HotModuleReplacement.runtime")
|
||||
);
|
||||
|
||||
/**
|
||||
* @typedef {Object} HotModuleReplacementPluginHooks
|
||||
* @property {SyncBailHook<[TODO, TODO]>} hotAcceptCallback
|
||||
* @property {SyncBailHook<[TODO, TODO]>} hotAcceptWithoutCallback
|
||||
*/
|
||||
|
||||
/** @type {WeakMap<JavascriptParser, HotModuleReplacementPluginHooks>} */
|
||||
const parserHooksMap = new WeakMap();
|
||||
|
||||
module.exports = class HotModuleReplacementPlugin {
|
||||
/**
|
||||
* @param {JavascriptParser} parser the parser
|
||||
* @returns {HotModuleReplacementPluginHooks} hooks
|
||||
*/
|
||||
static getHooks(parser) {
|
||||
if (!(parser instanceof JavascriptParser)) {
|
||||
throw new TypeError(
|
||||
|
|
|
@ -11,24 +11,26 @@ const Template = require("./Template");
|
|||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
/** @typedef {import("./ModuleTemplate").RenderContext} RenderContext */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
module.exports = class HotUpdateChunkTemplate {
|
||||
constructor(outputOptions) {
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncWaterfallHook<Source, ModuleTemplate, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, ModuleTemplate, RenderContext]>} */
|
||||
modules: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleTemplate",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<Source, ModuleTemplate, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, ModuleTemplate, RenderContext, string]>} */
|
||||
render: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleTemplate",
|
||||
"renderContext",
|
||||
"hash"
|
||||
]),
|
||||
/** @type {SyncHook<[Hash]>} */
|
||||
hash: new SyncHook(["hash"])
|
||||
});
|
||||
}
|
||||
|
@ -60,6 +62,11 @@ module.exports = class HotUpdateChunkTemplate {
|
|||
return source;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates hash with information from this template
|
||||
* @param {Hash} hash the hash to update
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update("HotUpdateChunkTemplate");
|
||||
hash.update("1");
|
||||
|
|
|
@ -25,7 +25,7 @@ const createHash = require("./util/createHash");
|
|||
|
||||
/**
|
||||
* @typedef {Object} JavascriptModulesPluginHooks
|
||||
* @property {SyncBailHook<Module, Chunk>} shouldRender
|
||||
* @property {SyncBailHook<[Module, Chunk]>} shouldRender
|
||||
*/
|
||||
|
||||
/** @type {WeakMap<Compilation, JavascriptModulesPluginHooks>} */
|
||||
|
|
|
@ -9,14 +9,22 @@ const JavascriptModulesPlugin = require("./JavascriptModulesPlugin");
|
|||
const JsonGenerator = require("./JsonGenerator");
|
||||
const JsonParser = require("./JsonParser");
|
||||
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
|
||||
class JsonModulesPlugin {
|
||||
/**
|
||||
* @param {Compiler} compiler webpack compiler
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(
|
||||
"JsonModulesPlugin",
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
const hooks = JavascriptModulesPlugin.getHooks(compilation);
|
||||
hooks.shouldRender.tap("JavascriptModulesPlugin", module => {
|
||||
if (module.type === "json") return true;
|
||||
if (module.type === "json") {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
normalModuleFactory.hooks.createParser
|
||||
.for("json")
|
||||
|
|
|
@ -16,17 +16,17 @@ const Template = require("./Template");
|
|||
|
||||
/** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
|
||||
/** @typedef {import("webpack-sources").Source} Source */
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
/** @typedef {import("./Chunk")} Chunk */
|
||||
/** @typedef {import("./Module")} Module} */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash} */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates} */
|
||||
/** @typedef {import("./ModuleTemplate").RenderContext} RenderContext} */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate} */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph} */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph} */
|
||||
/** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions} */
|
||||
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry} */
|
||||
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
||||
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
||||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||
/** @typedef {import("./ModuleTemplate").RenderContext} RenderContext */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("./Template").RenderManifestEntry} RenderManifestEntry */
|
||||
/** @typedef {import("./Template").RenderManifestOptions} RenderManifestOptions */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
/**
|
||||
* @typedef {Object} MainRenderContext
|
||||
|
@ -64,61 +64,65 @@ module.exports = class MainTemplate {
|
|||
/** @type {TODO?} */
|
||||
this.outputOptions = outputOptions || {};
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncWaterfallHook<TODO[], RenderManifestOptions>} */
|
||||
/** @type {SyncWaterfallHook<[TODO[], RenderManifestOptions]>} */
|
||||
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
||||
/** @type {SyncWaterfallHook<Source, ModuleTemplate, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, ModuleTemplate, MainRenderContext]>} */
|
||||
modules: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleTemplate",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<string, string, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[string, string, MainRenderContext]>} */
|
||||
moduleObj: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleIdExpression",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<string, string, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[string, string, MainRenderContext]>} */
|
||||
requireEnsure: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunkIdExpression",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<string, ModuleTemplate, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[string, ModuleTemplate, MainRenderContext]>} */
|
||||
bootstrap: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleTemplate",
|
||||
"renderContext"
|
||||
]),
|
||||
localVars: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
/** @type {SyncWaterfallHook<string, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[string, MainRenderContext]>} */
|
||||
require: new SyncWaterfallHook(["source", "renderContext"]),
|
||||
/** @type {SyncWaterfallHook<string, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[string, MainRenderContext]>} */
|
||||
requireExtensions: new SyncWaterfallHook(["source", "renderContext"]),
|
||||
/** @type {SyncWaterfallHook<string, Chunk, string>} */
|
||||
/** @type {SyncWaterfallHook<[string, Chunk, string]>} */
|
||||
beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
/** @type {SyncWaterfallHook<string, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[string, MainRenderContext]>} */
|
||||
startup: new SyncWaterfallHook(["source", "renderContext"]),
|
||||
/** @type {SyncWaterfallHook<Source, ModuleTemplate, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, ModuleTemplate, MainRenderContext]>} */
|
||||
render: new SyncWaterfallHook([
|
||||
"source",
|
||||
"moduleTemplate",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<[Source, Chunk, string]>} */
|
||||
renderWithEntry: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
||||
/** @type {SyncWaterfallHook<[string, Chunk, string, string|number]>} */
|
||||
moduleRequire: new SyncWaterfallHook([
|
||||
"source",
|
||||
"chunk",
|
||||
"hash",
|
||||
"moduleIdExpression"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<string, {moduleId: string, module: string}, MainRenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[string, {moduleId: string, module: string}, MainRenderContext]>} */
|
||||
addModule: new SyncWaterfallHook([
|
||||
"source",
|
||||
"expressions",
|
||||
"renderContext"
|
||||
]),
|
||||
/** @type {SyncWaterfallHook<[string, number]>} */
|
||||
currentHash: new SyncWaterfallHook(["source", "requestedLength"]),
|
||||
/** @type {SyncWaterfallHook<[string, TODO]>} */
|
||||
assetPath: new SyncWaterfallHook(["path", "options"]),
|
||||
hash: new SyncHook(["hash"]),
|
||||
hashForChunk: new SyncHook(["hash", "chunk"]),
|
||||
|
|
|
@ -14,6 +14,7 @@ const { SyncWaterfallHook, SyncHook } = require("tapable");
|
|||
/** @typedef {import("./Module")} Module */
|
||||
/** @typedef {import("./ModuleGraph")} ModuleGraph */
|
||||
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
||||
/** @typedef {import("./util/createHash").Hash} Hash */
|
||||
|
||||
/**
|
||||
* @typedef {Object} RenderContext
|
||||
|
@ -29,14 +30,15 @@ module.exports = class ModuleTemplate {
|
|||
this.runtimeTemplate = runtimeTemplate;
|
||||
this.type = type;
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncWaterfallHook<Source, Module, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, Module, RenderContext]>} */
|
||||
content: new SyncWaterfallHook(["source", "module", "context"]),
|
||||
/** @type {SyncWaterfallHook<Source, Module, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, Module, RenderContext]>} */
|
||||
module: new SyncWaterfallHook(["source", "module", "context"]),
|
||||
/** @type {SyncWaterfallHook<Source, Module, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, Module, RenderContext]>} */
|
||||
render: new SyncWaterfallHook(["source", "module", "context"]),
|
||||
/** @type {SyncWaterfallHook<Source, Module, RenderContext>} */
|
||||
/** @type {SyncWaterfallHook<[Source, Module, RenderContext]>} */
|
||||
package: new SyncWaterfallHook(["source", "module", "context"]),
|
||||
/** @type {SyncHook<[Hash]>} */
|
||||
hash: new SyncHook(["hash"])
|
||||
});
|
||||
}
|
||||
|
@ -83,6 +85,10 @@ module.exports = class ModuleTemplate {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Hash} hash the hash to update
|
||||
* @returns {void}
|
||||
*/
|
||||
updateHash(hash) {
|
||||
hash.update("1");
|
||||
this.hooks.hash.call(hash);
|
||||
|
|
|
@ -61,11 +61,17 @@ const dependencyCache = new WeakMap();
|
|||
class NormalModuleFactory {
|
||||
constructor(context, resolverFactory, options) {
|
||||
this.hooks = Object.freeze({
|
||||
/** @type {SyncWaterfallHook<[TODO]>} */
|
||||
resolver: new SyncWaterfallHook(["resolver"]),
|
||||
/** @type {SyncWaterfallHook<[TODO]>} */
|
||||
factory: new SyncWaterfallHook(["factory"]),
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO]>} */
|
||||
beforeResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {AsyncSeriesWaterfallHook<[TODO]>} */
|
||||
afterResolve: new AsyncSeriesWaterfallHook(["data"]),
|
||||
/** @type {SyncBailHook<[TODO]>} */
|
||||
createModule: new SyncBailHook(["data"]),
|
||||
/** @type {SyncWaterfallHook<[TODO, TODO]>} */
|
||||
module: new SyncWaterfallHook(["module", "data"]),
|
||||
createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
|
||||
parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
|
||||
|
|
|
@ -45,12 +45,15 @@ class SetVarMainTemplatePlugin {
|
|||
}
|
||||
};
|
||||
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.renderWithEntry.tap(
|
||||
"SetVarMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
}
|
||||
mainTemplate.hooks.renderWithEntry.tap(
|
||||
"SetVarMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
chunkTemplate.hooks.renderWithEntry.tap(
|
||||
"SetVarMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
mainTemplate.hooks.globalHashPaths.tap(
|
||||
"SetVarMainTemplatePlugin",
|
||||
|
|
|
@ -88,12 +88,6 @@ class UmdMainTemplatePlugin {
|
|||
apply(compilation) {
|
||||
const { mainTemplate, chunkTemplate, runtimeTemplate } = compilation;
|
||||
|
||||
/**
|
||||
* @param {Source} source source
|
||||
* @param {Chunk} chunk chunk
|
||||
* @param {string} hash Hash
|
||||
* @returns {Source} new source
|
||||
*/
|
||||
const onRenderWithEntry = (source, chunk, hash) => {
|
||||
const chunkGraph = compilation.chunkGraph;
|
||||
const modules = chunkGraph
|
||||
|
@ -292,12 +286,15 @@ class UmdMainTemplatePlugin {
|
|||
);
|
||||
};
|
||||
|
||||
for (const template of [mainTemplate, chunkTemplate]) {
|
||||
template.hooks.renderWithEntry.tap(
|
||||
"UmdMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
}
|
||||
mainTemplate.hooks.renderWithEntry.tap(
|
||||
"UmdMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
chunkTemplate.hooks.renderWithEntry.tap(
|
||||
"UmdMainTemplatePlugin",
|
||||
onRenderWithEntry
|
||||
);
|
||||
|
||||
mainTemplate.hooks.globalHashPaths.tap("UmdMainTemplatePlugin", paths => {
|
||||
if (this.names.root) paths = paths.concat(this.names.root);
|
||||
|
|
|
@ -33,7 +33,6 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^9.6.4",
|
||||
"@types/tapable": "^1.0.1",
|
||||
"@types/webpack-sources": "^0.1.4",
|
||||
"benchmark": "^2.1.1",
|
||||
"bundle-loader": "~0.5.0",
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
type Measure<T extends number> =
|
||||
T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 ?
|
||||
T extends 0 | 1 | 2 | 3 ?
|
||||
T extends 0 | 1 ?
|
||||
T extends 0 ?
|
||||
0 : 1 : 2 : 4 :
|
||||
number extends T ? never : 8;
|
||||
type Drop1<T extends any[]> = (((..._: T) => 0) extends (a0?: any, ..._: infer R) => 0 ? R : never);
|
||||
type Drop2<T extends any[]> = (((..._: T) => 0) extends (a0?: any, a1?: any, ..._: infer R) => 0 ? R : never);
|
||||
type Drop4<T extends any[]> = (((..._: T) => 0) extends (a0?: any, a1?: any, a2?: any, a3?: any, ..._: infer R) => 0 ? R : never);
|
||||
type Drop8<T extends any[]> = (((..._: T) => 0) extends (a0?: any, a1?: any, a2?: any, a3?: any, a4?: any, a5?: any, a6?: any, a7?: any, ..._: infer R) => 0 ? R : never);
|
||||
type ConcatRev1<A extends any[], B extends any[]> = ((a0: A[0], ..._: B) => 0) extends (..._: infer R) => 0 ? R : never;
|
||||
type ConcatRev2<A extends any[], B extends any[]> = ((a0: A[1], a1: A[0], ..._: B) => 0) extends (..._: infer R) => 0 ? R : never;
|
||||
type ConcatRev4<A extends any[], B extends any[]> = ((a0: A[3], a1: A[2], a2: A[1], a3: A[0], ..._: B) => 0) extends (..._: infer R) => 0 ? R : never;
|
||||
type ConcatRev8<A extends any[], B extends any[]> = ((a0: A[7], a1: A[6], a2: A[5], a3: A[4], a4: A[3], a5: A[2], a6: A[1], a7: A[0], ..._: B) => 0) extends (..._: infer R) => 0 ? R : never;
|
||||
type ConcatRev<A extends any[], B extends any[] = []> = {
|
||||
0: B;
|
||||
1: ConcatRev<Drop1<A>, ConcatRev1<A, B>>;
|
||||
2: ConcatRev<Drop2<A>, ConcatRev2<A, B>>;
|
||||
4: ConcatRev<Drop4<A>, ConcatRev4<A, B>>;
|
||||
8: ConcatRev<Drop8<A>, ConcatRev8<A, B>>;
|
||||
}[Measure<A['length']>];
|
||||
type Concat<A extends any[], B extends any[] = []> = ConcatRev<ConcatRev<A>, B>;
|
||||
|
||||
declare module "tapable" {
|
||||
type HookCallback<R, E = Error> = (error?: E, result?: R) => void
|
||||
type TapType = "sync" | "async" | "promise";
|
||||
|
||||
export interface Tap {
|
||||
name: string;
|
||||
type: TapType;
|
||||
fn: Function;
|
||||
stage: number;
|
||||
context: boolean;
|
||||
}
|
||||
|
||||
export class Hook<T extends any[], R = any> {
|
||||
constructor(args: string[]);
|
||||
call(...args: T): R;
|
||||
callAsync(...args: Concat<T, [HookCallback<R>]>): void;
|
||||
promise(...args: T): Promise<R>;
|
||||
tap(options: string | Tap, fn: (...args: T) => R): void;
|
||||
tapAsync(options: string | Tap, fn: (...args: Concat<T, [HookCallback<R>]>) => void): void;
|
||||
tapPromise(options: string | Tap, fn: (...args: T) => Promise<R>): void;
|
||||
intercept(interceptor: HookInterceptor): void;
|
||||
}
|
||||
|
||||
export class SyncHook<T extends any[], R> extends Hook<T, R> {}
|
||||
export class SyncBailHook<T extends any[], R> extends Hook<T, R> {}
|
||||
export class SyncLoopHook<T extends any[], R> extends Hook<T, R> {}
|
||||
export class SyncWaterfallHook<T extends any[], R> extends Hook<T, R> {}
|
||||
|
||||
export class AsyncParallelHook<T extends any[], R> extends Hook<T, R> {}
|
||||
export class AsyncParallelBailHook<T extends any[], R> extends Hook<T, R> {}
|
||||
export class AsyncSeriesHook<T extends any[], R> extends Hook<T, R> {}
|
||||
export class AsyncSeriesBailHook<T extends any[], R> extends Hook<T, R> {}
|
||||
export class AsyncSeriesWaterfallHook<T extends any[], R> extends Hook<T, R> {}
|
||||
|
||||
export class HookInterceptor {
|
||||
call(...args: any[]): void;
|
||||
loop(...args: any[]): void;
|
||||
tap(tap: Tap): void;
|
||||
register(tap: Tap): Tap | undefined;
|
||||
context: boolean;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export class HookMap<T extends any[], R> {
|
||||
constructor(fn: () => Hook<T, R>);
|
||||
get(key: string): Hook<T, R> | undefined;
|
||||
for(key: string): Hook<T, R>;
|
||||
tap(key: string, options: string | Tap, fn: (...args: T) => R): void;
|
||||
tapAsync(key: string, options: string | Tap, fn: (...args: Concat<T, [HookCallback<R>]>) => void): void;
|
||||
tapPromise(key: string, options: string | Tap, fn: (...args: T) => Promise<R>): void;
|
||||
intercept(interceptor: HookMapInterceptor<T, R>): void;
|
||||
}
|
||||
|
||||
export class HookMapInterceptor<T extends any[], R> {
|
||||
factory(key: string, hook: Hook<T, R>): Hook<T, R>;
|
||||
}
|
||||
|
||||
export class MultiHook<T extends any[], R> {
|
||||
constructor(hooks: Hook<T, R>[]);
|
||||
}
|
||||
}
|
|
@ -12,5 +12,11 @@
|
|||
"types": ["node"],
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["declarations.d.ts", "bin/*.js", "lib/**/*.js", "tooling/**/*.js"]
|
||||
"include": [
|
||||
"declarations.d.ts",
|
||||
"tapable.d.ts",
|
||||
"bin/*.js",
|
||||
"lib/**/*.js",
|
||||
"tooling/**/*.js"
|
||||
]
|
||||
}
|
||||
|
|
|
@ -44,10 +44,6 @@
|
|||
version "0.1.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/source-list-map/-/source-list-map-0.1.2.tgz#0078836063ffaf17412349bba364087e0ac02ec9"
|
||||
|
||||
"@types/tapable@^1.0.1":
|
||||
version "1.0.2"
|
||||
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.2.tgz#e13182e1b69871a422d7863e11a4a6f5b814a4bd"
|
||||
|
||||
"@types/webpack-sources@^0.1.4":
|
||||
version "0.1.5"
|
||||
resolved "https://registry.yarnpkg.com/@types/webpack-sources/-/webpack-sources-0.1.5.tgz#be47c10f783d3d6efe1471ff7f042611bd464a92"
|
||||
|
|
Loading…
Reference in New Issue