Skip to content

feat(DEP0210,DEP0211): add node:sqlite class renames codemod - #571

Open
FrustratedBoy420 wants to merge 4 commits into
nodejs:mainfrom
FrustratedBoy420:feat/dep0210-sqlite-class-renames
Open

FrustratedBoy420 wants to merge 4 commits into
nodejs:mainfrom
FrustratedBoy420:feat/dep0210-sqlite-class-renames

Conversation

@FrustratedBoy420

@FrustratedBoy420 FrustratedBoy420 commented Nov 12, 2026 •

Copy link
Copy Markdown

Closes #560

What

Adds a new recipe, @nodejs/sqlite-class-renames, for DEP0210 and DEP0211. It renames DatabaseSync to Database and StatementSync to Statement for bindings that resolve to node:sqlite.

-import { DatabaseSync, StatementSync } from 'node:sqlite';
+import { Database, Statement } from 'node:sqlite';

-const db = new DatabaseSync(':memory:');
+const db = new Database(':memory:');
 const statement = db.prepare('SELECT 1');
-console.log(statement instanceof StatementSync);
+console.log(statement instanceof Statement);

Supported forms

  • ESM named imports (including import { type StatementSync }), namespace imports, and default imports
  • CommonJS destructuring (const { DatabaseSync } = require(...)) and property access (sqlite.DatabaseSync, require('node:sqlite').StatementSync)
  • await import('node:sqlite') with destructuring or a namespace binding
  • Re-exports and local exports
  • TypeScript type references, including sqlite.StatementSync as a qualified type

How it stays safe

Following the guidance in the issue:

  • Only node:sqlite is resolved. The shared helpers match ^(node:)?sqlite$, but sqlite without the prefix is a third-party package, so this recipe matches the node:sqlite specifier only.
  • Explicit aliases are preserved. DatabaseSync as DB becomes Database as DB, and references to DB do not change.
  • Collisions and shadowing. A local binding is renamed in place only when the new name is unused in the file and the old name is not declared anywhere else (parameters, variables, functions, classes, types, catch clauses, other imports). Otherwise the import keeps the old local name as an alias, for example import { Database as DatabaseSync } from 'node:sqlite', and no other code changes.
  • Public export names are preserved. export { DatabaseSync } from 'node:sqlite' becomes export { Database as DatabaseSync } from 'node:sqlite'. export { DatabaseSync } of a renamed local becomes export { Database as DatabaseSync }, and the shorthand { DatabaseSync } becomes { DatabaseSync: Database }.
  • No new Statement() is introduced. Only existing references are renamed.
  • Namespace redeclaration. If the namespace binding (for example sqlite) is declared again in the file, its member accesses are left unchanged and a warning is printed.
  • Idempotent. Replacement names and the alias form are left unchanged on a second run.

Not covered (documented in the README): computed access such as sqlite['DatabaseSync'], and import('node:sqlite').then(...) callbacks.

Tests

12 fixtures: ESM named, ESM aliases, ESM namespace and default imports, CJS destructuring with aliases, CJS property access, dynamic import, binding collisions, shadowed identifiers, re-exports and local exports, TypeScript, unrelated modules (sqlite, local files, plain properties), and already-migrated code.

  • npm test in the recipe: 12 passed
  • Idempotency: running the transform on every expected file produces no changes (12 passed)
  • biome lint: clean
  • npm run type-check: clean

AI assistance

This PR was written with help from Claude Code (claude-opus-5-5), following the OpenJS AI Coding Assistants Policy. All commits carry an Assisted-by: Claude Code (claude-opus-5-5) trailer. I take responsibility for this submission.

Rename `DatabaseSync` to `Database` and `StatementSync` to `Statement`
for bindings that resolve to `node:sqlite`. Support ESM named,
namespace, and default imports, CommonJS destructuring and property
access, aliases, `await import()`, re-exports, and TypeScript type
references.

Keep the old local name as an alias when the new name is already used
or the old name is declared again, and keep public export names. Leave
third-party `sqlite` packages and unrelated identifiers unchanged.

Closes nodejs#560

Assisted-by: Claude Code (claude-opus-5-5)
Copilot AI balanced review requested due to automatic review settings November 12, 2026 12:38

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@AugustinMauroy AugustinMauroy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could you read and apply rule of https://ai-coding-assistants-policy.openjsf.org/

Find `node:sqlite` bindings with `getModuleDependencies` and
`resolveBindingPath` from `@nodejs/codemod-utils` instead of custom
import, require, and dynamic import queries.

Type-only imports are not resolved by `resolveBindingPath`, so they are
now left unchanged and documented as a limitation.

Assisted-by: Claude Code (claude-opus-5-5)
@FrustratedBoy420

Copy link
Copy Markdown
Author

Thanks for the review, @AugustinMauroy. I've read the OpenJS AI Coding Assistants Policy and added an AI assistance section to the PR description. The new commit uses an Assisted-by trailer; the first one has Co-Authored-By: Claude, so could the squash message use Assisted-by: Claude Code (claude-opus-5-5)? I've also pushed the refactor to use the shared utils (details in the inline thread).

@FrustratedBoy420
FrustratedBoy420 force-pushed the feat/dep0210-sqlite-class-renames branch from 534035b to 84ec1f8 Compare November 13, 2026 10:03
@FrustratedBoy420

Copy link
Copy Markdown
Author

Update: I've rewritten the commit trailers to Assisted-by: Claude Code (claude-opus-5-5) and force-pushed. The code is unchanged; the refactor commit mentioned in the inline thread is now 84ec1f8.

Replace `node.kind() === '...'` comparisons with `node.is('...')`, as
suggested by @AugustinMauroy in review.

Assisted-by: Claude Code (claude-opus-5-5)
@FrustratedBoy420

Copy link
Copy Markdown
Author

Thanks for the suggestions, @AugustinMauroy! I've applied all five in 95edc81 and switched the one remaining kind() === check (the shorthand pattern in migrateNamedBinding) to is() as well, so the file is consistent. Tests, lint, and type-check all pass.

@FrustratedBoy420

Copy link
Copy Markdown
Author

@AugustinMauroy all review threads are addressed and resolved (the suggestions landed in 95edc81, and the trailers now follow the OpenJS AI policy). Could you take another look when you have time? Thanks!

@FrustratedBoy420

Copy link
Copy Markdown
Author

@brunocroh @JakobJingleheimer could one of you also take a look at this one? Thanks!

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.

feat(DEP0210,DEP0211): migrate SQLite class names to Database and Statement

3 participants