From e2096e3eadc3b90b3fd8519919400a4f2e29e745 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Wed, 18 Mar 2026 14:39:16 -0700 Subject: [PATCH] Add NodeJS support and update tests. Fix node worker construction, message handling, and parent port import. Expand esbuild config functionality and build options. Move test vectors to separate file, rename .env vector import, and add tests. --- esbuild.mjs | 36 ---------------- esbuild/config.mjs | 51 ++++++++++++++++++++++ esbuild/dev.mjs | 8 ++++ esbuild/prod.mjs | 8 ++++ index.html | 105 ++++++++++++++++++++++++++++++--------------- index.ts | 88 +++++++++++++++++++++++++++---------- package.json | 8 ++-- test.mjs | 52 ++++++++++++++++------ vectors.mjs | 26 +++++++++++ 9 files changed, 272 insertions(+), 110 deletions(-) delete mode 100644 esbuild.mjs create mode 100644 esbuild/config.mjs create mode 100644 esbuild/dev.mjs create mode 100644 esbuild/prod.mjs create mode 100644 vectors.mjs diff --git a/esbuild.mjs b/esbuild.mjs deleted file mode 100644 index 8e8240e..0000000 --- a/esbuild.mjs +++ /dev/null @@ -1,36 +0,0 @@ -//! SPDX-FileCopyrightText: 2026 Chris Duncan -//! SPDX-License-Identifier: GPL-3.0-or-later - -import { build } from 'esbuild' - -/** - * @type import("esbuild").BuildOptions - */ -const common = { - bundle: true, - loader: { - '.wasm': 'binary' - }, - format: 'esm', - legalComments: 'inline', - outdir: 'dist', - target: 'esnext', - dropLabels: process.env.NODE_ENV === 'development' ? [] : [ 'LOG' ] -} - -await build({ - ...common, - platform: 'browser', - entryPoints: [ - { in: './index.ts', out: 'browser' } - ] -}) - -await build({ - ...common, - platform: 'node', - entryPoints: [ - { in: './index.ts', out: 'node' } - ], - packages: 'external' -}) diff --git a/esbuild/config.mjs b/esbuild/config.mjs new file mode 100644 index 0000000..dabf9d1 --- /dev/null +++ b/esbuild/config.mjs @@ -0,0 +1,51 @@ +//! SPDX-FileCopyrightText: 2026 Chris Duncan +//! SPDX-License-Identifier: GPL-3.0-or-later + +/** + * @type import("esbuild").BuildOptions + */ +const commonOptions = { + bundle: true, + loader: { + '.wasm': 'binary' + }, + format: 'esm', + legalComments: 'inline', + outdir: 'dist', +} + +/** + * @type {import('esbuild').BuildOptions} + */ +export const prodOptions = { + drop: ['console', 'debugger'], + minify: true, + sourcemap: false +} + +/** + * @type import("esbuild").BuildOptions + */ +export const browserOptions = { + ...commonOptions, + platform: 'browser', + target: 'esnext', + entryPoints: [ + { in: './index.ts', out: 'browser' } + ], + dropLabels: ['NODE'] +} + +/** + * @type import("esbuild").BuildOptions + */ +export const nodeOptions = { + ...commonOptions, + platform: 'node', + target: 'node22', + entryPoints: [ + { in: './index.ts', out: 'node' } + ], + packages: 'external', + dropLabels: ['BROWSER'] +} diff --git a/esbuild/dev.mjs b/esbuild/dev.mjs new file mode 100644 index 0000000..e632a0b --- /dev/null +++ b/esbuild/dev.mjs @@ -0,0 +1,8 @@ +//! SPDX-FileCopyrightText: 2026 Chris Duncan +//! SPDX-License-Identifier: GPL-3.0-or-later + +import { build } from 'esbuild' +import { browserOptions, nodeOptions } from './config.mjs' + +await build(browserOptions) +await build(nodeOptions) diff --git a/esbuild/prod.mjs b/esbuild/prod.mjs new file mode 100644 index 0000000..26ded3e --- /dev/null +++ b/esbuild/prod.mjs @@ -0,0 +1,8 @@ +//! SPDX-FileCopyrightText: 2025 Chris Duncan +//! SPDX-License-Identifier: GPL-3.0-or-later + +import { build } from 'esbuild' +import { browserOptions, nodeOptions, prodOptions } from './config.mjs' + +await build({ ...browserOptions, ...prodOptions }) +await build({ ...nodeOptions, ...prodOptions }) diff --git a/index.html b/index.html index 8be9240..c299e53 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@ SPDX-License-Identifier: GPL-3.0-or-later