Skip to content

build: drop ambient host types from the published build - #7

Merged
b2m9 merged 2 commits into
mainfrom
build/no-ambient-host-types
Jul 31, 2026
Merged

build: drop ambient host types from the published build#7
b2m9 merged 2 commits into
mainfrom
build/no-ambient-host-types

Conversation

@b2m9

@b2m9 b2m9 commented Jul 31, 2026

Copy link
Copy Markdown
Owner

Adds "types": [] to tsconfig.build.json.

Why

src/ imports no Node built-ins — the fold is pure ECMAScript. But the build config inherits types: ["node"] from the root tsconfig.json, so a stray import { randomUUID } from "node:crypto" in src/ would compile cleanly, pass lint, and break only for consumers who bundle the package for a browser.

tsconfig.build.json already scopes to include: ["src"], so emptying the types list lands exactly on the published surface. The test program is untouched and keeps the Node globals that vitest and vite pull in through their own type declarations.

Verification

  • npm run check passes end to end.
  • The guard fires. With import { randomUUID } from "node:crypto" added to src/objects.ts, npm run build fails:
    src/objects.ts(42,28): error TS2591: Cannot find name 'node:crypto'.
    
  • Note that npm run typecheck still passes on that same code, since the root config supplies node types to src. That is why the guard belongs in the build config. Both steps run under npm run check, so CI catches it either way.
  • The emitted .d.ts references nothing node-related, before or after.

Scope

Independent of #6 — that one pins the @types/node version, this one bounds where those types apply. Branched off main, so the two can merge in either order.

🤖 Generated with Claude Code


Summary by cubic

Remove ambient Node types from the published build to keep the library browser-safe. Set "types": [] in tsconfig.build.json so any Node built-in import in src fails at build time, while tests keep Node types from the root config.

Written for commit 49a0cad. Summary will update on new commits.

Review in cubic

b2m9 and others added 2 commits July 31, 2026 12:16
The fold is pure ECMAScript and imports no Node built-ins, but the build
inherited types: ["node"] from the root config, so a stray built-in import
in src would compile and only break for consumers bundling to a browser.

The build config already scopes to src, so emptying the types list there
constrains the published surface without touching the test program, which
needs the Node globals that vitest and vite pull in.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

Re-trigger cubic

@b2m9
b2m9 merged commit 43e0cbf into main Jul 31, 2026
3 checks passed
@b2m9
b2m9 deleted the build/no-ambient-host-types branch July 31, 2026 10:21
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