@hpcc-js/esbuild-plugins 1.3.0 → 1.3.1
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/LICENSE +43 -43
- package/README.md +45 -45
- package/dist/index.js +7 -17
- package/dist/index.js.map +4 -4
- package/dist/sfx-wrapper.js.map +1 -1
- package/package.json +7 -8
- package/src/build.ts +96 -144
- package/src/exclude-sourcemap.ts +20 -20
- package/src/index.ts +6 -7
- package/src/problem-matcher.ts +24 -24
- package/src/rebuild-logger.ts +24 -24
- package/src/remove-strict.ts +24 -21
- package/src/sfx-wrapper.ts +108 -108
- package/types/build.d.ts +4 -21
- package/types/index.d.ts +0 -1
- package/src/inline-css.ts +0 -44
- package/types/inline-css.d.ts +0 -5
package/LICENSE
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
|
-
HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
|
|
2
|
-
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
you may not use this file except in compliance with the License.
|
|
5
|
-
You may obtain a copy of the License at
|
|
6
|
-
|
|
7
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
|
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
See the License for the specific language governing permissions and
|
|
13
|
-
limitations under the License.
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
Intersection Algorithms Provided by Kevin Lindsey
|
|
17
|
-
Copyright (c) 2000-2011, Kevin Lindsey
|
|
18
|
-
All rights reserved.
|
|
19
|
-
|
|
20
|
-
Redistribution and use in source and binary forms, with or without
|
|
21
|
-
modification, are permitted provided that the following conditions are met:
|
|
22
|
-
|
|
23
|
-
- Redistributions of source code must retain the above copyright notice,
|
|
24
|
-
this list of conditions and the following disclaimer.
|
|
25
|
-
|
|
26
|
-
- Redistributions in binary form must reproduce the above copyright
|
|
27
|
-
notice, this list of conditions and the following disclaimer in the
|
|
28
|
-
documentation and/or other materials provided with the distribution.
|
|
29
|
-
|
|
30
|
-
- Neither the name of this software nor the names of its contributors
|
|
31
|
-
may be used to endorse or promote products derived from this software
|
|
32
|
-
without specific prior written permission.
|
|
33
|
-
|
|
34
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
35
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
36
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
37
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
38
|
-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
39
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
40
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
41
|
-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
42
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
43
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
1
|
+
HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
you may not use this file except in compliance with the License.
|
|
5
|
+
You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
See the License for the specific language governing permissions and
|
|
13
|
+
limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
Intersection Algorithms Provided by Kevin Lindsey
|
|
17
|
+
Copyright (c) 2000-2011, Kevin Lindsey
|
|
18
|
+
All rights reserved.
|
|
19
|
+
|
|
20
|
+
Redistribution and use in source and binary forms, with or without
|
|
21
|
+
modification, are permitted provided that the following conditions are met:
|
|
22
|
+
|
|
23
|
+
- Redistributions of source code must retain the above copyright notice,
|
|
24
|
+
this list of conditions and the following disclaimer.
|
|
25
|
+
|
|
26
|
+
- Redistributions in binary form must reproduce the above copyright
|
|
27
|
+
notice, this list of conditions and the following disclaimer in the
|
|
28
|
+
documentation and/or other materials provided with the distribution.
|
|
29
|
+
|
|
30
|
+
- Neither the name of this software nor the names of its contributors
|
|
31
|
+
may be used to endorse or promote products derived from this software
|
|
32
|
+
without specific prior written permission.
|
|
33
|
+
|
|
34
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
35
|
+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
36
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
37
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
38
|
+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
39
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
40
|
+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
41
|
+
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
42
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
43
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
# esbuild-plugin-sfx-wasm
|
|
2
|
-
|
|
3
|
-
## Installation
|
|
4
|
-
|
|
5
|
-
With npm:
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
npm i -D esbuild-plugin-sfx-wasm
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
## Use-cases
|
|
12
|
-
|
|
13
|
-
**The primary motivation for this plugin is to simplify the bundling and distribution of web assembly modules**
|
|
14
|
-
|
|
15
|
-
- Compresses the wasm module using Zstd
|
|
16
|
-
- Encodes the compressed wasm module as a base91 string
|
|
17
|
-
- Generates a standalone module that decodes and instantiates the wasm module on demand
|
|
18
|
-
|
|
19
|
-
## Usage
|
|
20
|
-
|
|
21
|
-
### Build Config
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
import esbuild from "esbuild";
|
|
25
|
-
import sfxWasm from "esbuild-plugin-sfx-wasm";
|
|
26
|
-
|
|
27
|
-
esbuild.build({
|
|
28
|
-
/* ... */
|
|
29
|
-
plugins: [
|
|
30
|
-
sfxWasm()
|
|
31
|
-
],
|
|
32
|
-
/* ... */
|
|
33
|
-
});
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### Usage in your code
|
|
37
|
-
|
|
38
|
-
```js
|
|
39
|
-
import loadCalculator from "../build/calculator.wasm";
|
|
40
|
-
|
|
41
|
-
async function add(a, b) {
|
|
42
|
-
const calc = await loadCalculator();
|
|
43
|
-
return calc.add(1, 2);
|
|
44
|
-
}
|
|
45
|
-
```
|
|
1
|
+
# esbuild-plugin-sfx-wasm
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
With npm:
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm i -D esbuild-plugin-sfx-wasm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use-cases
|
|
12
|
+
|
|
13
|
+
**The primary motivation for this plugin is to simplify the bundling and distribution of web assembly modules**
|
|
14
|
+
|
|
15
|
+
- Compresses the wasm module using Zstd
|
|
16
|
+
- Encodes the compressed wasm module as a base91 string
|
|
17
|
+
- Generates a standalone module that decodes and instantiates the wasm module on demand
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
### Build Config
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import esbuild from "esbuild";
|
|
25
|
+
import sfxWasm from "esbuild-plugin-sfx-wasm";
|
|
26
|
+
|
|
27
|
+
esbuild.build({
|
|
28
|
+
/* ... */
|
|
29
|
+
plugins: [
|
|
30
|
+
sfxWasm()
|
|
31
|
+
],
|
|
32
|
+
/* ... */
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Usage in your code
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
import loadCalculator from "../build/calculator.wasm";
|
|
40
|
+
|
|
41
|
+
async function add(a, b) {
|
|
42
|
+
const calc = await loadCalculator();
|
|
43
|
+
return calc.add(1, 2);
|
|
44
|
+
}
|
|
45
|
+
```
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
|
-
import*as
|
|
2
|
-
|
|
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}";`:""}
|
|
1
|
+
import*as u from"process";import{readFileSync as S}from"fs";import*as g from"path";import*as f from"esbuild";import{umdWrapper as x}from"esbuild-plugin-umd-wrapper";function m(r){return{name:"rebuild-logger",setup(n){n.onStart(()=>{console.log("[watch] build started")}),n.onEnd(()=>{console.log(`Rebuilt ${r.outfile??"Unknown"}`)})}}}import{readFile as y}from"fs/promises";import{existsSync as P}from"fs";import{Base91 as h}from"@hpcc-js/wasm-base91";import{Zstd as B}from"@hpcc-js/wasm-zstd";function $(r,n,t){let e=t.length+8192<=n.length,o=P(r);return`${e?'import { decompress } from "fzstd";':""}
|
|
2
|
+
${o?`import wrapper from "${r}";`:""}
|
|
14
3
|
|
|
15
4
|
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
|
|
16
5
|
|
|
@@ -48,15 +37,15 @@ function decode(raw: string): Uint8Array {
|
|
|
48
37
|
return new Uint8Array(ret);
|
|
49
38
|
}
|
|
50
39
|
|
|
51
|
-
const blobStr = '${
|
|
40
|
+
const blobStr = '${e?t:n}';
|
|
52
41
|
|
|
53
42
|
let g_module: Uint8Array | undefined;
|
|
54
43
|
let g_wasmBinary: Uint8Array | undefined;
|
|
55
44
|
export default function() {
|
|
56
45
|
if (!g_wasmBinary) {
|
|
57
|
-
g_wasmBinary = ${
|
|
46
|
+
g_wasmBinary = ${e?"decompress(decode(blobStr))":"decode(blobStr)"};
|
|
58
47
|
}
|
|
59
|
-
${
|
|
48
|
+
${o?` if (!g_module) {
|
|
60
49
|
g_module = wrapper({
|
|
61
50
|
wasmBinary: g_wasmBinary,
|
|
62
51
|
locateFile: undefined
|
|
@@ -71,5 +60,6 @@ export function reset() {
|
|
|
71
60
|
if (g_module) {
|
|
72
61
|
g_module = undefined;
|
|
73
62
|
}
|
|
74
|
-
} `.trim()}async function
|
|
63
|
+
} `.trim()}async function j(r){let n=await h.load(),t=await B.load(),e=await y(r);r=r.replace(/\.js$/,".xxx");let o=r.replace(/\.wasm$/,".js"),i=n.encode(e),p=t.compress(e),s=n.encode(p);return $(o,i,s)}function c(){return{name:"sfx-wasm",setup(r){r.onLoad({filter:/\.wasm$/},async n=>({contents:await j(n.path),loader:"ts"}))}}}var b=JSON.parse(S(g.join(u.cwd(),"./package.json"),"utf8")),v=b.type==="module"?"js":"mjs",E=b.type==="module"?"cjs":"js";async function a(r,n="esm",t=[],e,o=u.argv.includes("--development"),i=u.argv.includes("--watch")){let s=await f.context({entryPoints:[r],format:n,bundle:!0,minify:!o,sourcemap:o,external:t,...e,plugins:[...i?[m(e)]:[],...e.plugins??[],c()]});i?await s.watch():(o&&Array.isArray(e.entryPoints)&&console.log("Start: ",e.entryPoints[0],e.outfile),await s.rebuild(),await s.dispose(),o&&Array.isArray(e.entryPoints)&&console.log("Stop: ",e.entryPoints[0],e.outfile))}function d(r,n,t="esm",e,o,i=[]){return a(r,t,i,{outfile:`${n}.${t==="esm"?"js":`${t}.js`}`,platform:"browser",target:"es2022",globalName:e,plugins:t==="umd"?[x({libraryName:o})]:[]})}function l(r,n,t="esm",e=[]){return a(r,t,e,{outfile:`${n}.${t==="esm"?v:E}`,platform:"node",target:"node20",packages:"external"})}function T(r,n,t="esm",e,o,i=[]){return a(r,t,i,{outfile:`${n}.${t==="esm"?"js":"umd.js"}`,platform:"neutral",target:"es2022",globalName:e,plugins:t==="umd"?[x({libraryName:o})]:[]})}function O(r,n,t,e,o=[]){return Promise.all([d(r,n,"esm",t,e,o),d(r,n,"umd",t,e,o)])}function C(r,n,t=[]){return Promise.all([l(r,n,"esm",t),l(r,n,"cjs",t)])}function M(r,n,t,e,o=[]){return Promise.all([O(r,n,t,e,o),l(r,n,"cjs",o)])}import{readFile as _}from"fs/promises";function Y(r){return{name:"exclude-sourcemap",setup(n){n.onLoad({filter:r.filter},async t=>({contents:await _(t.path,"utf8")+`
|
|
64
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==`,loader:"default"}))}}}function N(){return{name:"problem-matcher",setup(r){r.onStart(()=>{console.log("[watch] build started")}),r.onEnd(n=>{n.errors.forEach(({text:t,location:e})=>{console.error(`\u2718 [ERROR] ${t}`),console.error(` ${e?.file}:${e?.line}:${e?.column}:`)}),console.log("[watch] build finished")})}}}import{writeFileSync as w}from"node:fs";function G(){return{name:"remove-strict",setup(r){r.initialOptions.write=!1,r.onEnd(n=>{n?.outputFiles?.forEach(t=>{if(t.path.endsWith(".js")){let e=t.text.replace(/"use strict";/g,"");e.indexOf("use strict")>=0&&console.error("remove-strict: ",t.path),w(t.path,e,{encoding:"utf8"})}else w(t.path,t.contents,{encoding:"binary"})})})}}}export{E as NODE_CJS,v as NODE_MJS,M as bothTpl,O as browserBoth,d as browserTpl,a as buildWatch,Y as excludeSourcemap,T as neutralTpl,C as nodeBoth,l as nodeTpl,b as pkg,N as problemMatcher,m as rebuildLogger,G as removeStrict,c as sfxWasm,j as wrap};
|
|
75
65
|
//# 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, 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,
|
|
6
|
-
"names": ["process", "readFileSync", "
|
|
3
|
+
"sources": ["../src/build.ts", "../src/rebuild-logger.ts", "../src/sfx-wrapper.ts", "../src/exclude-sourcemap.ts", "../src/problem-matcher.ts", "../src/remove-strict.ts"],
|
|
4
|
+
"sourcesContent": ["import * as process from \"process\";\r\nimport { readFileSync } from \"fs\";\r\nimport * as path from \"path\";\r\nimport * as esbuild from \"esbuild\";\r\nimport type { BuildOptions, Format } from \"esbuild\";\r\nimport { umdWrapper } from \"esbuild-plugin-umd-wrapper\";\r\nimport { rebuildLogger } from \"./rebuild-logger.ts\";\r\nimport { sfxWasm } from \"./sfx-wrapper.ts\";\r\n\r\nexport const pkg = JSON.parse(readFileSync(path.join(process.cwd(), \"./package.json\"), \"utf8\"));\r\nexport const NODE_MJS = pkg.type === \"module\" ? \"js\" : \"mjs\";\r\nexport const NODE_CJS = pkg.type === \"module\" ? \"cjs\" : \"js\";\r\n\r\nexport 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> {\r\n const isProduction = !isDevelopment;\r\n\r\n const ctx = await esbuild.context({\r\n entryPoints: [input],\r\n format: format as Format,\r\n bundle: true,\r\n minify: isProduction,\r\n sourcemap: isDevelopment,\r\n external,\r\n ...config,\r\n plugins: [\r\n ...(isWatch ? [rebuildLogger(config)] : []),\r\n ...(config.plugins ?? []),\r\n sfxWasm()\r\n ]\r\n });\r\n\r\n if (isWatch) {\r\n await ctx.watch();\r\n } else {\r\n if (isDevelopment && Array.isArray(config.entryPoints)) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"Start: \", config.entryPoints[0], config.outfile);\r\n }\r\n await ctx.rebuild();\r\n await ctx.dispose();\r\n if (isDevelopment && Array.isArray(config.entryPoints)) {\r\n // eslint-disable-next-line no-console\r\n console.log(\"Stop: \", config.entryPoints[0], config.outfile);\r\n }\r\n }\r\n}\r\n\r\nexport function browserTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, libraryName?: string, external: string[] = []) {\r\n return buildWatch(input, format, external, {\r\n outfile: `${output}.${format === \"esm\" ? \"js\" : `${format}.js`}`,\r\n platform: \"browser\",\r\n target: \"es2022\",\r\n globalName,\r\n plugins: format === \"umd\" ? [umdWrapper({ libraryName })] : []\r\n });\r\n}\r\n\r\nexport function nodeTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", external: string[] = []) {\r\n return buildWatch(input, format, external, {\r\n outfile: `${output}.${format === \"esm\" ? NODE_MJS : NODE_CJS}`,\r\n platform: \"node\",\r\n target: \"node20\",\r\n packages: \"external\"\r\n });\r\n}\r\n\r\nexport function neutralTpl(input: string, output: string, format: Format | \"umd\" = \"esm\", globalName?: string, libraryName?: string, external: string[] = []) {\r\n return buildWatch(input, format, external, {\r\n outfile: `${output}.${format === \"esm\" ? \"js\" : \"umd.js\"}`,\r\n platform: \"neutral\",\r\n target: \"es2022\",\r\n globalName,\r\n plugins: format === \"umd\" ? [umdWrapper({ libraryName })] : []\r\n });\r\n}\r\n\r\nexport function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {\r\n return Promise.all([\r\n browserTpl(input, output, \"esm\", globalName, libraryName, external),\r\n browserTpl(input, output, \"umd\", globalName, libraryName, external)\r\n ]);\r\n}\r\n\r\nexport function nodeBoth(input: string, output: string, external: string[] = []) {\r\n return Promise.all([\r\n nodeTpl(input, output, \"esm\", external),\r\n nodeTpl(input, output, \"cjs\", external)\r\n ]);\r\n}\r\n\r\nexport function bothTpl(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {\r\n return Promise.all([\r\n browserBoth(input, output, globalName, libraryName, external),\r\n nodeTpl(input, output, \"cjs\", external)\r\n ]);\r\n}\r\n", "import type { PluginBuild, Plugin } from \"esbuild\";\r\n\r\nexport interface RebuildLoggerOptions {\r\n outfile?: string;\r\n}\r\n\r\nexport function rebuildLogger(opts: RebuildLoggerOptions): Plugin {\r\n return {\r\n name: \"rebuild-logger\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onStart(() => {\r\n // eslint-disable-next-line no-console\r\n console.log(\"[watch] build started\");\r\n });\r\n\r\n build.onEnd(() => {\r\n // eslint-disable-next-line no-console\r\n console.log(`Rebuilt ${opts.outfile ?? \"Unknown\"}`);\r\n });\r\n }\r\n };\r\n}\r\n", "import { readFile } from \"fs/promises\";\r\nimport { existsSync } from \"fs\";\r\nimport { Base91 } from \"@hpcc-js/wasm-base91\";\r\nimport { Zstd } from \"@hpcc-js/wasm-zstd\";\r\nimport type { Plugin, PluginBuild } from \"esbuild\";\r\n\r\nfunction tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {\r\n\r\n const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;\r\n const wasmJsExists = existsSync(wasmJsPath);\r\n\r\n return `\\\r\n${compressed ? 'import { decompress } from \"fzstd\";' : \"\"}\r\n${wasmJsExists ? `import wrapper from \"${wasmJsPath}\";` : \"\"}\r\n\r\nconst table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\\`{|}~\"';\r\n\r\nfunction decode(raw: string): Uint8Array {\r\n const len = raw.length;\r\n const ret: number[] = [];\r\n\r\n let b = 0;\r\n let n = 0;\r\n let v = -1;\r\n\r\n for (let i = 0; i < len; i++) {\r\n const p = table.indexOf(raw[i]);\r\n /* istanbul ignore next */\r\n if (p === -1) continue;\r\n if (v < 0) {\r\n v = p;\r\n } else {\r\n v += p * 91;\r\n b |= v << n;\r\n n += (v & 8191) > 88 ? 13 : 14;\r\n do {\r\n ret.push(b & 0xff);\r\n b >>= 8;\r\n n -= 8;\r\n } while (n > 7);\r\n v = -1;\r\n }\r\n }\r\n\r\n if (v > -1) {\r\n ret.push((b | v << n) & 0xff);\r\n }\r\n\r\n return new Uint8Array(ret);\r\n}\r\n\r\nconst blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';\r\n\r\nlet g_module: Uint8Array | undefined;\r\nlet g_wasmBinary: Uint8Array | undefined;\r\nexport default function() {\r\n if (!g_wasmBinary) {\r\n g_wasmBinary = ${compressed ? \"decompress(decode(blobStr))\" : \"decode(blobStr)\"};\r\n }\r\n${!wasmJsExists ? `\\\r\n return g_wasmBinary;\r\n`: `\\\r\n if (!g_module) {\r\n g_module = wrapper({\r\n wasmBinary: g_wasmBinary,\r\n locateFile: undefined\r\n });\r\n }\r\n return g_module;\r\n`}\r\n}\r\n\r\nexport function reset() {\r\n if (g_module) {\r\n g_module = undefined;\r\n }\r\n} `.trim();\r\n}\r\n\r\nexport async function wrap(path: string) {\r\n const base91 = await Base91.load();\r\n const zstd = await Zstd.load();\r\n\r\n const wasm = await readFile(path);\r\n path = path.replace(/\\.js$/, \".xxx\");\r\n const wasmJsPath = path.replace(/\\.wasm$/, \".js\");\r\n const base91Wasm = base91.encode(wasm);\r\n const compressedWasm = zstd.compress(wasm);\r\n const base91CompressedWasm = base91.encode(compressedWasm);\r\n\r\n return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);\r\n}\r\n\r\nexport function sfxWasm(): Plugin {\r\n return {\r\n name: \"sfx-wasm\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onLoad({ filter: /\\.wasm$/ }, async args => {\r\n return {\r\n contents: await wrap(args.path),\r\n loader: \"ts\",\r\n };\r\n });\r\n }\r\n };\r\n}\r\n", "import { readFile } from \"fs/promises\";\r\nimport type { PluginBuild, Plugin } from \"esbuild\";\r\n\r\nexport interface ExcludeSourcemapOptions {\r\n filter: RegExp;\r\n}\r\nexport function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {\r\n return {\r\n name: \"exclude-sourcemap\",\r\n\r\n setup(build: PluginBuild) {\r\n build.onLoad({ filter: opts.filter }, async args => {\r\n return {\r\n contents: await readFile(args.path, \"utf8\") + \"\\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==\",\r\n loader: \"default\",\r\n };\r\n });\r\n },\r\n };\r\n}\r\n", "import type { PluginBuild, Plugin } from \"esbuild\";\r\n\r\nexport function problemMatcher(): Plugin {\r\n return {\r\n name: \"problem-matcher\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onStart(() => {\r\n // eslint-disable-next-line no-console\r\n console.log(\"[watch] build started\");\r\n });\r\n\r\n build.onEnd((result) => {\r\n result.errors.forEach(({ text, location }) => {\r\n console.error(`\u2718 [ERROR] ${text}`);\r\n console.error(` ${location?.file}:${location?.line}:${location?.column}:`);\r\n });\r\n // eslint-disable-next-line no-console\r\n console.log(\"[watch] build finished\");\r\n });\r\n }\r\n };\r\n}\r\n", "import { writeFileSync } from \"node:fs\";\r\nimport type { PluginBuild, Plugin } from \"esbuild\";\r\n\r\nexport function removeStrict(): Plugin {\r\n return {\r\n name: \"remove-strict\",\r\n setup(build: PluginBuild) {\r\n build.initialOptions.write = false;\r\n build.onEnd((result) => {\r\n result?.outputFiles?.forEach(file => {\r\n if (file.path.endsWith(\".js\")) {\r\n const contents = file.text.replace(/\"use strict\";/g, \"\");\r\n if (contents.indexOf(\"use strict\") >= 0) {\r\n console.error(\"remove-strict: \", file.path);\r\n }\r\n writeFileSync(file.path, contents, { encoding: \"utf8\" });\r\n } else {\r\n writeFileSync(file.path, file.contents, { encoding: \"binary\" });\r\n }\r\n });\r\n });\r\n }\r\n };\r\n}\r\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": ["process", "readFileSync", "path", "esbuild", "umdWrapper", "rebuildLogger", "opts", "build", "readFile", "existsSync", "Base91", "Zstd", "tpl", "wasmJsPath", "base91Wasm", "base91CompressedWasm", "compressed", "wasmJsExists", "wrap", "path", "base91", "zstd", "wasm", "compressedWasm", "sfxWasm", "build", "args", "pkg", "readFileSync", "NODE_MJS", "NODE_CJS", "buildWatch", "input", "format", "external", "config", "isDevelopment", "isWatch", "ctx", "rebuildLogger", "sfxWasm", "browserTpl", "output", "globalName", "libraryName", "umdWrapper", "nodeTpl", "neutralTpl", "browserBoth", "nodeBoth", "bothTpl", "readFile", "excludeSourcemap", "opts", "build", "args", "problemMatcher", "build", "result", "text", "location", "writeFileSync", "removeStrict", "build", "result", "file", "contents"]
|
|
7
7
|
}
|
package/dist/sfx-wrapper.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/sfx-wrapper.ts"],
|
|
4
|
-
"sourcesContent": ["import { readFile } from \"fs/promises\";\nimport { existsSync } from \"fs\";\nimport { Base91 } from \"@hpcc-js/wasm-base91\";\nimport { Zstd } from \"@hpcc-js/wasm-zstd\";\nimport type { Plugin, PluginBuild } from \"esbuild\";\n\nfunction tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {\n\n const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;\n const wasmJsExists = existsSync(wasmJsPath);\n\n return `\\\n${compressed ? 'import { decompress } from \"fzstd\";' : \"\"}\n${wasmJsExists ? `import wrapper from \"${wasmJsPath}\";` : \"\"}\n\nconst table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\\`{|}~\"';\n\nfunction decode(raw: string): Uint8Array {\n const len = raw.length;\n const ret: number[] = [];\n\n let b = 0;\n let n = 0;\n let v = -1;\n\n for (let i = 0; i < len; i++) {\n const p = table.indexOf(raw[i]);\n /* istanbul ignore next */\n if (p === -1) continue;\n if (v < 0) {\n v = p;\n } else {\n v += p * 91;\n b |= v << n;\n n += (v & 8191) > 88 ? 13 : 14;\n do {\n ret.push(b & 0xff);\n b >>= 8;\n n -= 8;\n } while (n > 7);\n v = -1;\n }\n }\n\n if (v > -1) {\n ret.push((b | v << n) & 0xff);\n }\n\n return new Uint8Array(ret);\n}\n\nconst blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';\n\nlet g_module: Uint8Array | undefined;\nlet g_wasmBinary: Uint8Array | undefined;\nexport default function() {\n if (!g_wasmBinary) {\n g_wasmBinary = ${compressed ? \"decompress(decode(blobStr))\" : \"decode(blobStr)\"};\n }\n${!wasmJsExists ? `\\\n return g_wasmBinary;\n`: `\\\n if (!g_module) {\n g_module = wrapper({\n wasmBinary: g_wasmBinary,\n locateFile: undefined\n });\n }\n return g_module;\n`}\n}\n\nexport function reset() {\n if (g_module) {\n g_module = undefined;\n }\n} `.trim();\n}\n\nexport async function wrap(path: string) {\n const base91 = await Base91.load();\n const zstd = await Zstd.load();\n\n const wasm = await readFile(path);\n path = path.replace(/\\.js$/, \".xxx\");\n const wasmJsPath = path.replace(/\\.wasm$/, \".js\");\n const base91Wasm = base91.encode(wasm);\n const compressedWasm = zstd.compress(wasm);\n const base91CompressedWasm = base91.encode(compressedWasm);\n\n return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);\n}\n\nexport function sfxWasm(): Plugin {\n return {\n name: \"sfx-wasm\",\n\n setup(build: PluginBuild) {\n\n build.onLoad({ filter: /\\.wasm$/ }, async args => {\n return {\n contents: await wrap(args.path),\n loader: \"ts\",\n };\n });\n }\n };\n}\n"],
|
|
4
|
+
"sourcesContent": ["import { readFile } from \"fs/promises\";\r\nimport { existsSync } from \"fs\";\r\nimport { Base91 } from \"@hpcc-js/wasm-base91\";\r\nimport { Zstd } from \"@hpcc-js/wasm-zstd\";\r\nimport type { Plugin, PluginBuild } from \"esbuild\";\r\n\r\nfunction tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {\r\n\r\n const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;\r\n const wasmJsExists = existsSync(wasmJsPath);\r\n\r\n return `\\\r\n${compressed ? 'import { decompress } from \"fzstd\";' : \"\"}\r\n${wasmJsExists ? `import wrapper from \"${wasmJsPath}\";` : \"\"}\r\n\r\nconst table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\\`{|}~\"';\r\n\r\nfunction decode(raw: string): Uint8Array {\r\n const len = raw.length;\r\n const ret: number[] = [];\r\n\r\n let b = 0;\r\n let n = 0;\r\n let v = -1;\r\n\r\n for (let i = 0; i < len; i++) {\r\n const p = table.indexOf(raw[i]);\r\n /* istanbul ignore next */\r\n if (p === -1) continue;\r\n if (v < 0) {\r\n v = p;\r\n } else {\r\n v += p * 91;\r\n b |= v << n;\r\n n += (v & 8191) > 88 ? 13 : 14;\r\n do {\r\n ret.push(b & 0xff);\r\n b >>= 8;\r\n n -= 8;\r\n } while (n > 7);\r\n v = -1;\r\n }\r\n }\r\n\r\n if (v > -1) {\r\n ret.push((b | v << n) & 0xff);\r\n }\r\n\r\n return new Uint8Array(ret);\r\n}\r\n\r\nconst blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';\r\n\r\nlet g_module: Uint8Array | undefined;\r\nlet g_wasmBinary: Uint8Array | undefined;\r\nexport default function() {\r\n if (!g_wasmBinary) {\r\n g_wasmBinary = ${compressed ? \"decompress(decode(blobStr))\" : \"decode(blobStr)\"};\r\n }\r\n${!wasmJsExists ? `\\\r\n return g_wasmBinary;\r\n`: `\\\r\n if (!g_module) {\r\n g_module = wrapper({\r\n wasmBinary: g_wasmBinary,\r\n locateFile: undefined\r\n });\r\n }\r\n return g_module;\r\n`}\r\n}\r\n\r\nexport function reset() {\r\n if (g_module) {\r\n g_module = undefined;\r\n }\r\n} `.trim();\r\n}\r\n\r\nexport async function wrap(path: string) {\r\n const base91 = await Base91.load();\r\n const zstd = await Zstd.load();\r\n\r\n const wasm = await readFile(path);\r\n path = path.replace(/\\.js$/, \".xxx\");\r\n const wasmJsPath = path.replace(/\\.wasm$/, \".js\");\r\n const base91Wasm = base91.encode(wasm);\r\n const compressedWasm = zstd.compress(wasm);\r\n const base91CompressedWasm = base91.encode(compressedWasm);\r\n\r\n return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);\r\n}\r\n\r\nexport function sfxWasm(): Plugin {\r\n return {\r\n name: \"sfx-wasm\",\r\n\r\n setup(build: PluginBuild) {\r\n\r\n build.onLoad({ filter: /\\.wasm$/ }, async args => {\r\n return {\r\n contents: await wrap(args.path),\r\n loader: \"ts\",\r\n };\r\n });\r\n }\r\n };\r\n}\r\n"],
|
|
5
5
|
"mappings": "AAAA,OAAS,YAAAA,MAAgB,cACzB,OAAS,cAAAC,MAAkB,KAC3B,OAAS,UAAAC,MAAc,uBACvB,OAAS,QAAAC,MAAY,qBAGrB,SAASC,EAAIC,EAAoBC,EAAoBC,EAA8B,CAE/E,IAAMC,EAAcD,EAAqB,OAAS,MAAaD,EAAW,OACpEG,EAAeR,EAAWI,CAAU,EAE1C,MAAO,GACTG,EAAa,sCAAwC,EAAE;AAAA,EACvDC,EAAe,wBAAwBJ,CAAU,KAAO,EAAE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAsCzCG,EAAaD,EAAuBD,CAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAMxCE,EAAa,8BAAgC,iBAAiB;AAAA;AAAA,EAEpFC,EAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAFe;AAAA,CAUjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOG,KAAK,CACT,CAEA,eAAsBC,EAAKC,EAAc,CACrC,IAAMC,EAAS,MAAMV,EAAO,KAAK,EAC3BW,EAAO,MAAMV,EAAK,KAAK,EAEvBW,EAAO,MAAMd,EAASW,CAAI,EAChCA,EAAOA,EAAK,QAAQ,QAAS,MAAM,EACnC,IAAMN,EAAaM,EAAK,QAAQ,UAAW,KAAK,EAC1CL,EAAaM,EAAO,OAAOE,CAAI,EAC/BC,EAAiBF,EAAK,SAASC,CAAI,EACnCP,EAAuBK,EAAO,OAAOG,CAAc,EAEzD,OAAOX,EAAIC,EAAYC,EAAYC,CAAoB,CAC3D,CAEO,SAASS,GAAkB,CAC9B,MAAO,CACH,KAAM,WAEN,MAAMC,EAAoB,CAEtBA,EAAM,OAAO,CAAE,OAAQ,SAAU,EAAG,MAAMC,IAC/B,CACH,SAAU,MAAMR,EAAKQ,EAAK,IAAI,EAC9B,OAAQ,IACZ,EACH,CACL,CACJ,CACJ",
|
|
6
6
|
"names": ["readFile", "existsSync", "Base91", "Zstd", "tpl", "wasmJsPath", "base91Wasm", "base91CompressedWasm", "compressed", "wasmJsExists", "wrap", "path", "base91", "zstd", "wasm", "compressedWasm", "sfxWasm", "build", "args"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hpcc-js/esbuild-plugins",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Various esbuild plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -34,15 +34,14 @@
|
|
|
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",
|
|
37
40
|
"update": "npx --yes npm-check-updates -u -t minor"
|
|
38
41
|
},
|
|
39
42
|
"dependencies": {
|
|
40
|
-
"@hpcc-js/wasm-base91": "1.
|
|
41
|
-
"@hpcc-js/wasm-zstd": "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",
|
|
43
|
+
"@hpcc-js/wasm-base91": "1.13.0",
|
|
44
|
+
"@hpcc-js/wasm-zstd": "1.12.0",
|
|
46
45
|
"fzstd": "0.1.1"
|
|
47
46
|
},
|
|
48
47
|
"keywords": [
|
|
@@ -59,5 +58,5 @@
|
|
|
59
58
|
},
|
|
60
59
|
"homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
|
|
61
60
|
"license": "Apache-2.0",
|
|
62
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "0907b8d15d369c89483954a1d96e2247ba020cb6"
|
|
63
62
|
}
|
package/src/build.ts
CHANGED
|
@@ -1,144 +1,96 @@
|
|
|
1
|
-
import * as process from "process";
|
|
2
|
-
import { readFileSync
|
|
3
|
-
import * as path from "path";
|
|
4
|
-
import * as esbuild from "esbuild";
|
|
5
|
-
import type { BuildOptions, Format
|
|
6
|
-
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
}
|
|
115
|
-
return buildWatch(input, format, external, {
|
|
116
|
-
outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
|
|
117
|
-
platform: "neutral",
|
|
118
|
-
target: "es2022",
|
|
119
|
-
globalName,
|
|
120
|
-
keepNames,
|
|
121
|
-
plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
|
|
122
|
-
} as BuildOptions);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
|
|
126
|
-
return Promise.all([
|
|
127
|
-
browserTpl(input, output, { format: "esm", globalName, libraryName, external }),
|
|
128
|
-
browserTpl(input, output, { format: "umd", globalName, libraryName, external })
|
|
129
|
-
]);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function nodeBoth(input: string, output: string, external: string[] = []) {
|
|
133
|
-
return Promise.all([
|
|
134
|
-
nodeTpl(input, output, { format: "esm", external }),
|
|
135
|
-
nodeTpl(input, output, { format: "cjs", external })
|
|
136
|
-
]);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function bothTpl(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
|
|
140
|
-
return Promise.all([
|
|
141
|
-
browserBoth(input, output, globalName, libraryName, external),
|
|
142
|
-
nodeTpl(input, output, { format: "cjs", external })
|
|
143
|
-
]);
|
|
144
|
-
}
|
|
1
|
+
import * as process from "process";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import * as esbuild from "esbuild";
|
|
5
|
+
import type { BuildOptions, Format } from "esbuild";
|
|
6
|
+
import { umdWrapper } from "esbuild-plugin-umd-wrapper";
|
|
7
|
+
import { rebuildLogger } from "./rebuild-logger.ts";
|
|
8
|
+
import { sfxWasm } from "./sfx-wrapper.ts";
|
|
9
|
+
|
|
10
|
+
export const pkg = JSON.parse(readFileSync(path.join(process.cwd(), "./package.json"), "utf8"));
|
|
11
|
+
export const NODE_MJS = pkg.type === "module" ? "js" : "mjs";
|
|
12
|
+
export const NODE_CJS = pkg.type === "module" ? "cjs" : "js";
|
|
13
|
+
|
|
14
|
+
export async function buildWatch(input: string, format: Format | "umd" = "esm", external: string[] = [], config: BuildOptions, isDevelopment: boolean = process.argv.includes("--development"), isWatch: boolean = process.argv.includes("--watch")): Promise<void> {
|
|
15
|
+
const isProduction = !isDevelopment;
|
|
16
|
+
|
|
17
|
+
const ctx = await esbuild.context({
|
|
18
|
+
entryPoints: [input],
|
|
19
|
+
format: format as Format,
|
|
20
|
+
bundle: true,
|
|
21
|
+
minify: isProduction,
|
|
22
|
+
sourcemap: isDevelopment,
|
|
23
|
+
external,
|
|
24
|
+
...config,
|
|
25
|
+
plugins: [
|
|
26
|
+
...(isWatch ? [rebuildLogger(config)] : []),
|
|
27
|
+
...(config.plugins ?? []),
|
|
28
|
+
sfxWasm()
|
|
29
|
+
]
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
if (isWatch) {
|
|
33
|
+
await ctx.watch();
|
|
34
|
+
} else {
|
|
35
|
+
if (isDevelopment && Array.isArray(config.entryPoints)) {
|
|
36
|
+
// eslint-disable-next-line no-console
|
|
37
|
+
console.log("Start: ", config.entryPoints[0], config.outfile);
|
|
38
|
+
}
|
|
39
|
+
await ctx.rebuild();
|
|
40
|
+
await ctx.dispose();
|
|
41
|
+
if (isDevelopment && Array.isArray(config.entryPoints)) {
|
|
42
|
+
// eslint-disable-next-line no-console
|
|
43
|
+
console.log("Stop: ", config.entryPoints[0], config.outfile);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function browserTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
|
|
49
|
+
return buildWatch(input, format, external, {
|
|
50
|
+
outfile: `${output}.${format === "esm" ? "js" : `${format}.js`}`,
|
|
51
|
+
platform: "browser",
|
|
52
|
+
target: "es2022",
|
|
53
|
+
globalName,
|
|
54
|
+
plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function nodeTpl(input: string, output: string, format: Format | "umd" = "esm", external: string[] = []) {
|
|
59
|
+
return buildWatch(input, format, external, {
|
|
60
|
+
outfile: `${output}.${format === "esm" ? NODE_MJS : NODE_CJS}`,
|
|
61
|
+
platform: "node",
|
|
62
|
+
target: "node20",
|
|
63
|
+
packages: "external"
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function neutralTpl(input: string, output: string, format: Format | "umd" = "esm", globalName?: string, libraryName?: string, external: string[] = []) {
|
|
68
|
+
return buildWatch(input, format, external, {
|
|
69
|
+
outfile: `${output}.${format === "esm" ? "js" : "umd.js"}`,
|
|
70
|
+
platform: "neutral",
|
|
71
|
+
target: "es2022",
|
|
72
|
+
globalName,
|
|
73
|
+
plugins: format === "umd" ? [umdWrapper({ libraryName })] : []
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
|
|
78
|
+
return Promise.all([
|
|
79
|
+
browserTpl(input, output, "esm", globalName, libraryName, external),
|
|
80
|
+
browserTpl(input, output, "umd", globalName, libraryName, external)
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function nodeBoth(input: string, output: string, external: string[] = []) {
|
|
85
|
+
return Promise.all([
|
|
86
|
+
nodeTpl(input, output, "esm", external),
|
|
87
|
+
nodeTpl(input, output, "cjs", external)
|
|
88
|
+
]);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function bothTpl(input: string, output: string, globalName?: string, libraryName?: string, external: string[] = []) {
|
|
92
|
+
return Promise.all([
|
|
93
|
+
browserBoth(input, output, globalName, libraryName, external),
|
|
94
|
+
nodeTpl(input, output, "cjs", external)
|
|
95
|
+
]);
|
|
96
|
+
}
|
package/src/exclude-sourcemap.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
import { readFile } from "fs/promises";
|
|
2
|
-
import type { PluginBuild, Plugin } from "esbuild";
|
|
3
|
-
|
|
4
|
-
export interface ExcludeSourcemapOptions {
|
|
5
|
-
filter: RegExp;
|
|
6
|
-
}
|
|
7
|
-
export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
|
|
8
|
-
return {
|
|
9
|
-
name: "exclude-sourcemap",
|
|
10
|
-
|
|
11
|
-
setup(build: PluginBuild) {
|
|
12
|
-
build.onLoad({ filter: opts.filter }, async args => {
|
|
13
|
-
return {
|
|
14
|
-
contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
|
|
15
|
-
loader: "default",
|
|
16
|
-
};
|
|
17
|
-
});
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import type { PluginBuild, Plugin } from "esbuild";
|
|
3
|
+
|
|
4
|
+
export interface ExcludeSourcemapOptions {
|
|
5
|
+
filter: RegExp;
|
|
6
|
+
}
|
|
7
|
+
export function excludeSourcemap(opts: ExcludeSourcemapOptions): Plugin {
|
|
8
|
+
return {
|
|
9
|
+
name: "exclude-sourcemap",
|
|
10
|
+
|
|
11
|
+
setup(build: PluginBuild) {
|
|
12
|
+
build.onLoad({ filter: opts.filter }, async args => {
|
|
13
|
+
return {
|
|
14
|
+
contents: await readFile(args.path, "utf8") + "\n//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIiJdLCJtYXBwaW5ncyI6IkEifQ==",
|
|
15
|
+
loader: "default",
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export * from "./build.ts";
|
|
2
|
-
export * from "./exclude-sourcemap.ts";
|
|
3
|
-
export * from "./problem-matcher.ts";
|
|
4
|
-
export * from "./rebuild-logger.ts";
|
|
5
|
-
export * from "./remove-strict.ts";
|
|
6
|
-
export * from "./sfx-wrapper.ts";
|
|
7
|
-
export * from "./inline-css.ts";
|
|
1
|
+
export * from "./build.ts";
|
|
2
|
+
export * from "./exclude-sourcemap.ts";
|
|
3
|
+
export * from "./problem-matcher.ts";
|
|
4
|
+
export * from "./rebuild-logger.ts";
|
|
5
|
+
export * from "./remove-strict.ts";
|
|
6
|
+
export * from "./sfx-wrapper.ts";
|
package/src/problem-matcher.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { PluginBuild, Plugin } from "esbuild";
|
|
2
|
-
|
|
3
|
-
export function problemMatcher(): Plugin {
|
|
4
|
-
return {
|
|
5
|
-
name: "problem-matcher",
|
|
6
|
-
|
|
7
|
-
setup(build: PluginBuild) {
|
|
8
|
-
|
|
9
|
-
build.onStart(() => {
|
|
10
|
-
// eslint-disable-next-line no-console
|
|
11
|
-
console.log("[watch] build started");
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
build.onEnd((result) => {
|
|
15
|
-
result.errors.forEach(({ text, location }) => {
|
|
16
|
-
console.error(`✘ [ERROR] ${text}`);
|
|
17
|
-
console.error(` ${location?.file}:${location?.line}:${location?.column}:`);
|
|
18
|
-
});
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.log("[watch] build finished");
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
1
|
+
import type { PluginBuild, Plugin } from "esbuild";
|
|
2
|
+
|
|
3
|
+
export function problemMatcher(): Plugin {
|
|
4
|
+
return {
|
|
5
|
+
name: "problem-matcher",
|
|
6
|
+
|
|
7
|
+
setup(build: PluginBuild) {
|
|
8
|
+
|
|
9
|
+
build.onStart(() => {
|
|
10
|
+
// eslint-disable-next-line no-console
|
|
11
|
+
console.log("[watch] build started");
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
build.onEnd((result) => {
|
|
15
|
+
result.errors.forEach(({ text, location }) => {
|
|
16
|
+
console.error(`✘ [ERROR] ${text}`);
|
|
17
|
+
console.error(` ${location?.file}:${location?.line}:${location?.column}:`);
|
|
18
|
+
});
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.log("[watch] build finished");
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
package/src/rebuild-logger.ts
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { PluginBuild, Plugin } from "esbuild";
|
|
2
|
-
|
|
3
|
-
export interface RebuildLoggerOptions {
|
|
4
|
-
outfile?: string;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export function rebuildLogger(opts: RebuildLoggerOptions): Plugin {
|
|
8
|
-
return {
|
|
9
|
-
name: "rebuild-logger",
|
|
10
|
-
|
|
11
|
-
setup(build: PluginBuild) {
|
|
12
|
-
|
|
13
|
-
build.onStart(() => {
|
|
14
|
-
// eslint-disable-next-line no-console
|
|
15
|
-
console.log("[watch] build started");
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
build.onEnd(() => {
|
|
19
|
-
// eslint-disable-next-line no-console
|
|
20
|
-
console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
|
1
|
+
import type { PluginBuild, Plugin } from "esbuild";
|
|
2
|
+
|
|
3
|
+
export interface RebuildLoggerOptions {
|
|
4
|
+
outfile?: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export function rebuildLogger(opts: RebuildLoggerOptions): Plugin {
|
|
8
|
+
return {
|
|
9
|
+
name: "rebuild-logger",
|
|
10
|
+
|
|
11
|
+
setup(build: PluginBuild) {
|
|
12
|
+
|
|
13
|
+
build.onStart(() => {
|
|
14
|
+
// eslint-disable-next-line no-console
|
|
15
|
+
console.log("[watch] build started");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
build.onEnd(() => {
|
|
19
|
+
// eslint-disable-next-line no-console
|
|
20
|
+
console.log(`Rebuilt ${opts.outfile ?? "Unknown"}`);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
package/src/remove-strict.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
|
-
import { writeFileSync } from "node:fs";
|
|
2
|
-
import type { PluginBuild, Plugin } from "esbuild";
|
|
3
|
-
|
|
4
|
-
export function removeStrict(): Plugin {
|
|
5
|
-
return {
|
|
6
|
-
name: "remove-strict",
|
|
7
|
-
setup(build: PluginBuild) {
|
|
8
|
-
build.initialOptions.write = false;
|
|
9
|
-
build.onEnd((result) => {
|
|
10
|
-
result?.outputFiles?.forEach(file => {
|
|
11
|
-
if (file.path.endsWith(".js")) {
|
|
12
|
-
const contents = file.text.replace(/"use strict";/g, "");
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import type { PluginBuild, Plugin } from "esbuild";
|
|
3
|
+
|
|
4
|
+
export function removeStrict(): Plugin {
|
|
5
|
+
return {
|
|
6
|
+
name: "remove-strict",
|
|
7
|
+
setup(build: PluginBuild) {
|
|
8
|
+
build.initialOptions.write = false;
|
|
9
|
+
build.onEnd((result) => {
|
|
10
|
+
result?.outputFiles?.forEach(file => {
|
|
11
|
+
if (file.path.endsWith(".js")) {
|
|
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
|
+
writeFileSync(file.path, contents, { encoding: "utf8" });
|
|
17
|
+
} else {
|
|
18
|
+
writeFileSync(file.path, file.contents, { encoding: "binary" });
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
package/src/sfx-wrapper.ts
CHANGED
|
@@ -1,108 +1,108 @@
|
|
|
1
|
-
import { readFile } from "fs/promises";
|
|
2
|
-
import { existsSync } from "fs";
|
|
3
|
-
import { Base91 } from "@hpcc-js/wasm-base91";
|
|
4
|
-
import { Zstd } from "@hpcc-js/wasm-zstd";
|
|
5
|
-
import type { Plugin, PluginBuild } from "esbuild";
|
|
6
|
-
|
|
7
|
-
function tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {
|
|
8
|
-
|
|
9
|
-
const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;
|
|
10
|
-
const wasmJsExists = existsSync(wasmJsPath);
|
|
11
|
-
|
|
12
|
-
return `\
|
|
13
|
-
${compressed ? 'import { decompress } from "fzstd";' : ""}
|
|
14
|
-
${wasmJsExists ? `import wrapper from "${wasmJsPath}";` : ""}
|
|
15
|
-
|
|
16
|
-
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
|
|
17
|
-
|
|
18
|
-
function decode(raw: string): Uint8Array {
|
|
19
|
-
const len = raw.length;
|
|
20
|
-
const ret: number[] = [];
|
|
21
|
-
|
|
22
|
-
let b = 0;
|
|
23
|
-
let n = 0;
|
|
24
|
-
let v = -1;
|
|
25
|
-
|
|
26
|
-
for (let i = 0; i < len; i++) {
|
|
27
|
-
const p = table.indexOf(raw[i]);
|
|
28
|
-
/* istanbul ignore next */
|
|
29
|
-
if (p === -1) continue;
|
|
30
|
-
if (v < 0) {
|
|
31
|
-
v = p;
|
|
32
|
-
} else {
|
|
33
|
-
v += p * 91;
|
|
34
|
-
b |= v << n;
|
|
35
|
-
n += (v & 8191) > 88 ? 13 : 14;
|
|
36
|
-
do {
|
|
37
|
-
ret.push(b & 0xff);
|
|
38
|
-
b >>= 8;
|
|
39
|
-
n -= 8;
|
|
40
|
-
} while (n > 7);
|
|
41
|
-
v = -1;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (v > -1) {
|
|
46
|
-
ret.push((b | v << n) & 0xff);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return new Uint8Array(ret);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';
|
|
53
|
-
|
|
54
|
-
let g_module: Uint8Array | undefined;
|
|
55
|
-
let g_wasmBinary: Uint8Array | undefined;
|
|
56
|
-
export default function() {
|
|
57
|
-
if (!g_wasmBinary) {
|
|
58
|
-
g_wasmBinary = ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
|
|
59
|
-
}
|
|
60
|
-
${!wasmJsExists ? `\
|
|
61
|
-
return g_wasmBinary;
|
|
62
|
-
`: `\
|
|
63
|
-
if (!g_module) {
|
|
64
|
-
g_module = wrapper({
|
|
65
|
-
wasmBinary: g_wasmBinary,
|
|
66
|
-
locateFile: undefined
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
return g_module;
|
|
70
|
-
`}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function reset() {
|
|
74
|
-
if (g_module) {
|
|
75
|
-
g_module = undefined;
|
|
76
|
-
}
|
|
77
|
-
} `.trim();
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export async function wrap(path: string) {
|
|
81
|
-
const base91 = await Base91.load();
|
|
82
|
-
const zstd = await Zstd.load();
|
|
83
|
-
|
|
84
|
-
const wasm = await readFile(path);
|
|
85
|
-
path = path.replace(/\.js$/, ".xxx");
|
|
86
|
-
const wasmJsPath = path.replace(/\.wasm$/, ".js");
|
|
87
|
-
const base91Wasm = base91.encode(wasm);
|
|
88
|
-
const compressedWasm = zstd.compress(wasm);
|
|
89
|
-
const base91CompressedWasm = base91.encode(compressedWasm);
|
|
90
|
-
|
|
91
|
-
return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
export function sfxWasm(): Plugin {
|
|
95
|
-
return {
|
|
96
|
-
name: "sfx-wasm",
|
|
97
|
-
|
|
98
|
-
setup(build: PluginBuild) {
|
|
99
|
-
|
|
100
|
-
build.onLoad({ filter: /\.wasm$/ }, async args => {
|
|
101
|
-
return {
|
|
102
|
-
contents: await wrap(args.path),
|
|
103
|
-
loader: "ts",
|
|
104
|
-
};
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
}
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { Base91 } from "@hpcc-js/wasm-base91";
|
|
4
|
+
import { Zstd } from "@hpcc-js/wasm-zstd";
|
|
5
|
+
import type { Plugin, PluginBuild } from "esbuild";
|
|
6
|
+
|
|
7
|
+
function tpl(wasmJsPath: string, base91Wasm: string, base91CompressedWasm: string) {
|
|
8
|
+
|
|
9
|
+
const compressed = (base91CompressedWasm.length + 8 * 1024) <= base91Wasm.length;
|
|
10
|
+
const wasmJsExists = existsSync(wasmJsPath);
|
|
11
|
+
|
|
12
|
+
return `\
|
|
13
|
+
${compressed ? 'import { decompress } from "fzstd";' : ""}
|
|
14
|
+
${wasmJsExists ? `import wrapper from "${wasmJsPath}";` : ""}
|
|
15
|
+
|
|
16
|
+
const table = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_\`{|}~"';
|
|
17
|
+
|
|
18
|
+
function decode(raw: string): Uint8Array {
|
|
19
|
+
const len = raw.length;
|
|
20
|
+
const ret: number[] = [];
|
|
21
|
+
|
|
22
|
+
let b = 0;
|
|
23
|
+
let n = 0;
|
|
24
|
+
let v = -1;
|
|
25
|
+
|
|
26
|
+
for (let i = 0; i < len; i++) {
|
|
27
|
+
const p = table.indexOf(raw[i]);
|
|
28
|
+
/* istanbul ignore next */
|
|
29
|
+
if (p === -1) continue;
|
|
30
|
+
if (v < 0) {
|
|
31
|
+
v = p;
|
|
32
|
+
} else {
|
|
33
|
+
v += p * 91;
|
|
34
|
+
b |= v << n;
|
|
35
|
+
n += (v & 8191) > 88 ? 13 : 14;
|
|
36
|
+
do {
|
|
37
|
+
ret.push(b & 0xff);
|
|
38
|
+
b >>= 8;
|
|
39
|
+
n -= 8;
|
|
40
|
+
} while (n > 7);
|
|
41
|
+
v = -1;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (v > -1) {
|
|
46
|
+
ret.push((b | v << n) & 0xff);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return new Uint8Array(ret);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const blobStr = '${compressed ? base91CompressedWasm : base91Wasm}';
|
|
53
|
+
|
|
54
|
+
let g_module: Uint8Array | undefined;
|
|
55
|
+
let g_wasmBinary: Uint8Array | undefined;
|
|
56
|
+
export default function() {
|
|
57
|
+
if (!g_wasmBinary) {
|
|
58
|
+
g_wasmBinary = ${compressed ? "decompress(decode(blobStr))" : "decode(blobStr)"};
|
|
59
|
+
}
|
|
60
|
+
${!wasmJsExists ? `\
|
|
61
|
+
return g_wasmBinary;
|
|
62
|
+
`: `\
|
|
63
|
+
if (!g_module) {
|
|
64
|
+
g_module = wrapper({
|
|
65
|
+
wasmBinary: g_wasmBinary,
|
|
66
|
+
locateFile: undefined
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return g_module;
|
|
70
|
+
`}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function reset() {
|
|
74
|
+
if (g_module) {
|
|
75
|
+
g_module = undefined;
|
|
76
|
+
}
|
|
77
|
+
} `.trim();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export async function wrap(path: string) {
|
|
81
|
+
const base91 = await Base91.load();
|
|
82
|
+
const zstd = await Zstd.load();
|
|
83
|
+
|
|
84
|
+
const wasm = await readFile(path);
|
|
85
|
+
path = path.replace(/\.js$/, ".xxx");
|
|
86
|
+
const wasmJsPath = path.replace(/\.wasm$/, ".js");
|
|
87
|
+
const base91Wasm = base91.encode(wasm);
|
|
88
|
+
const compressedWasm = zstd.compress(wasm);
|
|
89
|
+
const base91CompressedWasm = base91.encode(compressedWasm);
|
|
90
|
+
|
|
91
|
+
return tpl(wasmJsPath, base91Wasm, base91CompressedWasm);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export function sfxWasm(): Plugin {
|
|
95
|
+
return {
|
|
96
|
+
name: "sfx-wasm",
|
|
97
|
+
|
|
98
|
+
setup(build: PluginBuild) {
|
|
99
|
+
|
|
100
|
+
build.onLoad({ filter: /\.wasm$/ }, async args => {
|
|
101
|
+
return {
|
|
102
|
+
contents: await wrap(args.path),
|
|
103
|
+
loader: "ts",
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
package/types/build.d.ts
CHANGED
|
@@ -1,28 +1,11 @@
|
|
|
1
|
-
import type { BuildOptions, Format
|
|
2
|
-
export declare const copyStaticFiles: Plugin;
|
|
1
|
+
import type { BuildOptions, Format } from "esbuild";
|
|
3
2
|
export declare const pkg: any;
|
|
4
3
|
export declare const NODE_MJS: string;
|
|
5
4
|
export declare const NODE_CJS: string;
|
|
6
5
|
export declare function buildWatch(input: string, format: (Format | "umd") | undefined, external: string[] | undefined, config: BuildOptions, isDevelopment?: boolean, isWatch?: boolean): Promise<void>;
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
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>;
|
|
6
|
+
export declare function browserTpl(input: string, output: string, format?: Format | "umd", globalName?: string, libraryName?: string, external?: string[]): Promise<void>;
|
|
7
|
+
export declare function nodeTpl(input: string, output: string, format?: Format | "umd", external?: string[]): Promise<void>;
|
|
8
|
+
export declare function neutralTpl(input: string, output: string, format?: Format | "umd", globalName?: string, libraryName?: string, external?: string[]): Promise<void>;
|
|
26
9
|
export declare function browserBoth(input: string, output: string, globalName?: string, libraryName?: string, external?: string[]): Promise<[void, void]>;
|
|
27
10
|
export declare function nodeBoth(input: string, output: string, external?: string[]): Promise<[void, void]>;
|
|
28
11
|
export declare function bothTpl(input: string, output: string, globalName?: string, libraryName?: string, external?: string[]): Promise<[[void, void], void]>;
|
package/types/index.d.ts
CHANGED
package/src/inline-css.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
-
|