@hpcc-js/esbuild-plugins 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -13
- package/dist/index.js.map +3 -3
- package/package.json +5 -5
- package/src/build.ts +84 -44
- package/types/build.d.ts +13 -8
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
if (!document.getElementById('${
|
|
1
|
+
import*as a from"process";import{readFileSync as h,existsSync as L,writeFileSync as F}from"fs";import*as c from"path";import*as y from"esbuild";import{umdWrapper as w}from"esbuild-plugin-umd-wrapper";import*as ne from"esbuild-copy-static-files";import E from"path";import N from"crypto";import{readFile as k}from"fs/promises";function g(r={}){return{name:"inline-css",setup(t){t.onLoad({filter:/\.(css)$/},async e=>{if(t.initialOptions.platform==="browser"){let n=E.resolve(e.path);return{contents:await _(n),loader:"js"}}})}}}async function _(r){let t=C(r),e=await k(r,"utf8");return`(function(){
|
|
2
|
+
if (!document.getElementById('${t}')) {
|
|
3
3
|
var e = document.createElement('style');
|
|
4
|
-
e.id = '${
|
|
5
|
-
e.textContent = \`${
|
|
4
|
+
e.id = '${t}';
|
|
5
|
+
e.textContent = \`${e.split("\\25").join("\\x15")}\`;
|
|
6
6
|
document.head.appendChild(e);
|
|
7
7
|
}
|
|
8
|
-
})();`}function
|
|
9
|
-
export const PKG_VERSION = "${
|
|
10
|
-
export const BUILD_VERSION = "${
|
|
11
|
-
`,"utf8")}
|
|
12
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function
|
|
13
|
-
${
|
|
8
|
+
})();`}function C(r){return N.createHash("sha256").update(r).digest("hex").slice(0,8)}function b(r){return{name:"rebuild-logger",setup(t){t.onStart(()=>{console.log("[watch] build started")}),t.onEnd(()=>{console.log(`Rebuilt ${r.outfile??"Unknown"}`)})}}}var i=JSON.parse(h(c.join(a.cwd(),"./package.json"),"utf8")),j=i.type==="module"?"js":"mjs",P=i.type==="module"?"cjs":"js";async function d(r,t){let e=a.argv.includes("--development"),n=a.argv.includes("--watch"),s=!e;if(s&&L(c.join(a.cwd(),"../../package.json"))){let o=JSON.parse(h(c.join(a.cwd(),"../../package.json"),"utf8"));F(c.join(a.cwd(),"src/__package__.ts"),`export const PKG_NAME = "${i.name}";
|
|
9
|
+
export const PKG_VERSION = "${i.version}";
|
|
10
|
+
export const BUILD_VERSION = "${o.version}";
|
|
11
|
+
`,"utf8")}t={entryPoints:r,format:"esm",bundle:!0,minify:s,sourcemap:!0,external:[...t.external??[]],...t,loader:{...t.loader},outExtension:{...t.outExtension},banner:{...t.banner},footer:{...t.footer},plugins:[...n?[b(t)]:[],...t.plugins??[],g()],nodePaths:[...t.nodePaths??[]]};let l=await y.context(t);n?await l.watch():(e&&Array.isArray(t.entryPoints)&&console.log("Start: ",t.entryPoints[0],t.outfile),await l.rebuild(),await l.dispose(),e&&Array.isArray(t.entryPoints)&&console.log("Stop: ",t.entryPoints[0],t.outfile))}function I(r){return[...i.dependencies?Object.keys(i.dependencies):[],...i.peerDependencies?Object.keys(i.peerDependencies):[],...r??[]]}function x(r,t,e={}){return e.format=e.format??"esm",d([r],{format:e.format==="umd"?"esm":e.format,external:e.external??[],outfile:`${t}.${e.format==="esm"?"js":`${e.format}.js`}`,platform:"browser",target:"es2022",globalName:e.globalName,keepNames:e.keepNames,plugins:e.format==="umd"?[w({libraryName:e.libraryName}),...e.plugins??[]]:[...e.plugins??[]],alias:e.alias,define:e.define,loader:e.loader})}function p(r,t,e={}){return e.packages=e.packages??"external",e.packages==="auto"&&(e.external=I(e.external)),d([r],{format:e.format==="umd"?"esm":e.format,outfile:`${t}.${e.format==="esm"?j:P}`,platform:"node",target:"node22",packages:e.packages==="auto"?"bundle":e.packages})}function ie(r,t,e={}){e.format=e.format??"esm";let n="";switch(e.format){case"iife":n="iife.js";break;case"esm":n=j;break;case"cjs":n=P;break;case"umd":n="umd.js";break;default:throw new Error(`Unknown format: ${e.format}`)}return d([r],{format:e.format==="umd"?"esm":e.format,outfile:`${t}.${e.format==="esm"?"js":`${e.format}.js`}`,platform:"neutral",target:"es2022",globalName:e.globalName,keepNames:e.keepNames,plugins:e.format==="umd"?[w({libraryName:e.libraryName})]:[]})}function J(r,t,e={}){return Promise.all([x(r,t,{format:"esm",...e}),x(r,t,{format:"umd",...e})])}function ae(r,t,e={}){return Promise.all([p(r,t,{format:"esm",...e}),p(r,t,{format:"cjs",...e})])}function le(r,t,e={}){return Promise.all([J(r,t,{...e}),p(r,t,{format:"cjs",...e})])}import{readFile as R}from"fs/promises";function ue(r){return{name:"exclude-sourcemap",setup(t){t.onLoad({filter:r.filter},async e=>({contents:await R(e.path,"utf8")+`
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function de(){return{name:"problem-matcher",setup(r){r.onStart(()=>{console.log("[watch] build started")}),r.onEnd(t=>{t.errors.forEach(({text:e,location:n})=>{console.error(`\u2718 [ERROR] ${e}`),console.error(` ${n?.file}:${n?.line}:${n?.column}:`)}),console.log("[watch] build finished")})}}}import{writeFileSync as O}from"node:fs";function be(){return{name:"remove-strict",setup(r){r.initialOptions.write=!1,r.onEnd(t=>{t?.outputFiles?.forEach(e=>{if(e.path.endsWith(".js")){let n=e.text.replace(/"use strict";/g,"");O(e.path,n,{encoding:"utf8"})}else O(e.path,e.contents,{encoding:"binary"})})})}}}import{readFile as U}from"fs/promises";import{existsSync as A}from"fs";import{Base91 as T}from"@hpcc-js/wasm-base91";import{Zstd as D}from"@hpcc-js/wasm-zstd";function W(r,t,e){let n=e.length+8192<=t.length,s=A(r);return`${n?'import { decompress } from "fzstd";':""}
|
|
13
|
+
${s?`import wrapper from "${r}";`:""}
|
|
14
14
|
|
|
15
15
|
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
|
|
16
16
|
|
|
@@ -48,7 +48,7 @@ function decode(raw: string): Uint8Array {
|
|
|
48
48
|
return new Uint8Array(ret);
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
const blobStr = '${n?t
|
|
51
|
+
const blobStr = '${n?e:t}';
|
|
52
52
|
|
|
53
53
|
let g_module: Uint8Array | undefined;
|
|
54
54
|
let g_wasmBinary: Uint8Array | undefined;
|
|
@@ -56,7 +56,7 @@ export default function() {
|
|
|
56
56
|
if (!g_wasmBinary) {
|
|
57
57
|
g_wasmBinary = ${n?"decompress(decode(blobStr))":"decode(blobStr)"};
|
|
58
58
|
}
|
|
59
|
-
${
|
|
59
|
+
${s?` if (!g_module) {
|
|
60
60
|
g_module = wrapper({
|
|
61
61
|
wasmBinary: g_wasmBinary,
|
|
62
62
|
locateFile: undefined
|
|
@@ -71,5 +71,5 @@ export function reset() {
|
|
|
71
71
|
if (g_module) {
|
|
72
72
|
g_module = undefined;
|
|
73
73
|
}
|
|
74
|
-
} `.trim()}async function
|
|
74
|
+
} `.trim()}async function z(r){let t=await T.load(),e=await D.load(),n=await U(r);r=r.replace(/\.js$/,".xxx");let s=r.replace(/\.wasm$/,".js"),l=t.encode(n),o=e.compress(n),u=t.encode(o);return W(s,l,u)}function Pe(){return{name:"sfx-wasm",setup(r){r.onLoad({filter:/\.wasm$/},async t=>({contents:await z(t.path),loader:"ts"}))}}}import{defineConfig as V}from"vite";import H from"vite-plugin-css-injected-by-js";import{viteStaticCopy as M}from"vite-plugin-static-copy";var G={"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 K(r){let t=[],e={};for(let n in r.dependencies)t.push(n),e[n]=n;for(let n in r.peerDependencies??{})t.push(n),e[n]=n;return{alias:r.name!=="@hpcc-js/common"&&r.dependencies["@hpcc-js/common"]?G:{},external:t,globals:e}}function Ee(r,t={}){let{external:e=[],plugins:n=[],includeFontAwesome:s=!1,entry:l="src/index.ts",configOverrides:o={}}=t,{alias:u,external:S,globals:$}=K(r),B=[...S,...e],f=[H({topExecutionPriority:!1}),...n];s&&f.push(M({targets:[{src:"../../node_modules/font-awesome/fonts",dest:"../font-awesome"},{src:"../../node_modules/font-awesome/css",dest:"../font-awesome"}]}));let v={build:{lib:{...{entry:l,name:r.name,fileName:"index"},...o.build?.lib||{}},rollupOptions:{external:B,output:{globals:$},...o.build?.rollupOptions||{}},sourcemap:!0,...o.build?Object.fromEntries(Object.entries(o.build).filter(([m])=>m!=="lib"&&m!=="rollupOptions")):{}},resolve:{alias:u,...o.resolve||{}},esbuild:{minifyIdentifiers:!1,...o.esbuild||{}},plugins:f,...Object.fromEntries(Object.entries(o).filter(([m])=>!["build","resolve","esbuild","plugins"].includes(m)))};return V(v)}export{P as NODE_CJS,j as NODE_MJS,le as bothTpl,J as browserBoth,x as browserTpl,d as buildWatch,ne as copyStaticFiles,Ee as createHpccViteConfig,ue as excludeSourcemap,K as hpccBundleNames,g as inlineCSS,ie as neutralTpl,ae as nodeBoth,p as nodeTpl,i as pkg,de as problemMatcher,b as rebuildLogger,be as removeStrict,Pe as sfxWasm,z as wrap};
|
|
75
75
|
//# 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/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 })] : [] as Plugin[]\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", "import { defineConfig, UserConfig } from \"vite\";\nimport cssInjectedByJsPlugin from \"vite-plugin-css-injected-by-js\";\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\n\nconst 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}\n\nexport interface ViteHpccConfigOptions {\n /**\n * Additional external items\n */\n external?: string[];\n /**\n * Additional plugins to include in the configuration\n */\n plugins?: any[];\n /**\n * Whether to include font-awesome static copy (used by @hpcc-js/common)\n */\n includeFontAwesome?: boolean;\n /**\n * Custom entry point (defaults to \"src/index.ts\")\n */\n entry?: string;\n /**\n * Additional vite config options to merge\n */\n configOverrides?: Partial<UserConfig>;\n}\n\n/**\n * Creates a standardized Vite configuration for HPCC-JS packages\n */\nexport function createHpccViteConfig(pkg: any, options: ViteHpccConfigOptions = {}): UserConfig {\n const {\n external: additionalExternal = [],\n plugins: additionalPlugins = [],\n includeFontAwesome = false,\n entry = \"src/index.ts\",\n configOverrides = {}\n } = options;\n\n const { alias, external, globals } = hpccBundleNames(pkg);\n const allExternals = [...external, ...additionalExternal];\n\n const allPlugins = [\n cssInjectedByJsPlugin({\n topExecutionPriority: false\n }),\n ...additionalPlugins\n ];\n\n if (includeFontAwesome) {\n allPlugins.push(\n viteStaticCopy({\n targets: [\n {\n src: \"../../node_modules/font-awesome/fonts\",\n dest: \"../font-awesome\"\n }, {\n src: \"../../node_modules/font-awesome/css\",\n dest: \"../font-awesome\",\n }\n ]\n })\n );\n }\n\n const defaultLibConfig = {\n entry,\n name: pkg.name,\n fileName: \"index\",\n };\n\n const config: UserConfig = {\n build: {\n lib: {\n ...defaultLibConfig,\n ...(configOverrides.build?.lib || {})\n },\n rollupOptions: {\n external: allExternals,\n output: {\n globals,\n },\n ...(configOverrides.build?.rollupOptions || {})\n },\n sourcemap: true,\n ...(configOverrides.build ? Object.fromEntries(Object.entries(configOverrides.build).filter(([key]) => key !== \"lib\" && key !== \"rollupOptions\")) : {})\n },\n resolve: {\n alias,\n ...(configOverrides.resolve || {})\n },\n esbuild: {\n minifyIdentifiers: false,\n ...(configOverrides.esbuild || {})\n },\n plugins: allPlugins,\n ...Object.fromEntries(Object.entries(configOverrides).filter(([key]) => ![\"build\", \"resolve\", \"esbuild\", \"plugins\"].includes(key)))\n };\n\n return defineConfig(config);\n}"],
|
|
5
|
-
"mappings": "AAAA,UAAYA,MAAa,UACzB,OAAS,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,KACxD,UAAYC,MAAU,OACtB,UAAYC,MAAa,UAEzB,OAAS,cAAAC,MAAkB,
|
|
6
|
-
"names": ["process", "readFileSync", "existsSync", "writeFileSync", "path", "esbuild", "umdWrapper", "path", "crypto", "readFile", "inlineCSS", "options", "build", "args", "sourcePath", "generateInjectCSS", "styleID", "sha256", "sourceCSS", "rebuildLogger", "opts", "build", "
|
|
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 * as copyStaticFiles from \"esbuild-copy-static-files\";\nimport { inlineCSS } from \"./inline-css.ts\";\nimport { rebuildLogger } from \"./rebuild-logger.ts\";\n\nexport { 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(inputs: string[] | Record<string, string> | { in: string, out: string }[], config: BuildOptions): Promise<void> {\n const isDevelopment = process.argv.includes(\"--development\");\n const isWatch = process.argv.includes(\"--watch\");\n const isProduction = !isDevelopment;\n\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 config = {\n entryPoints: inputs,\n format: \"esm\",\n bundle: true,\n minify: isProduction,\n sourcemap: true,\n external: [\n ...config.external ?? []\n ],\n ...config,\n loader: {\n ...config.loader\n },\n outExtension: {\n ...config.outExtension\n },\n banner: {\n ...config.banner\n },\n footer: {\n ...config.footer\n },\n plugins: [\n ...(isWatch ? [rebuildLogger(config)] : []),\n ...config.plugins ?? [],\n inlineCSS()\n ],\n nodePaths: [\n ...config.nodePaths ?? []\n ]\n };\n const ctx = await esbuild.context(config);\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 packages?: \"bundle\" | \"external\" | \"auto\";\n};\n\nfunction autoExternal(external?: string[]): string[] {\n return [\n ...pkg.dependencies ? Object.keys(pkg.dependencies) : [], ...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],\n ...external ?? []\n ];\n}\n\nexport function browserTpl(input: string, output: string, options: TplOptions = {}) {\n options.format = options.format ?? \"esm\";\n\n return buildWatch([input], {\n format: options.format === \"umd\" ? \"esm\" : options.format,\n external: options.external ?? [],\n outfile: `${output}.${options.format === \"esm\" ? \"js\" : `${options.format}.js`}`,\n platform: \"browser\",\n target: \"es2022\",\n globalName: options.globalName,\n keepNames: options.keepNames,\n plugins: options.format === \"umd\" ? [umdWrapper({ libraryName: options.libraryName }), ...options.plugins ?? []] : [...options.plugins ?? []],\n alias: options.alias,\n define: options.define,\n loader: options.loader,\n });\n}\n\nexport function nodeTpl(input: string, output: string, options: TplOptions = {}) {\n options.packages = options.packages ?? \"external\";\n if (options.packages === \"auto\") {\n options.external = autoExternal(options.external);\n }\n\n return buildWatch([input], {\n format: options.format === \"umd\" ? \"esm\" : options.format,\n outfile: `${output}.${options.format === \"esm\" ? NODE_MJS : NODE_CJS}`,\n platform: \"node\",\n target: \"node22\",\n packages: options.packages === \"auto\" ? \"bundle\" : options.packages,\n });\n}\n\nexport function neutralTpl(input: string, output: string, options: TplOptions = {}) {\n options.format = options.format ?? \"esm\";\n\n let postfix = \"\";\n switch (options.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: ${options.format}`);\n }\n return buildWatch([input], {\n format: options.format === \"umd\" ? \"esm\" : options.format,\n outfile: `${output}.${options.format === \"esm\" ? \"js\" : `${options.format}.js`}`,\n platform: \"neutral\",\n target: \"es2022\",\n globalName: options.globalName,\n keepNames: options.keepNames,\n plugins: options.format === \"umd\" ? [umdWrapper({ libraryName: options.libraryName })] : [] as Plugin[]\n });\n}\n\nexport function browserBoth(input: string, output: string, options: TplOptions = {}) {\n return Promise.all([\n browserTpl(input, output, { format: \"esm\", ...options }),\n browserTpl(input, output, { format: \"umd\", ...options })\n ]);\n}\n\nexport function nodeBoth(input: string, output: string, options: TplOptions = {}) {\n return Promise.all([\n nodeTpl(input, output, { format: \"esm\", ...options }),\n nodeTpl(input, output, { format: \"cjs\", ...options })\n ]);\n}\n\nexport function bothTpl(input: string, output: string, options: TplOptions = {}) {\n return Promise.all([\n browserBoth(input, output, { ...options }),\n nodeTpl(input, output, { format: \"cjs\", ...options })\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", "import { defineConfig, UserConfig } from \"vite\";\nimport cssInjectedByJsPlugin from \"vite-plugin-css-injected-by-js\";\nimport { viteStaticCopy } from \"vite-plugin-static-copy\";\n\nconst 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}\n\nexport interface ViteHpccConfigOptions {\n /**\n * Additional external items\n */\n external?: string[];\n /**\n * Additional plugins to include in the configuration\n */\n plugins?: any[];\n /**\n * Whether to include font-awesome static copy (used by @hpcc-js/common)\n */\n includeFontAwesome?: boolean;\n /**\n * Custom entry point (defaults to \"src/index.ts\")\n */\n entry?: string;\n /**\n * Additional vite config options to merge\n */\n configOverrides?: Partial<UserConfig>;\n}\n\n/**\n * Creates a standardized Vite configuration for HPCC-JS packages\n */\nexport function createHpccViteConfig(pkg: any, options: ViteHpccConfigOptions = {}): UserConfig {\n const {\n external: additionalExternal = [],\n plugins: additionalPlugins = [],\n includeFontAwesome = false,\n entry = \"src/index.ts\",\n configOverrides = {}\n } = options;\n\n const { alias, external, globals } = hpccBundleNames(pkg);\n const allExternals = [...external, ...additionalExternal];\n\n const allPlugins = [\n cssInjectedByJsPlugin({\n topExecutionPriority: false\n }),\n ...additionalPlugins\n ];\n\n if (includeFontAwesome) {\n allPlugins.push(\n viteStaticCopy({\n targets: [\n {\n src: \"../../node_modules/font-awesome/fonts\",\n dest: \"../font-awesome\"\n }, {\n src: \"../../node_modules/font-awesome/css\",\n dest: \"../font-awesome\",\n }\n ]\n })\n );\n }\n\n const defaultLibConfig = {\n entry,\n name: pkg.name,\n fileName: \"index\",\n };\n\n const config: UserConfig = {\n build: {\n lib: {\n ...defaultLibConfig,\n ...(configOverrides.build?.lib || {})\n },\n rollupOptions: {\n external: allExternals,\n output: {\n globals,\n },\n ...(configOverrides.build?.rollupOptions || {})\n },\n sourcemap: true,\n ...(configOverrides.build ? Object.fromEntries(Object.entries(configOverrides.build).filter(([key]) => key !== \"lib\" && key !== \"rollupOptions\")) : {})\n },\n resolve: {\n alias,\n ...(configOverrides.resolve || {})\n },\n esbuild: {\n minifyIdentifiers: false,\n ...(configOverrides.esbuild || {})\n },\n plugins: allPlugins,\n ...Object.fromEntries(Object.entries(configOverrides).filter(([key]) => ![\"build\", \"resolve\", \"esbuild\", \"plugins\"].includes(key)))\n };\n\n return defineConfig(config);\n}"],
|
|
5
|
+
"mappings": "AAAA,UAAYA,MAAa,UACzB,OAAS,gBAAAC,EAAc,cAAAC,EAAY,iBAAAC,MAAqB,KACxD,UAAYC,MAAU,OACtB,UAAYC,MAAa,UAEzB,OAAS,cAAAC,MAAkB,6BAC3B,UAAYC,OAAqB,4BCLjC,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,C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QA,EAAgB,KAAK,EAAE,OAAO,CAAC,CAACI,CAAG,IAAMA,IAAQ,OAASA,IAAQ,eAAe,CAAC,EAAI,CAAC,CACzJ,EACA,QAAS,CACL,MAAAhB,EACA,GAAIY,EAAgB,SAAW,CAAC,CACpC,EACA,QAAS,CACL,kBAAmB,GACnB,GAAIA,EAAgB,SAAW,CAAC,CACpC,EACA,QAASE,EACT,GAAG,OAAO,YAAY,OAAO,QAAQF,CAAe,EAAE,OAAO,CAAC,CAACI,CAAG,IAAM,CAAC,CAAC,QAAS,UAAW,UAAW,SAAS,EAAE,SAASA,CAAG,CAAC,CAAC,CACtI,EAEA,OAAOnB,EAAakB,CAAM,CAC9B",
|
|
6
|
+
"names": ["process", "readFileSync", "existsSync", "writeFileSync", "path", "esbuild", "umdWrapper", "copyStaticFiles", "path", "crypto", "readFile", "inlineCSS", "options", "build", "args", "sourcePath", "generateInjectCSS", "styleID", "sha256", "sourceCSS", "rebuildLogger", "opts", "build", "pkg", "readFileSync", "NODE_MJS", "NODE_CJS", "buildWatch", "inputs", "config", "isDevelopment", "isWatch", "isProduction", "existsSync", "rootPkg", "writeFileSync", "rebuildLogger", "inlineCSS", "ctx", "autoExternal", "external", "browserTpl", "input", "output", "options", "umdWrapper", "nodeTpl", "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", "defineConfig", "cssInjectedByJsPlugin", "viteStaticCopy", "alias", "hpccBundleNames", "pkg", "external", "globals", "dep", "createHpccViteConfig", "options", "additionalExternal", "additionalPlugins", "includeFontAwesome", "entry", "configOverrides", "allExternals", "allPlugins", "config", "key"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/esbuild-plugins",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "Various esbuild plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -39,14 +39,14 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@hpcc-js/wasm-base91": "1.3.1",
|
|
41
41
|
"@hpcc-js/wasm-zstd": "1.2.1",
|
|
42
|
-
"esbuild": "0.25.
|
|
42
|
+
"esbuild": "0.25.5",
|
|
43
43
|
"esbuild-copy-static-files": "0.1.0",
|
|
44
44
|
"esbuild-plugin-inline-css": "0.0.1",
|
|
45
45
|
"esbuild-plugin-umd-wrapper": "3.0.0",
|
|
46
46
|
"fzstd": "0.1.1",
|
|
47
|
-
"vite": "
|
|
47
|
+
"vite": "7.0.0",
|
|
48
48
|
"vite-plugin-css-injected-by-js": "3.5.2",
|
|
49
|
-
"vite-plugin-static-copy": "3.0
|
|
49
|
+
"vite-plugin-static-copy": "3.1.0"
|
|
50
50
|
},
|
|
51
51
|
"keywords": [
|
|
52
52
|
"esbuild",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
},
|
|
63
63
|
"homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
|
|
64
64
|
"license": "Apache-2.0",
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "8afa398a6246f7f913bc2cb88402b776d65deb00"
|
|
66
66
|
}
|
package/src/build.ts
CHANGED
|
@@ -4,19 +4,21 @@ import * as path from "path";
|
|
|
4
4
|
import * as esbuild from "esbuild";
|
|
5
5
|
import type { BuildOptions, Format, Loader, Plugin } from "esbuild";
|
|
6
6
|
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
7
|
+
import * as copyStaticFiles from "esbuild-copy-static-files";
|
|
7
8
|
import { inlineCSS } from "./inline-css.ts";
|
|
8
9
|
import { rebuildLogger } from "./rebuild-logger.ts";
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
import _copyStaticFiles from "esbuild-copy-static-files";
|
|
12
|
-
export const copyStaticFiles: Plugin = _copyStaticFiles;
|
|
11
|
+
export { copyStaticFiles };
|
|
13
12
|
|
|
14
13
|
export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
|
|
15
14
|
export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
|
|
16
15
|
export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
|
|
17
16
|
|
|
18
|
-
export async function buildWatch(
|
|
17
|
+
export async function buildWatch(inputs: string[] | Record<string, string> | { in: string, out: string }[], config: BuildOptions): Promise<void> {
|
|
18
|
+
const isDevelopment = process.argv.includes("--development");
|
|
19
|
+
const isWatch = process.argv.includes("--watch");
|
|
19
20
|
const isProduction = !isDevelopment;
|
|
21
|
+
|
|
20
22
|
if (isProduction && existsSync(path.join(process.cwd(), "../../package.json"))) {
|
|
21
23
|
const rootPkg = JSON.parse(readFileSync(path.join(process.cwd(), "../../package.json"), "utf8"));
|
|
22
24
|
writeFileSync(path.join(process.cwd(), "src/__package__.ts"), `\
|
|
@@ -26,20 +28,38 @@ export const BUILD_VERSION = "${rootPkg.version}";
|
|
|
26
28
|
`, "utf8");
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
|
|
30
|
-
entryPoints:
|
|
31
|
-
format:
|
|
31
|
+
config = {
|
|
32
|
+
entryPoints: inputs,
|
|
33
|
+
format: "esm",
|
|
32
34
|
bundle: true,
|
|
33
35
|
minify: isProduction,
|
|
34
36
|
sourcemap: true,
|
|
35
|
-
external
|
|
37
|
+
external: [
|
|
38
|
+
...config.external ?? []
|
|
39
|
+
],
|
|
36
40
|
...config,
|
|
41
|
+
loader: {
|
|
42
|
+
...config.loader
|
|
43
|
+
},
|
|
44
|
+
outExtension: {
|
|
45
|
+
...config.outExtension
|
|
46
|
+
},
|
|
47
|
+
banner: {
|
|
48
|
+
...config.banner
|
|
49
|
+
},
|
|
50
|
+
footer: {
|
|
51
|
+
...config.footer
|
|
52
|
+
},
|
|
37
53
|
plugins: [
|
|
38
54
|
...(isWatch ? [rebuildLogger(config)] : []),
|
|
39
|
-
...
|
|
55
|
+
...config.plugins ?? [],
|
|
40
56
|
inlineCSS()
|
|
57
|
+
],
|
|
58
|
+
nodePaths: [
|
|
59
|
+
...config.nodePaths ?? []
|
|
41
60
|
]
|
|
42
|
-
}
|
|
61
|
+
};
|
|
62
|
+
const ctx = await esbuild.context(config);
|
|
43
63
|
|
|
44
64
|
if (isWatch) {
|
|
45
65
|
await ctx.watch();
|
|
@@ -68,35 +88,54 @@ export type TplOptions = {
|
|
|
68
88
|
supported?: Record<string, boolean>;
|
|
69
89
|
alias?: Record<string, string>;
|
|
70
90
|
define?: { [key: string]: string };
|
|
91
|
+
packages?: "bundle" | "external" | "auto";
|
|
71
92
|
};
|
|
72
93
|
|
|
73
|
-
|
|
74
|
-
return
|
|
75
|
-
|
|
94
|
+
function autoExternal(external?: string[]): string[] {
|
|
95
|
+
return [
|
|
96
|
+
...pkg.dependencies ? Object.keys(pkg.dependencies) : [], ...pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : [],
|
|
97
|
+
...external ?? []
|
|
98
|
+
];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function browserTpl(input: string, output: string, options: TplOptions = {}) {
|
|
102
|
+
options.format = options.format ?? "esm";
|
|
103
|
+
|
|
104
|
+
return buildWatch([input], {
|
|
105
|
+
format: options.format === "umd" ? "esm" : options.format,
|
|
106
|
+
external: options.external ?? [],
|
|
107
|
+
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
|
|
76
108
|
platform: "browser",
|
|
77
109
|
target: "es2022",
|
|
78
|
-
globalName,
|
|
79
|
-
keepNames,
|
|
80
|
-
plugins: format === "umd" ? [umdWrapper({ libraryName }), ...plugins] : [...plugins],
|
|
81
|
-
alias,
|
|
82
|
-
define,
|
|
83
|
-
loader
|
|
84
|
-
}
|
|
110
|
+
globalName: options.globalName,
|
|
111
|
+
keepNames: options.keepNames,
|
|
112
|
+
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName }), ...options.plugins ?? []] : [...options.plugins ?? []],
|
|
113
|
+
alias: options.alias,
|
|
114
|
+
define: options.define,
|
|
115
|
+
loader: options.loader,
|
|
116
|
+
});
|
|
85
117
|
}
|
|
86
118
|
|
|
87
|
-
export function nodeTpl(input: string, output: string,
|
|
88
|
-
|
|
89
|
-
|
|
119
|
+
export function nodeTpl(input: string, output: string, options: TplOptions = {}) {
|
|
120
|
+
options.packages = options.packages ?? "external";
|
|
121
|
+
if (options.packages === "auto") {
|
|
122
|
+
options.external = autoExternal(options.external);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return buildWatch([input], {
|
|
126
|
+
format: options.format === "umd" ? "esm" : options.format,
|
|
127
|
+
outfile: `${output}.${options.format === "esm" ? NODE_MJS : NODE_CJS}`,
|
|
90
128
|
platform: "node",
|
|
91
|
-
target: "
|
|
92
|
-
packages: "
|
|
93
|
-
supported
|
|
129
|
+
target: "node22",
|
|
130
|
+
packages: options.packages === "auto" ? "bundle" : options.packages,
|
|
94
131
|
});
|
|
95
132
|
}
|
|
96
133
|
|
|
97
|
-
export function neutralTpl(input: string, output: string,
|
|
134
|
+
export function neutralTpl(input: string, output: string, options: TplOptions = {}) {
|
|
135
|
+
options.format = options.format ?? "esm";
|
|
136
|
+
|
|
98
137
|
let postfix = "";
|
|
99
|
-
switch (format) {
|
|
138
|
+
switch (options.format) {
|
|
100
139
|
case "iife":
|
|
101
140
|
postfix = "iife.js";
|
|
102
141
|
break;
|
|
@@ -110,35 +149,36 @@ export function neutralTpl(input: string, output: string, { format = "esm", glob
|
|
|
110
149
|
postfix = "umd.js";
|
|
111
150
|
break;
|
|
112
151
|
default:
|
|
113
|
-
throw new Error(`Unknown format: ${format}`);
|
|
152
|
+
throw new Error(`Unknown format: ${options.format}`);
|
|
114
153
|
}
|
|
115
|
-
return buildWatch(input,
|
|
116
|
-
|
|
154
|
+
return buildWatch([input], {
|
|
155
|
+
format: options.format === "umd" ? "esm" : options.format,
|
|
156
|
+
outfile: `${output}.${options.format === "esm" ? "js" : `${options.format}.js`}`,
|
|
117
157
|
platform: "neutral",
|
|
118
158
|
target: "es2022",
|
|
119
|
-
globalName,
|
|
120
|
-
keepNames,
|
|
121
|
-
plugins: format === "umd" ? [umdWrapper({ libraryName })] : [] as Plugin[]
|
|
122
|
-
}
|
|
159
|
+
globalName: options.globalName,
|
|
160
|
+
keepNames: options.keepNames,
|
|
161
|
+
plugins: options.format === "umd" ? [umdWrapper({ libraryName: options.libraryName })] : [] as Plugin[]
|
|
162
|
+
});
|
|
123
163
|
}
|
|
124
164
|
|
|
125
|
-
export function browserBoth(input: string, output: string,
|
|
165
|
+
export function browserBoth(input: string, output: string, options: TplOptions = {}) {
|
|
126
166
|
return Promise.all([
|
|
127
|
-
browserTpl(input, output, { format: "esm",
|
|
128
|
-
browserTpl(input, output, { format: "umd",
|
|
167
|
+
browserTpl(input, output, { format: "esm", ...options }),
|
|
168
|
+
browserTpl(input, output, { format: "umd", ...options })
|
|
129
169
|
]);
|
|
130
170
|
}
|
|
131
171
|
|
|
132
|
-
export function nodeBoth(input: string, output: string,
|
|
172
|
+
export function nodeBoth(input: string, output: string, options: TplOptions = {}) {
|
|
133
173
|
return Promise.all([
|
|
134
|
-
nodeTpl(input, output, { format: "esm",
|
|
135
|
-
nodeTpl(input, output, { format: "cjs",
|
|
174
|
+
nodeTpl(input, output, { format: "esm", ...options }),
|
|
175
|
+
nodeTpl(input, output, { format: "cjs", ...options })
|
|
136
176
|
]);
|
|
137
177
|
}
|
|
138
178
|
|
|
139
|
-
export function bothTpl(input: string, output: string,
|
|
179
|
+
export function bothTpl(input: string, output: string, options: TplOptions = {}) {
|
|
140
180
|
return Promise.all([
|
|
141
|
-
browserBoth(input, output,
|
|
142
|
-
nodeTpl(input, output, { format: "cjs",
|
|
181
|
+
browserBoth(input, output, { ...options }),
|
|
182
|
+
nodeTpl(input, output, { format: "cjs", ...options })
|
|
143
183
|
]);
|
|
144
184
|
}
|
package/types/build.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { BuildOptions, Format, Loader, Plugin } from "esbuild";
|
|
2
|
-
|
|
2
|
+
import * as copyStaticFiles from "esbuild-copy-static-files";
|
|
3
|
+
export { copyStaticFiles };
|
|
3
4
|
export declare const pkg: any;
|
|
4
5
|
export declare const NODE_MJS: string;
|
|
5
6
|
export declare const NODE_CJS: string;
|
|
6
|
-
export declare function buildWatch(
|
|
7
|
+
export declare function buildWatch(inputs: string[] | Record<string, string> | {
|
|
8
|
+
in: string;
|
|
9
|
+
out: string;
|
|
10
|
+
}[], config: BuildOptions): Promise<void>;
|
|
7
11
|
export type TplOptions = {
|
|
8
12
|
format?: Format | "umd";
|
|
9
13
|
globalName?: string;
|
|
@@ -19,10 +23,11 @@ export type TplOptions = {
|
|
|
19
23
|
define?: {
|
|
20
24
|
[key: string]: string;
|
|
21
25
|
};
|
|
26
|
+
packages?: "bundle" | "external" | "auto";
|
|
22
27
|
};
|
|
23
|
-
export declare function browserTpl(input: string, output: string,
|
|
24
|
-
export declare function nodeTpl(input: string, output: string,
|
|
25
|
-
export declare function neutralTpl(input: string, output: string,
|
|
26
|
-
export declare function browserBoth(input: string, output: string,
|
|
27
|
-
export declare function nodeBoth(input: string, output: string,
|
|
28
|
-
export declare function bothTpl(input: string, output: string,
|
|
28
|
+
export declare function browserTpl(input: string, output: string, options?: TplOptions): Promise<void>;
|
|
29
|
+
export declare function nodeTpl(input: string, output: string, options?: TplOptions): Promise<void>;
|
|
30
|
+
export declare function neutralTpl(input: string, output: string, options?: TplOptions): Promise<void>;
|
|
31
|
+
export declare function browserBoth(input: string, output: string, options?: TplOptions): Promise<[void, void]>;
|
|
32
|
+
export declare function nodeBoth(input: string, output: string, options?: TplOptions): Promise<[void, void]>;
|
|
33
|
+
export declare function bothTpl(input: string, output: string, options?: TplOptions): Promise<[[void, void], void]>;
|