index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. "use strict";
  2. const { Command } = require("@lerna/command");
  3. const { collectUpdates } = require("@lerna/collect-updates");
  4. const listable = require("@lerna/listable");
  5. const { output } = require("@lerna/output");
  6. module.exports = factory;
  7. function factory(argv) {
  8. return new ChangedCommand(argv);
  9. }
  10. class ChangedCommand extends Command {
  11. get otherCommandConfigs() {
  12. // back-compat
  13. return ["version", "publish"];
  14. }
  15. initialize() {
  16. if (this.options.conventionalGraduate) {
  17. // provide artificial --conventional-commits so --conventional-graduate works
  18. this.options.conventionalCommits = true;
  19. if (this.options.forcePublish) {
  20. this.logger.warn("option", "--force-publish superseded by --conventional-graduate");
  21. }
  22. }
  23. const updates = collectUpdates(
  24. this.packageGraph.rawPackageList,
  25. this.packageGraph,
  26. this.execOpts,
  27. this.options
  28. );
  29. this.result = listable.format(
  30. updates.map((node) => node.pkg),
  31. this.options
  32. );
  33. if (this.result.count === 0) {
  34. this.logger.info("", "No changed packages found");
  35. process.exitCode = 1;
  36. // prevents execute()
  37. return false;
  38. }
  39. }
  40. execute() {
  41. output(this.result.text);
  42. this.logger.success(
  43. "found",
  44. "%d %s ready to publish",
  45. this.result.count,
  46. this.result.count === 1 ? "package" : "packages"
  47. );
  48. }
  49. }
  50. module.exports.ChangedCommand = ChangedCommand;