Comparing version
@@ -32,4 +32,5 @@ /* | ||
let code = ""; | ||
code += `if(${i} < _results.length && ((_results.length = ${i + | ||
1}), (_results[${i}] = { error: ${err} }), _checkDone())) {\n`; | ||
code += `if(${i} < _results.length && ((_results.length = ${ | ||
i + 1 | ||
}), (_results[${i}] = { error: ${err} }), _checkDone())) {\n`; | ||
code += doneBreak(true); | ||
@@ -43,4 +44,5 @@ code += "} else {\n"; | ||
let code = ""; | ||
code += `if(${i} < _results.length && (${result} !== undefined && (_results.length = ${i + | ||
1}), (_results[${i}] = { result: ${result} }), _checkDone())) {\n`; | ||
code += `if(${i} < _results.length && (${result} !== undefined && (_results.length = ${ | ||
i + 1 | ||
}), (_results[${i}] = { result: ${result} }), _checkDone())) {\n`; | ||
code += doneBreak(true); | ||
@@ -71,3 +73,3 @@ code += "} else {\n"; | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -74,0 +76,0 @@ return factory.create(options); |
@@ -21,3 +21,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -24,0 +24,0 @@ return factory.create(options); |
@@ -26,3 +26,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -29,0 +29,0 @@ return factory.create(options); |
@@ -21,3 +21,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -24,0 +24,0 @@ return factory.create(options); |
@@ -21,3 +21,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -24,0 +24,0 @@ return factory.create(options); |
@@ -29,3 +29,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -32,0 +32,0 @@ return factory.create(options); |
@@ -9,14 +9,16 @@ /* | ||
const deprecateContext = util.deprecate(() => {}, | ||
"Hook.context is deprecated and will be removed"); | ||
const deprecateContext = util.deprecate( | ||
() => {}, | ||
"Hook.context is deprecated and will be removed" | ||
); | ||
const CALL_DELEGATE = function(...args) { | ||
const CALL_DELEGATE = function (...args) { | ||
this.call = this._createCall("sync"); | ||
return this.call(...args); | ||
}; | ||
const CALL_ASYNC_DELEGATE = function(...args) { | ||
const CALL_ASYNC_DELEGATE = function (...args) { | ||
this.callAsync = this._createCall("async"); | ||
return this.callAsync(...args); | ||
}; | ||
const PROMISE_DELEGATE = function(...args) { | ||
const PROMISE_DELEGATE = function (...args) { | ||
this.promise = this._createCall("promise"); | ||
@@ -103,3 +105,3 @@ return this.promise(...args); | ||
withOptions(options) { | ||
const mergeOptions = opt => | ||
const mergeOptions = (opt) => | ||
Object.assign({}, options, typeof opt === "string" ? { name: opt } : opt); | ||
@@ -112,5 +114,5 @@ | ||
tapPromise: (opt, fn) => this.tapPromise(mergeOptions(opt), fn), | ||
intercept: interceptor => this.intercept(interceptor), | ||
intercept: (interceptor) => this.intercept(interceptor), | ||
isUsed: () => this.isUsed(), | ||
withOptions: opt => this.withOptions(mergeOptions(opt)) | ||
withOptions: (opt) => this.withOptions(mergeOptions(opt)) | ||
}; | ||
@@ -117,0 +119,0 @@ } |
@@ -24,4 +24,4 @@ /* | ||
this.contentWithInterceptors({ | ||
onError: err => `throw ${err};\n`, | ||
onResult: result => `return ${result};\n`, | ||
onError: (err) => `throw ${err};\n`, | ||
onResult: (result) => `return ${result};\n`, | ||
resultReturns: true, | ||
@@ -41,4 +41,4 @@ onDone: () => "", | ||
this.contentWithInterceptors({ | ||
onError: err => `_callback(${err});\n`, | ||
onResult: result => `_callback(null, ${result});\n`, | ||
onError: (err) => `_callback(${err});\n`, | ||
onResult: (result) => `_callback(null, ${result});\n`, | ||
onDone: () => "_callback();\n" | ||
@@ -51,7 +51,7 @@ }) | ||
const content = this.contentWithInterceptors({ | ||
onError: err => { | ||
onError: (err) => { | ||
errorHelperUsed = true; | ||
return `_error(${err});\n`; | ||
}, | ||
onResult: result => `_resolve(${result});\n`, | ||
onResult: (result) => `_resolve(${result});\n`, | ||
onDone: () => "_resolve();\n" | ||
@@ -86,3 +86,3 @@ }); | ||
setup(instance, options) { | ||
instance._x = options.taps.map(t => t.fn); | ||
instance._x = options.taps.map((t) => t.fn); | ||
} | ||
@@ -121,3 +121,3 @@ | ||
onError && | ||
(err => { | ||
((err) => { | ||
let code = ""; | ||
@@ -135,3 +135,3 @@ for (let i = 0; i < this.options.interceptors.length; i++) { | ||
onResult && | ||
(result => { | ||
((result) => { | ||
let code = ""; | ||
@@ -291,3 +291,3 @@ for (let i = 0; i < this.options.interceptors.length; i++) { | ||
if (this.options.taps.length === 0) return onDone(); | ||
const firstAsync = this.options.taps.findIndex(t => t.type !== "sync"); | ||
const firstAsync = this.options.taps.findIndex((t) => t.type !== "sync"); | ||
const somethingReturns = resultReturns || doneReturns; | ||
@@ -310,3 +310,3 @@ let code = ""; | ||
const done = current; | ||
const doneBreak = skipDone => { | ||
const doneBreak = (skipDone) => { | ||
if (skipDone) return ""; | ||
@@ -316,6 +316,6 @@ return onDone(); | ||
const content = this.callTap(i, { | ||
onError: error => onError(i, error, done, doneBreak), | ||
onError: (error) => onError(i, error, done, doneBreak), | ||
onResult: | ||
onResult && | ||
(result => { | ||
((result) => { | ||
return onResult(i, result, done, doneBreak); | ||
@@ -335,3 +335,3 @@ }), | ||
if (this.options.taps.length === 0) return onDone(); | ||
const syncOnly = this.options.taps.every(t => t.type === "sync"); | ||
const syncOnly = this.options.taps.every((t) => t.type === "sync"); | ||
let code = ""; | ||
@@ -414,3 +414,3 @@ if (!syncOnly) { | ||
}; | ||
const doneBreak = skipDone => { | ||
const doneBreak = (skipDone) => { | ||
if (skipDone || !onDone) return "_counter = 0;\n"; | ||
@@ -424,3 +424,3 @@ else return "_counter = 0;\n_done();\n"; | ||
this.callTap(i, { | ||
onError: error => { | ||
onError: (error) => { | ||
let code = ""; | ||
@@ -434,3 +434,3 @@ code += "if(_counter > 0) {\n"; | ||
onResult && | ||
(result => { | ||
((result) => { | ||
let code = ""; | ||
@@ -437,0 +437,0 @@ code += "if(_counter > 0) {\n"; |
@@ -49,11 +49,11 @@ /* | ||
HookMap.prototype.tap = util.deprecate(function(key, options, fn) { | ||
HookMap.prototype.tap = util.deprecate(function (key, options, fn) { | ||
return this.for(key).tap(options, fn); | ||
}, "HookMap#tap(key,…) is deprecated. Use HookMap#for(key).tap(…) instead."); | ||
HookMap.prototype.tapAsync = util.deprecate(function(key, options, fn) { | ||
HookMap.prototype.tapAsync = util.deprecate(function (key, options, fn) { | ||
return this.for(key).tapAsync(options, fn); | ||
}, "HookMap#tapAsync(key,…) is deprecated. Use HookMap#for(key).tapAsync(…) instead."); | ||
HookMap.prototype.tapPromise = util.deprecate(function(key, options, fn) { | ||
HookMap.prototype.tapPromise = util.deprecate(function (key, options, fn) { | ||
return this.for(key).tapPromise(options, fn); | ||
@@ -60,0 +60,0 @@ }, "HookMap#tapPromise(key,…) is deprecated. Use HookMap#for(key).tapPromise(…) instead."); |
@@ -48,3 +48,3 @@ /* | ||
return new MultiHook( | ||
this.hooks.map(h => h.withOptions(options)), | ||
this.hooks.map((h) => h.withOptions(options)), | ||
this.name | ||
@@ -51,0 +51,0 @@ ); |
@@ -35,3 +35,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -38,0 +38,0 @@ return factory.create(options); |
@@ -30,3 +30,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -33,0 +33,0 @@ return factory.create(options); |
@@ -30,3 +30,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -33,0 +33,0 @@ return factory.create(options); |
@@ -39,3 +39,3 @@ /* | ||
const COMPILE = function(options) { | ||
const COMPILE = function (options) { | ||
factory.setup(this, options); | ||
@@ -42,0 +42,0 @@ return factory.create(options); |
@@ -9,3 +9,3 @@ /* | ||
let once = true; | ||
return function() { | ||
return function () { | ||
if (once) { | ||
@@ -12,0 +12,0 @@ console.warn("DeprecationWarning: " + msg); |
{ | ||
"name": "tapable", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"author": "Tobias Koppers @sokra", | ||
@@ -16,5 +16,5 @@ "description": "Just a little module for plugins.", | ||
"babel-jest": "^24.8.0", | ||
"codecov": "^3.5.0", | ||
"jest": "^24.8.0", | ||
"prettier": "^1.17.1" | ||
"prettier": "^3.5.3", | ||
"prettier-1": "npm:prettier@^1" | ||
}, | ||
@@ -24,7 +24,3 @@ "engines": { | ||
}, | ||
"files": [ | ||
"lib", | ||
"!lib/__tests__", | ||
"tapable.d.ts" | ||
], | ||
"files": ["lib", "!lib/__tests__", "tapable.d.ts"], | ||
"main": "lib/index.js", | ||
@@ -36,6 +32,7 @@ "types": "./tapable.d.ts", | ||
"scripts": { | ||
"test": "jest", | ||
"travis": "yarn pretty-lint && jest --coverage && codecov", | ||
"pretty-lint": "prettier --check lib/*.js lib/__tests__/*.js", | ||
"pretty": "prettier --loglevel warn --write lib/*.js lib/__tests__/*.js" | ||
"lint": "yarn fmt:check", | ||
"fmt": "yarn fmt:base --log-level warn --write", | ||
"fmt:check": "yarn fmt:base --check", | ||
"fmt:base": "node node_modules/prettier/bin/prettier.cjs --cache --ignore-unknown .", | ||
"test": "jest" | ||
}, | ||
@@ -42,0 +39,0 @@ "jest": { |
230
README.md
# Tapable | ||
The tapable package expose many Hook classes, which can be used to create hooks for plugins. | ||
The tapable package exposes many Hook classes, which can be used to create hooks for plugins. | ||
``` javascript | ||
```javascript | ||
const { | ||
@@ -16,3 +16,3 @@ SyncHook, | ||
AsyncSeriesWaterfallHook | ||
} = require("tapable"); | ||
} = require("tapable"); | ||
``` | ||
@@ -22,3 +22,3 @@ | ||
``` shell | ||
```shell | ||
npm install --save tapable | ||
@@ -31,3 +31,3 @@ ``` | ||
``` js | ||
```js | ||
const hook = new SyncHook(["arg1", "arg2", "arg3"]); | ||
@@ -38,3 +38,3 @@ ``` | ||
``` js | ||
```js | ||
class Car { | ||
@@ -55,3 +55,3 @@ constructor() { | ||
``` js | ||
```js | ||
const myCar = new Car(); | ||
@@ -67,4 +67,6 @@ | ||
``` js | ||
myCar.hooks.accelerate.tap("LoggerPlugin", newSpeed => console.log(`Accelerating to ${newSpeed}`)); | ||
```js | ||
myCar.hooks.accelerate.tap("LoggerPlugin", (newSpeed) => | ||
console.log(`Accelerating to ${newSpeed}`) | ||
); | ||
``` | ||
@@ -74,32 +76,41 @@ | ||
``` js | ||
myCar.hooks.calculateRoutes.tapPromise("GoogleMapsPlugin", (source, target, routesList) => { | ||
// return a promise | ||
return google.maps.findRoute(source, target).then(route => { | ||
routesList.add(route); | ||
}); | ||
}); | ||
myCar.hooks.calculateRoutes.tapAsync("BingMapsPlugin", (source, target, routesList, callback) => { | ||
bing.findRoute(source, target, (err, route) => { | ||
if(err) return callback(err); | ||
routesList.add(route); | ||
// call the callback | ||
callback(); | ||
}); | ||
}); | ||
```js | ||
myCar.hooks.calculateRoutes.tapPromise( | ||
"GoogleMapsPlugin", | ||
(source, target, routesList) => { | ||
// return a promise | ||
return google.maps.findRoute(source, target).then((route) => { | ||
routesList.add(route); | ||
}); | ||
} | ||
); | ||
myCar.hooks.calculateRoutes.tapAsync( | ||
"BingMapsPlugin", | ||
(source, target, routesList, callback) => { | ||
bing.findRoute(source, target, (err, route) => { | ||
if (err) return callback(err); | ||
routesList.add(route); | ||
// call the callback | ||
callback(); | ||
}); | ||
} | ||
); | ||
// You can still use sync plugins | ||
myCar.hooks.calculateRoutes.tap("CachedRoutesPlugin", (source, target, routesList) => { | ||
const cachedRoute = cache.get(source, target); | ||
if(cachedRoute) | ||
routesList.add(cachedRoute); | ||
}) | ||
myCar.hooks.calculateRoutes.tap( | ||
"CachedRoutesPlugin", | ||
(source, target, routesList) => { | ||
const cachedRoute = cache.get(source, target); | ||
if (cachedRoute) routesList.add(cachedRoute); | ||
} | ||
); | ||
``` | ||
The class declaring these hooks need to call them: | ||
``` js | ||
The class declaring these hooks needs to call them: | ||
```js | ||
class Car { | ||
/** | ||
* You won't get returned value from SyncHook or AsyncParallelHook, | ||
* to do that, use SyncWaterfallHook and AsyncSeriesWaterfallHook respectively | ||
* You won't get returned value from SyncHook or AsyncParallelHook, | ||
* to do that, use SyncWaterfallHook and AsyncSeriesWaterfallHook respectively | ||
**/ | ||
@@ -114,6 +125,8 @@ | ||
const routesList = new List(); | ||
return this.hooks.calculateRoutes.promise(source, target, routesList).then((res) => { | ||
// res is undefined for AsyncParallelHook | ||
return routesList.getRoutes(); | ||
}); | ||
return this.hooks.calculateRoutes | ||
.promise(source, target, routesList) | ||
.then((res) => { | ||
// res is undefined for AsyncParallelHook | ||
return routesList.getRoutes(); | ||
}); | ||
} | ||
@@ -123,4 +136,4 @@ | ||
const routesList = new List(); | ||
this.hooks.calculateRoutes.callAsync(source, target, routesList, err => { | ||
if(err) return callback(err); | ||
this.hooks.calculateRoutes.callAsync(source, target, routesList, (err) => { | ||
if (err) return callback(err); | ||
callback(null, routesList.getRoutes()); | ||
@@ -133,8 +146,9 @@ }); | ||
The Hook will compile a method with the most efficient way of running your plugins. It generates code depending on: | ||
* The number of registered plugins (none, one, many) | ||
* The kind of registered plugins (sync, async, promise) | ||
* The used call method (sync, async, promise) | ||
* The number of arguments | ||
* Whether interception is used | ||
- The number of registered plugins (none, one, many) | ||
- The kind of registered plugins (sync, async, promise) | ||
- The used call method (sync, async, promise) | ||
- The number of arguments | ||
- Whether interception is used | ||
This ensures fastest possible execution. | ||
@@ -146,21 +160,20 @@ | ||
* Basic hook (without “Waterfall”, “Bail” or “Loop” in its name). This hook simply calls every function it tapped in a row. | ||
- Basic hook (without “Waterfall”, “Bail” or “Loop” in its name). This hook simply calls every function it tapped in a row. | ||
* __Waterfall__. A waterfall hook also calls each tapped function in a row. Unlike the basic hook, it passes a return value from each function to the next function. | ||
- **Waterfall**. A waterfall hook also calls each tapped function in a row. Unlike the basic hook, it passes a return value from each function to the next function. | ||
* __Bail__. A bail hook allows exiting early. When any of the tapped function returns anything, the bail hook will stop executing the remaining ones. | ||
- **Bail**. A bail hook allows exiting early. When any of the tapped function returns anything, the bail hook will stop executing the remaining ones. | ||
* __Loop__. When a plugin in a loop hook returns a non-undefined value the hook will restart from the first plugin. It will loop until all plugins return undefined. | ||
- **Loop**. When a plugin in a loop hook returns a non-undefined value the hook will restart from the first plugin. It will loop until all plugins return undefined. | ||
Additionally, hooks can be synchronous or asynchronous. To reflect this, there’re “Sync”, “AsyncSeries”, and “AsyncParallel” hook classes: | ||
* __Sync__. A sync hook can only be tapped with synchronous functions (using `myHook.tap()`). | ||
- **Sync**. A sync hook can only be tapped with synchronous functions (using `myHook.tap()`). | ||
* __AsyncSeries__. An async-series hook can be tapped with synchronous, callback-based and promise-based functions (using `myHook.tap()`, `myHook.tapAsync()` and `myHook.tapPromise()`). They call each async method in a row. | ||
- **AsyncSeries**. An async-series hook can be tapped with synchronous, callback-based and promise-based functions (using `myHook.tap()`, `myHook.tapAsync()` and `myHook.tapPromise()`). They call each async method in a row. | ||
* __AsyncParallel__. An async-parallel hook can also be tapped with synchronous, callback-based and promise-based functions (using `myHook.tap()`, `myHook.tapAsync()` and `myHook.tapPromise()`). However, they run each async method in parallel. | ||
- **AsyncParallel**. An async-parallel hook can also be tapped with synchronous, callback-based and promise-based functions (using `myHook.tap()`, `myHook.tapAsync()` and `myHook.tapPromise()`). However, they run each async method in parallel. | ||
The hook type is reflected in its class name. E.g., `AsyncSeriesWaterfallHook` allows asynchronous functions and runs them in series, passing each function’s return value into the next function. | ||
## Interception | ||
@@ -170,3 +183,3 @@ | ||
``` js | ||
```js | ||
myCar.hooks.calculateRoutes.intercept({ | ||
@@ -181,3 +194,3 @@ call: (source, target, routesList) => { | ||
} | ||
}) | ||
}); | ||
``` | ||
@@ -197,3 +210,3 @@ | ||
``` js | ||
```js | ||
myCar.hooks.accelerate.intercept({ | ||
@@ -214,12 +227,15 @@ context: true, | ||
myCar.hooks.accelerate.tap({ | ||
name: "NoisePlugin", | ||
context: true | ||
}, (context, newSpeed) => { | ||
if (context && context.hasMuffler) { | ||
console.log("Silence..."); | ||
} else { | ||
console.log("Vroom!"); | ||
myCar.hooks.accelerate.tap( | ||
{ | ||
name: "NoisePlugin", | ||
context: true | ||
}, | ||
(context, newSpeed) => { | ||
if (context && context.hasMuffler) { | ||
console.log("Silence..."); | ||
} else { | ||
console.log("Vroom!"); | ||
} | ||
} | ||
}); | ||
); | ||
``` | ||
@@ -231,16 +247,24 @@ | ||
``` js | ||
const keyedHook = new HookMap(key => new SyncHook(["arg"])) | ||
```js | ||
const keyedHook = new HookMap((key) => new SyncHook(["arg"])); | ||
``` | ||
``` js | ||
keyedHook.for("some-key").tap("MyPlugin", (arg) => { /* ... */ }); | ||
keyedHook.for("some-key").tapAsync("MyPlugin", (arg, callback) => { /* ... */ }); | ||
keyedHook.for("some-key").tapPromise("MyPlugin", (arg) => { /* ... */ }); | ||
```js | ||
keyedHook.for("some-key").tap("MyPlugin", (arg) => { | ||
/* ... */ | ||
}); | ||
keyedHook.for("some-key").tapAsync("MyPlugin", (arg, callback) => { | ||
/* ... */ | ||
}); | ||
keyedHook.for("some-key").tapPromise("MyPlugin", (arg) => { | ||
/* ... */ | ||
}); | ||
``` | ||
``` js | ||
```js | ||
const hook = keyedHook.get("some-key"); | ||
if(hook !== undefined) { | ||
hook.callAsync("arg", err => { /* ... */ }); | ||
if (hook !== undefined) { | ||
hook.callAsync("arg", (err) => { | ||
/* ... */ | ||
}); | ||
} | ||
@@ -253,34 +277,40 @@ ``` | ||
``` ts | ||
```ts | ||
interface Hook { | ||
tap: (name: string | Tap, fn: (context?, ...args) => Result) => void, | ||
tapAsync: (name: string | Tap, fn: (context?, ...args, callback: (err, result: Result) => void) => void) => void, | ||
tapPromise: (name: string | Tap, fn: (context?, ...args) => Promise<Result>) => void, | ||
intercept: (interceptor: HookInterceptor) => void | ||
tap: (name: string | Tap, fn: (context?, ...args) => Result) => void; | ||
tapAsync: ( | ||
name: string | Tap, | ||
fn: (context?, ...args, callback: (err, result: Result) => void) => void | ||
) => void; | ||
tapPromise: ( | ||
name: string | Tap, | ||
fn: (context?, ...args) => Promise<Result> | ||
) => void; | ||
intercept: (interceptor: HookInterceptor) => void; | ||
} | ||
interface HookInterceptor { | ||
call: (context?, ...args) => void, | ||
loop: (context?, ...args) => void, | ||
tap: (context?, tap: Tap) => void, | ||
register: (tap: Tap) => Tap, | ||
context: boolean | ||
call: (context?, ...args) => void; | ||
loop: (context?, ...args) => void; | ||
tap: (context?, tap: Tap) => void; | ||
register: (tap: Tap) => Tap; | ||
context: boolean; | ||
} | ||
interface HookMap { | ||
for: (key: any) => Hook, | ||
intercept: (interceptor: HookMapInterceptor) => void | ||
for: (key: any) => Hook; | ||
intercept: (interceptor: HookMapInterceptor) => void; | ||
} | ||
interface HookMapInterceptor { | ||
factory: (key: any, hook: Hook) => Hook | ||
factory: (key: any, hook: Hook) => Hook; | ||
} | ||
interface Tap { | ||
name: string, | ||
type: string | ||
fn: Function, | ||
stage: number, | ||
context: boolean, | ||
before?: string | Array | ||
name: string; | ||
type: string; | ||
fn: Function; | ||
stage: number; | ||
context: boolean; | ||
before?: string | Array; | ||
} | ||
@@ -291,13 +321,13 @@ ``` | ||
``` ts | ||
```ts | ||
interface Hook { | ||
isUsed: () => boolean, | ||
call: (...args) => Result, | ||
promise: (...args) => Promise<Result>, | ||
callAsync: (...args, callback: (err, result: Result) => void) => void, | ||
isUsed: () => boolean; | ||
call: (...args) => Result; | ||
promise: (...args) => Promise<Result>; | ||
callAsync: (...args, callback: (err, result: Result) => void) => void; | ||
} | ||
interface HookMap { | ||
get: (key: any) => Hook | undefined, | ||
for: (key: any) => Hook | ||
get: (key: any) => Hook | undefined; | ||
for: (key: any) => Hook; | ||
} | ||
@@ -310,3 +340,3 @@ ``` | ||
``` js | ||
```js | ||
const { MultiHook } = require("tapable"); | ||
@@ -313,0 +343,0 @@ |
@@ -6,3 +6,3 @@ type FixedSizeArray<T extends number, U> = T extends 0 | ||
length: T; | ||
}; | ||
}; | ||
type Measure<T extends number> = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ||
@@ -25,3 +25,3 @@ ? T | ||
declare class UnsetAdditionalOptions { | ||
_UnsetAdditionalOptions: true | ||
_UnsetAdditionalOptions: true; | ||
} | ||
@@ -34,5 +34,5 @@ type IfSet<X> = X extends UnsetAdditionalOptions ? {} : X; | ||
type FullTap = Tap & { | ||
type: "sync" | "async" | "promise", | ||
fn: Function | ||
} | ||
type: "sync" | "async" | "promise"; | ||
fn: Function; | ||
}; | ||
@@ -56,3 +56,5 @@ type Tap = TapOptions & { | ||
done?: () => void; | ||
register?: (tap: FullTap & IfSet<AdditionalOptions>) => FullTap & IfSet<AdditionalOptions>; | ||
register?: ( | ||
tap: FullTap & IfSet<AdditionalOptions> | ||
) => FullTap & IfSet<AdditionalOptions>; | ||
} | ||
@@ -65,2 +67,3 @@ | ||
name: string | undefined; | ||
interceptors: HookInterceptor<T, R, AdditionalOptions>[]; | ||
taps: FullTap[]; | ||
@@ -71,21 +74,44 @@ intercept(interceptor: HookInterceptor<T, R, AdditionalOptions>): void; | ||
promise(...args: AsArray<T>): Promise<R>; | ||
tap(options: string | Tap & IfSet<AdditionalOptions>, fn: (...args: AsArray<T>) => R): void; | ||
withOptions(options: TapOptions & IfSet<AdditionalOptions>): Omit<this, "call" | "callAsync" | "promise">; | ||
tap( | ||
options: string | (Tap & IfSet<AdditionalOptions>), | ||
fn: (...args: AsArray<T>) => R | ||
): void; | ||
withOptions( | ||
options: TapOptions & IfSet<AdditionalOptions> | ||
): Omit<this, "call" | "callAsync" | "promise">; | ||
} | ||
export class SyncHook<T, R = void, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> { | ||
export class SyncHook< | ||
T, | ||
R = void, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends Hook<T, R, AdditionalOptions> { | ||
call(...args: AsArray<T>): R; | ||
} | ||
export class SyncBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, R, AdditionalOptions> {} | ||
export class SyncLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, void, AdditionalOptions> {} | ||
export class SyncWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends SyncHook<T, AsArray<T>[0], AdditionalOptions> {} | ||
export class SyncBailHook< | ||
T, | ||
R, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends SyncHook<T, R, AdditionalOptions> {} | ||
export class SyncLoopHook< | ||
T, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends SyncHook<T, void, AdditionalOptions> {} | ||
export class SyncWaterfallHook< | ||
T, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends SyncHook<T, AsArray<T>[0], AdditionalOptions> {} | ||
declare class AsyncHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends Hook<T, R, AdditionalOptions> { | ||
declare class AsyncHook< | ||
T, | ||
R, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends Hook<T, R, AdditionalOptions> { | ||
tapAsync( | ||
options: string | Tap & IfSet<AdditionalOptions>, | ||
options: string | (Tap & IfSet<AdditionalOptions>), | ||
fn: (...args: Append<AsArray<T>, InnerCallback<Error, R>>) => void | ||
): void; | ||
tapPromise( | ||
options: string | Tap & IfSet<AdditionalOptions>, | ||
options: string | (Tap & IfSet<AdditionalOptions>), | ||
fn: (...args: AsArray<T>) => Promise<R> | ||
@@ -95,8 +121,28 @@ ): void; | ||
export class AsyncParallelHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {} | ||
export class AsyncParallelBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {} | ||
export class AsyncSeriesHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {} | ||
export class AsyncSeriesBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, R, AdditionalOptions> {} | ||
export class AsyncSeriesLoopHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, void, AdditionalOptions> {} | ||
export class AsyncSeriesWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends AsyncHook<T, AsArray<T>[0], AdditionalOptions> {} | ||
export class AsyncParallelHook< | ||
T, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends AsyncHook<T, void, AdditionalOptions> {} | ||
export class AsyncParallelBailHook< | ||
T, | ||
R, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends AsyncHook<T, R, AdditionalOptions> {} | ||
export class AsyncSeriesHook< | ||
T, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends AsyncHook<T, void, AdditionalOptions> {} | ||
export class AsyncSeriesBailHook< | ||
T, | ||
R, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends AsyncHook<T, R, AdditionalOptions> {} | ||
export class AsyncSeriesLoopHook< | ||
T, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends AsyncHook<T, void, AdditionalOptions> {} | ||
export class AsyncSeriesWaterfallHook< | ||
T, | ||
AdditionalOptions = UnsetAdditionalOptions | ||
> extends AsyncHook<T, AsArray<T>[0], AdditionalOptions> {} | ||
@@ -103,0 +149,0 @@ type HookFactory<H> = (key: any, hook?: H) => H; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
47215
0.61%1292
4.03%327
10.1%1
Infinity%