[Suggestion] Improve 'lerna add' for TypeScript users
Expected Behavior
TypeScript added support for composite projects and project references several releases ago. In an effort to improve tooling support for TypeScript projects, I would suggest an addition to the lerna add command to recognize tsconfig.json files in lerna-managed packages such that when adding one lerna-managed package as a dependency of another lerna-managed package that lerna could detect whether the dependent project is "composite" and, if so, add a reference to the depending project.
Alternatively, I would suggest an extensibility mechanism for lerna such that a third-party plugin could be loaded that could be triggered during lerna add to provide this functionality.
My first reaction was "this sounds like a Typescript tool's responsibility, not Lerna." Or, perhaps, a package manager's. I don't think we should bake TS-specific logic directly into lerna add.
That being said, I do want to make life easier for TS folks who use project references (who knows, it could be me soon! 😅). There's a ...lot... of issues strewn about this repo that noodle about what a Lerna "plugin" API would look like. I can't say any of them have really struck me, and obviously none of them have been implemented.
The most "consonant with npm patterns" approach, as I see it, is a special npm scripts lifecycle ("lerna-${command}"?) that would be invoked either in the root manifest or leaf manifest (or both?) when the opportunity arises to do something (following the "pre${script}"/"${script}"/"post${script}" naming/calling convention, as well). There would be certain environment variables available, such as the package name, directory path, etc (just like normal npm scripts, such as version).
How does that sound?
Being able to run scripts in response to lerna commands (be that before or after) would be a welcome addition, and might satisfy the use case at least somewhat.
The idea of having lerna lifecycle scripts would be great! I would vote for both in root and leaf manifests...
Hi Folks 👋
Please take a look at our published roadmap for Lerna v7 here: https://github.com/lerna/lerna/discussions/3410
One of the key items covered at length on there (please do read it for full context) is that now that we find ourselves in late 2022, it no longer makes sense for lerna to supplement package management concerns (such as installation, boostrapping, linking etc) which are covered reliably for monorepo workspaces by the three main package managers: npm, yarn and pnpm. lerna bootstrap et al were developed in completely different era of the JavaScript ecosystem.
If you have any specific concerns please do join in on that discussion, and provide as much context as possible.
Many thanks 🙏