Skip to content

fix(bundlecheck): auto-detect node platform for packages using Node.js built-in modules - #537

Merged
aversini merged 3 commits into
mainfrom
fix_bundlecheck_auto_detect_node_platform_for_packages_using_nodejs_builtin_modules
Mar 25, 2026
Merged

aversini merged 3 commits into
mainfrom
fix_bundlecheck_auto_detect_node_platform_for_packages_using_nodejs_builtin_modules

Conversation

@aversini

Copy link
Copy Markdown
Collaborator

Summary

  • Auto-retry with platform: "node" when esbuild fails to resolve Node.js built-in modules (path, fs, http, etc.) during browser bundling
  • Handle native .node addon files (e.g., fsevents) by treating them as empty during bundling
  • Store the actual detected platform in the cache so cached results display correctly

Fixes packages like @docmd/core that don't declare engines.node in their package.json but use Node.js APIs — these were incorrectly bundled as browser packages, causing build failures.

Test plan

  • Unit tests added for auto-retry on Node.js built-ins (2 new tests)
  • Unit tests verify explicit --platform browser still errors on Node.js built-ins
  • All 268 existing tests pass
  • E2E verified: bundlecheck "@docmd/core" succeeds and shows node (auto-detected)
  • E2E verified: cached result also shows node (auto-detected)

🤖 Generated with Claude Code

…s built-in modules

When esbuild fails to resolve Node.js built-ins (path, fs, http, etc.)
during browser bundling, automatically retry with platform: "node". This
fixes packages like @docmd/core that don't declare engines.node but use
Node.js APIs.

Also handles native .node addon files (e.g., fsevents) by treating them
as empty during bundling, and stores the actual detected platform in the
cache so cached results display the correct platform.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aversini
aversini requested a review from Copilot March 25, 2026 21:52

Copilot AI 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.

Pull request overview

This PR improves bundlecheck’s platform detection by retrying failed browser bundles as Node bundles when esbuild errors indicate Node.js built-in usage, and updates caching so results reflect the actual detected platform.

Changes:

  • Auto-retry bundling with platform: "node" when unresolved modules are recognized as Node.js built-ins
  • Treat native .node addons as empty during bundling to avoid esbuild loader failures
  • Add actual_platform to cache schema and hydrate cached results with the real platform

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/bundlecheck/src/cache.ts Adds actual_platform column + logic to read/write actual detected platform in cache
packages/bundlecheck/src/bundler.ts Adds Node built-in detection + retry to node; treats .node addons as empty
packages/bundlecheck/src/tests/bundler.test.ts Adds unit tests covering node built-in auto-retry and “explicit browser platform” behavior
.claude/skills/tdd Adds Claude tooling skill indirection file
.claude/settings.json Adds Claude Code settings/permissions configuration
.claude/commands/branch.md Adds a Claude workflow command document

Comment thread packages/bundlecheck/src/bundler.ts Outdated
Comment thread packages/bundlecheck/src/cache.ts
Comment thread packages/bundlecheck/src/cache.ts
Comment thread .claude/settings.json
Split on "/" and check the root segment so that imports like
"fs/promises" or "node:path/posix" are correctly identified as
Node.js built-ins.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aversini
aversini merged commit dbd4a25 into main Mar 25, 2026
6 checks passed
@aversini
aversini deleted the fix_bundlecheck_auto_detect_node_platform_for_packages_using_nodejs_builtin_modules branch March 25, 2026 22:06
@aversini aversini mentioned this pull request Mar 25, 2026
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.

2 participants