esm-merge-coverage

Converts CommonJS sources to ESM after merging pre-ESM branches into apps/app.

1.5k|244|Updated Feb 16, 2017
One-click install
npx skills add https://github.com/growilabs/growi --skill esm-merge-coverage
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: esm-merge-coverage
Source: https://github.com/growilabs/growi/tree/main/apps/app/.claude/skills/esm-merge-coverage
Command: npx skills add https://github.com/growilabs/growi --skill esm-merge-coverage

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires jscodeshift.

What problem does it solve?

Merging a pre-ESM branch into the v8 ESM mainline of apps/app silently reintroduces CommonJS code (require, module.exports, __dirname, .js specifiers) that only fails later at build or runtime. This Skill runs the post-merge coverage pass that detects, converts, and verifies those incoming files so the merge finishes green.

Core Features & Use Cases

  • Scoped detection and conversion: Diffs against the merge base to find incoming files, then runs the repo's codemods (cjs-to-esm, migrations-cjs-to-esm, normalize-import-convention) bucket by bucket, leaf to root.
  • CJS isolation and config handling: Keeps genuinely CJS-only configs as .cjs with .d.cts siblings, converts migrate-mongo migrations to named ESM exports, and re-evaluates package.json type fields and transpilePackages.
  • Verification gates: Drives lint:no-cjs, lint:import-convention, lint:route-guard, build:server, verify-dist-resolution, and a boot smoke test to prove the conversion is complete.
  • Use Case: After merging a v7-era feature branch into master, run this Skill to convert the incoming server sources, strip stray .js extensions, fix circular-dependency hazards via factory DI, and confirm all gates pass before opening the PR.

Quick Start

After merging a pre-ESM branch into apps/app, ask the assistant to run the ESM merge coverage pass and bring the merged code up to the ESM convention.

Frequently Asked Questions about esm-merge-coverage

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I convert CommonJS to ESM after merging an old branch?

Diff against the merge base to list incoming files, then run the repo's cjs-to-esm codemod on server sources leaf-to-root, followed by the migrations codemod and import-convention normalizer. Finish by running the lint, build, and dist-resolution verification gates.

Why does a git merge break an ESM codebase?

A git merge copies source verbatim and never runs codemods, lint, or build steps, so pre-ESM files with require and module.exports land unconverted. They only surface later as type-check failures, ERR_MODULE_NOT_FOUND, or initialization errors at runtime.

How do I fix circular dependency errors after ESM conversion?

ESM static hoisting exposes cycles that CJS lazy require hid, throwing Cannot access before initialization at boot. The fix is factory DI: services and models must receive the Crowi instance as an argument instead of importing the Crowi class, or split shared types into an interfaces file.

Should migrate-mongo migrations use export default or named exports?

Migrations must use named exports, export async function up and down, because migrate-mongo reads migration.up and migration.down off the loaded module. export default leaves migration.up undefined and module.exports throws under type module.

When should a config file stay CommonJS instead of ESM?

Keep a config as .cjs only when it is consumed by a CJS-only CLI such as migrate-mongo, paired with a hand-written .d.cts sibling and .cjs specifiers in importers. Configs consumed by ESM-capable tooling should use .mjs instead.

When should I not use this merge coverage skill?

Do not use it for net-new code authored on an ESM branch, which is already covered by the normal lint gates and ESM authoring rules. It is specifically for imported code from branches that predate the v8 ESM migration.