@hpcc-js/esbuild-plugins 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,108 +1,108 @@
1
- import { readFile } from "fs/promises";
2
- import { existsSync } from "fs";
3
- import { Base91 } from "@hpcc-js/wasm-base91";
4
- import { Zstd } from "@hpcc-js/wasm-zstd";
5
- import type { Plugin, PluginBuild } from "esbuild";
6
-
7
- function tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {
8
-
9
- const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;
10
- const wasmJsExists = existsSync(wasmJsPath);
11
-
12
- return `\
13
- ${compressed ? 'import { decompress } from "fzstd";' : ''}
14
- ${wasmJsExists ? `import wrapper from "${wasmJsPath}";` : ''}
15
-
16
- const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
17
-
18
- function decode(raw: string): Uint8Array {
19
- const len = raw.length;
20
- const ret: number[] = [];
21
-
22
- let b = 0;
23
- let n = 0;
24
- let v = -1;
25
-
26
- for (let i = 0; i < len; i++) {
27
- const p = table.indexOf(raw[i]);
28
- /* istanbul ignore next */
29
- if (p === -1) continue;
30
- if (v < 0) {
31
- v = p;
32
- } else {
33
- v += p * 91;
34
- b |= v << n;
35
- n += (v & 8191) > 88 ? 13 : 14;
36
- do {
37
- ret.push(b & 0xff);
38
- b >>= 8;
39
- n -= 8;
40
- } while (n > 7);
41
- v = -1;
42
- }
43
- }
44
-
45
- if (v > -1) {
46
- ret.push((b | v << n) & 0xff);
47
- }
48
-
49
- return new Uint8Array(ret);
50
- }
51
-
52
- const blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';
53
-
54
- let g_module: Uint8Array | undefined;
55
- let g_wasmBinary: Uint8Array | undefined;
56
- export default function() {
57
- if (!g_wasmBinary) {
58
- g_wasmBinary = ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
59
- }
60
- ${!wasmJsExists ? `\
61
- return g_wasmBinary;
62
- `: `\
63
- if (!g_module) {
64
- g_module = wrapper({
65
- wasmBinary: g_wasmBinary,
66
- locateFile: undefined
67
- });
68
- }
69
- return g_module;
70
- `}
71
- }
72
-
73
- export function reset() {
74
- if (g_module) {
75
- g_module = undefined;
76
- }
77
- } `.trim();
78
- }
79
-
80
- export async function wrap(path: string) {
81
- const base91 = await Base91.load();
82
- const zstd = await Zstd.load();
83
-
84
- const wasm = await readFile(path);
85
- path = path.replace(/\.js$/, ".xxx");
86
- const wasmJsPath = path.replace(/\.wasm$/, ".js");
87
- const base91Wasm = base91.encode(wasm);
88
- const compressedWasm = zstd.compress(wasm);
89
- const base91CompressedWasm = base91.encode(compressedWasm);
90
-
91
- return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);
92
- }
93
-
94
- export function sfxWasm(): Plugin {
95
- return {
96
- name: "sfx-wasm",
97
-
98
- setup(build: PluginBuild) {
99
-
100
- build.onLoad({ filter: /\.wasm$/ }, async args => {
101
- return {
102
- contents: await wrap(args.path),
103
- loader: "ts",
104
- };
105
- });
106
- }
107
- }
108
- };
1
+ import { readFile } from "fs/promises";
2
+ import { existsSync } from "fs";
3
+ import { Base91 } from "@hpcc-js/wasm-base91";
4
+ import { Zstd } from "@hpcc-js/wasm-zstd";
5
+ import type { Plugin, PluginBuild } from "esbuild";
6
+
7
+ function tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {
8
+
9
+ const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;
10
+ const wasmJsExists = existsSync(wasmJsPath);
11
+
12
+ return `\
13
+ ${compressed ? 'import { decompress } from "fzstd";' : ""}
14
+ ${wasmJsExists ? `import wrapper from "${wasmJsPath}";` : ""}
15
+
16
+ const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
17
+
18
+ function decode(raw: string): Uint8Array {
19
+ const len = raw.length;
20
+ const ret: number[] = [];
21
+
22
+ let b = 0;
23
+ let n = 0;
24
+ let v = -1;
25
+
26
+ for (let i = 0; i < len; i++) {
27
+ const p = table.indexOf(raw[i]);
28
+ /* istanbul ignore next */
29
+ if (p === -1) continue;
30
+ if (v < 0) {
31
+ v = p;
32
+ } else {
33
+ v += p * 91;
34
+ b |= v << n;
35
+ n += (v & 8191) > 88 ? 13 : 14;
36
+ do {
37
+ ret.push(b & 0xff);
38
+ b >>= 8;
39
+ n -= 8;
40
+ } while (n > 7);
41
+ v = -1;
42
+ }
43
+ }
44
+
45
+ if (v > -1) {
46
+ ret.push((b | v << n) & 0xff);
47
+ }
48
+
49
+ return new Uint8Array(ret);
50
+ }
51
+
52
+ const blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';
53
+
54
+ let g_module: Uint8Array | undefined;
55
+ let g_wasmBinary: Uint8Array | undefined;
56
+ export default function() {
57
+ if (!g_wasmBinary) {
58
+ g_wasmBinary = ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
59
+ }
60
+ ${!wasmJsExists ? `\
61
+ return g_wasmBinary;
62
+ `: `\
63
+ if (!g_module) {
64
+ g_module = wrapper({
65
+ wasmBinary: g_wasmBinary,
66
+ locateFile: undefined
67
+ });
68
+ }
69
+ return g_module;
70
+ `}
71
+ }
72
+
73
+ export function reset() {
74
+ if (g_module) {
75
+ g_module = undefined;
76
+ }
77
+ } `.trim();
78
+ }
79
+
80
+ export async function wrap(path: string) {
81
+ const base91 = await Base91.load();
82
+ const zstd = await Zstd.load();
83
+
84
+ const wasm = await readFile(path);
85
+ path = path.replace(/\.js$/, ".xxx");
86
+ const wasmJsPath = path.replace(/\.wasm$/, ".js");
87
+ const base91Wasm = base91.encode(wasm);
88
+ const compressedWasm = zstd.compress(wasm);
89
+ const base91CompressedWasm = base91.encode(compressedWasm);
90
+
91
+ return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);
92
+ }
93
+
94
+ export function sfxWasm(): Plugin {
95
+ return {
96
+ name: "sfx-wasm",
97
+
98
+ setup(build: PluginBuild) {
99
+
100
+ build.onLoad({ filter: /\.wasm$/ }, async args => {
101
+ return {
102
+ contents: await wrap(args.path),
103
+ loader: "ts",
104
+ };
105
+ });
106
+ }
107
+ };
108
+ }
package/types/build.d.ts CHANGED
@@ -1,7 +1,21 @@
1
1
  import * as esbuild from "esbuild";
2
2
  import type { BuildOptions, Format } from "esbuild";
3
+ export declare const pkg: any;
4
+ export declare const NODE_MJS: string;
5
+ export declare const NODE_CJS: string;
6
+ export declare const argv: {
7
+ [x: string]: unknown;
8
+ _: (string | number)[];
9
+ $0: string;
10
+ } | {
11
+ [x: string]: unknown;
12
+ _: (string | number)[];
13
+ $0: string;
14
+ };
15
+ export declare const isDevelopment: boolean;
16
+ export declare const isProduction: boolean;
17
+ export declare const isWatch: unknown;
3
18
  export declare function build(config: BuildOptions): Promise<esbuild.BuildResult<{
4
- sourcemap: "linked";
5
19
  plugins: esbuild.Plugin[];
6
20
  bundle?: boolean;
7
21
  splitting?: boolean;
@@ -43,6 +57,7 @@ export declare function build(config: BuildOptions): Promise<esbuild.BuildResult
43
57
  stdin?: esbuild.StdinOptions;
44
58
  absWorkingDir?: string;
45
59
  nodePaths?: string[];
60
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
46
61
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
47
62
  sourceRoot?: string;
48
63
  sourcesContent?: boolean;
@@ -84,7 +99,6 @@ export declare function build(config: BuildOptions): Promise<esbuild.BuildResult
84
99
  }>>;
85
100
  export declare function watch(config: BuildOptions): Promise<void>;
86
101
  export declare function buildWatch(config: BuildOptions): Promise<void> | Promise<esbuild.BuildResult<{
87
- sourcemap: "linked";
88
102
  plugins: esbuild.Plugin[];
89
103
  bundle?: boolean;
90
104
  splitting?: boolean;
@@ -126,6 +140,7 @@ export declare function buildWatch(config: BuildOptions): Promise<void> | Promis
126
140
  stdin?: esbuild.StdinOptions;
127
141
  absWorkingDir?: string;
128
142
  nodePaths?: string[];
143
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
129
144
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
130
145
  sourceRoot?: string;
131
146
  sourcesContent?: boolean;
@@ -166,7 +181,6 @@ export declare function buildWatch(config: BuildOptions): Promise<void> | Promis
166
181
  tsconfigRaw?: string | esbuild.TsconfigRaw;
167
182
  }>>;
168
183
  export declare function browserTpl(input: string, output: string, format?: Format | "umd", globalName?: string, external?: string[]): Promise<void> | Promise<esbuild.BuildResult<{
169
- sourcemap: "linked";
170
184
  plugins: esbuild.Plugin[];
171
185
  bundle?: boolean;
172
186
  splitting?: boolean;
@@ -208,6 +222,7 @@ export declare function browserTpl(input: string, output: string, format?: Forma
208
222
  stdin?: esbuild.StdinOptions;
209
223
  absWorkingDir?: string;
210
224
  nodePaths?: string[];
225
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
211
226
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
212
227
  sourceRoot?: string;
213
228
  sourcesContent?: boolean;
@@ -248,7 +263,6 @@ export declare function browserTpl(input: string, output: string, format?: Forma
248
263
  tsconfigRaw?: string | esbuild.TsconfigRaw;
249
264
  }>>;
250
265
  export declare function browserBoth(input: string, output: string, globalName?: string, external?: string[]): Promise<[void | esbuild.BuildResult<{
251
- sourcemap: "linked";
252
266
  plugins: esbuild.Plugin[];
253
267
  bundle?: boolean;
254
268
  splitting?: boolean;
@@ -290,6 +304,7 @@ export declare function browserBoth(input: string, output: string, globalName?:
290
304
  stdin?: esbuild.StdinOptions;
291
305
  absWorkingDir?: string;
292
306
  nodePaths?: string[];
307
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
293
308
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
294
309
  sourceRoot?: string;
295
310
  sourcesContent?: boolean;
@@ -329,7 +344,6 @@ export declare function browserBoth(input: string, output: string, globalName?:
329
344
  logOverride?: Record<string, esbuild.LogLevel>;
330
345
  tsconfigRaw?: string | esbuild.TsconfigRaw;
331
346
  }>, void | esbuild.BuildResult<{
332
- sourcemap: "linked";
333
347
  plugins: esbuild.Plugin[];
334
348
  bundle?: boolean;
335
349
  splitting?: boolean;
@@ -371,6 +385,7 @@ export declare function browserBoth(input: string, output: string, globalName?:
371
385
  stdin?: esbuild.StdinOptions;
372
386
  absWorkingDir?: string;
373
387
  nodePaths?: string[];
388
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
374
389
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
375
390
  sourceRoot?: string;
376
391
  sourcesContent?: boolean;
@@ -411,7 +426,6 @@ export declare function browserBoth(input: string, output: string, globalName?:
411
426
  tsconfigRaw?: string | esbuild.TsconfigRaw;
412
427
  }>]>;
413
428
  export declare function nodeTpl(input: string, output: string, format?: Format | "umd", external?: string[]): Promise<void> | Promise<esbuild.BuildResult<{
414
- sourcemap: "linked";
415
429
  plugins: esbuild.Plugin[];
416
430
  bundle?: boolean;
417
431
  splitting?: boolean;
@@ -453,6 +467,7 @@ export declare function nodeTpl(input: string, output: string, format?: Format |
453
467
  stdin?: esbuild.StdinOptions;
454
468
  absWorkingDir?: string;
455
469
  nodePaths?: string[];
470
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
456
471
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
457
472
  sourceRoot?: string;
458
473
  sourcesContent?: boolean;
@@ -493,7 +508,6 @@ export declare function nodeTpl(input: string, output: string, format?: Format |
493
508
  tsconfigRaw?: string | esbuild.TsconfigRaw;
494
509
  }>>;
495
510
  export declare function neutralTpl(input: string, output: string, format?: Format | "umd", globalName?: string, external?: string[]): Promise<void> | Promise<esbuild.BuildResult<{
496
- sourcemap: "linked";
497
511
  plugins: esbuild.Plugin[];
498
512
  bundle?: boolean;
499
513
  splitting?: boolean;
@@ -535,6 +549,7 @@ export declare function neutralTpl(input: string, output: string, format?: Forma
535
549
  stdin?: esbuild.StdinOptions;
536
550
  absWorkingDir?: string;
537
551
  nodePaths?: string[];
552
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
538
553
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
539
554
  sourceRoot?: string;
540
555
  sourcesContent?: boolean;
@@ -575,7 +590,6 @@ export declare function neutralTpl(input: string, output: string, format?: Forma
575
590
  tsconfigRaw?: string | esbuild.TsconfigRaw;
576
591
  }>>;
577
592
  export declare function nodeBoth(input: string, output: string, external?: string[]): Promise<[void | esbuild.BuildResult<{
578
- sourcemap: "linked";
579
593
  plugins: esbuild.Plugin[];
580
594
  bundle?: boolean;
581
595
  splitting?: boolean;
@@ -617,6 +631,7 @@ export declare function nodeBoth(input: string, output: string, external?: strin
617
631
  stdin?: esbuild.StdinOptions;
618
632
  absWorkingDir?: string;
619
633
  nodePaths?: string[];
634
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
620
635
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
621
636
  sourceRoot?: string;
622
637
  sourcesContent?: boolean;
@@ -656,7 +671,6 @@ export declare function nodeBoth(input: string, output: string, external?: strin
656
671
  logOverride?: Record<string, esbuild.LogLevel>;
657
672
  tsconfigRaw?: string | esbuild.TsconfigRaw;
658
673
  }>, void | esbuild.BuildResult<{
659
- sourcemap: "linked";
660
674
  plugins: esbuild.Plugin[];
661
675
  bundle?: boolean;
662
676
  splitting?: boolean;
@@ -698,6 +712,7 @@ export declare function nodeBoth(input: string, output: string, external?: strin
698
712
  stdin?: esbuild.StdinOptions;
699
713
  absWorkingDir?: string;
700
714
  nodePaths?: string[];
715
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
701
716
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
702
717
  sourceRoot?: string;
703
718
  sourcesContent?: boolean;
@@ -738,7 +753,6 @@ export declare function nodeBoth(input: string, output: string, external?: strin
738
753
  tsconfigRaw?: string | esbuild.TsconfigRaw;
739
754
  }>]>;
740
755
  export declare function bothTpl(input: string, output: string, globalName?: string, external?: string[]): Promise<[[void | esbuild.BuildResult<{
741
- sourcemap: "linked";
742
756
  plugins: esbuild.Plugin[];
743
757
  bundle?: boolean;
744
758
  splitting?: boolean;
@@ -780,6 +794,7 @@ export declare function bothTpl(input: string, output: string, globalName?: stri
780
794
  stdin?: esbuild.StdinOptions;
781
795
  absWorkingDir?: string;
782
796
  nodePaths?: string[];
797
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
783
798
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
784
799
  sourceRoot?: string;
785
800
  sourcesContent?: boolean;
@@ -819,7 +834,6 @@ export declare function bothTpl(input: string, output: string, globalName?: stri
819
834
  logOverride?: Record<string, esbuild.LogLevel>;
820
835
  tsconfigRaw?: string | esbuild.TsconfigRaw;
821
836
  }>, void | esbuild.BuildResult<{
822
- sourcemap: "linked";
823
837
  plugins: esbuild.Plugin[];
824
838
  bundle?: boolean;
825
839
  splitting?: boolean;
@@ -861,6 +875,7 @@ export declare function bothTpl(input: string, output: string, globalName?: stri
861
875
  stdin?: esbuild.StdinOptions;
862
876
  absWorkingDir?: string;
863
877
  nodePaths?: string[];
878
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
864
879
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
865
880
  sourceRoot?: string;
866
881
  sourcesContent?: boolean;
@@ -900,7 +915,6 @@ export declare function bothTpl(input: string, output: string, globalName?: stri
900
915
  logOverride?: Record<string, esbuild.LogLevel>;
901
916
  tsconfigRaw?: string | esbuild.TsconfigRaw;
902
917
  }>], void | esbuild.BuildResult<{
903
- sourcemap: "linked";
904
918
  plugins: esbuild.Plugin[];
905
919
  bundle?: boolean;
906
920
  splitting?: boolean;
@@ -942,6 +956,7 @@ export declare function bothTpl(input: string, output: string, globalName?: stri
942
956
  stdin?: esbuild.StdinOptions;
943
957
  absWorkingDir?: string;
944
958
  nodePaths?: string[];
959
+ sourcemap: boolean | "linked" | "inline" | "external" | "both";
945
960
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
946
961
  sourceRoot?: string;
947
962
  sourcesContent?: boolean;