Add local-publish script for the Node package

nodejs/scripts/publish.mjs builds the wasm (wasm-pack), runs the smoke test,
then `npm publish` to a configurable registry (default a local one at
http://localhost:4873; override via --registry= or NPM_REGISTRY). Supports
--dry-run. Wired as `npm run publish:local`.
This commit is contained in:
Chris Tsang
2026-07-24 13:37:25 +01:00
parent 170b0322a4
commit 42f94f0d15
2 changed files with 43 additions and 0 deletions
+1
View File
@@ -15,6 +15,7 @@
"scripts": {
"build": "wasm-pack build --target nodejs --out-dir pkg",
"test": "node test.js",
"publish:local": "node scripts/publish.mjs",
"prepublishOnly": "npm run build"
},
"keywords": ["svg", "vectorization", "raster", "wasm", "computer-graphics"],
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env node
// Build the wasm package and publish it, by default to a local npm registry
// (e.g. a Verdaccio instance at http://localhost:4873).
//
// node scripts/publish.mjs # publish to the local registry
// node scripts/publish.mjs --dry-run # build + pack, don't publish
// node scripts/publish.mjs --registry=http://... # override the registry
// NPM_REGISTRY=http://... node scripts/publish.mjs
//
// The registry may also be given via the NPM_REGISTRY env var.
import { execFileSync } from 'node:child_process';
import { fileURLToPath } from 'node:url';
import { dirname, resolve } from 'node:path';
const pkgDir = resolve(dirname(fileURLToPath(import.meta.url)), '..');
const args = process.argv.slice(2);
const dryRun = args.includes('--dry-run');
const regArg = args.find((a) => a.startsWith('--registry='));
const registry =
(regArg && regArg.slice('--registry='.length)) ||
process.env.NPM_REGISTRY ||
'http://localhost:4873';
function run(cmd, cmdArgs) {
console.log(`\n$ ${cmd} ${cmdArgs.join(' ')}`);
execFileSync(cmd, cmdArgs, { stdio: 'inherit', cwd: pkgDir });
}
// 1. Fresh wasm build (regenerates pkg/).
run('wasm-pack', ['build', '--target', 'nodejs', '--out-dir', 'pkg']);
// 2. Sanity check before publishing.
run('node', ['test.js']);
// 3. Publish (or dry-run) to the chosen registry.
const publishArgs = ['publish', '--registry', registry];
if (dryRun) publishArgs.push('--dry-run');
run('npm', publishArgs);
console.log(`\n${dryRun ? 'dry-run for' : 'published to'} ${registry}`);