The published package could not be used at all. `require('nomyo-js')`
succeeded, but constructing a client threw:
Cannot find module './node'
Platform selection was done with a runtime require:
const NodeSecureMemory = require('./node').NodeSecureMemory;
Rollup flattens every module into one file, so './node' and './browser'
no longer exist at runtime — and because the calls sit inside function
bodies, rollup left them as literal runtime requires rather than
resolving them. The failure was therefore deferred to first use: module
load and Object.keys() both looked fine, so nothing noticed. The
SecureCompletionClient constructor calls createSecureMemory() and
createHttpClient(), which made every client unconstructable.
Confirmed present at 057ff6c, this branch's merge base, so the npm
package has never worked.
Platform implementations are now injected by the entry points, which is
what src/node.ts and src/browser.ts always claimed to do (they merely
re-exported ./index). createSecureMemory/createHttpClient consult a
registered factory and throw a directive error if none was registered.
No require fallback is kept: leaving one would put an unresolvable
relative require back in the bundle, and bundlers resolve requires
statically, so webpack/vite would fail on a path that does not exist in
dist/. Jest registers the platform via tests/setup.ts instead.
This also keeps the Node HTTP client and the optional native addon out
of the browser bundle, which previously carried both.
Second defect found while verifying: dist/esm/index.mjs contained 13
require() calls (crypto, fs, path, jose, nomyo-native) that the source
loads lazily. `require` does not exist in ES module scope, so an ESM
consumer crashed with "require is not defined" as soon as one ran —
using keyDir for key persistence would have hit it on every Node
version. Node 24 masked the crypto case by having a global crypto. The
ESM output now carries a createRequire shim.
tests/integration/bundle.test.ts covers the artefact that actually
ships: both bundles construct a client, expose the API, resolve the
platform layer, keep Node-only modules out of the browser build, and the
ESM entry is imported and used by a real spawned Node process. Every
other suite runs against src/ through ts-jest, where these paths resolve
normally — which is precisely why this went unnoticed.
Verified end to end by installing the packed tarball into a clean
project: CommonJS and ESM both construct a client and run fs-backed key
generation on Node 18.19.1 and 24.18.0.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The dependency bumps on main left `npm test` and `npm run build:types`
broken independently of any feature work; both fail on a clean checkout
of origin/main.
TypeScript 6 no longer auto-includes @types packages the way node10
resolution did, so every test suite failed to compile with "Cannot find
name 'describe'/'expect'". Declare the needed @types explicitly instead:
- tsconfig.json: types: ["node"]
- jest.config.js: types: ["jest", "node"]
TypeScript 6 also errors on two settings this config relied on:
- moduleResolution "node" (node10) is deprecated -> "bundler", which
matches how the package is actually consumed (rollup-bundled, with
"module": "ESNext")
- an implicit rootDir is now an error when outDir/declarationDir are
set -> rootDir: "./src"
Drop three unused imports that noUnusedLocals turns into hard errors,
failing --emitDeclarationOnly.
Finally, NodeSecureMemory logged to stdout unconditionally on
construction. This was dormant while the native addon failed to load;
once it loads, it broke the "no console.log when debug=false" test. A
library must not write to stdout uninvited, and the client already
reports this via getProtectionInfo() behind its own debug flag.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>