Back to Cypress

ESM Migration Guide: Monorepo Alignment

guides/esm-migration.md

15.13.15.5 KB
Original Source

ESM Migration Guide: Monorepo Alignment

Migration Checklist

Phase 1: Convert Packages to TypeScript

Criteria

  • No require statements are to be used in .ts files
  • Unit tests in package are written in TypeScript
  • Does not include scripts or system test migrations

Notes

When migrating some of these projects away from the ts-node entry see @packages/scaffold-config example, it is somewhat difficult to make separate browser/node entries as the v8-snapshot tsconfig.json is using an older style of module resolution where the exports key inside a package's package.json is not well supported. Because of this, we need to find ways to bundle code that is needed internally in the browser vs in node without them being a part of the same bundle. This is a temporary work around until we are able to get every package being able to build as an ES Module, which as that point we can re assess how the Cypress binary is being built as well as v8-snapshots, and will allow us to reconfigure this packages to export content in a more proper fashion. We are currently doing something similar in the following packages:

  • @packages/scaffold-config
  • @packages/socket
  • @packages/telemetry

Status

NPM Packages
  • cli ✅ COMPLETED
  • npm/angular ✅ COMPLETED
  • npm/cypress-schematic ✅ COMPLETED
  • npm/eslint-plugin-dev
  • npm/grep ✅ COMPLETED
  • npm/mount-utils ✅ COMPLETED
  • npm/puppeteer ✅ COMPLETED
  • npm/react ✅ COMPLETED
  • npm/svelte ✅ COMPLETED
  • npm/vite-dev-server ✅ COMPLETED
  • vite-plugin-cypress-esm ✅ COMPLETED
  • npm/vue ✅ COMPLETED
  • npm/webpack-batteries-included-preprocessor ✅ COMPLETED
  • npm/webpack-dev-server ✅ COMPLETED
  • npm/webpack-preprocessor ✅ COMPLETED
Binary Packages
  • packages/app PARTIAL - low priority: frontend package
  • packages/config ✅ COMPLETED
  • packages/data-context PARTIAL - entry point is JS
  • packages/driver ✅ COMPLETED - source complete, cypress tests need migration
  • packages/electron ✅ COMPLETED
  • packages/error ✅ COMPLETED
  • packages/eslint-config ✅ COMPLETED
  • packages/example
  • packages/extension ✅ COMPLETED
  • packages/frontend-shared PARTIAL - entry point is JS
  • packages/electron ✅ COMPLETED
  • packages/https-proxy - ✅ COMPLETED
  • packages/icons ✅ COMPLETED
  • packages/launcher ✅ COMPLETED
  • packages/launchpad ✅ COMPLETED
  • packages/net-stubbing ✅ COMPLETED
  • packages/network ✅ COMPLETED
  • packages/network-tools ✅ COMPLETED
  • packages/packherd-require ✅ COMPLETED
  • packages/proxy PARTIAL - entry point is JS
  • packages/reporter ✅ COMPLETED
  • packages/resolve-dist ✅ COMPLETED
  • packages/rewriter PARTIAL - entry point is JS
  • packages/root ✅ COMPLETED
  • packages/runner ✅ COMPLETED
  • packages/scaffold-config ✅ COMPLETED
  • packages/server PARTIAL - many source/test files in JS. highest priority
  • packages/socket ✅ COMPLETED
  • packages/stderr-filtering ✅ COMPLETED
  • packages/telemetry ✅ COMPLETED
  • packages/ts PARTIAL - ultimate goal is removal and likely not worth the effort to convert
  • packages/types ✅ COMPLETED
  • packages/v8-snapshot-require
  • packages/web-config

Phase 2: Convert Package tests from Mocha to Vitest

Status

NPM Packages
  • cli ✅ COMPLETED
  • npm/cypress-schematic ✅ COMPLETED
  • npm/eslint-plugin-dev ✅ COMPLETED
  • npm/grep ✅ COMPLETED
  • npm/puppeteer ✅ COMPLETED
  • npm/vite-dev-server ✅ COMPLETED
  • npm/webpack-batteries-included-preprocessor ✅ COMPLETED
  • npm/webpack-dev-server ✅ COMPLETED
  • npm/webpack-preprocessor ✅ COMPLETED
Binary Packages
  • packages/config ✅ COMPLETED
  • packages/data-context COMPLETED (migrated from mocha/sinon/chai to jest). See package README for more details as to why jest over vitest
  • packages/driver ✅ COMPLETED
  • packages/electron ✅ COMPLETED
  • packages/error ✅ COMPLETED
  • packages/extension ✅ COMPLETED
  • packages/https-proxy ✅ COMPLETED
  • packages/electron ✅ COMPLETED
  • packages/icons ✅ COMPLETED
  • packages/launcher ✅ COMPLETED
  • packages/net-stubbing ✅ COMPLETED
  • packages/network ✅ COMPLETED
  • packages/network-tools ✅ COMPLETED
  • packages/packherd-require ✅ COMPLETED
  • packages/proxy ✅ COMPLETED
  • packages/rewriter ✅ COMPLETED
  • packages/scaffold-config ✅ COMPLETED
  • packages/server
  • packages/socket ✅ COMPLETED
  • packages/stderr-filtering ✅ COMPLETED
  • packages/telemetry ✅ COMPLETED
  • packages/ts - ultimate goal is removal and likely not worth the effort to convert
  • packages/types ✅ COMPLETED
  • packages/v8-snapshot-require ✅ COMPLETED

Phase 3: Bundle ESM/CJS versions of NPM packages

TBD: details will be clearer at the end of Phase 2

Phase 4: Run Cypress server as an ESM package

TBD: details will be clearer at the end of Phase 2