@hpcc-js/esbuild-plugins 1.6.1 → 1.8.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/esbuild-plugins",
3
- "version": "1.6.1",
3
+ "version": "1.8.0",
4
4
  "description": "Various esbuild plugins",
5
5
  "type": "module",
6
6
  "exports": {
@@ -34,10 +34,11 @@
34
34
  "lint-skypack": "npx -y @skypack/package-check",
35
35
  "lint-eslint": "eslint src/**/*.ts",
36
36
  "lint": "run-p lint-eslint lint-skypack",
37
- "update": "npx --yes npm-check-updates -u -t minor"
37
+ "update": "npx --yes npm-check-updates -u -t minor",
38
+ "update-major": "npx --yes npm-check-updates -u"
38
39
  },
39
40
  "dependencies": {
40
- "esbuild": "0.25.11",
41
+ "esbuild": "0.27.2",
41
42
  "esbuild-copy-static-files": "0.1.0",
42
43
  "esbuild-plugin-inline-css": "0.0.1",
43
44
  "esbuild-plugin-umd-wrapper": "3.0.0",
@@ -46,8 +47,8 @@
46
47
  "vite-plugin-static-copy": "3.1.4"
47
48
  },
48
49
  "devDependencies": {
49
- "@hpcc-js/wasm-base91": "1.8.0",
50
- "@hpcc-js/wasm-zstd": "1.7.0"
50
+ "@hpcc-js/wasm-base91": "1.10.0",
51
+ "@hpcc-js/wasm-zstd": "1.9.0"
51
52
  },
52
53
  "keywords": [
53
54
  "esbuild",
@@ -63,5 +64,5 @@
63
64
  },
64
65
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
65
66
  "license": "Apache-2.0",
66
- "gitHead": "d93d09e45945a39ab056bae20a3dcca3c918cd82"
67
+ "gitHead": "70194f16ed27ea1167af126b35cbf4af5f181be9"
67
68
  }
@@ -1,10 +1,19 @@
1
- import { readFile } from "fs/promises";
2
- import { existsSync } from "fs";
1
+ import { readFile } from "node:fs/promises";
2
+ import { existsSync } from "node:fs";
3
3
  import { Base91 } from "@hpcc-js/wasm-base91";
4
4
  import { Zstd } from "@hpcc-js/wasm-zstd";
5
5
  import type { Plugin, PluginBuild } from "esbuild";
6
6
 
7
- function tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {
7
+ const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
8
+ const DECODE_TABLE = (() => {
9
+ const t = new Int8Array(128).fill(-1);
10
+ for (let i = 0; i < table.length; ++i) {
11
+ t[table.charCodeAt(i)] = i;
12
+ }
13
+ return t;
14
+ })();
15
+
16
+ function tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string, wasmSize: number, compressedSize: number) {
8
17
 
9
18
  const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;
10
19
  const wasmJsExists = existsSync(wasmJsPath);
@@ -13,20 +22,17 @@ function tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: strin
13
22
  ${compressed ? 'import { decompress } from "fzstd";' : ""}
14
23
  ${wasmJsExists ? `import wrapper from "${wasmJsPath}";` : ""}
15
24
 
16
- const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
17
-
18
- function decode(raw: string): Uint8Array {
19
- const len = raw.length;
20
- const ret: number[] = [];
25
+ const D = new Int8Array([${DECODE_TABLE.join(",")}]);
21
26
 
22
- let b = 0;
23
- let n = 0;
24
- let v = -1;
27
+ function decode(s: string): Uint8Array {
28
+ const out = new Uint8Array(${compressed ? compressedSize : wasmSize});
29
+ let pos = 0, b = 0, n = 0, v = -1;
25
30
 
26
- for (let i = 0; i < len; i++) {
27
- const p = table.indexOf(raw[i]);
28
- /* istanbul ignore next */
29
- if (p === -1) continue;
31
+ for (let i = 0, len = s.length; i < len; i++) {
32
+ const c = s.charCodeAt(i);
33
+ if (c > 127) continue;
34
+ const p = D[c];
35
+ if (p < 0) continue;
30
36
  if (v < 0) {
31
37
  v = p;
32
38
  } else {
@@ -34,61 +40,99 @@ function decode(raw: string): Uint8Array {
34
40
  b |= v << n;
35
41
  n += (v & 8191) > 88 ? 13 : 14;
36
42
  do {
37
- ret.push(b & 0xff);
38
- b >>= 8;
43
+ out[pos++] = b;
44
+ b >>>= 8;
39
45
  n -= 8;
40
46
  } while (n > 7);
41
47
  v = -1;
42
48
  }
43
49
  }
44
50
 
45
- if (v > -1) {
46
- ret.push((b | v << n) & 0xff);
47
- }
51
+ if (v >= 0) out[pos++] = (b | v << n) & 0xff;
48
52
 
49
- return new Uint8Array(ret);
53
+ return out;
50
54
  }
51
55
 
52
56
  const blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';
53
57
 
54
- let g_module: Uint8Array | undefined;
55
58
  let g_wasmBinary: Uint8Array | undefined;
56
59
  export default function() {
57
- if (!g_wasmBinary) {
58
- g_wasmBinary = ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
59
- }
60
+ g_wasmBinary ??= ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
60
61
  ${!wasmJsExists ? `\
61
62
  return g_wasmBinary;
62
63
  `: `\
63
- if (!g_module) {
64
- g_module = wrapper({
65
- wasmBinary: g_wasmBinary,
66
- locateFile: (name: string) => "sfx-wrapper nop"
67
- });
68
- }
69
- return g_module;
64
+ return wrapper({
65
+ wasmBinary: g_wasmBinary,
66
+ locateFile: () => ""
67
+ });
70
68
  `}
71
69
  }
72
70
 
73
71
  export function reset() {
74
- if (g_module) {
75
- g_module = undefined;
76
- }
72
+ g_wasmBinary = undefined;
77
73
  } `.trim();
78
74
  }
79
75
 
76
+ let base91Promise: Promise<Base91> | undefined;
77
+ let zstdPromise: Promise<Zstd> | undefined;
78
+ function getBase91() {
79
+ base91Promise ??= Base91.load();
80
+ return base91Promise;
81
+ }
82
+ function getZstd() {
83
+ zstdPromise ??= Zstd.load();
84
+ return zstdPromise;
85
+ }
86
+
80
87
  export async function wrap(path: string) {
81
- const base91 = await Base91.load();
82
- const zstd = await Zstd.load();
88
+ console.info(`Wrapping: ${path}`);
89
+ const [base91, zstd] = await Promise.all([getBase91(), getZstd()]);
83
90
 
91
+ console.info(" Reading WASM file...");
84
92
  const wasm = await readFile(path);
85
- path = path.replace(/\.js$/, ".xxx");
86
93
  const wasmJsPath = path.replace(/\.wasm$/, ".js");
87
- const base91Wasm = base91.encode(wasm);
88
- const compressedWasm = zstd.compress(wasm);
89
- const base91CompressedWasm = base91.encode(compressedWasm);
94
+ const CHUNK_SIZE = 64 * 1024 * 1024;
95
+
96
+ const base91Parts: string[] = [];
97
+ base91.reset();
98
+ for (let offset = 0; offset < wasm.length; offset += CHUNK_SIZE) {
99
+ const chunk = wasm.subarray(offset, Math.min(offset + CHUNK_SIZE, wasm.length));
100
+ base91Parts.push(base91.encodeChunk(chunk));
101
+ console.info(` Encoded ${Math.min(offset + CHUNK_SIZE, wasm.length)} / ${wasm.length} bytes`);
102
+ }
103
+ base91Parts.push(base91.encodeChunkEnd());
104
+ const base91Wasm = base91Parts.join("");
105
+
106
+ console.info(" Compressing...");
107
+ const compressedChunks: Uint8Array[] = [];
108
+ zstd.reset();
109
+ for (let offset = 0; offset < wasm.length; offset += CHUNK_SIZE) {
110
+ const chunk = wasm.subarray(offset, Math.min(offset + CHUNK_SIZE, wasm.length));
111
+ compressedChunks.push(zstd.compressChunk(chunk));
112
+ console.info(` Compressed ${Math.min(offset + CHUNK_SIZE, wasm.length)} / ${wasm.length} bytes`);
113
+ }
114
+ compressedChunks.push(zstd.compressEnd());
115
+ const totalLength = compressedChunks.reduce((sum, chunk) => sum + chunk.length, 0);
116
+ const compressedWasm = new Uint8Array(totalLength);
117
+ let compressionOffset = 0;
118
+ for (const chunk of compressedChunks) {
119
+ compressedWasm.set(chunk, compressionOffset);
120
+ compressionOffset += chunk.length;
121
+ }
122
+
123
+ console.info(" Encoding compressed...");
124
+ const base91CompressedParts: string[] = [];
125
+ base91.reset();
126
+ for (let offset = 0; offset < compressedWasm.length; offset += CHUNK_SIZE) {
127
+ const chunk = compressedWasm.subarray(offset, Math.min(offset + CHUNK_SIZE, compressedWasm.length));
128
+ base91CompressedParts.push(base91.encodeChunk(chunk));
129
+ console.info(` Encoded ${Math.min(offset + CHUNK_SIZE, compressedWasm.length)} / ${compressedWasm.length} bytes (compressed)`);
130
+ }
131
+ base91CompressedParts.push(base91.encodeChunkEnd());
132
+ const base91CompressedWasm = base91CompressedParts.join("");
90
133
 
91
- return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);
134
+ console.info(" Creating wrapper...");
135
+ return tpl(wasmJsPath, base91Wasm, base91CompressedWasm, wasm.length, compressedWasm.length);
92
136
  }
93
137
 
94
138
  export function sfxWasm(): Plugin {
package/src/vite-utils.ts CHANGED
@@ -78,6 +78,19 @@ export function hpccBundleNames(pkg: any) {
78
78
  return { alias: (pkg.name !== "@hpcc-js/common" && pkg.dependencies?.["@hpcc-js/common"]) ? alias : {}, external, globals };
79
79
  }
80
80
 
81
+ const commonCoverageConfig = {
82
+ reporter: ["text", "json", "html"],
83
+ exclude: [
84
+ ...configDefaults.coverage.exclude || [],
85
+ "**/*.spec.ts",
86
+ "**/*.test.ts",
87
+ "**/tests/**",
88
+ "**/dist/**",
89
+ "**/lib-*/**",
90
+ "**/types/**",
91
+ ]
92
+ };
93
+
81
94
  export interface ViteHpccConfigOptions {
82
95
  /**
83
96
  * Additional external items
@@ -115,7 +128,11 @@ export const nodeConfig = defineConfig({
115
128
  "**/demos/**",
116
129
  ],
117
130
  environment: "node",
118
- setupFiles: []
131
+ setupFiles: [],
132
+ coverage: {
133
+ provider: "v8",
134
+ ...commonCoverageConfig
135
+ }
119
136
  }
120
137
  });
121
138
 
@@ -147,6 +164,10 @@ export const browserConfig = defineConfig({
147
164
  screenshotFailures: false,
148
165
  },
149
166
  setupFiles: [],
167
+ coverage: {
168
+ provider: "istanbul",
169
+ ...commonCoverageConfig
170
+ }
150
171
  }
151
172
  });
152
173