@oazmi/superbuild 0.1.0
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/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts +598 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.js +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts +617 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.js +671 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts +487 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.js +536 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts +266 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.js +318 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts +368 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.js +380 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts +711 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.js +1173 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts +171 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.js +308 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts +10 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.js +10 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts +168 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.js +236 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts +90 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.js +237 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts +213 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.js +363 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts +233 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.js +256 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts +1436 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.js +1730 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts +647 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.js +762 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts +538 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.js +626 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts +734 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.js +764 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts +137 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.js +234 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts +391 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts.map +1 -0
- package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.js +8 -0
- package/esm/deps.d.ts +56 -0
- package/esm/deps.d.ts.map +1 -0
- package/esm/deps.js +37 -0
- package/esm/esbuild/metafile.d.ts +90 -0
- package/esm/esbuild/metafile.d.ts.map +1 -0
- package/esm/esbuild/metafile.js +275 -0
- package/esm/esbuild/native.d.ts +95 -0
- package/esm/esbuild/native.d.ts.map +1 -0
- package/esm/esbuild/native.js +127 -0
- package/esm/esbuild/outputfile.d.ts +86 -0
- package/esm/esbuild/outputfile.d.ts.map +1 -0
- package/esm/esbuild/outputfile.js +221 -0
- package/esm/esbuild/strongtypes.d.ts +90 -0
- package/esm/esbuild/strongtypes.d.ts.map +1 -0
- package/esm/esbuild/strongtypes.js +8 -0
- package/esm/esbuild/typedefs.d.ts +121 -0
- package/esm/esbuild/typedefs.d.ts.map +1 -0
- package/esm/esbuild/typedefs.js +55 -0
- package/esm/esbuild/weaktypes.d.ts +46 -0
- package/esm/esbuild/weaktypes.d.ts.map +1 -0
- package/esm/esbuild/weaktypes.js +8 -0
- package/esm/funcdefs.d.ts +89 -0
- package/esm/funcdefs.d.ts.map +1 -0
- package/esm/funcdefs.js +145 -0
- package/esm/mod.d.ts +4 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +2 -0
- package/esm/package.json +3 -0
- package/esm/plugins/emissions_driver.d.ts +33 -0
- package/esm/plugins/emissions_driver.d.ts.map +1 -0
- package/esm/plugins/emissions_driver.js +260 -0
- package/esm/plugins/long_build.d.ts +138 -0
- package/esm/plugins/long_build.d.ts.map +1 -0
- package/esm/plugins/long_build.js +288 -0
- package/esm/plugins/native_replica.d.ts +48 -0
- package/esm/plugins/native_replica.d.ts.map +1 -0
- package/esm/plugins/native_replica.js +122 -0
- package/esm/super/build.d.ts +53 -0
- package/esm/super/build.d.ts.map +1 -0
- package/esm/super/build.js +39 -0
- package/esm/super/build_context.d.ts +83 -0
- package/esm/super/build_context.d.ts.map +1 -0
- package/esm/super/build_context.js +124 -0
- package/esm/super/mod.d.ts +12 -0
- package/esm/super/mod.d.ts.map +1 -0
- package/esm/super/mod.js +9 -0
- package/esm/super/plugin.d.ts +23 -0
- package/esm/super/plugin.d.ts.map +1 -0
- package/esm/super/plugin.js +31 -0
- package/esm/super/plugin_build.d.ts +38 -0
- package/esm/super/plugin_build.d.ts.map +1 -0
- package/esm/super/plugin_build.js +198 -0
- package/esm/super/typedefs.d.ts +323 -0
- package/esm/super/typedefs.d.ts.map +1 -0
- package/esm/super/typedefs.js +10 -0
- package/esm/typedefs.d.ts +21 -0
- package/esm/typedefs.d.ts.map +1 -0
- package/esm/typedefs.js +5 -0
- package/license.md +37 -0
- package/package.json +88 -0
- package/readme.md +181 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/** a utility functions submodule.
|
|
2
|
+
*
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import type { EsbuildEntryPointsType } from "./esbuild/typedefs.js";
|
|
6
|
+
import type { LoggerFunction } from "./typedefs.js";
|
|
7
|
+
export declare const concatArrays: <T>(arr1?: Array<T>, arr2?: Array<T>) => Array<T> | undefined;
|
|
8
|
+
export declare const mergeMapArrays: <K, T>(map1: Map<K, Array<T>>, map2: Map<K, Array<T>>) => Map<K, Array<T>>;
|
|
9
|
+
/** this function wraps on top of a promise-resolver function, and returns two functions.
|
|
10
|
+
* the first function, when called, will resolve the original `promise_resolver` _after_ the specified `delay` amount of milliseconds have passed.
|
|
11
|
+
* during this delay time, you may use the second function that is returned to cancel the task of running the `promise_resolver` before it times out.
|
|
12
|
+
* you also have the option to specify the `delay` for the next time the returned `resolve` function is called.
|
|
13
|
+
* if it is not specified, then the `original_delay` will be used in its place.
|
|
14
|
+
*/
|
|
15
|
+
export declare const cancelableDelayedPromiseResolver: <T>(promise_resolver: (value: T) => void, original_delay: number, logger?: LoggerFunction) => [resolve: (value: T) => void, cancel: (delay?: number) => void];
|
|
16
|
+
/** generates `segments` number of 8-character (32-bit) uuid based on the current time stamp. */
|
|
17
|
+
export declare const generateUuid: (segments?: number, current_time?: number) => string;
|
|
18
|
+
export declare const splitNamespacedPath: (resolved_namespaced_path: string) => {
|
|
19
|
+
namespace: string;
|
|
20
|
+
path: string;
|
|
21
|
+
};
|
|
22
|
+
/** alias for `console.log`. this is the default logging function. */
|
|
23
|
+
export declare const logLogger: LoggerFunction;
|
|
24
|
+
/** the history of the {@link arrayLogger} function gets contained here. */
|
|
25
|
+
export declare const arrayLoggerHistory: Array<any[]>;
|
|
26
|
+
/** an array based logging function. the log history is kept in the {@link arrayLoggerHistory} array. */
|
|
27
|
+
export declare const arrayLogger: LoggerFunction;
|
|
28
|
+
/** a no operation logger function that does nothing. */
|
|
29
|
+
export declare const noopLogger: LoggerFunction;
|
|
30
|
+
/** this function accepts various forms of entry-points that are accepted by esbuild, and transforms them into an array of 2-tuples.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
35
|
+
*
|
|
36
|
+
* // aliasing our functions for brevity
|
|
37
|
+
* const
|
|
38
|
+
* fn = entryPointsToImportMapEntries,
|
|
39
|
+
* eq = assertEquals
|
|
40
|
+
*
|
|
41
|
+
* eq(fn(["input-a", "input-b", "input-c"]), [
|
|
42
|
+
* ["input-a", "input-a"],
|
|
43
|
+
* ["input-b", "input-b"],
|
|
44
|
+
* ["input-c", "input-c"],
|
|
45
|
+
* ])
|
|
46
|
+
*
|
|
47
|
+
* eq(fn({
|
|
48
|
+
* "input-a": "output-a",
|
|
49
|
+
* "input-b": "output-b",
|
|
50
|
+
* "input-c": "output-c",
|
|
51
|
+
* }), [
|
|
52
|
+
* ["input-a", "output-a"],
|
|
53
|
+
* ["input-b", "output-b"],
|
|
54
|
+
* ["input-c", "output-c"],
|
|
55
|
+
* ])
|
|
56
|
+
*
|
|
57
|
+
* eq(fn([
|
|
58
|
+
* ["input-a", "output-a"],
|
|
59
|
+
* ["input-b", "output-b"],
|
|
60
|
+
* ["input-c", "output-c"],
|
|
61
|
+
* ]), [
|
|
62
|
+
* ["input-a", "output-a"],
|
|
63
|
+
* ["input-b", "output-b"],
|
|
64
|
+
* ["input-c", "output-c"],
|
|
65
|
+
* ])
|
|
66
|
+
*
|
|
67
|
+
* eq(fn([
|
|
68
|
+
* { in: "input-a", out: "output-a" },
|
|
69
|
+
* { in: "input-b", out: "output-b" },
|
|
70
|
+
* { in: "input-c", out: "output-c" },
|
|
71
|
+
* ]), [
|
|
72
|
+
* ["input-a", "output-a"],
|
|
73
|
+
* ["input-b", "output-b"],
|
|
74
|
+
* ["input-c", "output-c"],
|
|
75
|
+
* ])
|
|
76
|
+
*
|
|
77
|
+
* eq(fn([
|
|
78
|
+
* "input-a",
|
|
79
|
+
* ["input-b", "output-b"],
|
|
80
|
+
* { in: "input-c", out: "output-c" },
|
|
81
|
+
* ]), [
|
|
82
|
+
* ["input-a", "input-a"],
|
|
83
|
+
* ["input-b", "output-b"],
|
|
84
|
+
* ["input-c", "output-c"],
|
|
85
|
+
* ])
|
|
86
|
+
* ```
|
|
87
|
+
*/
|
|
88
|
+
export declare const entryPointsToImportMapEntries: (entry_points: EsbuildEntryPointsType) => Array<[input: string, output: string]>;
|
|
89
|
+
//# sourceMappingURL=funcdefs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"funcdefs.d.ts","sourceRoot":"","sources":["../src/funcdefs.ts"],"names":[],"mappings":"AAAA;;;EAGE;AAGF,OAAO,KAAK,EAAE,sBAAsB,EAAyB,MAAM,uBAAuB,CAAA;AAC1F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAGnD,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,KAAG,KAAK,CAAC,CAAC,CAAC,GAAG,SAK7E,CAAA;AAED,eAAO,MAAM,cAAc,GAAI,CAAC,EAAE,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,KAAG,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAQpG,CAAA;AAED;;;;;EAKE;AACF,eAAO,MAAM,gCAAgC,GAAI,CAAC,oBAC/B,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,kBACpB,MAAM,WACd,cAAc,KACpB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAkBhE,CAAA;AAID,gGAAgG;AAChG,eAAO,MAAM,YAAY,qCAAiC,MAAM,WAW/D,CAAA;AAED,eAAO,MAAM,mBAAmB,6BAA8B,MAAM,KAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAMvG,CAAA;AAED,qEAAqE;AACrE,eAAO,MAAM,SAAS,EAAE,cAA4B,CAAA;AAOpD,2EAA2E;AAC3E,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,GAAG,EAAE,CAAM,CAAA;AAElD,wGAAwG;AACxG,eAAO,MAAM,WAAW,EAAE,cAAqE,CAAA;AAE/F,wDAAwD;AACxD,eAAO,MAAM,UAAU,EAAE,cAAqB,CAAA;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAyDE;AACF,eAAO,MAAM,6BAA6B,iBAAkB,sBAAsB,KAAG,KAAK,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAQzH,CAAA"}
|
package/esm/funcdefs.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/** a utility functions submodule.
|
|
2
|
+
*
|
|
3
|
+
* @module
|
|
4
|
+
*/
|
|
5
|
+
import { bind_array_push, console_log, crc32, date_now, DEBUG, dom_clearTimeout, dom_setTimeout, isArray, isString, math_max, noop, object_entries } from "./deps.js";
|
|
6
|
+
export const concatArrays = (arr1, arr2) => {
|
|
7
|
+
return (!arr1 && !arr2) ? undefined
|
|
8
|
+
: !arr1 ? arr2
|
|
9
|
+
: !arr2 ? arr1
|
|
10
|
+
: [...arr1, ...arr2];
|
|
11
|
+
};
|
|
12
|
+
export const mergeMapArrays = (map1, map2) => {
|
|
13
|
+
const result = new Map(map1);
|
|
14
|
+
for (const [key, arr] of map2) {
|
|
15
|
+
const existing_arr = result.get(key);
|
|
16
|
+
if (existing_arr === undefined) {
|
|
17
|
+
result.set(key, arr);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
result.set(key, existing_arr.concat(arr));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
/** this function wraps on top of a promise-resolver function, and returns two functions.
|
|
26
|
+
* the first function, when called, will resolve the original `promise_resolver` _after_ the specified `delay` amount of milliseconds have passed.
|
|
27
|
+
* during this delay time, you may use the second function that is returned to cancel the task of running the `promise_resolver` before it times out.
|
|
28
|
+
* you also have the option to specify the `delay` for the next time the returned `resolve` function is called.
|
|
29
|
+
* if it is not specified, then the `original_delay` will be used in its place.
|
|
30
|
+
*/
|
|
31
|
+
export const cancelableDelayedPromiseResolver = (promise_resolver, original_delay, logger = noopLogger) => {
|
|
32
|
+
let
|
|
33
|
+
// bloody deno's node-compatibility "enhancements" is creating more incompatibilities with existing well known web-compatible constructs.
|
|
34
|
+
// man, do I hate the direction deno is heading. this didn't use to be an issue pre-v2.8 of deno.
|
|
35
|
+
timer_id = -1, delay = original_delay;
|
|
36
|
+
const resolve = (value) => {
|
|
37
|
+
dom_clearTimeout(timer_id); // clear out any previous timer.
|
|
38
|
+
if (DEBUG.LOG) {
|
|
39
|
+
logger(`delayed promise will resolve in ${delay}ms.`);
|
|
40
|
+
}
|
|
41
|
+
timer_id = dom_setTimeout(promise_resolver, delay, value);
|
|
42
|
+
}, cancel = (new_delay = original_delay) => {
|
|
43
|
+
dom_clearTimeout(timer_id); // clear out any previous timer.
|
|
44
|
+
if (DEBUG.LOG) {
|
|
45
|
+
logger(`delayed promise was canceled.`);
|
|
46
|
+
}
|
|
47
|
+
delay = new_delay;
|
|
48
|
+
};
|
|
49
|
+
return [resolve, cancel];
|
|
50
|
+
};
|
|
51
|
+
let uuid_counter = -1;
|
|
52
|
+
/** generates `segments` number of 8-character (32-bit) uuid based on the current time stamp. */
|
|
53
|
+
export const generateUuid = (segments = 1, current_time) => {
|
|
54
|
+
current_time ??= date_now();
|
|
55
|
+
uuid_counter++;
|
|
56
|
+
const crc32_segments = Array(math_max(segments, 0)).fill(current_time).map((time, i) => {
|
|
57
|
+
const seed = uuid_counter + time + i, seed_arr = new Uint8Array((new Uint32Array([seed])).buffer), uuid_segment = crc32(seed_arr);
|
|
58
|
+
return uuid_segment.toString(16).padStart(8, "0");
|
|
59
|
+
});
|
|
60
|
+
return crc32_segments.join("-");
|
|
61
|
+
};
|
|
62
|
+
export const splitNamespacedPath = (resolved_namespaced_path) => {
|
|
63
|
+
const namespace_splitting_idx = resolved_namespaced_path.indexOf(":"), namespace = resolved_namespaced_path.slice(0, namespace_splitting_idx), path = resolved_namespaced_path.slice(namespace_splitting_idx + 1);
|
|
64
|
+
return { namespace, path };
|
|
65
|
+
};
|
|
66
|
+
/** alias for `console.log`. this is the default logging function. */
|
|
67
|
+
export const logLogger = console_log;
|
|
68
|
+
const arrayLoggerFactory = (history) => {
|
|
69
|
+
const history_push = bind_array_push(history);
|
|
70
|
+
return (...data) => { history_push(data); };
|
|
71
|
+
};
|
|
72
|
+
/** the history of the {@link arrayLogger} function gets contained here. */
|
|
73
|
+
export const arrayLoggerHistory = [];
|
|
74
|
+
/** an array based logging function. the log history is kept in the {@link arrayLoggerHistory} array. */
|
|
75
|
+
export const arrayLogger = /*@__PURE__*/ arrayLoggerFactory(arrayLoggerHistory);
|
|
76
|
+
/** a no operation logger function that does nothing. */
|
|
77
|
+
export const noopLogger = noop;
|
|
78
|
+
/** this function accepts various forms of entry-points that are accepted by esbuild, and transforms them into an array of 2-tuples.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```ts
|
|
82
|
+
* import { assertEquals } from "jsr:@std/assert"
|
|
83
|
+
*
|
|
84
|
+
* // aliasing our functions for brevity
|
|
85
|
+
* const
|
|
86
|
+
* fn = entryPointsToImportMapEntries,
|
|
87
|
+
* eq = assertEquals
|
|
88
|
+
*
|
|
89
|
+
* eq(fn(["input-a", "input-b", "input-c"]), [
|
|
90
|
+
* ["input-a", "input-a"],
|
|
91
|
+
* ["input-b", "input-b"],
|
|
92
|
+
* ["input-c", "input-c"],
|
|
93
|
+
* ])
|
|
94
|
+
*
|
|
95
|
+
* eq(fn({
|
|
96
|
+
* "input-a": "output-a",
|
|
97
|
+
* "input-b": "output-b",
|
|
98
|
+
* "input-c": "output-c",
|
|
99
|
+
* }), [
|
|
100
|
+
* ["input-a", "output-a"],
|
|
101
|
+
* ["input-b", "output-b"],
|
|
102
|
+
* ["input-c", "output-c"],
|
|
103
|
+
* ])
|
|
104
|
+
*
|
|
105
|
+
* eq(fn([
|
|
106
|
+
* ["input-a", "output-a"],
|
|
107
|
+
* ["input-b", "output-b"],
|
|
108
|
+
* ["input-c", "output-c"],
|
|
109
|
+
* ]), [
|
|
110
|
+
* ["input-a", "output-a"],
|
|
111
|
+
* ["input-b", "output-b"],
|
|
112
|
+
* ["input-c", "output-c"],
|
|
113
|
+
* ])
|
|
114
|
+
*
|
|
115
|
+
* eq(fn([
|
|
116
|
+
* { in: "input-a", out: "output-a" },
|
|
117
|
+
* { in: "input-b", out: "output-b" },
|
|
118
|
+
* { in: "input-c", out: "output-c" },
|
|
119
|
+
* ]), [
|
|
120
|
+
* ["input-a", "output-a"],
|
|
121
|
+
* ["input-b", "output-b"],
|
|
122
|
+
* ["input-c", "output-c"],
|
|
123
|
+
* ])
|
|
124
|
+
*
|
|
125
|
+
* eq(fn([
|
|
126
|
+
* "input-a",
|
|
127
|
+
* ["input-b", "output-b"],
|
|
128
|
+
* { in: "input-c", out: "output-c" },
|
|
129
|
+
* ]), [
|
|
130
|
+
* ["input-a", "input-a"],
|
|
131
|
+
* ["input-b", "output-b"],
|
|
132
|
+
* ["input-c", "output-c"],
|
|
133
|
+
* ])
|
|
134
|
+
* ```
|
|
135
|
+
*/
|
|
136
|
+
export const entryPointsToImportMapEntries = (entry_points) => {
|
|
137
|
+
if (!isArray(entry_points)) {
|
|
138
|
+
entry_points = object_entries(entry_points);
|
|
139
|
+
}
|
|
140
|
+
return entry_points.map((entry) => {
|
|
141
|
+
return isString(entry) ? ([entry, entry])
|
|
142
|
+
: !isArray(entry) ? ([entry.in, entry.out])
|
|
143
|
+
: (entry);
|
|
144
|
+
});
|
|
145
|
+
};
|
package/esm/mod.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** exports a wrapper on top of esbuild to provide you with extended esbuild plugin-api capabilities (hence a super set of esbuild). */
|
|
2
|
+
export type * from "./super/mod.js";
|
|
3
|
+
export { INNER_PLUGIN_BUILD, SuperBuild, SuperBuildContext, SuperPluginBuild } from "./super/mod.js";
|
|
4
|
+
//# sourceMappingURL=mod.d.ts.map
|
package/esm/mod.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,uIAAuI;AAEvI,mBAAmB,gBAAgB,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
|
package/esm/mod.js
ADDED
package/esm/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/** an internal super-build plugin that drives and governs the {@link SuperPluginBuild.onEmit} and {@link SuperPluginBuild.onEnd} hooks,
|
|
2
|
+
* in order to make it possible for other plugins to modify the final output files (after their transformation and bundling)
|
|
3
|
+
* before they get emitted into the file system.
|
|
4
|
+
*
|
|
5
|
+
* this plugin should generally go in second place, after the long-build plugin, and before all other user plugins.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { EsbuildPlugin, EsbuildPluginSetup } from "../esbuild/strongtypes.js";
|
|
10
|
+
import type { SuperBuildContext } from "../super/build_context.js";
|
|
11
|
+
export interface EmissionsDriverPluginSetupConfig {
|
|
12
|
+
ctx: SuperBuildContext;
|
|
13
|
+
}
|
|
14
|
+
/** this plugin drives all {@link SuperPluginBuild.onEmit} and {@link SuperPluginBuild.onEnd} hooks,
|
|
15
|
+
* in order to make it possible for other plugins to modify the final output files (after their transformation and bundling).
|
|
16
|
+
*
|
|
17
|
+
* > [!note]
|
|
18
|
+
* > this plugin should generally go in second place, after the long-build plugin, and before all other user plugins.
|
|
19
|
+
*
|
|
20
|
+
* > Hello Maddam Siiir, you're vehicle has failed its emissions inspection.
|
|
21
|
+
* > you must subscribe to UK's £19/day _unclean vehicle_ program in order to use your vehicle,
|
|
22
|
+
* > so that we can offset your unclean carbon emissions and keep our planet clean. thank you for understanding.
|
|
23
|
+
* >
|
|
24
|
+
* > _meanwhile, at the hall of jeffery, circa 2013_
|
|
25
|
+
* >
|
|
26
|
+
* > _Larry McOracle_: jeffery, my second best friend, how many data centers did our supreme minister say he would like on 300 acre patches of american soil?
|
|
27
|
+
* >
|
|
28
|
+
* > _Jeffy McEpstien_: he says yes. and also get peter griffin, I mean thiel, onboard for a new mass surveillance initiative.
|
|
29
|
+
*/
|
|
30
|
+
export declare const emissionsDriverPluginSetup: (config: EmissionsDriverPluginSetupConfig) => EsbuildPluginSetup;
|
|
31
|
+
/** {@inheritDoc emissionsDriverPluginSetup} */
|
|
32
|
+
export declare const emissionsDriverPlugin: (config: EmissionsDriverPluginSetupConfig) => EsbuildPlugin;
|
|
33
|
+
//# sourceMappingURL=emissions_driver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emissions_driver.d.ts","sourceRoot":"","sources":["../../src/plugins/emissions_driver.ts"],"names":[],"mappings":"AAAA;;;;;;;EAOE;AAKF,OAAO,KAAK,EAAoF,aAAa,EAAsB,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAExL,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAA;AAOlE,MAAM,WAAW,gCAAgC;IAChD,GAAG,EAAE,iBAAiB,CAAA;CACtB;AAED;;;;;;;;;;;;;;;EAeE;AACF,eAAO,MAAM,0BAA0B,WAAY,gCAAgC,KAAG,kBAoGrF,CAAA;AAED,+CAA+C;AAC/C,eAAO,MAAM,qBAAqB,WAAY,gCAAgC,KAAG,aAKhF,CAAA"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/** an internal super-build plugin that drives and governs the {@link SuperPluginBuild.onEmit} and {@link SuperPluginBuild.onEnd} hooks,
|
|
2
|
+
* in order to make it possible for other plugins to modify the final output files (after their transformation and bundling)
|
|
3
|
+
* before they get emitted into the file system.
|
|
4
|
+
*
|
|
5
|
+
* this plugin should generally go in second place, after the long-build plugin, and before all other user plugins.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import { array_isEmpty, ensureEndSlash, fileUrlToLocalPath, getRuntimeCwd, identifyCurrentRuntime, isArray, isNull, pathToPosixPath, promise_all, promiseOutside, resolveAsUrl, resolvePathFactory, textDecoder } from "../deps.js";
|
|
10
|
+
import { concatArrays } from "../funcdefs.js";
|
|
11
|
+
import { INNER_PLUGIN_BUILD } from "../super/typedefs.js";
|
|
12
|
+
/** this plugin drives all {@link SuperPluginBuild.onEmit} and {@link SuperPluginBuild.onEnd} hooks,
|
|
13
|
+
* in order to make it possible for other plugins to modify the final output files (after their transformation and bundling).
|
|
14
|
+
*
|
|
15
|
+
* > [!note]
|
|
16
|
+
* > this plugin should generally go in second place, after the long-build plugin, and before all other user plugins.
|
|
17
|
+
*
|
|
18
|
+
* > Hello Maddam Siiir, you're vehicle has failed its emissions inspection.
|
|
19
|
+
* > you must subscribe to UK's £19/day _unclean vehicle_ program in order to use your vehicle,
|
|
20
|
+
* > so that we can offset your unclean carbon emissions and keep our planet clean. thank you for understanding.
|
|
21
|
+
* >
|
|
22
|
+
* > _meanwhile, at the hall of jeffery, circa 2013_
|
|
23
|
+
* >
|
|
24
|
+
* > _Larry McOracle_: jeffery, my second best friend, how many data centers did our supreme minister say he would like on 300 acre patches of american soil?
|
|
25
|
+
* >
|
|
26
|
+
* > _Jeffy McEpstien_: he says yes. and also get peter griffin, I mean thiel, onboard for a new mass surveillance initiative.
|
|
27
|
+
*/
|
|
28
|
+
export const emissionsDriverPluginSetup = (config) => {
|
|
29
|
+
const ctx = config.ctx;
|
|
30
|
+
return (build) => {
|
|
31
|
+
const abs_working_dir = pathToPosixPath(build.initialOptions.absWorkingDir ?? "./"), runtime_cwd = ensureEndSlash(getRuntimeCwd(identifyCurrentRuntime())), cwd = fileUrlToLocalPath(resolveAsUrl(abs_working_dir, runtime_cwd)), resolve_path = resolvePathFactory(cwd), base_plugin_build = INNER_PLUGIN_BUILD in build
|
|
32
|
+
? build[INNER_PLUGIN_BUILD]
|
|
33
|
+
: build;
|
|
34
|
+
const longBuildController = ctx.longBuildController, onEmitHandlers = ctx.onEmitHandlers, onEndHandlers = ctx.onEndHandlers;
|
|
35
|
+
// handles all registered `onEmit` hooks.
|
|
36
|
+
const performOnEmit = async (metafile) => {
|
|
37
|
+
const ctx = {
|
|
38
|
+
longBuildController,
|
|
39
|
+
metafile,
|
|
40
|
+
resolvePath: resolve_path,
|
|
41
|
+
warnings: metafile.warnings,
|
|
42
|
+
errors: [],
|
|
43
|
+
};
|
|
44
|
+
const longbuild_file = findLongBuildFile(ctx);
|
|
45
|
+
if (isNull(longbuild_file)) {
|
|
46
|
+
return { warnings: ctx.warnings, errors: ctx.errors };
|
|
47
|
+
}
|
|
48
|
+
await incorporateLongBuildImportedEntities(ctx, longbuild_file);
|
|
49
|
+
const files_dependency_graph = metafile.createFileDependencyGraph(), dependency_graph = DependencyGraphNode.fromGraph(files_dependency_graph), source_resource_nodes = DependencyGraphNode.chainNodePromises(dependency_graph), all_node_promises = Promise.all([...dependency_graph.values()].map((node) => (node.promise))), on_emit_callback = async (node, dependency_results) => {
|
|
50
|
+
const entity = node.key, on_emit_result = await entity.performOnEmit(onEmitHandlers);
|
|
51
|
+
// if any error is encountered in the user's `onEmit` hook function's return value,
|
|
52
|
+
// exit the build early by rejecting the promise, and cancelling everything downstream.
|
|
53
|
+
if ((on_emit_result?.errors?.length ?? 0) > 0) {
|
|
54
|
+
node.reject(on_emit_result.errors);
|
|
55
|
+
}
|
|
56
|
+
return on_emit_result;
|
|
57
|
+
};
|
|
58
|
+
dependency_graph.forEach((node) => { node.setCallback(on_emit_callback); });
|
|
59
|
+
source_resource_nodes.forEach((node) => { node.fire(); });
|
|
60
|
+
// waiting for all of the `onEmit` hooks to take action, and then accumulate all warnings and errors.
|
|
61
|
+
await all_node_promises
|
|
62
|
+
.then((all_on_emit_results) => {
|
|
63
|
+
for (const on_emit_result of all_on_emit_results) {
|
|
64
|
+
if (on_emit_result?.warnings) {
|
|
65
|
+
ctx.warnings.push(...on_emit_result.warnings);
|
|
66
|
+
}
|
|
67
|
+
// there shouldn't be any errors by this point. but I'll just put this case, just in case.
|
|
68
|
+
if (on_emit_result?.errors) {
|
|
69
|
+
ctx.errors.push(...on_emit_result.errors);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}).catch((errors) => {
|
|
73
|
+
if (isArray(errors)) {
|
|
74
|
+
ctx.errors.push(...errors);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
ctx.errors.push(errors);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
return { warnings: ctx.warnings, errors: ctx.errors };
|
|
81
|
+
};
|
|
82
|
+
// handle all registered `onEnd` hooks.
|
|
83
|
+
const performOnEnd = async (result) => {
|
|
84
|
+
const on_end_promises = onEndHandlers.map(async (handler) => {
|
|
85
|
+
const { pluginName, callback } = handler, on_end_result = await callback(result);
|
|
86
|
+
// inserting the original plugin names of the plugins where the errors and warnings originated from.
|
|
87
|
+
on_end_result?.warnings?.forEach((warning) => { if (!warning.pluginName) {
|
|
88
|
+
warning.pluginName = pluginName;
|
|
89
|
+
} });
|
|
90
|
+
on_end_result?.errors?.forEach((error) => { if (!error.pluginName) {
|
|
91
|
+
error.pluginName = pluginName;
|
|
92
|
+
} });
|
|
93
|
+
return on_end_result;
|
|
94
|
+
});
|
|
95
|
+
const warnings = [], errors = [];
|
|
96
|
+
for (const value of await promise_all(on_end_promises)) {
|
|
97
|
+
if (value?.warnings) {
|
|
98
|
+
warnings.push(...value.warnings);
|
|
99
|
+
}
|
|
100
|
+
if (value?.errors) {
|
|
101
|
+
errors.push(...value.errors);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return { warnings, errors };
|
|
105
|
+
};
|
|
106
|
+
base_plugin_build.onEnd(async (result) => {
|
|
107
|
+
const metafile = ctx.createMetafile(result, { resolvePath: resolve_path }), on_emit_results = await performOnEmit(metafile), on_end_results = await performOnEnd(result), warnings = concatArrays(on_emit_results?.warnings, on_end_results?.warnings), errors = concatArrays(on_emit_results?.errors, on_end_results?.errors);
|
|
108
|
+
// end this build by informing the build context via its `endBuild` method.
|
|
109
|
+
await ctx.endBuild(metafile);
|
|
110
|
+
return { warnings, errors };
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
/** {@inheritDoc emissionsDriverPluginSetup} */
|
|
115
|
+
export const emissionsDriverPlugin = (config) => {
|
|
116
|
+
return {
|
|
117
|
+
name: "oazmi-superbuild-emissions_driver-plugin",
|
|
118
|
+
setup: emissionsDriverPluginSetup(config),
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
/** searches for the long-build file (that originates from the {@link longBuildPlugin}) in the list of bundled output files generated by esbuild. */
|
|
122
|
+
const findLongBuildFile = (ctx) => {
|
|
123
|
+
const { longBuildController, metafile, errors } = ctx;
|
|
124
|
+
const longbuild_plugin_namespace = longBuildController.pluginNamespace, longbuild_files = metafile.findFileFromSources((input_sources) => {
|
|
125
|
+
const does_include_longbuild_source_file = input_sources.some(({ path: _source_resolved_path, namespace }) => {
|
|
126
|
+
return namespace === longbuild_plugin_namespace;
|
|
127
|
+
});
|
|
128
|
+
return does_include_longbuild_source_file;
|
|
129
|
+
});
|
|
130
|
+
if (longbuild_files.length !== 1) {
|
|
131
|
+
errors.push({ text: `[findLongBuildFile]: expected there to be only a single long-build file after bundling, instead found: ${longbuild_files.length} files.` });
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const longbuild_file = longbuild_files[0];
|
|
135
|
+
return longbuild_file;
|
|
136
|
+
};
|
|
137
|
+
/** parses the long-build plugin's output js file to discover additional user-made imports (specified during the transformation stage),
|
|
138
|
+
* and then adds them to their respective importer's {@link OutputFileEntity}.
|
|
139
|
+
*/
|
|
140
|
+
const incorporateLongBuildImportedEntities = async (ctx, longbuild_file) => {
|
|
141
|
+
const { longBuildController, metafile, resolvePath, warnings, } = ctx;
|
|
142
|
+
const longbuild_path = longbuild_file.initialPath ?? longbuild_file.outputPath, longbuild_contents = textDecoder.decode(longbuild_file.contents), import_entities = await longBuildController.parseLongBuildFileContent(longbuild_contents);
|
|
143
|
+
for (let [importer_resolved_path, entities_to_import] of import_entities) {
|
|
144
|
+
// `entities_to_import` are the runtime-based imports in the output file made by the user (i.e. plugins) during the transformation stage.
|
|
145
|
+
// our goal below is to first identify which output file entity(ies) originate from the `importer_resolved_path` source file,
|
|
146
|
+
// and then we shall inject the new (user made) imports into it/them (if there were multiple files using the same importer as their source file).
|
|
147
|
+
importer_resolved_path = importer_resolved_path.toLowerCase();
|
|
148
|
+
const entities_using_importer_as_input_source = metafile.findFileFromSources((input_sources) => {
|
|
149
|
+
const entity_uses_importer_as_source = input_sources.some(({ path, namespace }) => {
|
|
150
|
+
return (namespace + ":" + path).toLowerCase() === importer_resolved_path;
|
|
151
|
+
});
|
|
152
|
+
return entity_uses_importer_as_source;
|
|
153
|
+
});
|
|
154
|
+
if (array_isEmpty(entities_using_importer_as_input_source)) {
|
|
155
|
+
warnings.push({ text: `[incorporateLongBuildImportedEntities]: failed to find an output file that uses the following source as its input: "${importer_resolved_path}".` });
|
|
156
|
+
continue;
|
|
157
|
+
}
|
|
158
|
+
// TODO: re-consider what scenarios can lead to the warnable situation below. is it even a problem if it occurs?
|
|
159
|
+
if (entities_using_importer_as_input_source.length > 1) {
|
|
160
|
+
warnings.push({ text: `[incorporateLongBuildImportedEntities]: we usually expect only a single output file to be made out of the given input source: "${importer_resolved_path}".` });
|
|
161
|
+
}
|
|
162
|
+
// collect all import entity nodes that is to be incorporated into each entity using these imports.
|
|
163
|
+
const imported_entity_nodes = entities_to_import.map((import_entity) => {
|
|
164
|
+
// note: remember, `import_entity.path` is relative to the longbuild file, and not the importer's `initial_output_path`.
|
|
165
|
+
// moreover, only non-external entities must go through the local-file output path resolution.
|
|
166
|
+
const { key, path, with: with_attr = {}, external = false } = import_entity, kind = "user-import", // this is our standard `kind` label for user imports that originate from the transformation stage.
|
|
167
|
+
entity = external
|
|
168
|
+
? { externalPath: path }
|
|
169
|
+
: metafile.getFile(resolvePath(longbuild_path, path));
|
|
170
|
+
return { key, kind, with: with_attr, external, entity };
|
|
171
|
+
});
|
|
172
|
+
// finally, we add append copies of the `imported_entity_nodes` to each file entity that uses the `importer` file as an input source.
|
|
173
|
+
for (const file_entity of entities_using_importer_as_input_source) {
|
|
174
|
+
const initial_output_path = file_entity.initialPath ?? file_entity.outputPath, number_of_sources = file_entity.inputs.length;
|
|
175
|
+
// TODO: I'm not sure why I considered the situation below to be harmful. re-consider if there even is an issue with this scenario.
|
|
176
|
+
if (number_of_sources > 1) {
|
|
177
|
+
const input_sources = file_entity.inputs.map((input_source) => (input_source.namespace + ":" + input_source.path));
|
|
178
|
+
warnings.push({
|
|
179
|
+
text: `[incorporateLongBuildImportedEntities]: expected the output file "${initial_output_path}" to be composed of just a single file, `
|
|
180
|
+
+ `but instead found it to be comprised of ${number_of_sources} source: [${input_sources.join(",\n")}]`
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
// appending copies of the `imported_entity_nodes` into this file entity's `imports`.
|
|
184
|
+
file_entity.imports.push(...imported_entity_nodes.map((node) => { return { ...node }; }));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
class DependencyGraphNode {
|
|
189
|
+
key;
|
|
190
|
+
dependencies;
|
|
191
|
+
promise;
|
|
192
|
+
resolve;
|
|
193
|
+
reject;
|
|
194
|
+
callback;
|
|
195
|
+
constructor(key, dependencies) {
|
|
196
|
+
this.key = key;
|
|
197
|
+
this.dependencies = new Set(dependencies);
|
|
198
|
+
const [promise, resolve, reject] = promiseOutside();
|
|
199
|
+
this.promise = promise;
|
|
200
|
+
this.resolve = resolve;
|
|
201
|
+
this.reject = reject;
|
|
202
|
+
}
|
|
203
|
+
/** set the callback function to run once the {@link promise | promises} of _this_ node's {@link dependencies} get resolved.
|
|
204
|
+
* once your callback has been executed and waited for, the {@link promise} of _this_ node will also get resolved.
|
|
205
|
+
*/
|
|
206
|
+
setCallback(callback) {
|
|
207
|
+
this.callback = callback;
|
|
208
|
+
}
|
|
209
|
+
/** manually fire the {@link callback} function of this node, and have its {@Link promise} get resolved.
|
|
210
|
+
* this is only intended to be used for source nodes (which carry no dependencies), although it is not enforced.
|
|
211
|
+
*/
|
|
212
|
+
async fire() {
|
|
213
|
+
if (this.callback) {
|
|
214
|
+
this.callback(this, []).then(this.resolve, this.reject);
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
this.reject([{ text: `[DependencyGraphNode.fire]: no callback was set for node id: "${this.key}".` }]);
|
|
218
|
+
}
|
|
219
|
+
return this.promise;
|
|
220
|
+
}
|
|
221
|
+
/** create a dependency graph from an existing graph `Map`. */
|
|
222
|
+
static fromGraph(dependency_graph) {
|
|
223
|
+
const graph = [...dependency_graph].map(([key, dependencies]) => {
|
|
224
|
+
const node = new this(key, dependencies);
|
|
225
|
+
return [key, node];
|
|
226
|
+
});
|
|
227
|
+
return new Map(graph);
|
|
228
|
+
}
|
|
229
|
+
/** chains the promises of a dependency graph, so that each node's {@link callback} is fired after all of it dependencies have been fired,
|
|
230
|
+
* while maintaining asynchronocity among all branches.
|
|
231
|
+
* the returned value contains an array of all nodes that are source nodes (carry no dependency).
|
|
232
|
+
*/
|
|
233
|
+
static chainNodePromises(dependency_graph) {
|
|
234
|
+
const source_nodes = [];
|
|
235
|
+
for (const [id, node] of dependency_graph) {
|
|
236
|
+
if (node.dependencies.size <= 0) {
|
|
237
|
+
source_nodes.push(node);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const dependency_promises = [...node.dependencies].map((dep_id) => {
|
|
241
|
+
const dep_node = dependency_graph.get(dep_id);
|
|
242
|
+
return dep_node.promise;
|
|
243
|
+
});
|
|
244
|
+
Promise.all(dependency_promises)
|
|
245
|
+
.then((dependency_results) => {
|
|
246
|
+
const callback = node.callback;
|
|
247
|
+
if (!callback) {
|
|
248
|
+
node.reject([{
|
|
249
|
+
text: `[DependencyGraphNode::chainNodePromises]: no callback was set for node id: "${node.key}".`
|
|
250
|
+
}]);
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
node.resolve(callback(node, dependency_results));
|
|
254
|
+
}
|
|
255
|
+
})
|
|
256
|
+
.catch((reason) => node.reject(reason));
|
|
257
|
+
}
|
|
258
|
+
return source_nodes;
|
|
259
|
+
}
|
|
260
|
+
}
|