@bluelibs/runner 4.5.6 → 4.5.8
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 +207 -216
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -5
- package/dist/index.mjs +207 -209
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1692,11 +1692,7 @@ declare function buildTestFacade(deps: {
|
|
|
1692
1692
|
declare const globals: {
|
|
1693
1693
|
events: {
|
|
1694
1694
|
readonly ready: IEvent<{
|
|
1695
|
-
root: IResource<any, any, any, any>;
|
|
1696
|
-
}>;
|
|
1697
|
-
readonly unhandledError: IEvent<{
|
|
1698
|
-
kind: "task" | "middleware" | "resourceInit" | "hook" | "process" | "run";
|
|
1699
|
-
error: any;
|
|
1695
|
+
root: IResource<any, any, any, any, any, any, any>;
|
|
1700
1696
|
}>;
|
|
1701
1697
|
};
|
|
1702
1698
|
resources: {
|
package/dist/index.mjs
CHANGED
|
@@ -229,6 +229,211 @@ __export(errors_exports, {
|
|
|
229
229
|
UnknownItemTypeError: () => UnknownItemTypeError,
|
|
230
230
|
ValidationError: () => ValidationError
|
|
231
231
|
});
|
|
232
|
+
|
|
233
|
+
// src/platform/index.ts
|
|
234
|
+
function detectEnvironment() {
|
|
235
|
+
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
236
|
+
return "browser";
|
|
237
|
+
}
|
|
238
|
+
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
239
|
+
return "node";
|
|
240
|
+
}
|
|
241
|
+
return "universal";
|
|
242
|
+
}
|
|
243
|
+
__name(detectEnvironment, "detectEnvironment");
|
|
244
|
+
var _PlatformAdapter = class _PlatformAdapter {
|
|
245
|
+
constructor(env) {
|
|
246
|
+
this.isInitialized = false;
|
|
247
|
+
this.nodeALSClass = null;
|
|
248
|
+
// timers
|
|
249
|
+
this.setTimeout = globalThis.setTimeout;
|
|
250
|
+
this.clearTimeout = globalThis.clearTimeout;
|
|
251
|
+
this.env = env ?? detectEnvironment();
|
|
252
|
+
}
|
|
253
|
+
async init() {
|
|
254
|
+
if (this.env === "node") {
|
|
255
|
+
{
|
|
256
|
+
{
|
|
257
|
+
const mod = await import('async_hooks');
|
|
258
|
+
this.nodeALSClass = mod.AsyncLocalStorage;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
onUncaughtException(handler) {
|
|
264
|
+
switch (this.env) {
|
|
265
|
+
case "node": {
|
|
266
|
+
process.on("uncaughtException", handler);
|
|
267
|
+
return () => process.off("uncaughtException", handler);
|
|
268
|
+
}
|
|
269
|
+
case "browser": {
|
|
270
|
+
const target = globalThis.window ?? globalThis;
|
|
271
|
+
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
272
|
+
target.addEventListener?.("error", h);
|
|
273
|
+
return () => target.removeEventListener?.("error", h);
|
|
274
|
+
}
|
|
275
|
+
default: {
|
|
276
|
+
const tgt = globalThis;
|
|
277
|
+
if (tgt.addEventListener) {
|
|
278
|
+
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
279
|
+
tgt.addEventListener("error", h);
|
|
280
|
+
return () => tgt.removeEventListener("error", h);
|
|
281
|
+
}
|
|
282
|
+
return () => {
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
onUnhandledRejection(handler) {
|
|
288
|
+
switch (this.env) {
|
|
289
|
+
case "node": {
|
|
290
|
+
const h = /* @__PURE__ */ __name((reason) => handler(reason), "h");
|
|
291
|
+
process.on("unhandledRejection", h);
|
|
292
|
+
return () => process.off("unhandledRejection", h);
|
|
293
|
+
}
|
|
294
|
+
case "browser": {
|
|
295
|
+
const target = globalThis.window;
|
|
296
|
+
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason), "wrap");
|
|
297
|
+
target.addEventListener?.("unhandledrejection", wrap);
|
|
298
|
+
return () => target.removeEventListener?.("unhandledrejection", wrap);
|
|
299
|
+
}
|
|
300
|
+
default: {
|
|
301
|
+
const tgt = globalThis;
|
|
302
|
+
if (tgt.addEventListener) {
|
|
303
|
+
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason ?? e), "wrap");
|
|
304
|
+
tgt.addEventListener("unhandledrejection", wrap);
|
|
305
|
+
return () => tgt.removeEventListener("unhandledrejection", wrap);
|
|
306
|
+
}
|
|
307
|
+
return () => {
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
onShutdownSignal(handler) {
|
|
313
|
+
switch (this.env) {
|
|
314
|
+
case "node": {
|
|
315
|
+
process.on("SIGINT", handler);
|
|
316
|
+
process.on("SIGTERM", handler);
|
|
317
|
+
return () => {
|
|
318
|
+
process.off("SIGINT", handler);
|
|
319
|
+
process.off("SIGTERM", handler);
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
case "browser": {
|
|
323
|
+
const win = window;
|
|
324
|
+
win.addEventListener?.("beforeunload", handler);
|
|
325
|
+
return () => {
|
|
326
|
+
win.removeEventListener?.("beforeunload", handler);
|
|
327
|
+
};
|
|
328
|
+
}
|
|
329
|
+
default: {
|
|
330
|
+
const tgt = globalThis;
|
|
331
|
+
const cleanup = [];
|
|
332
|
+
if (tgt.addEventListener) {
|
|
333
|
+
tgt.addEventListener("beforeunload", handler);
|
|
334
|
+
cleanup.push(
|
|
335
|
+
() => tgt.removeEventListener?.("beforeunload", handler)
|
|
336
|
+
);
|
|
337
|
+
const vis = /* @__PURE__ */ __name(() => {
|
|
338
|
+
const doc = globalThis.document;
|
|
339
|
+
if (doc && doc.visibilityState === "hidden") handler();
|
|
340
|
+
}, "vis");
|
|
341
|
+
tgt.addEventListener("visibilitychange", vis);
|
|
342
|
+
cleanup.push(
|
|
343
|
+
() => tgt.removeEventListener?.("visibilitychange", vis)
|
|
344
|
+
);
|
|
345
|
+
}
|
|
346
|
+
if (typeof process !== "undefined" && process.on) {
|
|
347
|
+
process.on("SIGINT", handler);
|
|
348
|
+
process.on("SIGTERM", handler);
|
|
349
|
+
cleanup.push(() => {
|
|
350
|
+
process.off?.("SIGINT", handler);
|
|
351
|
+
process.off?.("SIGTERM", handler);
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
return () => cleanup.forEach((fn) => fn());
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
exit(code) {
|
|
359
|
+
switch (this.env) {
|
|
360
|
+
case "node":
|
|
361
|
+
process.exit(code);
|
|
362
|
+
return;
|
|
363
|
+
default:
|
|
364
|
+
throw new PlatformUnsupportedFunction("exit");
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
getEnv(key) {
|
|
368
|
+
switch (this.env) {
|
|
369
|
+
case "node":
|
|
370
|
+
return process.env[key];
|
|
371
|
+
default: {
|
|
372
|
+
const g = globalThis;
|
|
373
|
+
if (g.__ENV__ && typeof g.__ENV__ === "object") return g.__ENV__[key];
|
|
374
|
+
if (typeof process !== "undefined" && process.env)
|
|
375
|
+
return process.env[key];
|
|
376
|
+
if (g.env && typeof g.env === "object") return g.env[key];
|
|
377
|
+
return void 0;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
hasAsyncLocalStorage() {
|
|
382
|
+
switch (this.env) {
|
|
383
|
+
case "node":
|
|
384
|
+
return true;
|
|
385
|
+
// We'll try native, else polyfill
|
|
386
|
+
case "browser":
|
|
387
|
+
default:
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
createAsyncLocalStorage() {
|
|
392
|
+
switch (this.env) {
|
|
393
|
+
case "node": {
|
|
394
|
+
let instance;
|
|
395
|
+
const get = /* @__PURE__ */ __name(() => {
|
|
396
|
+
if (!instance) {
|
|
397
|
+
if (!this.nodeALSClass) {
|
|
398
|
+
throw new PlatformUnsupportedFunction(
|
|
399
|
+
"createAsyncLocalStorage: Platform not initialized"
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
instance = new this.nodeALSClass();
|
|
403
|
+
}
|
|
404
|
+
return instance;
|
|
405
|
+
}, "get");
|
|
406
|
+
return {
|
|
407
|
+
getStore: /* @__PURE__ */ __name(() => get().getStore(), "getStore"),
|
|
408
|
+
run: /* @__PURE__ */ __name((store2, callback) => get().run(store2, callback), "run")
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
case "browser":
|
|
412
|
+
default:
|
|
413
|
+
return {
|
|
414
|
+
getStore: /* @__PURE__ */ __name(() => {
|
|
415
|
+
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
416
|
+
}, "getStore"),
|
|
417
|
+
run: /* @__PURE__ */ __name(() => {
|
|
418
|
+
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
419
|
+
}, "run")
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
__name(_PlatformAdapter, "PlatformAdapter");
|
|
425
|
+
var PlatformAdapter = _PlatformAdapter;
|
|
426
|
+
var platformInstance = null;
|
|
427
|
+
function getPlatform() {
|
|
428
|
+
if (!platformInstance) {
|
|
429
|
+
const env = detectEnvironment();
|
|
430
|
+
platformInstance = new PlatformAdapter(env);
|
|
431
|
+
}
|
|
432
|
+
return platformInstance;
|
|
433
|
+
}
|
|
434
|
+
__name(getPlatform, "getPlatform");
|
|
435
|
+
|
|
436
|
+
// src/errors.ts
|
|
232
437
|
var _RuntimeError = class _RuntimeError extends Error {
|
|
233
438
|
constructor(message) {
|
|
234
439
|
super(message);
|
|
@@ -387,7 +592,7 @@ var EventEmissionCycleError = _EventEmissionCycleError;
|
|
|
387
592
|
var _PlatformUnsupportedFunction = class _PlatformUnsupportedFunction extends RuntimeError {
|
|
388
593
|
constructor(functionName) {
|
|
389
594
|
super(
|
|
390
|
-
`Platform function not supported in this environment: ${functionName}
|
|
595
|
+
`Platform function not supported in this environment: ${functionName}. Detected platform: ${detectEnvironment()}.`
|
|
391
596
|
);
|
|
392
597
|
this.name = "PlatformUnsupportedFunction";
|
|
393
598
|
}
|
|
@@ -685,202 +890,6 @@ function isOptional(definition) {
|
|
|
685
890
|
}
|
|
686
891
|
__name(isOptional, "isOptional");
|
|
687
892
|
|
|
688
|
-
// src/platform/index.ts
|
|
689
|
-
function detectEnvironment() {
|
|
690
|
-
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
691
|
-
return "browser";
|
|
692
|
-
}
|
|
693
|
-
if (typeof process !== "undefined" && process.versions && process.versions.node) {
|
|
694
|
-
return "node";
|
|
695
|
-
}
|
|
696
|
-
return "universal";
|
|
697
|
-
}
|
|
698
|
-
__name(detectEnvironment, "detectEnvironment");
|
|
699
|
-
var _PlatformAdapter = class _PlatformAdapter {
|
|
700
|
-
constructor(env) {
|
|
701
|
-
this.isInitialized = false;
|
|
702
|
-
this.nodeALSClass = null;
|
|
703
|
-
// timers
|
|
704
|
-
this.setTimeout = globalThis.setTimeout;
|
|
705
|
-
this.clearTimeout = globalThis.clearTimeout;
|
|
706
|
-
this.env = env ?? detectEnvironment();
|
|
707
|
-
}
|
|
708
|
-
async init() {
|
|
709
|
-
if (this.env === "node") ;
|
|
710
|
-
}
|
|
711
|
-
onUncaughtException(handler) {
|
|
712
|
-
switch (this.env) {
|
|
713
|
-
case "node": {
|
|
714
|
-
process.on("uncaughtException", handler);
|
|
715
|
-
return () => process.off("uncaughtException", handler);
|
|
716
|
-
}
|
|
717
|
-
case "browser": {
|
|
718
|
-
const target = globalThis.window ?? globalThis;
|
|
719
|
-
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
720
|
-
target.addEventListener?.("error", h);
|
|
721
|
-
return () => target.removeEventListener?.("error", h);
|
|
722
|
-
}
|
|
723
|
-
default: {
|
|
724
|
-
const tgt = globalThis;
|
|
725
|
-
if (tgt.addEventListener) {
|
|
726
|
-
const h = /* @__PURE__ */ __name((e) => handler(e?.error ?? e), "h");
|
|
727
|
-
tgt.addEventListener("error", h);
|
|
728
|
-
return () => tgt.removeEventListener("error", h);
|
|
729
|
-
}
|
|
730
|
-
return () => {
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
onUnhandledRejection(handler) {
|
|
736
|
-
switch (this.env) {
|
|
737
|
-
case "node": {
|
|
738
|
-
const h = /* @__PURE__ */ __name((reason) => handler(reason), "h");
|
|
739
|
-
process.on("unhandledRejection", h);
|
|
740
|
-
return () => process.off("unhandledRejection", h);
|
|
741
|
-
}
|
|
742
|
-
case "browser": {
|
|
743
|
-
const target = globalThis.window;
|
|
744
|
-
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason), "wrap");
|
|
745
|
-
target.addEventListener?.("unhandledrejection", wrap);
|
|
746
|
-
return () => target.removeEventListener?.("unhandledrejection", wrap);
|
|
747
|
-
}
|
|
748
|
-
default: {
|
|
749
|
-
const tgt = globalThis;
|
|
750
|
-
if (tgt.addEventListener) {
|
|
751
|
-
const wrap = /* @__PURE__ */ __name((e) => handler(e.reason ?? e), "wrap");
|
|
752
|
-
tgt.addEventListener("unhandledrejection", wrap);
|
|
753
|
-
return () => tgt.removeEventListener("unhandledrejection", wrap);
|
|
754
|
-
}
|
|
755
|
-
return () => {
|
|
756
|
-
};
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
onShutdownSignal(handler) {
|
|
761
|
-
switch (this.env) {
|
|
762
|
-
case "node": {
|
|
763
|
-
process.on("SIGINT", handler);
|
|
764
|
-
process.on("SIGTERM", handler);
|
|
765
|
-
return () => {
|
|
766
|
-
process.off("SIGINT", handler);
|
|
767
|
-
process.off("SIGTERM", handler);
|
|
768
|
-
};
|
|
769
|
-
}
|
|
770
|
-
case "browser": {
|
|
771
|
-
const win = window;
|
|
772
|
-
win.addEventListener?.("beforeunload", handler);
|
|
773
|
-
return () => {
|
|
774
|
-
win.removeEventListener?.("beforeunload", handler);
|
|
775
|
-
};
|
|
776
|
-
}
|
|
777
|
-
default: {
|
|
778
|
-
const tgt = globalThis;
|
|
779
|
-
const cleanup = [];
|
|
780
|
-
if (tgt.addEventListener) {
|
|
781
|
-
tgt.addEventListener("beforeunload", handler);
|
|
782
|
-
cleanup.push(
|
|
783
|
-
() => tgt.removeEventListener?.("beforeunload", handler)
|
|
784
|
-
);
|
|
785
|
-
const vis = /* @__PURE__ */ __name(() => {
|
|
786
|
-
const doc = globalThis.document;
|
|
787
|
-
if (doc && doc.visibilityState === "hidden") handler();
|
|
788
|
-
}, "vis");
|
|
789
|
-
tgt.addEventListener("visibilitychange", vis);
|
|
790
|
-
cleanup.push(
|
|
791
|
-
() => tgt.removeEventListener?.("visibilitychange", vis)
|
|
792
|
-
);
|
|
793
|
-
}
|
|
794
|
-
if (typeof process !== "undefined" && process.on) {
|
|
795
|
-
process.on("SIGINT", handler);
|
|
796
|
-
process.on("SIGTERM", handler);
|
|
797
|
-
cleanup.push(() => {
|
|
798
|
-
process.off?.("SIGINT", handler);
|
|
799
|
-
process.off?.("SIGTERM", handler);
|
|
800
|
-
});
|
|
801
|
-
}
|
|
802
|
-
return () => cleanup.forEach((fn) => fn());
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
exit(code) {
|
|
807
|
-
switch (this.env) {
|
|
808
|
-
case "node":
|
|
809
|
-
process.exit(code);
|
|
810
|
-
return;
|
|
811
|
-
default:
|
|
812
|
-
throw new PlatformUnsupportedFunction("exit");
|
|
813
|
-
}
|
|
814
|
-
}
|
|
815
|
-
getEnv(key) {
|
|
816
|
-
switch (this.env) {
|
|
817
|
-
case "node":
|
|
818
|
-
return process.env[key];
|
|
819
|
-
default: {
|
|
820
|
-
const g = globalThis;
|
|
821
|
-
if (g.__ENV__ && typeof g.__ENV__ === "object") return g.__ENV__[key];
|
|
822
|
-
if (typeof process !== "undefined" && process.env)
|
|
823
|
-
return process.env[key];
|
|
824
|
-
if (g.env && typeof g.env === "object") return g.env[key];
|
|
825
|
-
return void 0;
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
hasAsyncLocalStorage() {
|
|
830
|
-
switch (this.env) {
|
|
831
|
-
case "node":
|
|
832
|
-
return true;
|
|
833
|
-
// We'll try native, else polyfill
|
|
834
|
-
case "browser":
|
|
835
|
-
default:
|
|
836
|
-
return false;
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
createAsyncLocalStorage() {
|
|
840
|
-
switch (this.env) {
|
|
841
|
-
case "node": {
|
|
842
|
-
let instance;
|
|
843
|
-
const get = /* @__PURE__ */ __name(() => {
|
|
844
|
-
if (!instance) {
|
|
845
|
-
if (!this.nodeALSClass) {
|
|
846
|
-
throw new PlatformUnsupportedFunction(
|
|
847
|
-
"createAsyncLocalStorage: Platform not initialized"
|
|
848
|
-
);
|
|
849
|
-
}
|
|
850
|
-
instance = new this.nodeALSClass();
|
|
851
|
-
}
|
|
852
|
-
return instance;
|
|
853
|
-
}, "get");
|
|
854
|
-
return {
|
|
855
|
-
getStore: /* @__PURE__ */ __name(() => get().getStore(), "getStore"),
|
|
856
|
-
run: /* @__PURE__ */ __name((store2, callback) => get().run(store2, callback), "run")
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
case "browser":
|
|
860
|
-
default:
|
|
861
|
-
return {
|
|
862
|
-
getStore: /* @__PURE__ */ __name(() => {
|
|
863
|
-
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
864
|
-
}, "getStore"),
|
|
865
|
-
run: /* @__PURE__ */ __name(() => {
|
|
866
|
-
throw new PlatformUnsupportedFunction("createAsyncLocalStorage");
|
|
867
|
-
}, "run")
|
|
868
|
-
};
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
};
|
|
872
|
-
__name(_PlatformAdapter, "PlatformAdapter");
|
|
873
|
-
var PlatformAdapter = _PlatformAdapter;
|
|
874
|
-
var platformInstance = null;
|
|
875
|
-
function getPlatform() {
|
|
876
|
-
if (!platformInstance) {
|
|
877
|
-
const env = detectEnvironment();
|
|
878
|
-
platformInstance = new PlatformAdapter(env);
|
|
879
|
-
}
|
|
880
|
-
return platformInstance;
|
|
881
|
-
}
|
|
882
|
-
__name(getPlatform, "getPlatform");
|
|
883
|
-
|
|
884
893
|
// src/globals/middleware/requireContext.middleware.ts
|
|
885
894
|
var requireContextTaskMiddleware = defineTaskMiddleware({
|
|
886
895
|
id: "globals.middleware.requireContext",
|
|
@@ -965,7 +974,7 @@ var globalTags = {
|
|
|
965
974
|
};
|
|
966
975
|
|
|
967
976
|
// src/globals/globalEvents.ts
|
|
968
|
-
|
|
977
|
+
globalTags.system;
|
|
969
978
|
var globalEvents = {
|
|
970
979
|
// Minimal core events retained if any (custom events can still be defined by users)
|
|
971
980
|
/**
|
|
@@ -977,17 +986,6 @@ var globalEvents = {
|
|
|
977
986
|
title: "System Ready",
|
|
978
987
|
description: "Emitted when the system has completed boot and is ready for listeners to start work.This runs right before returning value for run()."
|
|
979
988
|
}
|
|
980
|
-
}),
|
|
981
|
-
/**
|
|
982
|
-
* Central error boundary event for any thrown error across the runner.
|
|
983
|
-
*/
|
|
984
|
-
unhandledError: defineEvent({
|
|
985
|
-
id: "globals.events.unhandledError",
|
|
986
|
-
meta: {
|
|
987
|
-
title: "Unhandled Error",
|
|
988
|
-
description: "Central error boundary event for any thrown error across the runner."
|
|
989
|
-
},
|
|
990
|
-
tags: [systemTag, globalTags.excludeFromGlobalHooks]
|
|
991
989
|
})
|
|
992
990
|
};
|
|
993
991
|
var globalEventsArray = [globalEvents.ready];
|