Skip to content

refactor: migrate to @socketsecurity/lib/primordials#71

Merged
John-David Dalton (jdalton) merged 1 commit intomainfrom
chore/primordials
Apr 27, 2026
Merged

refactor: migrate to @socketsecurity/lib/primordials#71
John-David Dalton (jdalton) merged 1 commit intomainfrom
chore/primordials

Conversation

@jdalton
Copy link
Copy Markdown
Collaborator

Summary

Swaps direct Error constructor usage for ErrorCtor primordial across the core SDK, hardening against prototype tampering on Error. Also adds a catalog: block to pnpm-workspace.yaml so the existing .claude/hooks/check-new-deps hook (which references @socketsecurity/lib via catalog:) resolves cleanly — pre-existing scaffolding bug.

Audit

Used prim audit (the socket-lib/tools/prim tool):

node /path/to/socket-lib/tools/prim/bin/prim.mts \
  audit --target . --dir src \
  --surface /path/to/socket-lib/src/primordials.ts

Initial audit: 19 sites total — 9 ErrorCtor in core .ts files, 10 SymbolFor in browser-side src/pages/*.js files.

After conversion: 0 sites remain in the core; pages/ intentionally untouched.

Sites converted (9 in 4 files)

File Sites
src/compare.ts 1 × ErrorErrorCtor
src/package-url.ts 5 × ErrorErrorCtor
src/purl-types/npm.ts 3 × ErrorErrorCtor
src/result.ts 3 × ErrorErrorCtor (kept instanceof Error runtime checks unchanged — those need the global identity)

Out of scope

  • src/pages/*.js — 10 Symbol.for() sites in browser-side page glue. Pulling @socketsecurity/lib into the browser bundle would add weight for cosmetic page tokens. Skipped.

Verification

pnpm install         ✓
pnpm run check --all ✓
pnpm test            ✓ all tests pass

Test plan

  • Type-check passes
  • All unit tests pass (566+ in main suite + isolated test)
  • CI matrix passes

Swaps direct Error constructor usage for ErrorCtor primordial across
the core SDK source, hardening against prototype tampering on Error.

Sites converted (9):
  src/compare.ts: 1 site
  src/package-url.ts: 5 sites
  src/purl-types/npm.ts: 3 sites
  src/result.ts: 3 sites (kept `instanceof Error` runtime checks
                          unchanged — those need the global identity)

The browser-side files in src/pages/ that use Symbol.for() (10 sites)
are intentionally left as-is — pulling @socketsecurity/lib into the
browser bundle would add unnecessary weight for cosmetic page glue.

Also adds a `catalog:` block to pnpm-workspace.yaml so the
.claude/hooks/check-new-deps hook (which references @socketsecurity/lib
via "catalog:") resolves cleanly. Without this, pnpm install fails
with ERR_PNPM_CATALOG_ENTRY_NOT_FOUND_FOR_SPEC. socket-packageurl-js
already pins @socketsecurity/lib at 5.25.1 in root package.json, so
the catalog entry just mirrors that.

Verification:
  pnpm install         ✓
  pnpm run check --all ✓
  pnpm test            ✓ all tests pass
@jdalton John-David Dalton (jdalton) merged commit e8dbd44 into main Apr 27, 2026
9 of 10 checks passed
@jdalton John-David Dalton (jdalton) deleted the chore/primordials branch April 27, 2026 14:24
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