]> git.codecow.com Git - libnemo.git/commitdiff
Consolidate browser and node build scripts.
authorChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 15:20:31 +0000 (08:20 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 23 Jul 2025 15:20:31 +0000 (08:20 -0700)
esbuild-common.mjs [deleted file]
esbuild-dev.mjs [deleted file]
esbuild-node.mjs [deleted file]
esbuild-prod.mjs
esbuild.mjs [new file with mode: 0644]
package.json

diff --git a/esbuild-common.mjs b/esbuild-common.mjs
deleted file mode 100644 (file)
index 8e786eb..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
-//! SPDX-License-Identifier: GPL-3.0-or-later
-
-/**
-* @type {import('esbuild').BuildOptions}
-*/
-export const options = {
-       bundle: true,
-       platform: 'browser',
-       entryPoints: [
-               { in: './src/main.ts', out: 'main.dev' },
-               { in: './src/types.d.ts', out: 'types.d' }
-       ],
-       loader: {
-               '.d.ts': 'copy'
-       },
-       format: 'esm',
-       legalComments: 'inline',
-       outdir: 'dist',
-       target: 'esnext'
-}
diff --git a/esbuild-dev.mjs b/esbuild-dev.mjs
deleted file mode 100644 (file)
index 2a4f1d1..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
-//! SPDX-License-Identifier: GPL-3.0-or-later
-
-import { build } from 'esbuild'
-import { options } from './esbuild-common.mjs'
-
-options.dropLabels = ['NODE']
-options.inject = ['./buffer.mjs']
-await build(options)
diff --git a/esbuild-node.mjs b/esbuild-node.mjs
deleted file mode 100644 (file)
index 21e8d81..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
-//! SPDX-License-Identifier: GPL-3.0-or-later
-
-import { build } from 'esbuild'
-import { options } from './esbuild-common.mjs'
-
-options.dropLabels = ['BROWSER']
-options.external = ['node:worker_threads']
-await build(options)
index 48c565422d2e139baba4ca8c0c80470906fe2f1c..50ff3590072ef941e15f68c762d949cda94fb65a 100644 (file)
@@ -2,32 +2,14 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
 import { build } from 'esbuild'
-import { options } from './esbuild-common.mjs'
+import { browserOptions, nodeOptions } from './esbuild.mjs'
 
-// Shared properties
-options.drop = ['console', 'debugger']
-options.minifySyntax = true
-options.minifyWhitespace = true
-
-// Node build
-const nodeOptions = {
-       ...options,
-       entryPoints: [
-               { in: './src/main.ts', out: 'nodejs.min' }
-       ],
-       dropLabels: ['BROWSER'],
-       external: ['node:worker_threads']
-}
-await build(nodeOptions)
+browserOptions.drop = nodeOptions.drop = ['console', 'debugger']
+browserOptions.minifySyntax = nodeOptions.minifySyntax = true
+browserOptions.minifyWhitespace = nodeOptions.minifyWhitespace = true
 
 // Browser build
-const browserOptions = {
-       ...options,
-       entryPoints: [
-               { in: './src/main.ts', out: 'browser.min' },
-               { in: './src/types.d.ts', out: 'types.d' }
-       ],
-       dropLabels: ['NODE'],
-       inject: ['./buffer.mjs']
-}
 await build(browserOptions)
+
+// Node build
+await build(nodeOptions)
diff --git a/esbuild.mjs b/esbuild.mjs
new file mode 100644 (file)
index 0000000..42c4a76
--- /dev/null
@@ -0,0 +1,42 @@
+//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@zoso.dev>
+//! SPDX-License-Identifier: GPL-3.0-or-later
+
+import { build } from 'esbuild'
+
+/**
+* @type {import('esbuild').BuildOptions}
+*/
+const sharedOptions = {
+       bundle: true,
+       platform: 'browser',
+       loader: {
+               '.d.ts': 'copy'
+       },
+       format: 'esm',
+       legalComments: 'inline',
+       outdir: 'dist',
+       target: 'esnext'
+}
+
+// Browser build
+export const browserOptions = {
+       ...sharedOptions,
+       entryPoints: [
+               { in: './src/main.ts', out: 'browser.min' },
+               { in: './src/types.d.ts', out: 'types.d' }
+       ],
+       dropLabels: ['NODE'],
+       inject: ['./buffer.mjs']
+}
+await build(browserOptions)
+
+// Node build
+export const nodeOptions = {
+       ...sharedOptions,
+       entryPoints: [
+               { in: './src/main.ts', out: 'nodejs.min' }
+       ],
+       dropLabels: ['BROWSER'],
+       external: ['node:worker_threads']
+}
+await build(nodeOptions)
index 1284909094c9afa93382dc279c9e9b299627a33e..11f8bd226c6c8d72da7cd5d4acdcdeec3ebd000c 100644 (file)
        },
        "scripts": {
                "clean": "rm -rf {dist,types} && tsc",
-               "build": "npm run clean && node esbuild-dev.mjs",
-               "build:node": "npm run clean && node esbuild-node.mjs",
+               "build": "npm run clean && node esbuild.mjs",
                "build:prod": "npm run clean && node esbuild-prod.mjs",
                "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": "npm run build && npm run test:node",
                "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"
+               "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 ./coverage/ && rm ./coverage.info && xdg-open ./coverage/libnemo/index.html",
+               "test:node": "node --test --test-force-exit --no-experimental-strip-types --env-file .env",
+               "test:prod": "npm run build:prod && npm run test:node"
        },
        "imports": {
                "#src/*": "./src/*",