Skip to content

refactor(create): consolidate @lerna/create into the main lerna package#4300

Merged
JamesHenry merged 3 commits intolerna:mainfrom
AI-JamesHenry-Org:get-rid-of-the-need-for-@lerna/create-to-exist-as-a-separate-package-and-make-it
Mar 11, 2026
Merged

refactor(create): consolidate @lerna/create into the main lerna package#4300
JamesHenry merged 3 commits intolerna:mainfrom
AI-JamesHenry-Org:get-rid-of-the-need-for-@lerna/create-to-exist-as-a-separate-package-and-make-it

Conversation

@AI-JamesHenry
Copy link
Copy Markdown
Collaborator

Note

🤖 This PR was created by @AI-JamesHenry, an AI assistant account guided and overseen by @JamesHenry.

Summary

  • Bundle the create command into the main lerna package like every other command, eliminating the need for @lerna/create to exist as a separate published package
  • Solve the LERNA_MODULE_DATA bundling issue by configuring esbuild to copy lerna-module-data.js as an asset into the dist output, so init-package-json can still resolve it at runtime
  • Move unit tests and fixtures from the legacy-structure package into libs/commands/create/ where they belong
  • Remove packages/legacy-structure/ entirely — the only remaining contents were orphaned mock files unused by any test

What changed

The create command was the only command not bundled into the main lerna package. This was due to its use of require.resolve() with __dirname to locate lerna-module-data.js at runtime (consumed by init-package-json). When esbuild bundles the code, __dirname points to the output directory — so the file needs to exist there too.

The fix: configure esbuild to copy lerna-module-data.js as an asset to dist/commands/create/lib/, matching where the bundled code expects it. The create command is now imported via TypeScript and bundled like every other command.

Files changed

  • packages/lerna/src/index.tsimport instead of require("@lerna/create/command")
  • packages/lerna/project.json — asset copy config, entry points, removed external
  • packages/lerna/package.json — removed @lerna/create dependency
  • tsconfig.base.json — removed @lerna/create path mapping
  • libs/commands/create/ — added jest config, test target, moved tests + fixtures here
  • packages/legacy-structure/ — deleted entirely
  • package.json — removed dead workspace entry
  • .github/workflows/pkg-pr-new.yml — removed legacy-structure publish path

Test plan

  • nx run-many -t build passes
  • nx run-many -t test passes (19 projects, including create command tests)
  • nx run-many -t lint passes (34 projects)
  • npm run format:check passes
  • nx e2e e2e-create passes (60 tests)
  • nx sync — workspace up to date

The create command was the only command not bundled into the main lerna
package due to its use of require.resolve() with __dirname to locate
lerna-module-data.js at runtime (consumed by init-package-json).

This is solved by configuring esbuild to copy lerna-module-data.js as
an asset into dist/commands/create/lib/, matching the path the bundled
code expects. The create command is now imported and bundled like every
other command.

- Bundle create command via TypeScript import instead of external require
- Copy lerna-module-data.js as esbuild asset for runtime resolution
- Move unit tests and fixtures from legacy-structure into libs/commands/create
- Remove packages/legacy-structure/commands/create entirely
- Remove @lerna/create dependency, path mapping, and esbuild external
The legacy-structure directory only contained orphaned mock files that
are unused — all tests use the equivalent mocks from libs/test-helpers.
Also clean up stale references in workspaces, CI workflow, gitignore,
and release scripts.
@nx-cloud
Copy link
Copy Markdown

nx-cloud bot commented Mar 10, 2026

View your CI Pipeline Execution ↗ for commit 22d17ef

Command Status Duration Result
nx run-many --t e2e --parallel=1 ✅ Succeeded 11m 36s View ↗
nx run-many -t test --parallel=3 --ci --maxWork... ✅ Succeeded 24s View ↗
nx run-many -t build --parallel=3 ✅ Succeeded 18s View ↗
nx run-many -t lint --parallel=3 ✅ Succeeded 19s View ↗
nx run integration:integration --ci --maxWorkers=2 ✅ Succeeded 14s View ↗
nx-cloud record -- npx nx format:check ✅ Succeeded 3s View ↗
nx run-many -t build ✅ Succeeded <1s View ↗
nx run-many -t test --parallel=3 --ci --maxWork... ✅ Succeeded 25s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-10 18:16:17 UTC

When bundled into the main dist/index.js, __dirname is dist/ so the
asset needs to be at dist/lib/lerna-module-data.js. When loaded via
the separate entry point at dist/commands/create/index.js, __dirname
is dist/commands/create/ so it also needs to be there. Copy to both
locations to handle either entry path.
Copy link
Copy Markdown

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

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

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We added the missing output: "lib" asset copy entry to packages/lerna/project.json to fix all failing E2E tests. When esbuild bundles the create command into dist/index.js, __dirname resolves to dist/, causing require.resolve(path.join(__dirname, "./lib/lerna-module-data.js")) to look for dist/lib/lerna-module-data.js — a path that only existed in the PR's intent but was absent from the final merged file. This restores the file to both expected locations so the create command works whether invoked via the main CLI bundle or its own entry point.

Warning

The suggested diff is too large to display here, but you can view it on Nx Cloud ↗


Because this branch comes from a fork, it is not possible for us to apply fixes directly, but you can apply the changes locally using the available options below.

Apply changes locally with:

npx nx-cloud apply-locally ZV5F-jNUq

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

Copy link
Copy Markdown
Member

@JamesHenry JamesHenry left a comment

Choose a reason for hiding this comment

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

@pkg-pr-new publish

@JamesHenry JamesHenry marked this pull request as ready for review March 11, 2026 10:11
@JamesHenry JamesHenry merged commit c15070b into lerna:main Mar 11, 2026
18 checks passed
@JamesHenry JamesHenry deleted the get-rid-of-the-need-for-@lerna/create-to-exist-as-a-separate-package-and-make-it branch March 11, 2026 10:11
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