fix(core): load Node.js-only dependencies lazily so Core runs in browsers (#89) #90

Merged
crapougnax merged 1 commit from fix/89-core-browser-safe-node-imports into develop 2026-12-01 15:06:05 +00:00
Owner

Closes #89

Why

@quatrain/http 1.0.6 now depends on @quatrain/core, so browser apps using @quatrain/api-client bundle Core. Core imported node-persist, node:child_process and which at module load; isexe (via which) reads process.platform at evaluation → ReferenceError: process is not defined, blank page on a Vite-built backoffice.

What

  • Core.ts: the three Node.js-only modules are require()d on first use and cached (Core.storage becomes a getter; execPromise and getSystemCommandPath load on call). Types imported with import type. Public API unchanged.
  • Core.browser.test.ts: mocks the three modules to throw when evaluated, asserts that importing ./Core and ./index loads none of them, and that they load on first use. Fails on the previous Core.ts.

Verification

  • npx jest in packages/core: 119/119 passing
  • tsc --noEmit clean

Not in this PR

properties/HashProperty.ts still imports node:crypto at top level (see #89 follow-up).

🤖 Generated with Claude Code

Closes #89 ## Why `@quatrain/http` 1.0.6 now depends on `@quatrain/core`, so browser apps using `@quatrain/api-client` bundle Core. Core imported `node-persist`, `node:child_process` and `which` at module load; `isexe` (via `which`) reads `process.platform` at evaluation → `ReferenceError: process is not defined`, blank page on a Vite-built backoffice. ## What - `Core.ts`: the three Node.js-only modules are `require()`d on first use and cached (`Core.storage` becomes a getter; `execPromise` and `getSystemCommandPath` load on call). Types imported with `import type`. Public API unchanged. - `Core.browser.test.ts`: mocks the three modules to throw when evaluated, asserts that importing `./Core` and `./index` loads none of them, and that they load on first use. Fails on the previous `Core.ts`. ## Verification - `npx jest` in `packages/core`: 119/119 passing - `tsc --noEmit` clean ## Not in this PR `properties/HashProperty.ts` still imports `node:crypto` at top level (see #89 follow-up). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fix(core): load Node.js-only dependencies lazily so Core runs in browsers (#89)
All checks were successful
Quatrain Core CI / Monorepo Build, Tests & Quality Audit (pull_request) Successful in 3m2s
Quatrain Core CI / Publish Changed Packages to npm (pull_request) Has been skipped
2800247358
Core imported node-persist, node:child_process and which at module load.
Since @quatrain/http 1.0.6 depends on @quatrain/core (MessagePack
normalizer), any browser app using @quatrain/api-client pulled them into
its bundle and crashed on load with "ReferenceError: process is not
defined" (isexe reads process.platform at evaluation time).

These modules are now required on first use (Core.storage getter,
execPromise, getSystemCommandPath). Public API is unchanged.

Adds a regression test asserting that importing Core evaluates none of
them.

Closes #89

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
crapougnax merged commit 1d65699632 into develop 2026-12-01 15:06:05 +00:00
crapougnax deleted branch fix/89-core-browser-safe-node-imports 2026-12-01 15:06:05 +00:00
Sign in to join this conversation.
No description provided.