Skip to content

refactor: convert all packages to ESM with named exports#224

Merged
zkochan merged 1 commit intomainfrom
esm-conversion
Mar 11, 2026
Merged

refactor: convert all packages to ESM with named exports#224
zkochan merged 1 commit intomainfrom
esm-conversion

Conversation

@zkochan
Copy link
Copy Markdown
Owner

@zkochan zkochan commented Mar 11, 2026

Summary

  • Convert all 33 workspace packages from CJS to ESM ("type": "module", import/export)
  • Replace all export default with named exports across source files, .d.ts type declarations, and tests
  • Switch inter-workspace dependencies to workspace:^ protocol for correct local linking
  • Remove dependenciesMeta/injected self-reference pattern, add "exports" field instead for self-referencing imports
  • Update pnpm-workspace.yaml to exclude **/node_modules_link/**

Test plan

  • All 28 test suites pass (pnpm -r test)
  • All TypeScript packages compile (pnpm -r prepublishOnly)
  • No remaining require()/module.exports in source files
  • No remaining export default/export = in source or type files

🤖 Generated with Claude Code

- Add `"type": "module"` and `"exports"` field to all package.json files
- Convert all `require()`/`module.exports` to `import`/`export`
- Replace all `export default` with named exports across source, types, and tests
- Switch inter-workspace dependencies to `workspace:^` protocol
- Remove `dependenciesMeta`/`injected` self-reference pattern (caused infinite prepublishOnly loop)
- Update `pnpm-workspace.yaml` to exclude `**/node_modules_link/**`
- Fix `fs-extra` import in rename-overwrite (CJS package needs default import)
- Update which-pm-runs test fixtures to ESM

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR migrates the workspace packages from CommonJS to ESM and standardizes all public APIs on named exports, while also updating workspace dependency/linking to rely on workspace:^ and package exports for self-referencing.

Changes:

  • Convert packages to ESM ("type": "module") and replace require/module.exports with import/export named exports across source, tests, and .d.ts.
  • Add exports entries to package manifests and remove the prior dependenciesMeta.injected self-reference pattern.
  • Update pnpm workspace/linking config (workspace:^, workspace exclusions, lockfile updates).

Reviewed changes

Copilot reviewed 112 out of 135 changed files in this pull request and generated no comments.

Show a summary per file
File Description
write-yaml-file/package.json Mark package as ESM and expose entry via exports.
write-yaml-file/index.js Convert implementation to ESM and named exports.
write-yaml-file/index.d.ts Switch typings to named exports.
write-json5-file/test.js Update tests to ESM imports and named exports.
write-json5-file/package.json Mark package as ESM and expose entry via exports.
write-json5-file/index.js Convert implementation to ESM and named exports.
write-json5-file/index.d.ts Switch typings to named exports and standalone types.
write-ini-file/test.js Update tests to ESM imports and named exports.
write-ini-file/package.json Mark package as ESM, add exports, remove injected self-reference.
write-ini-file/index.js Convert implementation to ESM and named exports.
write-ini-file/index.d.ts Switch typings to named exports.
which-pm/test/index.js Update tests to ESM, add __dirname via fileURLToPath, use named export.
which-pm/package.json Mark package as ESM, add exports, remove injected self-reference.
which-pm/index.js Convert implementation to ESM and named export whichPM.
which-pm/index.d.ts Switch typings to named exports and exported result types.
which-pm/example.js Update example to ESM and named export.
which-pm-runs/test/index.js Update tests to ESM and compute __dirname for fixtures.
which-pm-runs/test/fixtures/yarn/package.json Mark fixture as ESM for Node execution under ESM semantics.
which-pm-runs/test/fixtures/yarn/index.js Update fixture script to import named export.
which-pm-runs/test/fixtures/pnpm/package.json Mark fixture as ESM for Node execution under ESM semantics.
which-pm-runs/test/fixtures/pnpm/index.js Update fixture script to import named export.
which-pm-runs/test/fixtures/npm/package.json Mark fixture as ESM for Node execution under ESM semantics.
which-pm-runs/test/fixtures/npm/index.js Update fixture script to import named export.
which-pm-runs/test/fixtures/cnpm/package.json Mark fixture as ESM for Node execution under ESM semantics.
which-pm-runs/test/fixtures/cnpm/index.js Update fixture script to import named export.
which-pm-runs/test/fixtures/bun/package.json Mark fixture as ESM for Node execution under ESM semantics.
which-pm-runs/test/fixtures/bun/index.js Update fixture script to import named export.
which-pm-runs/package.json Mark package as ESM, add exports, remove injected self-reference.
which-pm-runs/index.js Export whichPMRuns as a named ESM export.
safe-promise-defer/tsconfig.json Switch TS emit to NodeNext ESM + bump target, remove jest types config.
safe-promise-defer/src/index.ts Switch to named imports/exports (no default export).
safe-promise-defer/package.json Mark package as ESM, add exports, switch workspace dependency.
safe-promise-defer/tests/index.ts Update test import to named export (aliased for test naming).
safe-execa/src/index.ts Replace default export with named export safeExeca.
safe-execa/package.json Add exports field for the ESM entrypoint.
run-groups/package.json Add exports field and remove injected self-reference pattern.
root-link-target/test.js Update tests to ESM and named exports.
root-link-target/package.json Mark package as ESM, add exports, remove injected self-reference, switch workspace dep.
root-link-target/index.js Convert implementation to ESM and named exports; update internal deps to named exports.
root-link-target/index.d.ts Switch typings to named exports.
root-link-target/example.js Update example to ESM and named export.
rimraf/package.json Mark package as ESM and add exports.
rimraf/index.js Convert implementation to ESM and named exports (rimraf, rimrafSync).
rimraf/index.d.ts Switch typings to named exports.
rimraf/tests/index.js Update tests to ESM and named imports; update sync call site.
resolve-link-target/test.js Update tests to ESM and named exports; update symlink-dir import.
resolve-link-target/package.json Mark package as ESM and add exports.
resolve-link-target/index.js Convert implementation to ESM and named exports.
resolve-link-target/index.d.ts Switch typings to named exports.
render-help/tsconfig.json Switch TS emit to NodeNext ESM + bump target, remove jest types config.
render-help/src/index.ts Replace export = with named export renderHelp.
render-help/package.json Mark package as ESM and add exports.
render-help/example.js Update example to ESM and named export.
render-help/tests/index.ts Update tests to import named export directly.
rename-overwrite/test.js Update tests to ESM and named exports; update sync call sites.
rename-overwrite/package.json Mark package as ESM, add exports, remove injected self-reference pattern.
rename-overwrite/index.js Convert implementation to ESM and named exports; update rimraf usage to named exports.
rename-overwrite/index.d.ts Switch typings to named exports.
realpath-missing/test.js Update tests to ESM and named export.
realpath-missing/package.json Mark package as ESM and add exports.
realpath-missing/index.js Convert implementation to ESM and named export.
realpath-missing/index.d.ts Switch typings to named export.
read-yaml-file/test.js Update tests to ESM and named exports; update sync API usage.
read-yaml-file/package.json Mark package as ESM, add exports, remove injected self-reference.
read-yaml-file/index.js Convert implementation to ESM and named exports (async + sync).
read-yaml-file/index.d.ts Switch typings from default+sync to named exports.
read-json5-file/test/index.js Update tests to ESM, compute __dirname, use named exports.
read-json5-file/package.json Mark package as ESM and add exports.
read-json5-file/index.js Convert implementation to ESM and named exports (async + sync).
read-json5-file/index.d.ts Switch typings to named exports.
read-json5-file/example/index.js Update example to ESM and named export.
read-ini-file/test/index.js Update tests to ESM, compute __dirname, use named exports.
read-ini-file/package.json Mark package as ESM, add exports, remove injected self-reference.
read-ini-file/index.js Convert implementation to ESM and named exports (async + sync).
read-ini-file/index.d.ts Switch typings to named exports.
read-ini-file/example/index.js Update example to ESM and named export.
promise-share/test.js Update tests to ESM and named export.
promise-share/package.json Mark package as ESM.
promise-share/index.js Convert implementation to ESM and named export.
promise-share/index.d.ts Switch typings to named export.
preferred-pm/test/index.js Update tests to ESM, compute __dirname, use named export.
preferred-pm/package.json Mark package as ESM, add exports, remove injected self-reference.
preferred-pm/index.js Convert implementation to ESM and named export; update which-pm import.
preferred-pm/index.d.ts Switch typings to named export.
pnpm-workspace.yaml Broaden workspace exclusion for node_modules_link directories.
pnpm-lock.yaml Update lockfile for workspace protocol deps and dependency graph changes.
path-temp/test.js Update tests to ESM and named exports; use threadId import.
path-temp/package.json Mark package as ESM, add exports, remove injected self-reference.
path-temp/index.js Convert implementation to ESM and named exports; update worker_threads import.
path-temp/index.d.ts Switch typings to named exports.
path-absolute/package.json Mark package as ESM and add exports.
path-absolute/index.js Convert implementation to ESM and named export.
path-absolute/index.d.ts Switch typings to named export.
p-map-values/tsconfig.json Switch TS emit to NodeNext ESM + bump target, remove jest types config.
p-map-values/src/index.ts Replace default export with named export pMapValues.
p-map-values/package.json Mark package as ESM and add exports.
p-map-values/tests/index.ts Update tests to import named export.
make-empty-dir/test.js Update tests to ESM and named exports; update sync API usage.
make-empty-dir/package.json Mark package as ESM and add exports.
make-empty-dir/index.js Convert implementation to ESM and named exports; update rimraf usage to named exports.
make-empty-dir/index.d.ts Switch typings to named exports.
is-subdir/test.js Update tests to ESM and named exports; adjust is-windows import usage.
is-subdir/package.json Mark package as ESM, add exports, switch workspace dep.
is-subdir/index.js Convert implementation to ESM and split strict into named export.
is-subdir/index.d.ts Switch typings to named exports (including strict).
is-subdir/example.js Update example to ESM and named export.
is-inner-link/test.js Update tests to ESM and named export; update symlink-dir import.
is-inner-link/package.json Mark package as ESM, add exports, remove injected self-reference, switch workspace deps.
is-inner-link/index.js Convert implementation to ESM and named export; update internal deps to named exports.
graceful-git/test.js Update tests to ESM and named exports.
graceful-git/package.json Mark package as ESM, add exports, remove injected self-reference, switch workspace dep.
graceful-git/index.js Convert implementation to ESM and named exports; update safe-execa usage.
graceful-git/example.js Update example to ESM and named export.
dir-is-case-sensitive/tsconfig.json Switch TS emit to NodeNext ESM + bump target.
dir-is-case-sensitive/test/index.ts Update test to import named export directly.
dir-is-case-sensitive/src/index.ts Update path-temp import and export dirIsCaseSensitive as named export.
dir-is-case-sensitive/package.json Mark package as ESM, add exports, remove injected self-reference, switch workspace dep.
comver-to-semver/test.js Update tests to ESM and named export.
comver-to-semver/package.json Mark package as ESM and add exports.
comver-to-semver/index.js Convert implementation to ESM and named export.
comver-to-semver/index.d.ts Switch typings to named export.
cmd-extension/package.json Mark package as ESM and add exports.
cmd-extension/index.js Convert implementation to ESM and named export constant.
cmd-extension/index.d.ts Switch typings to named export constant.
can-write-to-dir/test.js Update tests to ESM and named exports; update sync API usage.
can-write-to-dir/package.json Mark package as ESM, add exports, remove injected self-reference, switch workspace dep.
can-write-to-dir/index.js Convert implementation to ESM and named exports; update path-temp import.
can-write-to-dir/index.d.ts Switch typings to named exports.
can-link/test.js Update tests to ESM and named exports; update sync API usage.
can-link/package.json Mark package as ESM, add exports, remove injected self-reference.
can-link/index.js Convert implementation to ESM and named exports.
can-link/index.d.ts Switch typings to named exports.
better-path-resolve/test.js Update tests to ESM and named export usage.
better-path-resolve/package.json Mark package as ESM and add exports.
better-path-resolve/index.js Convert implementation to ESM and named export constant.
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@zkochan zkochan merged commit 84c04ad into main Mar 11, 2026
22 checks passed
@zkochan zkochan deleted the esm-conversion branch March 11, 2026 02:17
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.

2 participants