command.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. "use strict";
  2. const log = require("npmlog");
  3. const versionCommand = require("@lerna/version/command");
  4. /**
  5. * @see https://github.com/yargs/yargs/blob/master/docs/advanced.md#providing-a-command-module
  6. */
  7. exports.command = "publish [bump]";
  8. exports.describe = "Publish packages in the current project.";
  9. exports.builder = (yargs) => {
  10. const opts = {
  11. c: {
  12. describe: "Publish packages after every successful merge using the sha as part of the tag.",
  13. alias: "canary",
  14. type: "boolean",
  15. },
  16. // preid is copied from ../version/command because a whitelist for one option isn't worth it
  17. preid: {
  18. describe: "Specify the prerelease identifier when publishing a prerelease",
  19. type: "string",
  20. requiresArg: true,
  21. defaultDescription: "alpha",
  22. },
  23. contents: {
  24. describe: "Subdirectory to publish. Must apply to ALL packages.",
  25. type: "string",
  26. requiresArg: true,
  27. defaultDescription: ".",
  28. },
  29. "dist-tag": {
  30. describe: "Publish packages with the specified npm dist-tag",
  31. type: "string",
  32. requiresArg: true,
  33. },
  34. "legacy-auth": {
  35. describe: "Legacy Base64 Encoded username and password.",
  36. type: "string",
  37. },
  38. "pre-dist-tag": {
  39. describe: "Publish prerelease packages with the specified npm dist-tag",
  40. type: "string",
  41. requiresArg: true,
  42. },
  43. "git-head": {
  44. describe:
  45. "Explicit SHA to set as gitHead when packing tarballs, only allowed with 'from-package' positional.",
  46. type: "string",
  47. requiresArg: true,
  48. },
  49. "graph-type": {
  50. describe: "Type of dependency to use when determining package hierarchy.",
  51. choices: ["all", "dependencies"],
  52. defaultDescription: "dependencies",
  53. },
  54. "ignore-prepublish": {
  55. describe: "Disable deprecated 'prepublish' lifecycle script",
  56. type: "boolean",
  57. },
  58. "ignore-scripts": {
  59. describe: "Disable all lifecycle scripts",
  60. type: "boolean",
  61. },
  62. // TODO: (major) make --no-granular-pathspec the default
  63. "no-granular-pathspec": {
  64. describe: "Do not reset changes file-by-file, but globally.",
  65. type: "boolean",
  66. },
  67. "granular-pathspec": {
  68. // proxy for --no-granular-pathspec
  69. hidden: true,
  70. // describe: "Reset changes file-by-file, not globally.",
  71. type: "boolean",
  72. },
  73. otp: {
  74. describe: "Supply a one-time password for publishing with two-factor authentication.",
  75. type: "string",
  76. requiresArg: true,
  77. },
  78. registry: {
  79. describe: "Use the specified registry for all npm client operations.",
  80. type: "string",
  81. requiresArg: true,
  82. },
  83. "require-scripts": {
  84. describe: "Execute ./scripts/prepublish.js and ./scripts/postpublish.js, relative to package root.",
  85. type: "boolean",
  86. },
  87. "no-git-reset": {
  88. describe: "Do not reset changes to working tree after publishing is complete.",
  89. type: "boolean",
  90. },
  91. "git-reset": {
  92. // proxy for --no-git-reset
  93. hidden: true,
  94. type: "boolean",
  95. },
  96. "temp-tag": {
  97. describe: "Create a temporary tag while publishing.",
  98. type: "boolean",
  99. },
  100. "no-verify-access": {
  101. describe: "Do not verify package read-write access for current npm user.",
  102. type: "boolean",
  103. },
  104. "verify-access": {
  105. // proxy for --no-verify-access
  106. hidden: true,
  107. type: "boolean",
  108. },
  109. // y: {
  110. // describe: "Skip all confirmation prompts.",
  111. // alias: "yes",
  112. // type: "boolean",
  113. // },
  114. };
  115. composeVersionOptions(yargs);
  116. yargs.options(opts);
  117. // "unhide" duplicate options
  118. const { hiddenOptions } = yargs.getOptions();
  119. const sharedKeys = ["preid", "y", "ignore-scripts"];
  120. for (const sharedKey of sharedKeys) {
  121. hiddenOptions.splice(
  122. hiddenOptions.findIndex((k) => k === sharedKey),
  123. 1
  124. );
  125. }
  126. yargs.group(Object.keys(opts).concat(sharedKeys), "Command Options:");
  127. return yargs
  128. .option("npm-tag", {
  129. // TODO: remove in next major release
  130. hidden: true,
  131. conflicts: "dist-tag",
  132. type: "string",
  133. requiresArg: true,
  134. })
  135. .option("verify-registry", {
  136. // TODO: remove in next major release
  137. hidden: true,
  138. type: "boolean",
  139. })
  140. .option("skip-npm", {
  141. // TODO: remove in next major release
  142. // deprecation notice handled in initialize()
  143. hidden: true,
  144. type: "boolean",
  145. })
  146. .check((argv) => {
  147. /* eslint-disable no-param-reassign */
  148. if (argv.npmTag) {
  149. argv.distTag = argv.npmTag;
  150. argv["dist-tag"] = argv.npmTag;
  151. delete argv.npmTag;
  152. delete argv["npm-tag"];
  153. log.warn("deprecated", "--npm-tag has been renamed --dist-tag");
  154. }
  155. /* eslint-enable no-param-reassign */
  156. return argv;
  157. });
  158. };
  159. exports.handler = function handler(argv) {
  160. return require(".")(argv);
  161. };
  162. function composeVersionOptions(yargs) {
  163. versionCommand.addBumpPositional(yargs, ["from-git", "from-package"]);
  164. versionCommand.builder(yargs, "publish");
  165. return yargs;
  166. }