From: Chris Duncan Date: Wed, 18 Mar 2026 21:39:16 +0000 (-0700) Subject: Add NodeJS support and update tests. X-Git-Tag: v1.0.0~6 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=e2096e3eadc3b90b3fd8519919400a4f2e29e745;p=nano25519.git 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. --- 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