-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Allow for 3rd party commands #1584
Comments
Thanks for opening this issue, it's something I've thought about too. I'm personally leaning more toward the So third-party Here's the steps I envisioned, roughly:
This "dashed-prefix" approach has admittedly more potential for namespace clobbering, but in practice I think it would be a lot easier to contribute to? It would remove the necessity for custom metadata per-package, and could even support global installations of custom commands. This approach would require extracting a "setup all the global lerna cli stuff except for adding commands" package, but that's something that should probably already exist anyway, given my previously-expressed goal of helpful modularity. A sketch of a third-party command executable: 'use strict';
const lernaCli = require('@lerna/cli');
const myCmd = require('../lib/my-cmd');
// myCmd is a yargs command module
// lernaCli() returns a yargs instance,
// which is then chained as desired...
const cli = lernaCli().command(myCmd);
// call parse() to execute after configuration
cli.parse(process.argv.slice(2)); |
…package This moves a step closer to the ideal of enabling third-party commands in the git manner. Refs #1584
Yargs actually support git-style sub-commands. The reason I tend to favor loading the commands (instead of spawning sub-processes) is the fact that you can flow context much better, because you can pass down stuff like the |
If you're extending the base Command class, you already get As a contributor to yargs, it's news to me that it supports git-style subcommands out of the box. In any case, there's a neat trick I learned from |
I'm on mobile and completely forgot the "as far as I know" part of that statement. I'm pretty sure I read it in the docs, but I might remember wrong, so sorry about that. I'll try to look it up tomorrow. |
Has anyone successfully contributed third-party commands to lerna? If so, has that been through a process of contributing a command to the lerna cli like |
Hi Folks 👋 This issue doesn't seem to have gained much traction. In order to allow our small team to focus on what matters most to Lerna v6 users in late 2022, I'm going to close this one. We do not currently have plans to support custom commands in If you have any other requests that could enhance your usage of Lerna 6, then please do let us know by opening a new discussion (for a feature) or issue (for a bug report) with as much context as possible. You can also check out our published roadmap for Lerna v7 here: #3410 Many thanks 🙏 |
With lerna's new structure, the different subcommands to the CLI is implemented as separate packages, all using a shared
Command
base class, which is available through it's own package. This lends itself very well to allowing third-party subcommands. The exact resolution strategy for finding these commands would need to be specced out, but I suggest something like the following:dependencies
anddevDependencies
), and find theirpackage.json
.lerna.command
key inpackage.json
(nested, so it would be{"lerna": {"command":"...."}}
)..command(require(path.resolve(path.dirname(pkgJsonPath, pkg.lerna.command))))
. (though, probalby to some check wrt names, to avoid clashes, and other validation).Things to note:
All in all, I think a basic implementation of this feature can be done fairly easily. If this is something that's wanted/would be accepted, I'm willing to work on this feature.
The text was updated successfully, but these errors were encountered: