Repository navigation
feat: adds support for conventional-commits (for CHANGELOG generation and verison bump) - #665
Conversation
|
@Tapppi, @stevemao, this pulls together everything being discussed in conventional-changelog/conventional-changelog#168 -- validating the week of noodling I've been doing in our |
| // write new package | ||
| FileSystemUtilities.writeFileSync(packageJsonLocation, pkg.toJsonString()); | ||
|
|
||
| // we can now generate the Chnagelog, based on the |
| // run conventional-changelog-cli to generate the markdown | ||
| // for the upcoming release. | ||
| const newEntry = ChildProcessUtilities.execSync( | ||
| `${require.resolve("conventional-changelog-cli/cli.js")} -l ${name} --commit-path=${pkgPath} --pkg=${pkgPath} -p angular` |
There was a problem hiding this comment.
Is there any reason we don't use the api module, conventional-changelog, here?
There was a problem hiding this comment.
It's my feeling that relying on the conventional-recommended-bump cli, and conventional-changelog-cli fits well with the existing patterns in the codebase; simply shelling out to npm with NpmUtilities.js , or git with GitUtilities.js:
- this minimized the number of modules from the conventional CHANGELOG ecosystem that I would need to pull in to support this functionality.
- and allows me, while adding tests, to use the same helpers/conventions used when adding tests to
npm/git:- it's my plan to mock
ChildProcess, using the same approach as here: https://github.com/lerna/lerna/blob/master/test/PublishCommand.js#L1707
- it's my plan to mock
I'm not completely married to this approach, but it feels pretty elegant to me that the lerna codebase doesn't need any domain specific knowledge of the conventional-changelog API -- as far as this codebase is concerned it's just calling another command line application.
|
|
||
| // CHANGELOG entries start with <a name=, we remove | ||
| // the header if it exists by starting at the first entry. | ||
| if (changelogContents.indexOf("<a name=") !== -1) { |
There was a problem hiding this comment.
@stevemao mind going into details don't completely follow?
There was a problem hiding this comment.
@stevemao I think we have slightly different use-cases in mind; I like the idea of adding in a header that explains the conventional-changelog format to curious parties -- I've found this is very useful for evangelizing the approach --
the annoying thing is it means we need to avoid adding the header multiple times as the CHANGELOG is updated; is there an existing module that solves this use-case?
There was a problem hiding this comment.
EDIT: I added this comment before your second comment
We could change the handlebars template for the header. It's easy to do it with the api module
conventionalChangelog(options, context, gitRawCommitsOpts, parserOpts, {
headerPartial: '{{#if isPatch~}}...' // without '<a name='
})But with the cli at the moment we need to provide a config file to change this option. The presets are good example of overwriting the default template partials
There was a problem hiding this comment.
@stevemao I think this is the header for specific commits? I'm talking about the use-case:
# Overall Title
Header that introduces conventional commits and doesn't change.
* commit.
* commit.
* commit
Why don't we add the actual CHANGELOG merging logic to conventional-changelog-cli; then we could use the same logic for lerna and for standard-version; I think this would be a good solution because it DRYs up both codebases logic.
There was a problem hiding this comment.
The header of conventional-changelog-writer is per release. I'm not talking about the CHANGELOG_HEADER here and I think this is done right. I'm just saying stripping <a name= manually shouldn't be needed since we could just overwrite the headerPartial template.
There was a problem hiding this comment.
@stevemao gotcha; I think my comment is just confusing.
I don't want to strip the generated header; I just want to insert the new commit message between CHANGELOG_HEADER and the old commit messages; this is the same logic used by standard-version., and might be worth DRYing up.
There was a problem hiding this comment.
Oops sorry, misread the code :)
|
@bcoe This is awesome, I think enabling a workflow as easy as |
|
|
||
| ${newEntry} | ||
|
|
||
| ${changelogContents}`.replace(/\n+$/, "\n") |
There was a problem hiding this comment.
Orthogonal to this PR, but I really like dedent for readable indentation of multi-line template strings.
| @logger.logifySync() | ||
| static recommendVersion(name, version) { | ||
| try { | ||
| const pkgPath = `./packages/${name}/`; |
There was a problem hiding this comment.
This won't support our customizable (and potentially multiple) packages config. I would recommend instead simply passing the Package instance in and dereferencing the fields directly (such as pkg.location, which will give you what you want here).
There was a problem hiding this comment.
@evocateur yeah, I noticed this when I started writing tests; wasn't sure how complex pkg.location could become.
It feels like changelog.location should then be something like path.resolve(pkg.location, 'changelog.md')?
| // the updated version that we're about to release. | ||
| if (this.flags.conventionalCommits) { | ||
| ConventionalCommitUtilties.updateChangelog(update.package.name, changelogLocation); | ||
| changedFiles.push(changelogLocation); |
There was a problem hiding this comment.
I would prefer to encapsulate the changelogLocation assignment inside updateChangelog(). Perhaps return the changed location for pushing into changedFiles, then?
In fact, changelogs being important enough, regardless of how one generates them, I can justify adding a changelogLocation getter to the Package class, thus removing the need for a return value.
diff --git a/src/Package.js b/src/Package.js
index 76a88da..d4d4bee 100644
--- a/src/Package.js
+++ b/src/Package.js
@@ -17,6 +17,10 @@ export default class Package {
return this._location;
}
+ get changelogLocation() {
+ return path.join(this._location, "CHANGELOG.md");
+ }
+
get nodeModulesLocation() {
return path.join(this._location, "node_modules");
}|
Hi @bcoe, thanks for opening this. I just wanted to make you aware of some plans for the future. We're planning on merging Lerna into Yarn through "workspaces" (sounds like npm has some related plans). I'm not sure a feature like this makes sense to be built directly into Yarn or npm, but definitely on top of it. I'm wondering how we can enable you to build features like this on top of Lerna and later Yarn so that you don't have to rethink everything in the future. One thing I've always wanted in Lerna which is part of the plan for Yarn is I think this functionality could be built on top of that and give you a lot more flexibility in the future. |
|
@thejameskyle Is there a planning wiki/issue for "workspaces" that we can follow? |
|
@thejameskyle @evocateur I was thinking events resembling package lifecycle scripts would get you pretty far ... but, one killer feature of a conventional changelog I couldn't think of an elegant way to facilitate, was recommending the version bump: If you're using a conventional changelog format, we know when the release should be a I've been talking to @iarna about my requirements around a monorepo, and was aware of the plans of rolling this workflow (at least in some form) into yarn -- my two cents, I think that the tagging and publication workflow that lerna facilitates in an abstract way is quite powerful, it would be cool to continue having a library that lives separately from your npm client of choice to facilitate the advanced workflows I rely on as an open-source maintainer: git-tagging, CHANGELOG generation, etc. |
|
I'm not sure |
|
I think Lerna should as much as possible try to model what would be built into Yarn or npm. People have and are going to continue building a lot of tooling on top of this functionality and it would be nice if that tooling didn't lock people in place. There's a lot we can build into Lerna as an independent tool, but what's maybe more interesting is using Lerna as an experiment into how we can build features like workspaces into our package managers while finding the right extension points. If we can build conventional-changelog tooling on top of Lerna, that tool can be easily reused if people want to switch to Yarn or npm. |
|
@thejameskyle @evocateur here's how I think I could offer this functionality in a more abstract way:
With regards to this pull request, should @evocateur and I continue moving this feature forward without this abstraction (it feels like it will take longer to build out this lifecycle abstraction, and I sure wouldn't complain if I had |
|
Yes, exactly!
… On Mar 13, 2017, at 21:46, Benjamin E. Coe ***@***.***> wrote:
@bcoe commented on this pull request.
In src/ConventionalCommitUtilties.js:
> @@ -0,0 +1,61 @@
+import ChildProcessUtilities from "./ChildProcessUtilities";
+import FileSystemUtilities from "./FileSystemUtilities";
+import logger from "./logger";
+import semver from "semver";
+
+const CHANGELOG_HEADER = `# Change Log
+
+All notable changes to this project will be documented in this file.
+See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.`;
+
+export default class ConventionalCommitUtilties {
+ @logger.logifySync()
+ static recommendVersion(name, version) {
+ try {
+ const pkgPath = `./packages/${name}/`;
@evocateur yeah, I noticed this when I started writing tests; wasn't sure how complex pkg.location could become.
It feels like changelog.location should then be something like path.resolve(pkg.location, 'changelog.md')?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
3a604c2 to
2a83b5f
Compare
| ]], | ||
| [FileSystemUtilities, "writeFileSync", {}, [ | ||
| { | ||
| args: ["/foo/bar/CHANGELOG.md", dedent(` |
There was a problem hiding this comment.
The path here needs to use path.normalize so windows doesn't whine
There was a problem hiding this comment.
@evocateur how did I not know about path.normalize? I've been using path.sep all over the place in a ton of my repos.
There was a problem hiding this comment.
It's implicitly called behind the scenes when you use path.join() or path.resolve(), too, though for this purpose a direct normalize call seems appropriate.
|
@evocateur I've addressed your code review; I think all the suggestions were great, and things feel cleaner post refactoring. I've also added tests for the I've been testing against this repo. I'm really happy with how simple the workflow feels. |
|
I'm satisfied, let's hope Windows is too! Pretty excited for this, it's gonna make independent mode so much smoother. |
|
I'm hoping #635 helps iron out some of those flapping tests. Thanks for your patience with the path issues (try saying that six times fast)! |
|
@evocateur awesome 💃 thanks for your help on this, I can't wait to use this with |
|
Whoops, we forgot to update |
|
follow up in #676 |
|
FYI, I have created a task in Yarn where I aggregate the progress on Yarn workspaces and related PRs, RFC and discussions yarnpkg/yarn#3294 |
|
Thanks! |
|
This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Problem
Independent mode forces you to manually bump each package; it can be easy to lose track of whether versions are
major,minor,patch.Solution
Using a conventional-commit-format the git history can be parsed, and used to:
Notes
Please note that this functionality is optional, and is turned on by the flag
--conventional-commits.Todo
ConventionalCommitUtilties.js.addresses #662 (CC: @hzoo, @evocateur).