Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(init): default useNx and useWorkspaces to true for new lerna workspaces #3255

Merged

Conversation

fahslaj
Copy link
Contributor

@fahslaj fahslaj commented Jul 22, 2022

When initializing lerna for the first time with lerna init, workspaces and nx will both be enabled by default.

Description

For lerna init:

  • default useNx to true
  • default useWorkspaces to true
  • automatically add nx as a dev dependency if useNx will be true
  • automatically add workspaces property to package.json if useWorkspaces will be true
  • explicitly set useNx to false if lerna.json already exists and useNx is not set
  • explicitly set useWorkspaces to false if lerna.json already exists and useWorkspaces is not set
  • fix a bug where useNx was being reset to false whenever lerna init was run on an existing workspace with useNx: true
  • refactor ensurePackageJson() and ensureLernaConfig() into one ensureConfig() function to reduce surface area for bugs in configuration that spans both config files (such as workspaces)
  • add an informational message upon successful initialization that links the user to the lerna docs

For all commands:

  • add a warning to the console when a command is run and lerna does not have either:
    • useWorkspaces: true in lerna.json AND a workspaces property set in package.json
    • packages property set in lerna.json
  • add a warning to the console when workspaces are defined in package.json, but lerna.json does not have useWorkspaces: true

For the docs:

  • updated the getting started guide to no longer describe needing to install nx manually on a newly created lerna project

For lerna --help

  • update the link to point to the new docs

Motivation and Context

This change enables two of lerna's most powerful features by default - the ability to run commands with nx and the ability to make use of Yarn/npm workspaces by default for detecting packages.

How Has This Been Tested?

Extensive unit, integration, and e2e tests have been added. I have also manually tested the lerna init command for each of these scenarios.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (change that has absolutely no effect on users)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

commands/init/index.js Outdated Show resolved Hide resolved
@fahslaj fahslaj marked this pull request as ready for review July 22, 2022 14:50
@fahslaj fahslaj force-pushed the lerna-init-default-useNx-useWorkspaces-true branch from e5cee67 to 334cf6a Compare July 22, 2022 14:50
@fahslaj fahslaj force-pushed the lerna-init-default-useNx-useWorkspaces-true branch from 334cf6a to 97d36a1 Compare July 22, 2022 15:14
@JamesHenry JamesHenry changed the title feat: Lerna init default useNx and useWorkspaces to true feat(init): default useNx and useWorkspaces to true for new lerna workspaces Jul 22, 2022
Copy link
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.

Per slack discussion

@fahslaj fahslaj requested a review from JamesHenry July 22, 2022 16:47
@JamesHenry JamesHenry merged commit a0e83e5 into lerna:main Jul 22, 2022
@AviVahl
Copy link
Contributor

AviVahl commented Jul 23, 2022

This installs nx and its many dependencies (some of which are requesting exact versions) to any project using lerna, even if they don't use nx. 👎

Even stuff that I wouldn't expect like tsconfig-paths and @parcel/watcher are now being installed.

@fahslaj fahslaj deleted the lerna-init-default-useNx-useWorkspaces-true branch July 25, 2022 14:36
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.

None yet

3 participants