release-please 12.5.0 → 13.0.0-candidate.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (253) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +4 -0
  3. package/build/src/bin/release-please.d.ts +55 -11
  4. package/build/src/bin/release-please.js +419 -152
  5. package/build/src/bootstrapper.d.ts +12 -0
  6. package/build/src/bootstrapper.js +60 -0
  7. package/build/src/changelog-notes/default.d.ts +17 -0
  8. package/build/src/changelog-notes/default.js +72 -0
  9. package/build/src/changelog-notes.d.ts +17 -0
  10. package/build/src/{updaters/java/readme.js → changelog-notes.js} +2 -7
  11. package/build/src/commit.d.ts +26 -0
  12. package/build/src/{util/to-conventional-changelog-format.js → commit.js} +97 -2
  13. package/build/src/errors/index.d.ts +0 -5
  14. package/build/src/errors/index.js +1 -10
  15. package/build/src/factory.d.ts +25 -37
  16. package/build/src/factory.js +160 -150
  17. package/build/src/github.d.ts +154 -884
  18. package/build/src/github.js +608 -1036
  19. package/build/src/manifest.d.ts +191 -47
  20. package/build/src/manifest.js +599 -487
  21. package/build/src/plugin.d.ts +20 -0
  22. package/build/src/{plugins/plugin.js → plugin.js} +10 -9
  23. package/build/src/plugins/cargo-workspace.d.ts +48 -18
  24. package/build/src/plugins/cargo-workspace.js +247 -328
  25. package/build/src/plugins/merge.d.ts +11 -0
  26. package/build/src/plugins/merge.js +83 -0
  27. package/build/src/plugins/node-workspace.d.ts +35 -17
  28. package/build/src/plugins/node-workspace.js +234 -271
  29. package/build/src/plugins/workspace.d.ts +102 -0
  30. package/build/src/plugins/workspace.js +170 -0
  31. package/build/src/pull-request.d.ts +10 -0
  32. package/build/src/{updaters/java/pom-xml.js → pull-request.js} +2 -7
  33. package/build/src/release-notes.d.ts +29 -0
  34. package/build/src/release-notes.js +71 -0
  35. package/build/src/release-pull-request.d.ts +13 -0
  36. package/build/src/release-pull-request.js +16 -0
  37. package/build/src/release.d.ts +6 -0
  38. package/build/src/release.js +16 -0
  39. package/build/src/repository.d.ts +5 -0
  40. package/build/src/repository.js +16 -0
  41. package/build/src/strategies/dart.d.ts +8 -0
  42. package/build/src/strategies/dart.js +63 -0
  43. package/build/src/strategies/elixir.d.ts +5 -0
  44. package/build/src/{releasers → strategies}/elixir.js +18 -14
  45. package/build/src/strategies/go-yoshi.d.ts +13 -0
  46. package/build/src/strategies/go-yoshi.js +106 -0
  47. package/build/src/strategies/go.d.ts +5 -0
  48. package/build/src/{releasers → strategies}/go.js +11 -12
  49. package/build/src/strategies/helm.d.ts +8 -0
  50. package/build/src/strategies/helm.js +63 -0
  51. package/build/src/strategies/java-yoshi.d.ts +24 -0
  52. package/build/src/strategies/java-yoshi.js +203 -0
  53. package/build/src/strategies/krm-blueprint.d.ts +7 -0
  54. package/build/src/{releasers → strategies}/krm-blueprint.js +26 -22
  55. package/build/src/strategies/node.d.ts +9 -0
  56. package/build/src/strategies/node.js +82 -0
  57. package/build/src/strategies/ocaml.d.ts +5 -0
  58. package/build/src/{releasers → strategies}/ocaml.js +34 -28
  59. package/build/src/strategies/php-yoshi.d.ts +10 -0
  60. package/build/src/strategies/php-yoshi.js +213 -0
  61. package/build/src/strategies/php.d.ts +6 -0
  62. package/build/src/{releasers → strategies}/php.js +24 -23
  63. package/build/src/strategies/python.d.ts +8 -0
  64. package/build/src/strategies/python.js +117 -0
  65. package/build/src/strategies/ruby-yoshi.d.ts +17 -0
  66. package/build/src/strategies/ruby-yoshi.js +116 -0
  67. package/build/src/strategies/ruby.d.ts +13 -0
  68. package/build/src/{releasers → strategies}/ruby.js +26 -27
  69. package/build/src/strategies/rust.d.ts +20 -0
  70. package/build/src/strategies/rust.js +120 -0
  71. package/build/src/strategies/simple.d.ts +5 -0
  72. package/build/src/{releasers → strategies}/simple.js +18 -14
  73. package/build/src/strategies/terraform-module.d.ts +7 -0
  74. package/build/src/{releasers → strategies}/terraform-module.js +29 -23
  75. package/build/src/strategy.d.ts +100 -0
  76. package/build/src/strategy.js +233 -0
  77. package/build/src/update.d.ts +23 -0
  78. package/build/src/{updaters/update.js → update.js} +1 -1
  79. package/build/src/updaters/changelog.d.ts +7 -10
  80. package/build/src/updaters/changelog.js +3 -9
  81. package/build/src/updaters/changelog.js.map +1 -1
  82. package/build/src/updaters/composite.d.ts +19 -0
  83. package/build/src/updaters/composite.js +42 -0
  84. package/build/src/updaters/dart/pubspec-yaml.d.ts +12 -0
  85. package/build/src/updaters/{pubspec-yaml.js → dart/pubspec-yaml.js} +13 -12
  86. package/build/src/updaters/default.d.ts +21 -0
  87. package/build/src/updaters/{version-txt.js → default.js} +16 -10
  88. package/build/src/updaters/dotnet/csproj.d.ts +12 -0
  89. package/build/src/updaters/{java/google-utils.js → dotnet/csproj.js} +16 -13
  90. package/build/src/updaters/elixir/elixir-mix-exs.d.ts +12 -0
  91. package/build/src/updaters/{elixir-mix-exs.js → elixir/elixir-mix-exs.js} +12 -10
  92. package/build/src/updaters/helm/chart-yaml.d.ts +10 -11
  93. package/build/src/updaters/helm/chart-yaml.js +12 -10
  94. package/build/src/updaters/java/java-update.d.ts +14 -0
  95. package/build/src/updaters/java/{java_update.js → java-update.js} +22 -22
  96. package/build/src/updaters/java/versions-manifest.d.ts +12 -2
  97. package/build/src/updaters/java/versions-manifest.js +20 -4
  98. package/build/src/updaters/krm/krm-blueprint-version.d.ts +10 -11
  99. package/build/src/updaters/krm/krm-blueprint-version.js +13 -12
  100. package/build/src/updaters/node/package-json.d.ts +12 -0
  101. package/build/src/updaters/{package-json.js → node/package-json.js} +14 -16
  102. package/build/src/updaters/node/package-lock-json.d.ts +8 -0
  103. package/build/src/updaters/node/package-lock-json.js +36 -0
  104. package/build/src/updaters/node/samples-package-json.d.ts +23 -0
  105. package/build/src/updaters/{samples-package-json.js → node/samples-package-json.js} +19 -8
  106. package/build/src/updaters/ocaml/dune-project.d.ts +10 -11
  107. package/build/src/updaters/ocaml/dune-project.js +11 -9
  108. package/build/src/updaters/ocaml/esy-json.d.ts +10 -11
  109. package/build/src/updaters/ocaml/esy-json.js +12 -10
  110. package/build/src/updaters/ocaml/opam.d.ts +10 -11
  111. package/build/src/updaters/ocaml/opam.js +11 -9
  112. package/build/src/updaters/php/php-client-version.d.ts +12 -0
  113. package/build/src/updaters/{php-client-version.js → php/php-client-version.js} +10 -9
  114. package/build/src/updaters/php/php-manifest.d.ts +13 -0
  115. package/build/src/updaters/{php-manifest.js → php/php-manifest.js} +17 -15
  116. package/build/src/updaters/php/root-composer-update-packages.d.ts +12 -0
  117. package/build/src/updaters/{root-composer-update-packages.js → php/root-composer-update-packages.js} +17 -16
  118. package/build/src/updaters/python/pyproject-toml.d.ts +10 -11
  119. package/build/src/updaters/python/pyproject-toml.js +13 -11
  120. package/build/src/updaters/python/python-file-with-version.d.ts +7 -11
  121. package/build/src/updaters/python/python-file-with-version.js +7 -8
  122. package/build/src/updaters/python/setup-cfg.d.ts +10 -11
  123. package/build/src/updaters/python/setup-cfg.js +10 -8
  124. package/build/src/updaters/python/setup-py.d.ts +10 -11
  125. package/build/src/updaters/python/setup-py.js +10 -8
  126. package/build/src/updaters/raw-content.d.ts +19 -0
  127. package/build/src/{plugins/index.js → updaters/raw-content.js} +23 -12
  128. package/build/src/updaters/release-please-config.d.ts +8 -0
  129. package/build/src/updaters/release-please-config.js +41 -0
  130. package/build/src/updaters/release-please-manifest.d.ts +2 -11
  131. package/build/src/updaters/release-please-manifest.js +11 -14
  132. package/build/src/updaters/ruby/version-rb.d.ts +12 -0
  133. package/build/src/updaters/{version-rb.js → ruby/version-rb.js} +10 -8
  134. package/build/src/updaters/rust/cargo-lock.d.ts +7 -11
  135. package/build/src/updaters/rust/cargo-lock.js +14 -16
  136. package/build/src/updaters/rust/cargo-toml.d.ts +7 -11
  137. package/build/src/updaters/rust/cargo-toml.js +19 -21
  138. package/build/src/updaters/terraform/module-version.d.ts +10 -11
  139. package/build/src/updaters/terraform/module-version.js +11 -9
  140. package/build/src/updaters/terraform/readme.d.ts +10 -11
  141. package/build/src/updaters/terraform/readme.js +11 -10
  142. package/build/src/updaters/terraform/readme.js.map +1 -1
  143. package/build/src/util/branch-name.d.ts +5 -4
  144. package/build/src/util/branch-name.js +13 -10
  145. package/build/src/{commit-split.d.ts → util/commit-split.d.ts} +2 -4
  146. package/build/src/{commit-split.js → util/commit-split.js} +4 -2
  147. package/build/src/util/indent-commit.d.ts +1 -1
  148. package/build/src/util/logger.d.ts +5 -2
  149. package/build/src/util/logger.js +9 -4
  150. package/build/src/util/pull-request-body.d.ts +20 -0
  151. package/build/src/util/pull-request-body.js +129 -0
  152. package/build/src/util/pull-request-title.d.ts +8 -6
  153. package/build/src/util/pull-request-title.js +20 -6
  154. package/build/src/util/tag-name.d.ts +9 -0
  155. package/build/src/util/tag-name.js +41 -0
  156. package/build/src/{updaters → util}/toml-edit.d.ts +0 -0
  157. package/build/src/{updaters → util}/toml-edit.js +0 -0
  158. package/build/src/version.d.ts +11 -0
  159. package/build/src/version.js +45 -0
  160. package/build/src/versioning-strategies/always-bump-patch.d.ts +7 -0
  161. package/build/src/{updaters/package-lock-json.js → versioning-strategies/always-bump-patch.js} +8 -11
  162. package/build/src/versioning-strategies/default.d.ts +15 -0
  163. package/build/src/versioning-strategies/default.js +67 -0
  164. package/build/src/versioning-strategies/dependency-manifest.d.ts +7 -0
  165. package/build/src/versioning-strategies/dependency-manifest.js +90 -0
  166. package/build/src/versioning-strategies/java-add-snapshot.d.ts +9 -0
  167. package/build/src/versioning-strategies/java-add-snapshot.js +53 -0
  168. package/build/src/versioning-strategies/java-snapshot.d.ts +9 -0
  169. package/build/src/versioning-strategies/java-snapshot.js +67 -0
  170. package/build/src/versioning-strategies/service-pack.d.ts +7 -0
  171. package/build/src/versioning-strategies/service-pack.js +40 -0
  172. package/build/src/versioning-strategy.d.ts +28 -0
  173. package/build/src/versioning-strategy.js +55 -0
  174. package/package.json +9 -8
  175. package/build/src/constants.d.ts +0 -6
  176. package/build/src/constants.js +0 -23
  177. package/build/src/conventional-commits.d.ts +0 -53
  178. package/build/src/conventional-commits.js +0 -167
  179. package/build/src/github-release.d.ts +0 -34
  180. package/build/src/github-release.js +0 -92
  181. package/build/src/graphql-to-commits.d.ts +0 -60
  182. package/build/src/graphql-to-commits.js +0 -112
  183. package/build/src/index.d.ts +0 -94
  184. package/build/src/index.js +0 -32
  185. package/build/src/plugins/index.d.ts +0 -5
  186. package/build/src/plugins/plugin.d.ts +0 -21
  187. package/build/src/release-pr.d.ts +0 -101
  188. package/build/src/release-pr.js +0 -461
  189. package/build/src/releasers/dart.d.ts +0 -9
  190. package/build/src/releasers/dart.js +0 -65
  191. package/build/src/releasers/elixir.d.ts +0 -5
  192. package/build/src/releasers/go-yoshi.d.ts +0 -10
  193. package/build/src/releasers/go-yoshi.js +0 -162
  194. package/build/src/releasers/go.d.ts +0 -6
  195. package/build/src/releasers/helm.d.ts +0 -9
  196. package/build/src/releasers/helm.js +0 -66
  197. package/build/src/releasers/index.d.ts +0 -7
  198. package/build/src/releasers/index.js +0 -76
  199. package/build/src/releasers/java/bump_type.d.ts +0 -4
  200. package/build/src/releasers/java/bump_type.js +0 -38
  201. package/build/src/releasers/java/stability.d.ts +0 -5
  202. package/build/src/releasers/java/stability.js +0 -37
  203. package/build/src/releasers/java/version.d.ts +0 -13
  204. package/build/src/releasers/java/version.js +0 -112
  205. package/build/src/releasers/java-backport.d.ts +0 -9
  206. package/build/src/releasers/java-backport.js +0 -43
  207. package/build/src/releasers/java-bom.d.ts +0 -16
  208. package/build/src/releasers/java-bom.js +0 -83
  209. package/build/src/releasers/java-lts.d.ts +0 -9
  210. package/build/src/releasers/java-lts.js +0 -47
  211. package/build/src/releasers/java-yoshi.d.ts +0 -28
  212. package/build/src/releasers/java-yoshi.js +0 -304
  213. package/build/src/releasers/krm-blueprint.d.ts +0 -6
  214. package/build/src/releasers/node.d.ts +0 -10
  215. package/build/src/releasers/node.js +0 -84
  216. package/build/src/releasers/ocaml.d.ts +0 -5
  217. package/build/src/releasers/php-yoshi.d.ts +0 -5
  218. package/build/src/releasers/php-yoshi.js +0 -191
  219. package/build/src/releasers/php.d.ts +0 -7
  220. package/build/src/releasers/python.d.ts +0 -11
  221. package/build/src/releasers/python.js +0 -127
  222. package/build/src/releasers/ruby-yoshi.d.ts +0 -5
  223. package/build/src/releasers/ruby-yoshi.js +0 -142
  224. package/build/src/releasers/ruby.d.ts +0 -11
  225. package/build/src/releasers/rust.d.ts +0 -30
  226. package/build/src/releasers/rust.js +0 -163
  227. package/build/src/releasers/simple.d.ts +0 -5
  228. package/build/src/releasers/terraform-module.d.ts +0 -6
  229. package/build/src/updaters/elixir-mix-exs.d.ts +0 -13
  230. package/build/src/updaters/java/google-utils.d.ts +0 -13
  231. package/build/src/updaters/java/java_update.d.ts +0 -13
  232. package/build/src/updaters/java/pom-xml.d.ts +0 -3
  233. package/build/src/updaters/java/readme.d.ts +0 -3
  234. package/build/src/updaters/java/readme.js.map +0 -1
  235. package/build/src/updaters/package-json.d.ts +0 -16
  236. package/build/src/updaters/package-lock-json.d.ts +0 -7
  237. package/build/src/updaters/php-client-version.d.ts +0 -13
  238. package/build/src/updaters/php-manifest.d.ts +0 -13
  239. package/build/src/updaters/pubspec-yaml.d.ts +0 -13
  240. package/build/src/updaters/root-composer-update-package.d.ts +0 -13
  241. package/build/src/updaters/root-composer-update-package.js +0 -45
  242. package/build/src/updaters/root-composer-update-packages.d.ts +0 -13
  243. package/build/src/updaters/samples-package-json.d.ts +0 -13
  244. package/build/src/updaters/update.d.ts +0 -20
  245. package/build/src/updaters/version-rb.d.ts +0 -13
  246. package/build/src/updaters/version-txt.d.ts +0 -12
  247. package/build/src/updaters/version.d.ts +0 -13
  248. package/build/src/updaters/version.js +0 -31
  249. package/build/src/util/checkpoint.d.ts +0 -6
  250. package/build/src/util/checkpoint.js +0 -33
  251. package/build/src/util/release-notes.d.ts +0 -7
  252. package/build/src/util/release-notes.js +0 -34
  253. package/build/src/util/to-conventional-changelog-format.d.ts +0 -2
@@ -13,17 +13,19 @@
13
13
  // See the License for the specific language governing permissions and
14
14
  // limitations under the License.
15
15
  Object.defineProperty(exports, "__esModule", { value: true });
16
- const semver = require("semver");
17
- const cu = require("@lerna/collect-updates");
18
- const package_1 = require("@lerna/package");
16
+ exports.NodeWorkspace = void 0;
19
17
  const package_graph_1 = require("@lerna/package-graph");
20
- const run_topologically_1 = require("@lerna/run-topologically");
21
- const plugin_1 = require("./plugin");
18
+ const package_1 = require("@lerna/package");
19
+ const logger_1 = require("../util/logger");
20
+ const manifest_1 = require("../manifest");
21
+ const version_1 = require("../version");
22
+ const raw_content_1 = require("../updaters/raw-content");
23
+ const pull_request_title_1 = require("../util/pull-request-title");
24
+ const pull_request_body_1 = require("../util/pull-request-body");
25
+ const branch_name_1 = require("../util/branch-name");
22
26
  const json_stringify_1 = require("../util/json-stringify");
23
- const checkpoint_1 = require("../util/checkpoint");
24
- const constants_1 = require("../constants");
25
- const conventional_commits_1 = require("../conventional-commits");
26
27
  const changelog_1 = require("../updaters/changelog");
28
+ const workspace_1 = require("./workspace");
27
29
  class Package extends package_1.Package {
28
30
  constructor(rawContent, location, pkg) {
29
31
  super(pkg !== null && pkg !== void 0 ? pkg : JSON.parse(rawContent), location);
@@ -33,301 +35,262 @@ class Package extends package_1.Package {
33
35
  return new Package(this.rawContent, this.location, this.toJSON());
34
36
  }
35
37
  }
36
- class NodeWorkspaceDependencyUpdates extends plugin_1.ManifestPlugin {
37
- // package.json contents already updated by the node releasers.
38
- filterPackages(pkgsWithPRData) {
39
- const pathPkgs = new Map();
40
- for (const pkg of pkgsWithPRData) {
41
- if (pkg.config.releaseType === 'node' && pkg.config.path !== '.') {
42
- for (const [path, fileData] of pkg.prData.changes) {
43
- if (path === `${pkg.config.path}/package.json`) {
44
- this.log(`found ${path} in changes`, checkpoint_1.CheckpointType.Success);
45
- pathPkgs.set(path, fileData.content);
46
- }
47
- }
48
- }
49
- }
50
- return pathPkgs;
38
+ /**
39
+ * The plugin analyzed a cargo workspace and will bump dependencies
40
+ * of managed packages if those dependencies are being updated.
41
+ *
42
+ * If multiple node packages are being updated, it will merge them
43
+ * into a single node package.
44
+ */
45
+ class NodeWorkspace extends workspace_1.WorkspacePlugin {
46
+ constructor(github, targetBranch, repositoryConfig, options = {}) {
47
+ super(github, targetBranch, repositoryConfig, options);
48
+ this.alwaysLinkLocal = options.alwaysLinkLocal === false ? false : true;
51
49
  }
52
- // all packages' package.json content - both updated by this run as well as
53
- // those that did not update (no user facing commits).
54
- async getAllWorkspacePackages(rpUpdatedPkgs) {
55
- const nodePkgs = new Map();
56
- for (const pkg of this.config.parsedPackages) {
57
- if (pkg.releaseType !== 'node' || pkg.path === '.') {
50
+ async buildAllPackages(candidates) {
51
+ const candidatesByPath = new Map();
52
+ for (const candidate of candidates) {
53
+ candidatesByPath.set(candidate.path, candidate);
54
+ }
55
+ const candidatesByPackage = {};
56
+ const packagesByPath = new Map();
57
+ for (const path in this.repositoryConfig) {
58
+ const config = this.repositoryConfig[path];
59
+ if (config.releaseType !== 'node') {
58
60
  continue;
59
61
  }
60
- const path = `${pkg.path}/package.json`;
61
- let contents;
62
- const alreadyUpdated = rpUpdatedPkgs.get(path);
63
- if (alreadyUpdated) {
64
- contents = alreadyUpdated;
62
+ const candidate = candidatesByPath.get(path);
63
+ if (candidate) {
64
+ logger_1.logger.debug(`Found candidate pull request for path: ${candidate.path}`);
65
+ const packagePath = addPath(candidate.path, 'package.json');
66
+ const packageUpdate = candidate.pullRequest.updates.find(update => update.path === packagePath);
67
+ if (packageUpdate === null || packageUpdate === void 0 ? void 0 : packageUpdate.cachedFileContents) {
68
+ const pkg = new Package(packageUpdate.cachedFileContents.parsedContent, candidate.path);
69
+ packagesByPath.set(candidate.path, pkg);
70
+ candidatesByPackage[pkg.name] = candidate;
71
+ }
72
+ else {
73
+ const contents = await this.github.getFileContentsOnBranch(packagePath, this.targetBranch);
74
+ const pkg = new Package(contents.parsedContent, candidate.path);
75
+ packagesByPath.set(candidate.path, pkg);
76
+ candidatesByPackage[pkg.name] = candidate;
77
+ }
65
78
  }
66
79
  else {
67
- const { parsedContent } = await this.gh.getFileContents(path);
68
- contents = parsedContent;
80
+ const packagePath = addPath(path, 'package.json');
81
+ logger_1.logger.debug(`No candidate pull request for path: ${path} - inspect package from ${packagePath}`);
82
+ const contents = await this.github.getFileContentsOnBranch(packagePath, this.targetBranch);
83
+ packagesByPath.set(path, new Package(contents.parsedContent, path));
69
84
  }
70
- this.log(`loaded ${path} from ${alreadyUpdated ? 'existing changes' : 'github'}`, checkpoint_1.CheckpointType.Success);
71
- nodePkgs.set(path, new Package(contents, path));
72
85
  }
73
- return nodePkgs;
86
+ const allPackages = Array.from(packagesByPath.values());
87
+ this.packageGraph = new package_graph_1.PackageGraph(allPackages, 'allDependencies', this.alwaysLinkLocal);
88
+ return {
89
+ allPackages,
90
+ candidatesByPackage,
91
+ };
92
+ }
93
+ bumpVersion(pkg) {
94
+ const version = version_1.Version.parse(pkg.version);
95
+ version.patch += 1;
96
+ return version;
74
97
  }
75
- async runLernaVersion(rpUpdatedPkgs, allPkgs) {
98
+ updateCandidate(existingCandidate, pkg, updatedVersions) {
76
99
  var _a;
77
- // Build the graph of all the packages: similar to https://git.io/Jqf1v
78
- const packageGraph = new package_graph_1.PackageGraph(
79
- // use pkg.clone() which does a shallow copy of the internal data storage
80
- // so we can preserve the original allPkgs for version diffing later.
81
- [...allPkgs.values()].map(pkg => pkg.clone()), 'allDependencies', (_a = this.config['always-link-local']) !== null && _a !== void 0 ? _a : true);
82
- // release-please already did the work of @lerna/collectUpdates (identifying
83
- // which packages need version bumps based on conventional commits). We use
84
- // that as our `isCandidate` callback in @lerna/collectUpdates.collectPackages.
85
- // similar to https://git.io/JqUOB
86
- // `collectPackages` includes "localDependents" of our release-please updated
87
- // packages as they need to be patch bumped.
88
- const isCandidate = (node) => rpUpdatedPkgs.has(node.location);
89
- const updatesWithDependents = cu.collectPackages(packageGraph, {
90
- isCandidate,
91
- onInclude: name => this.log(`${name} collected for update (dependency-only = ${!isCandidate(packageGraph.get(name))})`, checkpoint_1.CheckpointType.Success),
92
- excludeDependents: false,
93
- });
94
- // our implementation of producing a Map<pkgName, newVersion> similar to
95
- // `this.updatesVersions` which is used to set updated package
96
- // (https://git.io/JqfD7) and dependency (https://git.io/JqU3q) versions
97
- //
98
- // `lerna version` accomplishes this with:
99
- // `getVersionsForUpdates` (https://git.io/JqfyI)
100
- // -> `getVersion` + `reduceVersions` (https://git.io/JqfDI)
101
- const updatesVersions = new Map();
102
- const invalidVersions = new Set();
103
- for (const node of updatesWithDependents) {
104
- let version;
105
- let source;
106
- if (rpUpdatedPkgs.has(node.location)) {
107
- version = node.version;
108
- source = constants_1.RELEASE_PLEASE;
100
+ const graphPackage = (_a = this.packageGraph) === null || _a === void 0 ? void 0 : _a.get(pkg.name);
101
+ if (!graphPackage) {
102
+ throw new Error(`Could not find graph package for ${pkg.name}`);
103
+ }
104
+ const updatedPackage = pkg.clone();
105
+ for (const [depName, resolved] of graphPackage.localDependencies) {
106
+ const depVersion = updatedVersions.get(depName);
107
+ if (depVersion && resolved.type !== 'directory') {
108
+ updatedPackage.updateLocalDependency(resolved, depVersion.toString(), '^');
109
+ logger_1.logger.info(`${pkg.name}.${depName} updated to ^${depVersion.toString()}`);
109
110
  }
110
- else {
111
- // must be a dependent, check for releaseAs config otherwise default
112
- // to a patch bump.
113
- const pkgConfig = this.config.parsedPackages.find(p => {
114
- const pkgPath = `${p.path}/package.json`;
115
- const match = pkgPath === node.location;
116
- this.log(`Checking node "${node.location}" against parsed package "${pkgPath}"`, match ? checkpoint_1.CheckpointType.Success : checkpoint_1.CheckpointType.Failure);
117
- return match;
118
- });
119
- if (!pkgConfig) {
120
- this.log(`No pkgConfig found for ${node.location}`, checkpoint_1.CheckpointType.Failure);
121
- }
122
- else if (!pkgConfig.releaseAs) {
123
- this.log(`No pkgConfig.releaseAs for ${node.location}`, checkpoint_1.CheckpointType.Failure);
111
+ }
112
+ const dependencyNotes = getChangelogDepsNotes(pkg, updatedPackage);
113
+ existingCandidate.pullRequest.updates =
114
+ existingCandidate.pullRequest.updates.map(update => {
115
+ if (update.path === addPath(existingCandidate.path, 'package.json')) {
116
+ update.updater = new raw_content_1.RawContent(json_stringify_1.jsonStringify(updatedPackage.toJSON(), updatedPackage.rawContent));
124
117
  }
125
- if (pkgConfig === null || pkgConfig === void 0 ? void 0 : pkgConfig.releaseAs) {
126
- version = pkgConfig.releaseAs;
127
- source = 'release-as configuration';
128
- }
129
- else {
130
- const patch = semver.inc(node.version, 'patch');
131
- if (patch === null) {
132
- this.log(`Don't know how to patch ${node.name}'s version(${node.version})`, checkpoint_1.CheckpointType.Failure);
133
- invalidVersions.add(node.name);
134
- version = node.version;
135
- source = 'failed to patch bump';
136
- }
137
- else {
138
- version = patch;
139
- source = 'dependency bump';
140
- }
118
+ else if (update.updater instanceof changelog_1.Changelog) {
119
+ update.updater.changelogEntry = appendDependenciesSectionToChangelog(update.updater.changelogEntry, dependencyNotes);
141
120
  }
121
+ return update;
122
+ });
123
+ // append dependency notes
124
+ if (dependencyNotes) {
125
+ if (existingCandidate.pullRequest.body.releaseData.length > 0) {
126
+ existingCandidate.pullRequest.body.releaseData[0].notes =
127
+ appendDependenciesSectionToChangelog(existingCandidate.pullRequest.body.releaseData[0].notes, dependencyNotes);
142
128
  }
143
- this.log(`setting ${node.location} to ${version} from ${source}`, checkpoint_1.CheckpointType.Success);
144
- updatesVersions.set(node.name, version);
145
- }
146
- // our implementation of a subset of `updatePackageVersions` to produce a
147
- // callback for updating versions and dependencies (https://git.io/Jqfyu)
148
- const runner = async (pkg) => {
149
- pkg.set('version', updatesVersions.get(pkg.name));
150
- const graphPkg = packageGraph.get(pkg.name);
151
- for (const [depName, resolved] of graphPkg.localDependencies) {
152
- const depVersion = updatesVersions.get(depName);
153
- if (depVersion && resolved.type !== 'directory') {
154
- pkg.updateLocalDependency(resolved, depVersion, '^');
155
- this.log(`${pkg.name}.${depName} updated to ^${depVersion}`, checkpoint_1.CheckpointType.Success);
156
- }
129
+ else {
130
+ existingCandidate.pullRequest.body.releaseData.push({
131
+ component: updatedPackage.name,
132
+ version: existingCandidate.pullRequest.version,
133
+ notes: appendDependenciesSectionToChangelog('', dependencyNotes),
134
+ });
157
135
  }
158
- return pkg;
159
- };
160
- // https://git.io/Jqfyp
161
- const allUpdated = (await run_topologically_1.runTopologically(updatesWithDependents.map(node => node.pkg), runner, {
162
- graphType: 'allDependencies',
163
- concurrency: 1,
164
- rejectCycles: false,
165
- }));
166
- return new Map(allUpdated.map(p => [p.location, p]));
136
+ }
137
+ return existingCandidate;
167
138
  }
168
- async updatePkgsWithPRData(pkgsWithPRData, newManifestVersions, allUpdated, allOrigPkgs) {
169
- // already had version bumped by release-please, may have also had
170
- // dependency version bumps as well
171
- for (const data of pkgsWithPRData) {
172
- if (data.config.releaseType !== 'node' || data.config.path === '.') {
173
- continue;
139
+ newCandidate(pkg, updatedVersions) {
140
+ var _a;
141
+ const graphPackage = (_a = this.packageGraph) === null || _a === void 0 ? void 0 : _a.get(pkg.name);
142
+ if (!graphPackage) {
143
+ throw new Error(`Could not find graph package for ${pkg.name}`);
144
+ }
145
+ const updatedPackage = pkg.clone();
146
+ for (const [depName, resolved] of graphPackage.localDependencies) {
147
+ const depVersion = updatedVersions.get(depName);
148
+ if (depVersion && resolved.type !== 'directory') {
149
+ updatedPackage.updateLocalDependency(resolved, depVersion.toString(), '^');
150
+ logger_1.logger.info(`${pkg.name}.${depName} updated to ^${depVersion.toString()}`);
174
151
  }
175
- const filePath = `${data.config.path}/package.json`;
176
- const updated = allUpdated.get(filePath); // bug if not defined
177
- data.prData.changes.set(filePath, {
178
- content: json_stringify_1.jsonStringify(updated.toJSON(), updated.rawContent),
179
- mode: '100644',
180
- });
181
- await this.setChangelogEntry(data.config, data.prData.changes, updated, allOrigPkgs.get(filePath).toJSON() // bug if undefined.
182
- );
183
- allUpdated.delete(filePath);
184
152
  }
185
- // non-release-please updated packages that have updates solely because
186
- // dependency versions incremented.
187
- for (const [filePath, updated] of allUpdated) {
188
- const pkg = this.config.parsedPackages.find(p => `${p.path}/package.json` === filePath); // bug if undefined.
189
- pkg.packageName = updated.name;
190
- const content = json_stringify_1.jsonStringify(updated.toJSON(), updated.rawContent);
191
- const changes = new Map([[filePath, { content, mode: '100644' }]]);
192
- await this.setChangelogEntry(pkg, changes, updated, allOrigPkgs.get(filePath) // bug if undefined.
193
- );
194
- pkgsWithPRData.push({
195
- config: pkg,
196
- prData: {
197
- version: updated.version,
198
- changes,
153
+ const dependencyNotes = getChangelogDepsNotes(pkg, updatedPackage);
154
+ const packageJson = updatedPackage.toJSON();
155
+ const version = version_1.Version.parse(packageJson.version);
156
+ const pullRequest = {
157
+ title: pull_request_title_1.PullRequestTitle.ofTargetBranch(this.targetBranch),
158
+ body: new pull_request_body_1.PullRequestBody([
159
+ {
160
+ component: updatedPackage.name,
161
+ version,
162
+ notes: appendDependenciesSectionToChangelog('', dependencyNotes),
163
+ },
164
+ ]),
165
+ updates: [
166
+ {
167
+ path: addPath(updatedPackage.location, 'package.json'),
168
+ createIfMissing: false,
169
+ updater: new raw_content_1.RawContent(json_stringify_1.jsonStringify(packageJson, updatedPackage.rawContent)),
170
+ },
171
+ {
172
+ path: addPath(updatedPackage.location, 'CHANGELOG.md'),
173
+ createIfMissing: false,
174
+ updater: new changelog_1.Changelog({
175
+ version,
176
+ changelogEntry: dependencyNotes,
177
+ }),
199
178
  },
179
+ ],
180
+ labels: [],
181
+ headRefName: branch_name_1.BranchName.ofTargetBranch(this.targetBranch).toString(),
182
+ version,
183
+ draft: false,
184
+ };
185
+ return {
186
+ path: updatedPackage.location,
187
+ pullRequest,
188
+ config: {
189
+ releaseType: 'node',
190
+ },
191
+ };
192
+ }
193
+ async buildGraph(allPackages) {
194
+ var _a, _b, _c, _d;
195
+ const graph = new Map();
196
+ const workspacePackageNames = new Set(allPackages.map(packageJson => packageJson.name));
197
+ for (const packageJson of allPackages) {
198
+ const allDeps = Object.keys({
199
+ ...((_a = packageJson.dependencies) !== null && _a !== void 0 ? _a : {}),
200
+ ...((_b = packageJson.devDependencies) !== null && _b !== void 0 ? _b : {}),
201
+ ...((_c = packageJson.optionalDependencies) !== null && _c !== void 0 ? _c : {}),
202
+ ...((_d = packageJson.peerDependencies) !== null && _d !== void 0 ? _d : {}),
203
+ });
204
+ const workspaceDeps = allDeps.filter(dep => workspacePackageNames.has(dep));
205
+ graph.set(packageJson.name, {
206
+ deps: workspaceDeps,
207
+ value: packageJson,
200
208
  });
201
- newManifestVersions.set(filePath.replace(/\/package.json$/, ''), updated.version);
202
209
  }
210
+ return graph;
203
211
  }
204
- getChangelogDepsNotes(pkg, origPkgJson) {
205
- var _a;
206
- let depUpdateNotes = '';
207
- const depTypes = [
208
- 'dependencies',
209
- 'devDependencies',
210
- 'peerDependencies',
211
- 'optionalDependencies',
212
- ];
213
- const updates = new Map();
214
- for (const depType of depTypes) {
215
- const depUpdates = [];
216
- const pkgDepTypes = pkg[depType];
217
- if (pkgDepTypes === undefined) {
218
- continue;
219
- }
220
- for (const [depName, currentDepVer] of Object.entries(pkgDepTypes)) {
221
- const origDepVer = (_a = origPkgJson[depType]) === null || _a === void 0 ? void 0 : _a[depName];
222
- if (currentDepVer !== origDepVer) {
223
- depUpdates.push(`\n * ${depName} bumped from ${origDepVer} to ${currentDepVer}`);
224
- }
225
- }
226
- if (depUpdates.length > 0) {
227
- updates.set(depType, depUpdates);
228
- }
212
+ inScope(candidate) {
213
+ return (candidate.config.releaseType === 'node' &&
214
+ candidate.path !== manifest_1.ROOT_PROJECT_PATH);
215
+ }
216
+ packageNameFromPackage(pkg) {
217
+ return pkg.name;
218
+ }
219
+ }
220
+ exports.NodeWorkspace = NodeWorkspace;
221
+ function getChangelogDepsNotes(original, updated) {
222
+ var _a;
223
+ let depUpdateNotes = '';
224
+ const depTypes = [
225
+ 'dependencies',
226
+ 'devDependencies',
227
+ 'peerDependencies',
228
+ 'optionalDependencies',
229
+ ];
230
+ const updates = new Map();
231
+ for (const depType of depTypes) {
232
+ const depUpdates = [];
233
+ const pkgDepTypes = updated[depType];
234
+ if (pkgDepTypes === undefined) {
235
+ continue;
229
236
  }
230
- for (const [dt, notes] of updates) {
231
- depUpdateNotes += `\n * ${dt}`;
232
- for (const note of notes) {
233
- depUpdateNotes += note;
237
+ for (const [depName, currentDepVer] of Object.entries(pkgDepTypes)) {
238
+ const origDepVer = (_a = original[depType]) === null || _a === void 0 ? void 0 : _a[depName];
239
+ if (currentDepVer !== origDepVer) {
240
+ depUpdates.push(`\n * ${depName} bumped from ${origDepVer} to ${currentDepVer}`);
234
241
  }
235
242
  }
236
- return depUpdateNotes;
237
- }
238
- updateChangelogEntry(exChangelog, changelogEntry, pkg) {
239
- changelogEntry = changelogEntry.replace(new RegExp(`^###? \\[${pkg.version}\\].*### Dependencies`, 's'), '### Dependencies');
240
- const match = exChangelog.match(new RegExp(`(?<before>^.*?###? \\[${pkg.version}\\].*?\n)(?<after>###? [0-9[].*)`, 's'));
241
- if (!match) {
242
- this.log(`Appending update notes to end of changelog for ${pkg.name}`, checkpoint_1.CheckpointType.Failure);
243
- changelogEntry = `${exChangelog}\n\n\n${changelogEntry}`;
244
- }
245
- else {
246
- const { before, after } = match.groups;
247
- changelogEntry = `${before.trim()}\n\n\n${changelogEntry}\n\n${after.trim()}`;
243
+ if (depUpdates.length > 0) {
244
+ updates.set(depType, depUpdates);
248
245
  }
249
- return changelogEntry;
250
246
  }
251
- async newChangelogEntry(changelogEntry, changelogPath, pkg) {
252
- let changelog;
253
- try {
254
- changelog = (await this.gh.getFileContents(changelogPath)).parsedContent;
247
+ for (const [dt, notes] of updates) {
248
+ depUpdateNotes += `\n * ${dt}`;
249
+ for (const note of notes) {
250
+ depUpdateNotes += note;
255
251
  }
256
- catch (e) {
257
- if (e.status !== 404) {
258
- this.log(`Failed to retrieve ${changelogPath}: ${e}`, checkpoint_1.CheckpointType.Failure);
259
- return '';
252
+ }
253
+ if (depUpdateNotes) {
254
+ return `* The following workspace dependencies were updated${depUpdateNotes}`;
255
+ }
256
+ return '';
257
+ }
258
+ const DEPENDENCY_HEADER = new RegExp('### Dependencies');
259
+ function appendDependenciesSectionToChangelog(changelog, notes) {
260
+ if (!changelog) {
261
+ return `### Dependencies\n\n${notes}`;
262
+ }
263
+ const newLines = [];
264
+ let seenDependenciesSection = false;
265
+ let seenDependencySectionSpacer = false;
266
+ let injected = false;
267
+ for (const line of changelog.split('\n')) {
268
+ if (seenDependenciesSection) {
269
+ const trimmedLine = line.trim();
270
+ if (seenDependencySectionSpacer &&
271
+ !injected &&
272
+ !trimmedLine.startsWith('*')) {
273
+ newLines.push(changelog);
274
+ injected = true;
260
275
  }
261
- else {
262
- this.log(`Creating a new changelog at ${changelogPath}`, checkpoint_1.CheckpointType.Success);
276
+ if (trimmedLine === '') {
277
+ seenDependencySectionSpacer = true;
263
278
  }
264
279
  }
265
- const changelogUpdater = new changelog_1.Changelog({
266
- path: changelogPath,
267
- changelogEntry,
268
- version: pkg.version,
269
- packageName: pkg.name,
270
- });
271
- return changelogUpdater.updateContent(changelog);
272
- }
273
- async setChangelogEntry(config, changes, pkg, origPkgJson) {
274
- var _a, _b, _c;
275
- const depUpdateNotes = this.getChangelogDepsNotes(pkg, origPkgJson);
276
- if (!depUpdateNotes) {
277
- return;
278
- }
279
- const cc = new conventional_commits_1.ConventionalCommits({
280
- changelogSections: [{ type: 'deps', section: 'Dependencies' }],
281
- commits: [
282
- {
283
- sha: '',
284
- message: 'deps: The following workspace dependencies were updated',
285
- files: [],
286
- },
287
- ],
288
- owner: this.gh.owner,
289
- repository: this.gh.repo,
290
- bumpMinorPreMajor: config.bumpMinorPreMajor,
291
- });
292
- let tagPrefix = ((_a = config.packageName) === null || _a === void 0 ? void 0 : _a.match(/^@[\w-]+\//)) ? config.packageName.split('/')[1]
293
- : config.packageName;
294
- tagPrefix += '-v';
295
- let changelogEntry = await cc.generateChangelogEntry({
296
- version: pkg.version,
297
- currentTag: tagPrefix + pkg.version,
298
- previousTag: tagPrefix + origPkgJson.version,
299
- });
300
- changelogEntry += depUpdateNotes;
301
- let updatedChangelog;
302
- let changelogPath = (_b = config.changelogPath) !== null && _b !== void 0 ? _b : 'CHANGELOG.md';
303
- if (config.path !== '.') {
304
- changelogPath = `${config.path}/${changelogPath}`;
305
- }
306
- const exChangelog = (_c = changes.get(changelogPath)) === null || _c === void 0 ? void 0 : _c.content;
307
- if (exChangelog) {
308
- updatedChangelog = this.updateChangelogEntry(exChangelog, changelogEntry, pkg);
309
- }
310
- else {
311
- updatedChangelog = await this.newChangelogEntry(changelogEntry, changelogPath, pkg);
312
- }
313
- if (updatedChangelog) {
314
- changes.set(changelogPath, {
315
- content: updatedChangelog,
316
- mode: '100644',
317
- });
280
+ if (line.match(DEPENDENCY_HEADER)) {
281
+ seenDependenciesSection = true;
318
282
  }
283
+ newLines.push(line);
319
284
  }
320
- /**
321
- * Update node monorepo workspace package dependencies.
322
- * Inspired by and using a subset of the logic from `lerna version`
323
- */
324
- async run(newManifestVersions, pkgsWithPRData) {
325
- const rpUpdatedPkgs = this.filterPackages(pkgsWithPRData);
326
- const allPkgs = await this.getAllWorkspacePackages(rpUpdatedPkgs);
327
- const allUpdated = await this.runLernaVersion(rpUpdatedPkgs, allPkgs);
328
- await this.updatePkgsWithPRData(pkgsWithPRData, newManifestVersions, allUpdated, allPkgs);
329
- return [newManifestVersions, pkgsWithPRData];
285
+ if (injected) {
286
+ return newLines.join('\n');
330
287
  }
288
+ if (seenDependenciesSection) {
289
+ return `${changelog}\n${notes}`;
290
+ }
291
+ return `${changelog}\n\n\n### Dependencies\n\n${notes}`;
292
+ }
293
+ function addPath(path, file) {
294
+ return path === manifest_1.ROOT_PROJECT_PATH ? file : `${path}/${file}`;
331
295
  }
332
- exports.default = NodeWorkspaceDependencyUpdates;
333
296
  //# sourceMappingURL=node-workspace.js.map