@hpcc-js/esbuild-plugins 1.2.0 → 1.3.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 +17 -7
- package/dist/index.js.map +4 -4
- package/package.json +8 -7
- package/src/build.ts +66 -18
- package/src/index.ts +1 -0
- package/src/inline-css.ts +44 -0
- package/src/remove-strict.ts +0 -3
- package/types/build.d.ts +21 -4
- package/types/index.d.ts +1 -0
- package/types/inline-css.d.ts +5 -0
package/dist/index.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
|
|
1
|
+
import*as l from"process";import{readFileSync as b,existsSync as k,writeFileSync as F}from"fs";import*as u from"path";import*as w 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(t={}){return{name:"inline-css",setup(r){r.onLoad({filter:/\.(css)$/},async e=>{if(r.initialOptions.platform==="browser"){let o=B.resolve(e.path);return{contents:await E(o),loader:"js"}}})}}}async function E(t){let r=v(t),e=await _(t,"utf8");return`(function(){
|
|
2
|
+
if (!document.getElementById('${r}')) {
|
|
3
|
+
var e = document.createElement('style');
|
|
4
|
+
e.id = '${r}';
|
|
5
|
+
e.textContent = \`${e.split("\\25").join("\\x15")}\`;
|
|
6
|
+
document.head.appendChild(e);
|
|
7
|
+
}
|
|
8
|
+
})();`}function v(t){return O.createHash("sha256").update(t).digest("hex").slice(0,8)}function f(t){return{name:"rebuild-logger",setup(r){r.onStart(()=>{console.log("[watch] build started")}),r.onEnd(()=>{console.log(`Rebuilt ${t.outfile??"Unknown"}`)})}}}import L from"esbuild-copy-static-files";var H=L,p=JSON.parse(b(u.join(l.cwd(),"./package.json"),"utf8")),h=p.type==="module"?"js":"mjs",P=p.type==="module"?"cjs":"js";async function d(t,r="esm",e=[],o,n=l.argv.includes("--development"),s=l.argv.includes("--watch")){let a=!n;if(a&&k(u.join(l.cwd(),"../../package.json"))){let c=JSON.parse(b(u.join(l.cwd(),"../../package.json"),"utf8"));F(u.join(l.cwd(),"src/__package__.ts"),`export const PKG_NAME = "${p.name}";
|
|
9
|
+
export const PKG_VERSION = "${p.version}";
|
|
10
|
+
export const BUILD_VERSION = "${c.version}";
|
|
11
|
+
`,"utf8")}let i=await w.context({entryPoints:[t],format:r,bundle:!0,minify:a,sourcemap:!0,external:e,...o,plugins:[...s?[f(o)]:[],...o.plugins??[],g()]});s?await i.watch():(n&&Array.isArray(o.entryPoints)&&console.log("Start: ",o.entryPoints[0],o.outfile),await i.rebuild(),await i.dispose(),n&&Array.isArray(o.entryPoints)&&console.log("Stop: ",o.entryPoints[0],o.outfile))}function x(t,r,{format:e="esm",globalName:o,libraryName:n,keepNames:s,external:a=[],plugins:i=[],alias:c={},define:$={},loader:j={}}={}){return d(t,e,a,{outfile:`${r}.${e==="esm"?"js":`${e}.js`}`,platform:"browser",target:"es2022",globalName:o,keepNames:s,plugins:e==="umd"?[y({libraryName:n}),...i]:[...i],alias:c,define:$,loader:j})}function m(t,r,{format:e="esm",external:o=[],supported:n={}}={}){return d(t,e,o,{outfile:`${r}.${e==="esm"?h:P}`,platform:"node",target:"node20",packages:"external",supported:n})}function Q(t,r,{format:e="esm",globalName:o,libraryName:n,keepNames:s,external:a=[]}={}){let i="";switch(e){case"iife":i="iife.js";break;case"esm":i=h;break;case"cjs":i=P;break;case"umd":i="umd.js";break;default:throw new Error(`Unknown format: ${e}`)}return d(t,e,a,{outfile:`${r}.${e==="esm"?"js":`${e}.js`}`,platform:"neutral",target:"es2022",globalName:o,keepNames:s,plugins:e==="umd"?[y({libraryName:n})]:[]})}function J(t,r,e,o,n=[]){return Promise.all([x(t,r,{format:"esm",globalName:e,libraryName:o,external:n}),x(t,r,{format:"umd",globalName:e,libraryName:o,external:n})])}function q(t,r,e=[]){return Promise.all([m(t,r,{format:"esm",external:e}),m(t,r,{format:"cjs",external:e})])}function ee(t,r,e,o,n=[]){return Promise.all([J(t,r,e,o,n),m(t,r,{format:"cjs",external:n})])}import{readFile as R}from"fs/promises";function oe(t){return{name:"exclude-sourcemap",setup(r){r.onLoad({filter:t.filter},async e=>({contents:await R(e.path,"utf8")+`
|
|
12
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function ie(){return{name:"problem-matcher",setup(t){t.onStart(()=>{console.log("[watch] build started")}),t.onEnd(r=>{r.errors.forEach(({text:e,location:o})=>{console.error(`\u2718 [ERROR] ${e}`),console.error(` ${o?.file}:${o?.line}:${o?.column}:`)}),console.log("[watch] build finished")})}}}import{writeFileSync as S}from"node:fs";function le(){return{name:"remove-strict",setup(t){t.initialOptions.write=!1,t.onEnd(r=>{r?.outputFiles?.forEach(e=>{if(e.path.endsWith(".js")){let o=e.text.replace(/"use strict";/g,"");S(e.path,o,{encoding:"utf8"})}else S(e.path,e.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(t,r,e){let o=e.length+8192<=r.length,n=A(t);return`${o?'import { decompress } from "fzstd";':""}
|
|
13
|
+
${n?`import wrapper from "${t}";`:""}
|
|
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
|
|
51
|
+
const blobStr = '${o?e:r}';
|
|
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 = ${
|
|
57
|
+
g_wasmBinary = ${o?"decompress(decode(blobStr))":"decode(blobStr)"};
|
|
47
58
|
}
|
|
48
|
-
${
|
|
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
|
|
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(t){let r=await C.load(),e=await N.load(),o=await I(t);t=t.replace(/\.js$/,".xxx");let n=t.replace(/\.wasm$/,".js"),s=r.encode(o),a=e.compress(o),i=r.encode(a);return T(n,s,i)}function ge(){return{name:"sfx-wasm",setup(t){t.onLoad({filter:/\.wasm$/},async r=>({contents:await U(r.path),loader:"ts"}))}}}export{P as NODE_CJS,h as NODE_MJS,ee as bothTpl,J as browserBoth,x as browserTpl,d as buildWatch,H as copyStaticFiles,oe as excludeSourcemap,g as inlineCSS,Q as neutralTpl,q as nodeBoth,m as nodeTpl,p as pkg,ie as problemMatcher,f as rebuildLogger,le as removeStrict,ge 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/
|
|
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,
|
|
6
|
-
"names": ["process", "readFileSync", "
|
|
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"],
|
|
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"],
|
|
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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BAsCzCG,EAAaD,EAAuBD,CAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAMxCE,EAAa,8BAAgC,iBAAiB;AAAA;AAAA,EAEpFC,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAFe;AAAA,CAUjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOG,KAAK,CACT,CAEA,eAAsBC,EAAKC,EAAc,CACrC,IAAMC,EAAS,MAAMV,EAAO,KAAK,EAC3BW,EAAO,MAAMV,EAAK,KAAK,EAEvBW,EAAO,MAAMd,EAASW,CAAI,EAChCA,EAAOA,EAAK,QAAQ,QAAS,MAAM,EACnC,IAAMN,EAAaM,EAAK,QAAQ,UAAW,KAAK,EAC1CL,EAAaM,EAAO,OAAOE,CAAI,EAC/BC,EAAiBF,EAAK,SAASC,CAAI,EACnCP,EAAuBK,EAAO,OAAOG,CAAc,EAEzD,OAAOX,EAAIC,EAAYC,EAAYC,CAAoB,CAC3D,CAEO,SAASS,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",
|
|
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"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/esbuild-plugins",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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.
|
|
44
|
-
"@hpcc-js/wasm-zstd": "1.2.
|
|
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": "
|
|
62
|
+
"gitHead": "658c50fd965a7744ba8db675ba6878607c44d5e2"
|
|
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
|
-
|
|
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:
|
|
34
|
+
sourcemap: true,
|
|
23
35
|
external,
|
|
24
36
|
...config,
|
|
25
37
|
plugins: [
|
|
26
38
|
...(isWatch ? [rebuildLogger(config)] : []),
|
|
27
39
|
...(config.plugins ?? []),
|
|
28
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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" :
|
|
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
|
@@ -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
|
+
|
package/src/remove-strict.ts
CHANGED
|
@@ -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" });
|
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
|
|
7
|
-
|
|
8
|
-
|
|
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