@hpcc-js/esbuild-plugins 1.2.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 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.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/build.ts", "../src/rebuild-logger.ts", "../src/sfx-wrapper.ts", "../src/exclude-sourcemap.ts", "../src/problem-matcher.ts", "../src/remove-strict.ts"],
4
- "sourcesContent": ["import * as process from \"process\";\nimport { readFileSync } from \"fs\";\nimport * as path from \"path\";\nimport * as esbuild from \"esbuild\";\nimport type { BuildOptions, Format } from \"esbuild\";\nimport { umdWrapper } from \"esbuild-plugin-umd-wrapper\";\nimport { 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"],
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
5
  "mappings": "AAAA,UAAYA,MAAa,UACzB,OAAS,gBAAAC,MAAoB,KAC7B,UAAYC,MAAU,OACtB,UAAYC,MAAa,UAEzB,OAAS,cAAAC,MAAkB,6BCCpB,SAASC,EAAcC,EAAoC,CAC9D,MAAO,CACH,KAAM,iBAEN,MAAMC,EAAoB,CAEtBA,EAAM,QAAQ,IAAM,CAEhB,QAAQ,IAAI,uBAAuB,CACvC,CAAC,EAEDA,EAAM,MAAM,IAAM,CAEd,QAAQ,IAAI,WAAWD,EAAK,SAAW,SAAS,EAAE,CACtD,CAAC,CACL,CACJ,CACJ,CCvBA,OAAS,YAAAE,MAAgB,cACzB,OAAS,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;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M,OAAOC,GAAU,IAAI,IAAIA,GAAU,IAAI,IAAIA,GAAU,MAAM,GAAG,CAChF,CAAC,EAED,QAAQ,IAAI,wBAAwB,CACxC,CAAC,CACL,CACJ,CACJ,CCvBA,OAAS,iBAAAC,MAAqB,UAGvB,SAASC,GAAuB,CACnC,MAAO,CACH,KAAM,gBACN,MAAMC,EAAoB,CACtBA,EAAM,eAAe,MAAQ,GAC7BA,EAAM,MAAOC,GAAW,CACpBA,GAAQ,aAAa,QAAQC,GAAQ,CACjC,GAAIA,EAAK,KAAK,SAAS,KAAK,EAAG,CAC3B,IAAMC,EAAWD,EAAK,KAAK,QAAQ,iBAAkB,EAAE,EACnDC,EAAS,QAAQ,YAAY,GAAK,GAClC,QAAQ,MAAM,mBAAoBD,EAAK,IAAI,EAE/CJ,EAAcI,EAAK,KAAMC,EAAU,CAAE,SAAU,MAAO,CAAC,CAC3D,MACIL,EAAcI,EAAK,KAAMA,EAAK,SAAU,CAAE,SAAU,QAAS,CAAC,CAEtE,CAAC,CACL,CAAC,CACL,CACJ,CACJ",
6
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
  }
@@ -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,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ACJ,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.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Various esbuild plugins",
5
5
  "type": "module",
6
6
  "exports": {
@@ -40,8 +40,8 @@
40
40
  "update": "npx --yes npm-check-updates -u -t minor"
41
41
  },
42
42
  "dependencies": {
43
- "@hpcc-js/wasm-base91": "1.3.0",
44
- "@hpcc-js/wasm-zstd": "1.2.0",
43
+ "@hpcc-js/wasm-base91": "1.13.0",
44
+ "@hpcc-js/wasm-zstd": "1.12.0",
45
45
  "fzstd": "0.1.1"
46
46
  },
47
47
  "keywords": [
@@ -58,5 +58,5 @@
58
58
  },
59
59
  "homepage": "https://hpcc-systems.github.io/hpcc-js-wasm/",
60
60
  "license": "Apache-2.0",
61
- "gitHead": "fbbef050700b0e9d76ef99714856383d95155149"
61
+ "gitHead": "0907b8d15d369c89483954a1d96e2247ba020cb6"
62
62
  }
package/src/build.ts CHANGED
@@ -1,96 +1,96 @@
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
- }
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
+ }
@@ -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,6 +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";
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";
@@ -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
+ }
@@ -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
+ }
@@ -1,24 +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
- 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
- }
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
+ }
@@ -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
+ }