Project Init

This commit is contained in:
Muluhabt
2026-05-29 15:23:46 +03:00
commit 2fbc557aac
67387 changed files with 6063341 additions and 0 deletions

22
node_modules/@rspack/lite-tapable/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,22 @@
MIT License
Copyright (c) 2022-present Bytedance, Inc. and its affiliates.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

22
node_modules/@rspack/lite-tapable/README.md generated vendored Normal file
View File

@@ -0,0 +1,22 @@
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://assets.rspack.dev/rspack/rspack-banner-plain-dark.png">
<img alt="Rspack Banner" src="https://assets.rspack.dev/rspack/rspack-banner-plain-light.png">
</picture>
# @rspack/lite-tapable
<p>
<a href="https://www.npmjs.com/package/@rspack/lite-tapable?activeTab=readme"><img src="https://img.shields.io/npm/v/@rspack/lite-tapable?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /></a>
<a href="https://npmcharts.com/compare/@rspack/lite-tapable?minimal=true"><img src="https://img.shields.io/npm/dm/@rspack/lite-tapable.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a>
<a href="https://github.com/web-infra-dev/rspack/blob/main/LICENSE"><img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" /></a>
</p>
Lite weight tapable for Rspack.
## Documentation
See [webpack/tapable](https://github.com/webpack/tapable) for usages.
## License
`@rspack/lite-tapable` is [MIT licensed](https://github.com/web-infra-dev/rspack/blob/main/LICENSE).

736
node_modules/@rspack/lite-tapable/dist/index.cjs generated vendored Normal file
View File

@@ -0,0 +1,736 @@
"use strict";
var __webpack_require__ = {};
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
AsyncParallelHook: ()=>AsyncParallelHook,
AsyncSeriesBailHook: ()=>AsyncSeriesBailHook,
AsyncSeriesHook: ()=>AsyncSeriesHook,
AsyncSeriesWaterfallHook: ()=>AsyncSeriesWaterfallHook,
HookBase: ()=>HookBase,
HookMap: ()=>HookMap,
MultiHook: ()=>MultiHook,
QueriedHook: ()=>QueriedHook,
QueriedHookMap: ()=>QueriedHookMap,
SyncBailHook: ()=>SyncBailHook,
SyncHook: ()=>SyncHook,
SyncWaterfallHook: ()=>SyncWaterfallHook,
maxStage: ()=>maxStage,
minStage: ()=>minStage,
safeStage: ()=>safeStage
});
function _define_property(obj, key, value) {
if (key in obj) Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
else obj[key] = value;
return obj;
}
class HookBase {
intercept(interceptor) {
this.interceptors.push(Object.assign({}, interceptor));
if (interceptor.register) for(let i = 0; i < this.taps.length; i++)this.taps[i] = interceptor.register(this.taps[i]);
}
_runRegisterInterceptors(options) {
return this.interceptors.reduce((options, interceptor)=>interceptor.register?.(options) ?? options, options);
}
_runCallInterceptors(...args) {
for (const interceptor of this.interceptors)if (interceptor.call) interceptor.call(...args);
}
_runErrorInterceptors(e) {
for (const interceptor of this.interceptors)if (interceptor.error) interceptor.error(e);
}
_runTapInterceptors(tap) {
for (const interceptor of this.interceptors)if (interceptor.tap) interceptor.tap(tap);
}
_runDoneInterceptors() {
for (const interceptor of this.interceptors)if (interceptor.done) interceptor.done();
}
_runResultInterceptors(r) {
for (const interceptor of this.interceptors)if (interceptor.result) interceptor.result(r);
}
withOptions(options) {
const mergeOptions = (opt)=>Object.assign({}, options, 'string' == typeof opt ? {
name: opt
} : opt);
return {
name: this.name,
tap: (opt, fn)=>this.tap(mergeOptions(opt), fn),
tapAsync: (opt, fn)=>this.tapAsync(mergeOptions(opt), fn),
tapPromise: (opt, fn)=>this.tapPromise(mergeOptions(opt), fn),
intercept: (interceptor)=>this.intercept(interceptor),
isUsed: ()=>this.isUsed(),
withOptions: (opt)=>this.withOptions(mergeOptions(opt)),
queryStageRange: (stageRange)=>this.queryStageRange(stageRange)
};
}
isUsed() {
return this.taps.length > 0 || this.interceptors.length > 0;
}
queryStageRange(stageRange) {
return new QueriedHook(stageRange, this);
}
callAsyncStageRange(queried) {
throw new Error('Hook should implement there own _callAsyncStageRange');
}
callAsync(...args) {
return this.callAsyncStageRange(this.queryStageRange(allStageRange), ...args);
}
promiseStageRange(queried, ...args) {
return new Promise((resolve, reject)=>{
this.callAsyncStageRange(queried, ...args, (e, r)=>{
if (e) return reject(e);
return resolve(r);
});
});
}
promise(...args) {
return this.promiseStageRange(this.queryStageRange(allStageRange), ...args);
}
tap(options, fn) {
this._tap('sync', options, fn);
}
tapAsync(options, fn) {
this._tap('async', options, fn);
}
tapPromise(options, fn) {
this._tap('promise', options, fn);
}
_tap(type, options, fn) {
let normalizedOptions = options;
if ('string' == typeof options) normalizedOptions = {
name: options.trim()
};
else if ('object' != typeof options || null === options) throw new Error('Invalid tap options');
if ('string' != typeof normalizedOptions.name || '' === normalizedOptions.name) throw new Error('Missing name for tap');
this._insert(this._runRegisterInterceptors(Object.assign({
type,
fn
}, normalizedOptions)));
}
_insert(item) {
let before;
if ('string' == typeof item.before) before = new Set([
item.before
]);
else if (Array.isArray(item.before)) before = new Set(item.before);
let stage = 0;
if ('number' == typeof item.stage) stage = item.stage;
let i = this.taps.length;
while(i > 0){
i--;
const x = this.taps[i];
this.taps[i + 1] = x;
const xStage = x.stage || 0;
if (before) {
if (before.has(x.name)) {
before.delete(x.name);
continue;
}
if (before.size > 0) continue;
}
if (xStage > stage) continue;
i++;
break;
}
this.taps[i] = item;
}
_prepareArgs(args) {
const len = this.args.length;
if (args.length < len) {
args.length = len;
return args.fill(void 0, args.length, len);
}
if (args.length > len) args.length = len;
return args;
}
constructor(args = [], name){
_define_property(this, "args", void 0);
_define_property(this, "name", void 0);
_define_property(this, "taps", void 0);
_define_property(this, "interceptors", void 0);
this.args = args;
this.name = name;
this.taps = [];
this.interceptors = [];
}
}
const minStage = -1 / 0;
const maxStage = 1 / 0;
const allStageRange = [
minStage,
maxStage
];
const i32MIN = -(2 ** 31);
const i32MAX = 2 ** 31 - 1;
const safeStage = (stage)=>{
if (stage < i32MIN) return i32MIN;
if (stage > i32MAX) return i32MAX;
return stage;
};
class QueriedHook {
isUsed() {
if (this.tapsInRange.length > 0) return true;
if (this.stageRange[0] === minStage && this.hook.interceptors.some((i)=>i.call)) return true;
if (this.stageRange[1] === maxStage && this.hook.interceptors.some((i)=>i.done)) return true;
return false;
}
call(...args) {
if ('function' != typeof this.hook.callStageRange) throw new Error('hook is not a SyncHook, call methods only exists on SyncHook');
return this.hook.callStageRange(this, ...args);
}
callAsync(...args) {
return this.hook.callAsyncStageRange(this, ...args);
}
promise(...args) {
return this.hook.promiseStageRange(this, ...args);
}
constructor(stageRange, hook){
_define_property(this, "stageRange", void 0);
_define_property(this, "hook", void 0);
_define_property(this, "tapsInRange", void 0);
const tapsInRange = [];
const [from, to] = stageRange;
for (const tap of hook.taps){
const stage = tap.stage ?? 0;
if (from <= stage && stage < to) tapsInRange.push(tap);
else if (to === maxStage && stage === maxStage) tapsInRange.push(tap);
}
this.stageRange = stageRange;
this.hook = hook;
this.tapsInRange = tapsInRange;
}
}
class SyncHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from, to], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
try {
tap.fn(...args2);
} catch (e) {
const err = e;
this._runErrorInterceptors(err);
return cb(err);
}
}
if (to === maxStage) {
this._runDoneInterceptors();
cb(null);
}
}
call(...args) {
return this.callStageRange(this.queryStageRange(allStageRange), ...args);
}
callStageRange(queried, ...args) {
let result;
let error;
this.callAsyncStageRange(queried, ...args, (e, r)=>{
error = e;
result = r;
});
if (error) throw error;
return result;
}
tapAsync() {
throw new Error('tapAsync is not supported on a SyncHook');
}
tapPromise() {
throw new Error('tapPromise is not supported on a SyncHook');
}
}
class SyncBailHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from, to], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
let r;
try {
r = tap.fn(...args2);
} catch (e) {
const err = e;
this._runErrorInterceptors(err);
return cb(err);
}
if (void 0 !== r) {
this._runResultInterceptors(r);
return cb(null, r);
}
}
if (to === maxStage) {
this._runDoneInterceptors();
cb(null);
}
}
call(...args) {
return this.callStageRange(this.queryStageRange(allStageRange), ...args);
}
callStageRange(queried, ...args) {
let result;
let error;
this.callAsyncStageRange(queried, ...args, (e, r)=>{
error = e;
result = r;
});
if (error) throw error;
return result;
}
tapAsync() {
throw new Error('tapAsync is not supported on a SyncBailHook');
}
tapPromise() {
throw new Error('tapPromise is not supported on a SyncBailHook');
}
}
class SyncWaterfallHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from, to], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
try {
const r = tap.fn(...args2);
if (void 0 !== r) args2[0] = r;
} catch (e) {
const err = e;
this._runErrorInterceptors(err);
return cb(err);
}
}
if (to === maxStage) {
this._runDoneInterceptors();
cb(null, args2[0]);
}
}
call(...args) {
return this.callStageRange(this.queryStageRange(allStageRange), ...args);
}
callStageRange(queried, ...args) {
let result;
let error;
this.callAsyncStageRange(queried, ...args, (e, r)=>{
error = e;
result = r;
});
if (error) throw error;
return result;
}
tapAsync() {
throw new Error('tapAsync is not supported on a SyncWaterfallHook');
}
tapPromise() {
throw new Error('tapPromise is not supported on a SyncWaterfallHook');
}
constructor(args = [], name){
if (args.length < 1) throw new Error('Waterfall hooks must have at least one argument');
super(args, name);
}
}
class AsyncParallelHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const done = ()=>{
this._runDoneInterceptors();
cb(null);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
if (0 === tapsInRange.length) return done();
let counter = tapsInRange.length;
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then(()=>{
counter -= 1;
if (0 === counter) done();
}, (e)=>{
counter = 0;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e)=>{
if (e) {
counter = 0;
error(e);
} else {
counter -= 1;
if (0 === counter) done();
}
});
else {
let hasError = false;
try {
tap.fn(...args2);
} catch (e) {
hasError = true;
counter = 0;
error(e);
}
if (!hasError && 0 === --counter) done();
}
if (counter <= 0) return;
}
}
}
class AsyncSeriesHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const done = ()=>{
this._runDoneInterceptors();
cb(null);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
if (0 === tapsInRange.length) return done();
let index = 0;
const next = ()=>{
const tap = tapsInRange[index];
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then(()=>{
index += 1;
if (index === tapsInRange.length) done();
else next();
}, (e)=>{
index = tapsInRange.length;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e)=>{
if (e) {
index = tapsInRange.length;
error(e);
} else {
index += 1;
if (index === tapsInRange.length) done();
else next();
}
});
else {
let hasError = false;
try {
tap.fn(...args2);
} catch (e) {
hasError = true;
index = tapsInRange.length;
error(e);
}
if (!hasError) {
index += 1;
if (index === tapsInRange.length) done();
else next();
}
}
if (index === tapsInRange.length) return;
};
next();
}
}
class AsyncSeriesBailHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const done = ()=>{
this._runDoneInterceptors();
cb(null);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
const result = (r)=>{
this._runResultInterceptors(r);
cb(null, r);
};
if (0 === tapsInRange.length) return done();
let index = 0;
const next = ()=>{
const tap = tapsInRange[index];
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then((r)=>{
index += 1;
if (void 0 !== r) result(r);
else if (index === tapsInRange.length) done();
else next();
}, (e)=>{
index = tapsInRange.length;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e, r)=>{
if (e) {
index = tapsInRange.length;
error(e);
} else {
index += 1;
if (void 0 !== r) result(r);
else if (index === tapsInRange.length) done();
else next();
}
});
else {
let hasError = false;
let r;
try {
r = tap.fn(...args2);
} catch (e) {
hasError = true;
index = tapsInRange.length;
error(e);
}
if (!hasError) {
index += 1;
if (void 0 !== r) result(r);
else if (index === tapsInRange.length) done();
else next();
}
}
if (index === tapsInRange.length) return;
};
next();
}
}
class AsyncSeriesWaterfallHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const result = (r)=>{
this._runResultInterceptors(r);
cb(null, r);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
if (0 === tapsInRange.length) return result(args2[0]);
let index = 0;
const next = ()=>{
const tap = tapsInRange[index];
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then((r)=>{
index += 1;
if (void 0 !== r) args2[0] = r;
if (index === tapsInRange.length) result(args2[0]);
else next();
}, (e)=>{
index = tapsInRange.length;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e, r)=>{
if (e) {
index = tapsInRange.length;
error(e);
} else {
index += 1;
if (void 0 !== r) args2[0] = r;
if (index === tapsInRange.length) result(args2[0]);
else next();
}
});
else {
let hasError = false;
try {
const r = tap.fn(...args2);
if (void 0 !== r) args2[0] = r;
} catch (e) {
hasError = true;
index = tapsInRange.length;
error(e);
}
if (!hasError) {
index += 1;
if (index === tapsInRange.length) result(args2[0]);
else next();
}
}
if (index === tapsInRange.length) return;
};
next();
}
constructor(args = [], name){
if (args.length < 1) throw new Error('Waterfall hooks must have at least one argument');
super(args, name);
}
}
const defaultFactory = (key, hook)=>hook;
class HookMap {
get(key) {
return this._map.get(key);
}
for(key) {
const hook = this.get(key);
if (void 0 !== hook) return hook;
let newHook = this._factory(key);
const interceptors = this._interceptors;
for(let i = 0; i < interceptors.length; i++){
const factory = interceptors[i].factory;
if (factory) newHook = factory(key, newHook);
}
this._map.set(key, newHook);
return newHook;
}
intercept(interceptor) {
this._interceptors.push(Object.assign({
factory: defaultFactory
}, interceptor));
}
isUsed() {
for (const key of this._map.keys()){
const hook = this.get(key);
if (hook?.isUsed()) return true;
}
return false;
}
queryStageRange(stageRange) {
return new QueriedHookMap(stageRange, this);
}
constructor(factory, name){
_define_property(this, "_map", new Map());
_define_property(this, "_factory", void 0);
_define_property(this, "name", void 0);
_define_property(this, "_interceptors", void 0);
this.name = name;
this._factory = factory;
this._interceptors = [];
}
}
class QueriedHookMap {
get(key) {
return this.hookMap.get(key)?.queryStageRange(this.stageRange);
}
for(key) {
return this.hookMap.for(key).queryStageRange(this.stageRange);
}
isUsed() {
for (const key of this.hookMap._map.keys())if (this.get(key)?.isUsed()) return true;
return false;
}
constructor(stageRange, hookMap){
_define_property(this, "stageRange", void 0);
_define_property(this, "hookMap", void 0);
this.stageRange = stageRange;
this.hookMap = hookMap;
}
}
class MultiHook {
tap(options, fn) {
for (const hook of this.hooks)hook.tap(options, fn);
}
tapAsync(options, fn) {
for (const hook of this.hooks)hook.tapAsync(options, fn);
}
tapPromise(options, fn) {
for (const hook of this.hooks)hook.tapPromise(options, fn);
}
isUsed() {
for (const hook of this.hooks)if (hook.isUsed()) return true;
return false;
}
intercept(interceptor) {
for (const hook of this.hooks)hook.intercept(interceptor);
}
withOptions(options) {
return new MultiHook(this.hooks.map((h)=>h.withOptions(options)), this.name);
}
constructor(hooks, name){
_define_property(this, "hooks", void 0);
_define_property(this, "name", void 0);
this.hooks = hooks;
this.name = name;
}
}
exports.AsyncParallelHook = __webpack_exports__.AsyncParallelHook;
exports.AsyncSeriesBailHook = __webpack_exports__.AsyncSeriesBailHook;
exports.AsyncSeriesHook = __webpack_exports__.AsyncSeriesHook;
exports.AsyncSeriesWaterfallHook = __webpack_exports__.AsyncSeriesWaterfallHook;
exports.HookBase = __webpack_exports__.HookBase;
exports.HookMap = __webpack_exports__.HookMap;
exports.MultiHook = __webpack_exports__.MultiHook;
exports.QueriedHook = __webpack_exports__.QueriedHook;
exports.QueriedHookMap = __webpack_exports__.QueriedHookMap;
exports.SyncBailHook = __webpack_exports__.SyncBailHook;
exports.SyncHook = __webpack_exports__.SyncHook;
exports.SyncWaterfallHook = __webpack_exports__.SyncWaterfallHook;
exports.maxStage = __webpack_exports__.maxStage;
exports.minStage = __webpack_exports__.minStage;
exports.safeStage = __webpack_exports__.safeStage;
for(var __webpack_i__ in __webpack_exports__)if (-1 === [
"AsyncParallelHook",
"AsyncSeriesBailHook",
"AsyncSeriesHook",
"AsyncSeriesWaterfallHook",
"HookBase",
"HookMap",
"MultiHook",
"QueriedHook",
"QueriedHookMap",
"SyncBailHook",
"SyncHook",
"SyncWaterfallHook",
"maxStage",
"minStage",
"safeStage"
].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
Object.defineProperty(exports, '__esModule', {
value: true
});

175
node_modules/@rspack/lite-tapable/dist/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,175 @@
type FixedSizeArray<T extends number, U> = T extends 0 ? undefined[] : ReadonlyArray<U> & {
0: U;
length: T;
};
type Measure<T extends number> = T extends 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 ? T : never;
type Append<T extends any[], U> = {
0: [U];
1: [T[0], U];
2: [T[0], T[1], U];
3: [T[0], T[1], T[2], U];
4: [T[0], T[1], T[2], T[3], U];
5: [T[0], T[1], T[2], T[3], T[4], U];
6: [T[0], T[1], T[2], T[3], T[4], T[5], U];
7: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], U];
8: [T[0], T[1], T[2], T[3], T[4], T[5], T[6], T[7], U];
}[Measure<T['length']>];
export type AsArray<T> = T extends any[] ? T : [T];
export type Fn<T, R> = (...args: AsArray<T>) => R;
export type FnAsync<T, R> = (...args: Append<AsArray<T>, InnerCallback<Error, R>>) => void;
export type FnPromise<T, R> = (...args: AsArray<T>) => Promise<R>;
declare class UnsetAdditionalOptions {
_UnsetAdditionalOptions: true;
}
type IfSet<X> = X extends UnsetAdditionalOptions ? {} : X;
export type Callback<E, T> = (error: E | null, result?: T) => void;
type InnerCallback<E, T> = (error?: E | null | false, result?: T) => void;
type FullTap = Tap & {
type: 'sync' | 'async' | 'promise';
fn: Function;
};
type Tap = TapOptions & {
name: string;
};
type TapOptions = {
before?: string;
stage?: number;
};
export type Options<AdditionalOptions = UnsetAdditionalOptions> = string | (Tap & IfSet<AdditionalOptions>);
export interface HookInterceptor<T, R, AdditionalOptions = UnsetAdditionalOptions> {
name?: string;
tap?: (tap: FullTap & IfSet<AdditionalOptions>) => void;
call?: (...args: any[]) => void;
loop?: (...args: any[]) => void;
error?: (err: Error) => void;
result?: (result: R) => void;
done?: () => void;
register?: (tap: FullTap & IfSet<AdditionalOptions>) => FullTap & IfSet<AdditionalOptions>;
}
type ArgumentNames<T extends any[]> = FixedSizeArray<T['length'], string>;
type ExtractHookArgs<H> = H extends Hook<infer T, any> ? T : never;
type ExtractHookReturn<H> = H extends Hook<any, infer R> ? R : never;
type ExtractHookAdditionalOptions<H> = H extends Hook<any, any, infer A> ? A : never;
export interface Hook<T = any, R = any, AdditionalOptions = UnsetAdditionalOptions> {
name?: string;
tap(opt: Options<AdditionalOptions>, fn: Fn<T, R>): void;
tapAsync(opt: Options<AdditionalOptions>, fn: FnAsync<T, R>): void;
tapPromise(opt: Options<AdditionalOptions>, fn: FnPromise<T, R>): void;
intercept(interceptor: HookInterceptor<T, R, AdditionalOptions>): void;
isUsed(): boolean;
withOptions(opt: TapOptions & IfSet<AdditionalOptions>): Hook<T, R, AdditionalOptions>;
queryStageRange(stageRange: StageRange): QueriedHook<T, R, AdditionalOptions>;
}
export declare class HookBase<T, R, AdditionalOptions = UnsetAdditionalOptions> implements Hook<T, R, AdditionalOptions> {
args: ArgumentNames<AsArray<T>>;
name?: string;
taps: (FullTap & IfSet<AdditionalOptions>)[];
interceptors: HookInterceptor<T, R, AdditionalOptions>[];
constructor(args?: ArgumentNames<AsArray<T>>, name?: string);
intercept(interceptor: HookInterceptor<T, R, AdditionalOptions>): void;
_runRegisterInterceptors(options: FullTap & IfSet<AdditionalOptions>): FullTap & IfSet<AdditionalOptions>;
_runCallInterceptors(...args: any[]): void;
_runErrorInterceptors(e: Error): void;
_runTapInterceptors(tap: FullTap & IfSet<AdditionalOptions>): void;
_runDoneInterceptors(): void;
_runResultInterceptors(r: R): void;
withOptions(options: TapOptions & IfSet<AdditionalOptions>): Hook<T, R, AdditionalOptions>;
isUsed(): boolean;
queryStageRange(stageRange: StageRange): QueriedHook<T, R, AdditionalOptions>;
callAsyncStageRange(queried: QueriedHook<T, R, AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, R>>): void;
callAsync(...args: Append<AsArray<T>, Callback<Error, R>>): void;
promiseStageRange(queried: QueriedHook<T, R, AdditionalOptions>, ...args: AsArray<T>): Promise<R>;
promise(...args: AsArray<T>): Promise<R>;
tap(options: Options<AdditionalOptions>, fn: Fn<T, R>): void;
tapAsync(options: Options<AdditionalOptions>, fn: FnAsync<T, R>): void;
tapPromise(options: Options<AdditionalOptions>, fn: FnPromise<T, R>): void;
_tap(type: 'sync' | 'async' | 'promise', options: Options<AdditionalOptions>, fn: Function): void;
_insert(item: FullTap & IfSet<AdditionalOptions>): void;
_prepareArgs(args: AsArray<T>): (T | undefined)[];
}
export type StageRange = readonly [number, number];
export declare const minStage: number;
export declare const maxStage: number;
export declare const safeStage: (stage: number) => number;
export declare class QueriedHook<T, R, AdditionalOptions = UnsetAdditionalOptions> {
stageRange: StageRange;
hook: HookBase<T, R, AdditionalOptions>;
tapsInRange: (FullTap & IfSet<AdditionalOptions>)[];
constructor(stageRange: StageRange, hook: HookBase<T, R, AdditionalOptions>);
isUsed(): boolean;
call(...args: AsArray<T>): R;
callAsync(...args: Append<AsArray<T>, Callback<Error, R>>): void;
promise(...args: AsArray<T>): Promise<R>;
}
export declare class SyncHook<T, R = void, AdditionalOptions = UnsetAdditionalOptions> extends HookBase<T, R, AdditionalOptions> {
callAsyncStageRange(queried: QueriedHook<T, R, AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, R>>): void;
call(...args: AsArray<T>): R;
callStageRange(queried: QueriedHook<T, R, AdditionalOptions>, ...args: AsArray<T>): R;
tapAsync(): never;
tapPromise(): never;
}
export declare class SyncBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends HookBase<T, R, AdditionalOptions> {
callAsyncStageRange(queried: QueriedHook<T, R, AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, R>>): void;
call(...args: AsArray<T>): R;
callStageRange(queried: QueriedHook<T, R, AdditionalOptions>, ...args: AsArray<T>): R;
tapAsync(): never;
tapPromise(): never;
}
export declare class SyncWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends HookBase<T, AsArray<T>[0], AdditionalOptions> {
constructor(args?: ArgumentNames<AsArray<T>>, name?: string);
callAsyncStageRange(queried: QueriedHook<T, AsArray<T>[0], AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, AsArray<T>[0]>>): void;
call(...args: AsArray<T>): AsArray<T>[0];
callStageRange(queried: QueriedHook<T, AsArray<T>[0], AdditionalOptions>, ...args: AsArray<T>): AsArray<T>[0];
tapAsync(): never;
tapPromise(): never;
}
export declare class AsyncParallelHook<T, AdditionalOptions = UnsetAdditionalOptions> extends HookBase<T, void, AdditionalOptions> {
callAsyncStageRange(queried: QueriedHook<T, void, AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, void>>): void;
}
export declare class AsyncSeriesHook<T, AdditionalOptions = UnsetAdditionalOptions> extends HookBase<T, void, AdditionalOptions> {
callAsyncStageRange(queried: QueriedHook<T, void, AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, void>>): void;
}
export declare class AsyncSeriesBailHook<T, R, AdditionalOptions = UnsetAdditionalOptions> extends HookBase<T, R, AdditionalOptions> {
callAsyncStageRange(queried: QueriedHook<T, R, AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, R>>): void;
}
export declare class AsyncSeriesWaterfallHook<T, AdditionalOptions = UnsetAdditionalOptions> extends HookBase<T, AsArray<T>[0], AdditionalOptions> {
constructor(args?: ArgumentNames<AsArray<T>>, name?: string);
callAsyncStageRange(queried: QueriedHook<T, AsArray<T>[0], AdditionalOptions>, ...args: Append<AsArray<T>, Callback<Error, AsArray<T>[0]>>): void;
}
export type HookMapKey = any;
export type HookFactory<H> = (key: HookMapKey, hook?: H) => H;
export interface HookMapInterceptor<H> {
factory?: HookFactory<H>;
}
export declare class HookMap<H extends Hook> {
_map: Map<HookMapKey, H>;
_factory: HookFactory<H>;
name?: string;
_interceptors: HookMapInterceptor<H>[];
constructor(factory: HookFactory<H>, name?: string);
get(key: HookMapKey): H | undefined;
for(key: HookMapKey): H;
intercept(interceptor: HookMapInterceptor<H>): void;
isUsed(): boolean;
queryStageRange(stageRange: StageRange): QueriedHookMap<H>;
}
export declare class QueriedHookMap<H extends Hook> {
stageRange: StageRange;
hookMap: HookMap<H>;
constructor(stageRange: StageRange, hookMap: HookMap<H>);
get(key: HookMapKey): QueriedHook<any, any, UnsetAdditionalOptions> | undefined;
for(key: HookMapKey): QueriedHook<any, any, UnsetAdditionalOptions>;
isUsed(): boolean;
}
export declare class MultiHook<H extends Hook> {
hooks: H[];
name?: string;
constructor(hooks: H[], name?: string);
tap(options: Options<ExtractHookAdditionalOptions<Hook>>, fn: Fn<ExtractHookArgs<Hook>, ExtractHookReturn<Hook>>): void;
tapAsync(options: Options<ExtractHookAdditionalOptions<Hook>>, fn: FnAsync<ExtractHookArgs<Hook>, ExtractHookReturn<Hook>>): void;
tapPromise(options: Options<ExtractHookAdditionalOptions<Hook>>, fn: FnPromise<ExtractHookArgs<Hook>, ExtractHookReturn<Hook>>): void;
isUsed(): boolean;
intercept(interceptor: HookInterceptor<ExtractHookArgs<Hook>, ExtractHookReturn<Hook>, ExtractHookAdditionalOptions<Hook>>): void;
withOptions(options: TapOptions & IfSet<ExtractHookAdditionalOptions<Hook>>): MultiHook<Hook<any, any, UnsetAdditionalOptions>>;
}
export {};

660
node_modules/@rspack/lite-tapable/dist/index.js generated vendored Normal file
View File

@@ -0,0 +1,660 @@
function _define_property(obj, key, value) {
if (key in obj) Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
else obj[key] = value;
return obj;
}
class HookBase {
intercept(interceptor) {
this.interceptors.push(Object.assign({}, interceptor));
if (interceptor.register) for(let i = 0; i < this.taps.length; i++)this.taps[i] = interceptor.register(this.taps[i]);
}
_runRegisterInterceptors(options) {
return this.interceptors.reduce((options, interceptor)=>interceptor.register?.(options) ?? options, options);
}
_runCallInterceptors(...args) {
for (const interceptor of this.interceptors)if (interceptor.call) interceptor.call(...args);
}
_runErrorInterceptors(e) {
for (const interceptor of this.interceptors)if (interceptor.error) interceptor.error(e);
}
_runTapInterceptors(tap) {
for (const interceptor of this.interceptors)if (interceptor.tap) interceptor.tap(tap);
}
_runDoneInterceptors() {
for (const interceptor of this.interceptors)if (interceptor.done) interceptor.done();
}
_runResultInterceptors(r) {
for (const interceptor of this.interceptors)if (interceptor.result) interceptor.result(r);
}
withOptions(options) {
const mergeOptions = (opt)=>Object.assign({}, options, 'string' == typeof opt ? {
name: opt
} : opt);
return {
name: this.name,
tap: (opt, fn)=>this.tap(mergeOptions(opt), fn),
tapAsync: (opt, fn)=>this.tapAsync(mergeOptions(opt), fn),
tapPromise: (opt, fn)=>this.tapPromise(mergeOptions(opt), fn),
intercept: (interceptor)=>this.intercept(interceptor),
isUsed: ()=>this.isUsed(),
withOptions: (opt)=>this.withOptions(mergeOptions(opt)),
queryStageRange: (stageRange)=>this.queryStageRange(stageRange)
};
}
isUsed() {
return this.taps.length > 0 || this.interceptors.length > 0;
}
queryStageRange(stageRange) {
return new QueriedHook(stageRange, this);
}
callAsyncStageRange(queried) {
throw new Error('Hook should implement there own _callAsyncStageRange');
}
callAsync(...args) {
return this.callAsyncStageRange(this.queryStageRange(allStageRange), ...args);
}
promiseStageRange(queried, ...args) {
return new Promise((resolve, reject)=>{
this.callAsyncStageRange(queried, ...args, (e, r)=>{
if (e) return reject(e);
return resolve(r);
});
});
}
promise(...args) {
return this.promiseStageRange(this.queryStageRange(allStageRange), ...args);
}
tap(options, fn) {
this._tap('sync', options, fn);
}
tapAsync(options, fn) {
this._tap('async', options, fn);
}
tapPromise(options, fn) {
this._tap('promise', options, fn);
}
_tap(type, options, fn) {
let normalizedOptions = options;
if ('string' == typeof options) normalizedOptions = {
name: options.trim()
};
else if ('object' != typeof options || null === options) throw new Error('Invalid tap options');
if ('string' != typeof normalizedOptions.name || '' === normalizedOptions.name) throw new Error('Missing name for tap');
this._insert(this._runRegisterInterceptors(Object.assign({
type,
fn
}, normalizedOptions)));
}
_insert(item) {
let before;
if ('string' == typeof item.before) before = new Set([
item.before
]);
else if (Array.isArray(item.before)) before = new Set(item.before);
let stage = 0;
if ('number' == typeof item.stage) stage = item.stage;
let i = this.taps.length;
while(i > 0){
i--;
const x = this.taps[i];
this.taps[i + 1] = x;
const xStage = x.stage || 0;
if (before) {
if (before.has(x.name)) {
before.delete(x.name);
continue;
}
if (before.size > 0) continue;
}
if (xStage > stage) continue;
i++;
break;
}
this.taps[i] = item;
}
_prepareArgs(args) {
const len = this.args.length;
if (args.length < len) {
args.length = len;
return args.fill(void 0, args.length, len);
}
if (args.length > len) args.length = len;
return args;
}
constructor(args = [], name){
_define_property(this, "args", void 0);
_define_property(this, "name", void 0);
_define_property(this, "taps", void 0);
_define_property(this, "interceptors", void 0);
this.args = args;
this.name = name;
this.taps = [];
this.interceptors = [];
}
}
const minStage = -1 / 0;
const maxStage = 1 / 0;
const allStageRange = [
minStage,
maxStage
];
const i32MIN = -(2 ** 31);
const i32MAX = 2 ** 31 - 1;
const safeStage = (stage)=>{
if (stage < i32MIN) return i32MIN;
if (stage > i32MAX) return i32MAX;
return stage;
};
class QueriedHook {
isUsed() {
if (this.tapsInRange.length > 0) return true;
if (this.stageRange[0] === minStage && this.hook.interceptors.some((i)=>i.call)) return true;
if (this.stageRange[1] === maxStage && this.hook.interceptors.some((i)=>i.done)) return true;
return false;
}
call(...args) {
if ('function' != typeof this.hook.callStageRange) throw new Error('hook is not a SyncHook, call methods only exists on SyncHook');
return this.hook.callStageRange(this, ...args);
}
callAsync(...args) {
return this.hook.callAsyncStageRange(this, ...args);
}
promise(...args) {
return this.hook.promiseStageRange(this, ...args);
}
constructor(stageRange, hook){
_define_property(this, "stageRange", void 0);
_define_property(this, "hook", void 0);
_define_property(this, "tapsInRange", void 0);
const tapsInRange = [];
const [from, to] = stageRange;
for (const tap of hook.taps){
const stage = tap.stage ?? 0;
if (from <= stage && stage < to) tapsInRange.push(tap);
else if (to === maxStage && stage === maxStage) tapsInRange.push(tap);
}
this.stageRange = stageRange;
this.hook = hook;
this.tapsInRange = tapsInRange;
}
}
class SyncHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from, to], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
try {
tap.fn(...args2);
} catch (e) {
const err = e;
this._runErrorInterceptors(err);
return cb(err);
}
}
if (to === maxStage) {
this._runDoneInterceptors();
cb(null);
}
}
call(...args) {
return this.callStageRange(this.queryStageRange(allStageRange), ...args);
}
callStageRange(queried, ...args) {
let result;
let error;
this.callAsyncStageRange(queried, ...args, (e, r)=>{
error = e;
result = r;
});
if (error) throw error;
return result;
}
tapAsync() {
throw new Error('tapAsync is not supported on a SyncHook');
}
tapPromise() {
throw new Error('tapPromise is not supported on a SyncHook');
}
}
class SyncBailHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from, to], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
let r;
try {
r = tap.fn(...args2);
} catch (e) {
const err = e;
this._runErrorInterceptors(err);
return cb(err);
}
if (void 0 !== r) {
this._runResultInterceptors(r);
return cb(null, r);
}
}
if (to === maxStage) {
this._runDoneInterceptors();
cb(null);
}
}
call(...args) {
return this.callStageRange(this.queryStageRange(allStageRange), ...args);
}
callStageRange(queried, ...args) {
let result;
let error;
this.callAsyncStageRange(queried, ...args, (e, r)=>{
error = e;
result = r;
});
if (error) throw error;
return result;
}
tapAsync() {
throw new Error('tapAsync is not supported on a SyncBailHook');
}
tapPromise() {
throw new Error('tapPromise is not supported on a SyncBailHook');
}
}
class SyncWaterfallHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from, to], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
try {
const r = tap.fn(...args2);
if (void 0 !== r) args2[0] = r;
} catch (e) {
const err = e;
this._runErrorInterceptors(err);
return cb(err);
}
}
if (to === maxStage) {
this._runDoneInterceptors();
cb(null, args2[0]);
}
}
call(...args) {
return this.callStageRange(this.queryStageRange(allStageRange), ...args);
}
callStageRange(queried, ...args) {
let result;
let error;
this.callAsyncStageRange(queried, ...args, (e, r)=>{
error = e;
result = r;
});
if (error) throw error;
return result;
}
tapAsync() {
throw new Error('tapAsync is not supported on a SyncWaterfallHook');
}
tapPromise() {
throw new Error('tapPromise is not supported on a SyncWaterfallHook');
}
constructor(args = [], name){
if (args.length < 1) throw new Error('Waterfall hooks must have at least one argument');
super(args, name);
}
}
class AsyncParallelHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const done = ()=>{
this._runDoneInterceptors();
cb(null);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
if (0 === tapsInRange.length) return done();
let counter = tapsInRange.length;
for (const tap of tapsInRange){
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then(()=>{
counter -= 1;
if (0 === counter) done();
}, (e)=>{
counter = 0;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e)=>{
if (e) {
counter = 0;
error(e);
} else {
counter -= 1;
if (0 === counter) done();
}
});
else {
let hasError = false;
try {
tap.fn(...args2);
} catch (e) {
hasError = true;
counter = 0;
error(e);
}
if (!hasError && 0 === --counter) done();
}
if (counter <= 0) return;
}
}
}
class AsyncSeriesHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const done = ()=>{
this._runDoneInterceptors();
cb(null);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
if (0 === tapsInRange.length) return done();
let index = 0;
const next = ()=>{
const tap = tapsInRange[index];
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then(()=>{
index += 1;
if (index === tapsInRange.length) done();
else next();
}, (e)=>{
index = tapsInRange.length;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e)=>{
if (e) {
index = tapsInRange.length;
error(e);
} else {
index += 1;
if (index === tapsInRange.length) done();
else next();
}
});
else {
let hasError = false;
try {
tap.fn(...args2);
} catch (e) {
hasError = true;
index = tapsInRange.length;
error(e);
}
if (!hasError) {
index += 1;
if (index === tapsInRange.length) done();
else next();
}
}
if (index === tapsInRange.length) return;
};
next();
}
}
class AsyncSeriesBailHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const done = ()=>{
this._runDoneInterceptors();
cb(null);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
const result = (r)=>{
this._runResultInterceptors(r);
cb(null, r);
};
if (0 === tapsInRange.length) return done();
let index = 0;
const next = ()=>{
const tap = tapsInRange[index];
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then((r)=>{
index += 1;
if (void 0 !== r) result(r);
else if (index === tapsInRange.length) done();
else next();
}, (e)=>{
index = tapsInRange.length;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e, r)=>{
if (e) {
index = tapsInRange.length;
error(e);
} else {
index += 1;
if (void 0 !== r) result(r);
else if (index === tapsInRange.length) done();
else next();
}
});
else {
let hasError = false;
let r;
try {
r = tap.fn(...args2);
} catch (e) {
hasError = true;
index = tapsInRange.length;
error(e);
}
if (!hasError) {
index += 1;
if (void 0 !== r) result(r);
else if (index === tapsInRange.length) done();
else next();
}
}
if (index === tapsInRange.length) return;
};
next();
}
}
class AsyncSeriesWaterfallHook extends HookBase {
callAsyncStageRange(queried, ...args) {
const { stageRange: [from], tapsInRange } = queried;
const argsWithoutCb = args.slice(0, args.length - 1);
const cb = args[args.length - 1];
const args2 = this._prepareArgs(argsWithoutCb);
if (from === minStage) this._runCallInterceptors(...args2);
const result = (r)=>{
this._runResultInterceptors(r);
cb(null, r);
};
const error = (e)=>{
this._runErrorInterceptors(e);
cb(e);
};
if (0 === tapsInRange.length) return result(args2[0]);
let index = 0;
const next = ()=>{
const tap = tapsInRange[index];
this._runTapInterceptors(tap);
if ('promise' === tap.type) {
const promise = tap.fn(...args2);
if (!promise || !promise.then) throw new Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
promise.then((r)=>{
index += 1;
if (void 0 !== r) args2[0] = r;
if (index === tapsInRange.length) result(args2[0]);
else next();
}, (e)=>{
index = tapsInRange.length;
error(e);
});
} else if ('async' === tap.type) tap.fn(...args2, (e, r)=>{
if (e) {
index = tapsInRange.length;
error(e);
} else {
index += 1;
if (void 0 !== r) args2[0] = r;
if (index === tapsInRange.length) result(args2[0]);
else next();
}
});
else {
let hasError = false;
try {
const r = tap.fn(...args2);
if (void 0 !== r) args2[0] = r;
} catch (e) {
hasError = true;
index = tapsInRange.length;
error(e);
}
if (!hasError) {
index += 1;
if (index === tapsInRange.length) result(args2[0]);
else next();
}
}
if (index === tapsInRange.length) return;
};
next();
}
constructor(args = [], name){
if (args.length < 1) throw new Error('Waterfall hooks must have at least one argument');
super(args, name);
}
}
const defaultFactory = (key, hook)=>hook;
class HookMap {
get(key) {
return this._map.get(key);
}
for(key) {
const hook = this.get(key);
if (void 0 !== hook) return hook;
let newHook = this._factory(key);
const interceptors = this._interceptors;
for(let i = 0; i < interceptors.length; i++){
const factory = interceptors[i].factory;
if (factory) newHook = factory(key, newHook);
}
this._map.set(key, newHook);
return newHook;
}
intercept(interceptor) {
this._interceptors.push(Object.assign({
factory: defaultFactory
}, interceptor));
}
isUsed() {
for (const key of this._map.keys()){
const hook = this.get(key);
if (hook?.isUsed()) return true;
}
return false;
}
queryStageRange(stageRange) {
return new QueriedHookMap(stageRange, this);
}
constructor(factory, name){
_define_property(this, "_map", new Map());
_define_property(this, "_factory", void 0);
_define_property(this, "name", void 0);
_define_property(this, "_interceptors", void 0);
this.name = name;
this._factory = factory;
this._interceptors = [];
}
}
class QueriedHookMap {
get(key) {
return this.hookMap.get(key)?.queryStageRange(this.stageRange);
}
for(key) {
return this.hookMap.for(key).queryStageRange(this.stageRange);
}
isUsed() {
for (const key of this.hookMap._map.keys())if (this.get(key)?.isUsed()) return true;
return false;
}
constructor(stageRange, hookMap){
_define_property(this, "stageRange", void 0);
_define_property(this, "hookMap", void 0);
this.stageRange = stageRange;
this.hookMap = hookMap;
}
}
class MultiHook {
tap(options, fn) {
for (const hook of this.hooks)hook.tap(options, fn);
}
tapAsync(options, fn) {
for (const hook of this.hooks)hook.tapAsync(options, fn);
}
tapPromise(options, fn) {
for (const hook of this.hooks)hook.tapPromise(options, fn);
}
isUsed() {
for (const hook of this.hooks)if (hook.isUsed()) return true;
return false;
}
intercept(interceptor) {
for (const hook of this.hooks)hook.intercept(interceptor);
}
withOptions(options) {
return new MultiHook(this.hooks.map((h)=>h.withOptions(options)), this.name);
}
constructor(hooks, name){
_define_property(this, "hooks", void 0);
_define_property(this, "name", void 0);
this.hooks = hooks;
this.name = name;
}
}
export { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesWaterfallHook, HookBase, HookMap, MultiHook, QueriedHook, QueriedHookMap, SyncBailHook, SyncHook, SyncWaterfallHook, maxStage, minStage, safeStage };

51
node_modules/@rspack/lite-tapable/package.json generated vendored Normal file
View File

@@ -0,0 +1,51 @@
{
"name": "@rspack/lite-tapable",
"version": "1.1.0",
"repository": "https://github.com/rspack-contrib/rspack-lite-tapable",
"license": "MIT",
"description": "Lite weight tapable for Rspack",
"type": "module",
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
},
"scripts": {
"build": "rslib build",
"dev": "rslib build --watch",
"lint": "biome check .",
"lint:write": "biome check . --write",
"prepare": "simple-git-hooks && npm run build",
"test": "rstest run",
"bump": "npx bumpp"
},
"files": ["dist"],
"simple-git-hooks": {
"pre-commit": "npx nano-staged"
},
"nano-staged": {
"*.{js,jsx,ts,tsx,mjs,cjs}": [
"biome check --write --no-errors-on-unmatched"
]
},
"devDependencies": {
"@biomejs/biome": "^1.9.4",
"@rslib/core": "^0.17.1",
"@rspack/core": "^1.6.0",
"@rstest/core": "0.6.1",
"@types/node": "^22.18.13",
"nano-staged": "^0.8.0",
"simple-git-hooks": "^2.13.1",
"typescript": "5.9.3"
},
"packageManager": "pnpm@10.20.0",
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}