Skip to content

feat: bundle uuid into stack package and expose schema builder#451

Merged
calvinbrewer merged 2 commits into
mainfrom
bug-esm
May 16, 2026
Merged

feat: bundle uuid into stack package and expose schema builder#451
calvinbrewer merged 2 commits into
mainfrom
bug-esm

Conversation

@calvinbrewer
Copy link
Copy Markdown
Contributor

@calvinbrewer calvinbrewer commented May 14, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Resolved crashes for CommonJS consumers by ensuring ESM-only dependencies are handled in the CJS build.
  • New Features

    • Encrypted tables now expose their column builders as a public, read-only field for easier programmatic access and iteration.
  • Tests

    • Added regression tests to verify CJS bundle loading and the public column-builders behavior.

Review Change Stack

@calvinbrewer calvinbrewer requested a review from a team as a code owner May 14, 2026 18:28
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

🦋 Changeset detected

Latest commit: 9f0b9cc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@cipherstash/stack Minor
@cipherstash/bench Patch
@cipherstash/prisma-next Patch
@cipherstash/basic-example Patch
@cipherstash/prisma-next-example Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

This PR exposes EncryptedTable.columnBuilders as a public, read-only field and updates the build to bundle the ESM-only uuid into CommonJS outputs, plus regression tests ensuring CJS bundles load without requiring ESM-only modules.

Changes

Stack Release: columnBuilders API & CJS uuid Fix

Layer / File(s) Summary
EncryptedTable.columnBuilders public API
packages/stack/src/schema/index.ts, .changeset/stack-cjs-uuid-and-column-builders.md, packages/stack/__tests__/schema-builders.test.ts
EncryptedTable now exposes columnBuilders as a public read-only field; a test asserts the exposed map contains the original typed column-builder instances and is stable.
CJS build and regression tests for uuid bundling
packages/stack/tsup.config.ts, packages/stack/__tests__/cjs-require.test.ts
Tsup noExternal now includes uuid so the CJS build inlines the ESM-only uuid. New Vitest tests discover .cjs bundles, scan for bare require(...) of ESM-only deps, and spawn Node to require each bundle to ensure runtime compatibility.

Sequence Diagram(s)

Possibly related PRs

  • cipherstash/stack#360: Also modified packages/stack/tsup.config.ts to change CJS bundling behavior for an ESM-only dependency.

Suggested reviewers

  • auxesis
  • coderdan

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit checks the build and sees,
Column builders open like trees,
UUID bundled safe in CJS snug,
Tests run clean — a warm little hug. 🐇✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes both main changes: bundling uuid into the stack package for CJS compatibility and exposing the schema builder (columnBuilders property).
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bug-esm

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint skipped: no ESLint configuration detected in root package.json. To enable, add eslint to devDependencies.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

"@cipherstash/stack": minor
---

Fix CJS consumers crashing with `Must use import to load ES Module: .../uuid/dist-node/index.js`. The `uuid` package is pure ESM and has no CJS entry point, so the CJS build of `@cipherstash/stack` could not `require()` it at runtime. `uuid` is now bundled into the CJS output (the ESM build is unchanged).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add something to tests/CI to validate this and prevent regressions?

Copy link
Copy Markdown
Contributor

@coderdan coderdan left a comment

Choose a reason for hiding this comment

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

I'd prefer to add some test or verification before approving.

Copy link
Copy Markdown
Contributor

@auxesis auxesis left a comment

Choose a reason for hiding this comment

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

Agree with @coderdan on this — let's get a regression test added, and then it'll be good to merge.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/stack/__tests__/cjs-require.test.ts`:
- Around line 73-78: The top-level build run using execFileSync guarded by
distIsFresh() should be moved into a test lifecycle hook: wrap the distIsFresh()
check and execFileSync('pnpm', ['run', 'build'], { cwd: packageRoot, stdio:
'inherit' }) inside a beforeAll() in the test suite so builds only run during
test setup (and avoid running at module-load time), and remove the top-level
const cjsEntries = findCjsEntries() so findCjsEntries() is invoked after the
build inside the beforeAll or in tests as needed; reference distIsFresh(),
execFileSync, packageRoot, findCjsEntries(), cjsEntries, and beforeAll() when
making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d76713fb-597e-4bd7-a051-3a2f0c9cdb87

📥 Commits

Reviewing files that changed from the base of the PR and between 1c2fdbf and 9f0b9cc.

📒 Files selected for processing (2)
  • packages/stack/__tests__/cjs-require.test.ts
  • packages/stack/__tests__/schema-builders.test.ts

Comment on lines +73 to +78
if (!distIsFresh()) {
execFileSync('pnpm', ['run', 'build'], {
cwd: packageRoot,
stdio: 'inherit',
})
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Move build execution into a beforeAll() hook.

Running execFileSync at module-load time (outside any test lifecycle hook) can cause race conditions when tests run in parallel and triggers even when executing unrelated test files in the workspace.

🔧 Proposed fix to move build into test lifecycle

Move the freshness check and build inside the test suite:

-if (!distIsFresh()) {
-  execFileSync('pnpm', ['run', 'build'], {
-    cwd: packageRoot,
-    stdio: 'inherit',
-  })
-}
-
-const cjsEntries = findCjsEntries()
-
 describe('CJS consumers can require the built bundles', () => {
+  let cjsEntries: string[]
+
+  beforeAll(() => {
+    if (!distIsFresh()) {
+      execFileSync('pnpm', ['run', 'build'], {
+        cwd: packageRoot,
+        stdio: 'inherit',
+      })
+    }
+    cjsEntries = findCjsEntries()
+  })
+
   it('discovers at least the public entry points', () => {

Then remove the const cjsEntries = findCjsEntries() line from the top level (line 80).

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (!distIsFresh()) {
execFileSync('pnpm', ['run', 'build'], {
cwd: packageRoot,
stdio: 'inherit',
})
}
describe('CJS consumers can require the built bundles', () => {
let cjsEntries: string[]
beforeAll(() => {
if (!distIsFresh()) {
execFileSync('pnpm', ['run', 'build'], {
cwd: packageRoot,
stdio: 'inherit',
})
}
cjsEntries = findCjsEntries()
})
it('discovers at least the public entry points', () => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/stack/__tests__/cjs-require.test.ts` around lines 73 - 78, The
top-level build run using execFileSync guarded by distIsFresh() should be moved
into a test lifecycle hook: wrap the distIsFresh() check and
execFileSync('pnpm', ['run', 'build'], { cwd: packageRoot, stdio: 'inherit' })
inside a beforeAll() in the test suite so builds only run during test setup (and
avoid running at module-load time), and remove the top-level const cjsEntries =
findCjsEntries() so findCjsEntries() is invoked after the build inside the
beforeAll or in tests as needed; reference distIsFresh(), execFileSync,
packageRoot, findCjsEntries(), cjsEntries, and beforeAll() when making the
change.

@calvinbrewer calvinbrewer merged commit eaf9c71 into main May 16, 2026
6 checks passed
@calvinbrewer calvinbrewer deleted the bug-esm branch May 16, 2026 16:17
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.

3 participants