From: Chris Duncan Date: Wed, 23 Jul 2025 05:32:26 +0000 (-0700) Subject: Modify scripts to publish both browser and node builds, and pass tests before publishing. X-Git-Tag: v0.10.5~55^2~29 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=19ac9785763b1285992c3fd1bae8016ef4c69990;p=libnemo.git Modify scripts to publish both browser and node builds, and pass tests before publishing. --- diff --git a/esbuild-common.mjs b/esbuild-common.mjs index 3966def..8e786eb 100644 --- a/esbuild-common.mjs +++ b/esbuild-common.mjs @@ -8,7 +8,7 @@ export const options = { bundle: true, platform: 'browser', entryPoints: [ - { in: './src/main.ts', out: 'main.min' }, + { in: './src/main.ts', out: 'main.dev' }, { in: './src/types.d.ts', out: 'types.d' } ], loader: { diff --git a/esbuild-prod.mjs b/esbuild-prod.mjs index a4b534c..64ee6e0 100644 --- a/esbuild-prod.mjs +++ b/esbuild-prod.mjs @@ -4,7 +4,24 @@ import { build } from 'esbuild' import { options } from './esbuild-common.mjs' +// Shared properties options.drop = ['console', 'debugger'] +options.minifySyntax = true +options.minifyWhitespace = true + +// Node build +options.entryPoints = [ + { in: './src/main.ts', out: 'nodejs.min' } +] +options.dropLabels = ['BROWSER'] +options.external = ['node:worker_threads'] +await build(options) + +// Browser build +options.entryPoints = [ + { in: './src/main.ts', out: 'browser.min' }, + { in: './src/types.d.ts', out: 'types.d' } +] options.dropLabels = ['NODE'] options.inject = ['./buffer.mjs'] await build(options) diff --git a/package.json b/package.json index f4adfb4..1284909 100644 --- a/package.json +++ b/package.json @@ -46,9 +46,10 @@ "build": "npm run clean && node esbuild-dev.mjs", "build:node": "npm run clean && node esbuild-node.mjs", "build:prod": "npm run clean && node esbuild-prod.mjs", - "publish": "npm run build:prod", + "prepublishOnly": "npm run test:prod", "test": "npm run build", "test:node": "npm run build:node && node --test --test-force-exit --no-experimental-strip-types --env-file .env", + "test:prod": "npm run build:prod && node --test --test-force-exit --no-experimental-strip-types --env-file .env", "test:coverage": "npm run test:node -- --experimental-test-coverage", "test:coverage:report": "npm run test:coverage -- --test-reporter=lcov --test-reporter-destination=coverage.info && genhtml coverage.info --flat --dark-mode --keep-going --output-directory test/coverage && rm coverage.info && xdg-open ./test/coverage/libnemo/index.html" },