Skip to content

feat(codec): Node-runnable published artifact (dual-target exports)#38

Merged
ignromanov merged 4 commits into
mainfrom
056-phase3-b2-node-artifact
Jun 3, 2026
Merged

feat(codec): Node-runnable published artifact (dual-target exports)#38
ignromanov merged 4 commits into
mainfrom
056-phase3-b2-node-artifact

Conversation

@ignromanov
Copy link
Copy Markdown
Contributor

Summary

Part of #17

Wires the Node-runnable published artifact for @void-layer/codec:

  • Dual-target exports: exports["."]["node"]dist/index.node.js; exports["."]["import"]dist/index.js (bundler). Consumers get the right entry automatically via export conditions.
  • wire.ts single source: encode/decode wire logic extracted into wire.ts, shared by both index.ts (bundler) and index.node.ts (Node ESM). No duplication.
  • pkg-node/ in published files: wasm-pack --target nodejs output included in the tarball so Node consumers get fs-based WASM loading without fetch.
  • build runs both targets: wasm-pack bundler + wasm-pack nodejs + tsc in one pnpm build.
  • test:pack smoke: pack → install → Node ESM import → canonical + wire round-trip, all green.
  • @void-layer/types moved to devDependencies: codec must not ship types as a runtime dep; types is a peer/dev concern only.

TS6 / vitest4 toolchain fix

tsconfig.json gains "types": ["node"]. Under moduleResolution: "bundler" (correct for bundler consumers), TS6 does not auto-include Node built-in types. index.node.ts uses createRequire from 'module' and import.meta.url — both require @types/node to resolve. @types/node was already in devDependencies; this just activates it for tsc.

Validation (TS 6.0.3 / vitest 4.1.8 / @vitest/coverage-v8 4.1.8)

Check Result
pnpm build (bundler + nodejs wasm-pack + tsc) green
pnpm test (vitest run) 365/365 passed, coverage 98.24%
pnpm test:pack (Node ESM smoke) B2 SMOKE PASS
pnpm lint (clippy + rustfmt + eslint) green

Coverage parse warnings for .rs files are non-fatal (coverage-v8 excludes them gracefully) — pre-existing behavior unchanged from vitest3.

- Move @void-layer/types to devDependencies (import type only, zero runtime presence)
- Add src/index.node.ts: ESM wrapper using createRequire to load pkg-node CJS
  glue + brotli-wasm index.node.js (require condition, fs-based, no fetch)
- Wire `node` export condition → dist/index.node.js in package.json#exports
- Add pkg-node/ to package.json#files
- Update build script to run wasm-pack --target nodejs + rm pkg-node/.gitignore
- Add test:pack script (scripts/test-pack.mjs): pnpm-pack → tmp-install → Node ESM import
- Exclude src/index.node.ts from vitest coverage (exercised by test:pack, not vitest)

Bundler path (pkg/ via `import` condition) retained alongside node path.
WASM gzip: 79,264 bytes (cap 81,920; headroom ~2.7 KB).
Smoke test: pnpm test:pack
….mjs

P2 — de-duplication:
- Extract src/wire.ts: single source for COMPRESSED_FLAG, MAX_DECOMPRESSED_BYTES,
  decompressBounded (DoS guard from d83cef9), encodeWire, decodeWire
- Both index.ts (bundler) and index.node.ts (Node) import from wire.ts; the
  only per-entry difference is the brotli-wasm loader (ESM import() vs require)
- Remove no-explicit-any eslint-disable directives (as{} cast satisfies the rule)

P1 — ESLint:
- scripts/test-pack.mjs: remove unused rmSync import, use bare catch{} for
  intentional empty cleanup handlers, fix unused err catch param
- eslint.config.mjs: add scripts/**/*.mjs override declaring Node globals
  (console/process/URL) so no-undef does not fire on tooling scripts
…ion:bundler

index.node.ts uses createRequire from 'module' and import.meta.url — both
require @types/node to resolve under moduleResolution:"bundler". TS6 enforces
this more strictly. @types/node is already in devDependencies.
@ignromanov ignromanov merged commit caae262 into main Jun 3, 2026
7 checks passed
@ignromanov ignromanov deleted the 056-phase3-b2-node-artifact branch June 3, 2026 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant