index.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. const { Command } = require("@lerna/command");
  3. const listable = require("@lerna/listable");
  4. const { output } = require("@lerna/output");
  5. const { getFilteredPackages } = require("@lerna/filter-options");
  6. module.exports = factory;
  7. function factory(argv) {
  8. return new ListCommand(argv);
  9. }
  10. class ListCommand extends Command {
  11. get requiresGit() {
  12. return false;
  13. }
  14. initialize() {
  15. let chain = Promise.resolve();
  16. chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
  17. chain = chain.then((filteredPackages) => {
  18. this.result = listable.format(filteredPackages, this.options);
  19. });
  20. return chain;
  21. }
  22. execute() {
  23. // piping to `wc -l` should not yield 1 when no packages matched
  24. if (this.result.text.length) {
  25. output(this.result.text);
  26. }
  27. this.logger.success(
  28. "found",
  29. "%d %s",
  30. this.result.count,
  31. this.result.count === 1 ? "package" : "packages"
  32. );
  33. }
  34. }
  35. module.exports.ListCommand = ListCommand;