@hpcc-js/esbuild-plugins 1.2.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,16 @@
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}";`:""}
1
+ import*as a from"process";import{readFileSync as x,existsSync as F,writeFileSync as k}from"fs";import*as l from"path";import*as b from"esbuild";import{umdWrapper as y}from"esbuild-plugin-umd-wrapper";import B from"path";import O from"crypto";import{readFile as _}from"fs/promises";function g(e={}){return{name:"inline-css",setup(o){o.onLoad({filter:/\.(css)$/},async t=>{if(o.initialOptions.platform==="browser"){let r=B.resolve(t.path);return{contents:await E(r),loader:"js"}}})}}}async function E(e){let o=v(e),t=await _(e,"utf8");return`(function(){
2
+ if (!document.getElementById('${o}')) {
3
+ var e = document.createElement('style');
4
+ e.id = '${o}';
5
+ e.textContent = \`${t.split("\\25").join("\\x15")}\`;
6
+ document.head.appendChild(e);
7
+ }
8
+ })();`}function v(e){return O.createHash("sha256").update(e).digest("hex").slice(0,8)}function f(e){return{name:"rebuild-logger",setup(o){o.onStart(()=>{console.log("[watch] build started")}),o.onEnd(()=>{console.log(`Rebuilt ${e.outfile??"Unknown"}`)})}}}import L from"esbuild-copy-static-files";var Q=L,p=JSON.parse(x(l.join(a.cwd(),"./package.json"),"utf8")),w=p.type==="module"?"js":"mjs",j=p.type==="module"?"cjs":"js";async function d(e,o="esm",t=[],r,n=a.argv.includes("--development"),i=a.argv.includes("--watch")){let c=!n;if(c&&F(l.join(a.cwd(),"../../package.json"))){let m=JSON.parse(x(l.join(a.cwd(),"../../package.json"),"utf8"));k(l.join(a.cwd(),"src/__package__.ts"),`export const PKG_NAME = "${p.name}";
9
+ export const PKG_VERSION = "${p.version}";
10
+ export const BUILD_VERSION = "${m.version}";
11
+ `,"utf8")}let s=await b.context({entryPoints:[e],format:o,bundle:!0,minify:c,sourcemap:!0,external:t,...r,plugins:[...i?[f(r)]:[],...r.plugins??[],g()]});i?await s.watch():(n&&Array.isArray(r.entryPoints)&&console.log("Start: ",r.entryPoints[0],r.outfile),await s.rebuild(),await s.dispose(),n&&Array.isArray(r.entryPoints)&&console.log("Stop: ",r.entryPoints[0],r.outfile))}function h(e,o,{format:t="esm",globalName:r,libraryName:n,keepNames:i,external:c=[],plugins:s=[],alias:m={},define:S={},loader:$={}}={}){return d(e,t,c,{outfile:`${o}.${t==="esm"?"js":`${t}.js`}`,platform:"browser",target:"es2022",globalName:r,keepNames:i,plugins:t==="umd"?[y({libraryName:n}),...s]:[...s],alias:m,define:S,loader:$})}function u(e,o,{format:t="esm",external:r=[],supported:n={}}={}){return d(e,t,r,{outfile:`${o}.${t==="esm"?w:j}`,platform:"node",target:"node20",packages:"external",supported:n})}function q(e,o,{format:t="esm",globalName:r,libraryName:n,keepNames:i,external:c=[]}={}){let s="";switch(t){case"iife":s="iife.js";break;case"esm":s=w;break;case"cjs":s=j;break;case"umd":s="umd.js";break;default:throw new Error(`Unknown format: ${t}`)}return d(e,t,c,{outfile:`${o}.${t==="esm"?"js":`${t}.js`}`,platform:"neutral",target:"es2022",globalName:r,keepNames:i,plugins:t==="umd"?[y({libraryName:n})]:[]})}function J(e,o,t,r,n=[]){return Promise.all([h(e,o,{format:"esm",globalName:t,libraryName:r,external:n}),h(e,o,{format:"umd",globalName:t,libraryName:r,external:n})])}function ee(e,o,t=[]){return Promise.all([u(e,o,{format:"esm",external:t}),u(e,o,{format:"cjs",external:t})])}function te(e,o,t,r,n=[]){return Promise.all([J(e,o,t,r,n),u(e,o,{format:"cjs",external:n})])}import{readFile as R}from"fs/promises";function ne(e){return{name:"exclude-sourcemap",setup(o){o.onLoad({filter:e.filter},async t=>({contents:await R(t.path,"utf8")+`
12
+ //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function ie(){return{name:"problem-matcher",setup(e){e.onStart(()=>{console.log("[watch] build started")}),e.onEnd(o=>{o.errors.forEach(({text:t,location:r})=>{console.error(`\u2718 [ERROR] ${t}`),console.error(` ${r?.file}:${r?.line}:${r?.column}:`)}),console.log("[watch] build finished")})}}}import{writeFileSync as P}from"node:fs";function le(){return{name:"remove-strict",setup(e){e.initialOptions.write=!1,e.onEnd(o=>{o?.outputFiles?.forEach(t=>{if(t.path.endsWith(".js")){let r=t.text.replace(/"use strict";/g,"");P(t.path,r,{encoding:"utf8"})}else P(t.path,t.contents,{encoding:"binary"})})})}}}import{readFile as I}from"fs/promises";import{existsSync as A}from"fs";import{Base91 as C}from"@hpcc-js/wasm-base91";import{Zstd as N}from"@hpcc-js/wasm-zstd";function T(e,o,t){let r=t.length+8192<=o.length,n=A(e);return`${r?'import { decompress } from "fzstd";':""}
13
+ ${n?`import wrapper from "${e}";`:""}
3
14
 
4
15
  const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
5
16
 
@@ -37,15 +48,15 @@ function decode(raw: string): Uint8Array {
37
48
  return new Uint8Array(ret);
38
49
  }
39
50
 
40
- const blobStr = '${e?t:n}';
51
+ const blobStr = '${r?t:o}';
41
52
 
42
53
  let g_module: Uint8Array | undefined;
43
54
  let g_wasmBinary: Uint8Array | undefined;
44
55
  export default function() {
45
56
  if (!g_wasmBinary) {
46
- g_wasmBinary = ${e?"decompress(decode(blobStr))":"decode(blobStr)"};
57
+ g_wasmBinary = ${r?"decompress(decode(blobStr))":"decode(blobStr)"};
47
58
  }
48
- ${o?` if (!g_module) {
59
+ ${n?` if (!g_module) {
49
60
  g_module = wrapper({
50
61
  wasmBinary: g_wasmBinary,
51
62
  locateFile: undefined
@@ -60,6 +71,5 @@ export function reset() {
60
71
  if (g_module) {
61
72
  g_module = undefined;
62
73
  }
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};
74
+ } `.trim()}async function U(e){let o=await C.load(),t=await N.load(),r=await I(e);e=e.replace(/\.js$/,".xxx");let n=e.replace(/\.wasm$/,".js"),i=o.encode(r),c=t.compress(r),s=o.encode(c);return T(n,i,s)}function fe(){return{name:"sfx-wasm",setup(e){e.onLoad({filter:/\.wasm$/},async o=>({contents:await U(o.path),loader:"ts"}))}}}var z={"d3-array":"@hpcc-js/common","d3-brush":"@hpcc-js/common","d3-collection":"@hpcc-js/common","d3-color":"@hpcc-js/common","d3-dispatch":"@hpcc-js/common","d3-drag":"@hpcc-js/common","d3-dsv":"@hpcc-js/common","d3-ease":"@hpcc-js/common","d3-format":"@hpcc-js/common","d3-interpolate":"@hpcc-js/common","d3-scale":"@hpcc-js/common","d3-selection":"@hpcc-js/common","d3-time-format":"@hpcc-js/common","d3-transition":"@hpcc-js/common","d3-zoom":"@hpcc-js/common"};function xe(e){let o=[],t={};for(let r in e.dependencies)o.push(r),t[r]=r;for(let r in e.peerDependencies??{})o.push(r),t[r]=r;return{alias:e.name!=="@hpcc-js/common"&&e.dependencies["@hpcc-js/common"]?z:{},external:o,globals:t}}export{j as NODE_CJS,w as NODE_MJS,te as bothTpl,J as browserBoth,h as browserTpl,d as buildWatch,Q as copyStaticFiles,ne as excludeSourcemap,xe as hpccBundleNames,g as inlineCSS,q as neutralTpl,ee as nodeBoth,u as nodeTpl,p as pkg,ie as problemMatcher,f as rebuildLogger,le as removeStrict,fe as sfxWasm,U as wrap};
65
75
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 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 { 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,CA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CAC3D,MACIL,EAAcI,EAAK,KAAMA,EAAK,SAAU,CAAE,SAAU,QAAS,CAAC,CAEtE,CAAC,CACL,CAAC,CACL,CACJ,CACJ",
6
- "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"]
3
+ "sources": ["../src/build.ts", "../src/inline-css.ts", "../src/rebuild-logger.ts", "../src/exclude-sourcemap.ts", "../src/problem-matcher.ts", "../src/remove-strict.ts", "../src/sfx-wrapper.ts", "../src/vite-utils.ts"],
4
+ "sourcesContent": ["import * as process from \"process\";\nimport { readFileSync, existsSync, writeFileSync } from \"fs\";\nimport * as path from \"path\";\nimport * as esbuild from \"esbuild\";\nimport type { BuildOptions, Format, Loader, Plugin } from \"esbuild\";\nimport { umdWrapper } from \"esbuild-plugin-umd-wrapper\";\nimport { inlineCSS } from \"./inline-css.ts\";\nimport { rebuildLogger } from \"./rebuild-logger.ts\";\n\n//@ts-ignore\nimport _copyStaticFiles from \"esbuild-copy-static-files\";\nexport const copyStaticFiles: Plugin = _copyStaticFiles;\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 if (isProduction && existsSync(path.join(process.cwd(), \"../../package.json\"))) {\n const rootPkg = JSON.parse(readFileSync(path.join(process.cwd(), \"../../package.json\"), \"utf8\"));\n writeFileSync(path.join(process.cwd(), \"src/__package__.ts\"), `\\\nexport const PKG_NAME = \"${pkg.name}\";\nexport const PKG_VERSION = \"${pkg.version}\";\nexport const BUILD_VERSION = \"${rootPkg.version}\";\n`, \"utf8\");\n }\n\n const ctx = await esbuild.context({\n entryPoints: [input],\n format: format as Format,\n bundle: true,\n minify: isProduction,\n sourcemap: true,\n external,\n ...config,\n plugins: [\n ...(isWatch ? [rebuildLogger(config)] : []),\n ...(config.plugins ?? []),\n inlineCSS()\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 type TplOptions = {\n format?: Format | \"umd\";\n globalName?: string;\n libraryName?: string;\n keepNames?: boolean;\n external?: string[];\n plugins?: Plugin[];\n loader?: { [ext: string]: Loader };\n supported?: Record<string, boolean>;\n alias?: Record<string, string>;\n define?: { [key: string]: string };\n};\n\nexport function browserTpl(input: string, output: string, { format = \"esm\", globalName, libraryName, keepNames, external = [], plugins = [], alias = {}, define = {}, loader = {} }: TplOptions = {}) {\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? \"js\" : `${format}.js`}`,\n platform: \"browser\",\n target: \"es2022\",\n globalName,\n keepNames,\n plugins: format === \"umd\" ? [umdWrapper({ libraryName }), ...plugins] : [...plugins],\n alias,\n define,\n loader\n } as BuildOptions);\n}\n\nexport function nodeTpl(input: string, output: string, { format = \"esm\", external = [], supported = {} }: TplOptions = {}) {\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 supported\n });\n}\n\nexport function neutralTpl(input: string, output: string, { format = \"esm\", globalName, libraryName, keepNames, external = [] }: TplOptions = {}) {\n let postfix = \"\";\n switch (format) {\n case \"iife\":\n postfix = \"iife.js\";\n break;\n case \"esm\":\n postfix = NODE_MJS;\n break;\n case \"cjs\":\n postfix = NODE_CJS;\n break;\n case \"umd\":\n postfix = \"umd.js\";\n break;\n default:\n throw new Error(`Unknown format: ${format}`);\n }\n return buildWatch(input, format, external, {\n outfile: `${output}.${format === \"esm\" ? \"js\" : `${format}.js`}`,\n platform: \"neutral\",\n target: \"es2022\",\n globalName,\n keepNames,\n plugins: format === \"umd\" ? [umdWrapper({ libraryName })] : []\n } as BuildOptions);\n}\n\nexport function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {\n return Promise.all([\n browserTpl(input, output, { format: \"esm\", globalName, libraryName, external }),\n browserTpl(input, output, { format: \"umd\", globalName, libraryName, external })\n ]);\n}\n\nexport function nodeBoth(input: string, output: string, external: string[] = []) {\n return Promise.all([\n nodeTpl(input, output, { format: \"esm\", external }),\n nodeTpl(input, output, { format: \"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, { format: \"cjs\", external })\n ]);\n}\n", "import type { PluginBuild, Plugin } from \"esbuild\";\nimport path from \"path\";\nimport crypto from \"crypto\";\nimport { readFile } from \"fs/promises\";\n\nexport function inlineCSS(options = {}) {\n return {\n name: \"inline-css\",\n\n setup(build: PluginBuild) {\n\n build.onLoad({ filter: /\\.(css)$/ }, async (args) => {\n if (build.initialOptions.platform === \"browser\") {\n const sourcePath = path.resolve(args.path);\n const sourceJS = await generateInjectCSS(sourcePath);\n return {\n contents: sourceJS,\n loader: \"js\"\n };\n }\n });\n },\n };\n}\n\nasync function generateInjectCSS(sourcePath: string) {\n const styleID = sha256(sourcePath);\n const sourceCSS = await readFile(sourcePath, \"utf8\");\n\n return `(function(){\n if (!document.getElementById('${styleID}')) {\n var e = document.createElement('style');\n e.id = '${styleID}';\n e.textContent = \\`${sourceCSS.split(\"\\\\25\").join(\"\\\\x15\")}\\`;\n document.head.appendChild(e);\n }\n })();`;\n}\n\nfunction sha256(sourcePath: string) {\n const hash = crypto.createHash(\"sha256\").update(sourcePath).digest(\"hex\");\n return hash.slice(0, 8); // Use the first 8 characters of the hash\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 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 writeFileSync(file.path, contents, { encoding: \"utf8\" });\n } else {\n writeFileSync(file.path, file.contents, { encoding: \"binary\" });\n }\n });\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", "const alias = {\n \"d3-array\": \"@hpcc-js/common\",\n \"d3-brush\": \"@hpcc-js/common\",\n \"d3-collection\": \"@hpcc-js/common\",\n \"d3-color\": \"@hpcc-js/common\",\n \"d3-dispatch\": \"@hpcc-js/common\",\n \"d3-drag\": \"@hpcc-js/common\",\n \"d3-dsv\": \"@hpcc-js/common\",\n \"d3-ease\": \"@hpcc-js/common\",\n \"d3-format\": \"@hpcc-js/common\",\n \"d3-interpolate\": \"@hpcc-js/common\",\n \"d3-scale\": \"@hpcc-js/common\",\n \"d3-selection\": \"@hpcc-js/common\",\n \"d3-time-format\": \"@hpcc-js/common\",\n \"d3-transition\": \"@hpcc-js/common\",\n \"d3-zoom\": \"@hpcc-js/common\"\n};\n\nexport function hpccBundleNames(pkg: any) {\n const external: string[] = [];\n const globals: { [id: string]: string } = {};\n for (const dep in pkg.dependencies) {\n external.push(dep);\n globals[dep] = dep;\n }\n for (const dep in pkg.peerDependencies ?? {}) {\n external.push(dep);\n globals[dep] = dep;\n }\n return { alias: (pkg.name !== \"@hpcc-js/common\" && pkg.dependencies[\"@hpcc-js/common\"]) ? alias : {}, external, globals };\n}"],
5
+ "mappings": "AAAA,UAAYA,MAAa,UACzB,OAAS,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,KACxD,UAAYC,MAAU,OACtB,UAAYC,MAAa,UAEzB,OAAS,cAAAC,MAAkB,6BCJ3B,OAAOC,MAAU,OACjB,OAAOC,MAAY,SACnB,OAAS,YAAAC,MAAgB,cAElB,SAASC,EAAUC,EAAU,CAAC,EAAG,CACpC,MAAO,CACH,KAAM,aAEN,MAAMC,EAAoB,CAEtBA,EAAM,OAAO,CAAE,OAAQ,UAAW,EAAG,MAAOC,GAAS,CACjD,GAAID,EAAM,eAAe,WAAa,UAAW,CAC7C,IAAME,EAAaP,EAAK,QAAQM,EAAK,IAAI,EAEzC,MAAO,CACH,SAFa,MAAME,EAAkBD,CAAU,EAG/C,OAAQ,IACZ,CACJ,CACJ,CAAC,CACL,CACJ,CACJ,CAEA,eAAeC,EAAkBD,EAAoB,CACjD,IAAME,EAAUC,EAAOH,CAAU,EAC3BI,EAAY,MAAMT,EAASK,EAAY,MAAM,EAEnD,MAAO;AAAA,wCAC6BE,CAAO;AAAA;AAAA,sBAEzBA,CAAO;AAAA,gCACGE,EAAU,MAAM,MAAM,EA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uBK,EAAO,OAAOG,CAAc,EAEzD,OAAOX,EAAIC,EAAYC,EAAYC,CAAoB,CAC3D,CAEO,SAASS,IAAkB,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,CC3GA,IAAMC,EAAQ,CACV,WAAY,kBACZ,WAAY,kBACZ,gBAAiB,kBACjB,WAAY,kBACZ,cAAe,kBACf,UAAW,kBACX,SAAU,kBACV,UAAW,kBACX,YAAa,kBACb,iBAAkB,kBAClB,WAAY,kBACZ,eAAgB,kBAChB,iBAAkB,kBAClB,gBAAiB,kBACjB,UAAW,iBACf,EAEO,SAASC,GAAgBC,EAAU,CACtC,IAAMC,EAAqB,CAAC,EACtBC,EAAoC,CAAC,EAC3C,QAAWC,KAAOH,EAAI,aAClBC,EAAS,KAAKE,CAAG,EACjBD,EAAQC,CAAG,EAAIA,EAEnB,QAAWA,KAAOH,EAAI,kBAAoB,CAAC,EACvCC,EAAS,KAAKE,CAAG,EACjBD,EAAQC,CAAG,EAAIA,EAEnB,MAAO,CAAE,MAAQH,EAAI,OAAS,mBAAqBA,EAAI,aAAa,iBAAiB,EAAKF,EAAQ,CAAC,EAAG,SAAAG,EAAU,QAAAC,CAAQ,CAC5H",
6
+ "names": ["process", "readFileSync", "existsSync", "writeFileSync", "path", "esbuild", "umdWrapper", "path", "crypto", "readFile", "inlineCSS", "options", "build", "args", "sourcePath", "generateInjectCSS", "styleID", "sha256", "sourceCSS", "rebuildLogger", "opts", "build", "_copyStaticFiles", "copyStaticFiles", "pkg", "readFileSync", "NODE_MJS", "NODE_CJS", "buildWatch", "input", "format", "external", "config", "isDevelopment", "isWatch", "isProduction", "existsSync", "rootPkg", "writeFileSync", "ctx", "rebuildLogger", "inlineCSS", "browserTpl", "output", "globalName", "libraryName", "keepNames", "plugins", "alias", "define", "loader", "umdWrapper", "nodeTpl", "supported", "neutralTpl", "postfix", "browserBoth", "nodeBoth", "bothTpl", "readFile", "excludeSourcemap", "opts", "build", "args", "problemMatcher", "build", "result", "text", "location", "writeFileSync", "removeStrict", "build", "result", "file", "contents", "readFile", "existsSync", "Base91", "Zstd", "tpl", "wasmJsPath", "base91Wasm", "base91CompressedWasm", "compressed", "wasmJsExists", "wrap", "path", "base91", "zstd", "wasm", "compressedWasm", "sfxWasm", "build", "args", "alias", "hpccBundleNames", "pkg", "external", "globals", "dep"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hpcc-js/esbuild-plugins",
3
- "version": "1.2.0",
3
+ "version": "1.4.0",
4
4
  "description": "Various esbuild plugins",
5
5
  "type": "module",
6
6
  "exports": {
@@ -34,14 +34,15 @@
34
34
  "lint-skypack": "npx -y @skypack/package-check",
35
35
  "lint-eslint": "eslint src/**/*.ts",
36
36
  "lint": "run-p lint-eslint lint-skypack",
37
- "test-cli": "npx . -v",
38
- "test-cli-help": "npx .",
39
- "test-node": "npx . -v",
40
37
  "update": "npx --yes npm-check-updates -u -t minor"
41
38
  },
42
39
  "dependencies": {
43
- "@hpcc-js/wasm-base91": "1.3.0",
44
- "@hpcc-js/wasm-zstd": "1.2.0",
40
+ "@hpcc-js/wasm-base91": "1.3.1",
41
+ "@hpcc-js/wasm-zstd": "1.2.1",
42
+ "esbuild": "0.24.0",
43
+ "esbuild-copy-static-files": "0.1.0",
44
+ "esbuild-plugin-inline-css": "0.0.1",
45
+ "esbuild-plugin-umd-wrapper": "3.0.0",
45
46
  "fzstd": "0.1.1"
46
47
  },
47
48
  "keywords": [
@@ -58,5 +59,5 @@
58
59
  },
59
60
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
60
61
  "license": "Apache-2.0",
61
- "gitHead": "fbbef050700b0e9d76ef99714856383d95155149"
62
+ "gitHead": "145a4d4c8189c70f08e9804e63959d6dd398bd9f"
62
63
  }
package/src/build.ts CHANGED
@@ -1,11 +1,15 @@
1
1
  import * as process from "process";
2
- import { readFileSync } from "fs";
2
+ import { readFileSync, existsSync, writeFileSync } from "fs";
3
3
  import * as path from "path";
4
4
  import * as esbuild from "esbuild";
5
- import type { BuildOptions, Format } from "esbuild";
5
+ import type { BuildOptions, Format, Loader, Plugin } from "esbuild";
6
6
  import { umdWrapper } from "esbuild-plugin-umd-wrapper";
7
+ import { inlineCSS } from "./inline-css.ts";
7
8
  import { rebuildLogger } from "./rebuild-logger.ts";
8
- import { sfxWasm } from "./sfx-wrapper.ts";
9
+
10
+ //@ts-ignore
11
+ import _copyStaticFiles from "esbuild-copy-static-files";
12
+ export const copyStaticFiles: Plugin = _copyStaticFiles;
9
13
 
10
14
  export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
11
15
  export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
@@ -13,19 +17,27 @@ export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
13
17
 
14
18
  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
19
  const isProduction = !isDevelopment;
20
+ if (isProduction && existsSync(path.join(process.cwd(), "../../package.json"))) {
21
+ const rootPkg = JSON.parse(readFileSync(path.join(process.cwd(), "../../package.json"), "utf8"));
22
+ writeFileSync(path.join(process.cwd(), "src/__package__.ts"), `\
23
+ export const PKG_NAME = "${pkg.name}";
24
+ export const PKG_VERSION = "${pkg.version}";
25
+ export const BUILD_VERSION = "${rootPkg.version}";
26
+ `, "utf8");
27
+ }
16
28
 
17
29
  const ctx = await esbuild.context({
18
30
  entryPoints: [input],
19
31
  format: format as Format,
20
32
  bundle: true,
21
33
  minify: isProduction,
22
- sourcemap: isDevelopment,
34
+ sourcemap: true,
23
35
  external,
24
36
  ...config,
25
37
  plugins: [
26
38
  ...(isWatch ? [rebuildLogger(config)] : []),
27
39
  ...(config.plugins ?? []),
28
- sfxWasm()
40
+ inlineCSS()
29
41
  ]
30
42
  });
31
43
 
@@ -45,52 +57,88 @@ export async function buildWatch(input: string, format: Format | "umd" = "esm",
45
57
  }
46
58
  }
47
59
 
48
- export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
60
+ export type TplOptions = {
61
+ format?: Format | "umd";
62
+ globalName?: string;
63
+ libraryName?: string;
64
+ keepNames?: boolean;
65
+ external?: string[];
66
+ plugins?: Plugin[];
67
+ loader?: { [ext: string]: Loader };
68
+ supported?: Record<string, boolean>;
69
+ alias?: Record<string, string>;
70
+ define?: { [key: string]: string };
71
+ };
72
+
73
+ export function browserTpl(input: string, output: string, { format = "esm", globalName, libraryName, keepNames, external = [], plugins = [], alias = {}, define = {}, loader = {} }: TplOptions = {}) {
49
74
  return buildWatch(input, format, external, {
50
75
  outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
51
76
  platform: "browser",
52
77
  target: "es2022",
53
78
  globalName,
54
- plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
55
- });
79
+ keepNames,
80
+ plugins: format === "umd" ? [umdWrapper({ libraryName }), ...plugins] : [...plugins],
81
+ alias,
82
+ define,
83
+ loader
84
+ } as BuildOptions);
56
85
  }
57
86
 
58
- export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
87
+ export function nodeTpl(input: string, output: string, { format = "esm", external = [], supported = {} }: TplOptions = {}) {
59
88
  return buildWatch(input, format, external, {
60
89
  outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
61
90
  platform: "node",
62
91
  target: "node20",
63
- packages: "external"
92
+ packages: "external",
93
+ supported
64
94
  });
65
95
  }
66
96
 
67
- export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
97
+ export function neutralTpl(input: string, output: string, { format = "esm", globalName, libraryName, keepNames, external = [] }: TplOptions = {}) {
98
+ let postfix = "";
99
+ switch (format) {
100
+ case "iife":
101
+ postfix = "iife.js";
102
+ break;
103
+ case "esm":
104
+ postfix = NODE_MJS;
105
+ break;
106
+ case "cjs":
107
+ postfix = NODE_CJS;
108
+ break;
109
+ case "umd":
110
+ postfix = "umd.js";
111
+ break;
112
+ default:
113
+ throw new Error(`Unknown format: ${format}`);
114
+ }
68
115
  return buildWatch(input, format, external, {
69
- outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
116
+ outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
70
117
  platform: "neutral",
71
118
  target: "es2022",
72
119
  globalName,
120
+ keepNames,
73
121
  plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
74
- });
122
+ } as BuildOptions);
75
123
  }
76
124
 
77
125
  export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
78
126
  return Promise.all([
79
- browserTpl(input, output, "esm", globalName, libraryName, external),
80
- browserTpl(input, output, "umd", globalName, libraryName, external)
127
+ browserTpl(input, output, { format: "esm", globalName, libraryName, external }),
128
+ browserTpl(input, output, { format: "umd", globalName, libraryName, external })
81
129
  ]);
82
130
  }
83
131
 
84
132
  export function nodeBoth(input: string, output: string, external: string[] = []) {
85
133
  return Promise.all([
86
- nodeTpl(input, output, "esm", external),
87
- nodeTpl(input, output, "cjs", external)
134
+ nodeTpl(input, output, { format: "esm", external }),
135
+ nodeTpl(input, output, { format: "cjs", external })
88
136
  ]);
89
137
  }
90
138
 
91
139
  export function bothTpl(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
92
140
  return Promise.all([
93
141
  browserBoth(input, output, globalName, libraryName, external),
94
- nodeTpl(input, output, "cjs", external)
142
+ nodeTpl(input, output, { format: "cjs", external })
95
143
  ]);
96
144
  }
package/src/index.ts CHANGED
@@ -4,3 +4,5 @@ export * from "./problem-matcher.ts";
4
4
  export * from "./rebuild-logger.ts";
5
5
  export * from "./remove-strict.ts";
6
6
  export * from "./sfx-wrapper.ts";
7
+ export * from "./inline-css.ts";
8
+ export * from "./vite-utils.ts";
@@ -0,0 +1,44 @@
1
+ import type { PluginBuild, Plugin } from "esbuild";
2
+ import path from "path";
3
+ import crypto from "crypto";
4
+ import { readFile } from "fs/promises";
5
+
6
+ export function inlineCSS(options = {}) {
7
+ return {
8
+ name: "inline-css",
9
+
10
+ setup(build: PluginBuild) {
11
+
12
+ build.onLoad({ filter: /\.(css)$/ }, async (args) => {
13
+ if (build.initialOptions.platform === "browser") {
14
+ const sourcePath = path.resolve(args.path);
15
+ const sourceJS = await generateInjectCSS(sourcePath);
16
+ return {
17
+ contents: sourceJS,
18
+ loader: "js"
19
+ };
20
+ }
21
+ });
22
+ },
23
+ };
24
+ }
25
+
26
+ async function generateInjectCSS(sourcePath: string) {
27
+ const styleID = sha256(sourcePath);
28
+ const sourceCSS = await readFile(sourcePath, "utf8");
29
+
30
+ return `(function(){
31
+ if (!document.getElementById('${styleID}')) {
32
+ var e = document.createElement('style');
33
+ e.id = '${styleID}';
34
+ e.textContent = \`${sourceCSS.split("\\25").join("\\x15")}\`;
35
+ document.head.appendChild(e);
36
+ }
37
+ })();`;
38
+ }
39
+
40
+ function sha256(sourcePath: string) {
41
+ const hash = crypto.createHash("sha256").update(sourcePath).digest("hex");
42
+ return hash.slice(0, 8); // Use the first 8 characters of the hash
43
+ }
44
+
@@ -10,9 +10,6 @@ export function removeStrict(): Plugin {
10
10
  result?.outputFiles?.forEach(file => {
11
11
  if (file.path.endsWith(".js")) {
12
12
  const contents = file.text.replace(/"use strict";/g, "");
13
- if (contents.indexOf("use strict") >= 0) {
14
- console.error("remove-strict: ", file.path);
15
- }
16
13
  writeFileSync(file.path, contents, { encoding: "utf8" });
17
14
  } else {
18
15
  writeFileSync(file.path, file.contents, { encoding: "binary" });
@@ -0,0 +1,31 @@
1
+ const alias = {
2
+ "d3-array": "@hpcc-js/common",
3
+ "d3-brush": "@hpcc-js/common",
4
+ "d3-collection": "@hpcc-js/common",
5
+ "d3-color": "@hpcc-js/common",
6
+ "d3-dispatch": "@hpcc-js/common",
7
+ "d3-drag": "@hpcc-js/common",
8
+ "d3-dsv": "@hpcc-js/common",
9
+ "d3-ease": "@hpcc-js/common",
10
+ "d3-format": "@hpcc-js/common",
11
+ "d3-interpolate": "@hpcc-js/common",
12
+ "d3-scale": "@hpcc-js/common",
13
+ "d3-selection": "@hpcc-js/common",
14
+ "d3-time-format": "@hpcc-js/common",
15
+ "d3-transition": "@hpcc-js/common",
16
+ "d3-zoom": "@hpcc-js/common"
17
+ };
18
+
19
+ export function hpccBundleNames(pkg: any) {
20
+ const external: string[] = [];
21
+ const globals: { [id: string]: string } = {};
22
+ for (const dep in pkg.dependencies) {
23
+ external.push(dep);
24
+ globals[dep] = dep;
25
+ }
26
+ for (const dep in pkg.peerDependencies ?? {}) {
27
+ external.push(dep);
28
+ globals[dep] = dep;
29
+ }
30
+ return { alias: (pkg.name !== "@hpcc-js/common" && pkg.dependencies["@hpcc-js/common"]) ? alias : {}, external, globals };
31
+ }
package/types/build.d.ts CHANGED
@@ -1,11 +1,28 @@
1
- import type { BuildOptions, Format } from "esbuild";
1
+ import type { BuildOptions, Format, Loader, Plugin } from "esbuild";
2
+ export declare const copyStaticFiles: Plugin;
2
3
  export declare const pkg: any;
3
4
  export declare const NODE_MJS: string;
4
5
  export declare const NODE_CJS: string;
5
6
  export declare function buildWatch(input: string, format: (Format | "umd") | undefined, external: string[] | undefined, config: BuildOptions, isDevelopment?: boolean, isWatch?: boolean): Promise<void>;
6
- export declare function browserTpl(input: string, output: string, format?: Format | "umd", globalName?: string, libraryName?: string, external?: string[]): Promise<void>;
7
- export declare function nodeTpl(input: string, output: string, format?: Format | "umd", external?: string[]): Promise<void>;
8
- export declare function neutralTpl(input: string, output: string, format?: Format | "umd", globalName?: string, libraryName?: string, external?: string[]): Promise<void>;
7
+ export type TplOptions = {
8
+ format?: Format | "umd";
9
+ globalName?: string;
10
+ libraryName?: string;
11
+ keepNames?: boolean;
12
+ external?: string[];
13
+ plugins?: Plugin[];
14
+ loader?: {
15
+ [ext: string]: Loader;
16
+ };
17
+ supported?: Record<string, boolean>;
18
+ alias?: Record<string, string>;
19
+ define?: {
20
+ [key: string]: string;
21
+ };
22
+ };
23
+ export declare function browserTpl(input: string, output: string, { format, globalName, libraryName, keepNames, external, plugins, alias, define, loader }?: TplOptions): Promise<void>;
24
+ export declare function nodeTpl(input: string, output: string, { format, external, supported }?: TplOptions): Promise<void>;
25
+ export declare function neutralTpl(input: string, output: string, { format, globalName, libraryName, keepNames, external }?: TplOptions): Promise<void>;
9
26
  export declare function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external?: string[]): Promise<[void, void]>;
10
27
  export declare function nodeBoth(input: string, output: string, external?: string[]): Promise<[void, void]>;
11
28
  export declare function bothTpl(input: string, output: string, globalName?: string, libraryName?: string, external?: string[]): Promise<[[void, void], void]>;
package/types/index.d.ts CHANGED
@@ -4,3 +4,5 @@ export * from "./problem-matcher.ts";
4
4
  export * from "./rebuild-logger.ts";
5
5
  export * from "./remove-strict.ts";
6
6
  export * from "./sfx-wrapper.ts";
7
+ export * from "./inline-css.ts";
8
+ export * from "./vite-utils.ts";
@@ -0,0 +1,5 @@
1
+ import type { PluginBuild } from "esbuild";
2
+ export declare function inlineCSS(options?: {}): {
3
+ name: string;
4
+ setup(build: PluginBuild): void;
5
+ };
@@ -0,0 +1,7 @@
1
+ export declare function hpccBundleNames(pkg: any): {
2
+ alias: {};
3
+ external: string[];
4
+ globals: {
5
+ [id: string]: string;
6
+ };
7
+ };