@bluelibs/runner 4.5.6 → 4.5.7
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.
- package/dist/index.cjs +206 -204
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +206 -197
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -237,6 +237,211 @@ __export(errors_exports, {
|
|
|
237
237
|
UnknownItemTypeError: () => UnknownItemTypeError,
|
|
238
238
|
ValidationError: () => ValidationError
|
|
239
239
|
});
|
|
240
|
+
|
|
241
|
+
// src/platform/index.ts
|
|
242
|
+
function detectEnvironment() {
|
|
243
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
244
|
+
return "browser";
|
|
245
|
+
}
|
|
246
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
247
|
+
return "node";
|
|
248
|
+
}
|
|
249
|
+
return "universal";
|
|
250
|
+
}
|
|
251
|
+
__name(detectEnvironment, "detectEnvironment");
|
|
252
|
+
var _PlatformAdapter = class _PlatformAdapter {
|
|
253
|
+
constructor(env) {
|
|
254
|
+
this.isInitialized = false;
|
|
255
|
+
this.nodeALSClass = null;
|
|
256
|
+
// timers
|
|
257
|
+
this.setTimeout = globalThis.setTimeout;
|
|
258
|
+
this.clearTimeout = globalThis.clearTimeout;
|
|
259
|
+
this.env = env ?? detectEnvironment();
|
|
260
|
+
}
|
|
261
|
+
async init() {
|
|
262
|
+
if (this.env === "node") {
|
|
263
|
+
{
|
|
264
|
+
{
|
|
265
|
+
const mod = __require("async_hooks");
|
|
266
|
+
this.nodeALSClass = mod.AsyncLocalStorage;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
onUncaughtException(handler) {
|
|
272
|
+
switch (this.env) {
|
|
273
|
+
case "node": {
|
|
274
|
+
process.on("uncaughtException", handler);
|
|
275
|
+
return () => process.off("uncaughtException", handler);
|
|
276
|
+
}
|
|
277
|
+
case "browser": {
|
|
278
|
+
const target = globalThis.window ?? globalThis;
|
|
279
|
+
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
280
|
+
target.addEventListener?.("error", h);
|
|
281
|
+
return () => target.removeEventListener?.("error", h);
|
|
282
|
+
}
|
|
283
|
+
default: {
|
|
284
|
+
const tgt = globalThis;
|
|
285
|
+
if (tgt.addEventListener) {
|
|
286
|
+
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
287
|
+
tgt.addEventListener("error", h);
|
|
288
|
+
return () => tgt.removeEventListener("error", h);
|
|
289
|
+
}
|
|
290
|
+
return () => {
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
onUnhandledRejection(handler) {
|
|
296
|
+
switch (this.env) {
|
|
297
|
+
case "node": {
|
|
298
|
+
const h = /* @__PURE__ */ __name((reason) => handler(reason), "h");
|
|
299
|
+
process.on("unhandledRejection", h);
|
|
300
|
+
return () => process.off("unhandledRejection", h);
|
|
301
|
+
}
|
|
302
|
+
case "browser": {
|
|
303
|
+
const target = globalThis.window;
|
|
304
|
+
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason), "wrap");
|
|
305
|
+
target.addEventListener?.("unhandledrejection", wrap);
|
|
306
|
+
return () => target.removeEventListener?.("unhandledrejection", wrap);
|
|
307
|
+
}
|
|
308
|
+
default: {
|
|
309
|
+
const tgt = globalThis;
|
|
310
|
+
if (tgt.addEventListener) {
|
|
311
|
+
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason ?? e), "wrap");
|
|
312
|
+
tgt.addEventListener("unhandledrejection", wrap);
|
|
313
|
+
return () => tgt.removeEventListener("unhandledrejection", wrap);
|
|
314
|
+
}
|
|
315
|
+
return () => {
|
|
316
|
+
};
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
onShutdownSignal(handler) {
|
|
321
|
+
switch (this.env) {
|
|
322
|
+
case "node": {
|
|
323
|
+
process.on("SIGINT", handler);
|
|
324
|
+
process.on("SIGTERM", handler);
|
|
325
|
+
return () => {
|
|
326
|
+
process.off("SIGINT", handler);
|
|
327
|
+
process.off("SIGTERM", handler);
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
case "browser": {
|
|
331
|
+
const win = window;
|
|
332
|
+
win.addEventListener?.("beforeunload", handler);
|
|
333
|
+
return () => {
|
|
334
|
+
win.removeEventListener?.("beforeunload", handler);
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
default: {
|
|
338
|
+
const tgt = globalThis;
|
|
339
|
+
const cleanup = [];
|
|
340
|
+
if (tgt.addEventListener) {
|
|
341
|
+
tgt.addEventListener("beforeunload", handler);
|
|
342
|
+
cleanup.push(
|
|
343
|
+
() => tgt.removeEventListener?.("beforeunload", handler)
|
|
344
|
+
);
|
|
345
|
+
const vis = /* @__PURE__ */ __name(() => {
|
|
346
|
+
const doc = globalThis.document;
|
|
347
|
+
if (doc && doc.visibilityState === "hidden") handler();
|
|
348
|
+
}, "vis");
|
|
349
|
+
tgt.addEventListener("visibilitychange", vis);
|
|
350
|
+
cleanup.push(
|
|
351
|
+
() => tgt.removeEventListener?.("visibilitychange", vis)
|
|
352
|
+
);
|
|
353
|
+
}
|
|
354
|
+
if (typeof process !== "undefined" && process.on) {
|
|
355
|
+
process.on("SIGINT", handler);
|
|
356
|
+
process.on("SIGTERM", handler);
|
|
357
|
+
cleanup.push(() => {
|
|
358
|
+
process.off?.("SIGINT", handler);
|
|
359
|
+
process.off?.("SIGTERM", handler);
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
return () => cleanup.forEach((fn) => fn());
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
exit(code) {
|
|
367
|
+
switch (this.env) {
|
|
368
|
+
case "node":
|
|
369
|
+
process.exit(code);
|
|
370
|
+
return;
|
|
371
|
+
default:
|
|
372
|
+
throw new PlatformUnsupportedFunction("exit");
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
getEnv(key) {
|
|
376
|
+
switch (this.env) {
|
|
377
|
+
case "node":
|
|
378
|
+
return process.env[key];
|
|
379
|
+
default: {
|
|
380
|
+
const g = globalThis;
|
|
381
|
+
if (g.__ENV__ && typeof g.__ENV__ === "object") return g.__ENV__[key];
|
|
382
|
+
if (typeof process !== "undefined" && process.env)
|
|
383
|
+
return process.env[key];
|
|
384
|
+
if (g.env && typeof g.env === "object") return g.env[key];
|
|
385
|
+
return void 0;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
hasAsyncLocalStorage() {
|
|
390
|
+
switch (this.env) {
|
|
391
|
+
case "node":
|
|
392
|
+
return true;
|
|
393
|
+
// We'll try native, else polyfill
|
|
394
|
+
case "browser":
|
|
395
|
+
default:
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
createAsyncLocalStorage() {
|
|
400
|
+
switch (this.env) {
|
|
401
|
+
case "node": {
|
|
402
|
+
let instance;
|
|
403
|
+
const get = /* @__PURE__ */ __name(() => {
|
|
404
|
+
if (!instance) {
|
|
405
|
+
if (!this.nodeALSClass) {
|
|
406
|
+
throw new PlatformUnsupportedFunction(
|
|
407
|
+
"createAsyncLocalStorage: Platform not initialized"
|
|
408
|
+
);
|
|
409
|
+
}
|
|
410
|
+
instance = new this.nodeALSClass();
|
|
411
|
+
}
|
|
412
|
+
return instance;
|
|
413
|
+
}, "get");
|
|
414
|
+
return {
|
|
415
|
+
getStore: /* @__PURE__ */ __name(() => get().getStore(), "getStore"),
|
|
416
|
+
run: /* @__PURE__ */ __name((store2, callback) => get().run(store2, callback), "run")
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
case "browser":
|
|
420
|
+
default:
|
|
421
|
+
return {
|
|
422
|
+
getStore: /* @__PURE__ */ __name(() => {
|
|
423
|
+
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
424
|
+
}, "getStore"),
|
|
425
|
+
run: /* @__PURE__ */ __name(() => {
|
|
426
|
+
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
427
|
+
}, "run")
|
|
428
|
+
};
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
__name(_PlatformAdapter, "PlatformAdapter");
|
|
433
|
+
var PlatformAdapter = _PlatformAdapter;
|
|
434
|
+
var platformInstance = null;
|
|
435
|
+
function getPlatform() {
|
|
436
|
+
if (!platformInstance) {
|
|
437
|
+
const env = detectEnvironment();
|
|
438
|
+
platformInstance = new PlatformAdapter(env);
|
|
439
|
+
}
|
|
440
|
+
return platformInstance;
|
|
441
|
+
}
|
|
442
|
+
__name(getPlatform, "getPlatform");
|
|
443
|
+
|
|
444
|
+
// src/errors.ts
|
|
240
445
|
var _RuntimeError = class _RuntimeError extends Error {
|
|
241
446
|
constructor(message) {
|
|
242
447
|
super(message);
|
|
@@ -395,7 +600,7 @@ var EventEmissionCycleError = _EventEmissionCycleError;
|
|
|
395
600
|
var _PlatformUnsupportedFunction = class _PlatformUnsupportedFunction extends RuntimeError {
|
|
396
601
|
constructor(functionName) {
|
|
397
602
|
super(
|
|
398
|
-
`Platform function not supported in this environment: ${functionName}
|
|
603
|
+
`Platform function not supported in this environment: ${functionName}. Detected platform: ${detectEnvironment()}.`
|
|
399
604
|
);
|
|
400
605
|
this.name = "PlatformUnsupportedFunction";
|
|
401
606
|
}
|
|
@@ -693,209 +898,6 @@ function isOptional(definition) {
|
|
|
693
898
|
}
|
|
694
899
|
__name(isOptional, "isOptional");
|
|
695
900
|
|
|
696
|
-
// src/platform/index.ts
|
|
697
|
-
function detectEnvironment() {
|
|
698
|
-
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
699
|
-
return "browser";
|
|
700
|
-
}
|
|
701
|
-
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
702
|
-
return "node";
|
|
703
|
-
}
|
|
704
|
-
return "universal";
|
|
705
|
-
}
|
|
706
|
-
__name(detectEnvironment, "detectEnvironment");
|
|
707
|
-
var _PlatformAdapter = class _PlatformAdapter {
|
|
708
|
-
constructor(env) {
|
|
709
|
-
this.isInitialized = false;
|
|
710
|
-
this.nodeALSClass = null;
|
|
711
|
-
// timers
|
|
712
|
-
this.setTimeout = globalThis.setTimeout;
|
|
713
|
-
this.clearTimeout = globalThis.clearTimeout;
|
|
714
|
-
this.env = env ?? detectEnvironment();
|
|
715
|
-
}
|
|
716
|
-
async init() {
|
|
717
|
-
if (this.env === "node") {
|
|
718
|
-
{
|
|
719
|
-
{
|
|
720
|
-
const mod = __require("async_hooks");
|
|
721
|
-
this.nodeALSClass = mod.AsyncLocalStorage;
|
|
722
|
-
}
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
onUncaughtException(handler) {
|
|
727
|
-
switch (this.env) {
|
|
728
|
-
case "node": {
|
|
729
|
-
process.on("uncaughtException", handler);
|
|
730
|
-
return () => process.off("uncaughtException", handler);
|
|
731
|
-
}
|
|
732
|
-
case "browser": {
|
|
733
|
-
const target = globalThis.window ?? globalThis;
|
|
734
|
-
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
735
|
-
target.addEventListener?.("error", h);
|
|
736
|
-
return () => target.removeEventListener?.("error", h);
|
|
737
|
-
}
|
|
738
|
-
default: {
|
|
739
|
-
const tgt = globalThis;
|
|
740
|
-
if (tgt.addEventListener) {
|
|
741
|
-
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
742
|
-
tgt.addEventListener("error", h);
|
|
743
|
-
return () => tgt.removeEventListener("error", h);
|
|
744
|
-
}
|
|
745
|
-
return () => {
|
|
746
|
-
};
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
onUnhandledRejection(handler) {
|
|
751
|
-
switch (this.env) {
|
|
752
|
-
case "node": {
|
|
753
|
-
const h = /* @__PURE__ */ __name((reason) => handler(reason), "h");
|
|
754
|
-
process.on("unhandledRejection", h);
|
|
755
|
-
return () => process.off("unhandledRejection", h);
|
|
756
|
-
}
|
|
757
|
-
case "browser": {
|
|
758
|
-
const target = globalThis.window;
|
|
759
|
-
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason), "wrap");
|
|
760
|
-
target.addEventListener?.("unhandledrejection", wrap);
|
|
761
|
-
return () => target.removeEventListener?.("unhandledrejection", wrap);
|
|
762
|
-
}
|
|
763
|
-
default: {
|
|
764
|
-
const tgt = globalThis;
|
|
765
|
-
if (tgt.addEventListener) {
|
|
766
|
-
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason ?? e), "wrap");
|
|
767
|
-
tgt.addEventListener("unhandledrejection", wrap);
|
|
768
|
-
return () => tgt.removeEventListener("unhandledrejection", wrap);
|
|
769
|
-
}
|
|
770
|
-
return () => {
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
}
|
|
774
|
-
}
|
|
775
|
-
onShutdownSignal(handler) {
|
|
776
|
-
switch (this.env) {
|
|
777
|
-
case "node": {
|
|
778
|
-
process.on("SIGINT", handler);
|
|
779
|
-
process.on("SIGTERM", handler);
|
|
780
|
-
return () => {
|
|
781
|
-
process.off("SIGINT", handler);
|
|
782
|
-
process.off("SIGTERM", handler);
|
|
783
|
-
};
|
|
784
|
-
}
|
|
785
|
-
case "browser": {
|
|
786
|
-
const win = window;
|
|
787
|
-
win.addEventListener?.("beforeunload", handler);
|
|
788
|
-
return () => {
|
|
789
|
-
win.removeEventListener?.("beforeunload", handler);
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
default: {
|
|
793
|
-
const tgt = globalThis;
|
|
794
|
-
const cleanup = [];
|
|
795
|
-
if (tgt.addEventListener) {
|
|
796
|
-
tgt.addEventListener("beforeunload", handler);
|
|
797
|
-
cleanup.push(
|
|
798
|
-
() => tgt.removeEventListener?.("beforeunload", handler)
|
|
799
|
-
);
|
|
800
|
-
const vis = /* @__PURE__ */ __name(() => {
|
|
801
|
-
const doc = globalThis.document;
|
|
802
|
-
if (doc && doc.visibilityState === "hidden") handler();
|
|
803
|
-
}, "vis");
|
|
804
|
-
tgt.addEventListener("visibilitychange", vis);
|
|
805
|
-
cleanup.push(
|
|
806
|
-
() => tgt.removeEventListener?.("visibilitychange", vis)
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
if (typeof process !== "undefined" && process.on) {
|
|
810
|
-
process.on("SIGINT", handler);
|
|
811
|
-
process.on("SIGTERM", handler);
|
|
812
|
-
cleanup.push(() => {
|
|
813
|
-
process.off?.("SIGINT", handler);
|
|
814
|
-
process.off?.("SIGTERM", handler);
|
|
815
|
-
});
|
|
816
|
-
}
|
|
817
|
-
return () => cleanup.forEach((fn) => fn());
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
}
|
|
821
|
-
exit(code) {
|
|
822
|
-
switch (this.env) {
|
|
823
|
-
case "node":
|
|
824
|
-
process.exit(code);
|
|
825
|
-
return;
|
|
826
|
-
default:
|
|
827
|
-
throw new PlatformUnsupportedFunction("exit");
|
|
828
|
-
}
|
|
829
|
-
}
|
|
830
|
-
getEnv(key) {
|
|
831
|
-
switch (this.env) {
|
|
832
|
-
case "node":
|
|
833
|
-
return process.env[key];
|
|
834
|
-
default: {
|
|
835
|
-
const g = globalThis;
|
|
836
|
-
if (g.__ENV__ && typeof g.__ENV__ === "object") return g.__ENV__[key];
|
|
837
|
-
if (typeof process !== "undefined" && process.env)
|
|
838
|
-
return process.env[key];
|
|
839
|
-
if (g.env && typeof g.env === "object") return g.env[key];
|
|
840
|
-
return void 0;
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
}
|
|
844
|
-
hasAsyncLocalStorage() {
|
|
845
|
-
switch (this.env) {
|
|
846
|
-
case "node":
|
|
847
|
-
return true;
|
|
848
|
-
// We'll try native, else polyfill
|
|
849
|
-
case "browser":
|
|
850
|
-
default:
|
|
851
|
-
return false;
|
|
852
|
-
}
|
|
853
|
-
}
|
|
854
|
-
createAsyncLocalStorage() {
|
|
855
|
-
switch (this.env) {
|
|
856
|
-
case "node": {
|
|
857
|
-
let instance;
|
|
858
|
-
const get = /* @__PURE__ */ __name(() => {
|
|
859
|
-
if (!instance) {
|
|
860
|
-
if (!this.nodeALSClass) {
|
|
861
|
-
throw new PlatformUnsupportedFunction(
|
|
862
|
-
"createAsyncLocalStorage: Platform not initialized"
|
|
863
|
-
);
|
|
864
|
-
}
|
|
865
|
-
instance = new this.nodeALSClass();
|
|
866
|
-
}
|
|
867
|
-
return instance;
|
|
868
|
-
}, "get");
|
|
869
|
-
return {
|
|
870
|
-
getStore: /* @__PURE__ */ __name(() => get().getStore(), "getStore"),
|
|
871
|
-
run: /* @__PURE__ */ __name((store2, callback) => get().run(store2, callback), "run")
|
|
872
|
-
};
|
|
873
|
-
}
|
|
874
|
-
case "browser":
|
|
875
|
-
default:
|
|
876
|
-
return {
|
|
877
|
-
getStore: /* @__PURE__ */ __name(() => {
|
|
878
|
-
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
879
|
-
}, "getStore"),
|
|
880
|
-
run: /* @__PURE__ */ __name(() => {
|
|
881
|
-
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
882
|
-
}, "run")
|
|
883
|
-
};
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
};
|
|
887
|
-
__name(_PlatformAdapter, "PlatformAdapter");
|
|
888
|
-
var PlatformAdapter = _PlatformAdapter;
|
|
889
|
-
var platformInstance = null;
|
|
890
|
-
function getPlatform() {
|
|
891
|
-
if (!platformInstance) {
|
|
892
|
-
const env = detectEnvironment();
|
|
893
|
-
platformInstance = new PlatformAdapter(env);
|
|
894
|
-
}
|
|
895
|
-
return platformInstance;
|
|
896
|
-
}
|
|
897
|
-
__name(getPlatform, "getPlatform");
|
|
898
|
-
|
|
899
901
|
// src/globals/middleware/requireContext.middleware.ts
|
|
900
902
|
var requireContextTaskMiddleware = defineTaskMiddleware({
|
|
901
903
|
id: "globals.middleware.requireContext",
|