@eggjs/mock 6.1.0-beta.9 → 7.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/README.md +1 -1
  2. package/README.zh_CN.md +1 -1
  3. package/dist/_virtual/rolldown_runtime.js +1 -24
  4. package/dist/inject_mocha.d.ts +1 -1
  5. package/dist/inject_mocha.js +2 -3
  6. package/dist/lib/context.js +1 -3
  7. package/package.json +8 -11
  8. package/dist/node_modules/.pnpm/ansi-styles@4.3.0/node_modules/ansi-styles/index.js +0 -142
  9. package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/index.js +0 -157
  10. package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/templates.js +0 -97
  11. package/dist/node_modules/.pnpm/chalk@4.1.2/node_modules/chalk/source/util.js +0 -40
  12. package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/conversions.js +0 -814
  13. package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/index.js +0 -50
  14. package/dist/node_modules/.pnpm/color-convert@2.0.1/node_modules/color-convert/route.js +0 -68
  15. package/dist/node_modules/.pnpm/color-name@1.1.4/node_modules/color-name/index.js +0 -752
  16. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/browser.js +0 -203
  17. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/common.js +0 -209
  18. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/index.js +0 -18
  19. package/dist/node_modules/.pnpm/debug@4.4.3_supports-color@8.1.1/node_modules/debug/src/node.js +0 -215
  20. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/dmp.js +0 -24
  21. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/convert/xml.js +0 -33
  22. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/array.js +0 -29
  23. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/base.js +0 -185
  24. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/character.js +0 -23
  25. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/css.js +0 -26
  26. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/json.js +0 -83
  27. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/line.js +0 -51
  28. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/sentence.js +0 -26
  29. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/diff/word.js +0 -151
  30. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/index.js +0 -178
  31. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/apply.js +0 -168
  32. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/create.js +0 -301
  33. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/line-endings.js +0 -137
  34. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/merge.js +0 -367
  35. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/parse.js +0 -91
  36. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/patch/reverse.js +0 -99
  37. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/array.js +0 -23
  38. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/distance-iterator.js +0 -30
  39. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/params.js +0 -22
  40. package/dist/node_modules/.pnpm/diff@7.0.0/node_modules/diff/lib/util/string.js +0 -97
  41. package/dist/node_modules/.pnpm/escape-string-regexp@4.0.0/node_modules/escape-string-regexp/index.js +0 -14
  42. package/dist/node_modules/.pnpm/has-flag@4.0.0/node_modules/has-flag/index.js +0 -16
  43. package/dist/node_modules/.pnpm/he@1.2.0/node_modules/he/he.js +0 -4093
  44. package/dist/node_modules/.pnpm/is-unicode-supported@0.1.0/node_modules/is-unicode-supported/index.js +0 -14
  45. package/dist/node_modules/.pnpm/log-symbols@4.1.0/node_modules/log-symbols/index.js +0 -27
  46. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/index.js +0 -12
  47. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/context.js +0 -83
  48. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/error-constants.js +0 -35
  49. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/errors.js +0 -392
  50. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/hook.js +0 -86
  51. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/bdd.js +0 -104
  52. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/common.js +0 -99
  53. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/exports.js +0 -65
  54. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/index.js +0 -18
  55. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/qunit.js +0 -95
  56. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/interfaces/tdd.js +0 -105
  57. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocha.js +0 -1037
  58. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/mocharc.js +0 -24
  59. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/buffered-worker-pool.js +0 -152
  60. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/esm-utils.js +0 -74
  61. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/file-unloader.js +0 -22
  62. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/parallel-buffered-runner.js +0 -329
  63. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/nodejs/serializer.js +0 -314
  64. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/pending.js +0 -22
  65. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/base.js +0 -417
  66. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/doc.js +0 -79
  67. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/dot.js +0 -75
  68. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/html.js +0 -283
  69. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/index.js +0 -40
  70. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json-stream.js +0 -90
  71. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/json.js +0 -145
  72. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/landing.js +0 -107
  73. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/list.js +0 -77
  74. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/markdown.js +0 -106
  75. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/min.js +0 -57
  76. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/nyan.js +0 -233
  77. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/progress.js +0 -92
  78. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/spec.js +0 -91
  79. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/tap.js +0 -261
  80. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/reporters/xunit.js +0 -166
  81. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runnable.js +0 -346
  82. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/runner.js +0 -922
  83. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/stats-collector.js +0 -72
  84. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/suite.js +0 -517
  85. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/test.js +0 -105
  86. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/lib/utils.js +0 -505
  87. package/dist/node_modules/.pnpm/mocha@11.7.2/node_modules/mocha/package.js +0 -225
  88. package/dist/node_modules/.pnpm/ms@2.1.3/node_modules/ms/index.js +0 -124
  89. package/dist/node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js +0 -11
  90. package/dist/node_modules/.pnpm/serialize-javascript@6.0.2/node_modules/serialize-javascript/index.js +0 -114
  91. package/dist/node_modules/.pnpm/supports-color@7.2.0/node_modules/supports-color/index.js +0 -76
  92. package/dist/node_modules/.pnpm/supports-color@8.1.1/node_modules/supports-color/index.js +0 -89
  93. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js +0 -366
  94. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js +0 -248
  95. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/WorkerHandler.js +0 -419
  96. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/debug-port-allocator.js +0 -27
  97. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/environment.js +0 -18
  98. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/generated/embeddedWorker.js +0 -16
  99. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/index.js +0 -63
  100. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/transfer.js +0 -21
  101. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/validateOptions.js +0 -9
  102. package/dist/node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/worker.js +0 -277
@@ -1,366 +0,0 @@
1
- import { __commonJS } from "../../../../../../_virtual/rolldown_runtime.js";
2
- import { require_environment } from "./environment.js";
3
- import { require_Promise } from "./Promise.js";
4
- import { require_WorkerHandler } from "./WorkerHandler.js";
5
- import { require_debug_port_allocator } from "./debug-port-allocator.js";
6
-
7
- //#region ../../node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js
8
- var require_Pool = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Pool.js": ((exports, module) => {
9
- var { Promise: Promise$1 } = require_Promise();
10
- var WorkerHandler = require_WorkerHandler();
11
- var environment = require_environment();
12
- var DEBUG_PORT_ALLOCATOR = new (require_debug_port_allocator())();
13
- /**
14
- * A pool to manage workers, which can be created using the function workerpool.pool.
15
- *
16
- * @param {String} [script] Optional worker script
17
- * @param {import('./types.js').WorkerPoolOptions} [options] See docs
18
- * @constructor
19
- */
20
- function Pool(script, options) {
21
- if (typeof script === "string")
22
- /** @readonly */
23
- this.script = script || null;
24
- else {
25
- this.script = null;
26
- options = script;
27
- }
28
- /** @private */
29
- this.workers = [];
30
- /** @private */
31
- this.tasks = [];
32
- options = options || {};
33
- /** @readonly */
34
- this.forkArgs = Object.freeze(options.forkArgs || []);
35
- /** @readonly */
36
- this.forkOpts = Object.freeze(options.forkOpts || {});
37
- /** @readonly */
38
- this.workerOpts = Object.freeze(options.workerOpts || {});
39
- /** @readonly */
40
- this.workerThreadOpts = Object.freeze(options.workerThreadOpts || {});
41
- /** @private */
42
- this.debugPortStart = options.debugPortStart || 43210;
43
- /** @readonly @deprecated */
44
- this.nodeWorker = options.nodeWorker;
45
- /** @readonly
46
- * @type {'auto' | 'web' | 'process' | 'thread'}
47
- */
48
- this.workerType = options.workerType || options.nodeWorker || "auto";
49
- /** @readonly */
50
- this.maxQueueSize = options.maxQueueSize || Infinity;
51
- /** @readonly */
52
- this.workerTerminateTimeout = options.workerTerminateTimeout || 1e3;
53
- /** @readonly */
54
- this.onCreateWorker = options.onCreateWorker || (() => null);
55
- /** @readonly */
56
- this.onTerminateWorker = options.onTerminateWorker || (() => null);
57
- /** @readonly */
58
- this.emitStdStreams = options.emitStdStreams || false;
59
- if (options && "maxWorkers" in options) {
60
- validateMaxWorkers(options.maxWorkers);
61
- /** @readonly */
62
- this.maxWorkers = options.maxWorkers;
63
- } else this.maxWorkers = Math.max((environment.cpus || 4) - 1, 1);
64
- if (options && "minWorkers" in options) {
65
- if (options.minWorkers === "max")
66
- /** @readonly */
67
- this.minWorkers = this.maxWorkers;
68
- else {
69
- validateMinWorkers(options.minWorkers);
70
- this.minWorkers = options.minWorkers;
71
- this.maxWorkers = Math.max(this.minWorkers, this.maxWorkers);
72
- }
73
- this._ensureMinWorkers();
74
- }
75
- /** @private */
76
- this._boundNext = this._next.bind(this);
77
- if (this.workerType === "thread") WorkerHandler.ensureWorkerThreads();
78
- }
79
- /**
80
- * Execute a function on a worker.
81
- *
82
- * Example usage:
83
- *
84
- * var pool = new Pool()
85
- *
86
- * // call a function available on the worker
87
- * pool.exec('fibonacci', [6])
88
- *
89
- * // offload a function
90
- * function add(a, b) {
91
- * return a + b
92
- * };
93
- * pool.exec(add, [2, 4])
94
- * .then(function (result) {
95
- * console.log(result); // outputs 6
96
- * })
97
- * .catch(function(error) {
98
- * console.log(error);
99
- * });
100
- * @template { (...args: any[]) => any } T
101
- * @param {String | T} method Function name or function.
102
- * If `method` is a string, the corresponding
103
- * method on the worker will be executed
104
- * If `method` is a Function, the function
105
- * will be stringified and executed via the
106
- * workers built-in function `run(fn, args)`.
107
- * @param {Parameters<T> | null} [params] Function arguments applied when calling the function
108
- * @param {import('./types.js').ExecOptions} [options] Options
109
- * @return {Promise<ReturnType<T>>}
110
- */
111
- Pool.prototype.exec = function(method, params, options) {
112
- if (params && !Array.isArray(params)) throw new TypeError("Array expected as argument \"params\"");
113
- if (typeof method === "string") {
114
- var resolver = Promise$1.defer();
115
- if (this.tasks.length >= this.maxQueueSize) throw new Error("Max queue size of " + this.maxQueueSize + " reached");
116
- var tasks = this.tasks;
117
- var task = {
118
- method,
119
- params,
120
- resolver,
121
- timeout: null,
122
- options
123
- };
124
- tasks.push(task);
125
- var originalTimeout = resolver.promise.timeout;
126
- resolver.promise.timeout = function timeout(delay) {
127
- if (tasks.indexOf(task) !== -1) {
128
- task.timeout = delay;
129
- return resolver.promise;
130
- } else return originalTimeout.call(resolver.promise, delay);
131
- };
132
- this._next();
133
- return resolver.promise;
134
- } else if (typeof method === "function") return this.exec("run", [String(method), params], options);
135
- else throw new TypeError("Function or string expected as argument \"method\"");
136
- };
137
- /**
138
- * Create a proxy for current worker. Returns an object containing all
139
- * methods available on the worker. All methods return promises resolving the methods result.
140
- * @template { { [k: string]: (...args: any[]) => any } } T
141
- * @return {Promise<import('./types.js').Proxy<T>, Error>} Returns a promise which resolves with a proxy object
142
- */
143
- Pool.prototype.proxy = function() {
144
- if (arguments.length > 0) throw new Error("No arguments expected");
145
- var pool = this;
146
- return this.exec("methods").then(function(methods) {
147
- var proxy = {};
148
- methods.forEach(function(method) {
149
- proxy[method] = function() {
150
- return pool.exec(method, Array.prototype.slice.call(arguments));
151
- };
152
- });
153
- return proxy;
154
- });
155
- };
156
- /**
157
- * Creates new array with the results of calling a provided callback function
158
- * on every element in this array.
159
- * @param {Array} array
160
- * @param {function} callback Function taking two arguments:
161
- * `callback(currentValue, index)`
162
- * @return {Promise.<Array>} Returns a promise which resolves with an Array
163
- * containing the results of the callback function
164
- * executed for each of the array elements.
165
- */
166
- /**
167
- * Grab the first task from the queue, find a free worker, and assign the
168
- * worker to the task.
169
- * @private
170
- */
171
- Pool.prototype._next = function() {
172
- if (this.tasks.length > 0) {
173
- var worker = this._getWorker();
174
- if (worker) {
175
- var me = this;
176
- var task = this.tasks.shift();
177
- if (task.resolver.promise.pending) {
178
- var promise = worker.exec(task.method, task.params, task.resolver, task.options).then(me._boundNext).catch(function() {
179
- if (worker.terminated) return me._removeWorker(worker);
180
- }).then(function() {
181
- me._next();
182
- });
183
- if (typeof task.timeout === "number") promise.timeout(task.timeout);
184
- } else me._next();
185
- }
186
- }
187
- };
188
- /**
189
- * Get an available worker. If no worker is available and the maximum number
190
- * of workers isn't yet reached, a new worker will be created and returned.
191
- * If no worker is available and the maximum number of workers is reached,
192
- * null will be returned.
193
- *
194
- * @return {WorkerHandler | null} worker
195
- * @private
196
- */
197
- Pool.prototype._getWorker = function() {
198
- var workers = this.workers;
199
- for (var i = 0; i < workers.length; i++) {
200
- var worker = workers[i];
201
- if (worker.busy() === false) return worker;
202
- }
203
- if (workers.length < this.maxWorkers) {
204
- worker = this._createWorkerHandler();
205
- workers.push(worker);
206
- return worker;
207
- }
208
- return null;
209
- };
210
- /**
211
- * Remove a worker from the pool.
212
- * Attempts to terminate worker if not already terminated, and ensures the minimum
213
- * pool size is met.
214
- * @param {WorkerHandler} worker
215
- * @return {Promise<WorkerHandler>}
216
- * @private
217
- */
218
- Pool.prototype._removeWorker = function(worker) {
219
- var me = this;
220
- DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);
221
- this._removeWorkerFromList(worker);
222
- this._ensureMinWorkers();
223
- return new Promise$1(function(resolve, reject) {
224
- worker.terminate(false, function(err) {
225
- me.onTerminateWorker({
226
- forkArgs: worker.forkArgs,
227
- forkOpts: worker.forkOpts,
228
- workerThreadOpts: worker.workerThreadOpts,
229
- script: worker.script
230
- });
231
- if (err) reject(err);
232
- else resolve(worker);
233
- });
234
- });
235
- };
236
- /**
237
- * Remove a worker from the pool list.
238
- * @param {WorkerHandler} worker
239
- * @private
240
- */
241
- Pool.prototype._removeWorkerFromList = function(worker) {
242
- var index = this.workers.indexOf(worker);
243
- if (index !== -1) this.workers.splice(index, 1);
244
- };
245
- /**
246
- * Close all active workers. Tasks currently being executed will be finished first.
247
- * @param {boolean} [force=false] If false (default), the workers are terminated
248
- * after finishing all tasks currently in
249
- * progress. If true, the workers will be
250
- * terminated immediately.
251
- * @param {number} [timeout] If provided and non-zero, worker termination promise will be rejected
252
- * after timeout if worker process has not been terminated.
253
- * @return {Promise.<void, Error>}
254
- */
255
- Pool.prototype.terminate = function(force, timeout) {
256
- var me = this;
257
- this.tasks.forEach(function(task) {
258
- task.resolver.reject(/* @__PURE__ */ new Error("Pool terminated"));
259
- });
260
- this.tasks.length = 0;
261
- var f = function(worker) {
262
- DEBUG_PORT_ALLOCATOR.releasePort(worker.debugPort);
263
- this._removeWorkerFromList(worker);
264
- };
265
- var removeWorker = f.bind(this);
266
- var promises = [];
267
- this.workers.slice().forEach(function(worker) {
268
- var termPromise = worker.terminateAndNotify(force, timeout).then(removeWorker).always(function() {
269
- me.onTerminateWorker({
270
- forkArgs: worker.forkArgs,
271
- forkOpts: worker.forkOpts,
272
- workerThreadOpts: worker.workerThreadOpts,
273
- script: worker.script
274
- });
275
- });
276
- promises.push(termPromise);
277
- });
278
- return Promise$1.all(promises);
279
- };
280
- /**
281
- * Retrieve statistics on tasks and workers.
282
- * @return {{totalWorkers: number, busyWorkers: number, idleWorkers: number, pendingTasks: number, activeTasks: number}} Returns an object with statistics
283
- */
284
- Pool.prototype.stats = function() {
285
- var totalWorkers = this.workers.length;
286
- var busyWorkers = this.workers.filter(function(worker) {
287
- return worker.busy();
288
- }).length;
289
- return {
290
- totalWorkers,
291
- busyWorkers,
292
- idleWorkers: totalWorkers - busyWorkers,
293
- pendingTasks: this.tasks.length,
294
- activeTasks: busyWorkers
295
- };
296
- };
297
- /**
298
- * Ensures that a minimum of minWorkers is up and running
299
- * @private
300
- */
301
- Pool.prototype._ensureMinWorkers = function() {
302
- if (this.minWorkers) for (var i = this.workers.length; i < this.minWorkers; i++) this.workers.push(this._createWorkerHandler());
303
- };
304
- /**
305
- * Helper function to create a new WorkerHandler and pass all options.
306
- * @return {WorkerHandler}
307
- * @private
308
- */
309
- Pool.prototype._createWorkerHandler = function() {
310
- const overriddenParams = this.onCreateWorker({
311
- forkArgs: this.forkArgs,
312
- forkOpts: this.forkOpts,
313
- workerOpts: this.workerOpts,
314
- workerThreadOpts: this.workerThreadOpts,
315
- script: this.script
316
- }) || {};
317
- return new WorkerHandler(overriddenParams.script || this.script, {
318
- forkArgs: overriddenParams.forkArgs || this.forkArgs,
319
- forkOpts: overriddenParams.forkOpts || this.forkOpts,
320
- workerOpts: overriddenParams.workerOpts || this.workerOpts,
321
- workerThreadOpts: overriddenParams.workerThreadOpts || this.workerThreadOpts,
322
- debugPort: DEBUG_PORT_ALLOCATOR.nextAvailableStartingAt(this.debugPortStart),
323
- workerType: this.workerType,
324
- workerTerminateTimeout: this.workerTerminateTimeout,
325
- emitStdStreams: this.emitStdStreams
326
- });
327
- };
328
- /**
329
- * Ensure that the maxWorkers option is an integer >= 1
330
- * @param {*} maxWorkers
331
- * @returns {boolean} returns true maxWorkers has a valid value
332
- */
333
- function validateMaxWorkers(maxWorkers) {
334
- if (!isNumber(maxWorkers) || !isInteger(maxWorkers) || maxWorkers < 1) throw new TypeError("Option maxWorkers must be an integer number >= 1");
335
- }
336
- /**
337
- * Ensure that the minWorkers option is an integer >= 0
338
- * @param {*} minWorkers
339
- * @returns {boolean} returns true when minWorkers has a valid value
340
- */
341
- function validateMinWorkers(minWorkers) {
342
- if (!isNumber(minWorkers) || !isInteger(minWorkers) || minWorkers < 0) throw new TypeError("Option minWorkers must be an integer number >= 0");
343
- }
344
- /**
345
- * Test whether a variable is a number
346
- * @param {*} value
347
- * @returns {boolean} returns true when value is a number
348
- */
349
- function isNumber(value) {
350
- return typeof value === "number";
351
- }
352
- /**
353
- * Test whether a number is an integer
354
- * @param {number} value
355
- * @returns {boolean} Returns true if value is an integer
356
- */
357
- function isInteger(value) {
358
- return Math.round(value) == value;
359
- }
360
- module.exports = Pool;
361
- }) });
362
-
363
- //#endregion
364
- export default require_Pool();
365
-
366
- export { require_Pool };
@@ -1,248 +0,0 @@
1
- import { __commonJS } from "../../../../../../_virtual/rolldown_runtime.js";
2
-
3
- //#region ../../node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js
4
- var require_Promise = /* @__PURE__ */ __commonJS({ "../../node_modules/.pnpm/workerpool@9.3.4/node_modules/workerpool/src/Promise.js": ((exports) => {
5
- /**
6
- * Promise
7
- *
8
- * Inspired by https://gist.github.com/RubaXa/8501359 from RubaXa <trash@rubaxa.org>
9
- * @template T
10
- * @template [E=Error]
11
- * @param {Function} handler Called as handler(resolve: Function, reject: Function)
12
- * @param {Promise} [parent] Parent promise for propagation of cancel and timeout
13
- */
14
- function Promise$1(handler, parent) {
15
- var me = this;
16
- if (!(this instanceof Promise$1)) throw new SyntaxError("Constructor must be called with the new operator");
17
- if (typeof handler !== "function") throw new SyntaxError("Function parameter handler(resolve, reject) missing");
18
- var _onSuccess = [];
19
- var _onFail = [];
20
- /**
21
- * @readonly
22
- */
23
- this.resolved = false;
24
- /**
25
- * @readonly
26
- */
27
- this.rejected = false;
28
- /**
29
- * @readonly
30
- */
31
- this.pending = true;
32
- /**
33
- * @readonly
34
- */
35
- this[Symbol.toStringTag] = "Promise";
36
- /**
37
- * Process onSuccess and onFail callbacks: add them to the queue.
38
- * Once the promise is resolved, the function _promise is replace.
39
- * @param {Function} onSuccess
40
- * @param {Function} onFail
41
- * @private
42
- */
43
- var _process = function(onSuccess, onFail) {
44
- _onSuccess.push(onSuccess);
45
- _onFail.push(onFail);
46
- };
47
- /**
48
- * Add an onSuccess callback and optionally an onFail callback to the Promise
49
- * @template TT
50
- * @template [TE=never]
51
- * @param {(r: T) => TT | PromiseLike<TT>} onSuccess
52
- * @param {(r: E) => TE | PromiseLike<TE>} [onFail]
53
- * @returns {Promise<TT | TE, any>} promise
54
- */
55
- this.then = function(onSuccess, onFail) {
56
- return new Promise$1(function(resolve, reject) {
57
- var s = onSuccess ? _then(onSuccess, resolve, reject) : resolve;
58
- var f = onFail ? _then(onFail, resolve, reject) : reject;
59
- _process(s, f);
60
- }, me);
61
- };
62
- /**
63
- * Resolve the promise
64
- * @param {*} result
65
- * @type {Function}
66
- */
67
- var _resolve = function(result) {
68
- me.resolved = true;
69
- me.rejected = false;
70
- me.pending = false;
71
- _onSuccess.forEach(function(fn) {
72
- fn(result);
73
- });
74
- _process = function(onSuccess, onFail) {
75
- onSuccess(result);
76
- };
77
- _resolve = _reject = function() {};
78
- return me;
79
- };
80
- /**
81
- * Reject the promise
82
- * @param {Error} error
83
- * @type {Function}
84
- */
85
- var _reject = function(error) {
86
- me.resolved = false;
87
- me.rejected = true;
88
- me.pending = false;
89
- _onFail.forEach(function(fn) {
90
- fn(error);
91
- });
92
- _process = function(onSuccess, onFail) {
93
- onFail(error);
94
- };
95
- _resolve = _reject = function() {};
96
- return me;
97
- };
98
- /**
99
- * Cancel the promise. This will reject the promise with a CancellationError
100
- * @returns {this} self
101
- */
102
- this.cancel = function() {
103
- if (parent) parent.cancel();
104
- else _reject(new CancellationError());
105
- return me;
106
- };
107
- /**
108
- * Set a timeout for the promise. If the promise is not resolved within
109
- * the time, the promise will be cancelled and a TimeoutError is thrown.
110
- * If the promise is resolved in time, the timeout is removed.
111
- * @param {number} delay Delay in milliseconds
112
- * @returns {this} self
113
- */
114
- this.timeout = function(delay) {
115
- if (parent) parent.timeout(delay);
116
- else {
117
- var timer = setTimeout(function() {
118
- _reject(new TimeoutError("Promise timed out after " + delay + " ms"));
119
- }, delay);
120
- me.always(function() {
121
- clearTimeout(timer);
122
- });
123
- }
124
- return me;
125
- };
126
- handler(function(result) {
127
- _resolve(result);
128
- }, function(error) {
129
- _reject(error);
130
- });
131
- }
132
- /**
133
- * Execute given callback, then call resolve/reject based on the returned result
134
- * @param {Function} callback
135
- * @param {Function} resolve
136
- * @param {Function} reject
137
- * @returns {Function}
138
- * @private
139
- */
140
- function _then(callback, resolve, reject) {
141
- return function(result) {
142
- try {
143
- var res = callback(result);
144
- if (res && typeof res.then === "function" && typeof res["catch"] === "function") res.then(resolve, reject);
145
- else resolve(res);
146
- } catch (error) {
147
- reject(error);
148
- }
149
- };
150
- }
151
- /**
152
- * Add an onFail callback to the Promise
153
- * @template TT
154
- * @param {(error: E) => TT | PromiseLike<TT>} onFail
155
- * @returns {Promise<T | TT>} promise
156
- */
157
- Promise$1.prototype["catch"] = function(onFail) {
158
- return this.then(null, onFail);
159
- };
160
- /**
161
- * Execute given callback when the promise either resolves or rejects.
162
- * @template TT
163
- * @param {() => Promise<TT>} fn
164
- * @returns {Promise<TT>} promise
165
- */
166
- Promise$1.prototype.always = function(fn) {
167
- return this.then(fn, fn);
168
- };
169
- /**
170
- * Execute given callback when the promise either resolves or rejects.
171
- * Same semantics as Node's Promise.finally()
172
- * @param {Function | null | undefined} [fn]
173
- * @returns {Promise} promise
174
- */
175
- Promise$1.prototype.finally = function(fn) {
176
- const me = this;
177
- const final = function() {
178
- return new Promise$1((resolve) => resolve()).then(fn).then(() => me);
179
- };
180
- return this.then(final, final);
181
- };
182
- /**
183
- * Create a promise which resolves when all provided promises are resolved,
184
- * and fails when any of the promises resolves.
185
- * @param {Promise[]} promises
186
- * @returns {Promise<any[], any>} promise
187
- */
188
- Promise$1.all = function(promises) {
189
- return new Promise$1(function(resolve, reject) {
190
- var remaining = promises.length, results = [];
191
- if (remaining) promises.forEach(function(p, i) {
192
- p.then(function(result) {
193
- results[i] = result;
194
- remaining--;
195
- if (remaining == 0) resolve(results);
196
- }, function(error) {
197
- remaining = 0;
198
- reject(error);
199
- });
200
- });
201
- else resolve(results);
202
- });
203
- };
204
- /**
205
- * Create a promise resolver
206
- * @returns {{promise: Promise, resolve: Function, reject: Function}} resolver
207
- */
208
- Promise$1.defer = function() {
209
- var resolver = {};
210
- resolver.promise = new Promise$1(function(resolve, reject) {
211
- resolver.resolve = resolve;
212
- resolver.reject = reject;
213
- });
214
- return resolver;
215
- };
216
- /**
217
- * Create a cancellation error
218
- * @param {String} [message]
219
- * @extends Error
220
- */
221
- function CancellationError(message) {
222
- this.message = message || "promise cancelled";
223
- this.stack = (/* @__PURE__ */ new Error()).stack;
224
- }
225
- CancellationError.prototype = /* @__PURE__ */ new Error();
226
- CancellationError.prototype.constructor = Error;
227
- CancellationError.prototype.name = "CancellationError";
228
- Promise$1.CancellationError = CancellationError;
229
- /**
230
- * Create a timeout error
231
- * @param {String} [message]
232
- * @extends Error
233
- */
234
- function TimeoutError(message) {
235
- this.message = message || "timeout exceeded";
236
- this.stack = (/* @__PURE__ */ new Error()).stack;
237
- }
238
- TimeoutError.prototype = /* @__PURE__ */ new Error();
239
- TimeoutError.prototype.constructor = Error;
240
- TimeoutError.prototype.name = "TimeoutError";
241
- Promise$1.TimeoutError = TimeoutError;
242
- exports.Promise = Promise$1;
243
- }) });
244
-
245
- //#endregion
246
- export default require_Promise();
247
-
248
- export { require_Promise };