]> git.codecow.com Git - nano-pow.git/commitdiff
Refactor build to export utility functions as submodule.
authorChris Duncan <chris@codecow.com>
Sun, 5 Apr 2026 09:33:52 +0000 (02:33 -0700)
committerChris Duncan <chris@codecow.com>
Sun, 5 Apr 2026 09:33:52 +0000 (02:33 -0700)
esbuild.mjs
package.json
src/bin/cli.ts
src/bin/server.ts
src/index.d.ts [moved from src/types.d.ts with 100% similarity]
src/index.ts
test/index.html
tsconfig.json

index 6b61e33f08beb566ee09b730d71eca9ab1ff29ca..bf309e351c9efe6cf0d74bd659febe48c100150e 100644 (file)
@@ -11,6 +11,7 @@ const sharedOptions = {
        format: 'esm',
        outdir: 'dist',
        loader: {
+               '.d.ts': 'copy',
                '.wasm': 'binary'
        },
        legalComments: 'inline',
@@ -29,7 +30,8 @@ const bundleOptions = {
        platform: 'browser',
        target: 'es2022',
        entryPoints: [
-               './src/index.ts'
+               './src/index.ts',
+               './src/utils/index.ts'
        ]
 }
 
@@ -38,6 +40,7 @@ const cliOptions = {
        ...sharedOptions,
        platform: 'node',
        target: 'node22',
+       bundle: false,
        outdir: 'dist/bin',
        entryPoints: [
                './src/bin/cli.ts',
index de36bf7d414f76ac5a7c328114211c5bb971519f..186cb064de31b3bbfa9b45458e61cc4edea6500e 100644 (file)
                ".": {
                        "types": "./dist/index.d.ts",
                        "default": "./dist/index.js"
+               },
+               "./utils": {
+                       "types": "./dist/utils/index.d.ts",
+                       "default": "./dist/utils/index.js"
                }
        },
        "types": "./dist/index.d.ts"
index 63a3a5f6a27d783ff025e69d35eee2bdc02c13b4..a1beaf03099265a9ea3f07e122caa5ae8b43a367 100755 (executable)
@@ -3,7 +3,7 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
 import { WorkErrorResponse, WorkGenerateResponse, WorkValidateResponse } from '#types'
-import { isHex32, isHex8, Logger, stats } from '#utils'
+import { isHex32, isHex8, Logger, stats } from 'nano-pow/utils'
 import { Serializable, spawn } from 'node:child_process'
 import { getRandomValues } from 'node:crypto'
 import { createInterface } from 'node:readline/promises'
index 655e23eba0577431b345486c3566130fcdff6931..2c54c0700ebf890b62876633a8223f63c9777825 100755 (executable)
@@ -3,7 +3,7 @@
 //! SPDX-License-Identifier: GPL-3.0-or-later
 
 import { WorkErrorResponse, WorkGenerateResponse, WorkValidateResponse } from '#types'
-import { isHex32, isHex8, Logger } from '#utils'
+import { isHex32, isHex8, Logger } from 'nano-pow/utils'
 import { Serializable } from 'node:child_process'
 import { hash } from 'node:crypto'
 import { readFile, writeFile } from 'node:fs/promises'
similarity index 100%
rename from src/types.d.ts
rename to src/index.d.ts
index 3a95d6f2c75a91d0c356529580299f6c760dd432..9555e0eb76795ed54093899c1f87b55f48817edc 100644 (file)
@@ -14,7 +14,7 @@ import { generate, validate } from './lib'
 * @param {number} [options.effort=0x4] - GPU load when generating work. Larger values are not necessarily better since they can quickly overwhelm the GPU. Default: 0x4
 * @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
 */
-export async function work_generate (hash: bigint | string, options: NanoPowOptions): Promise<WorkGenerateResponse | WorkErrorResponse> {
+async function work_generate (hash: bigint | string, options: NanoPowOptions): Promise<WorkGenerateResponse | WorkErrorResponse> {
        return generate(hash, options)
 }
 
@@ -27,12 +27,10 @@ export async function work_generate (hash: bigint | string, options: NanoPowOpti
 * @param {boolean} [options.debug=false] - Enables additional debug logging to the console. Default: false
 * @param {bigint} [options.difficulty=0xfffffff800000000] - Minimum value result of `BLAKE2b(nonce||blockhash)`. Default: 0xFFFFFFF800000000
 */
-export async function work_validate (work: bigint | string, hash: bigint | string, options: NanoPowOptions): Promise<WorkValidateResponse | WorkErrorResponse> {
+async function work_validate (work: bigint | string, hash: bigint | string, options: NanoPowOptions): Promise<WorkValidateResponse | WorkErrorResponse> {
        return validate(work, hash, options)
 }
 
-export const NanoPow = { work_generate, work_validate }
+const NanoPow = { work_generate, work_validate }
 
-export default NanoPow
-
-export { clearCache, stats } from '#utils'
+export { NanoPow as default, NanoPow, work_generate, work_validate }
index 98bc0c7ccfb19c4225b7e7ddeaf90b973962e624..882e091f5de5316201f5a38442e2b622ac011865 100644 (file)
@@ -11,15 +11,31 @@ SPDX-License-Identifier: GPL-3.0-or-later
        try {
                let NanoPow, stats
                try {
-                       ({ NanoPow, stats } = await import('../dist/main.min.js'))
+                       ({ NanoPow } = await import('../dist/index.js'))
                } catch (err) {
                        console.warn(err)
                        try {
-                               ({ NanoPow, stats } = await import('https://unpkg.com/nano-pow@5.1/dist/main.min.js'))
+                               ({ NanoPow, stats } = await import('https://unpkg.com/nano-pow@5.1/dist/index.js'))
                        } catch (err) {
                                console.warn(err)
                                try {
-                                       ({ NanoPow, stats } = await import('https://cdn.jsdelivr.net/npm/nano-pow@5.1/dist/main.min.js'))
+                                       ({ NanoPow, stats } = await import('https://cdn.jsdelivr.net/npm/nano-pow@5.1/dist/index.js'))
+                               } catch (err) {
+                                       throw new Error(`Failed to load NanoPow ${err}`)
+                               }
+                       }
+               }
+
+               try {
+                       ({ stats } = await import('../dist/utils/index.js'))
+               } catch (err) {
+                       console.warn(err)
+                       try {
+                               ({ NanoPow, stats } = await import('https://unpkg.com/nano-pow@5.1/dist/utils/index.js'))
+                       } catch (err) {
+                               console.warn(err)
+                               try {
+                                       ({ NanoPow, stats } = await import('https://cdn.jsdelivr.net/npm/nano-pow@5.1/dist/utils/index.js'))
                                } catch (err) {
                                        throw new Error(`Failed to load NanoPow ${err}`)
                                }
index 70c303313932e951d280174a8a749d506f9845fc..a7f60a7c523456e07b17a185814595b38d586100 100644 (file)
@@ -5,7 +5,7 @@
                "moduleResolution": "bundler",
                "declaration": true,
                "emitDeclarationOnly": true,
-               "declarationDir": "./types",
+               "declarationDir": "./dist",
                "alwaysStrict": true,
                "downlevelIteration": false,
                "esModuleInterop": true,
@@ -19,7 +19,7 @@
                                "./src/lib/*"
                        ],
                        "#types": [
-                               "./src/types.d.ts"
+                               "./src/index.d.ts"
                        ],
                        "#utils": [
                                "./src/utils/index.ts"