Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 250 Vote(s) - 3.36 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is Lerna needed anymore with NPM workspaces?

#1
Is Lerna needed anymore with NPM 7.0.0 workspaces?

I don't really have experience with this new npm feature.

[npm/RFCs][1] writes:

> First and foremost there’s the alternative of leaving the problem set
> for userland to solve, there’s already the very popular project Lerna
> that provides some of these features.
>
> Also available is the alternative of supporting only the install (or
> bootstrap as Lerna names it) aspect of this proposal, following a less
> feature-rich approach but one that would still enable the basic goal
> of improving the user experience of managing multiple child packages
> but from all the feedback collected during the research phase of this
> RFC, this alternative is much less desirable to the community of
> maintainers involved.


[1]:

[To see links please register here]


Glad for every answer and explanation :)
Reply

#2
The answer is yes, you still need Lerna or other tool to complement the features that came with npm@7 workspaces. These are the things that are not handled by npm@7 workspaces (as of writing of this answer):

**Understanding the monorepo topology**

npm workspaces are aware of monorepo package topology to certain level. Workspaces for example know that package-c uses package-a and package-b as its dependencies. But there is a small thing to keep in mind:

$ npm run build --workspaces

This command will run `npm run build` for all the monorepo packages.

Let’s say that package-a depends on package-b and package-c depends both on package-a and package-b. The order of execution you get from running the command is depends on your `workspaces` array in `package.json`. So if you have this:

```json
{
"workspaces": ["package-a", "package-b", "package-c"]
}
```

then the build order will be:

- package-a
- package-b
- package-c

but the correct order should be:

- package-b
- package-a
- package-c

For things to build in the correct order, you should ensure you list them in the correct order in package.json:


```json
{
"workspaces": ["package-b", "package-a", "package-c"]
}
```

**Change management**

Lerna can detect changes in monorepo and provide you with a list of packages that have changed. This is handy if you only want to run tests for changed packages. npm@7 workspaces can do no such thing yet (Oct 5th, 2021).

**Publishing**

Lerna can manage versioning and publishing of your packages. Comes with two different strategies of managing versions: fixed and independent. It generates changelog, and publishes only changed packages to npm.

There is much more to it for sure, but these are the main things that you still need on top of npm@7 workspaces. If you use Lerna or other tools, that's up to you.

I've documented all the [things I have learned while maintaining JavaScript monorepo with Lerna][1] in an article. It describes how monorepo management processes simplified significantly after npm@7 introduction, but why we still need to use Lerna or other tools on top of it.


[1]:

[To see links please register here]

Reply

#3
From a management perspective yes. Since it can handle things like change reports.

However, if you simply want to have a monorepos and you know the dependency build order rather than relying on `packages/*` there's no need for it. For the most part you can simply use the following sequence to do your builds and do away with lerna and dependencies until you really need it.

```
yarn install --frozen-lockfile
yarn workspaces run prepare
yarn workspaces run test
```

Reply

#4
[NPM has supported workspaces since version 7](

[To see links please register here]

), for two major releases now.

With workspaces, `npm i` / `npm ci` takes care of nested packages and symlinking. `npm run` and `npm exec` can be run across individual or all workspaces:

```
npm run test --workspace=a --workspace="name-from-package-dot-json"
```

```
npm run test --workspaces --if-present
```

With that said, `lerna` comes with many more high level features than `npm` or `yarn` workspaces.

One great example is the command: `lerna changed` which gives you the list of packages that have changed since the last tagged release, this could be extremely helpful for CI/CD. you are welcome to explore the extra commands provided by [lerna][2].

I've written an article that goes deeper into the configuration in case you want to [move to a monorepo][3] with npm7, so working without lerna is definitely an option, you will probably need to do more work on the CI/CD side compared to lerna and add some dev scripts by your self that will affect the nested packages. Also IMO lerna fits more to develop libs rather than apps.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

[3]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through