@hpcc-js/esbuild-plugins 1.1.1 → 1.1.2
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 +7 -7
- package/dist/index.js.map +3 -3
- package/package.json +3 -4
- package/src/build.ts +4 -30
- package/types/build.d.ts +2 -13
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
${
|
|
1
|
+
import*as u from"process";import{readFileSync as S}from"fs";import*as g from"path";import*as f from"esbuild";import{umdWrapper as x}from"esbuild-plugin-umd-wrapper";function m(r){return{name:"rebuild-logger",setup(n){n.onStart(()=>{console.log("[watch] build started")}),n.onEnd(()=>{console.log(`Rebuilt ${r.outfile??"Unknown"}`)})}}}import{readFile as y}from"fs/promises";import{existsSync as P}from"fs";import{Base91 as h}from"@hpcc-js/wasm-base91";import{Zstd as B}from"@hpcc-js/wasm-zstd";function $(r,n,t){let e=t.length+8192<=n.length,o=P(r);return`${e?'import { decompress } from "fzstd";':""}
|
|
2
|
+
${o?`import wrapper from "${r}";`:""}
|
|
3
3
|
|
|
4
4
|
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
|
|
5
5
|
|
|
@@ -37,15 +37,15 @@ function decode(raw: string): Uint8Array {
|
|
|
37
37
|
return new Uint8Array(ret);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
const blobStr = '${
|
|
40
|
+
const blobStr = '${e?t:n}';
|
|
41
41
|
|
|
42
42
|
let g_module: Uint8Array | undefined;
|
|
43
43
|
let g_wasmBinary: Uint8Array | undefined;
|
|
44
44
|
export default function() {
|
|
45
45
|
if (!g_wasmBinary) {
|
|
46
|
-
g_wasmBinary = ${
|
|
46
|
+
g_wasmBinary = ${e?"decompress(decode(blobStr))":"decode(blobStr)"};
|
|
47
47
|
}
|
|
48
|
-
${
|
|
48
|
+
${o?` if (!g_module) {
|
|
49
49
|
g_module = wrapper({
|
|
50
50
|
wasmBinary: g_wasmBinary,
|
|
51
51
|
locateFile: undefined
|
|
@@ -60,6 +60,6 @@ export function reset() {
|
|
|
60
60
|
if (g_module) {
|
|
61
61
|
g_module = undefined;
|
|
62
62
|
}
|
|
63
|
-
} `.trim()}async function
|
|
64
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function
|
|
63
|
+
} `.trim()}async function j(r){let n=await h.load(),t=await B.load(),e=await y(r);r=r.replace(/\.js$/,".xxx");let o=r.replace(/\.wasm$/,".js"),i=n.encode(e),p=t.compress(e),s=n.encode(p);return $(o,i,s)}function c(){return{name:"sfx-wasm",setup(r){r.onLoad({filter:/\.wasm$/},async n=>({contents:await j(n.path),loader:"ts"}))}}}var b=JSON.parse(S(g.join(u.cwd(),"./package.json"),"utf8")),v=b.type==="module"?"js":"mjs",E=b.type==="module"?"cjs":"js";async function a(r,n="esm",t=[],e,o=u.argv.includes("--development"),i=u.argv.includes("--watch")){let s=await f.context({entryPoints:[r],format:n,bundle:!0,minify:!o,sourcemap:o,external:t,...e,plugins:[...i?[m(e)]:[],...e.plugins??[],c()]});i?await s.watch():(o&&Array.isArray(e.entryPoints)&&console.log("Start: ",e.entryPoints[0],e.outfile),await s.rebuild(),await s.dispose(),o&&Array.isArray(e.entryPoints)&&console.log("Stop: ",e.entryPoints[0],e.outfile))}function d(r,n,t="esm",e,o,i=[]){return a(r,t,i,{outfile:`${n}.${t==="esm"?"js":`${t}.js`}`,platform:"browser",target:"es2022",globalName:e,plugins:t==="umd"?[x({libraryName:o})]:[]})}function l(r,n,t="esm",e=[]){return a(r,t,e,{outfile:`${n}.${t==="esm"?v:E}`,platform:"node",target:"node20",packages:"external"})}function T(r,n,t="esm",e,o,i=[]){return a(r,t,i,{outfile:`${n}.${t==="esm"?"js":"umd.js"}`,platform:"neutral",target:"es2022",globalName:e,plugins:t==="umd"?[x({libraryName:o})]:[]})}function O(r,n,t,e,o=[]){return Promise.all([d(r,n,"esm",t,e,o),d(r,n,"umd",t,e,o)])}function C(r,n,t=[]){return Promise.all([l(r,n,"esm",t),l(r,n,"cjs",t)])}function M(r,n,t,e,o=[]){return Promise.all([O(r,n,t,e,o),l(r,n,"cjs",o)])}import{readFile as _}from"fs/promises";function Y(r){return{name:"exclude-sourcemap",setup(n){n.onLoad({filter:r.filter},async t=>({contents:await _(t.path,"utf8")+`
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function N(){return{name:"problem-matcher",setup(r){r.onStart(()=>{console.log("[watch] build started")}),r.onEnd(n=>{n.errors.forEach(({text:t,location:e})=>{console.error(`\u2718 [ERROR] ${t}`),console.error(` ${e?.file}:${e?.line}:${e?.column}:`)}),console.log("[watch] build finished")})}}}import{writeFileSync as w}from"node:fs";function G(){return{name:"remove-strict",setup(r){r.initialOptions.write=!1,r.onEnd(n=>{n?.outputFiles?.forEach(t=>{if(t.path.endsWith(".js")){let e=t.text.replace(/"use strict";/g,"");e.indexOf("use strict")>=0&&console.error("remove-strict: ",t.path),w(t.path,e,{encoding:"utf8"})}else w(t.path,t.contents,{encoding:"binary"})})})}}}export{E as NODE_CJS,v as NODE_MJS,M as bothTpl,O as browserBoth,d as browserTpl,a as buildWatch,Y as excludeSourcemap,T as neutralTpl,C as nodeBoth,l as nodeTpl,b as pkg,N as problemMatcher,m as rebuildLogger,G as removeStrict,c as sfxWasm,j 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", "../src/remove-strict.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 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 ;\n\nexport const pkg = JSON.parse(readFileSync(path.join(process.cwd(), \"./package.json\"), \"utf8\"));\nexport const NODE_MJS = pkg.type === \"module\" ? \"js\" : \"mjs\";\nexport const NODE_CJS = pkg.type === \"module\" ? \"cjs\" : \"js\";\n\nexport const argv = await myYargs.argv;\nexport const isDevelopment = argv.mode === \"development\";\nexport const isProduction = !isDevelopment;\nexport const isWatch = argv.watch;\n\nasync function buildWatch(input: string, format: Format | \"umd\" = \"esm\", external: string[] = [], config: BuildOptions): Promise<void> {\n\n const ctx = await esbuild.context({\n entryPoints: [input],\n format: format as Format,\n bundle: true,\n minify: isProduction,\n sourcemap: isDevelopment,\n external,\n ...config,\n plugins: [\n ...(isWatch ? [rebuildLogger(config)] : []),\n ...(config.plugins ?? []),\n sfxWasm()\n ]\n });\n\n if (isWatch) {\n await ctx.watch();\n } else {\n if (isDevelopment && Array.isArray(config.entryPoints)) {\n // eslint-disable-next-line no-console\n console.log(\"Start: \", config.entryPoints[0], config.outfile);\n }\n await ctx.rebuild();\n await ctx.dispose();\n if (isDevelopment && Array.isArray(config.entryPoints)) {\n // eslint-disable-next-line no-console\n console.log(\"Stop: \", config.entryPoints[0], config.outfile);\n }\n }\n}\n\nexport function browserTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, libraryName?: string, external: string[] = []) {\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? \"js\" : `${format}.js`}`,\n platform: \"browser\",\n target: \"es2022\",\n globalName,\n plugins: format === \"umd\" ? [umdWrapper({ libraryName })] : []\n });\n}\n\nexport function nodeTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", external: string[] = []) {\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? NODE_MJS : NODE_CJS}`,\n platform: \"node\",\n target: \"node20\"\n });\n}\n\nexport function neutralTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, libraryName?: string, external: string[] = []) {\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? \"js\" : \"umd.js\"}`,\n platform: \"neutral\",\n target: \"es2022\",\n globalName,\n plugins: format === \"umd\" ? [umdWrapper({ libraryName })] : []\n });\n}\n\nexport function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {\n return Promise.all([\n browserTpl(input, output, \"esm\", globalName, libraryName, external),\n browserTpl(input, output, \"umd\", globalName, libraryName, external)\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, libraryName?: string, external: string[] = []) {\n return Promise.all([\n browserBoth(input, output, globalName, libraryName, 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 // eslint-disable-next-line no-console\n console.log(\"[watch] build started\");\n });\n\n build.onEnd(() => {\n // eslint-disable-next-line no-console\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 // eslint-disable-next-line no-console\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 // eslint-disable-next-line no-console\n console.log(\"[watch] build finished\");\n });\n }\n };\n}\n", "import { writeFileSync } from \"node:fs\";\nimport type { PluginBuild, Plugin } from \"esbuild\";\n\nexport function removeStrict(): Plugin {\n return {\n name: \"remove-strict\",\n setup(build: PluginBuild) {\n build.initialOptions.write = false;\n build.onEnd((result) => {\n result?.outputFiles?.forEach(file => {\n if (file.path.endsWith(\".js\")) {\n const contents = file.text.replace(/\"use strict\";/g, \"\");\n if (contents.indexOf(\"use strict\") >= 0) {\n console.error(\"remove-strict: \", file.path);\n }\n writeFileSync(file.path, contents, { encoding: \"utf8\" });\n } else {\n writeFileSync(file.path, file.contents, { encoding: \"binary\" });\n }\n });\n });\n }\n };\n}\n"],
|
|
5
|
-
"mappings": "AAAA,UAAYA,MAAa,UACzB,OAAS,gBAAAC,MAAoB,KAC7B,UAAYC,MAAU,OACtB,UAAYC,MAAa,UAEzB,OAAS,cAAAC,MAAkB,
|
|
6
|
-
"names": ["process", "readFileSync", "path", "esbuild", "umdWrapper", "
|
|
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 { rebuildLogger } from \"./rebuild-logger.ts\";\nimport { sfxWasm } from \"./sfx-wrapper.ts\";\n\nexport const pkg = JSON.parse(readFileSync(path.join(process.cwd(), \"./package.json\"), \"utf8\"));\nexport const NODE_MJS = pkg.type === \"module\" ? \"js\" : \"mjs\";\nexport const NODE_CJS = pkg.type === \"module\" ? \"cjs\" : \"js\";\n\nexport async function buildWatch(input: string, format: Format | \"umd\" = \"esm\", external: string[] = [], config: BuildOptions, isDevelopment: boolean = process.argv.includes(\"--development\"), isWatch: boolean = process.argv.includes(\"--watch\")): Promise<void> {\n const isProduction = !isDevelopment;\n\n const ctx = await esbuild.context({\n entryPoints: [input],\n format: format as Format,\n bundle: true,\n minify: isProduction,\n sourcemap: isDevelopment,\n external,\n ...config,\n plugins: [\n ...(isWatch ? [rebuildLogger(config)] : []),\n ...(config.plugins ?? []),\n sfxWasm()\n ]\n });\n\n if (isWatch) {\n await ctx.watch();\n } else {\n if (isDevelopment && Array.isArray(config.entryPoints)) {\n // eslint-disable-next-line no-console\n console.log(\"Start: \", config.entryPoints[0], config.outfile);\n }\n await ctx.rebuild();\n await ctx.dispose();\n if (isDevelopment && Array.isArray(config.entryPoints)) {\n // eslint-disable-next-line no-console\n console.log(\"Stop: \", config.entryPoints[0], config.outfile);\n }\n }\n}\n\nexport function browserTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, libraryName?: string, external: string[] = []) {\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? \"js\" : `${format}.js`}`,\n platform: \"browser\",\n target: \"es2022\",\n globalName,\n plugins: format === \"umd\" ? [umdWrapper({ libraryName })] : []\n });\n}\n\nexport function nodeTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", external: string[] = []) {\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? NODE_MJS : NODE_CJS}`,\n platform: \"node\",\n target: \"node20\",\n packages: \"external\"\n });\n}\n\nexport function neutralTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, libraryName?: string, external: string[] = []) {\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? \"js\" : \"umd.js\"}`,\n platform: \"neutral\",\n target: \"es2022\",\n globalName,\n plugins: format === \"umd\" ? [umdWrapper({ libraryName })] : []\n });\n}\n\nexport function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {\n return Promise.all([\n browserTpl(input, output, \"esm\", globalName, libraryName, external),\n browserTpl(input, output, \"umd\", globalName, libraryName, external)\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, libraryName?: string, external: string[] = []) {\n return Promise.all([\n browserBoth(input, output, globalName, libraryName, 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 // eslint-disable-next-line no-console\n console.log(\"[watch] build started\");\n });\n\n build.onEnd(() => {\n // eslint-disable-next-line no-console\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 // eslint-disable-next-line no-console\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 // eslint-disable-next-line no-console\n console.log(\"[watch] build finished\");\n });\n }\n };\n}\n", "import { writeFileSync } from \"node:fs\";\nimport type { PluginBuild, Plugin } from \"esbuild\";\n\nexport function removeStrict(): Plugin {\n return {\n name: \"remove-strict\",\n setup(build: PluginBuild) {\n build.initialOptions.write = false;\n build.onEnd((result) => {\n result?.outputFiles?.forEach(file => {\n if (file.path.endsWith(\".js\")) {\n const contents = file.text.replace(/\"use strict\";/g, \"\");\n if (contents.indexOf(\"use strict\") >= 0) {\n console.error(\"remove-strict: \", file.path);\n }\n writeFileSync(file.path, contents, { encoding: \"utf8\" });\n } else {\n writeFileSync(file.path, file.contents, { encoding: \"binary\" });\n }\n });\n });\n }\n };\n}\n"],
|
|
5
|
+
"mappings": "AAAA,UAAYA,MAAa,UACzB,OAAS,gBAAAC,MAAoB,KAC7B,UAAYC,MAAU,OACtB,UAAYC,MAAa,UAEzB,OAAS,cAAAC,MAAkB,6BCCpB,SAASC,EAAcC,EAAoC,CAC9D,MAAO,CACH,KAAM,iBAEN,MAAMC,EAAoB,CAEtBA,EAAM,QAAQ,IAAM,CAEhB,QAAQ,IAAI,uBAAuB,CACvC,CAAC,EAEDA,EAAM,MAAM,IAAM,CAEd,QAAQ,IAAI,WAAWD,EAAK,SAAW,SAAS,EAAE,CACtD,CAAC,CACL,CACJ,CACJ,CCvBA,OAAS,YAAAE,MAAgB,cACzB,OAAS,c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
|
+
"names": ["process", "readFileSync", "path", "esbuild", "umdWrapper", "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", "buildWatch", "input", "format", "external", "config", "isDevelopment", "isWatch", "ctx", "rebuildLogger", "sfxWasm", "browserTpl", "output", "globalName", "libraryName", "umdWrapper", "nodeTpl", "neutralTpl", "browserBoth", "nodeBoth", "bothTpl", "readFile", "excludeSourcemap", "opts", "build", "args", "problemMatcher", "build", "result", "text", "location", "writeFileSync", "removeStrict", "build", "result", "file", "contents"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/esbuild-plugins",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.2",
|
|
4
4
|
"description": "Various esbuild plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -42,8 +42,7 @@
|
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"@hpcc-js/wasm-base91": "1.0.1",
|
|
44
44
|
"@hpcc-js/wasm-zstd": "1.0.1",
|
|
45
|
-
"fzstd": "0.1.1"
|
|
46
|
-
"yargs": "17.7.2"
|
|
45
|
+
"fzstd": "0.1.1"
|
|
47
46
|
},
|
|
48
47
|
"keywords": [
|
|
49
48
|
"esbuild",
|
|
@@ -59,5 +58,5 @@
|
|
|
59
58
|
},
|
|
60
59
|
"homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
|
|
61
60
|
"license": "Apache-2.0",
|
|
62
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "e37d3419db2076640ae9374b8241d62133255235"
|
|
63
62
|
}
|
package/src/build.ts
CHANGED
|
@@ -4,42 +4,15 @@ import * as path from "path";
|
|
|
4
4
|
import * as esbuild from "esbuild";
|
|
5
5
|
import type { BuildOptions, Format } from "esbuild";
|
|
6
6
|
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
7
|
-
import yargs from "yargs";
|
|
8
|
-
import { hideBin } from "yargs/helpers";
|
|
9
7
|
import { rebuildLogger } from "./rebuild-logger.ts";
|
|
10
8
|
import { sfxWasm } from "./sfx-wrapper.ts";
|
|
11
9
|
|
|
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
10
|
export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
|
|
34
11
|
export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
|
|
35
12
|
export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
|
|
36
13
|
|
|
37
|
-
export
|
|
38
|
-
|
|
39
|
-
export const isProduction = !isDevelopment;
|
|
40
|
-
export const isWatch = argv.watch;
|
|
41
|
-
|
|
42
|
-
async function buildWatch(input: string, format: Format | "umd" = "esm", external: string[] = [], config: BuildOptions): Promise<void> {
|
|
14
|
+
export async function buildWatch(input: string, format: Format | "umd" = "esm", external: string[] = [], config: BuildOptions, isDevelopment: boolean = process.argv.includes("--development"), isWatch: boolean = process.argv.includes("--watch")): Promise<void> {
|
|
15
|
+
const isProduction = !isDevelopment;
|
|
43
16
|
|
|
44
17
|
const ctx = await esbuild.context({
|
|
45
18
|
entryPoints: [input],
|
|
@@ -86,7 +59,8 @@ export function nodeTpl(input: string, output: string, format: Format | "umd" =
|
|
|
86
59
|
return buildWatch(input, format, external, {
|
|
87
60
|
outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
|
|
88
61
|
platform: "node",
|
|
89
|
-
target: "node20"
|
|
62
|
+
target: "node20",
|
|
63
|
+
packages: "external"
|
|
90
64
|
});
|
|
91
65
|
}
|
|
92
66
|
|
package/types/build.d.ts
CHANGED
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import type { Format } from "esbuild";
|
|
1
|
+
import type { BuildOptions, Format } from "esbuild";
|
|
2
2
|
export declare const pkg: any;
|
|
3
3
|
export declare const NODE_MJS: string;
|
|
4
4
|
export declare const NODE_CJS: string;
|
|
5
|
-
export declare
|
|
6
|
-
[x: string]: unknown;
|
|
7
|
-
_: (string | number)[];
|
|
8
|
-
$0: string;
|
|
9
|
-
} | {
|
|
10
|
-
[x: string]: unknown;
|
|
11
|
-
_: (string | number)[];
|
|
12
|
-
$0: string;
|
|
13
|
-
};
|
|
14
|
-
export declare const isDevelopment: boolean;
|
|
15
|
-
export declare const isProduction: boolean;
|
|
16
|
-
export declare const isWatch: unknown;
|
|
5
|
+
export declare function buildWatch(input: string, format: (Format | "umd") | undefined, external: string[] | undefined, config: BuildOptions, isDevelopment?: boolean, isWatch?: boolean): Promise<void>;
|
|
17
6
|
export declare function browserTpl(input: string, output: string, format?: Format | "umd", globalName?: string, libraryName?: string, external?: string[]): Promise<void>;
|
|
18
7
|
export declare function nodeTpl(input: string, output: string, format?: Format | "umd", external?: string[]): Promise<void>;
|
|
19
8
|
export declare function neutralTpl(input: string, output: string, format?: Format | "umd", globalName?: string, libraryName?: string, external?: string[]): Promise<void>;
|