Skip to content

fix(@deepnote/convert): replace uuid with crypto.randomUUID for CJS compatibility#214

Merged
saltenasl merged 2 commits intomainfrom
ls/convert-cjs-compat
Jan 14, 2026
Merged

fix(@deepnote/convert): replace uuid with crypto.randomUUID for CJS compatibility#214
saltenasl merged 2 commits intomainfrom
ls/convert-cjs-compat

Conversation

@saltenasl
Copy link
Contributor

@saltenasl saltenasl commented Jan 14, 2026

Summary

  • Replace uuid package with Node.js built-in crypto.randomUUID() to fix ESM/CJS compatibility issues
  • Remove uuid dependency from package.json
  • Update test mocks to use node:crypto instead of uuid

Problem

When consuming @deepnote/convert in CommonJS environments (e.g., Jest), the following error occurred:

SyntaxError: Unexpected token 'export'

This happened because uuid@13+ is ESM-only, but the CJS build externalized it as require("uuid").

Solution

Replaced uuid.v4() with crypto.randomUUID(), which is a Node.js built-in available since v14.17.0. Since the package requires Node ≥22.14.0, this is safe and removes the need for any external UUID dependency.

Summary by CodeRabbit

  • Chores
    • Bumped package version to 2.1.3
    • Removed uuid dependency and updated ID generation mechanism across conversion modules
    • Updated test infrastructure to support internal changes
    • No breaking changes to public APIs

✏️ Tip: You can customize this high-level summary in your review settings.

@saltenasl saltenasl requested a review from a team as a code owner January 14, 2026 06:04
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 14, 2026

📝 Walkthrough

Walkthrough

The convert package migrates from the external uuid library to Node.js's built-in crypto.randomUUID() for ID generation across all notebook conversion modules. The uuid dependency was removed from package.json, and all ID generation calls (in jupyter, marimo, percent, and quarto converters) now use crypto.randomUUID instead of uuid.v4. Test mocks were updated to reflect this change. Version bumped to 2.1.3.

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Title accurately summarizes the main change: replacing uuid with crypto.randomUUID for CJS compatibility.

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


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

@codecov
Copy link

codecov bot commented Jan 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.57%. Comparing base (f74140a) to head (9f71b72).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #214   +/-   ##
=======================================
  Coverage   91.57%   91.57%           
=======================================
  Files          41       41           
  Lines        2041     2041           
  Branches      652      630   -22     
=======================================
  Hits         1869     1869           
  Misses        172      172           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/convert/src/jupyter-to-deepnote.test.ts (1)

1372-1372: Stale test description.

Test name references "uuid v4" but implementation now uses crypto.randomUUID.

Suggested fix
-  it('uses default uuid v4 when no idGenerator provided', () => {
+  it('uses default crypto.randomUUID when no idGenerator provided', () => {
🤖 Fix all issues with AI agents
In `@packages/convert/src/percent-to-deepnote.test.ts`:
- Around line 13-34: Extract a dedicated type alias (e.g., MockedRandomUUID) for
the mocked randomUUID type instead of repeating the complex cast; update the
mock creation (mockRandomUUID) to be cast as that alias and assign
__resetCounter on it, and change getMockedRandomUUID() to return that alias (use
vi.mocked(crypto.randomUUID) as MockedRandomUUID). This simplifies typings while
keeping the existing mock behavior and __resetCounter helper.
📜 Review details

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between f74140a and 9f71b72.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • packages/convert/package.json
  • packages/convert/src/jupyter-to-deepnote.test.ts
  • packages/convert/src/jupyter-to-deepnote.ts
  • packages/convert/src/marimo-to-deepnote.test.ts
  • packages/convert/src/marimo-to-deepnote.ts
  • packages/convert/src/percent-to-deepnote.test.ts
  • packages/convert/src/percent-to-deepnote.ts
  • packages/convert/src/quarto-to-deepnote.test.ts
  • packages/convert/src/quarto-to-deepnote.ts
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: Place test files next to source files with .test.ts or .test.tsx extension
Use strict type checking in TypeScript files
Prefer type safety over convenience in TypeScript
Use const for immutable values
Avoid any types - use proper type definitions
Follow Biome's rules (configured in biome.json)
Use literal keys instead of bracket notation when possible
Prefer single quotes for strings (except when avoiding escapes)
Keep code clean and readable following Biome standards

Files:

  • packages/convert/src/marimo-to-deepnote.test.ts
  • packages/convert/src/quarto-to-deepnote.test.ts
  • packages/convert/src/jupyter-to-deepnote.test.ts
  • packages/convert/src/quarto-to-deepnote.ts
  • packages/convert/src/marimo-to-deepnote.ts
  • packages/convert/src/percent-to-deepnote.ts
  • packages/convert/src/percent-to-deepnote.test.ts
  • packages/convert/src/jupyter-to-deepnote.ts
**/*.test.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.test.{ts,tsx}: Use Vitest as the testing framework
Follow existing test patterns in the codebase (see packages/blocks/src/blocks/*.test.ts)
Test edge cases, error handling, and special characters

Files:

  • packages/convert/src/marimo-to-deepnote.test.ts
  • packages/convert/src/quarto-to-deepnote.test.ts
  • packages/convert/src/jupyter-to-deepnote.test.ts
  • packages/convert/src/percent-to-deepnote.test.ts
🔇 Additional comments (19)
packages/convert/package.json (1)

3-3: LGTM!

Version bump and uuid removal are consistent with the migration to crypto.randomUUID. Node ≥22.14.0 requirement more than covers the API availability.

Also applies to: 37-43, 49-51

packages/convert/src/percent-to-deepnote.test.ts (2)

274-279: Correct mock reset.

Clearing and resetting counter ensures test isolation.


374-381: LGTM.

Same pattern applied consistently.

packages/convert/src/jupyter-to-deepnote.ts (3)

1-1: Clean import.

Named import randomUUID is cleaner than the old v4 as uuidv4 pattern.


43-48: LGTM.

Default to randomUUID is straightforward.


85-88: Consistent replacement.

All ID generation points now use randomUUID.

Also applies to: 97-97, 122-122

packages/convert/src/quarto-to-deepnote.ts (2)

1-1: Consistent with other converters.

Import and JSDoc update match the pattern.

Also applies to: 14-17


318-322: LGTM.

All ID generation uses randomUUID now.

Also applies to: 352-365, 385-385

packages/convert/src/marimo-to-deepnote.ts (3)

1-1: Same pattern applied.

Matches other converter files.


83-86: LGTM.

JSDoc and default ID generator updated correctly.

Also applies to: 297-299


302-307: Consistent implementation.

idGenerator option propagates correctly through the conversion chain.

Also applies to: 317-321

packages/convert/src/marimo-to-deepnote.test.ts (2)

1-30: Clean migration to crypto.randomUUID mock.

The mock setup correctly preserves the actual crypto module while overriding only randomUUID. The __resetCounter hook via type assertion is a practical approach for deterministic test IDs.


701-705: Reset pattern is consistent.

Both beforeEach blocks properly clear and reset the mock counter before each test.

Also applies to: 837-840

packages/convert/src/jupyter-to-deepnote.test.ts (1)

1-32: Mock setup matches other test files.

Consistent pattern for crypto.randomUUID mocking with reset capability.

packages/convert/src/quarto-to-deepnote.test.ts (2)

1-34: Consistent mock pattern.

Same approach as other test files. Clean implementation.


450-453: Reset blocks are correctly placed.

Also applies to: 534-536

packages/convert/src/percent-to-deepnote.ts (3)

1-1: Correct import.

Using node:crypto prefix is idiomatic for Node.js built-ins.


14-16: JSDoc updated.

Documentation reflects the new default.


159-159: All ID generation sites updated.

Consistent use of randomUUID throughout. Node ≥22.14.0 requirement ensures availability.

Also applies to: 176-176, 183-183, 201-201

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@saltenasl saltenasl merged commit 7f68999 into main Jan 14, 2026
20 checks passed
@saltenasl saltenasl deleted the ls/convert-cjs-compat branch January 14, 2026 07:47
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