@hpcc-js/esbuild-plugins 1.0.2 → 1.0.3
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/dist/index.js +118 -116
- package/dist/index.js.map +4 -4
- package/dist/sfx-wrapper.js +2 -1
- package/dist/sfx-wrapper.js.map +2 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6,7 +6,120 @@ import * as esbuild from "esbuild";
|
|
|
6
6
|
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
7
7
|
import yargs from "yargs";
|
|
8
8
|
import { hideBin } from "yargs/helpers";
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
// src/rebuild-logger.ts
|
|
11
|
+
function rebuildLogger(opts) {
|
|
12
|
+
return {
|
|
13
|
+
name: "rebuild-logger",
|
|
14
|
+
setup(build3) {
|
|
15
|
+
build3.onStart(() => {
|
|
16
|
+
console.log("[watch] build started");
|
|
17
|
+
});
|
|
18
|
+
build3.onEnd(() => {
|
|
19
|
+
console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// src/sfx-wrapper.ts
|
|
26
|
+
import { readFile } from "fs/promises";
|
|
27
|
+
import { existsSync } from "fs";
|
|
28
|
+
import { Base91 } from "@hpcc-js/wasm-base91";
|
|
29
|
+
import { Zstd } from "@hpcc-js/wasm-zstd";
|
|
30
|
+
function tpl(wasmJsPath, base91Wasm, base91CompressedWasm) {
|
|
31
|
+
const compressed = base91CompressedWasm.length + 8 * 1024 <= base91Wasm.length;
|
|
32
|
+
const wasmJsExists = existsSync(wasmJsPath);
|
|
33
|
+
return `${compressed ? 'import { decompress } from "fzstd";' : ""}
|
|
34
|
+
${wasmJsExists ? `import wrapper from "${wasmJsPath}";` : ""}
|
|
35
|
+
|
|
36
|
+
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
|
|
37
|
+
|
|
38
|
+
function decode(raw: string): Uint8Array {
|
|
39
|
+
const len = raw.length;
|
|
40
|
+
const ret: number[] = [];
|
|
41
|
+
|
|
42
|
+
let b = 0;
|
|
43
|
+
let n = 0;
|
|
44
|
+
let v = -1;
|
|
45
|
+
|
|
46
|
+
for (let i = 0; i < len; i++) {
|
|
47
|
+
const p = table.indexOf(raw[i]);
|
|
48
|
+
/* istanbul ignore next */
|
|
49
|
+
if (p === -1) continue;
|
|
50
|
+
if (v < 0) {
|
|
51
|
+
v = p;
|
|
52
|
+
} else {
|
|
53
|
+
v += p * 91;
|
|
54
|
+
b |= v << n;
|
|
55
|
+
n += (v & 8191) > 88 ? 13 : 14;
|
|
56
|
+
do {
|
|
57
|
+
ret.push(b & 0xff);
|
|
58
|
+
b >>= 8;
|
|
59
|
+
n -= 8;
|
|
60
|
+
} while (n > 7);
|
|
61
|
+
v = -1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (v > -1) {
|
|
66
|
+
ret.push((b | v << n) & 0xff);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return new Uint8Array(ret);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';
|
|
73
|
+
|
|
74
|
+
let g_module: Uint8Array | undefined;
|
|
75
|
+
let g_wasmBinary: Uint8Array | undefined;
|
|
76
|
+
export default function() {
|
|
77
|
+
if (!g_wasmBinary) {
|
|
78
|
+
g_wasmBinary = ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
|
|
79
|
+
}
|
|
80
|
+
${!wasmJsExists ? ` return g_wasmBinary;
|
|
81
|
+
` : ` if (!g_module) {
|
|
82
|
+
g_module = wrapper({
|
|
83
|
+
wasmBinary: g_wasmBinary,
|
|
84
|
+
locateFile: undefined
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return g_module;
|
|
88
|
+
`}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function reset() {
|
|
92
|
+
if (g_module) {
|
|
93
|
+
g_module = undefined;
|
|
94
|
+
}
|
|
95
|
+
} `.trim();
|
|
96
|
+
}
|
|
97
|
+
async function wrap(path2) {
|
|
98
|
+
const base91 = await Base91.load();
|
|
99
|
+
const zstd = await Zstd.load();
|
|
100
|
+
const wasm = await readFile(path2);
|
|
101
|
+
path2 = path2.replace(/\.js$/, ".xxx");
|
|
102
|
+
const wasmJsPath = path2.replace(/\.wasm$/, ".js");
|
|
103
|
+
const base91Wasm = base91.encode(wasm);
|
|
104
|
+
const compressedWasm = zstd.compress(wasm);
|
|
105
|
+
const base91CompressedWasm = base91.encode(compressedWasm);
|
|
106
|
+
return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);
|
|
107
|
+
}
|
|
108
|
+
function sfxWasm() {
|
|
109
|
+
return {
|
|
110
|
+
name: "sfx-wasm",
|
|
111
|
+
setup(build3) {
|
|
112
|
+
build3.onLoad({ filter: /\.wasm$/ }, async (args) => {
|
|
113
|
+
return {
|
|
114
|
+
contents: await wrap(args.path),
|
|
115
|
+
loader: "ts"
|
|
116
|
+
};
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// src/build.ts
|
|
10
123
|
var pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
|
|
11
124
|
var NODE_MJS = pkg.type === "module" ? "js" : "mjs";
|
|
12
125
|
var NODE_CJS = pkg.type === "module" ? "cjs" : "js";
|
|
@@ -119,14 +232,14 @@ function bothTpl(input, output, globalName, external = []) {
|
|
|
119
232
|
}
|
|
120
233
|
|
|
121
234
|
// src/exclude-sourcemap.ts
|
|
122
|
-
import { readFile } from "fs/promises";
|
|
235
|
+
import { readFile as readFile2 } from "fs/promises";
|
|
123
236
|
function excludeSourcemap(opts) {
|
|
124
237
|
return {
|
|
125
238
|
name: "exclude-sourcemap",
|
|
126
239
|
setup(build3) {
|
|
127
240
|
build3.onLoad({ filter: opts.filter }, async (args) => {
|
|
128
241
|
return {
|
|
129
|
-
contents: await
|
|
242
|
+
contents: await readFile2(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
|
|
130
243
|
loader: "default"
|
|
131
244
|
};
|
|
132
245
|
});
|
|
@@ -152,117 +265,6 @@ function problemMatcher() {
|
|
|
152
265
|
}
|
|
153
266
|
};
|
|
154
267
|
}
|
|
155
|
-
|
|
156
|
-
// src/rebuild-logger.ts
|
|
157
|
-
function rebuildLogger2(opts) {
|
|
158
|
-
return {
|
|
159
|
-
name: "rebuild-logger",
|
|
160
|
-
setup(build3) {
|
|
161
|
-
build3.onStart(() => {
|
|
162
|
-
console.log("[watch] build started");
|
|
163
|
-
});
|
|
164
|
-
build3.onEnd(() => {
|
|
165
|
-
console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// src/sfx-wrapper.ts
|
|
172
|
-
import { readFile as readFile2 } from "fs/promises";
|
|
173
|
-
import { existsSync } from "fs";
|
|
174
|
-
import { Base91, Zstd } from "@hpcc-js/wasm";
|
|
175
|
-
function tpl(wasmJsPath, base91Wasm, base91CompressedWasm) {
|
|
176
|
-
const compressed = base91CompressedWasm.length + 8 * 1024 <= base91Wasm.length;
|
|
177
|
-
const wasmJsExists = existsSync(wasmJsPath);
|
|
178
|
-
return `${compressed ? 'import { decompress } from "fzstd";' : ""}
|
|
179
|
-
${wasmJsExists ? `import wrapper from "${wasmJsPath}";` : ""}
|
|
180
|
-
|
|
181
|
-
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
|
|
182
|
-
|
|
183
|
-
function decode(raw: string): Uint8Array {
|
|
184
|
-
const len = raw.length;
|
|
185
|
-
const ret: number[] = [];
|
|
186
|
-
|
|
187
|
-
let b = 0;
|
|
188
|
-
let n = 0;
|
|
189
|
-
let v = -1;
|
|
190
|
-
|
|
191
|
-
for (let i = 0; i < len; i++) {
|
|
192
|
-
const p = table.indexOf(raw[i]);
|
|
193
|
-
/* istanbul ignore next */
|
|
194
|
-
if (p === -1) continue;
|
|
195
|
-
if (v < 0) {
|
|
196
|
-
v = p;
|
|
197
|
-
} else {
|
|
198
|
-
v += p * 91;
|
|
199
|
-
b |= v << n;
|
|
200
|
-
n += (v & 8191) > 88 ? 13 : 14;
|
|
201
|
-
do {
|
|
202
|
-
ret.push(b & 0xff);
|
|
203
|
-
b >>= 8;
|
|
204
|
-
n -= 8;
|
|
205
|
-
} while (n > 7);
|
|
206
|
-
v = -1;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (v > -1) {
|
|
211
|
-
ret.push((b | v << n) & 0xff);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return new Uint8Array(ret);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';
|
|
218
|
-
|
|
219
|
-
let g_module: Uint8Array | undefined;
|
|
220
|
-
let g_wasmBinary: Uint8Array | undefined;
|
|
221
|
-
export default function() {
|
|
222
|
-
if (!g_wasmBinary) {
|
|
223
|
-
g_wasmBinary = ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
|
|
224
|
-
}
|
|
225
|
-
${!wasmJsExists ? ` return g_wasmBinary;
|
|
226
|
-
` : ` if (!g_module) {
|
|
227
|
-
g_module = wrapper({
|
|
228
|
-
wasmBinary: g_wasmBinary,
|
|
229
|
-
locateFile: undefined
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
return g_module;
|
|
233
|
-
`}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export function reset() {
|
|
237
|
-
if (g_module) {
|
|
238
|
-
g_module = undefined;
|
|
239
|
-
}
|
|
240
|
-
} `.trim();
|
|
241
|
-
}
|
|
242
|
-
async function wrap(path2) {
|
|
243
|
-
const base91 = await Base91.load();
|
|
244
|
-
const zstd = await Zstd.load();
|
|
245
|
-
const wasm = await readFile2(path2);
|
|
246
|
-
path2 = path2.replace(/\.js$/, ".xxx");
|
|
247
|
-
const wasmJsPath = path2.replace(/\.wasm$/, ".js");
|
|
248
|
-
const base91Wasm = base91.encode(wasm);
|
|
249
|
-
const compressedWasm = zstd.compress(wasm);
|
|
250
|
-
const base91CompressedWasm = base91.encode(compressedWasm);
|
|
251
|
-
return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);
|
|
252
|
-
}
|
|
253
|
-
function sfxWasm2() {
|
|
254
|
-
return {
|
|
255
|
-
name: "sfx-wasm",
|
|
256
|
-
setup(build3) {
|
|
257
|
-
build3.onLoad({ filter: /\.wasm$/ }, async (args) => {
|
|
258
|
-
return {
|
|
259
|
-
contents: await wrap(args.path),
|
|
260
|
-
loader: "ts"
|
|
261
|
-
};
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
268
|
export {
|
|
267
269
|
bothTpl,
|
|
268
270
|
browserBoth,
|
|
@@ -274,8 +276,8 @@ export {
|
|
|
274
276
|
nodeBoth,
|
|
275
277
|
nodeTpl,
|
|
276
278
|
problemMatcher,
|
|
277
|
-
|
|
278
|
-
|
|
279
|
+
rebuildLogger,
|
|
280
|
+
sfxWasm,
|
|
279
281
|
watch,
|
|
280
282
|
wrap
|
|
281
283
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/build.ts", "../src/
|
|
4
|
-
"sourcesContent": ["import * as process from \"process\";\nimport { readFileSync } from \"fs\";\nimport * as path from \"path\";\nimport * as esbuild from \"esbuild\";\nimport type { BuildOptions, Format } from \"esbuild\";\nimport { umdWrapper } from \"esbuild-plugin-umd-wrapper\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { rebuildLogger
|
|
5
|
-
"mappings": ";AAAA,YAAY,aAAa;AACzB,SAAS,oBAAoB;AAC7B,YAAY,UAAU;AACtB,YAAY,aAAa;AAEzB,SAAS,kBAAkB;AAC3B,OAAO,WAAW;AAClB,SAAS,eAAe;
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../src/build.ts", "../src/rebuild-logger.ts", "../src/sfx-wrapper.ts", "../src/exclude-sourcemap.ts", "../src/problem-matcher.ts"],
|
|
4
|
+
"sourcesContent": ["import * as process from \"process\";\nimport { readFileSync } from \"fs\";\nimport * as path from \"path\";\nimport * as esbuild from \"esbuild\";\nimport type { BuildOptions, Format } from \"esbuild\";\nimport { umdWrapper } from \"esbuild-plugin-umd-wrapper\";\nimport yargs from \"yargs\";\nimport { hideBin } from \"yargs/helpers\";\nimport { rebuildLogger } from \"./rebuild-logger.ts\";\nimport { sfxWasm } from \"./sfx-wrapper.ts\";\n\nconst pkg = JSON.parse(readFileSync(path.join(process.cwd(), \"./package.json\"), \"utf8\"));\nconst NODE_MJS = pkg.type === \"module\" ? \"js\" : \"mjs\";\nconst NODE_CJS = pkg.type === \"module\" ? \"cjs\" : \"js\";\n\nconst myYargs = yargs(hideBin(process.argv));\nmyYargs\n .usage(\"Usage: node esbuild.mjs [options]\")\n .demandCommand(0, 0)\n .example(\"node esbuild.mjs --watch\", \"Bundle and watch for changes\")\n .option(\"mode\", {\n alias: \"m\",\n describe: \"Build mode\",\n choices: [\"development\", \"production\"],\n default: \"production\"\n })\n .option(\"w\", {\n alias: \"watch\",\n describe: \"Watch for changes\",\n type: \"boolean\"\n })\n .help(\"h\")\n .alias(\"h\", \"help\")\n .epilog(\"https://github.com/hpcc-systems/hpcc-js-wasm\")\n ;\nconst argv = await myYargs.argv;\nconst isDevelopment = argv.mode === \"development\";\nconst isProduction = !isDevelopment;\nconst isWatch = argv.watch;\n\nexport function build(config: BuildOptions) {\n if (isDevelopment && Array.isArray(config.entryPoints)) {\n console.log(\"Start: \", config.entryPoints[0], config.outfile);\n }\n return esbuild.build({\n ...config,\n sourcemap: \"linked\",\n plugins: [\n ...(config.plugins ?? []),\n sfxWasm()\n ]\n }).finally(() => {\n if (isDevelopment && Array.isArray(config.entryPoints)) {\n console.log(\"Stop: \", config.entryPoints[0], config.outfile);\n }\n });\n}\n\nexport async function watch(config: BuildOptions) {\n await build(config);\n return esbuild.context({\n ...config,\n sourcemap: \"external\",\n plugins: [\n ...(config.plugins ?? []),\n rebuildLogger(config),\n sfxWasm()\n ]\n }).then(ctx => {\n return ctx.watch();\n });\n}\n\nexport function buildWatch(config: BuildOptions) {\n return isWatch ? watch(config) : build(config);\n}\n\nexport function browserTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, external: string[] = []) {\n return buildWatch({\n entryPoints: [input],\n outfile: `${output}.${format === \"esm\" ? \"js\" : \"umd.js\"}`,\n platform: \"browser\",\n target: \"es2022\",\n format: format as Format,\n globalName,\n bundle: true,\n minify: isProduction,\n external,\n plugins: format === \"umd\" ? [umdWrapper()] : []\n });\n}\n\nexport function browserBoth(input: string, output: string, globalName?: string, external: string[] = []) {\n return Promise.all([\n browserTpl(input, output, \"esm\", globalName, external),\n browserTpl(input, output, \"umd\", globalName, external)\n ]);\n}\n\nexport function nodeTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", external: string[] = []) {\n return buildWatch({\n entryPoints: [input],\n outfile: `${output}.${format === \"esm\" ? NODE_MJS : NODE_CJS}`,\n platform: \"node\",\n target: \"node20\",\n format: format as Format,\n bundle: true,\n minify: isProduction,\n external\n });\n}\n\nexport function neutralTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, external: string[] = []) {\n return buildWatch({\n entryPoints: [input],\n outfile: `${output}.${format === \"esm\" ? \"js\" : \"umd.js\"}`,\n platform: \"neutral\",\n target: \"es2022\",\n format: format as Format,\n globalName,\n bundle: true,\n minify: isProduction,\n external,\n plugins: format === \"umd\" ? [umdWrapper()] : []\n });\n}\n\nexport function nodeBoth(input: string, output: string, external: string[] = []) {\n return Promise.all([\n nodeTpl(input, output, \"esm\", external),\n nodeTpl(input, output, \"cjs\", external)\n ]);\n}\n\nexport function bothTpl(input: string, output: string, globalName?: string, external: string[] = []) {\n return Promise.all([\n browserBoth(input, output, globalName, external),\n nodeTpl(input, output, \"cjs\", external)\n ]);\n}\n", "import type { PluginBuild, Plugin } from \"esbuild\";\n\nexport interface RebuildLoggerOptions {\n outfile?: string;\n}\n\nexport function rebuildLogger(opts: RebuildLoggerOptions): Plugin {\n return {\n name: \"rebuild-logger\",\n\n setup(build: PluginBuild) {\n\n build.onStart(() => {\n console.log(\"[watch] build started\");\n });\n\n build.onEnd(() => {\n console.log(`Rebuilt ${opts.outfile ?? \"Unknown\"}`);\n });\n }\n };\n}\n", "import { readFile } from \"fs/promises\";\nimport { existsSync } from \"fs\";\nimport { Base91 } from \"@hpcc-js/wasm-base91\";\nimport { Zstd } from \"@hpcc-js/wasm-zstd\";\nimport type { Plugin, PluginBuild } from \"esbuild\";\n\nfunction tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {\n\n const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;\n const wasmJsExists = existsSync(wasmJsPath);\n\n return `\\\n${compressed ? 'import { decompress } from \"fzstd\";' : ''}\n${wasmJsExists ? `import wrapper from \"${wasmJsPath}\";` : ''}\n\nconst table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\\`{|}~\"';\n\nfunction decode(raw: string): Uint8Array {\n const len = raw.length;\n const ret: number[] = [];\n\n let b = 0;\n let n = 0;\n let v = -1;\n\n for (let i = 0; i < len; i++) {\n const p = table.indexOf(raw[i]);\n /* istanbul ignore next */\n if (p === -1) continue;\n if (v < 0) {\n v = p;\n } else {\n v += p * 91;\n b |= v << n;\n n += (v & 8191) > 88 ? 13 : 14;\n do {\n ret.push(b & 0xff);\n b >>= 8;\n n -= 8;\n } while (n > 7);\n v = -1;\n }\n }\n\n if (v > -1) {\n ret.push((b | v << n) & 0xff);\n }\n\n return new Uint8Array(ret);\n}\n\nconst blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';\n\nlet g_module: Uint8Array | undefined;\nlet g_wasmBinary: Uint8Array | undefined;\nexport default function() {\n if (!g_wasmBinary) {\n g_wasmBinary = ${compressed ? \"decompress(decode(blobStr))\" : \"decode(blobStr)\"};\n }\n${!wasmJsExists ? `\\\n return g_wasmBinary;\n`: `\\\n if (!g_module) {\n g_module = wrapper({\n wasmBinary: g_wasmBinary,\n locateFile: undefined\n });\n }\n return g_module;\n`}\n}\n\nexport function reset() {\n if (g_module) {\n g_module = undefined;\n }\n} `.trim();\n}\n\nexport async function wrap(path: string) {\n const base91 = await Base91.load();\n const zstd = await Zstd.load();\n\n const wasm = await readFile(path);\n path = path.replace(/\\.js$/, \".xxx\");\n const wasmJsPath = path.replace(/\\.wasm$/, \".js\");\n const base91Wasm = base91.encode(wasm);\n const compressedWasm = zstd.compress(wasm);\n const base91CompressedWasm = base91.encode(compressedWasm);\n\n return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);\n}\n\nexport function sfxWasm(): Plugin {\n return {\n name: \"sfx-wasm\",\n\n setup(build: PluginBuild) {\n\n build.onLoad({ filter: /\\.wasm$/ }, async args => {\n return {\n contents: await wrap(args.path),\n loader: \"ts\",\n };\n });\n }\n }\n};\n", "import { readFile } from \"fs/promises\";\nimport type { PluginBuild, Plugin } from \"esbuild\";\n\nexport interface ExcludeSourcemapOptions {\n filter: RegExp;\n}\nexport function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {\n return {\n name: \"exclude-sourcemap\",\n\n setup(build: PluginBuild) {\n build.onLoad({ filter: opts.filter }, async args => {\n return {\n contents: await readFile(args.path, \"utf8\") + \"\\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==\",\n loader: \"default\",\n };\n });\n },\n };\n}\n", "import type { PluginBuild, Plugin } from \"esbuild\";\n\nexport function problemMatcher(): Plugin {\n return {\n name: \"problem-matcher\",\n\n setup(build: PluginBuild) {\n\n build.onStart(() => {\n console.log(\"[watch] build started\");\n });\n\n build.onEnd((result) => {\n result.errors.forEach(({ text, location }) => {\n console.error(`\u2718 [ERROR] ${text}`);\n console.error(` ${location?.file}:${location?.line}:${location?.column}:`);\n });\n console.log(\"[watch] build finished\");\n });\n }\n };\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,YAAY,aAAa;AACzB,SAAS,oBAAoB;AAC7B,YAAY,UAAU;AACtB,YAAY,aAAa;AAEzB,SAAS,kBAAkB;AAC3B,OAAO,WAAW;AAClB,SAAS,eAAe;;;ACDjB,SAAS,cAAc,MAAoC;AAC9D,SAAO;AAAA,IACH,MAAM;AAAA,IAEN,MAAMA,QAAoB;AAEtB,MAAAA,OAAM,QAAQ,MAAM;AAChB,gBAAQ,IAAI,uBAAuB;AAAA,MACvC,CAAC;AAED,MAAAA,OAAM,MAAM,MAAM;AACd,gBAAQ,IAAI,WAAW,KAAK,WAAW,SAAS,EAAE;AAAA,MACtD,CAAC;AAAA,IACL;AAAA,EACJ;AACJ;;;ACrBA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,cAAc;AACvB,SAAS,YAAY;AAGrB,SAAS,IAAI,YAAoB,YAAoB,sBAA8B;AAE/E,QAAM,aAAc,qBAAqB,SAAS,IAAI,QAAS,WAAW;AAC1E,QAAM,eAAe,WAAW,UAAU;AAE1C,SAAO,GACT,aAAa,wCAAwC,EAAE;AAAA,EACvD,eAAe,wBAAwB,UAAU,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MAAM,OAAO,UAAU,IAAI,IAAI,UAAU,IAAI,IAAI,UAAU,MAAM,GAAG;AAAA,QAChF,CAAC;AACD,gBAAQ,IAAI,wBAAwB;AAAA,MACxC,CAAC;AAAA,IACL;AAAA,EACJ;AACJ;",
|
|
6
|
+
"names": ["build", "path", "build", "argv", "build", "readFile", "build", "build"]
|
|
7
7
|
}
|
package/dist/sfx-wrapper.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
// src/sfx-wrapper.ts
|
|
2
2
|
import { readFile } from "fs/promises";
|
|
3
3
|
import { existsSync } from "fs";
|
|
4
|
-
import { Base91
|
|
4
|
+
import { Base91 } from "@hpcc-js/wasm-base91";
|
|
5
|
+
import { Zstd } from "@hpcc-js/wasm-zstd";
|
|
5
6
|
function tpl(wasmJsPath, base91Wasm, base91CompressedWasm) {
|
|
6
7
|
const compressed = base91CompressedWasm.length + 8 * 1024 <= base91Wasm.length;
|
|
7
8
|
const wasmJsExists = existsSync(wasmJsPath);
|
package/dist/sfx-wrapper.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/sfx-wrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import { readFile } from \"fs/promises\";\nimport { existsSync } from \"fs\";\nimport { Base91
|
|
5
|
-
"mappings": ";AAAA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,SAAS,
|
|
4
|
+
"sourcesContent": ["import { readFile } from \"fs/promises\";\nimport { existsSync } from \"fs\";\nimport { Base91 } from \"@hpcc-js/wasm-base91\";\nimport { Zstd } from \"@hpcc-js/wasm-zstd\";\nimport type { Plugin, PluginBuild } from \"esbuild\";\n\nfunction tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {\n\n const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;\n const wasmJsExists = existsSync(wasmJsPath);\n\n return `\\\n${compressed ? 'import { decompress } from \"fzstd\";' : ''}\n${wasmJsExists ? `import wrapper from \"${wasmJsPath}\";` : ''}\n\nconst table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\\`{|}~\"';\n\nfunction decode(raw: string): Uint8Array {\n const len = raw.length;\n const ret: number[] = [];\n\n let b = 0;\n let n = 0;\n let v = -1;\n\n for (let i = 0; i < len; i++) {\n const p = table.indexOf(raw[i]);\n /* istanbul ignore next */\n if (p === -1) continue;\n if (v < 0) {\n v = p;\n } else {\n v += p * 91;\n b |= v << n;\n n += (v & 8191) > 88 ? 13 : 14;\n do {\n ret.push(b & 0xff);\n b >>= 8;\n n -= 8;\n } while (n > 7);\n v = -1;\n }\n }\n\n if (v > -1) {\n ret.push((b | v << n) & 0xff);\n }\n\n return new Uint8Array(ret);\n}\n\nconst blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';\n\nlet g_module: Uint8Array | undefined;\nlet g_wasmBinary: Uint8Array | undefined;\nexport default function() {\n if (!g_wasmBinary) {\n g_wasmBinary = ${compressed ? \"decompress(decode(blobStr))\" : \"decode(blobStr)\"};\n }\n${!wasmJsExists ? `\\\n return g_wasmBinary;\n`: `\\\n if (!g_module) {\n g_module = wrapper({\n wasmBinary: g_wasmBinary,\n locateFile: undefined\n });\n }\n return g_module;\n`}\n}\n\nexport function reset() {\n if (g_module) {\n g_module = undefined;\n }\n} `.trim();\n}\n\nexport async function wrap(path: string) {\n const base91 = await Base91.load();\n const zstd = await Zstd.load();\n\n const wasm = await readFile(path);\n path = path.replace(/\\.js$/, \".xxx\");\n const wasmJsPath = path.replace(/\\.wasm$/, \".js\");\n const base91Wasm = base91.encode(wasm);\n const compressedWasm = zstd.compress(wasm);\n const base91CompressedWasm = base91.encode(compressedWasm);\n\n return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);\n}\n\nexport function sfxWasm(): Plugin {\n return {\n name: \"sfx-wasm\",\n\n setup(build: PluginBuild) {\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