@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
package/package.json ADDED
@@ -0,0 +1,88 @@
1
+ {
2
+ "name": "@oazmi/superbuild",
3
+ "version": "0.1.0",
4
+ "description": "A wrapper on top of esbuild to provide you with extended esbuild plugin-api capabilities (hence a super set of esbuild).",
5
+ "keywords": [
6
+ "superbuild",
7
+ "super-build",
8
+ "esbuild",
9
+ "esbuild-plugin",
10
+ "build-tools",
11
+ "bundler",
12
+ "plugin",
13
+ "minifier",
14
+ "transform",
15
+ "emit"
16
+ ],
17
+ "author": "Omar Azmi",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/oazmi/superbuild.git"
21
+ },
22
+ "license": "Apache-2.0",
23
+ "bugs": {
24
+ "url": "https://github.com/oazmi/superbuild/issues"
25
+ },
26
+ "module": "./esm/mod.js",
27
+ "exports": {
28
+ ".": {
29
+ "import": "./esm/mod.js"
30
+ },
31
+ "./super": {
32
+ "import": "./esm/super/mod.js"
33
+ },
34
+ "./esbuild/native": {
35
+ "import": "./esm/esbuild/native.js"
36
+ },
37
+ "./esbuild/metafile": {
38
+ "import": "./esm/esbuild/metafile.js"
39
+ },
40
+ "./esbuild/outputfile": {
41
+ "import": "./esm/esbuild/outputfile.js"
42
+ },
43
+ "./esbuild/strongtypes": {
44
+ "import": "./esm/esbuild/strongtypes.js"
45
+ },
46
+ "./esbuild/weaktypes": {
47
+ "import": "./esm/esbuild/weaktypes.js"
48
+ },
49
+ "./esbuild/typedefs": {
50
+ "import": "./esm/esbuild/typedefs.js"
51
+ },
52
+ "./plugins/long_build": {
53
+ "import": "./esm/plugins/long_build.js"
54
+ },
55
+ "./plugins/native_replica": {
56
+ "import": "./esm/plugins/native_replica.js"
57
+ },
58
+ "./plugins/emissions_driver": {
59
+ "import": "./esm/plugins/emissions_driver.js"
60
+ },
61
+ "./funcdefs": {
62
+ "import": "./esm/funcdefs.js"
63
+ },
64
+ "./typedefs": {
65
+ "import": "./esm/typedefs.js"
66
+ }
67
+ },
68
+ "scripts": {
69
+ "build-dist": "npm run build-esm && npm run build-esm-minify && npm run build-iife && npm run build-iife-minify",
70
+ "build-esm": "npx esbuild \"./src/mod.ts\" --bundle --format=esm --external:node:fs/promises --external:node:child_process --outfile=\"./dist/@oazmi/superbuild.esm.js\"",
71
+ "build-esm-minify": "npx esbuild \"./src/mod.ts\" --bundle --minify --format=esm --external:node:fs/promises --external:node:child_process --outfile=\"./dist/@oazmi/superbuild.esm.min.js\"",
72
+ "build-iife": "npx esbuild \"./src/mod.ts\" --bundle --format=iife --external:node:fs/promises --external:node:child_process --outfile=\"./dist/@oazmi/superbuild.iife.js\"",
73
+ "build-iife-minify": "npx esbuild \"./src/mod.ts\" --bundle --minify --format=iife --external:node:fs/promises --external:node:child_process --outfile=\"./dist/@oazmi/superbuild.iife.min.js\""
74
+ },
75
+ "type": "module",
76
+ "sideEffects": false,
77
+ "dependencies": {
78
+ "@oazmi/kitchensink": "0.10.0",
79
+ "@oazmi/esbuild-types": "0.28.0"
80
+ },
81
+ "devDependencies": {
82
+ "@types/node": "^20.9.0",
83
+ "typescript": "^5.6.0",
84
+ "esbuild": "^0.25.0",
85
+ "typedoc": "^0.28.1"
86
+ },
87
+ "_generatedBy": "dnt@dev"
88
+ }
package/readme.md ADDED
@@ -0,0 +1,181 @@
1
+ # @oazmi/superbuild
2
+
3
+ A wrapper on top of esbuild to provide you with extended esbuild Plugin-API capabilities (hence a super set of esbuild).
4
+
5
+ > [!note]
6
+ > This project is free of dependencies (only using my `jsr:@oazmi/kitchensink` for utility functionality),
7
+ > and bundles down to just `45kb` with minification. so, fear not of carrying extra baggage by using this library.
8
+
9
+ ## General Usage
10
+
11
+ ```ts
12
+ import esbuild from "npm:esbuild"
13
+ import { SuperBuild } from "jsr:@oazmi/superbuild" // or use "npm:@oazmi/superbuild".
14
+
15
+ const sbuild = new SuperBuild(esbuild)
16
+ const result = await sbuild.build({
17
+ entryPoints: ["./mod.ts"],
18
+ // ... other build options.
19
+ plugins: [{
20
+ name: "my-plugin",
21
+ setup: my_plugin_setup, // see the examples that follow.
22
+ }],
23
+ })
24
+ ```
25
+
26
+ ## Extended API Features
27
+
28
+ ### _onLoad_
29
+
30
+ The super-build wrapper lets you use any arbitrary string for the returned `loader` field,
31
+ and then have that loaded resource get captured by the [`onTransform`](#ontransform) stage's filter.
32
+
33
+ example:
34
+
35
+ ```ts
36
+ import type { OnLoadArgs, SuperPluginBuild, SuperPluginSetup } from "jsr:@oazmi/superbuild"
37
+
38
+ const my_plugin_setup: SuperPluginSetup = (build: SuperPluginBuild) => {
39
+ // ...
40
+ build.onLoad({ filter: /\.html$/ }, async (args: OnLoadArgs) => {
41
+ const contents = await (await fetch("...")).text()
42
+ return {
43
+ contents: contents,
44
+ loader: "html", // you may use any arbitrary string for the loader.
45
+ }
46
+ })
47
+ // ...
48
+ }
49
+ ```
50
+
51
+ ### _onTransform_
52
+
53
+ The newly added `build.onTransform` function lets you capture [_loaded_](#onload) content,
54
+ transform them in any arbitrary way, and then specify additional arbitrary imports that need to be bundled.
55
+
56
+ example:
57
+
58
+ ```ts
59
+ import type { ImportEntity, OnTransformArgs, SuperPluginBuild, SuperPluginSetup } from "@oazmi/superbuild"
60
+
61
+ const my_plugin_setup: SuperPluginSetup = (build: SuperPluginBuild) => {
62
+ // ...
63
+ build.onTransform({ filter: /.*/, loader: "html" }, async (args: OnTransformArgs) => {
64
+ const contents = typeof args.contents === "string" ? args.contents : new TextDecoder().decode(args.contents)
65
+ const html_doc = new DOMParser().parseFromString(contents, "text/html"),
66
+ js_imports: ImportEntity[] = scanJsImports(html_doc), // just a hypothetical function.
67
+ css_imports: ImportEntity[] = scanCssImports(html_doc), // just a hypothetical function.
68
+ my_additional_import: ImportEntity = {
69
+ key: "external-ref-0",
70
+ path: "http://example.com/favicon.ico",
71
+ external: true,
72
+ }
73
+ return {
74
+ contents: contents,
75
+ // below, you must specify an esbuild-compatible loader.
76
+ // for an html file , `copy` makes the most sense.
77
+ loader: "copy",
78
+ // all non-external files specified in the imports will also get bundled.
79
+ imports: [...js_imports, ...css_imports, my_additional_import],
80
+ // you may also attach arbitrary data that'll get re-captured during the onEmit stage.
81
+ emitData: { timeStamp: Date.now(), copywrites: ["Seto frikking Kaiba"] },
82
+ }
83
+ })
84
+ // ...
85
+ }
86
+ ```
87
+
88
+ ### _onEmit_
89
+
90
+ Finally, the new `build.onEmit` function lets you capture output file contents _after_ they have been bundled,
91
+ transform them in any arbitrary manner (such as re-incorporating user-made imports from the [transform stage](#ontransform)),
92
+ and finally renaming them (in topological dependency order).
93
+
94
+ example:
95
+
96
+ ```ts
97
+ import type { ImportedEntity, OnEmitArgs, SuperPluginBuild, SuperPluginSetup } from "@oazmi/superbuild"
98
+
99
+ const my_plugin_setup: SuperPluginSetup = (build: SuperPluginBuild) => {
100
+ // ...
101
+ build.onEmit({
102
+ filter: /.*/,
103
+ inputs: [{
104
+ // filter based on the resolved path of the resource that is bundled into the output file.
105
+ filter: /.*/,
106
+ namespace: undefined, // capture all namespaces.
107
+ loader: "html", // loader based filter.
108
+ transformLoader: "copy", // on-transform's loader based filter.
109
+ }],
110
+ }, async (args: OnEmitArgs) => {
111
+ const contents = typeof args.contents === "string" ? args.contents : new TextDecoder().decode(args.contents)
112
+ const html_doc = new DOMParser().parseFromString(contents, "text/html")
113
+ // just a hypothetical way of re-incorporating the bundled imports.
114
+ args.imports.forEach((imported_entity: ImportedEntity) => {
115
+ const { key, outputPath, write, external, kind } = imported_entity
116
+ if (external || !write) return
117
+ console.assert(kind === "user-import")
118
+ html_doc.querySelectorAll(`#${key}`).forEach((dom_element) => {
119
+ dom_element.setAttribute("src", outputPath)
120
+ })
121
+ })
122
+ const new_output_path = args.outputPath.replace(/\.html$/, ".xhtml")
123
+ return {
124
+ contents: html_doc.documentElement.outerHTML,
125
+ path: new_output_path,
126
+ write: true,
127
+ }
128
+ })
129
+ // ...
130
+ }
131
+ ```
132
+
133
+ ## Other Notable Features
134
+
135
+ - Dependency free, and under `45kb` when bundled with minification.
136
+ - Cross-runtime compatible (deno, node, bun, and the web (only when `write` is `false`)).
137
+ - You can rename output files during the emission stage, and the updated paths will be reflected in the dependent output files' `args.imports`.
138
+ This is because the emitted output files are always updated in their natural topological dependency order (in parallel).
139
+
140
+ ## Documentation and Links
141
+
142
+ - Documentation page: [https://oazmi.github.io/superbuild](https://oazmi.github.io/superbuild).
143
+ - JSR release page: [https://jsr.io/@oazmi/superbuild](https://jsr.io/@oazmi/superbuild).
144
+ - NPM release page: [https://www.npmjs.com/package/@oazmi/superbuild](https://www.npmjs.com/package/@oazmi/superbuild).
145
+ - Github repository: [https://github.com/oazmi/superbuild](https://github.com/oazmi/superbuild).
146
+
147
+ ## Prior Art
148
+
149
+ I was using [`esbuild-extra`](https://github.com/aleclarson/esbuild-extra) for a while for static-site generation, and I found it it be incredibly useful.
150
+ However, I needed additional freedom in manipulating resources, dynamically adding resources for bundling,
151
+ while supporting code-splitting and resource-sharing in the additional bundled resources (i.e. where sub-builds do not qualify).
152
+ So, I wrote this library, heavily inspired by the said library's vision.
153
+
154
+ However, do note that the `esbuild-extra`'s `onTransform` is fundamentally different from this library's `onTransform` hook.
155
+ In essence, the `onEmit` hook of this library resembles closer to `esbuild-extra`'s `onTransform`,
156
+ because it takes place _after_ esbuild has successfully bundled the resources.
157
+ Whereas the `onTransform` hook of _this_ library lets you manipulate the _loaded_ resources _before_ they get passed over to esbuild for bundling.
158
+
159
+ Another cool set of libraries that also manipulate esbuild's transformation and emission mechanism is [`@chialab/esbuild-rna`](https://github.com/chialab/rna).
160
+ Though, I could never get it to run with deno (during its early node-compatibility days), so I never gave it a try.
161
+
162
+ ## Notes
163
+
164
+ ### a few things that still need to be taken care of:
165
+
166
+ - I still need to figure out how to make `sourcemap`s possible for user-specified imports.
167
+ - Also, `<stdin>` isn't captured by my plugin right now, since esbuild process it directly (skipping the plugin API layer).
168
+
169
+ ### esbuild `Metafile`
170
+
171
+ - `pathname in keyof Metafile.inputs` corresponds to the template `${namespace}:${resolve_path_string}`,
172
+ unless the `namespace` is `file`, in which case it simply becomes `${resolve_path_string}`.
173
+ - esbuild's own path resolution format reads like: `"node_modules/@oazmi/kitchensink/esm/alias.js"`.
174
+ in other words, it strips away the leading `"./"`, to indicate that it is in the current working directory (or `absWorkingDir`).
175
+ - `Metafile.inputs[string].imports[number].path` dictates the `${namespace}:${resolve_path_string}` name of the imported resource.
176
+ - `pathname in keyof Metafile.outputs` corresponds to the template `${outdir}/${filepath}`, without any leading `"./"`.
177
+ - `pathname in keyof Metafile.outputs[string].inputs` corresponds to the `pathname in keyof Metafile.inputs`,
178
+ using the same `${namespace}:${resolve_path_string}` template.
179
+ - a new `entryPoint` is created for each dynamic importm using the same `${namespace}:${resolve_path_string}` template,
180
+ however, not all `Metafile.outputs[string]` have an `entryPoint` property, especially if they were an intermediate stplitted dependency.
181
+ - `Metafile.outputs[string].inputs` can be an empty record in case the file is a split-up chunk that only re-exports other imports.