@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.
Files changed (118) hide show
  1. package/esm/_dnt.shims.d.ts +2 -0
  2. package/esm/_dnt.shims.d.ts.map +1 -0
  3. package/esm/_dnt.shims.js +57 -0
  4. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts +598 -0
  5. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.d.ts.map +1 -0
  6. package/esm/deps/jsr.io/@oazmi/esbuild-types/0.28.0/src/mod.js +1 -0
  7. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts +617 -0
  8. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.d.ts.map +1 -0
  9. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/alias.js +671 -0
  10. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts +487 -0
  11. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array1d.js +536 -0
  13. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts +266 -0
  14. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/array2d.js +318 -0
  16. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts +368 -0
  17. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/binder.js +380 -0
  19. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts +711 -0
  20. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/crossenv.js +1173 -0
  22. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts +171 -0
  23. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/cryptoman.js +308 -0
  25. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts +10 -0
  26. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/deps.js +10 -0
  28. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts +168 -0
  29. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack.js +236 -0
  31. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts +90 -0
  32. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/eightpack_varint.js +237 -0
  34. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts +213 -0
  35. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericarray.js +363 -0
  37. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts +233 -0
  38. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/numericmethods.js +256 -0
  40. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts +1436 -0
  41. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/pathman.js +1730 -0
  43. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts +647 -0
  44. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/promiseman.js +762 -0
  46. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts +538 -0
  47. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/stringman.js +626 -0
  49. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts +734 -0
  50. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/struct.js +764 -0
  52. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts +137 -0
  53. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedbuffer.js +234 -0
  55. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts +391 -0
  56. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@oazmi/kitchensink/0.10.0/src/typedefs.js +8 -0
  58. package/esm/deps.d.ts +56 -0
  59. package/esm/deps.d.ts.map +1 -0
  60. package/esm/deps.js +37 -0
  61. package/esm/esbuild/metafile.d.ts +90 -0
  62. package/esm/esbuild/metafile.d.ts.map +1 -0
  63. package/esm/esbuild/metafile.js +275 -0
  64. package/esm/esbuild/native.d.ts +95 -0
  65. package/esm/esbuild/native.d.ts.map +1 -0
  66. package/esm/esbuild/native.js +127 -0
  67. package/esm/esbuild/outputfile.d.ts +86 -0
  68. package/esm/esbuild/outputfile.d.ts.map +1 -0
  69. package/esm/esbuild/outputfile.js +221 -0
  70. package/esm/esbuild/strongtypes.d.ts +90 -0
  71. package/esm/esbuild/strongtypes.d.ts.map +1 -0
  72. package/esm/esbuild/strongtypes.js +8 -0
  73. package/esm/esbuild/typedefs.d.ts +121 -0
  74. package/esm/esbuild/typedefs.d.ts.map +1 -0
  75. package/esm/esbuild/typedefs.js +55 -0
  76. package/esm/esbuild/weaktypes.d.ts +46 -0
  77. package/esm/esbuild/weaktypes.d.ts.map +1 -0
  78. package/esm/esbuild/weaktypes.js +8 -0
  79. package/esm/funcdefs.d.ts +89 -0
  80. package/esm/funcdefs.d.ts.map +1 -0
  81. package/esm/funcdefs.js +145 -0
  82. package/esm/mod.d.ts +4 -0
  83. package/esm/mod.d.ts.map +1 -0
  84. package/esm/mod.js +2 -0
  85. package/esm/package.json +3 -0
  86. package/esm/plugins/emissions_driver.d.ts +33 -0
  87. package/esm/plugins/emissions_driver.d.ts.map +1 -0
  88. package/esm/plugins/emissions_driver.js +260 -0
  89. package/esm/plugins/long_build.d.ts +138 -0
  90. package/esm/plugins/long_build.d.ts.map +1 -0
  91. package/esm/plugins/long_build.js +288 -0
  92. package/esm/plugins/native_replica.d.ts +48 -0
  93. package/esm/plugins/native_replica.d.ts.map +1 -0
  94. package/esm/plugins/native_replica.js +122 -0
  95. package/esm/super/build.d.ts +53 -0
  96. package/esm/super/build.d.ts.map +1 -0
  97. package/esm/super/build.js +39 -0
  98. package/esm/super/build_context.d.ts +83 -0
  99. package/esm/super/build_context.d.ts.map +1 -0
  100. package/esm/super/build_context.js +124 -0
  101. package/esm/super/mod.d.ts +12 -0
  102. package/esm/super/mod.d.ts.map +1 -0
  103. package/esm/super/mod.js +9 -0
  104. package/esm/super/plugin.d.ts +23 -0
  105. package/esm/super/plugin.d.ts.map +1 -0
  106. package/esm/super/plugin.js +31 -0
  107. package/esm/super/plugin_build.d.ts +38 -0
  108. package/esm/super/plugin_build.d.ts.map +1 -0
  109. package/esm/super/plugin_build.js +198 -0
  110. package/esm/super/typedefs.d.ts +323 -0
  111. package/esm/super/typedefs.d.ts.map +1 -0
  112. package/esm/super/typedefs.js +10 -0
  113. package/esm/typedefs.d.ts +21 -0
  114. package/esm/typedefs.d.ts.map +1 -0
  115. package/esm/typedefs.js +5 -0
  116. package/license.md +37 -0
  117. package/package.json +88 -0
  118. package/readme.md +181 -0
@@ -0,0 +1,53 @@
1
+ /** super-build lets you overload esbuild to expand what you're capable of doing in the plugin-api.
2
+ *
3
+ * @module
4
+ */
5
+ import type { Esbuild, EsbuildBuildOptions, EsbuildBuildResult } from "../esbuild/strongtypes.js";
6
+ import type { LoggerFunction } from "../typedefs.js";
7
+ import { SuperBuildContext } from "./build_context.js";
8
+ export interface SuperBuildOptions extends EsbuildBuildOptions {
9
+ /** enable internal logging of super-build for debugging, when {@link DEBUG.LOG} is enabled.
10
+ *
11
+ * when set to `true`, the logs will show up in your console via `console.log()`.
12
+ * you may also provide your own custom logger function if you wish.
13
+ *
14
+ * @defaultValue `false`
15
+ */
16
+ debuggingLogs?: boolean | LoggerFunction;
17
+ }
18
+ export type SuperBuildExclusiveOptions = Omit<SuperBuildOptions, keyof EsbuildBuildOptions>;
19
+ /** super-build lets you overload esbuild to expand what you're capable of doing in the plugin-api.
20
+ *
21
+ * this class creates a mere wrapper over a base `esbuild` object (acquired from `import esbuild from "npm:esbuild"`).
22
+ * this class itself does not do anything interesting aside from overloading the `esbuild.build` and `esbuild.buildSync` methods,
23
+ * to pass a modified version of your `esbuild.BuildOptions` that alters the plugin api (which is performed by {@link SuperBuildContext}).
24
+ */
25
+ export declare class SuperBuild implements Esbuild {
26
+ #private;
27
+ version: Esbuild["version"];
28
+ analyzeMetafile: Esbuild["analyzeMetafile"];
29
+ analyzeMetafileSync: Esbuild["analyzeMetafileSync"];
30
+ context: Esbuild["context"];
31
+ formatMessages: Esbuild["formatMessages"];
32
+ formatMessagesSync: Esbuild["formatMessagesSync"];
33
+ initialize: Esbuild["initialize"];
34
+ transform: Esbuild["transform"];
35
+ transformSync: Esbuild["transformSync"];
36
+ stop: Esbuild["stop"];
37
+ constructor(base_esbuild: Esbuild);
38
+ protected splitOptions(options: SuperBuildOptions): [
39
+ super_options: SuperBuildExclusiveOptions,
40
+ esbuild_options: EsbuildBuildOptions
41
+ ];
42
+ protected createContext(options: SuperBuildOptions): [
43
+ ctx: SuperBuildContext,
44
+ esbuild_options: EsbuildBuildOptions
45
+ ];
46
+ build<T extends SuperBuildOptions>(options: T & {
47
+ [Key in Exclude<keyof T, keyof SuperBuildOptions>]: never;
48
+ }): Promise<EsbuildBuildResult<T>>;
49
+ buildSync<T extends SuperBuildOptions>(options: T & {
50
+ [Key in Exclude<keyof T, keyof SuperBuildOptions>]: never;
51
+ }): EsbuildBuildResult<T>;
52
+ }
53
+ //# sourceMappingURL=build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/super/build.ts"],"names":[],"mappings":"AAAA;;;EAGE;AAGF,OAAO,KAAK,EACX,OAAO,EACP,mBAAmB,EACnB,kBAAkB,EAClB,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAGtD,MAAM,WAAW,iBAAkB,SAAQ,mBAAmB;IAC7D;;;;;;MAME;IACF,aAAa,CAAC,EAAE,OAAO,GAAG,cAAc,CAAA;CACxC;AAED,MAAM,MAAM,0BAA0B,GAAG,IAAI,CAAC,iBAAiB,EAAE,MAAM,mBAAmB,CAAC,CAAA;AAE3F;;;;;EAKE;AACF,qBAAa,UAAW,YAAW,OAAO;;IA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+ *
3
+ * @module
4
+ */
5
+ import { object_assign } from "../deps.js";
6
+ import { SuperBuildContext } from "./build_context.js";
7
+ /** super-build lets you overload esbuild to expand what you're capable of doing in the plugin-api.
8
+ *
9
+ * this class creates a mere wrapper over a base `esbuild` object (acquired from `import esbuild from "npm:esbuild"`).
10
+ * this class itself does not do anything interesting aside from overloading the `esbuild.build` and `esbuild.buildSync` methods,
11
+ * to pass a modified version of your `esbuild.BuildOptions` that alters the plugin api (which is performed by {@link SuperBuildContext}).
12
+ */
13
+ export class SuperBuild {
14
+ #esbuild;
15
+ constructor(base_esbuild) {
16
+ this.#esbuild = base_esbuild;
17
+ const { build, buildSync, ...rest_props } = base_esbuild;
18
+ object_assign(this, rest_props);
19
+ }
20
+ splitOptions(options) {
21
+ const { debuggingLogs, ...esbuild_options } = options;
22
+ const super_options = {
23
+ debuggingLogs
24
+ };
25
+ return [super_options, esbuild_options];
26
+ }
27
+ createContext(options) {
28
+ const [super_options, esbuild_options] = this.splitOptions(options), new_ctx = new SuperBuildContext(super_options);
29
+ return [new_ctx, esbuild_options];
30
+ }
31
+ async build(options) {
32
+ const [new_ctx, esbuild_options] = this.createContext(options);
33
+ return this.#esbuild.build(new_ctx.processPlugins(esbuild_options));
34
+ }
35
+ buildSync(options) {
36
+ const [new_ctx, esbuild_options] = this.createContext(options);
37
+ return this.#esbuild.buildSync(new_ctx.processPlugins(esbuild_options));
38
+ }
39
+ }
@@ -0,0 +1,83 @@
1
+ /** the {@link SuperBuildContext} is a centralized context that is created for each individual {@link SuperBuild.build} call.
2
+ *
3
+ * its main purpose is to inject some required plugins at their correct position, hold a few stateful objects,
4
+ * and create a wrapper on top of the user's provided plugins so that the extended plugin api becomes available to them.
5
+ *
6
+ * @module
7
+ */
8
+ import { Metafile, type MetafileConfig } from "../esbuild/metafile.js";
9
+ import type { EsbuildBuildOptions, EsbuildBuildResult, EsbuildOnEndCallback } from "../esbuild/strongtypes.js";
10
+ import { LongBuildController } from "../plugins/long_build.js";
11
+ import type { LoggerFunction, NamespacedPath } from "../typedefs.js";
12
+ import type { SuperBuildExclusiveOptions } from "./build.js";
13
+ import type { BundledInputFile, OnEmitCallback, OnEmitOptions, OnTransformCallback, OnTransformOptions } from "./typedefs.js";
14
+ export interface OnTransformHandler extends OnTransformOptions {
15
+ pluginName: string;
16
+ callback: OnTransformCallback;
17
+ }
18
+ export interface OnEmitHandler extends OnEmitOptions {
19
+ pluginName: string;
20
+ callback: OnEmitCallback;
21
+ }
22
+ export interface OnEndHandler {
23
+ pluginName: string;
24
+ callback: EsbuildOnEndCallback;
25
+ }
26
+ /** a centralized context is created for each individual {@link SuperBuild.build} call. */
27
+ export declare class SuperBuildContext {
28
+ /** contains a list of transformation handlers that will be used for matching contents returned by the plugins' `onLoad` hooks,
29
+ * in order to transfer them to the registered {@link SuperPluginBuild.onTransform} hooks.
30
+ */
31
+ onTransformHandlers: OnTransformHandler[];
32
+ /** contains a list of `onEmit` handlers that will be called once the file contents of the bundle has been finalized by esbuild,
33
+ * but additional actions (such as linking, and re-incorporating imports for generic loaders) still need to be taken care of by the user's plugins.
34
+ * the callbacks accumulated here are registered by {@link SuperPluginBuild.onEmit}.
35
+ */
36
+ onEmitHandlers: OnEmitHandler[];
37
+ /** contains a list of `onEnd` handlers that will be called at the end of the build,
38
+ * after we have modified the contents of the resulting in-memory files.
39
+ * the callbacks accumulated here are registered by {@link SuperPluginBuild.onEnd}.
40
+ */
41
+ onEndHandlers: OnEndHandler[];
42
+ /** holds all loaded resources, using `${namespace}:${resolved_path}` for the key.
43
+ * this registry is needed in order to trace back the loaded input file(s) from which an emitted file originates from,
44
+ * in order to make the functionality of {@link SuperPluginBuild.onEmit} possible.
45
+ */
46
+ resolvedResourceRegistry: Map<NamespacedPath, BundledInputFile>;
47
+ /** the controller used for commanding the state of the "long build" plugin. */
48
+ longBuildController: LongBuildController;
49
+ /** indicates the original `write` option specified by the user when instantiating the build. */
50
+ shouldWrite: boolean;
51
+ /** indicates if the original `allowOverwrite` option was enabled when the build was started. */
52
+ shouldOverwrite: boolean;
53
+ /** a logging function for internal debugging. it gets called only when {@link DEBUG.LOG} is enabled. */
54
+ log: LoggerFunction;
55
+ constructor(super_options: SuperBuildExclusiveOptions);
56
+ /** this method wraps a {@link SuperPlugin} on top of each of the user's base plugin,
57
+ * in addition to injecting two essential plugins at their correct position to make the new plugin apis work.
58
+ *
59
+ * the two internal plugins that get injected are:
60
+ * - {@link nativeReplicaPlugin}: this plugin mimics esbuild's native resource path resolution and loading,
61
+ * and it gets injected at the last, since esbuild only performs its native actions when other plugins don't return a viable result.
62
+ * - {@link longBuildPlugin}: this plugin gets injected at the beginning,
63
+ * and it book-keeps the number of resources/paths that have entered, the number of resources that have exited (i.e. loaded),
64
+ * and the number of resources that have been cached, in order to determine when esbuild has concluded processing all inputs,
65
+ * before esbuild exists out of the build and begins calling the `build.onEnd` callbacks.
66
+ * once this plugin has determined that all files in the current scope have been processed, it gathers all `imports` from the {@link OnTransformResult}s,
67
+ * and compiles/bundles them in a new recursive scope (hence the name "long-build").
68
+ */
69
+ processPlugins(options: EsbuildBuildOptions): EsbuildBuildOptions;
70
+ /** creates the the metafile object from esbuild's {@link EsbuildBuildResult},
71
+ * and registers all output files onto it for the {@link emissionsDriverPlugin} to initiate the next step (`onEmit` stage).
72
+ */
73
+ createMetafile(result: EsbuildBuildResult, config: Pick<MetafileConfig, "resolvePath">): Metafile;
74
+ /** concludes the build after the all registered {@link onEmitHandlers} and {@link onEndHandlers}
75
+ * have been executed by the {@link emissionsDriverPlugin} when it enters its `onEnd` stage (registered to the "true" `build` object).
76
+ *
77
+ * you must pass the mutated {@link Metafile} that you receive from calling the {@link createMetafile}
78
+ * method at the beginning of the {@link emissionsDriverPlugin}'s `onEnd` stage,
79
+ * so that if there's anything that should get written onto your filesystem, it will take place before the build concludes.
80
+ */
81
+ endBuild(metafile: Metafile): Promise<void>;
82
+ }
83
+ //# sourceMappingURL=build_context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file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,EAAE,OAAO,CAAQ;IAEvC,wGAAwG;IACjG,GAAG,EAAE,cAAc,CAAA;gBAEd,aAAa,EAAE,0BAA0B;IAUrD;;;;;;;;;;;;MAYE;IACK,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,mBAAmB;IAgCxE;;MAEE;IACK,cAAc,CACpB,MAAM,EAAE,kBAAkB,EAC1B,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,GACzC,QAAQ;IAYX;;;;;;MAME;IACW,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAKxD"}
@@ -0,0 +1,124 @@
1
+ /** the {@link SuperBuildContext} is a centralized context that is created for each individual {@link SuperBuild.build} call.
2
+ *
3
+ * its main purpose is to inject some required plugins at their correct position, hold a few stateful objects,
4
+ * and create a wrapper on top of the user's provided plugins so that the extended plugin api becomes available to them.
5
+ *
6
+ * @module
7
+ */
8
+ import { isArray, parseFilepathInfo } from "../deps.js";
9
+ import { Metafile } from "../esbuild/metafile.js";
10
+ import { logLogger, noopLogger } from "../funcdefs.js";
11
+ import { emissionsDriverPlugin } from "../plugins/emissions_driver.js";
12
+ import { LongBuildController, longBuildPlugin } from "../plugins/long_build.js";
13
+ import { nativeReplicaPlugin } from "../plugins/native_replica.js";
14
+ import { SuperPlugin } from "./plugin.js";
15
+ /** a centralized context is created for each individual {@link SuperBuild.build} call. */
16
+ export class SuperBuildContext {
17
+ /** contains a list of transformation handlers that will be used for matching contents returned by the plugins' `onLoad` hooks,
18
+ * in order to transfer them to the registered {@link SuperPluginBuild.onTransform} hooks.
19
+ */
20
+ onTransformHandlers = [];
21
+ /** contains a list of `onEmit` handlers that will be called once the file contents of the bundle has been finalized by esbuild,
22
+ * but additional actions (such as linking, and re-incorporating imports for generic loaders) still need to be taken care of by the user's plugins.
23
+ * the callbacks accumulated here are registered by {@link SuperPluginBuild.onEmit}.
24
+ */
25
+ onEmitHandlers = [];
26
+ /** contains a list of `onEnd` handlers that will be called at the end of the build,
27
+ * after we have modified the contents of the resulting in-memory files.
28
+ * the callbacks accumulated here are registered by {@link SuperPluginBuild.onEnd}.
29
+ */
30
+ onEndHandlers = [];
31
+ /** holds all loaded resources, using `${namespace}:${resolved_path}` for the key.
32
+ * this registry is needed in order to trace back the loaded input file(s) from which an emitted file originates from,
33
+ * in order to make the functionality of {@link SuperPluginBuild.onEmit} possible.
34
+ */
35
+ resolvedResourceRegistry = new Map();
36
+ /** the controller used for commanding the state of the "long build" plugin. */
37
+ longBuildController;
38
+ /** indicates the original `write` option specified by the user when instantiating the build. */
39
+ shouldWrite = true;
40
+ /** indicates if the original `allowOverwrite` option was enabled when the build was started. */
41
+ shouldOverwrite = false;
42
+ /** a logging function for internal debugging. it gets called only when {@link DEBUG.LOG} is enabled. */
43
+ log;
44
+ constructor(super_options) {
45
+ const { debuggingLogs = false } = super_options, log = debuggingLogs === false ? noopLogger
46
+ : debuggingLogs === true ? logLogger
47
+ : debuggingLogs;
48
+ this.log = log;
49
+ this.longBuildController = new LongBuildController({ debuggingLogs: log });
50
+ }
51
+ /** this method wraps a {@link SuperPlugin} on top of each of the user's base plugin,
52
+ * in addition to injecting two essential plugins at their correct position to make the new plugin apis work.
53
+ *
54
+ * the two internal plugins that get injected are:
55
+ * - {@link nativeReplicaPlugin}: this plugin mimics esbuild's native resource path resolution and loading,
56
+ * and it gets injected at the last, since esbuild only performs its native actions when other plugins don't return a viable result.
57
+ * - {@link longBuildPlugin}: this plugin gets injected at the beginning,
58
+ * and it book-keeps the number of resources/paths that have entered, the number of resources that have exited (i.e. loaded),
59
+ * and the number of resources that have been cached, in order to determine when esbuild has concluded processing all inputs,
60
+ * before esbuild exists out of the build and begins calling the `build.onEnd` callbacks.
61
+ * once this plugin has determined that all files in the current scope have been processed, it gathers all `imports` from the {@link OnTransformResult}s,
62
+ * and compiles/bundles them in a new recursive scope (hence the name "long-build").
63
+ */
64
+ processPlugins(options) {
65
+ options.plugins ??= [];
66
+ // insert the "native loader" at the last, so that esbuild never gets to load natively
67
+ // (which would bypass our `onLoad` overload, making all `onTransform` hooks unreachable).
68
+ options.plugins.push(nativeReplicaPlugin());
69
+ // insert the "emissions driver" as the second plugin,
70
+ // so that it can drive all `onEmit` and `onEnd` callback hooks after the build has concluded.
71
+ options.plugins.unshift(emissionsDriverPlugin({ ctx: this }));
72
+ // insert a longbuild plugin at the very beginning so that it can intercept all incoming files.
73
+ const controller = this.longBuildController;
74
+ options.plugins.unshift(longBuildPlugin({ controller }));
75
+ options.plugins = options.plugins.map((plugin) => (new SuperPlugin(this, plugin)));
76
+ // we also insert the unique long build entry point to the options.
77
+ const long_build_filename = controller.steps.at(-1).filename, entryPoints = (options.entryPoints ??= []);
78
+ if (isArray(entryPoints)) {
79
+ entryPoints.push(long_build_filename);
80
+ }
81
+ else {
82
+ // stripping away the ".js" extension from the filename.
83
+ entryPoints[long_build_filename] = parseFilepathInfo(long_build_filename).basename;
84
+ }
85
+ this.shouldWrite = options.write ?? true;
86
+ this.shouldOverwrite = options.allowOverwrite ?? false;
87
+ // we are forced to enable `metafile` and disable `write` because our emissions driver plugin depends on these crucial options.
88
+ // once the build has concluded, the emissions driver plugin will call the `endBuild`
89
+ // method to take care of emitting the files to the filesystem if `this.shouldWrite` is set to `true`.
90
+ options.metafile = true;
91
+ options.write = false;
92
+ return options;
93
+ }
94
+ /** creates the the metafile object from esbuild's {@link EsbuildBuildResult},
95
+ * and registers all output files onto it for the {@link emissionsDriverPlugin} to initiate the next step (`onEmit` stage).
96
+ */
97
+ createMetafile(result, config) {
98
+ const metafile = new Metafile(result.metafile, {
99
+ resolvePath: config.resolvePath,
100
+ resolvedResourceRegistry: this.resolvedResourceRegistry,
101
+ });
102
+ for (const esbuild_file of result.outputFiles) {
103
+ metafile.addFile(esbuild_file);
104
+ }
105
+ // in order for all imports to get discovered and linked to each other's output file objects,
106
+ // we must run the method below after all output files have been added.
107
+ metafile.scanEsbuildImports();
108
+ return metafile;
109
+ }
110
+ /** concludes the build after the all registered {@link onEmitHandlers} and {@link onEndHandlers}
111
+ * have been executed by the {@link emissionsDriverPlugin} when it enters its `onEnd` stage (registered to the "true" `build` object).
112
+ *
113
+ * you must pass the mutated {@link Metafile} that you receive from calling the {@link createMetafile}
114
+ * method at the beginning of the {@link emissionsDriverPlugin}'s `onEnd` stage,
115
+ * so that if there's anything that should get written onto your filesystem, it will take place before the build concludes.
116
+ */
117
+ async endBuild(metafile) {
118
+ // if the user had originally set the `EsbuildBuildOption.write` to `true | undefined`,
119
+ // then we shall emit the files onto the filesystem, now that the build has concluded.
120
+ if (this.shouldWrite) {
121
+ await metafile.writeFiles(this.shouldOverwrite);
122
+ }
123
+ }
124
+ }
@@ -0,0 +1,12 @@
1
+ /** super-build lets you overload esbuild to expand what you're capable of doing in the plugin-api.
2
+ *
3
+ * @module
4
+ */
5
+ export type * from "./build.js";
6
+ export { SuperBuild } from "./build.js";
7
+ export { SuperBuildContext } from "./build_context.js";
8
+ export { SuperPlugin, type SuperPluginSetup } from "./plugin.js";
9
+ export { SuperPluginBuild } from "./plugin_build.js";
10
+ export type * from "./typedefs.js";
11
+ export { INNER_PLUGIN_BUILD } from "./typedefs.js";
12
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/super/mod.ts"],"names":[],"mappings":"AAAA;;;EAGE;AAEF,mBAAmB,YAAY,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AACtD,OAAO,EAAE,WAAW,EAAE,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAChE,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AACpD,mBAAmB,eAAe,CAAA;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA"}
@@ -0,0 +1,9 @@
1
+ /** super-build lets you overload esbuild to expand what you're capable of doing in the plugin-api.
2
+ *
3
+ * @module
4
+ */
5
+ export { SuperBuild } from "./build.js";
6
+ export { SuperBuildContext } from "./build_context.js";
7
+ export { SuperPlugin } from "./plugin.js";
8
+ export { SuperPluginBuild } from "./plugin_build.js";
9
+ export { INNER_PLUGIN_BUILD } from "./typedefs.js";
@@ -0,0 +1,23 @@
1
+ /** the {@link SuperPlugin} class wraps over your regular esbuild plugins to swap the `build: esbuild.PluginBuild` object that esbuild passes,
2
+ * with a {@link SuperPluginBuild}, super-build lets you overload esbuild to expand what you're capable of doing in the plugin-api.
3
+ *
4
+ * @module
5
+ */
6
+ import type { MaybePromise } from "../deps.js";
7
+ import type { EsbuildPlugin, EsbuildPluginBuild } from "../esbuild/strongtypes.js";
8
+ import type { SuperBuildContext } from "./build_context.js";
9
+ import { SuperPluginBuild } from "./plugin_build.js";
10
+ /** convenient type for annotating your plugin setup functions that use super-build's extended plugin api. */
11
+ export type SuperPluginSetup = (build: SuperPluginBuild) => MaybePromise<void>;
12
+ /** this class wraps over a base `esbuild.Plugin` to swap out the `build: esbuild.PluginBuild` that gets passed to its `setup` function with a {@link SuperPluginBuild},
13
+ * so that the plugin get access to all the exclusive features.
14
+ *
15
+ * expand your horizons by enrolling into jujutsu-highschool this summer and learning a new domain expansion technique; only for $15,000!
16
+ */
17
+ export declare class SuperPlugin implements EsbuildPlugin {
18
+ #private;
19
+ name: string;
20
+ setup: (build: EsbuildPluginBuild | SuperPluginBuild) => MaybePromise<void>;
21
+ constructor(ctx: SuperBuildContext, base_plugin: EsbuildPlugin);
22
+ }
23
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/super/plugin.ts"],"names":[],"mappings":"AAAA;;;;EAIE;AAEF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAClF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAA;AAGpD,6GAA6G;AAC7G,MAAM,MAAM,gBAAgB,GAAG,CAAC,KAAK,EAAE,gBAAgB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAA;AAE9E;;;;EAIE;AACF,qBAAa,WAAY,YAAW,aAAa;;IAOzC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,CAAC,KAAK,EAAE,kBAAkB,GAAG,gBAAgB,KAAK,YAAY,CAAC,IAAI,CAAC,CAAA;gBAEtE,GAAG,EAAE,iBAAiB,EAAE,WAAW,EAAE,aAAa;CAW9D"}
@@ -0,0 +1,31 @@
1
+ /** the {@link SuperPlugin} class wraps over your regular esbuild plugins to swap the `build: esbuild.PluginBuild` object that esbuild passes,
2
+ * with a {@link SuperPluginBuild}, super-build lets you overload esbuild to expand what you're capable of doing in the plugin-api.
3
+ *
4
+ * @module
5
+ */
6
+ import { SuperPluginBuild } from "./plugin_build.js";
7
+ /** this class wraps over a base `esbuild.Plugin` to swap out the `build: esbuild.PluginBuild` that gets passed to its `setup` function with a {@link SuperPluginBuild},
8
+ * so that the plugin get access to all the exclusive features.
9
+ *
10
+ * expand your horizons by enrolling into jujutsu-highschool this summer and learning a new domain expansion technique; only for $15,000!
11
+ */
12
+ export class SuperPlugin {
13
+ // unfortunately, esbuild disallows any enumerable custom property to be set on the plugin `Object`.
14
+ // hence, we declare all custom properties as private, so that esbuild does not discover them.
15
+ // in the future, I may consider turning it into non-enumerable properties rather than private ones, if class extensions are desired.
16
+ #basePlugin;
17
+ #ctx;
18
+ name;
19
+ setup;
20
+ constructor(ctx, base_plugin) {
21
+ this.#basePlugin = base_plugin;
22
+ this.#ctx = ctx;
23
+ this.name = base_plugin.name;
24
+ // esbuild strips away the setup function from its host object, effectively removing the `this` context.
25
+ // thus, we define the setup function as a closure rather than a method.
26
+ const self = this;
27
+ this.setup = (build) => {
28
+ return self.#basePlugin.setup(new SuperPluginBuild(self.#ctx, build, self.name));
29
+ };
30
+ }
31
+ }
@@ -0,0 +1,38 @@
1
+ /** the {@link SuperPluginBuild} class extends `esbuild.PluginBuild` to introduce additional functionality to esbuild's plugin api.
2
+ *
3
+ * TODO: I think I should begin adding new utility features to the superbuild plugin build, such as "resolvePath" and "resolveOutdirPath", etc...
4
+ *
5
+ * @module
6
+ */
7
+ import type { EsbuildBuildOptions, EsbuildOnEndCallback, EsbuildOnStartCallback, EsbuildPluginBuild, EsbuildResolveOptions, EsbuildResolveResult, OnResolveCallback, OnResolveOptions } from "../esbuild/strongtypes.js";
8
+ import { SuperBuild } from "./build.js";
9
+ import type { SuperBuildContext } from "./build_context.js";
10
+ import type { OnEmitCallback, OnEmitOptions, OnLoadCallback, OnLoadOptions, OnTransformCallback, OnTransformOptions } from "./typedefs.js";
11
+ import { INNER_PLUGIN_BUILD } from "./typedefs.js";
12
+ /** this is the extension of `esbuild.PluginBuild` that introduces additional functionality to esbuild's plugin api. */
13
+ export declare class SuperPluginBuild implements EsbuildPluginBuild {
14
+ protected ctx: SuperBuildContext;
15
+ protected basePluginBuild: EsbuildPluginBuild;
16
+ protected readonly pluginName: string;
17
+ initialOptions: EsbuildBuildOptions;
18
+ readonly esbuild: SuperBuild;
19
+ /** a reference to the original {@link EsbuildPluginBuild} that was used to construct this class.
20
+ *
21
+ * its presence can be used to check whether or not your plugin is running inside a super-build.
22
+ * gaining access to esbuild's original `PluginBuild` can be useful in certain situations where bypassing super-build is necessary,
23
+ * such as in the case of the {@link nativeReplicaPlugin}, and the underlying {@link EsbuildNativeResolver} that it uses.
24
+ */
25
+ readonly [INNER_PLUGIN_BUILD]: EsbuildPluginBuild;
26
+ constructor(ctx: SuperBuildContext, base_plugin_build: EsbuildPluginBuild, plugin_name: string);
27
+ resolve(path: string, options?: EsbuildResolveOptions): Promise<EsbuildResolveResult>;
28
+ onStart(callback: EsbuildOnStartCallback): void;
29
+ onEnd(callback: EsbuildOnEndCallback): void;
30
+ onResolve(options: OnResolveOptions, callback: OnResolveCallback): void;
31
+ onLoad(options: OnLoadOptions, callback: OnLoadCallback): void;
32
+ onDispose(callback: () => void): void;
33
+ /** TODO: add documentation and usage examples. */
34
+ onTransform(options: OnTransformOptions, callback: OnTransformCallback): void;
35
+ /** TODO: add documentation and usage examples. */
36
+ onEmit(options: OnEmitOptions, callback: OnEmitCallback): void;
37
+ }
38
+ //# sourceMappingURL=plugin_build.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin_build.d.ts","sourceRoot":"","sources":["../../src/super/plugin_build.ts"],"names":[],"mappings":"AAAA;;;;;EAKE;AAGF,OAAO,KAAK,EACX,mBAAmB,EAEnB,oBAAoB,EAGpB,sBAAsB,EACtB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EAEpB,iBAAiB,EACjB,gBAAgB,EAChB,MAAM,2BAA2B,CAAA;AAIlC,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAA;AAC3D,OAAO,KAAK,EAEX,cAAc,EACd,aAAa,EAEb,cAAc,EACd,aAAa,EACb,mBAAmB,EACnB,kBAAkB,EAClB,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAmClD,uHAAuH;AACvH,qBAAa,gBAAiB,YAAW,kBAAkB;IAC1D,SAAS,CAAC,GAAG,EAAE,iBAAiB,CAAA;IAChC,SAAS,CAAC,eAAe,EAAE,kBAAkB,CAAA;IAC7C,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;IAC9B,cAAc,EAAE,mBAAmB,CAAA;IAC1C,SAAgB,OAAO,EAAE,UAAU,CAAA;IAEnC;;;;;MAKE;IACF,SAAgB,CAAC,kBAAkB,CAAC,EAAE,kBAAkB,CAAA;g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