@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,221 @@
|
|
|
1
|
+
/** a utility submodule that works alongside {@link Metafile} to aid in holding onto a given file's contents, path, inputs, and imports,
|
|
2
|
+
* in addition to providing useful file-related methods, such as {@link OnEmitOptions} filter matching, and etc...
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { array_isEmpty, isNull, isString, relativePath, textEncoder } from "../deps.js";
|
|
7
|
+
export class OutputFileEntity {
|
|
8
|
+
/** the **absolute** output path of this resource entity. */
|
|
9
|
+
outputPath;
|
|
10
|
+
/** if this resource entity was renamed during the {@link SuperPluginBuild.onEmit, emission stage},
|
|
11
|
+
* then its original (absolute) {@link outputPath} will get saved here.
|
|
12
|
+
*/
|
|
13
|
+
initialPath;
|
|
14
|
+
hash;
|
|
15
|
+
contents;
|
|
16
|
+
/** specify if this file entry should be written.
|
|
17
|
+
*
|
|
18
|
+
* @defaultValue `true` (i.e. it'll be written if `EsbuildBuildOption.write` is enabled, otherwise it won't be.)
|
|
19
|
+
*/
|
|
20
|
+
write = true;
|
|
21
|
+
/** an array of metadata on the loaded input files that were bundled into _this_ physical output file entity. */
|
|
22
|
+
inputs = [];
|
|
23
|
+
/** an array of metadata on the output files that are imported by _this_ file entity during runtime.
|
|
24
|
+
*
|
|
25
|
+
* each of these is basically associated with a js (`import { x, y, z } from "abc"`), css (`@import url("./blahblah.css")`),
|
|
26
|
+
* or user-import (i.e. {@link OnTransformResult.imports}) statement.
|
|
27
|
+
*/
|
|
28
|
+
imports = [];
|
|
29
|
+
metafile;
|
|
30
|
+
constructor(metafile, esbuild_file) {
|
|
31
|
+
this.metafile = metafile;
|
|
32
|
+
const output_path = metafile.resolvePath(esbuild_file.path), output_path_lowercase = output_path.toLowerCase(), metadata = metafile.outputs.get(output_path_lowercase);
|
|
33
|
+
if (!metadata) {
|
|
34
|
+
throw Error(`[OutputFileEntity.constructor]: no matching metadata for the file with the path "${output_path_lowercase}" could be found.`);
|
|
35
|
+
}
|
|
36
|
+
this.outputPath = output_path;
|
|
37
|
+
this.initialPath = undefined;
|
|
38
|
+
this.hash = esbuild_file.hash;
|
|
39
|
+
this.contents = esbuild_file.contents;
|
|
40
|
+
this.scanEsbuildInputs();
|
|
41
|
+
}
|
|
42
|
+
/** scans esbuild's metafile outputs to find the input sources bundled into this output file.
|
|
43
|
+
* the input sources are presented with resolved path information, namespace, `onEmit` information,
|
|
44
|
+
* and other additional information acquired from the resource's resolver, loader, and transformer results.
|
|
45
|
+
* (the collection of this information is stored in {@link metafile.resolvedResourceRegistry},
|
|
46
|
+
* which is inherited from the {@link SuperBuildContext}.)
|
|
47
|
+
*/
|
|
48
|
+
scanEsbuildInputs() {
|
|
49
|
+
const bundled_files = this.inputs;
|
|
50
|
+
if (!array_isEmpty(bundled_files)) {
|
|
51
|
+
return bundled_files;
|
|
52
|
+
} // if `inputs` were already added, then there's no scanning left to do.
|
|
53
|
+
const metafile = this.metafile, warnings = metafile.warnings, resolvedResourceRegistry = metafile.resolvedResourceRegistry, output_path_key = (this.initialPath ?? this.outputPath).toLowerCase(), metadata = metafile.outputs.get(output_path_key);
|
|
54
|
+
if (!metadata) {
|
|
55
|
+
throw Error(`[OutputFileEntity.scanEsbuildInputs]: no matching metadata for the file with the path "${output_path_key}" could be found.`);
|
|
56
|
+
}
|
|
57
|
+
// acquire the list of all bundled files which were included in the current output resource, that can be traced back from the resource registry.
|
|
58
|
+
for (const input_source_resolved_path of metadata.inputs) {
|
|
59
|
+
const bundled_file = resolvedResourceRegistry.get(input_source_resolved_path);
|
|
60
|
+
if (bundled_file) {
|
|
61
|
+
bundled_files.push(bundled_file);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
warnings.push({ text: `[OutputFileEntity.scanEsbuildInputs]: resource registry never encountered the resource: "${input_source_resolved_path}".` });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return bundled_files;
|
|
68
|
+
}
|
|
69
|
+
/** scans esbuild's metafile outputs to find all file imports performed by this output file.
|
|
70
|
+
* these only include entity imports found by esbuild natively (js imports, css imports, etc...), and not long-build plugin based imports.
|
|
71
|
+
*
|
|
72
|
+
* > [!important]
|
|
73
|
+
* > this function should be run _after_ all files have been added to your {@link metafile} via {@link metafile.addFile},
|
|
74
|
+
* > because the imports need to reference the {@link OutputFileEntity} associated with the imported file.
|
|
75
|
+
*/
|
|
76
|
+
scanEsbuildImports() {
|
|
77
|
+
const imported_entities = this.imports;
|
|
78
|
+
if (!array_isEmpty(imported_entities)) {
|
|
79
|
+
return imported_entities;
|
|
80
|
+
} // if `imports` were already added, then there's no scanning left to do.
|
|
81
|
+
const metafile = this.metafile, warnings = metafile.warnings, outputs = metafile.outputs, output_path_key = (this.initialPath ?? this.outputPath).toLowerCase(), metadata = outputs.get(output_path_key);
|
|
82
|
+
if (!metadata) {
|
|
83
|
+
throw Error(`[OutputFileEntity.scanEsbuildImports]: no matching metadata for the file with the path "${output_path_key}" could be found.`);
|
|
84
|
+
}
|
|
85
|
+
for (const import_props of metadata.imports) {
|
|
86
|
+
// here, we find the original namespaced resolved path of the file that resulted in the `import_output_path` file.
|
|
87
|
+
// since there could be multiple `inputs` that resulted in the creation of the file at `import_output_path`,
|
|
88
|
+
// we set the `key` to be an array of all `inputs`.
|
|
89
|
+
const { path: import_output_path, kind, external } = import_props;
|
|
90
|
+
// firstly though, esbuild based external imports have no output file associated with them, so they must not under go this process.
|
|
91
|
+
// for their keys, we simply set it to the their reference path/link.
|
|
92
|
+
if (external) {
|
|
93
|
+
const external_entity = { externalPath: import_output_path };
|
|
94
|
+
imported_entities.push({ key: [import_output_path], kind, external, entity: external_entity });
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const import_output_path_key = import_output_path.toLowerCase(), entity = metafile.outputFileEntities.get(import_output_path_key);
|
|
98
|
+
if (!entity) {
|
|
99
|
+
throw Error(`[OutputFileEntity.scanEsbuildImports]: no matching output file entity for the path "${import_output_path_key}" could be found.`);
|
|
100
|
+
}
|
|
101
|
+
const import_sources = entity.inputs.map((props) => { return (props.namespace + ":" + props.path).toLowerCase(); });
|
|
102
|
+
if (array_isEmpty(import_sources)) {
|
|
103
|
+
// TODO: under this scenario, I can technically still construct a `key` if I were to inspect the `imports` of the `outputPath`,
|
|
104
|
+
// and then trace which of _its_ inputs correspond to this `import_output_path`,
|
|
105
|
+
// but that's just too convoluted and it'll still require a bunch of guessing, at which point it will not be worth the effort.
|
|
106
|
+
warnings.push({
|
|
107
|
+
text: `[OutputFileEntity.scanEsbuildImports]: expected import file to be made out of at least one input resource. `
|
|
108
|
+
+ `but worry not, as this could happen when the emitted file is just a re-exporting chunk file.`,
|
|
109
|
+
location: { file: import_output_path },
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
imported_entities.push({ key: import_sources, kind, external, entity });
|
|
113
|
+
}
|
|
114
|
+
return imported_entities;
|
|
115
|
+
}
|
|
116
|
+
/** test if an `onEmit` handler's filters apply to _this_ output file entity. */
|
|
117
|
+
matchOnEmitFilter(options) {
|
|
118
|
+
const { filter, inputs: input_filters } = options, output_path = this.outputPath;
|
|
119
|
+
// test the output file name filter first.
|
|
120
|
+
// the reason why `this.initialPath` is not used is because it is impossible for a file entity to be renamed before it goes through the `onEmit` stage.
|
|
121
|
+
// hence, `this.initialPath` is guaranteed to be `undefined`.
|
|
122
|
+
if (!filter.test(output_path)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
// next we test if each input filter has been satisfied by at least one element in `this.inputs`
|
|
126
|
+
// (which is the list of all bundled source files which were included in the current file).
|
|
127
|
+
const bundled_files = this.inputs;
|
|
128
|
+
for (const input_filter of (input_filters ?? [])) {
|
|
129
|
+
const { filter, namespace, loader, transformLoader } = input_filter;
|
|
130
|
+
const at_least_one_file_satisfies_conditions = bundled_files.some((bundled_file) => {
|
|
131
|
+
return filter.test(bundled_file.path)
|
|
132
|
+
&& (namespace ? namespace === bundled_file.namespace : true)
|
|
133
|
+
&& (loader ? loader === bundled_file.loader : true)
|
|
134
|
+
&& (transformLoader ? transformLoader === bundled_file.transformLoader : true);
|
|
135
|
+
});
|
|
136
|
+
if (!at_least_one_file_satisfies_conditions) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
// if we've made it to here, then this entity has passed the filter test, and may proceed to the `onEmit` callback hook.
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
/** perform `onEmit` action on _this_ output file entity, based on the provided `onEmit` handlers. */
|
|
144
|
+
async performOnEmit(on_emit_handlers) {
|
|
145
|
+
const imported_entities = this.imports.map((imported_entity_node) => {
|
|
146
|
+
const { key, kind, external, entity, with: with_attr } = imported_entity_node, is_external_entity = "externalPath" in entity, outputPath = is_external_entity ? entity.externalPath : entity.outputPath, initialPath = is_external_entity ? undefined : entity.initialPath, write = is_external_entity ? false : entity.write;
|
|
147
|
+
return { key, outputPath, initialPath, kind, external, with: with_attr, write };
|
|
148
|
+
});
|
|
149
|
+
// attempt at matching the output file with all available `onEmit` hooks' filters,
|
|
150
|
+
// and stopping at the first match that yields a viable result.
|
|
151
|
+
for (const handler of on_emit_handlers) {
|
|
152
|
+
if (!this.matchOnEmitFilter(handler)) {
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const on_emit_result = await handler.callback({
|
|
156
|
+
outputPath: this.outputPath,
|
|
157
|
+
contents: this.contents,
|
|
158
|
+
inputs: this.inputs,
|
|
159
|
+
imports: imported_entities,
|
|
160
|
+
});
|
|
161
|
+
if (isNull(on_emit_result)) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
// updating the emitted file `path` and `contents` from the `result`.
|
|
165
|
+
if (on_emit_result.contents) {
|
|
166
|
+
this.contents = isString(on_emit_result.contents)
|
|
167
|
+
? textEncoder.encode(on_emit_result.contents)
|
|
168
|
+
: on_emit_result.contents;
|
|
169
|
+
}
|
|
170
|
+
if (on_emit_result.path) {
|
|
171
|
+
this.rename(on_emit_result.path);
|
|
172
|
+
}
|
|
173
|
+
if (!isNull(on_emit_result.write)) {
|
|
174
|
+
this.write = on_emit_result.write;
|
|
175
|
+
}
|
|
176
|
+
// TODO: what will happen to the files that depend on the deleted files?
|
|
177
|
+
// should I simply delete this resource from the dependency graph and call it a day?
|
|
178
|
+
// inserting the original plugin names of the plugins where the errors and warnings originated from.
|
|
179
|
+
const pluginName = handler.pluginName;
|
|
180
|
+
on_emit_result.warnings?.forEach((warning) => { if (!warning.pluginName) {
|
|
181
|
+
warning.pluginName = pluginName;
|
|
182
|
+
} });
|
|
183
|
+
on_emit_result.errors?.forEach((error) => { if (!error.pluginName) {
|
|
184
|
+
error.pluginName = pluginName;
|
|
185
|
+
} });
|
|
186
|
+
return on_emit_result;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/** rename this file. you can either provide an absolute path, or a relative path.
|
|
190
|
+
* relative paths will be resolved with respect to the `cwd` or esbuild's `absWorkingDir`.
|
|
191
|
+
*/
|
|
192
|
+
rename(new_output_path) {
|
|
193
|
+
// save the original output path into `initialPath` if it has never been assigned before.
|
|
194
|
+
this.initialPath ??= this.outputPath;
|
|
195
|
+
this.outputPath = this.metafile.resolvePath(new_output_path);
|
|
196
|
+
}
|
|
197
|
+
/** convert an output file entity to an esbuild-compatible {@link EsbuildOutputFile | output file description}.
|
|
198
|
+
*
|
|
199
|
+
* (honestly, I don't see myself using it, and if we're overloading esbuild anyway, why don't we overload the `OutputFile`
|
|
200
|
+
* interface to include new fields, such as `write` and `external`, etc...?)
|
|
201
|
+
*/
|
|
202
|
+
toEsbuildOutputFile(outdir = "./") {
|
|
203
|
+
if (!this.write) {
|
|
204
|
+
return undefined;
|
|
205
|
+
}
|
|
206
|
+
const metafile = this.metafile;
|
|
207
|
+
outdir = metafile.resolvePath(outdir);
|
|
208
|
+
const relative_path = relativePath(this.outputPath, outdir); // TODO: letter casing inconsistency can pose an issue here.
|
|
209
|
+
return {
|
|
210
|
+
path: relative_path,
|
|
211
|
+
hash: this.hash,
|
|
212
|
+
contents: this.contents,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
async writeFile(write_file_fn) {
|
|
216
|
+
if (!this.write) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
return write_file_fn(this.outputPath, this.contents);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/** this module contains esbuild type definitions of the latest esbuild version.
|
|
2
|
+
*
|
|
3
|
+
* this file is a partial copy from my `@oazmi/esbuild-plugin-deno` esbuild plugin's `typedefs` file.
|
|
4
|
+
* here's the original source: [github](https://github.com/oazmi/esbuild-plugin-deno/blob/b20109988a7245804b52e219ca0f2948fa4012ba/src/plugins/typedefs.ts).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { esbuild, MaybePromiseOrNull, MaybePromiseOrVoid } from "../deps.js";
|
|
9
|
+
import type { CommonPluginData } from "./typedefs.js";
|
|
10
|
+
/** an interface representing the `esbuild` namespace. */
|
|
11
|
+
export interface Esbuild {
|
|
12
|
+
/** this is only available at the top-level `esbuild` object, not in sub-builds residing inside of {@link EsbuildPluginBuild}. */
|
|
13
|
+
stop?: typeof esbuild.stop;
|
|
14
|
+
analyzeMetafile: typeof esbuild.analyzeMetafile;
|
|
15
|
+
analyzeMetafileSync: typeof esbuild.analyzeMetafileSync;
|
|
16
|
+
build: typeof esbuild.build;
|
|
17
|
+
buildSync: typeof esbuild.buildSync;
|
|
18
|
+
context: typeof esbuild.context;
|
|
19
|
+
formatMessages: typeof esbuild.formatMessages;
|
|
20
|
+
formatMessagesSync: typeof esbuild.formatMessagesSync;
|
|
21
|
+
initialize: typeof esbuild.initialize;
|
|
22
|
+
transform: typeof esbuild.transform;
|
|
23
|
+
transformSync: typeof esbuild.transformSync;
|
|
24
|
+
version: typeof esbuild.version;
|
|
25
|
+
}
|
|
26
|
+
/** type alias for `esbuild.OnResolveOptions`. */
|
|
27
|
+
export type OnResolveOptions = esbuild.OnResolveOptions;
|
|
28
|
+
/** type alias for `esbuild.OnResolveArgs`, slightly tweaked for this library's internal use. */
|
|
29
|
+
export type OnResolveArgs = Omit<esbuild.OnResolveArgs, "pluginData"> & {
|
|
30
|
+
pluginData: undefined | CommonPluginData;
|
|
31
|
+
};
|
|
32
|
+
/** type alias for `esbuild.OnResolveResult`. */
|
|
33
|
+
export type OnResolveResult = esbuild.OnResolveResult;
|
|
34
|
+
/** type alias for the callback function provided to the `onResolve` function (aka `esbuild.PluginBuild["onResolve"]`). */
|
|
35
|
+
export type OnResolveCallback = (args: OnResolveArgs) => MaybePromiseOrNull<OnResolveResult>;
|
|
36
|
+
/** type alias for `esbuild.OnLoadOptions`. */
|
|
37
|
+
export type OnLoadOptions = esbuild.OnLoadOptions;
|
|
38
|
+
/** type alias for `esbuild.OnLoadArgs`, slightly tweaked for this library's internal use. */
|
|
39
|
+
export type OnLoadArgs = Omit<esbuild.OnLoadArgs, "pluginData"> & {
|
|
40
|
+
pluginData: undefined | CommonPluginData;
|
|
41
|
+
};
|
|
42
|
+
/** type alias for `esbuild.OnLoadResult`. */
|
|
43
|
+
export type OnLoadResult = esbuild.OnLoadResult;
|
|
44
|
+
/** type alias for the callback function provided to the `OnLoad` function (aka `esbuild.PluginBuild["OnLoad"]`). */
|
|
45
|
+
export type OnLoadCallback = (args: OnLoadArgs) => MaybePromiseOrNull<OnLoadResult>;
|
|
46
|
+
/** type alias for `esbuild.ResolveOptions`. */
|
|
47
|
+
export type EsbuildResolveOptions = esbuild.ResolveOptions;
|
|
48
|
+
/** type alias for `esbuild.ResolveResult`. */
|
|
49
|
+
export type EsbuildResolveResult = esbuild.ResolveResult;
|
|
50
|
+
/** type alias for `esbuild.OnStartResult`. */
|
|
51
|
+
export type EsbuildOnStartResult = esbuild.OnStartResult;
|
|
52
|
+
/** type alias for the callback function provided to the `OnStart` function (aka `esbuild.PluginBuild["OnStart"]`). */
|
|
53
|
+
export type EsbuildOnStartCallback = () => MaybePromiseOrVoid<EsbuildOnStartResult>;
|
|
54
|
+
/** type alias for `esbuild.OnEndResult`. */
|
|
55
|
+
export type EsbuildOnEndResult = esbuild.OnEndResult;
|
|
56
|
+
/** type alias for the callback function provided to the `OnEnd` function (aka `esbuild.PluginBuild["OnEnd"]`). */
|
|
57
|
+
export type EsbuildOnEndCallback<ProvidedOptions extends EsbuildBuildOptions = EsbuildBuildOptions> = (result: EsbuildBuildResult<ProvidedOptions>) => MaybePromiseOrVoid<EsbuildOnEndResult>;
|
|
58
|
+
/** type alias for `esbuild.BuildOptions`. */
|
|
59
|
+
export type EsbuildBuildOptions = esbuild.BuildOptions;
|
|
60
|
+
/** type alias for `esbuild.BuildResult`. */
|
|
61
|
+
export type EsbuildBuildResult<ProvidedOptions extends EsbuildBuildOptions = EsbuildBuildOptions> = esbuild.BuildResult<ProvidedOptions>;
|
|
62
|
+
/** type alias for `esbuild.build`. */
|
|
63
|
+
export type EsbuildBuild = typeof esbuild.build;
|
|
64
|
+
/** type alias for `esbuild.Plugin`. */
|
|
65
|
+
export type EsbuildPlugin = esbuild.Plugin;
|
|
66
|
+
/** type alias for `esbuild.Plugin["setup"]`. */
|
|
67
|
+
export type EsbuildPluginSetup = esbuild.Plugin["setup"];
|
|
68
|
+
/** type alias for `esbuild.PluginBuild`. */
|
|
69
|
+
export type EsbuildPluginBuild = esbuild.PluginBuild;
|
|
70
|
+
/** type alias for `esbuild.Loader`. */
|
|
71
|
+
export type EsbuildLoaderType = esbuild.Loader;
|
|
72
|
+
/** type alias for `esbuild.Loader | undefined`. */
|
|
73
|
+
export type EsbuildLoaderTypeOrEmpty = EsbuildLoaderType | undefined;
|
|
74
|
+
/** type alias for `esbuild.ImportKind`. */
|
|
75
|
+
export type EsbuildImportKind = esbuild.ImportKind;
|
|
76
|
+
/** type alias for `esbuild.ImportKind | "file-loader"`. */
|
|
77
|
+
export type EsbuildOutputsImportKind = EsbuildMetafileImportProps["kind"];
|
|
78
|
+
/** type alias for `esbuild.Metafile`. */
|
|
79
|
+
export type EsbuildMetafile = esbuild.Metafile;
|
|
80
|
+
/** type alias for `esbuild.Metafile.outputs[number].imports[number]`. */
|
|
81
|
+
export type EsbuildMetafileImportProps = Required<esbuild.Metafile["outputs"][number]["imports"][number]>;
|
|
82
|
+
/** type alias for `esbuild.Message`. */
|
|
83
|
+
export type EsbuildMessage = esbuild.Message;
|
|
84
|
+
/** type alias for `esbuild.PartialMessage`. */
|
|
85
|
+
export type EsbuildPartialMessage = esbuild.PartialMessage;
|
|
86
|
+
/** useful non-public utility type copied from esbuild's source code. */
|
|
87
|
+
export type SameShape<Out, In extends Out> = In & {
|
|
88
|
+
[Key in Exclude<keyof In, keyof Out>]: never;
|
|
89
|
+
};
|
|
90
|
+
//# sourceMappingURL=strongtypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"strongtypes.d.ts","sourceRoot":"","sources":["../../src/esbuild/strongtypes.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** this module contains esbuild type definitions of the latest esbuild version.
|
|
2
|
+
*
|
|
3
|
+
* this file is a partial copy from my `@oazmi/esbuild-plugin-deno` esbuild plugin's `typedefs` file.
|
|
4
|
+
* here's the original source: [github](https://github.com/oazmi/esbuild-plugin-deno/blob/b20109988a7245804b52e219ca0f2948fa4012ba/src/plugins/typedefs.ts).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/** additional type definitions and central enum/constants variable management.
|
|
2
|
+
*
|
|
3
|
+
* this file is a partial copy from my `@oazmi/esbuild-plugin-deno` esbuild plugin's `typedefs` file.
|
|
4
|
+
* here's the original source: [github](https://github.com/oazmi/esbuild-plugin-deno/blob/b20109988a7245804b52e219ca0f2948fa4012ba/src/plugins/typedefs.ts).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { AbsolutePath } from "../typedefs.js";
|
|
9
|
+
import type { EsbuildLoaderTypeOrEmpty } from "./strongtypes.js";
|
|
10
|
+
import type { EsbuildLoaderTypeCompatible } from "./weaktypes.js";
|
|
11
|
+
/** a central enum containing the list of esbuild namespaces used by the plugins in this library. */
|
|
12
|
+
export declare const enum PLUGIN_NAMESPACE {
|
|
13
|
+
LOADER_GENERIC = "oazmi-loader-generic"
|
|
14
|
+
}
|
|
15
|
+
/** a list of default namespaces that esbuild uses for native/entry-point resolution. */
|
|
16
|
+
export declare const defaultEsbuildNamespaces: (string | undefined)[];
|
|
17
|
+
/** a list of all esbuild content type loaders. */
|
|
18
|
+
export declare const allEsbuildLoaders: Array<EsbuildLoaderTypeCompatible>;
|
|
19
|
+
/** this is the common plugin data utilized by this esbuild-plugin. */
|
|
20
|
+
export type CommonPluginData = any;
|
|
21
|
+
/** these are the various formats of input and output specification accepted by esbuild for a single entity. */
|
|
22
|
+
export type EsbuildEntryPointType = string | {
|
|
23
|
+
in: string;
|
|
24
|
+
out: string;
|
|
25
|
+
} | [input: string, output: string];
|
|
26
|
+
/** these are the various formats of entry points accepted by esbuild. */
|
|
27
|
+
export type EsbuildEntryPointsType = ImportMap | Array<EsbuildEntryPointType>;
|
|
28
|
+
/** an import map is just a key-value dictionary, where the value is an absolute path to a package's resource,
|
|
29
|
+
* and the key associated with it is an alias used by your code to reference the resource's path.
|
|
30
|
+
*
|
|
31
|
+
* > [!note]
|
|
32
|
+
* > the all keys that are provided are normalized first, so that a key like "hello/earth/../world" would transform to "hello/world".
|
|
33
|
+
* > further reading on [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap).
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* suppose that you have the following import map:
|
|
37
|
+
*
|
|
38
|
+
* ```ts
|
|
39
|
+
* const myImportMap: ImportMap = {
|
|
40
|
+
* "@scope/lib/some-entry": "https://jsr.io/@oazmi/kitchensink/0.9.2/src/array2d.ts", // this should require the http plugin to resolve
|
|
41
|
+
* "type-definitions" : "jsr:@oazmi/kitchensink@0.9.2/typedefs", // this should require the jsr plugin to resolve
|
|
42
|
+
* "build-cli/" : "jsr:@oazmi/build-tools@0.2.4/cli/", // reference to a whole directory
|
|
43
|
+
* }
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* then, with this import map, you should hypothetically be able to reference these libraries in your code as the following when bundling:
|
|
47
|
+
*
|
|
48
|
+
* ```ts ignore
|
|
49
|
+
* import { transposeArray2D } from "@scope/lib/some-entry"
|
|
50
|
+
* import { Optional, MethodsOf } from "type-definitions"
|
|
51
|
+
* import type { CliArgs as DocsCliArgs } from "build-cli/docs.ts" // the prefix is part of the import map
|
|
52
|
+
* import type { CliArgs as DistCliArgs } from "build-cli/dist.ts" // the prefix is part of the import map
|
|
53
|
+
*
|
|
54
|
+
* // your code...
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* ### Rules for import maps
|
|
58
|
+
*
|
|
59
|
+
* here are some rules that your import map record should follow:
|
|
60
|
+
* (copied from [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap#module_specifier_map)):
|
|
61
|
+
* - none of the _keys_ may be empty.
|
|
62
|
+
* - all of the _values_ must be strings, defining either a valid absolute url or a valid relative url string that starts with `"/"`, `"./"`, or `"../"`.
|
|
63
|
+
* - if a _key_ ends with `"/"`, then the corresponding value must also end with `"/"`.
|
|
64
|
+
* a key with a trailing `"/"` can be used as a prefix for when mapping (or remapping) modules addresses.
|
|
65
|
+
* - the object properties' ordering is irrelevant; if multiple keys can match the module specifier, the most specific key is used.
|
|
66
|
+
* in other words, a specifier "olive/branch/" would match before "olive/".
|
|
67
|
+
* - any path that is being matched against an import-map _will_ be normalized before being matched.
|
|
68
|
+
* this means that the path `"./foo/../js/app.js"` will be normalized and transformed to `"./js/app.js"`,
|
|
69
|
+
* before a suitable match is looked up in the import-map.
|
|
70
|
+
* - your import-map's keys should be **always** be pre-normalized.
|
|
71
|
+
* this is because a non-normalized key, such as `"hello/earth/../to/./this/world.txt"`, will never match any possible input path,
|
|
72
|
+
* because the input path will always be normalized first, thereby becoming un-matchable with any un-normalized key.
|
|
73
|
+
* so, the correct thing to do would be to ensure that your import-map keys are normalize before hand.
|
|
74
|
+
* (in the example here, the normalized version of the key would be `"hello/to/this/world.txt"`)
|
|
75
|
+
*/
|
|
76
|
+
export type ImportMap = Record<string, string>;
|
|
77
|
+
/** the in-memory output file description generated by `esbuild`. weakly similar to `esbuild.OutputFile`. */
|
|
78
|
+
export interface EsbuildOutputFile {
|
|
79
|
+
/** the absolute output path of the file. */
|
|
80
|
+
path: AbsolutePath;
|
|
81
|
+
/** a "text" rendering of the {@link contents} property, which changes automatically with any modifications to the {@link contents}.
|
|
82
|
+
*
|
|
83
|
+
* I'm not certain how it works under the hood, but I assume that it relies on checking for a new assignment (in its `setter` function),
|
|
84
|
+
* and only then updates the {@link text} accordingly.
|
|
85
|
+
* if that is the case, then mutations to the {@link contents} buffer itself will not result in the {@link text} being updated.
|
|
86
|
+
* instead, we will have to assign a new array buffer to the {@link contents} property for the effect to take place.
|
|
87
|
+
*/
|
|
88
|
+
text?: string;
|
|
89
|
+
/** the contents of the file to be written as a byte buffer.
|
|
90
|
+
* this is the single source of truth. the {@link text} property is merely a reflection of this property.
|
|
91
|
+
*
|
|
92
|
+
* TODO: this should ideally be set to `Uint8Array<ArrayBuffer>` instead of just `Uint8Array`,
|
|
93
|
+
* however, the typing on `esbuild.OutputFile.contents` still uses `Uint8Array`, causing type incompatibility issues.
|
|
94
|
+
* once esbuild has the typing fixed, I should update the type definition here as well.
|
|
95
|
+
*/
|
|
96
|
+
contents?: Uint8Array;
|
|
97
|
+
/** the (unique?) hash generated for this output file by esbuild. */
|
|
98
|
+
hash?: string;
|
|
99
|
+
}
|
|
100
|
+
/** this dictates esbuild's default/native file-extension to loader mapping.
|
|
101
|
+
* it is roughly based on the following esbuild function:
|
|
102
|
+
* [`"/internal/bundler/bundler.go":DefaultExtensionToLoaderMap`](https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/internal/bundler/bundler.go#L2916)
|
|
103
|
+
*
|
|
104
|
+
* > [!note]
|
|
105
|
+
* > one important distinction to note down is the fact that the loader for the "no extension" case (`""` empty string) is `undefined`,
|
|
106
|
+
* > meaning that it will use esbuild's own default loader for it (which happens to be `"js"` for such cases).
|
|
107
|
+
* >
|
|
108
|
+
* > the reason why we don't directly assign a `"js"` loader to this case is because our super-build's transformer hooks may utilize the knowledge of whether a "default" was originally passed,
|
|
109
|
+
* > or if an actual "js" loader was intended to be used by the prior `onLoad` hook's callback.
|
|
110
|
+
*
|
|
111
|
+
* PERMANENT-TODO: periodically check if the definitions are up to date.
|
|
112
|
+
*
|
|
113
|
+
* TODO: also, in the future, define these extension loaders based on the version of esbuild that is being used,
|
|
114
|
+
* using my `semver` resolver library from kitchensink.
|
|
115
|
+
*
|
|
116
|
+
* TODO: `".cts"` and `".mts"` both internally use a `LoaderTSNoAmbiguousLessThan` loader, which is different from a `LoaderTS`.
|
|
117
|
+
* however, the former is not exposed as a loader in javascript, where as the latter is.
|
|
118
|
+
* for now, I'm setting both `".cts"` and `".mts"` to load via the `"ts"` loader, but I don't know if there will be any negative consequences of this later.
|
|
119
|
+
*/
|
|
120
|
+
export declare const defaultExtensionToLoaderMap: Record<string, EsbuildLoaderTypeOrEmpty>;
|
|
121
|
+
//# sourceMappingURL=typedefs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typedefs.d.ts","sourceRoot":"","sources":["../../src/esbuild/typedefs.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAA;AAChE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAA;AAGjE,oGAAoG;AACpG,0BAAkB,gBAAgB;IACjC,cAAc,yBAAyB;CACvC;AAED,wFAAwF;AACxF,eAAO,MAAM,wBAAwB,wBAA0B,CAAA;AAE/D,kDAAkD;AAClD,eAAO,MAAM,iBAAiB,EAAE,KAAK,CAAC,2BAA2B,CAIhE,CAAA;AAED,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAElC,+GAA+G;AAC/G,MAAM,MAAM,qBAAqB,GAC9B,MAAM,GACN;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GAC3B,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAElC,yEAAyE;AACzE,MAAM,MAAM,sBAAsB,GAAG,SAAS,GAAG,KAAK,CAAC,qBAAqB,CAAC,CAAA;AAE7E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+CE;AACF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AAE9C,4GAA4G;AAC5G,MAAM,WAAW,iBAAiB;IACjC,4CAA4C;IAC5C,IAAI,EAAE,YAAY,CAAA;IAElB;;;;;;MAME;IACF,IAAI,CAAC,EAAE,MAAM,CAAA;IAEb;;;;;;MAME;IACF,QAAQ,CAAC,EAAE,UAAU,CAAA;IAErB,oEAAoE;IACpE,IAAI,CAAC,EAAE,MAAM,CAAA;CACb;AAED;;;;;;;;;;;;;;;;;;;EAmBE;AACF,eAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,MAAM,EAAE,wBAAwB,CAchF,CAAA"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/** additional type definitions and central enum/constants variable management.
|
|
2
|
+
*
|
|
3
|
+
* this file is a partial copy from my `@oazmi/esbuild-plugin-deno` esbuild plugin's `typedefs` file.
|
|
4
|
+
* here's the original source: [github](https://github.com/oazmi/esbuild-plugin-deno/blob/b20109988a7245804b52e219ca0f2948fa4012ba/src/plugins/typedefs.ts).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
/** a central enum containing the list of esbuild namespaces used by the plugins in this library. */
|
|
9
|
+
export var PLUGIN_NAMESPACE;
|
|
10
|
+
(function (PLUGIN_NAMESPACE) {
|
|
11
|
+
PLUGIN_NAMESPACE["LOADER_GENERIC"] = "oazmi-loader-generic";
|
|
12
|
+
})(PLUGIN_NAMESPACE || (PLUGIN_NAMESPACE = {}));
|
|
13
|
+
/** a list of default namespaces that esbuild uses for native/entry-point resolution. */
|
|
14
|
+
export const defaultEsbuildNamespaces = [undefined, "", "file"];
|
|
15
|
+
/** a list of all esbuild content type loaders. */
|
|
16
|
+
export const allEsbuildLoaders = [
|
|
17
|
+
"base64", "binary", "copy", "css", "dataurl",
|
|
18
|
+
"default", "empty", "file", "js", "json",
|
|
19
|
+
"jsx", "local-css", "text", "ts", "tsx",
|
|
20
|
+
];
|
|
21
|
+
/** this dictates esbuild's default/native file-extension to loader mapping.
|
|
22
|
+
* it is roughly based on the following esbuild function:
|
|
23
|
+
* [`"/internal/bundler/bundler.go":DefaultExtensionToLoaderMap`](https://github.com/evanw/esbuild/blob/6ff1d8b0d8c134e867a397eef39702a223ebef9e/internal/bundler/bundler.go#L2916)
|
|
24
|
+
*
|
|
25
|
+
* > [!note]
|
|
26
|
+
* > one important distinction to note down is the fact that the loader for the "no extension" case (`""` empty string) is `undefined`,
|
|
27
|
+
* > meaning that it will use esbuild's own default loader for it (which happens to be `"js"` for such cases).
|
|
28
|
+
* >
|
|
29
|
+
* > the reason why we don't directly assign a `"js"` loader to this case is because our super-build's transformer hooks may utilize the knowledge of whether a "default" was originally passed,
|
|
30
|
+
* > or if an actual "js" loader was intended to be used by the prior `onLoad` hook's callback.
|
|
31
|
+
*
|
|
32
|
+
* PERMANENT-TODO: periodically check if the definitions are up to date.
|
|
33
|
+
*
|
|
34
|
+
* TODO: also, in the future, define these extension loaders based on the version of esbuild that is being used,
|
|
35
|
+
* using my `semver` resolver library from kitchensink.
|
|
36
|
+
*
|
|
37
|
+
* TODO: `".cts"` and `".mts"` both internally use a `LoaderTSNoAmbiguousLessThan` loader, which is different from a `LoaderTS`.
|
|
38
|
+
* however, the former is not exposed as a loader in javascript, where as the latter is.
|
|
39
|
+
* for now, I'm setting both `".cts"` and `".mts"` to load via the `"ts"` loader, but I don't know if there will be any negative consequences of this later.
|
|
40
|
+
*/
|
|
41
|
+
export const defaultExtensionToLoaderMap = {
|
|
42
|
+
"": undefined,
|
|
43
|
+
".js": "js",
|
|
44
|
+
".mjs": "js",
|
|
45
|
+
".cjs": "js",
|
|
46
|
+
".jsx": "jsx",
|
|
47
|
+
".ts": "ts",
|
|
48
|
+
".cts": "ts",
|
|
49
|
+
".mts": "js",
|
|
50
|
+
".tsx": "tsx",
|
|
51
|
+
".css": "css",
|
|
52
|
+
".module.css": "local-css",
|
|
53
|
+
".json": "json",
|
|
54
|
+
".txt": "text",
|
|
55
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/** this module contains esbuild type definitions that are compatible with multiple versions of esbuild.
|
|
2
|
+
*
|
|
3
|
+
* this file is a partial copy from my `@oazmi/esbuild-plugin-deno` esbuild plugin's `typedefs` file.
|
|
4
|
+
* here's the original source: [github](https://github.com/oazmi/esbuild-plugin-deno/blob/b20109988a7245804b52e219ca0f2948fa4012ba/src/plugins/typedefs.ts).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { AutoSuggestOrString, MaybePromise } from "../deps.js";
|
|
9
|
+
import type { EsbuildBuildOptions, EsbuildBuildResult, EsbuildLoaderType, EsbuildMessage, EsbuildPluginBuild, OnLoadResult, SameShape } from "./strongtypes.js";
|
|
10
|
+
/** weakly typed alias for `esbuild.Plugin`, so that it is compatible over all versions of esbuild. */
|
|
11
|
+
export type EsbuildPluginCompatible = {
|
|
12
|
+
name: string;
|
|
13
|
+
setup: EsbuildPluginSetupCompatible;
|
|
14
|
+
};
|
|
15
|
+
/** weakly typed alias for `esbuild.Plugin["setup"]`, so that it is compatible over all versions of esbuild. */
|
|
16
|
+
export type EsbuildPluginSetupCompatible = (build: EsbuildPluginBuildCompatible) => MaybePromise<void>;
|
|
17
|
+
/** weakly typed alias for `esbuild.PluginBuild`, so that it is compatible over all versions of esbuild. */
|
|
18
|
+
export type EsbuildPluginBuildCompatible = Omit<{
|
|
19
|
+
[K in keyof EsbuildPluginBuild]: any;
|
|
20
|
+
}, "onLoad"> & {
|
|
21
|
+
onLoad: (options: any, callback: (args: any) => MaybePromise<OnLoadResult | null | undefined>) => void;
|
|
22
|
+
};
|
|
23
|
+
/** weakly typed alias for `esbuild.BuildOptions`, so that it is compatible over all versions of esbuild. */
|
|
24
|
+
export type EsbuildBuildOptionsCompatible = Omit<EsbuildBuildOptions, "alias" | "incremental" | "watch" | "packages" | "entryPoints" | "plugins"> & {
|
|
25
|
+
alias?: any;
|
|
26
|
+
incremental?: any;
|
|
27
|
+
watch?: any;
|
|
28
|
+
packages?: any;
|
|
29
|
+
entryPoints?: any;
|
|
30
|
+
};
|
|
31
|
+
/** weakly typed alias for `esbuild.BuildResult`, so that it is compatible over all versions of esbuild. */
|
|
32
|
+
export type EsbuildBuildResultCompatible = EsbuildBuildResult<EsbuildBuildOptionsCompatible>;
|
|
33
|
+
/** weakly typed alias for `esbuild.build`, so that it is compatible over all versions of esbuild. */
|
|
34
|
+
export type EsbuildBuildCompatible = <T extends EsbuildBuildOptionsCompatible>(options: SameShape<EsbuildBuildOptionsCompatible, T>) => Promise<EsbuildBuildResult<T>>;
|
|
35
|
+
/** weakly typed alias for `esbuild.Loader`.
|
|
36
|
+
* (though, technically it is a super-type, therefore incompatible with old esbuild versions.)
|
|
37
|
+
*/
|
|
38
|
+
export type EsbuildLoaderTypeCompatible = AutoSuggestOrString<EsbuildLoaderType>;
|
|
39
|
+
/** weakly typed alias for `esbuild.Message`, so that it is compatible over all versions of esbuild.
|
|
40
|
+
*
|
|
41
|
+
* > [!note]
|
|
42
|
+
* > the type interface hasn't changed since `v0.15.0` through the current version (`v0.28.0`).
|
|
43
|
+
* > so for now, this type is exactly equivalent to `esbuild.Message` (i.e. not weakly typed at all).
|
|
44
|
+
*/
|
|
45
|
+
export type EsbuildMessageCompatible = EsbuildMessage;
|
|
46
|
+
//# sourceMappingURL=weaktypes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weaktypes.d.ts","sourceRoot":"","sources":["../../src/esbuild/weaktypes.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,KAAK,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,cAAc,EAAE,kBAAkB,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAG/J,sGAAsG;AACtG,MAAM,MAAM,uBAAuB,GAAG;IACrC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,4BAA4B,CAAA;CACnC,CAAA;AAED,+GAA+G;AAC/G,MAAM,MAAM,4BAA4B,GAAG,CAAC,KAAK,EAAE,4BAA4B,KAAK,YAAY,CAAC,IAAI,CAAC,CAAA;AAEtG,2GAA2G;AAC3G,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAAC;KAAG,CAAC,IAAI,MAAM,kBAAkB,GAAG,GAAG;CAAE,EAAE,QAAQ,CAAC,GAAG;IACrG,MAAM,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,YAAY,CAAC,YAAY,GAAG,IAAI,GAAG,SAAS,CAAC,KAAK,IAAI,CAAA;CACtG,CAAA;AAED,4GAA4G;AAC5G,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAAC,mBAAmB,EAAE,OAAO,GAAG,aAAa,GAAG,OAAO,GAAG,UAAU,GAAG,aAAa,GAAG,SAAS,CAAC,GAAG;IACnJ,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,WAAW,CAAC,EAAE,GAAG,CAAA;IACjB,KAAK,CAAC,EAAE,GAAG,CAAA;IACX,QAAQ,CAAC,EAAE,GAAG,CAAA;IACd,WAAW,CAAC,EAAE,GAAG,CAAA;CACjB,CAAA;AAED,2GAA2G;AAC3G,MAAM,MAAM,4BAA4B,GAAG,kBAAkB,CAAC,6BAA6B,CAAC,CAAA;AAE5F,qGAAqG;AACrG,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,SAAS,6BAA6B,EAAE,OAAO,EAAE,SAAS,CAAC,6BAA6B,EAAE,CAAC,CAAC,KAAK,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAA;AAEtK;;EAEE;AACF,MAAM,MAAM,2BAA2B,GAAG,mBAAmB,CAAC,iBAAiB,CAAC,CAAA;AAEhF;;;;;EAKE;AACF,MAAM,MAAM,wBAAwB,GAAG,cAAc,CAAA"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** this module contains esbuild type definitions that are compatible with multiple versions of esbuild.
|
|
2
|
+
*
|
|
3
|
+
* this file is a partial copy from my `@oazmi/esbuild-plugin-deno` esbuild plugin's `typedefs` file.
|
|
4
|
+
* here's the original source: [github](https://github.com/oazmi/esbuild-plugin-deno/blob/b20109988a7245804b52e219ca0f2948fa4012ba/src/plugins/typedefs.ts).
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
export {};
|