Skip to content

feat(build): add CommonJS build output and package entrypoints (#156) - #419

Open
vihaan-vijay wants to merge 1 commit into
spotify:mainfrom
vihaan-vijay:feat/add-cjs-build-output
Open

feat(build): add CommonJS build output and package entrypoints (#156)#419
vihaan-vijay wants to merge 1 commit into
spotify:mainfrom
vihaan-vijay:feat/add-cjs-build-output

Conversation

@vihaan-vijay

Copy link
Copy Markdown

Summary

Fixes #156

This PR adds dual-module distribution support by adding CommonJS (CJS) package entrypoints and conditional exports alongside the existing ES Modules (ESM) build outputs across @spotify-confidence/sdk and related workspace packages.

Problem

Projects relying on CommonJS require() syntax or TypeScript tooling running with default CommonJS settings (e.g. ts-node) encountered ERR_PACKAGE_PATH_NOT_EXPORTED errors because:

  • The package.json manifest lacked top-level "main", "module", and "types" properties.
  • The "exports" configuration map in package.json did not define a "require" conditional export pointing to CommonJS build artifacts.

Changes Made

  1. Yarn Constraints & Package Manifests (yarn.config.cjs & package.json):
    • Updated yarn.config.cjs to enforce "main", "module", "types", and "exports" invariants across workspace packages.
    • Configured "main": "dist/index.cjs", "module": "dist/index.mjs", and "types": "dist/index.d.ts".
    • Added "require": "./dist/index.cjs" to the "exports" condition map.
  2. Cross-Platform Build Normalization (rollup.base.mjs):
    • Normalized Windows backslashes (\) to forward slashes (/) in normalizePath so Rollup bundling executes cleanly across Windows and POSIX environments.
  3. CJS Integration Test (packages/sdk/src/cjs.test.ts):
    • Added a unit test ensuring @spotify-confidence/sdk CommonJS artifacts can be required and cleanly expose exported interfaces (Confidence, Value, etc.).

Verification

  • Unit Tests: Ran yarn test — all 16 test suites (175 tests) passed cleanly.
  • Node.js CJS Resolution: Verified require('@spotify-confidence/sdk') in Node.js runtime without errors.
  • Node.js ESM Resolution: Verified import { Confidence } from '@spotify-confidence/sdk' in ESM runtime without errors.
  • Yarn Constraints: Verified yarn constraints passes without constraint errors.

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.

Reconsider adding a CommonJS build output

1 participant