Skip to content

chore(cli): Convert JS files to TS (part III)#873

Merged
Tobbe merged 13 commits intomainfrom
tobbe-cli-ts-part-II
Mar 18, 2026
Merged

chore(cli): Convert JS files to TS (part III)#873
Tobbe merged 13 commits intomainfrom
tobbe-cli-ts-part-II

Conversation

@Tobbe
Copy link
Member

@Tobbe Tobbe commented Dec 28, 2025

Continue on #855

@netlify
Copy link

netlify bot commented Dec 28, 2025

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit 2baaa10
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/69bb2d1ce658c7000894ce84

@github-actions github-actions bot added this to the chore milestone Dec 28, 2025
@nx-cloud
Copy link

nx-cloud bot commented Dec 28, 2025

🤖 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 2baaa10

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

☁️ Nx Cloud last updated this comment at 2026-03-18 23:12:30 UTC

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 28, 2025

Greptile Summary

This PR continues the JS→TS migration for CLI command handlers and their tests (build, console, dev, exec, lint, prerender, test, type-check, upgrade). The conversion adds proper interfaces and type annotations, replaces any casts with structured types, updates test files to use vi.mocked(), and removes now-unneeded @ts-expect-error comments where imported modules have been converted to TypeScript. Several improvements beyond pure type-annotation are included (e.g. res.ok HTTP checks in upgradeHandler, a isREPLServerWithHistory type guard in consoleHandler, and rendererOptions improvements in Listr calls).

Key concerns:

  • Critical regression in prerenderHandler.ts: The regex /\\{.*}/ introduced at line 372 only matches paths that contain a literal backslash character, effectively disabling the PathParamError guard that was supposed to detect unresolved route parameters like {id:Int}. The original /\{.*}/ was correct and should be restored.
  • Misleading error message in upgradeHandler.ts: The patch download loop's error handler uses the outer tree-API url variable instead of patch.url, making failures harder to diagnose.
  • Inconsistent import extension in type-check.test.ts: The handler import uses .ts rather than the .js extension used by every other test converted in this PR.

Confidence Score: 2/5

  • Not safe to merge as-is due to a critical regex regression that silently disables route-parameter validation in prerendering.
  • The bulk of the JS→TS conversion is clean and well-typed, but the change to /\\{.*}/ in prerenderHandler.ts breaks the PathParamError guard entirely. Any route that still has unresolved {param} placeholders will now silently proceed to prerender instead of erroring, producing incorrect HTML output. This regression must be fixed before merging. The misleading error URL in upgradeHandler.ts is lower severity but should still be corrected.
  • packages/cli/src/commands/prerenderHandler.ts (regex regression at line 372) and packages/cli/src/commands/upgrade/upgradeHandler.ts (wrong URL in error message at line 556).

Important Files Changed

Filename Overview
packages/cli/src/commands/prerenderHandler.ts Major TS conversion with several improvements, but introduces a regex regression at line 372 (/\\{.*}/ vs /\{.*}/) that silently disables the PathParamError guard for unresolved route parameters.
packages/cli/src/commands/upgrade/upgradeHandler.ts Adds !res.ok HTTP status checks (addressing a prior review comment), but the inner downloadYarnPatches error message reports the wrong URL (url instead of patch.url).
packages/cli/src/commands/tests/type-check.test.ts Proper TS conversion with vi.mocked() usage, but imports handler with .ts extension instead of the .js extension used consistently across all other converted tests in this PR.
packages/cli/src/commands/build/buildHandler.ts Clean JS→TS conversion: adds BuildHandlerOptions and PackageJson interfaces, correctly typed ListrTask filter cast, and @ts-expect-error suppression comments where needed.
packages/cli/src/commands/consoleHandler.ts Improved type safety: replaces unsafe ReplWithHistory cast with a proper isREPLServerWithHistory type guard, and fixes the asyncEval catch block to produce a proper Error for non-Error throws.
packages/cli/src/commands/test/tests/test.test.ts Full rewrite in TypeScript using vi.mocked(), import.meta.dirname, and a defaultOptions constant to satisfy required TestOptions fields, cleanly replacing the deleted .js version.
packages/cli/src/commands/execHandler.ts Refactors ExecArgs to ExecOptions interface, removes _ and $0 shorthand properties, adds Array.isArray guard for scriptArgs._, and removes stale @ts-expect-error for generatePrismaClient.
packages/cli/src/commands/lint.ts Switches getPaths/getConfig import from ../lib/index.js to @cedarjs/project-config; adds defensive runtime checks before accessing eslintLegacyConfigWarning.
packages/cli/src/commands/type-checkHandler.ts Exports TypeCheckHandlerArgs type, updates path import to node:path, removes stale @ts-expect-error, and adds rendererOptions: { collapseSubtasks: false } to the Listr call.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[CLI Command Entry .ts] --> B{Dynamic Import}
    B --> C[buildHandler.ts]
    B --> D[consoleHandler.ts]
    B --> E[devHandler.ts]
    B --> F[execHandler.ts]
    B --> G[prerenderHandler.ts]
    B --> H[type-checkHandler.ts]
    B --> I[upgradeHandler.ts]

    C --> C1[BuildHandlerOptions interface]
    C --> C2[ListrTask filter cast]
    D --> D1[isREPLServerWithHistory guard]
    D --> D2[async eval error wrapping]
    F --> F1[ExecOptions interface]
    F --> F2[Array.isArray scriptArgs._]
    G --> G1["regex /\\{.*}/ ⚠️ BUG"]
    G --> G2[typeof Prerender cast]
    G --> G3[QueryInfo queryCache type]
    H --> H1[Export TypeCheckHandlerArgs]
    H --> H2[rendererOptions added]
    I --> I1[res.ok checks added]
    I --> I2["Wrong URL in error msg ⚠️"]
Loading

Last reviewed commit: "fix test tests"

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Additional Comments (1)

  1. packages/cli/src/commands/execHandler.ts, line 177-179 (link)

    syntax: Same template literal interpolation issue

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

31 files reviewed, 3 comments

Edit Code Review Agent Settings | Greptile

@Tobbe
Copy link
Member Author

Tobbe commented Dec 30, 2025

@greptileai Please do a full review again and update your review summary

@Tobbe Tobbe changed the title chore(cli): Convert JS files to TS (part II) chore(cli): Convert JS files to TS (part III) Dec 30, 2025
@Tobbe Tobbe force-pushed the main branch 5 times, most recently from 0f0e039 to aa1c62d Compare January 8, 2026 23:14
@github-actions
Copy link

github-actions bot commented Mar 5, 2026

This PR is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added Stale and removed Stale labels Mar 5, 2026
@Tobbe Tobbe closed this Mar 18, 2026
# Conflicts:
#	packages/cli/src/commands/__tests__/build.test.ts
#	packages/cli/src/commands/__tests__/prisma.test.ts
#	packages/cli/src/commands/__tests__/upgrade.test.ts
#	packages/cli/src/commands/build.ts
#	packages/cli/src/commands/buildHandler.ts
#	packages/cli/src/commands/check.ts
#	packages/cli/src/commands/console.ts
#	packages/cli/src/commands/consoleHandler.ts
#	packages/cli/src/commands/destroy.ts
#	packages/cli/src/commands/dev.ts
#	packages/cli/src/commands/dev/__tests__/getDevNodeOptions.test.ts
#	packages/cli/src/commands/dev/devHandler.ts
#	packages/cli/src/commands/execHandler.ts
#	packages/cli/src/commands/experimental.ts
#	packages/cli/src/commands/generate.ts
#	packages/cli/src/commands/lint.ts
#	packages/cli/src/commands/prerender.ts
#	packages/cli/src/commands/prerenderHandler.ts
#	packages/cli/src/commands/prismaHandler.ts
#	packages/cli/src/commands/test.ts
#	packages/cli/src/commands/test/__tests__/test.test.js
#	packages/cli/src/commands/type-check.ts
#	packages/cli/src/commands/type-checkHandler.ts
#	packages/cli/src/commands/upgrade.ts
#	packages/cli/src/testLib/cells.ts
#	packages/cli/tsconfig.build.json
#	packages/cli/tsconfig.json
@Tobbe Tobbe reopened this Mar 18, 2026
@Tobbe
Copy link
Member Author

Tobbe commented Mar 18, 2026

@greptileai Please do a full review again

@Tobbe Tobbe merged commit 1466e90 into main Mar 18, 2026
42 checks passed
@Tobbe Tobbe deleted the tobbe-cli-ts-part-II branch March 18, 2026 23:15
@github-actions
Copy link

The changes in this PR are now available on npm.

Try them out by running yarn cedar upgrade -t 3.0.0-canary.13614

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.

1 participant