Skip to content

chore(codemods): Convert from CJS to ESM#1303

Merged
Tobbe merged 2 commits intomainfrom
tobbe-chore-codemods-esm-only
Mar 4, 2026
Merged

chore(codemods): Convert from CJS to ESM#1303
Tobbe merged 2 commits intomainfrom
tobbe-chore-codemods-esm-only

Conversation

@Tobbe
Copy link
Member

@Tobbe Tobbe commented Mar 4, 2026

This is safe as no one imports this package. It's always run as a bin

Tobbe added 2 commits March 4, 2026 09:58
This is save as no one imports this package. It's always run as a bin
@netlify
Copy link

netlify bot commented Mar 4, 2026

Deploy Preview for cedarjs canceled.

Name Link
🔨 Latest commit aa0f279
🔍 Latest deploy log https://app.netlify.com/projects/cedarjs/deploys/69a7f75733754800088e6802

@github-actions github-actions bot added this to the chore milestone Mar 4, 2026
@nx-cloud
Copy link

nx-cloud bot commented Mar 4, 2026

🤖 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 aa0f279

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 8s View ↗
nx run-many -t build ✅ Succeeded 8s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 26s View ↗
nx run-many -t test:types ✅ Succeeded 9s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-04 09:31:53 UTC

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 4, 2026

Greptile Summary

This PR converts the @cedarjs/codemods package from CommonJS to ESM by updating package.json to "type": "module", switching the build tool to buildEsm, and making all the mechanical code changes required (.js extensions on local imports, __dirnameimport.meta.dirname, ESM-compatible yargs imports, explicit jscodeshift/src/Runner.js path). The migration is safe since the package is consumed only as a CLI binary and never imported by other packages.

Key changes verified:

  • package.json: "type": "commonjs""type": "module"; build.mts switches to buildEsm()
  • All local imports gain explicit .js extensions as required by Node.js ESM resolution
  • All __dirname references replaced with import.meta.dirname (requires Node.js ≥ 20.11.0)
  • yargs entrypoint updated from the CJS default export to the ESM-compatible yargs/yargs factory pattern with hideBin(process.argv)
  • New tsconfig.build.json added with "module": "node20" / "moduleResolution": "node16", consistent with other packages in the monorepo (e.g. cli)
  • Code-generation templates updated so any newly-generated codemods are immediately ESM-compliant
  • Test utilities correctly updated with .js extensions; require.resolve() usage in test files is appropriate in vitest test environments

Confidence Score: 5/5

  • This PR is safe to merge — it is a clean, mechanical CJS-to-ESM migration with no behavioural changes.
  • All changes are consistent and follow the same pattern used by other ESM packages in the monorepo. The yargs ESM idiom is correct, import.meta.dirname is the proper replacement for __dirname, and explicit .js extensions are required by Node.js ESM. The code has been tested and passes CI. No new issues introduced.
  • No files require special attention.

Last reviewed commit: aa0f279

@Tobbe Tobbe merged commit 91b4a33 into main Mar 4, 2026
41 checks passed
@Tobbe Tobbe deleted the tobbe-chore-codemods-esm-only branch March 4, 2026 10:04
@github-actions
Copy link

github-actions bot commented Mar 4, 2026

The changes in this PR are now available on npm.

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

Tobbe added a commit that referenced this pull request Mar 7, 2026
This is safe as no one imports this package. It's always run as a bin
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