fix: make SDK_VERSION bundling-safe (literal + drift test); 1.0.1 - #21
Conversation
…test); 1.0.1
1.0.0 derived SDK_VERSION via `createRequire(import.meta.url)('../package.json')`.
That runtime read does NOT survive bundling: when a consumer inlines the SDK
into a self-contained artifact, the call is preserved and tries to resolve
`../package.json` relative to the consumer's bundle at load time — which throws
when the bundle runs in isolation (surfaced by claude-openmax's self-contained
bundle smoke test: `Cannot find module '../package.json'`).
- src/index.js: SDK_VERSION is now a hardcoded literal '1.0.1'; dropped the
now-unused createRequire import. No runtime package.json read remains in the
library source, so nothing breaks when the SDK is bundled.
- src/version.test.js: drift guard — asserts SDK_VERSION === package.json.version
(reading package.json in a test is safe; tests are never bundled). This keeps
the anti-drift guarantee that motivated the original createRequire approach,
but enforced at CI time instead of library runtime.
- bump to 1.0.1 (patch): the fix is a behavior fix for bundling consumers.
npm test 309/309; semgrep 0 findings.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Documents the version-bump checklist so future releases stay consistent: - the files that must change (package.json, package-lock.json, the SDK_VERSION literal in src/index.js, README prose) and which are CI-enforced; - the explicit DO-NOT: never revert SDK_VERSION to a runtime package.json read (bundling regression) — keep the literal + drift test; - the tag → release.yml → release-env approval → npm publish flow and the automatic latest/alpha dist-tag rule; - the promote-dist-tag escape hatch. Adds a one-line pointer to it from the README version note. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
zylos-luna-coco
left a comment
There was a problem hiding this comment.
Good catch and clean fix for the 1.0.0 bundling regression.
Root cause correct: createRequire(import.meta.url)('../package.json') survives in the consumer's bundle as a literal path resolution — but ../package.json is relative to the bundle, not the SDK's installed location. Any consumer that bundles the SDK (claude-openmax's esbuild flow) hits Cannot find module at load time.
Fix approach correct: revert to a hardcoded literal + add a CI-time drift guard (src/version.test.js) that reads package.json in-repo (safe — tests are never bundled). This preserves the anti-drift guarantee without the runtime read. Clean separation of concerns.
RELEASING.md: Good addition — spells out exactly which files to bump, explicitly warns against re-introducing the runtime createRequire read, and documents the tag → release → dist-tag flow. The "Do NOT" section is the key knowledge preservation.
Verified:
SDK_VERSIONliteral'1.0.1'matchespackage.jsonversion- No runtime
createRequire('../package.json')remains in non-testsrc/ - 309/309 tests per PR description (drift guard included)
- Version:
1.0.0→1.0.1(patch — behavior fix for bundling consumers)
LGTM.
Summary
Fixes a bundling regression in 1.0.0 and releases it as 1.0.1.
1.0.0 set
SDK_VERSIONviacreateRequire(import.meta.url)('../package.json').version. That runtime read does not survive bundling: when a consumer inlines the SDK into a self-contained artifact (e.g. claude-openmax bundlessrcinto itsdist/*.mjs), the call is preserved and resolves../package.jsonrelative to the consumer's bundle at load time — which throws when the bundle runs in isolation.Surfaced by claude-openmax's own self-contained bundle smoke test after bumping to 1.0.0:
(alpha.3 had
SDK_VERSIONas a literal, so this is a 1.0.0 regression for any consumer that bundles the SDK.)Changes
src/index.js:SDK_VERSIONis now a hardcoded literal ('1.0.1'); removed the now-unusedcreateRequireimport. No runtimepackage.jsonread remains in the library source → nothing breaks when the SDK is bundled.src/version.test.js: drift guard — assertsSDK_VERSION === package.json.version. Readingpackage.jsonin a test is safe (tests run in-repo and are never bundled). This preserves the anti-drift guarantee that motivated the originalcreateRequire, but enforces it at CI time instead of library runtime.package.json/ lock:1.0.0→1.0.1(patch — behavior fix for bundling consumers).Testing
npm test— 309/309 (adds the drift-guard test)semgrep scan --config auto --error— 0 findingscreateRequire('../package.json')remains in non-testsrc/SDK_VERSION(1.0.1) matchespackage.jsonversionReviewer
🤖 Generated with Claude Code