@hpcc-js/esbuild-plugins 1.0.7 → 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.
package/README.md CHANGED
@@ -1,45 +1,45 @@
1
- # esbuild-plugin-sfx-wasm
2
-
3
- ## Installation
4
-
5
- With npm:
6
-
7
- ```sh
8
- npm i -D esbuild-plugin-sfx-wasm
9
- ```
10
-
11
- ## Use-cases
12
-
13
- **The primary motivation for this plugin is to simplify the bundling and distribution of web assembly modules**
14
-
15
- - Compresses the wasm module using Zstd
16
- - Encodes the compressed wasm module as a base91 string
17
- - Generates a standalone module that decodes and instantiates the wasm module on demand
18
-
19
- ## Usage
20
-
21
- ### Build Config
22
-
23
- ```ts
24
- import esbuild from "esbuild";
25
- import sfxWasm from "esbuild-plugin-sfx-wasm";
26
-
27
- esbuild.build({
28
- /* ... */
29
- plugins: [
30
- sfxWasm()
31
- ],
32
- /* ... */
33
- });
34
- ```
35
-
36
- ### Usage in your code
37
-
38
- ```js
39
- import loadCalculator from "../build/calculator.wasm";
40
-
41
- async function add(a, b) {
42
- const calc = await loadCalculator();
43
- return calc.add(1, 2);
44
- }
45
- ```
1
+ # esbuild-plugin-sfx-wasm
2
+
3
+ ## Installation
4
+
5
+ With npm:
6
+
7
+ ```sh
8
+ npm i -D esbuild-plugin-sfx-wasm
9
+ ```
10
+
11
+ ## Use-cases
12
+
13
+ **The primary motivation for this plugin is to simplify the bundling and distribution of web assembly modules**
14
+
15
+ - Compresses the wasm module using Zstd
16
+ - Encodes the compressed wasm module as a base91 string
17
+ - Generates a standalone module that decodes and instantiates the wasm module on demand
18
+
19
+ ## Usage
20
+
21
+ ### Build Config
22
+
23
+ ```ts
24
+ import esbuild from "esbuild";
25
+ import sfxWasm from "esbuild-plugin-sfx-wasm";
26
+
27
+ esbuild.build({
28
+ /* ... */
29
+ plugins: [
30
+ sfxWasm()
31
+ ],
32
+ /* ... */
33
+ });
34
+ ```
35
+
36
+ ### Usage in your code
37
+
38
+ ```js
39
+ import loadCalculator from "../build/calculator.wasm";
40
+
41
+ async function add(a, b) {
42
+ const calc = await loadCalculator();
43
+ return calc.add(1, 2);
44
+ }
45
+ ```
package/dist/index.js CHANGED
@@ -60,6 +60,6 @@ export function reset() {
60
60
  if (g_module) {
61
61
  g_module = undefined;
62
62
  }
63
- } `.trim()}async function _(e){let t=await v.load(),r=await S.load(),o=await j(e);e=e.replace(/\.js$/,".xxx");let n=e.replace(/\.wasm$/,".js"),h=t.encode(o),P=r.compress(o),B=t.encode(P);return O(n,h,B)}function l(){return{name:"sfx-wasm",setup(e){e.onLoad({filter:/\.wasm$/},async t=>({contents:await _(t.path),loader:"ts"}))}}}var b=JSON.parse(E(g.join(i.cwd(),"./package.json"),"utf8")),L=b.type==="module"?"js":"mjs",W=b.type==="module"?"cjs":"js",y=F(J(i.argv));y.usage("Usage: node esbuild.mjs [options]").demandCommand(0,0).example("node esbuild.mjs --watch","Bundle and watch for changes").option("mode",{alias:"m",describe:"Build mode",choices:["development","production"],default:"production"}).option("w",{alias:"watch",describe:"Watch for changes",type:"boolean"}).help("h").alias("h","help").epilog("https://github.com/hpcc-systems/hpcc-js-wasm");var w=await y.argv,a=w.mode==="development",m=!a,A=w.watch;function x(e){return a&&Array.isArray(e.entryPoints)&&console.log("Start: ",e.entryPoints[0],e.outfile),s.build({...e,sourcemap:"linked",plugins:[...e.plugins??[],l()]}).finally(()=>{a&&Array.isArray(e.entryPoints)&&console.log("Stop: ",e.entryPoints[0],e.outfile)})}async function R(e){return await x(e),s.context({...e,sourcemap:"external",plugins:[...e.plugins??[],d(e),l()]}).then(t=>t.watch())}function p(e){return A?R(e):x(e)}function c(e,t,r="esm",o,n=[]){return p({entryPoints:[e],outfile:`${t}.${r==="esm"?"js":"umd.js"}`,platform:"browser",target:"es2022",format:r,globalName:o,bundle:!0,minify:m,external:n,plugins:r==="umd"?[f()]:[]})}function U(e,t,r,o=[]){return Promise.all([c(e,t,"esm",r,o),c(e,t,"umd",r,o)])}function u(e,t,r="esm",o=[]){return p({entryPoints:[e],outfile:`${t}.${r==="esm"?L:W}`,platform:"node",target:"node20",format:r,bundle:!0,minify:m,external:o})}function q(e,t,r="esm",o,n=[]){return p({entryPoints:[e],outfile:`${t}.${r==="esm"?"js":"umd.js"}`,platform:"neutral",target:"es2022",format:r,globalName:o,bundle:!0,minify:m,external:n,plugins:r==="umd"?[f()]:[]})}function G(e,t,r=[]){return Promise.all([u(e,t,"esm",r),u(e,t,"cjs",r)])}function H(e,t,r,o=[]){return Promise.all([U(e,t,r,o),u(e,t,"cjs",o)])}import{readFile as z}from"fs/promises";function te(e){return{name:"exclude-sourcemap",setup(t){t.onLoad({filter:e.filter},async r=>({contents:await z(r.path,"utf8")+`
64
- //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function oe(){return{name:"problem-matcher",setup(e){e.onStart(()=>{console.log("[watch] build started")}),e.onEnd(t=>{t.errors.forEach(({text:r,location:o})=>{console.error(`\u2718 [ERROR] ${r}`),console.error(` ${o?.file}:${o?.line}:${o?.column}:`)}),console.log("[watch] build finished")})}}}export{H as bothTpl,U as browserBoth,c as browserTpl,x as build,p as buildWatch,te as excludeSourcemap,q as neutralTpl,G as nodeBoth,u as nodeTpl,oe as problemMatcher,d as rebuildLogger,l as sfxWasm,R as watch,_ as wrap};
63
+ } `.trim()}async function _(e){let t=await v.load(),r=await S.load(),o=await j(e);e=e.replace(/\.js$/,".xxx");let n=e.replace(/\.wasm$/,".js"),h=t.encode(o),P=r.compress(o),B=t.encode(P);return O(n,h,B)}function l(){return{name:"sfx-wasm",setup(e){e.onLoad({filter:/\.wasm$/},async t=>({contents:await _(t.path),loader:"ts"}))}}}var b=F(J(i.argv));b.usage("Usage: node esbuild.mjs [options]").demandCommand(0,0).example("node esbuild.mjs --watch","Bundle and watch for changes").option("mode",{alias:"m",describe:"Build mode",choices:["development","production"],default:"production"}).option("w",{alias:"watch",describe:"Watch for changes",type:"boolean"}).help("h").alias("h","help").epilog("https://github.com/hpcc-systems/hpcc-js-wasm");var x=JSON.parse(E(g.join(i.cwd(),"./package.json"),"utf8")),L=x.type==="module"?"js":"mjs",W=x.type==="module"?"cjs":"js",y=await b.argv,a=y.mode==="development",m=!a,A=y.watch;function w(e){return a&&Array.isArray(e.entryPoints)&&console.log("Start: ",e.entryPoints[0],e.outfile),s.build({sourcemap:"linked",...e,plugins:[...e.plugins??[],l()]}).finally(()=>{a&&Array.isArray(e.entryPoints)&&console.log("Stop: ",e.entryPoints[0],e.outfile)})}async function R(e){return await w(e),s.context({sourcemap:"external",...e,plugins:[...e.plugins??[],d(e),l()]}).then(t=>t.watch())}function p(e){return A?R(e):w(e)}function c(e,t,r="esm",o,n=[]){return p({entryPoints:[e],outfile:`${t}.${r==="esm"?"js":"umd.js"}`,platform:"browser",target:"es2022",format:r,globalName:o,bundle:!0,minify:m,external:n,plugins:r==="umd"?[f({libraryName:o})]:[]})}function U(e,t,r,o=[]){return Promise.all([c(e,t,"esm",r,o),c(e,t,"umd",r,o)])}function u(e,t,r="esm",o=[]){return p({entryPoints:[e],outfile:`${t}.${r==="esm"?L:W}`,platform:"node",target:"node20",format:r,bundle:!0,minify:m,external:o})}function q(e,t,r="esm",o,n=[]){return p({entryPoints:[e],outfile:`${t}.${r==="esm"?"js":"umd.js"}`,platform:"neutral",target:"es2022",format:r,globalName:o,bundle:!0,minify:m,external:n,plugins:r==="umd"?[f()]:[]})}function G(e,t,r=[]){return Promise.all([u(e,t,"esm",r),u(e,t,"cjs",r)])}function H(e,t,r,o=[]){return Promise.all([U(e,t,r,o),u(e,t,"cjs",o)])}import{readFile as z}from"fs/promises";function te(e){return{name:"exclude-sourcemap",setup(t){t.onLoad({filter:e.filter},async r=>({contents:await z(r.path,"utf8")+`
64
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function oe(){return{name:"problem-matcher",setup(e){e.onStart(()=>{console.log("[watch] build started")}),e.onEnd(t=>{t.errors.forEach(({text:r,location:o})=>{console.error(`\u2718 [ERROR] ${r}`),console.error(` ${o?.file}:${o?.line}:${o?.column}:`)}),console.log("[watch] build finished")})}}}export{W as NODE_CJS,L as NODE_MJS,y as argv,H as bothTpl,U as browserBoth,c as browserTpl,w as build,p as buildWatch,te as excludeSourcemap,a as isDevelopment,m as isProduction,A as isWatch,q as neutralTpl,G as nodeBoth,u as nodeTpl,x as pkg,oe as problemMatcher,d as rebuildLogger,l as sfxWasm,R as watch,_ as wrap};
65
65
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
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,UAAYA,MAAa,UACzB,OAAS,gBAAAC,MAAoB,KAC7B,UAAYC,MAAU,OACtB,UAAYC,MAAa,UAEzB,OAAS,cAAAC,MAAkB,6BAC3B,OAAOC,MAAW,QAClB,OAAS,WAAAC,MAAe,gBCDjB,SAASC,EAAcC,EAAoC,CAC9D,MAAO,CACH,KAAM,iBAEN,MAAMC,EAAoB,CAEtBA,EAAM,QAAQ,IAAM,CAChB,QAAQ,IAAI,uBAAuB,CACvC,CAAC,EAEDA,EAAM,MAAM,IAAM,CACd,QAAQ,IAAI,WAAWD,EAAK,SAAW,SAAS,EAAE,CACtD,CAAC,CACL,CACJ,CACJ,CCrBA,OAAS,YAAAE,MAAgB,cACzB,OAAS,cAAAC,MAAkB,KAC3B,OAAS,UAAAC,MAAc,uBACvB,OAAS,QAAAC,MAAY,qBAGrB,SAASC,EAAIC,EAAoBC,EAAoBC,EAA8B,CAE/E,IAAMC,EAAc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C7E,OAAO,QAAQ,IAAI,CACfG,EAAQP,EAAOC,EAAQ,MAAOG,CAAQ,EACtCG,EAAQP,EAAOC,EAAQ,MAAOG,CAAQ,CAC1C,CAAC,CACL,CAEO,SAASM,EAAQV,EAAeC,EAAgBE,EAAqBC,EAAqB,CAAC,EAAG,CACjG,OAAO,QAAQ,IAAI,CACfE,EAAYN,EAAOC,EAAQE,EAAYC,CAAQ,EAC/CG,EAAQP,EAAOC,EAAQ,MAAOG,CAAQ,CAC1C,CAAC,CACL,CG3IA,OAAS,YAAAO,MAAgB,cAMlB,SAASC,GAAiBC,EAAuC,CACpE,MAAO,CACH,KAAM,oBAEN,MAAMC,EAAoB,CACtBA,EAAM,OAAO,CAAE,OAAQD,EAAK,MAAO,EAAG,MAAME,IACjC,CACH,SAAU,MAAMJ,EAASI,EAAK,KAAM,MAAM,EAAI;AAAA,gHAC9C,OAAQ,SACZ,EACH,CACL,CACJ,CACJ,CCjBO,SAASC,IAAyB,CACrC,MAAO,CACH,KAAM,kBAEN,MAAMC,EAAoB,CAEtBA,EAAM,QAAQ,IAAM,CAChB,QAAQ,IAAI,uBAAuB,CACvC,CAAC,EAEDA,EAAM,MAAOC,GAAW,CACpBA,EAAO,OAAO,QAAQ,CAAC,CAAE,KAAAC,EAAM,SAAAC,CAAS,IAAM,CAC1C,QAAQ,MAAM,kBAAaD,CAAI,EAAE,EACjC,QAAQ,MAAM,OAAOC,GAAU,IAAI,IAAIA,GAAU,IAAI,IAAIA,GAAU,MAAM,GAAG,CAChF,CAAC,EACD,QAAQ,IAAI,wBAAwB,CACxC,CAAC,CACL,CACJ,CACJ",
6
- "names": ["process", "readFileSync", "path", "esbuild", "umdWrapper", "yargs", "hideBin", "rebuildLogger", "opts", "build", "readFile", "existsSync", "Base91", "Zstd", "tpl", "wasmJsPath", "base91Wasm", "base91CompressedWasm", "compressed", "wasmJsExists", "wrap", "path", "base91", "zstd", "wasm", "compressedWasm", "sfxWasm", "build", "args", "pkg", "readFileSync", "NODE_MJS", "NODE_CJS", "myYargs", "yargs", "hideBin", "argv", "isDevelopment", "isProduction", "isWatch", "build", "config", "sfxWasm", "watch", "rebuildLogger", "ctx", "buildWatch", "browserTpl", "input", "output", "format", "globalName", "external", "umdWrapper", "browserBoth", "nodeTpl", "neutralTpl", "nodeBoth", "bothTpl", "readFile", "excludeSourcemap", "opts", "build", "args", "problemMatcher", "build", "result", "text", "location"]
4
+ "sourcesContent": ["import * as process from \"process\";\r\nimport { readFileSync } from \"fs\";\r\nimport * as path from \"path\";\r\nimport * as esbuild from \"esbuild\";\r\nimport type { BuildOptions, Format } from \"esbuild\";\r\nimport { umdWrapper } from \"esbuild-plugin-umd-wrapper\";\r\nimport yargs from \"yargs\";\r\nimport { hideBin } from \"yargs/helpers\";\r\nimport { rebuildLogger } from \"./rebuild-logger.ts\";\r\nimport { sfxWasm } from \"./sfx-wrapper.ts\";\r\n\r\nconst myYargs = yargs(hideBin(process.argv));\r\nmyYargs\r\n .usage(\"Usage: node esbuild.mjs [options]\")\r\n .demandCommand(0, 0)\r\n .example(\"node esbuild.mjs --watch\", \"Bundle and watch for changes\")\r\n .option(\"mode\", {\r\n alias: \"m\",\r\n describe: \"Build mode\",\r\n choices: [\"development\", \"production\"],\r\n default: \"production\"\r\n })\r\n .option(\"w\", {\r\n alias: \"watch\",\r\n describe: \"Watch for changes\",\r\n type: \"boolean\"\r\n })\r\n .help(\"h\")\r\n .alias(\"h\", \"help\")\r\n .epilog(\"https://github.com/hpcc-systems/hpcc-js-wasm\")\r\n ;\r\n\r\nexport const pkg = JSON.parse(readFileSync(path.join(process.cwd(), \"./package.json\"), \"utf8\"));\r\nexport const NODE_MJS = pkg.type === \"module\" ? \"js\" : \"mjs\";\r\nexport const NODE_CJS = pkg.type === \"module\" ? \"cjs\" : \"js\";\r\n\r\nexport const argv = await myYargs.argv;\r\nexport const isDevelopment = argv.mode === \"development\";\r\nexport const isProduction = !isDevelopment;\r\nexport const isWatch = argv.watch;\r\n\r\nexport function build(config: BuildOptions) {\r\n if (isDevelopment && Array.isArray(config.entryPoints)) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"Start: \", config.entryPoints[0], config.outfile);\r\n }\r\n return esbuild.build({\r\n sourcemap: \"linked\",\r\n ...config,\r\n plugins: [\r\n ...(config.plugins ?? []),\r\n sfxWasm()\r\n ]\r\n }).finally(() => {\r\n if (isDevelopment && Array.isArray(config.entryPoints)) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"Stop: \", config.entryPoints[0], config.outfile);\r\n }\r\n });\r\n}\r\n\r\nexport async function watch(config: BuildOptions) {\r\n await build(config);\r\n return esbuild.context({\r\n sourcemap: \"external\",\r\n ...config,\r\n plugins: [\r\n ...(config.plugins ?? []),\r\n rebuildLogger(config),\r\n sfxWasm()\r\n ]\r\n }).then(ctx => {\r\n return ctx.watch();\r\n });\r\n}\r\n\r\nexport function buildWatch(config: BuildOptions) {\r\n return isWatch ? watch(config) : build(config);\r\n}\r\n\r\nexport function browserTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, external: string[] = []) {\r\n return buildWatch({\r\n entryPoints: [input],\r\n outfile: `${output}.${format === \"esm\" ? \"js\" : \"umd.js\"}`,\r\n platform: \"browser\",\r\n target: \"es2022\",\r\n format: format as Format,\r\n globalName,\r\n bundle: true,\r\n minify: isProduction,\r\n external,\r\n plugins: format === \"umd\" ? [umdWrapper({ libraryName: globalName })] : []\r\n });\r\n}\r\n\r\nexport function browserBoth(input: string, output: string, globalName?: string, external: string[] = []) {\r\n return Promise.all([\r\n browserTpl(input, output, \"esm\", globalName, external),\r\n browserTpl(input, output, \"umd\", globalName, external)\r\n ]);\r\n}\r\n\r\nexport function nodeTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", external: string[] = []) {\r\n return buildWatch({\r\n entryPoints: [input],\r\n outfile: `${output}.${format === \"esm\" ? NODE_MJS : NODE_CJS}`,\r\n platform: \"node\",\r\n target: \"node20\",\r\n format: format as Format,\r\n bundle: true,\r\n minify: isProduction,\r\n external\r\n });\r\n}\r\n\r\nexport function neutralTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, external: string[] = []) {\r\n return buildWatch({\r\n entryPoints: [input],\r\n outfile: `${output}.${format === \"esm\" ? \"js\" : \"umd.js\"}`,\r\n platform: \"neutral\",\r\n target: \"es2022\",\r\n format: format as Format,\r\n globalName,\r\n bundle: true,\r\n minify: isProduction,\r\n external,\r\n plugins: format === \"umd\" ? [umdWrapper()] : []\r\n });\r\n}\r\n\r\nexport function nodeBoth(input: string, output: string, external: string[] = []) {\r\n return Promise.all([\r\n nodeTpl(input, output, \"esm\", external),\r\n nodeTpl(input, output, \"cjs\", external)\r\n ]);\r\n}\r\n\r\nexport function bothTpl(input: string, output: string, globalName?: string, external: string[] = []) {\r\n return Promise.all([\r\n browserBoth(input, output, globalName, external),\r\n nodeTpl(input, output, \"cjs\", external)\r\n ]);\r\n}\r\n", "import type { PluginBuild, Plugin } from \"esbuild\";\r\n\r\nexport interface RebuildLoggerOptions {\r\n outfile?: string;\r\n}\r\n\r\nexport function rebuildLogger(opts: RebuildLoggerOptions): Plugin {\r\n return {\r\n name: \"rebuild-logger\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onStart(() => {\r\n // eslint-disable-next-line no-console\r\n console.log(\"[watch] build started\");\r\n });\r\n\r\n build.onEnd(() => {\r\n // eslint-disable-next-line no-console\r\n console.log(`Rebuilt ${opts.outfile ?? \"Unknown\"}`);\r\n });\r\n }\r\n };\r\n}\r\n", "import { readFile } from \"fs/promises\";\r\nimport { existsSync } from \"fs\";\r\nimport { Base91 } from \"@hpcc-js/wasm-base91\";\r\nimport { Zstd } from \"@hpcc-js/wasm-zstd\";\r\nimport type { Plugin, PluginBuild } from \"esbuild\";\r\n\r\nfunction tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {\r\n\r\n const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;\r\n const wasmJsExists = existsSync(wasmJsPath);\r\n\r\n return `\\\r\n${compressed ? 'import { decompress } from \"fzstd\";' : \"\"}\r\n${wasmJsExists ? `import wrapper from \"${wasmJsPath}\";` : \"\"}\r\n\r\nconst table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\\`{|}~\"';\r\n\r\nfunction decode(raw: string): Uint8Array {\r\n const len = raw.length;\r\n const ret: number[] = [];\r\n\r\n let b = 0;\r\n let n = 0;\r\n let v = -1;\r\n\r\n for (let i = 0; i < len; i++) {\r\n const p = table.indexOf(raw[i]);\r\n /* istanbul ignore next */\r\n if (p === -1) continue;\r\n if (v < 0) {\r\n v = p;\r\n } else {\r\n v += p * 91;\r\n b |= v << n;\r\n n += (v & 8191) > 88 ? 13 : 14;\r\n do {\r\n ret.push(b & 0xff);\r\n b >>= 8;\r\n n -= 8;\r\n } while (n > 7);\r\n v = -1;\r\n }\r\n }\r\n\r\n if (v > -1) {\r\n ret.push((b | v << n) & 0xff);\r\n }\r\n\r\n return new Uint8Array(ret);\r\n}\r\n\r\nconst blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';\r\n\r\nlet g_module: Uint8Array | undefined;\r\nlet g_wasmBinary: Uint8Array | undefined;\r\nexport default function() {\r\n if (!g_wasmBinary) {\r\n g_wasmBinary = ${compressed ? \"decompress(decode(blobStr))\" : \"decode(blobStr)\"};\r\n }\r\n${!wasmJsExists ? `\\\r\n return g_wasmBinary;\r\n`: `\\\r\n if (!g_module) {\r\n g_module = wrapper({\r\n wasmBinary: g_wasmBinary,\r\n locateFile: undefined\r\n });\r\n }\r\n return g_module;\r\n`}\r\n}\r\n\r\nexport function reset() {\r\n if (g_module) {\r\n g_module = undefined;\r\n }\r\n} `.trim();\r\n}\r\n\r\nexport async function wrap(path: string) {\r\n const base91 = await Base91.load();\r\n const zstd = await Zstd.load();\r\n\r\n const wasm = await readFile(path);\r\n path = path.replace(/\\.js$/, \".xxx\");\r\n const wasmJsPath = path.replace(/\\.wasm$/, \".js\");\r\n const base91Wasm = base91.encode(wasm);\r\n const compressedWasm = zstd.compress(wasm);\r\n const base91CompressedWasm = base91.encode(compressedWasm);\r\n\r\n return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);\r\n}\r\n\r\nexport function sfxWasm(): Plugin {\r\n return {\r\n name: \"sfx-wasm\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onLoad({ filter: /\\.wasm$/ }, async args => {\r\n return {\r\n contents: await wrap(args.path),\r\n loader: \"ts\",\r\n };\r\n });\r\n }\r\n };\r\n}\r\n", "import { readFile } from \"fs/promises\";\r\nimport type { PluginBuild, Plugin } from \"esbuild\";\r\n\r\nexport interface ExcludeSourcemapOptions {\r\n filter: RegExp;\r\n}\r\nexport function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {\r\n return {\r\n name: \"exclude-sourcemap\",\r\n\r\n setup(build: PluginBuild) {\r\n build.onLoad({ filter: opts.filter }, async args => {\r\n return {\r\n contents: await readFile(args.path, \"utf8\") + \"\\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==\",\r\n loader: \"default\",\r\n };\r\n });\r\n },\r\n };\r\n}\r\n", "import type { PluginBuild, Plugin } from \"esbuild\";\r\n\r\nexport function problemMatcher(): Plugin {\r\n return {\r\n name: \"problem-matcher\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onStart(() => {\r\n // eslint-disable-next-line no-console\r\n console.log(\"[watch] build started\");\r\n });\r\n\r\n build.onEnd((result) => {\r\n result.errors.forEach(({ text, location }) => {\r\n console.error(`\u2718 [ERROR] ${text}`);\r\n console.error(` ${location?.file}:${location?.line}:${location?.column}:`);\r\n });\r\n // eslint-disable-next-line no-console\r\n console.log(\"[watch] build finished\");\r\n });\r\n }\r\n };\r\n}\r\n"],
5
+ "mappings": "AAAA,UAAYA,MAAa,UACzB,OAAS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BA,EAAM,QAAQ,IAAM,CAEhB,QAAQ,IAAI,uBAAuB,CACvC,CAAC,EAEDA,EAAM,MAAOC,GAAW,CACpBA,EAAO,OAAO,QAAQ,CAAC,CAAE,KAAAC,EAAM,SAAAC,CAAS,IAAM,CAC1C,QAAQ,MAAM,kBAAaD,CAAI,EAAE,EACjC,QAAQ,MAAM,OAAOC,GAAU,IAAI,IAAIA,GAAU,IAAI,IAAIA,GAAU,MAAM,GAAG,CAChF,CAAC,EAED,QAAQ,IAAI,wBAAwB,CACxC,CAAC,CACL,CACJ,CACJ",
6
+ "names": ["process", "readFileSync", "path", "esbuild", "umdWrapper", "yargs", "hideBin", "rebuildLogger", "opts", "build", "readFile", "existsSync", "Base91", "Zstd", "tpl", "wasmJsPath", "base91Wasm", "base91CompressedWasm", "compressed", "wasmJsExists", "wrap", "path", "base91", "zstd", "wasm", "compressedWasm", "sfxWasm", "build", "args", "myYargs", "yargs", "hideBin", "pkg", "readFileSync", "NODE_MJS", "NODE_CJS", "argv", "isDevelopment", "isProduction", "isWatch", "build", "config", "sfxWasm", "watch", "rebuildLogger", "ctx", "buildWatch", "browserTpl", "input", "output", "format", "globalName", "external", "umdWrapper", "browserBoth", "nodeTpl", "neutralTpl", "nodeBoth", "bothTpl", "readFile", "excludeSourcemap", "opts", "build", "args", "problemMatcher", "build", "result", "text", "location"]
7
7
  }
@@ -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 } 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"],
4
+ "sourcesContent": ["import { readFile } from \"fs/promises\";\r\nimport { existsSync } from \"fs\";\r\nimport { Base91 } from \"@hpcc-js/wasm-base91\";\r\nimport { Zstd } from \"@hpcc-js/wasm-zstd\";\r\nimport type { Plugin, PluginBuild } from \"esbuild\";\r\n\r\nfunction tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {\r\n\r\n const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;\r\n const wasmJsExists = existsSync(wasmJsPath);\r\n\r\n return `\\\r\n${compressed ? 'import { decompress } from \"fzstd\";' : \"\"}\r\n${wasmJsExists ? `import wrapper from \"${wasmJsPath}\";` : \"\"}\r\n\r\nconst table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\\`{|}~\"';\r\n\r\nfunction decode(raw: string): Uint8Array {\r\n const len = raw.length;\r\n const ret: number[] = [];\r\n\r\n let b = 0;\r\n let n = 0;\r\n let v = -1;\r\n\r\n for (let i = 0; i < len; i++) {\r\n const p = table.indexOf(raw[i]);\r\n /* istanbul ignore next */\r\n if (p === -1) continue;\r\n if (v < 0) {\r\n v = p;\r\n } else {\r\n v += p * 91;\r\n b |= v << n;\r\n n += (v & 8191) > 88 ? 13 : 14;\r\n do {\r\n ret.push(b & 0xff);\r\n b >>= 8;\r\n n -= 8;\r\n } while (n > 7);\r\n v = -1;\r\n }\r\n }\r\n\r\n if (v > -1) {\r\n ret.push((b | v << n) & 0xff);\r\n }\r\n\r\n return new Uint8Array(ret);\r\n}\r\n\r\nconst blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';\r\n\r\nlet g_module: Uint8Array | undefined;\r\nlet g_wasmBinary: Uint8Array | undefined;\r\nexport default function() {\r\n if (!g_wasmBinary) {\r\n g_wasmBinary = ${compressed ? \"decompress(decode(blobStr))\" : \"decode(blobStr)\"};\r\n }\r\n${!wasmJsExists ? `\\\r\n return g_wasmBinary;\r\n`: `\\\r\n if (!g_module) {\r\n g_module = wrapper({\r\n wasmBinary: g_wasmBinary,\r\n locateFile: undefined\r\n });\r\n }\r\n return g_module;\r\n`}\r\n}\r\n\r\nexport function reset() {\r\n if (g_module) {\r\n g_module = undefined;\r\n }\r\n} `.trim();\r\n}\r\n\r\nexport async function wrap(path: string) {\r\n const base91 = await Base91.load();\r\n const zstd = await Zstd.load();\r\n\r\n const wasm = await readFile(path);\r\n path = path.replace(/\\.js$/, \".xxx\");\r\n const wasmJsPath = path.replace(/\\.wasm$/, \".js\");\r\n const base91Wasm = base91.encode(wasm);\r\n const compressedWasm = zstd.compress(wasm);\r\n const base91CompressedWasm = base91.encode(compressedWasm);\r\n\r\n return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);\r\n}\r\n\r\nexport function sfxWasm(): Plugin {\r\n return {\r\n name: \"sfx-wasm\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onLoad({ filter: /\\.wasm$/ }, async args => {\r\n return {\r\n contents: await wrap(args.path),\r\n loader: \"ts\",\r\n };\r\n });\r\n }\r\n };\r\n}\r\n"],
5
5
  "mappings": "AAAA,OAAS,YAAAA,MAAgB,cACzB,OAAS,cAAAC,MAAkB,KAC3B,OAAS,UAAAC,MAAc,uBACvB,OAAS,QAAAC,MAAY,qBAGrB,SAASC,EAAIC,EAAoBC,EAAoBC,EAA8B,CAE/E,IAAMC,EAAcD,EAAqB,OAAS,MAAaD,EAAW,OACpEG,EAAeR,EAAWI,CAAU,EAE1C,MAAO,GACTG,EAAa,sCAAwC,EAAE;AAAA,EACvDC,EAAe,wBAAwBJ,CAAU,KAAO,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAsCzCG,EAAaD,EAAuBD,CAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAMxCE,EAAa,8BAAgC,iBAAiB;AAAA;AAAA,EAEpFC,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAFe;AAAA,CAUjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOG,KAAK,CACT,CAEA,eAAsBC,EAAKC,EAAc,CACrC,IAAMC,EAAS,MAAMV,EAAO,KAAK,EAC3BW,EAAO,MAAMV,EAAK,KAAK,EAEvBW,EAAO,MAAMd,EAASW,CAAI,EAChCA,EAAOA,EAAK,QAAQ,QAAS,MAAM,EACnC,IAAMN,EAAaM,EAAK,QAAQ,UAAW,KAAK,EAC1CL,EAAaM,EAAO,OAAOE,CAAI,EAC/BC,EAAiBF,EAAK,SAASC,CAAI,EACnCP,EAAuBK,EAAO,OAAOG,CAAc,EAEzD,OAAOX,EAAIC,EAAYC,EAAYC,CAAoB,CAC3D,CAEO,SAASS,GAAkB,CAC9B,MAAO,CACH,KAAM,WAEN,MAAMC,EAAoB,CAEtBA,EAAM,OAAO,CAAE,OAAQ,SAAU,EAAG,MAAMC,IAC/B,CACH,SAAU,MAAMR,EAAKQ,EAAK,IAAI,EAC9B,OAAQ,IACZ,EACH,CACL,CACJ,CACJ",
6
6
  "names": ["readFile", "existsSync", "Base91", "Zstd", "tpl", "wasmJsPath", "base91Wasm", "base91CompressedWasm", "compressed", "wasmJsExists", "wrap", "path", "base91", "zstd", "wasm", "compressedWasm", "sfxWasm", "build", "args"]
7
7
  }
package/package.json CHANGED
@@ -1,63 +1,63 @@
1
- {
2
- "name": "@hpcc-js/esbuild-plugins",
3
- "version": "1.0.7",
4
- "description": "Various esbuild plugins",
5
- "type": "module",
6
- "exports": {
7
- ".": {
8
- "types": "./types/index.d.ts",
9
- "default": "./dist/index.js"
10
- },
11
- "./sfx-wrapper": {
12
- "types": "./types/sfx-wrapper.d.ts",
13
- "default": "./dist/sfx-wrapper.js"
14
- }
15
- },
16
- "main": "./dist/index.js",
17
- "types": "./types/index.d.ts",
18
- "files": [
19
- "dist/**/*",
20
- "src/**/*",
21
- "types/**/*"
22
- ],
23
- "scripts": {
24
- "clean": "rimraf ./dist ./types",
25
- "build-types": "tsc --project tsconfig.json --emitDeclarationOnly",
26
- "build-types-watch": "npm run build-types -- --watch",
27
- "build-ts-dev": "esbuild ./src/index.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./dist/index.js",
28
- "build-ts": "npm run build-ts-dev -- --minify",
29
- "build-ts-watch": "npm run build-ts-dev -- --watch",
30
- "build-dev": "run-p build-types build-ts-dev",
31
- "build-sfx-wrapper-dev": "esbuild ./src/sfx-wrapper.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./dist/sfx-wrapper.js",
32
- "build-sfx-wrapper": "npm run build-sfx-wrapper-dev -- --minify",
33
- "build": "run-p build-types build-ts build-sfx-wrapper",
34
- "lint-skypack": "npx -y @skypack/package-check",
35
- "lint-eslint": "eslint src/**/*.ts",
36
- "lint": "run-p lint-eslint lint-skypack",
37
- "test-cli": "npx . -v",
38
- "test-cli-help": "npx .",
39
- "test-node": "npx . -v",
40
- "update": "npx --yes npm-check-updates -u -t minor"
41
- },
42
- "dependencies": {
43
- "@hpcc-js/wasm-base91": "1.0.1",
44
- "@hpcc-js/wasm-zstd": "1.0.1",
45
- "yargs": "17.7.2",
46
- "fzstd": "0.1.1"
47
- },
48
- "devDependencies": {},
49
- "keywords": [
50
- "esbuild",
51
- "plugins",
52
- "WebAssembly",
53
- "wasm",
54
- "sfx"
55
- ],
56
- "author": "hpcc-systems",
57
- "repository": {
58
- "type": "git",
59
- "url": "git+https://github.com/hpcc-systems/hpcc-js-wasm.git"
60
- },
61
- "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
62
- "license": "Apache-2.0"
1
+ {
2
+ "name": "@hpcc-js/esbuild-plugins",
3
+ "version": "1.0.8",
4
+ "description": "Various esbuild plugins",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./types/index.d.ts",
9
+ "default": "./dist/index.js"
10
+ },
11
+ "./sfx-wrapper": {
12
+ "types": "./types/sfx-wrapper.d.ts",
13
+ "default": "./dist/sfx-wrapper.js"
14
+ }
15
+ },
16
+ "main": "./dist/index.js",
17
+ "types": "./types/index.d.ts",
18
+ "files": [
19
+ "dist/**/*",
20
+ "src/**/*",
21
+ "types/**/*"
22
+ ],
23
+ "scripts": {
24
+ "clean": "rimraf ./dist ./types",
25
+ "build-types": "tsc --project tsconfig.json --emitDeclarationOnly",
26
+ "build-types-watch": "npm run build-types -- --watch",
27
+ "build-ts-dev": "esbuild ./src/index.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./dist/index.js",
28
+ "build-ts": "npm run build-ts-dev -- --minify",
29
+ "build-ts-watch": "npm run build-ts-dev -- --watch",
30
+ "build-dev": "run-p build-types build-ts-dev",
31
+ "build-sfx-wrapper-dev": "esbuild ./src/sfx-wrapper.ts --platform=node --format=esm --bundle --packages=external --sourcemap --outfile=./dist/sfx-wrapper.js",
32
+ "build-sfx-wrapper": "npm run build-sfx-wrapper-dev -- --minify",
33
+ "build": "run-p build-types build-ts build-sfx-wrapper",
34
+ "lint-skypack": "npx -y @skypack/package-check",
35
+ "lint-eslint": "eslint src/**/*.ts",
36
+ "lint": "run-p lint-eslint lint-skypack",
37
+ "test-cli": "npx . -v",
38
+ "test-cli-help": "npx .",
39
+ "test-node": "npx . -v",
40
+ "update": "npx --yes npm-check-updates -u -t minor"
41
+ },
42
+ "dependencies": {
43
+ "@hpcc-js/wasm-base91": "1.0.1",
44
+ "@hpcc-js/wasm-zstd": "1.0.1",
45
+ "yargs": "17.7.2",
46
+ "fzstd": "0.1.1"
47
+ },
48
+ "devDependencies": {},
49
+ "keywords": [
50
+ "esbuild",
51
+ "plugins",
52
+ "WebAssembly",
53
+ "wasm",
54
+ "sfx"
55
+ ],
56
+ "author": "hpcc-systems",
57
+ "repository": {
58
+ "type": "git",
59
+ "url": "git+https://github.com/hpcc-systems/hpcc-js-wasm.git"
60
+ },
61
+ "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
62
+ "license": "Apache-2.0"
63
63
  }
package/src/build.ts CHANGED
@@ -1,140 +1,143 @@
1
- import * as process from "process";
2
- import { readFileSync } from "fs";
3
- import * as path from "path";
4
- import * as esbuild from "esbuild";
5
- import type { BuildOptions, Format } from "esbuild";
6
- import { umdWrapper } from "esbuild-plugin-umd-wrapper";
7
- import yargs from "yargs";
8
- import { hideBin } from "yargs/helpers";
9
- import { rebuildLogger } from "./rebuild-logger.ts";
10
- import { sfxWasm } from "./sfx-wrapper.ts";
11
-
12
- const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
13
- const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
14
- const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
15
-
16
- const myYargs = yargs(hideBin(process.argv));
17
- myYargs
18
- .usage("Usage: node esbuild.mjs [options]")
19
- .demandCommand(0, 0)
20
- .example("node esbuild.mjs --watch", "Bundle and watch for changes")
21
- .option("mode", {
22
- alias: "m",
23
- describe: "Build mode",
24
- choices: ["development", "production"],
25
- default: "production"
26
- })
27
- .option("w", {
28
- alias: "watch",
29
- describe: "Watch for changes",
30
- type: "boolean"
31
- })
32
- .help("h")
33
- .alias("h", "help")
34
- .epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
35
- ;
36
- const argv = await myYargs.argv;
37
- const isDevelopment = argv.mode === "development";
38
- const isProduction = !isDevelopment;
39
- const isWatch = argv.watch;
40
-
41
- export function build(config: BuildOptions) {
42
- if (isDevelopment && Array.isArray(config.entryPoints)) {
43
- console.log("Start: ", config.entryPoints[0], config.outfile);
44
- }
45
- return esbuild.build({
46
- ...config,
47
- sourcemap: "linked",
48
- plugins: [
49
- ...(config.plugins ?? []),
50
- sfxWasm()
51
- ]
52
- }).finally(() => {
53
- if (isDevelopment && Array.isArray(config.entryPoints)) {
54
- console.log("Stop: ", config.entryPoints[0], config.outfile);
55
- }
56
- });
57
- }
58
-
59
- export async function watch(config: BuildOptions) {
60
- await build(config);
61
- return esbuild.context({
62
- ...config,
63
- sourcemap: "external",
64
- plugins: [
65
- ...(config.plugins ?? []),
66
- rebuildLogger(config),
67
- sfxWasm()
68
- ]
69
- }).then(ctx => {
70
- return ctx.watch();
71
- });
72
- }
73
-
74
- export function buildWatch(config: BuildOptions) {
75
- return isWatch ? watch(config) : build(config);
76
- }
77
-
78
- export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
79
- return buildWatch({
80
- entryPoints: [input],
81
- outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
82
- platform: "browser",
83
- target: "es2022",
84
- format: format as Format,
85
- globalName,
86
- bundle: true,
87
- minify: isProduction,
88
- external,
89
- plugins: format === "umd" ? [umdWrapper()] : []
90
- });
91
- }
92
-
93
- export function browserBoth(input: string, output: string, globalName?: string, external: string[] = []) {
94
- return Promise.all([
95
- browserTpl(input, output, "esm", globalName, external),
96
- browserTpl(input, output, "umd", globalName, external)
97
- ]);
98
- }
99
-
100
- export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
101
- return buildWatch({
102
- entryPoints: [input],
103
- outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
104
- platform: "node",
105
- target: "node20",
106
- format: format as Format,
107
- bundle: true,
108
- minify: isProduction,
109
- external
110
- });
111
- }
112
-
113
- export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
114
- return buildWatch({
115
- entryPoints: [input],
116
- outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
117
- platform: "neutral",
118
- target: "es2022",
119
- format: format as Format,
120
- globalName,
121
- bundle: true,
122
- minify: isProduction,
123
- external,
124
- plugins: format === "umd" ? [umdWrapper()] : []
125
- });
126
- }
127
-
128
- export function nodeBoth(input: string, output: string, external: string[] = []) {
129
- return Promise.all([
130
- nodeTpl(input, output, "esm", external),
131
- nodeTpl(input, output, "cjs", external)
132
- ]);
133
- }
134
-
135
- export function bothTpl(input: string, output: string, globalName?: string, external: string[] = []) {
136
- return Promise.all([
137
- browserBoth(input, output, globalName, external),
138
- nodeTpl(input, output, "cjs", external)
139
- ]);
140
- }
1
+ import * as process from "process";
2
+ import { readFileSync } from "fs";
3
+ import * as path from "path";
4
+ import * as esbuild from "esbuild";
5
+ import type { BuildOptions, Format } from "esbuild";
6
+ import { umdWrapper } from "esbuild-plugin-umd-wrapper";
7
+ import yargs from "yargs";
8
+ import { hideBin } from "yargs/helpers";
9
+ import { rebuildLogger } from "./rebuild-logger.ts";
10
+ import { sfxWasm } from "./sfx-wrapper.ts";
11
+
12
+ const myYargs = yargs(hideBin(process.argv));
13
+ myYargs
14
+ .usage("Usage: node esbuild.mjs [options]")
15
+ .demandCommand(0, 0)
16
+ .example("node esbuild.mjs --watch", "Bundle and watch for changes")
17
+ .option("mode", {
18
+ alias: "m",
19
+ describe: "Build mode",
20
+ choices: ["development", "production"],
21
+ default: "production"
22
+ })
23
+ .option("w", {
24
+ alias: "watch",
25
+ describe: "Watch for changes",
26
+ type: "boolean"
27
+ })
28
+ .help("h")
29
+ .alias("h", "help")
30
+ .epilog("https://github.com/hpcc-systems/hpcc-js-wasm")
31
+ ;
32
+
33
+ export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
34
+ export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
35
+ export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
36
+
37
+ export const argv = await myYargs.argv;
38
+ export const isDevelopment = argv.mode === "development";
39
+ export const isProduction = !isDevelopment;
40
+ export const isWatch = argv.watch;
41
+
42
+ export function build(config: BuildOptions) {
43
+ if (isDevelopment && Array.isArray(config.entryPoints)) {
44
+ // eslint-disable-next-line no-console
45
+ console.log("Start: ", config.entryPoints[0], config.outfile);
46
+ }
47
+ return esbuild.build({
48
+ sourcemap: "linked",
49
+ ...config,
50
+ plugins: [
51
+ ...(config.plugins ?? []),
52
+ sfxWasm()
53
+ ]
54
+ }).finally(() => {
55
+ if (isDevelopment && Array.isArray(config.entryPoints)) {
56
+ // eslint-disable-next-line no-console
57
+ console.log("Stop: ", config.entryPoints[0], config.outfile);
58
+ }
59
+ });
60
+ }
61
+
62
+ export async function watch(config: BuildOptions) {
63
+ await build(config);
64
+ return esbuild.context({
65
+ sourcemap: "external",
66
+ ...config,
67
+ plugins: [
68
+ ...(config.plugins ?? []),
69
+ rebuildLogger(config),
70
+ sfxWasm()
71
+ ]
72
+ }).then(ctx => {
73
+ return ctx.watch();
74
+ });
75
+ }
76
+
77
+ export function buildWatch(config: BuildOptions) {
78
+ return isWatch ? watch(config) : build(config);
79
+ }
80
+
81
+ export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
82
+ return buildWatch({
83
+ entryPoints: [input],
84
+ outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
85
+ platform: "browser",
86
+ target: "es2022",
87
+ format: format as Format,
88
+ globalName,
89
+ bundle: true,
90
+ minify: isProduction,
91
+ external,
92
+ plugins: format === "umd" ? [umdWrapper({ libraryName: globalName })] : []
93
+ });
94
+ }
95
+
96
+ export function browserBoth(input: string, output: string, globalName?: string, external: string[] = []) {
97
+ return Promise.all([
98
+ browserTpl(input, output, "esm", globalName, external),
99
+ browserTpl(input, output, "umd", globalName, external)
100
+ ]);
101
+ }
102
+
103
+ export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
104
+ return buildWatch({
105
+ entryPoints: [input],
106
+ outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
107
+ platform: "node",
108
+ target: "node20",
109
+ format: format as Format,
110
+ bundle: true,
111
+ minify: isProduction,
112
+ external
113
+ });
114
+ }
115
+
116
+ export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, external: string[] = []) {
117
+ return buildWatch({
118
+ entryPoints: [input],
119
+ outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
120
+ platform: "neutral",
121
+ target: "es2022",
122
+ format: format as Format,
123
+ globalName,
124
+ bundle: true,
125
+ minify: isProduction,
126
+ external,
127
+ plugins: format === "umd" ? [umdWrapper()] : []
128
+ });
129
+ }
130
+
131
+ export function nodeBoth(input: string, output: string, external: string[] = []) {
132
+ return Promise.all([
133
+ nodeTpl(input, output, "esm", external),
134
+ nodeTpl(input, output, "cjs", external)
135
+ ]);
136
+ }
137
+
138
+ export function bothTpl(input: string, output: string, globalName?: string, external: string[] = []) {
139
+ return Promise.all([
140
+ browserBoth(input, output, globalName, external),
141
+ nodeTpl(input, output, "cjs", external)
142
+ ]);
143
+ }
@@ -1,20 +1,20 @@
1
- import { readFile } from "fs/promises";
2
- import type { PluginBuild, Plugin } from "esbuild";
3
-
4
- export interface ExcludeSourcemapOptions {
5
- filter: RegExp;
6
- }
7
- export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
8
- return {
9
- name: "exclude-sourcemap",
10
-
11
- setup(build: PluginBuild) {
12
- build.onLoad({ filter: opts.filter }, async args => {
13
- return {
14
- contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
15
- loader: "default",
16
- };
17
- });
18
- },
19
- };
20
- }
1
+ import { readFile } from "fs/promises";
2
+ import type { PluginBuild, Plugin } from "esbuild";
3
+
4
+ export interface ExcludeSourcemapOptions {
5
+ filter: RegExp;
6
+ }
7
+ export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
8
+ return {
9
+ name: "exclude-sourcemap",
10
+
11
+ setup(build: PluginBuild) {
12
+ build.onLoad({ filter: opts.filter }, async args => {
13
+ return {
14
+ contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
15
+ loader: "default",
16
+ };
17
+ });
18
+ },
19
+ };
20
+ }
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./build.ts";
2
- export * from "./exclude-sourcemap.ts";
3
- export * from "./problem-matcher.ts";
4
- export * from "./rebuild-logger.ts";
5
- export * from "./sfx-wrapper.ts";
1
+ export * from "./build.ts";
2
+ export * from "./exclude-sourcemap.ts";
3
+ export * from "./problem-matcher.ts";
4
+ export * from "./rebuild-logger.ts";
5
+ export * from "./sfx-wrapper.ts";
@@ -1,22 +1,24 @@
1
- import type { PluginBuild, Plugin } from "esbuild";
2
-
3
- export function problemMatcher(): Plugin {
4
- return {
5
- name: "problem-matcher",
6
-
7
- setup(build: PluginBuild) {
8
-
9
- build.onStart(() => {
10
- console.log("[watch] build started");
11
- });
12
-
13
- build.onEnd((result) => {
14
- result.errors.forEach(({ text, location }) => {
15
- console.error(`✘ [ERROR] ${text}`);
16
- console.error(` ${location?.file}:${location?.line}:${location?.column}:`);
17
- });
18
- console.log("[watch] build finished");
19
- });
20
- }
21
- };
22
- }
1
+ import type { PluginBuild, Plugin } from "esbuild";
2
+
3
+ export function problemMatcher(): Plugin {
4
+ return {
5
+ name: "problem-matcher",
6
+
7
+ setup(build: PluginBuild) {
8
+
9
+ build.onStart(() => {
10
+ // eslint-disable-next-line no-console
11
+ console.log("[watch] build started");
12
+ });
13
+
14
+ build.onEnd((result) => {
15
+ result.errors.forEach(({ text, location }) => {
16
+ console.error(`✘ [ERROR] ${text}`);
17
+ console.error(` ${location?.file}:${location?.line}:${location?.column}:`);
18
+ });
19
+ // eslint-disable-next-line no-console
20
+ console.log("[watch] build finished");
21
+ });
22
+ }
23
+ };
24
+ }
@@ -1,22 +1,24 @@
1
- import type { PluginBuild, Plugin } from "esbuild";
2
-
3
- export interface RebuildLoggerOptions {
4
- outfile?: string;
5
- }
6
-
7
- export function rebuildLogger(opts: RebuildLoggerOptions): Plugin {
8
- return {
9
- name: "rebuild-logger",
10
-
11
- setup(build: PluginBuild) {
12
-
13
- build.onStart(() => {
14
- console.log("[watch] build started");
15
- });
16
-
17
- build.onEnd(() => {
18
- console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
19
- });
20
- }
21
- };
22
- }
1
+ import type { PluginBuild, Plugin } from "esbuild";
2
+
3
+ export interface RebuildLoggerOptions {
4
+ outfile?: string;
5
+ }
6
+
7
+ export function rebuildLogger(opts: RebuildLoggerOptions): Plugin {
8
+ return {
9
+ name: "rebuild-logger",
10
+
11
+ setup(build: PluginBuild) {
12
+
13
+ build.onStart(() => {
14
+ // eslint-disable-next-line no-console
15
+ console.log("[watch] build started");
16
+ });
17
+
18
+ build.onEnd(() => {
19
+ // eslint-disable-next-line no-console
20
+ console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
21
+ });
22
+ }
23
+ };
24
+ }
@@ -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;