Refactor: Migrate packages/cli from MJS to TypeScript #3

Merged
xiaonuo merged 3 commits from fix/1-migrate-cli-to-typescript into main 2026-05-28 14:53:04 +00:00
Owner

Summary

Migrates the packages/cli package from vanilla MJS to TypeScript with full type safety and comprehensive test coverage.

What Changed

  • Converted source files: urec.mjsurec.ts, uconn.mjsuconn.ts
  • Added TypeScript configuration: tsconfig.json with strict mode enabled
  • Created type declarations: src/types/protocol.d.ts for external protocol types
  • Comprehensive test suite: 22 tests across 3 test suites
  • Updated build process: Compiles to dist/ with source maps and type declarations
  • Updated package.json: Bin entries point to compiled dist/ output
  • Removed old MJS files: Cleaned up original .mjs sources

Why

Issue #1 requested TypeScript migration to improve:

  • Type safety across the CLI codebase
  • Developer experience with IDE autocomplete
  • Maintainability with explicit type contracts
  • Build-time error detection

Changes

New Files

  • packages/cli/tsconfig.json - TypeScript configuration with strict mode
  • packages/cli/src/urec.ts - Migrated from urec.mjs with full type annotations
  • packages/cli/src/uconn.ts - Migrated from uconn.mjs with full type annotations
  • packages/cli/src/types/protocol.d.ts - Type declarations for protocol
  • packages/cli/__tests__/urec.test.ts - Comprehensive urec test suite (196 lines)
  • packages/cli/__tests__/uconn.test.ts - Type safety tests for uconn
  • packages/cli/__tests__/build.test.ts - Build configuration tests

Modified Files

  • packages/cli/package.json - Added build script, updated bin entries, added @types/ws
  • bun.lock - Updated dependencies

Deleted Files

  • packages/cli/src/urec.mjs - Replaced by urec.ts
  • packages/cli/src/uconn.mjs - Replaced by uconn.ts

Verification

All 22 tests pass
TypeScript compiles with strict mode (0 errors)
Biome lint checks pass (0 errors)
Both executables work correctly after build
Zero any types in codebase
Full backward compatibility maintained

Ref

Fixes #1

## Summary Migrates the `packages/cli` package from vanilla MJS to TypeScript with full type safety and comprehensive test coverage. ## What Changed - **Converted source files**: `urec.mjs` → `urec.ts`, `uconn.mjs` → `uconn.ts` - **Added TypeScript configuration**: `tsconfig.json` with strict mode enabled - **Created type declarations**: `src/types/protocol.d.ts` for external protocol types - **Comprehensive test suite**: 22 tests across 3 test suites - **Updated build process**: Compiles to `dist/` with source maps and type declarations - **Updated package.json**: Bin entries point to compiled `dist/` output - **Removed old MJS files**: Cleaned up original `.mjs` sources ## Why Issue #1 requested TypeScript migration to improve: - Type safety across the CLI codebase - Developer experience with IDE autocomplete - Maintainability with explicit type contracts - Build-time error detection ## Changes ### New Files - `packages/cli/tsconfig.json` - TypeScript configuration with strict mode - `packages/cli/src/urec.ts` - Migrated from urec.mjs with full type annotations - `packages/cli/src/uconn.ts` - Migrated from uconn.mjs with full type annotations - `packages/cli/src/types/protocol.d.ts` - Type declarations for protocol - `packages/cli/__tests__/urec.test.ts` - Comprehensive urec test suite (196 lines) - `packages/cli/__tests__/uconn.test.ts` - Type safety tests for uconn - `packages/cli/__tests__/build.test.ts` - Build configuration tests ### Modified Files - `packages/cli/package.json` - Added build script, updated bin entries, added @types/ws - `bun.lock` - Updated dependencies ### Deleted Files - `packages/cli/src/urec.mjs` - Replaced by urec.ts - `packages/cli/src/uconn.mjs` - Replaced by uconn.ts ## Verification ✅ All 22 tests pass ✅ TypeScript compiles with strict mode (0 errors) ✅ Biome lint checks pass (0 errors) ✅ Both executables work correctly after build ✅ Zero `any` types in codebase ✅ Full backward compatibility maintained ## Ref Fixes #1
xiaonuo added 3 commits 2026-05-28 10:27:59 +00:00
Migrate urec and uconn CLI tools from plain JavaScript (.mjs) to TypeScript (.ts) with full type safety and strict mode enabled.

Changes:
- Created TypeScript configuration (tsconfig.json) with strict mode
- Migrated src/urec.mjs to src/urec.ts with proper type annotations
- Migrated src/uconn.mjs to src/uconn.ts with proper type annotations
- Added type declarations for @uncaged/dashboard-server/protocol
- Updated package.json with build script and bin entries pointing to dist/
- Added comprehensive test suites for type safety and functionality
- Added .gitignore to exclude built artifacts

Type Safety:
- No implicit any types throughout the codebase
- Explicit type annotations for all variables and functions
- Proper null safety with strictNullChecks
- Full type coverage for Node.js built-ins and external dependencies

Testing:
- 22 passing tests covering type safety, build config, and functionality
- Tests verify TypeScript compilation succeeds
- Tests verify executables work correctly with preserved shebangs
- Tests verify backward compatibility of CLI behavior

Build:
- TypeScript compiles successfully with no errors
- Built files maintain ESM format
- Shebang lines preserved in output
- Source maps generated for debugging

Resolves #1

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Apply biome auto-fixes:
- Sort imports: move type imports first in urec.ts and uconn.ts
- Remove inferrable type annotations (stdoutBuf, stderrBuf, backoff)

Complete migration:
- Delete old urec.mjs and uconn.mjs files

All biome checks now pass with no errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
style(cli): apply biome formatting to test files
CI / check (pull_request) Successful in 45s
a894a1642b
Fix import ordering and formatting in test files to pass biome checks.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
xiaonuo merged commit 44b13fe6f1 into main 2026-05-28 14:53:04 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/worker-dashboard#3