]> git.codecow.com Git - nano-pow.git/commitdiff
Refactor builds and exports
authorChris Duncan <chris@codecow.com>
Sun, 5 Apr 2026 09:01:19 +0000 (02:01 -0700)
committerChris Duncan <chris@codecow.com>
Sun, 5 Apr 2026 09:01:19 +0000 (02:01 -0700)
esbuild.mjs
package.json
src/bin/server.ts
src/lib/generate/index.ts
tsconfig.json

index a0ff603713c84a990f6d0b4c399203920534a399..6b61e33f08beb566ee09b730d71eca9ab1ff29ca 100644 (file)
@@ -3,22 +3,17 @@
 
 import { build } from 'esbuild'
 import { glsl } from 'esbuild-plugin-glsl'
+/** @import { BuildOptions } from 'esbuild' */
 
-await build({
+/** @type BuildOptions */
+const sharedOptions = {
        bundle: true,
-       platform: 'browser',
-       entryPoints: [
-               { in: './src/main.ts', out: 'main.min' },
-               { in: './src/types.d.ts', out: 'types.d' }
-       ],
+       format: 'esm',
+       outdir: 'dist',
        loader: {
-               '.d.ts': 'copy',
                '.wasm': 'binary'
        },
-       format: 'esm',
        legalComments: 'inline',
-       outdir: 'dist',
-       target: 'es2022',
        dropLabels: process.env.NODE_ENV === 'development' ? [] : ['LOG'],
        plugins: [
                glsl({
@@ -26,18 +21,30 @@ await build({
                        preserveLegalComments: true
                })
        ]
-})
+}
 
-await build({
-       bundle: true,
+/** @type BuildOptions */
+const bundleOptions = {
+       ...sharedOptions,
+       platform: 'browser',
+       target: 'es2022',
+       entryPoints: [
+               './src/index.ts'
+       ]
+}
+
+/** @type BuildOptions */
+const cliOptions = {
+       ...sharedOptions,
        platform: 'node',
+       target: 'node22',
+       outdir: 'dist/bin',
        entryPoints: [
                './src/bin/cli.ts',
                './src/bin/server.ts'
        ],
-       format: 'esm',
-       legalComments: 'inline',
-       outdir: 'dist/bin',
-       packages: 'external',
-       target: 'node22'
-})
+       packages: 'external'
+}
+
+await build(bundleOptions)
+await build(cliOptions)
index ca648b3bf99d408fcade0aabd0882984c3cd1bf9..de36bf7d414f76ac5a7c328114211c5bb971519f 100644 (file)
@@ -32,7 +32,6 @@
                "AUTHORS.md",
                "package.json.license"
        ],
-       "main": "./dist/main.min.js",
        "bin": {
                "nano-pow": "dist/bin/nano-pow.sh"
        },
        "type": "module",
        "exports": {
                ".": {
-                       "types": "./dist/types.d.ts",
-                       "default": "./dist/main.min.js"
+                       "types": "./dist/index.d.ts",
+                       "default": "./dist/index.js"
                }
        },
-       "types": "./dist/types.d.ts",
-       "unpkg": "./dist/main.min.js"
+       "types": "./dist/index.d.ts"
 }
index f3d1accb6fc12be1c0389b69b50f98f7af7cca54..655e23eba0577431b345486c3566130fcdff6931 100755 (executable)
@@ -2,15 +2,15 @@
 //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
-import * as http from 'node:http'
+import { WorkErrorResponse, WorkGenerateResponse, WorkValidateResponse } from '#types'
+import { isHex32, isHex8, Logger } from '#utils'
 import { Serializable } from 'node:child_process'
 import { hash } from 'node:crypto'
 import { readFile, writeFile } from 'node:fs/promises'
+import * as http from 'node:http'
 import { homedir } from 'node:os'
 import { join } from 'node:path'
 import { launch } from 'puppeteer'
-import { WorkErrorResponse, WorkGenerateResponse, WorkValidateResponse } from '#types'
-import { isHex8, isHex32, Logger } from '#utils'
 
 /**
 * Used to define NanoPow server configuration.
@@ -90,7 +90,7 @@ await loadConfig()
 
 // Initialize puppeteer
 LOG: logger.log('starting work server')
-const NanoPow = await readFile(new URL('../main.min.js', import.meta.url), 'utf-8')
+const NanoPow = await readFile(new URL('../index.js', import.meta.url), 'utf-8')
 LOG: logger.log('launching puppeteer browser')
 const browser = await launch({
        handleSIGHUP: false,
index 9fd5b9fba38ece35576359f2c00ad35739696c5c..c083030626c713cf65a226c6ae3d9f0a8ca9fd35 100644 (file)
@@ -1,7 +1,7 @@
 //! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
-export { generate as NanoPowCpu } from '#lib/generate/cpu'
-export { generate as NanoPowWasm } from '#lib/generate/wasm'
-export { generate as NanoPowWebgl } from '#lib/generate/webgl'
-export { generate as NanoPowWebgpu } from '#lib/generate/webgpu'
+export { generate as NanoPowCpu } from './cpu'
+export { generate as NanoPowWasm } from './wasm'
+export { generate as NanoPowWebgl } from './webgl'
+export { generate as NanoPowWebgpu } from './webgpu'
index f6f98b7e44e83f26a7496a92f12bf1074aef78d9..70c303313932e951d280174a8a749d506f9845fc 100644 (file)
@@ -30,7 +30,7 @@
                ]
        },
        "include": [
-               "src/main.ts",
+               "src/index.ts",
                "src/**/*.ts"
        ],
        "exclude": [