Skip to content

Conversation

@cs-raj
Copy link
Contributor

@cs-raj cs-raj commented Jan 28, 2026

Feat: Contentstack Migration – TypeScript conversion & unit tests (DX-3899)

Summary

Migrates the @contentstack/cli-migration package from JavaScript to TypeScript and adds unit test coverage.

Changes (contentstack-migration only)

TypeScript migration

  • Source: All src/ modules converted from .js to .ts (actions, commands, config, modules, services, utils, validators).
  • Build: Added tsconfig.json; package now compiles to lib/ and OCLIF commands point to lib/commands.
  • Types: Added types/index.d.ts for external module declarations.
  • Config: .gitignore updated for lib/ and tsconfig.tsbuildinfo; .mocharc.json and .nycrc.json added for TS test runs.

Package updates

  • Version: 1.10.31.11.0.
  • DevDependencies: TypeScript, ts-node, @types/node, @types/mocha, mocha, sinon, source-map-support.
  • Scripts: compile, prepack (compile before manifest/readme), tests updated to run test/unit/**/*.test.ts with mocha.

Example fix

  • change-master-locale: Example updated so masterLocale is set from masterLocale[0] (removed optional ?.code to match actual structure).

Unit tests

  • New unit tests for the migration package.
  • Tests wired into package scripts and run with the TypeScript toolchain.

Test coverage

  • How to run: From repo root, pnpm run test:unit:report in packages/contentstack-migration, or from that package: pnpm run test:unit:report.
  • Coverage report: nyc is configured (.nycrc.json) to report on lib/**/*.js (compiled output). Run the script to generate statements/branches/functions/lines coverage.
  • Areas covered:
    • Actions: action-list, action creators (index)
    • Commands: cm:stacks:migration
    • Config: api-config, default-options, master-locale, config index
    • Modules: base, content-types, fields, locale, migration, parser, module index
    • Services: content-types, locales, services index
    • Utils: auto-retry, callsite, constants, contentstack-sdk, error-helper, fs-helper, get-batches, get-config, group-by, logger, map, migration-logger, modules, object-helper, request, safe-promise, schema-helper, success-handler, utils index
    • Validators: api-error, base-validator, create-content-type-validator, edit-content-type-validator, field-validator, migration-error, schema-validator, type-error, validators index

Impact

  • No intended breaking changes for CLI consumers; migration command behavior unchanged.
  • Better type safety and maintainability; unit tests guard regressions.

Testing

  • Coverage is 80%+

aman19K
aman19K previously approved these changes Jan 30, 2026
aman19K
aman19K previously approved these changes Jan 30, 2026
@cs-raj cs-raj marked this pull request as ready for review January 30, 2026 11:18
@cs-raj cs-raj requested a review from a team as a code owner January 30, 2026 11:18
@cs-raj cs-raj merged commit 0301cbe into development Jan 30, 2026
10 checks passed
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.

3 participants