简体   繁体   中英

Moving from lerna to pnpm

I am currently migrating our project from Lerna to PNPM and we have a script we run I have posted it below

"postinstall": "npm run bootstrap"
"bootstrap": "lerna bootstrap --hoist",
"clean": "lerna clean -y",

is there a PNPM equivalent of Lerna bootstrap command and Lerna clean command?

You don't need any Lerna bootstrap equivalent, to get started with pnpm workspace is easy enough, you just need to add a pnpm-workspace.yaml file in your project root and add the location of your packages (which is typically packages/ . As mentioned on pnpm documentation :

A workspace must have a pnpm-workspace.yaml file in its root. A workspace also may have an .npmrc in its root.

Hoisting is not recommended with pnpm and is disabled by default, but if you really want to hoist then you can use add shamefully-hoist in .npmrc , see pnpm doc - shamefully-hoist

By default, pnpm creates a semistrict node_modules , meaning dependencies have access to undeclared dependencies but modules outside of node_modules do not. With this layout, most of the packages in the ecosystem work with no issues. However, if some tooling only works when the hoisted dependencies are in the root of node_modules , you can set this to true to hoist them for you.

I'm not sure about lerna clean equivalent but to remove a dependency from node module, you can use pnpm remove --recursive as per pnpm doc - remove

When used inside a workspace (with --recursive ), removes a dependency (or dependencies) from every workspace package.

When used not inside a workspace, removes a dependency (or dependencies) from every package found in subdirectories.

You can see an example of in Lerna-Lite pnpm-workspace.yaml and I would suggest you to take a look at Lerna-Lite and maybe not give up Lerna entirely, I created Lerna-Lite fork when Lerna was no longer maintained (it is now) and the big difference is that Lerna-Lite only has a subset of the original Lerna command (all the Lerna commands you mentioned aren't in Lerna-Lite because all package managers now handle these better than Lerna can), the other distinction is that it's much smaller since I also moved a few commands as optional packages and only kept version and publish in the core CLI, so it's much smaller if that is all you need. I also don't like of the changes and the direction that Lerna is now heading (it's becoming another Nx product, because Lerna v6 requires Nx behind the scene, and that is not the case with Lerna-Lite, Nx can be installed with Lerna-Lite but it's optional and that's the way it will always be).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM