added Compiler and Compilation hooks defs

This commit is contained in:
Dennis George
2018-03-05 16:25:58 -06:00
parent e8c0f80ed3
commit ec8691b39d
7 changed files with 774 additions and 3 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for tapable v0.2.5
// Type definitions for tapable v1.0.0
// Project: https://github.com/webpack/tapable.git
// Definitions by: e-cloud <https://github.com/e-cloud>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -9,6 +9,7 @@ declare abstract class Tapable {
}
/**
* @deprecated Tapable.plugin is deprecated. Use new API on `.hooks` instead
* Register plugin(s)
* This acts as the same as on() of EventEmitter, for registering a handler/listener to do something when the
* signal/event happens.
@@ -18,9 +19,11 @@ declare abstract class Tapable {
*/
plugin(names: string, handler: (this: this, ...args: any[]) => void): void;
/** @deprecated Tapable.plugin is deprecated. Use new API on `.hooks` instead */
plugin(names: string[], handler: (this: this, ...args: any[]) => void): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* invoke all plugins with this attached.
* This method is just to "apply" plugins' definition, so that the real event listeners can be registered into
* registry. Mostly the `apply` method of a plugin is the main place to place extension logic.
@@ -28,6 +31,7 @@ declare abstract class Tapable {
apply(...plugins: (((this: this) => any) | Tapable.Plugin)[]): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments.
@@ -44,6 +48,7 @@ declare abstract class Tapable {
applyPlugins2(name: string, param1: any, param2: any): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with the return value of the previous handler and all the rest arguments.
@@ -55,6 +60,7 @@ declare abstract class Tapable {
applyPluginsWaterfall(name: string, init: any, ...args: any[]): any;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called ONLY with the return value of the previous handler.
@@ -66,6 +72,7 @@ declare abstract class Tapable {
applyPluginsWaterfall0(name: string, init: any): any;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments.
@@ -75,6 +82,7 @@ declare abstract class Tapable {
applyPluginsBailResult(name: string, ...args: any[]): any;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with target param
@@ -88,6 +96,7 @@ declare abstract class Tapable {
applyPluginsBailResult1(name: string, param: any): any;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* asynchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments
@@ -101,6 +110,7 @@ declare abstract class Tapable {
applyPluginsAsync(name: string, ...args: any[]): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* same as `applyPluginsAsync`
* @see applyPluginsAsync
* @alias Tapable.applyPluginsAsync
@@ -112,6 +122,7 @@ declare abstract class Tapable {
applyPluginsAsyncSeries1(name: string, param: any, callback: Tapable.CallbackFunction): void
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* asynchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments
@@ -127,6 +138,7 @@ declare abstract class Tapable {
applyPluginsAsyncSeriesBailResult(name: string, ...args: any[]): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* asynchronously applies all registered handlers for target name(event id).
*
* @see applyPluginsAsyncSeriesBailResult
@@ -139,6 +151,7 @@ declare abstract class Tapable {
applyPluginsAsyncSeriesBailResult1(name: string, param: any, callback: Tapable.CallbackFunction): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* Asynchronously applies all registered handlers for target name(event id).
*
* The handlers are called with the current value and a callback function with the signature (err: Error,
@@ -155,6 +168,7 @@ declare abstract class Tapable {
applyPluginsAsyncWaterfall(name: string, init: any, callback: Tapable.CallbackFunction): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* applies all registered handlers for target name(event id) in parallel.
*
* The handlers are called with all the rest arguments
@@ -168,6 +182,7 @@ declare abstract class Tapable {
applyPluginsParallel(name: string, ...args: any[]): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* applies all registered handlers for target name(event id) in parallel.
*
* The handlers are called with all the rest arguments
@@ -182,6 +197,7 @@ declare abstract class Tapable {
applyPluginsParallelBailResult(name: string, ...args: any[]): void;
/**
* @deprecated Tapable.apply is deprecated. Call apply on the plugin directly instead
* applies all registered handlers for target name(event id) in parallel.
*
* @see applyPluginsParallelBailResult
@@ -208,6 +224,60 @@ declare namespace Tapable {
interface CallbackFunction {
(err?: Error, result?: any, ...args: any[]): void;
}
type TapType = "sync" | "async" | "promise";
interface HookCompileOptions {
type: TapType;
}
interface Tap {
name: string;
type: TapType;
fn: Function;
stage: number;
context: boolean;
}
interface Hook<TContext = any> {
compile(options: HookCompileOptions) : Function;
tap: (name: string | Tap, fn: (context: TContext, ...args: any[]) => any) => void;
tapAsync: (name: string | Tap, fn: (context: TContext, ...args: any[]) => void) => void;
tapPromise: (name: string | Tap, fn: (context: TContext, ...args: any[]) => Promise<any>) => void;
intercept: (interceptor: HookInterceptor) => void;
}
interface SyncHook<TContext = any> extends Hook<TContext> {}
interface SyncBailHook <TContext = any>extends Hook<TContext> {}
interface SyncLoopHook<TContext = any> extends Hook<TContext> {}
interface SyncWaterfallHook<TContext = any> extends Hook<TContext> {}
interface AsyncParallelHook<TContext = any> extends Hook<TContext> {}
interface AsyncParallelBailHook<TContext = any> extends Hook<TContext> {}
interface AsyncSeriesHook<TContext = any> extends Hook<TContext> {}
interface AsyncSeriesBailHook<TContext = any> extends Hook<TContext> {}
interface AsyncSeriesWaterfallHook<TContext = any> extends Hook<TContext> {}
interface HookInterceptor {
call: (...args: any[]) => void;
loop: (...args: any[]) => void;
tap: (tap: Tap) => void;
register: (tap: Tap) => Tap | undefined;
context: boolean;
}
interface HookMap<TContext = any> {
get: (key: any) => Hook<TContext> | undefined;
for: (key: any) => Hook<TContext>;
tap: (key: any, name: string | Tap, fn: (context: TContext, ...args: any[]) => any) => void;
tapAsync: (key: any, name: string | Tap, fn: (context: TContext, ...args: any[]) => void) => void;
tapPromise: (key: any, name: string | Tap, fn: (context: any, ...args: any[]) => Promise<any>) => void;
intercept: (interceptor: HookMapInterceptor<TContext>) => TContext;
}
interface HookMapInterceptor<TContext = any> {
factory: (key: any, hook: Hook<TContext>) => Hook<TContext>;
}
}
export = Tapable

213
types/tapable/v0/index.d.ts vendored Normal file
View File

@@ -0,0 +1,213 @@
// Type definitions for tapable v0.2.5
// Project: https://github.com/webpack/tapable.git
// Definitions by: e-cloud <https://github.com/e-cloud>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare abstract class Tapable {
private _plugins: {
[propName: string]: Tapable.Handler[]
}
/**
* Register plugin(s)
* This acts as the same as on() of EventEmitter, for registering a handler/listener to do something when the
* signal/event happens.
*
* @param names a string or an array of strings to generate the id(group name) of plugins
* @param handler a function which provides the plugin functionality *
*/
plugin(names: string, handler: (this: this, ...args: any[]) => void): void;
plugin(names: string[], handler: (this: this, ...args: any[]) => void): void;
/**
* invoke all plugins with this attached.
* This method is just to "apply" plugins' definition, so that the real event listeners can be registered into
* registry. Mostly the `apply` method of a plugin is the main place to place extension logic.
*/
apply(...plugins: (((this: this) => any) | Tapable.Plugin)[]): void;
/**
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments.
*
* @param name - plugin group name
* @param args
*/
applyPlugins(name: string, ...args: any[]): void;
applyPlugins0(name: string): void;
applyPlugins1(name: string, param: any): void;
applyPlugins2(name: string, param1: any, param2: any): void;
/**
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with the return value of the previous handler and all the rest arguments.
*
* `init` is used for the first handler.
*
* return the returned value of the last handler
*/
applyPluginsWaterfall(name: string, init: any, ...args: any[]): any;
/**
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called ONLY with the return value of the previous handler.
*
* `init` is used for the first handler.
*
* return the returned value of the last handler
*/
applyPluginsWaterfall0(name: string, init: any): any;
/**
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments.
*
* If a handler returns something !== undefined, that value is returned and no more handlers will be applied.
*/
applyPluginsBailResult(name: string, ...args: any[]): any;
/**
* synchronously applies all registered handlers for target name(event id).
*
* The handlers are called with target param
*
* If a handler returns something !== undefined, the value is returned and no more handlers are applied.
*
* Note: the fundamental difference with `{@link applyPluginsBailResult}`, is that,
* `{@link applyPluginsBailResult}` passes the arguments as arguments list for plugins
* while `{@link applyPluginsBailResult1}` passes the arguments as single param(any type) for plugins
*/
applyPluginsBailResult1(name: string, param: any): any;
/**
* asynchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments
* and a callback function with the signature (err: Error) => void.
*
* The handlers are called in series, one at a time. After all handlers are applied, callback is called.
*
* If any handler invokes the (anonymous)callback with error, no more handlers will be called
* and the real callback is call with that error.
*/
applyPluginsAsync(name: string, ...args: any[]): void;
/**
* same as `applyPluginsAsync`
* @see applyPluginsAsync
* @alias Tapable.applyPluginsAsync
* @param name
* @param args
*/
applyPluginsAsyncSeries(name: string, ...args: any[]): void;
applyPluginsAsyncSeries1(name: string, param: any, callback: Tapable.CallbackFunction): void
/**
* asynchronously applies all registered handlers for target name(event id).
*
* The handlers are called with all the rest arguments
* and a callback function with the signature (...params) => void.
*
* Handlers must invoke the (anonymous)callback, otherwise the series is cut down and real callback won't be
* invoked.
*
* The order is defined by registration order not by speed of the handler function.
*
* If a handler returns something !== undefined, that value is returned and no more handlers will be applied.
*/
applyPluginsAsyncSeriesBailResult(name: string, ...args: any[]): void;
/**
* asynchronously applies all registered handlers for target name(event id).
*
* @see applyPluginsAsyncSeriesBailResult
*
* Note: the fundamental difference with `{@link applyPluginsAsyncSeriesBailResult}`, is that,
* `{@link applyPluginsAsyncSeriesBailResult}` passes the arguments as arguments list for plugins
* while `{@link applyPluginsAsyncSeriesBailResult1}` passes the arguments as single param(any type)
* and a callback for plugins
*/
applyPluginsAsyncSeriesBailResult1(name: string, param: any, callback: Tapable.CallbackFunction): void;
/**
* Asynchronously applies all registered handlers for target name(event id).
*
* The handlers are called with the current value and a callback function with the signature (err: Error,
* nextValue: any) => void.
*
* `init` is used for the first handler. The rest handles are called with the value which previous handler uses
* to invoke the (anonymous)callback invoked
*
* After all handlers are applied, callback is called with the last value.
*
* If any handler invokes the (anonymous)callback with error, no more handlers will be called
* and the real callback is call with that error.
*/
applyPluginsAsyncWaterfall(name: string, init: any, callback: Tapable.CallbackFunction): void;
/**
* applies all registered handlers for target name(event id) in parallel.
*
* The handlers are called with all the rest arguments
* and a callback function with the signature (err?: Error) => void.
*
* The callback function is called when all handlers call the callback without err.
*
* If any handler invokes the callback with err, callback is invoked with this error and the other handlers are
* skipped.
*/
applyPluginsParallel(name: string, ...args: any[]): void;
/**
* applies all registered handlers for target name(event id) in parallel.
*
* The handlers are called with all the rest arguments
* and a callback function with the signature (currentResult?: []) => void.
*
* Handlers must call the callback.
*
* The first result (either error or value) with is not undefined is passed to the callback.
*
* The order is defined by registration not by speed of the handler function.
*/
applyPluginsParallelBailResult(name: string, ...args: any[]): void;
/**
* applies all registered handlers for target name(event id) in parallel.
*
* @see applyPluginsParallelBailResult
*
* Note: the fundamental difference with `{@link applyPluginsParallelBailResult}`, is that,
* `{@link applyPluginsParallelBailResult}` passes the arguments as arguments list for plugins
* while `{@link applyPluginsParallelBailResult1}` passes the arguments as single param(any type)
* and a callback for plugins
*/
applyPluginsParallelBailResult1(name: string, param: any, callback: Tapable.CallbackFunction): void;
static mixin(proto: any): void;
}
declare namespace Tapable {
interface Handler {
(...args: any[]): void;
}
interface Plugin {
apply(...args: any[]): void;
}
interface CallbackFunction {
(err?: Error, result?: any, ...args: any[]): void;
}
}
export = Tapable

View File

@@ -0,0 +1,45 @@
import Tapable = require('tapable');
class DllPlugin {
apply(compiler: Compiler) {
compiler.plugin('doSomething', function (...args: string[]) {
console.log(args);
});
compiler.plugin(['doSomething', 'doNothing'], function (...args: string[]) {
console.log(args);
});
}
}
class Compiler extends Tapable {
constructor(){
super()
}
}
const compiler = new Compiler();
let callback: Tapable.CallbackFunction = function () {
};
compiler.apply(new DllPlugin());
compiler.applyPlugins('doSomething', 'a', 'b');
compiler.applyPlugins0('doSomething');
compiler.applyPlugins1('doSomething', 'a');
compiler.applyPlugins2('doSomething', 'a', 'b');
compiler.applyPluginsWaterfall('doSomething', 'a', 'b');
compiler.applyPluginsWaterfall0('doSomething', 'a');
compiler.applyPluginsBailResult('doSomething', 'a', 'b');
compiler.applyPluginsBailResult1('doSomething', ['a', 'b']);
compiler.applyPluginsAsync('doSomething', 'a', 'b');
compiler.applyPluginsAsyncSeries('doSomething', 'a', 'b');
compiler.applyPluginsAsyncSeries1('doSomething', 'a', callback);
compiler.applyPluginsAsyncSeriesBailResult('doSomething', 'a', 'b');
compiler.applyPluginsAsyncSeriesBailResult1('doSomething', 'a', callback);
compiler.applyPluginsAsyncWaterfall('doSomething', 'a', callback);
compiler.applyPluginsParallel('doSomething', 'a', 'b');
compiler.applyPluginsParallelBailResult('doSomething', 'a', 'b');
compiler.applyPluginsParallelBailResult1('doSomething', 'a', callback);

View File

@@ -0,0 +1,27 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"tapable": ["tapable/v0"]
}
},
"files": [
"index.d.ts",
"tapable-tests.ts"
]
}

View File

@@ -1,4 +1,4 @@
// Type definitions for webpack 4.0
// Type definitions for webpack 4.1.0
// Project: https://github.com/webpack/webpack
// Definitions by: Qubo <https://github.com/tkqubo>
// Benjamin Lim <https://github.com/bumbleblym>
@@ -10,6 +10,7 @@
// Alan Agius <https://github.com/alan-agius4>
// Spencer Elliott <https://github.com/elliottsj>
// Jason Cheatham <https://github.com/jason0x43>
// Dennis George <https://github.com/dennispg>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
@@ -599,6 +600,311 @@ declare namespace webpack {
}
}
class Chunk {
constructor(name: string);
id: any;
ids: any;
debugId: number;
name: any;
entryModule: any;
files: any[];
rendered: boolean;
hash: any;
renderedHash: any;
chunkReason: any;
extraAsync: boolean;
hasRuntime(): boolean;
canBeInitial(): boolean;
isOnlyInitial(): boolean;
hasEntryModule() : boolean;
addModule(module: any): boolean;
removeModule(module: any): boolean;
setModules(modules: any): void;
getNumberOfModules(): number;
modulesIterable: any[];
addGroup(chunkGroup: any): boolean;
removeGroup(chunkGroup: any): boolean;
isInGroup(chunkGroup: any): boolean;
getNumberOfGroups(): number;
groupsIterable: any[];
compareTo(otherChunk: any): -1 | 0 | 1;
containsModule(module: any): boolean;
getModules(): any[];
getModulesIdent(): any[];
remove(reason: any): void;
moveModule(module: any, otherChunk: any): void;
integrate(otherChunk: any, reason: any): boolean;
split(newChunk: any): void;
isEmpty(): boolean;
updateHash(hash: any): void;
canBeIntegrated(otherChunk: any): boolean;
addMultiplierAndOverhead(size: number, options: any): number;
modulesSize(): number;
size(options: any): number;
integratedSize(otherChunk: any, options: any): number;
sortModules(sortByFn: Function): void;
getAllAsyncChunks(): Set<any>;
getChunkMaps(realHash: any): { hash: any, name: any };
getChunkModuleMaps(filterFn: Function): { id: any, hash: any };
hasModuleInGraph(filterFn: Function, filterChunkFn: Function): boolean;
toString(): string;
}
class Dependency {
constructor();
getResourceIdentifier(): any;
getReference(): any;
getExports() : any;
getWarnings(): any;
getErrors(): any;
updateHash(hash: any): void;
disconnect(): void;
static compare(a: any, b: any): any;
}
interface NormalModuleFactoryHooks {
resolver: Tapable.SyncWaterfallHook;
factory: Tapable.SyncWaterfallHook;
beforeResolve: Tapable.AsyncSeriesWaterfallHook;
afterResolve: Tapable.AsyncSeriesWaterfallHook;
createModule: Tapable.SyncBailHook;
module: Tapable.SyncWaterfallHook;
createParser: Tapable.HookMap;
parser: Tapable.HookMap;
createGenerator: Tapable.HookMap;
generator: Tapable.HookMap;
}
class NormalModuleFactory extends Tapable {
hooks: NormalModuleFactoryHooks;
}
interface ContextModuleFactoryHooks {
beforeResolve: Tapable.AsyncSeriesWaterfallHook;
afterResolve: Tapable.AsyncSeriesWaterfallHook;
contextModuleFiles: Tapable.SyncWaterfallHook;
alternatives: Tapable.AsyncSeriesWaterfallHook;
}
class ContextModuleFactory extends Tapable {
hooks: ContextModuleFactoryHooks;
}
class DllModuleFactory extends Tapable {
hooks: {};
}
interface CompilationHooks {
buildModule: Tapable.SyncHook;
rebuildModule: Tapable.SyncHook;
failedModule: Tapable.SyncHook;
succeedModule: Tapable.SyncHook;
finishModules: Tapable.SyncHook;
finishRebuildingModule: Tapable.SyncHook;
unseal: Tapable.SyncHook;
seal: Tapable.SyncHook;
optimizeDependenciesBasic: Tapable.SyncBailHook;
optimizeDependencies: Tapable.SyncBailHook;
optimizeDependenciesAdvanced: Tapable.SyncBailHook;
afterOptimizeDependencies: Tapable.SyncHook;
optimize: Tapable.SyncHook;
optimizeModulesBasic: Tapable.SyncBailHook;
optimizeModules: Tapable.SyncBailHook;
optimizeModulesAdvanced: Tapable.SyncBailHook;
afterOptimizeModules: Tapable.SyncHook;
optimizeChunksBasic: Tapable.SyncBailHook;
optimizeChunks: Tapable.SyncBailHook;
optimizeChunksAdvanced: Tapable.SyncBailHook;
afterOptimizeChunks: Tapable.SyncHook;
optimizeTree: Tapable.AsyncSeriesHook;
afterOptimizeTree: Tapable.SyncHook;
optimizeChunkModulesBasic: Tapable.SyncBailHook;
optimizeChunkModules: Tapable.SyncBailHook;
optimizeChunkModulesAdvanced: Tapable.SyncBailHook;
afterOptimizeChunkModules: Tapable.SyncHook;
shouldRecord: Tapable.SyncBailHook;
reviveModules: Tapable.SyncHook;
optimizeModuleOrder: Tapable.SyncHook;
advancedOptimizeModuleOrder: Tapable.SyncHook;
beforeModuleIds: Tapable.SyncHook;
moduleIds: Tapable.SyncHook;
optimizeModuleIds: Tapable.SyncHook;
afterOptimizeModuleIds: Tapable.SyncHook;
reviveChunks: Tapable.SyncHook;
optimizeChunkOrder: Tapable.SyncHook;
beforeChunkIds: Tapable.SyncHook;
optimizeChunkIds: Tapable.SyncHook;
afterOptimizeChunkIds: Tapable.SyncHook;
recordModules: Tapable.SyncHook;
recordChunks: Tapable.SyncHook;
beforeHash: Tapable.SyncHook;
afterHash: Tapable.SyncHook;
recordHash: Tapable.SyncHook;
record: Tapable.SyncHook;
beforeModuleAssets: Tapable.SyncHook;
shouldGenerateChunkAssets: Tapable.SyncBailHook;
beforeChunkAssets: Tapable.SyncHook;
additionalChunkAssets: Tapable.SyncHook;
records: Tapable.SyncHook;
additionalAssets: Tapable.AsyncSeriesHook;
optimizeChunkAssets: Tapable.AsyncSeriesHook<Chunk[]>;
afterOptimizeChunkAssets: Tapable.SyncHook;
optimizeAssets: Tapable.AsyncSeriesHook;
afterOptimizeAssets: Tapable.SyncHook;
needAdditionalSeal: Tapable.SyncBailHook;
afterSeal: Tapable.AsyncSeriesHook;
chunkHash: Tapable.SyncHook;
moduleAsset: Tapable.SyncHook;
chunkAsset: Tapable.SyncHook;
assetPath: Tapable.SyncWaterfallHook;
needAdditionalPass: Tapable.SyncBailHook;
childCompiler: Tapable.SyncHook;
normalModuleLoader: Tapable.SyncHook;
optimizeExtractedChunksBasic: Tapable.SyncBailHook;
optimizeExtractedChunks: Tapable.SyncBailHook;
optimizeExtractedChunksAdvanced: Tapable.SyncBailHook;
afterOptimizeExtractedChunks: Tapable.SyncHook;
}
interface CompilationModule {
module: any;
issuer: boolean;
build: boolean;
dependencies: boolean;
}
class MainTemplate extends Tapable {}
class ChunkTemplate extends Tapable {}
class HotUpdateChunkTemplate extends Tapable {}
class RuntimeTemplate {}
interface ModuleTemplateHooks {
content: Tapable.SyncWaterfallHook;
module: Tapable.SyncWaterfallHook;
render: Tapable.SyncWaterfallHook;
package: Tapable.SyncWaterfallHook;
hash: Tapable.SyncHook
}
class ModuleTemplate extends Tapable {
hooks: ModuleTemplateHooks;
}
class Compilation extends Tapable {
hooks: CompilationHooks;
compiler: Compiler;
resolverFactory: any;
inputFileSystem: any;
requestShortener: any;
outputOptions: any;
bail: any;
profile: any;
performance: any;
mainTemplate: MainTemplate;
chunkTemplate: ChunkTemplate;
hotUpdateChunkTemplate: HotUpdateChunkTemplate;
runtimeTemplate: RuntimeTemplate;
moduleTemplates: {
javascript: ModuleTemplate;
webassembly: ModuleTemplate;
};
entries: any[];
_preparedEntrypoints: any[];
entrypoints: Map<any, any>;
chunks: any[];
chunkGroups: any[];
namedChunkGroups: Map<any, any>;
namedChunks: Map<any, any>;
modules: any[];
_modules: Map<any, any>;
cache: any;
records: any;
nextFreeModuleIndex: any;
nextFreeModuleIndex2: any;
additionalChunkAssets: any[];
assets: any;
errors: any[];
warnings: any[];
children: any[];
dependencyFactories : Map<typeof Dependency, Tapable>;
dependencyTemplates : Map<typeof Dependency, Tapable>;
childrenCounters: any;
usedChunkIds: any;
usedModuleIds: any;
getStats(): Stats;
addModule(module: CompilationModule, cacheGroup: any): any;
// getModule(module)
// findModule(identifier)
// waitForBuildingFinished(module, callback)
// buildModule(module, optional, origin, dependencies, thisCallback)
// processModuleDependencies(module, callback)
// addModuleDependencies(module, dependencies, bail, cacheGroup, recursive, callback)
addEntry(context: any, entry: any, name: any, callback: Function): void;
// prefetch(context, dependency, callback)
// rebuildModule(module, thisCallback)
// finish()
// unseal()
// seal(callback)
// sortModules(modules)
// reportDependencyErrorsAndWarnings(module, blocks)
// addChunkInGroup(name, module, loc, request)
// addChunk(name)
// assignIndex(module)
// assignDepth(module)
// processDependenciesBlocksForChunkGroups(inputChunkGroups)
// removeReasonsOfDependencyBlock(module, block)
// patchChunksAfterReasonRemoval(module, chunk)
// removeChunkFromDependencies(block, chunk)
// applyModuleIds()
// applyChunkIds()
// sortItemsWithModuleIds()
// sortItemsWithChunkIds()
// summarizeDependencies()
// createHash()
// modifyHash(update)
// createModuleAssets()
// createChunkAssets()
getPath(filename: string, data: {hash?: any, chunk?: any, filename?: string, basename?: string, query?: any}): string;
// createChildCompiler(name, outputOptions, plugins)
// checkConstraints()
/**
* @deprecated Compilation.applyPlugins is deprecated. Use new API on `.hooks` instead
*/
applyPlugins(name: string, ...args: any[]): void;
}
// tslint:disable-next-line:interface-name
interface ICompiler {
run(handler: ICompiler.Handler): void;
@@ -631,9 +937,39 @@ declare namespace webpack {
invalidate(): void;
}
interface CompilerHooks {
shouldEmit: Tapable.SyncBailHook;
done: Tapable.AsyncSeriesHook;
additionalPass: Tapable.AsyncSeriesHook;
beforeRun: Tapable.AsyncSeriesHook;
run: Tapable.AsyncSeriesHook;
emit: Tapable.AsyncSeriesHook;
afterEmit: Tapable.AsyncSeriesHook;
thisCompilation: Tapable.SyncHook;
compilation: Tapable.SyncHook<Compilation>;
normalModuleFactory: Tapable.SyncHook<NormalModuleFactory>;
contextModuleFactory: Tapable.SyncHook<ContextModuleFactory>;
beforeCompile: Tapable.AsyncSeriesHook;
compile: Tapable.SyncHook;
make: Tapable.AsyncParallelHook;
afterCompile: Tapable.AsyncSeriesHook;
watchRun: Tapable.AsyncSeriesHook;
failed: Tapable.SyncHook;
invalid: Tapable.SyncHook;
watchClose: Tapable.SyncHook;
environment: Tapable.SyncHook;
afterEnvironment: Tapable.SyncHook;
afterPlugins: Tapable.SyncHook;
afterResolvers: Tapable.SyncHook;
entryOption: Tapable.SyncBailHook;
}
class Compiler extends Tapable implements ICompiler {
constructor();
hooks: CompilerHooks;
_pluginCompat: Tapable.SyncBailHook<Compilation>;
name: string;
options: Configuration;
outputFileSystem: any;

View File

@@ -14,7 +14,10 @@
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
"forceConsistentCasingInFileNames": true,
"paths": {
"tapable": ["tapable"]
}
},
"files": [
"index.d.ts",

View File

@@ -1,4 +1,5 @@
import webpack = require('webpack');
import Tapable = require('tapable');
import { RawSourceMap } from 'source-map';
const {
@@ -580,3 +581,79 @@ configuration = {
};
plugin = new webpack.SplitChunksPlugin({ chunks: "async", minChunks: 2 });
class SingleEntryDependency extends webpack.Dependency {}
class MultiEntryDependency extends webpack.Dependency {}
class MultiModuleFactory extends Tapable {}
class MultiEntryPlugin extends webpack.Plugin {
apply(compiler: webpack.Compiler) {
compiler.hooks.compilation.tap(
"MultiEntryPlugin",
(compilation, { normalModuleFactor }) => {
compilation.dependencyFactories.set(MultiEntryDependency, new MultiModuleFactory());
}
);
compiler.hooks.make.tapAsync(
"MultiEntryPlugin",
(compilation, callback) => {
const dep = new MultiEntryPlugin();
compilation.addEntry("", {}, "", () => {});
}
);
}
}
class IgnorePlugin extends webpack.Plugin {
checkIgnore(result: any) {
}
apply(compiler: webpack.Compiler) {
compiler.hooks.normalModuleFactory.tap("IgnorePlugin", nmf => {
nmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
});
compiler.hooks.contextModuleFactory.tap("IgnorePlugin", cmf => {
cmf.hooks.beforeResolve.tap("IgnorePlugin", this.checkIgnore);
});
}
}
class DllEntryDependency extends webpack.Dependency {}
class DllModuleFactory extends Tapable {}
class DllEntryPlugin extends webpack.Plugin {
apply(compiler: webpack.Compiler) {
compiler.hooks.compilation.tap(
"DllEntryPlugin",
(compilation, { normalModuleFactory }) => {
const dllModuleFactory = new DllModuleFactory();
compilation.dependencyFactories.set(
DllEntryDependency,
dllModuleFactory
);
compilation.dependencyFactories.set(
SingleEntryDependency,
normalModuleFactory
);
}
);
compiler.hooks.make.tapAsync("DllEntryPlugin", (compilation, callback) => {
compilation.addEntry("", new DllEntryDependency(), "", callback);
});
}
}
class BannerPlugin extends webpack.Plugin {
apply(compiler: webpack.Compiler) {
compiler.hooks.compilation.tap("BannerPlugin", compilation => {
compilation.hooks.optimizeChunkAssets.tap("BannerPlugin", chunks => {
for (const chunk of chunks) {
if (!chunk.canBeInitial()) {
continue;
}
for (const file of chunk.files) {
compilation.getPath("", {});
}
}
});
});
}
}