Skip to content

chore(cli): migrate JS files to TypeScript#1944

Merged
Tobbe merged 6 commits into
cedarjs:mainfrom
lisa-assistant:lisa/js-to-ts-20260618
Jun 18, 2026
Merged

chore(cli): migrate JS files to TypeScript#1944
Tobbe merged 6 commits into
cedarjs:mainfrom
lisa-assistant:lisa/js-to-ts-20260618

Conversation

@lisa-assistant

Copy link
Copy Markdown
Contributor

Summary

Migrates 10 JavaScript files in packages/cli/src/ to TypeScript. Each file was given appropriate types while keeping changes minimal — no logic changes, no refactoring.

Files migrated

File Notes
commands/build/buildPackagesTask.ts Typed task param with structural type; catch error as unknown
commands/experimental/setupOpentelemetryHandler.ts Typed handler args; inline task callback types
commands/experimental/setupRscHandler.ts Typed handler args; renamed local files var to cssFiles to avoid shadowing
commands/generate/job/jobHandler.ts Typed files() and handler() params; typed catch blocks
commands/generate/package/filesTask.ts Added typed options interface for files()
commands/generate/sdl/sdlHandler.ts Added types for Prisma field shapes; typed all helper functions
commands/generate/service/serviceHandler.ts Added PrismaField interface; typed scenario/field helpers
commands/setup/realtime/addRealtimeToGraphql.ts Typed ctx and task params
commands/setup/realtime/realtimeHandler.ts Typed handler args and internal callbacks
commands/setup/uploads/uploadsHandler.ts Typed handler arg

Type decisions

  • Used structural types (inline interfaces) for Listr task/ctx params rather than importing ListrTask types, to stay lightweight
  • Added a PrismaField interface in serviceHandler.ts and sdlHandler.ts for the Prisma DMMF field shape used throughout
  • Catch blocks use e as { message: string; exitCode?: number } — consistent with rest of the codebase
  • buildPackagesTask's task param uses a structural type since it's a Listr task context passed at runtime

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@netlify

netlify Bot commented Jun 18, 2026

Copy link
Copy Markdown

👷 Deploy request for cedarjs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 8d0f54c

@github-actions github-actions Bot added this to the chore milestone Jun 18, 2026
@nx-cloud

nx-cloud Bot commented Jun 18, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 8d0f54c

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded <1s View ↗
nx run-many -t build ✅ Succeeded 8s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 15s View ↗
nx run-many -t test:types ✅ Succeeded 7s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-18 20:13:54 UTC

@nx-cloud

nx-cloud Bot commented Jun 18, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit d0894ba

Command Status Duration Result
nx run-many -t build ✅ Succeeded 5s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-18 00:10:39 UTC

1 similar comment
@nx-cloud

nx-cloud Bot commented Jun 18, 2026

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit d0894ba

Command Status Duration Result
nx run-many -t build ✅ Succeeded 5s View ↗

💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-06-18 00:10:39 UTC

@greptile-apps

greptile-apps Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Migrates 10 CLI JavaScript files to TypeScript with minimal, non-breaking changes — adding structural interfaces for Prisma field shapes and Listr task params, narrowing catch blocks to unknown, and resolving previous strict-mode type errors in sdlHandler and serviceHandler.

  • All catch blocks now use instanceof Error narrowing rather than untyped e.message, which is consistent with the rest of the codebase.
  • The ModelSchemaField/ModelSchema and PrismaField interfaces introduced in sdlHandler.ts and serviceHandler.ts accurately model the Prisma DMMF shape and are reused correctly throughout both files.
  • fieldsToUpdate in serviceHandler.ts now handles composite foreign keys correctly via Object.fromEntries, and the documentation in docs/implementation-docs/2026-03-26-cedarjs-project-overview.md remains accurate — no CLI commands or behaviors changed.

Confidence Score: 5/5

Safe to merge — this is a type-annotation-only migration with no intentional logic changes and no modified runtime paths for production code.

All ten files add types without altering control flow. The catch-block narrowing and composite-FK fix are strict improvements. The only behavioral change found is in test-data generation for BigInt Prisma fields, which was already broken in the original JS (runtime TypeError); the migration converts that crash into a silent no-op, which is noted as a suggestion.

serviceHandler.ts — the BigInt update-value encoding path; sdlHandler.ts — worth a final tsc --noEmit pass to confirm the previous thread's strict-mode issues are fully resolved.

Important Files Changed

Filename Overview
packages/cli/src/commands/build/buildPackagesTask.ts Clean migration; adds structural task type, ?? '' fallback for .at(-1), and proper unknown catch with instanceof narrowing.
packages/cli/src/commands/experimental/setupOpentelemetryHandler.ts Handler args and all inline Listr task callbacks typed; catch block narrowed correctly.
packages/cli/src/commands/experimental/setupRscHandler.ts Typed handler args; ?? '' fallback for potentially-null entryClient is fine given the prerequisite check comment; files renamed to cssFiles to avoid shadowing.
packages/cli/src/commands/generate/job/jobHandler.ts Clean migration; files() and handler() params typed, catch block properly narrowed.
packages/cli/src/commands/generate/package/filesTask.ts Simple migration; options interface added and Promise.resolve typed, no issues.
packages/cli/src/commands/generate/sdl/sdlHandler.ts Complex migration; ModelSchemaField/ModelSchema interfaces introduced, idType return narrowed to string
packages/cli/src/commands/generate/service/serviceHandler.ts Complex migration with PrismaField interface; composite FK now correctly expands to separate keys via Object.fromEntries. BigInt case in fieldsToUpdate silently no-ops due to type guard (see comment).
packages/cli/src/commands/setup/realtime/addRealtimeToGraphql.ts Clean migration; ctx and task typed with minimal structural interfaces.
packages/cli/src/commands/setup/realtime/realtimeHandler.ts Clean migration; handler args typed, handleExamplesPreference return type explicit, catch block narrowed.
packages/cli/src/commands/setup/uploads/uploadsHandler.ts Minimal change — only the handler destructure typed, catch block narrowed.

Reviews (6): Last reviewed commit: "fix(cli): remove all remaining `as` type..." | Re-trigger Greptile

Comment thread packages/cli/src/commands/generate/sdl/sdlHandler.ts Outdated
Comment thread packages/cli/src/commands/generate/service/serviceHandler.ts
lisa-assistant and others added 3 commits June 18, 2026 02:19
Add ModelSchema/ModelSchemaField interfaces, fix idType return type,
and resolve strict-mode errors flagged by Greptile review.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…s in sdl/service handlers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Comment thread packages/cli/src/commands/generate/sdl/sdlHandler.ts Outdated
lisa-assistant and others added 2 commits June 18, 2026 21:34
- sdlHandler: remove unnecessary `as ModelSchema` cast (types is Record<string,ModelSchema>)
- sdlHandler: use optional chain `idField?.default` instead of `idField && idField.default`
- sdlHandler: use `includes()` instead of `indexOf() === -1`
- sdlHandler: use `ModelSchemaField[]` array syntax instead of `Array<ModelSchemaField>`
- sdlHandler: widen `idType` return type cast from narrow inline type to `ModelSchemaField[]`
- serviceHandler: use `{ name; dbName? }[]` array syntax instead of `Array<{...}>`
- serviceHandler: change `let scalarFields` to `const` (never reassigned)
- jobHandler: use optional catch binding `catch { }` instead of `catch (_e)`

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- buildPackagesTask: `w.split('/').at(-1) ?? ''` instead of `as string`;
  `instanceof Error` + `'stderr' in e` narrowing for execa errors
- setupOpentelemetryHandler/setupRscHandler/jobHandler/realtimeHandler/
  uploadsHandler: `instanceof Error` + exitCode narrowing in all catch blocks
- setupRscHandler: extract `entryClient = rwPaths.web.entryClient ?? ''`
  (non-null guaranteed by 'Check prerequisites' task that throws if null)
- filesTask: `Promise.resolve<Record<string, string>>({})` generic form
- realtimeHandler: `return incl ?? false` instead of `as boolean`
- sdlHandler: replace `idType() as string` with `typeof resolvedType === 'string'`
  guard — also fixes silent `field.type = undefined` corruption from original JS
- sdlHandler: replace `as ModelSchemaField[]` cast with `.filter((f): f is
  ModelSchemaField => f !== undefined)` — undefined elements now filtered
  rather than hidden by the cast
- serviceHandler: `typeof value === 'bigint/number/string'` narrowing in switch
  cases instead of `newValue as T` casts
- serviceHandler: `Array.isArray(fieldName)` guard + `Object.fromEntries` for
  composite FK case instead of `fieldName as string` cast

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Tobbe
Tobbe merged commit 93e436c into cedarjs:main Jun 18, 2026
46 checks passed
Tobbe added a commit that referenced this pull request Jun 18, 2026
Tobbe added a commit that referenced this pull request Jul 5, 2026
@Tobbe Tobbe modified the milestones: chore, v5.0.0 Jul 10, 2026
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