Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@lerna/conventional-commits unable to use conventional-changelog-conventionalcommits #2138

Closed
MunifTanjim opened this issue Jun 17, 2019 · 11 comments · Fixed by #2546
Closed

Comments

@MunifTanjim
Copy link
Contributor

Expected Behavior

Should be able to run

$ lerna version prerelease`

with the config

{
  "command": {
    "version": {
      "conventionalCommits": true,
      "changelogPreset": "conventional-changelog-conventionalcommits",
    }
  }
}

successfully.

Current Behavior

It terminates without any error message:

[munif:/<dir>/<repo>] master ± lerna version prerelease --yes --loglevel=silly -m "chore: msg"
lerna sill argv { _: [ 'version' ],
lerna sill argv   yes: true,
lerna sill argv   y: true,
lerna sill argv   loglevel: 'silly',
lerna sill argv   m: 'chore: msg',
lerna sill argv   message: 'chore: msg',
lerna sill argv   lernaVersion: '3.13.4',
lerna sill argv   '$0': 'node_modules/.bin/lerna',
lerna sill argv   bump: 'prerelease' }
lerna notice cli v3.13.4
lerna verb rootPath /<dir>/<repo>
lerna info versioning independent
lerna sill isAnythingCommitted 
lerna verb isAnythingCommitted 1
lerna sill currentBranch 
lerna verb currentBranch master
lerna sill hasTags 
lerna verb hasTags false
lerna info Assuming all packages changed
lerna verb updated @<scope>/<pkg1>
lerna verb updated @<scope>/<pkg2>
lerna verb updated @<scope>/<pkg3>
lerna info version Skipping unversioned private package "@<scope>/<pkg3>"
lerna verb git-describe undefined => "5b18165"
lerna sill git-describe parsed => {"refCount":"7","sha":"5b18165","isDirty":false}
lerna sill batched [ PackageGraphNode {
lerna sill batched     name: '@<scope>/<pkg1>',
lerna sill batched     externalDependencies: Map { '<dep>' => [Object] },
lerna sill batched     localDependencies: Map {},
lerna sill batched     localDependents: Map { '@<scope>/<pkg2>' => [PackageGraphNode] } } ]
lerna sill batched [ PackageGraphNode {
lerna sill batched     name: '@<scope>/<pkg2>',
lerna sill batched     externalDependencies: Map {},
lerna sill batched     localDependencies: Map {},
lerna sill batched     localDependents: Map {} } ]

Changes:
 - @<scope>/<pkg1>: 0.0.0 => 0.0.1-alpha.0
 - @<scope>/<pkg2>: 0.0.0 => 0.0.1-alpha.0

lerna info auto-confirmed 
lerna info execute Skipping git push
lerna info execute Skipping GitHub releases
lerna sill lifecycle No script for "preversion" in "<repo>", continuing
lerna sill lifecycle No script for "preversion" in "@<scope>/<pkg1>", continuing
lerna sill lifecycle No script for "version" in "@<scope>/<pkg1>", continuing
lerna sill independent for @<scope>/<pkg1> at /<dir>/<repo>/packages/<pkg1>
lerna verb getChangelogConfig using preset "conventional-changelog-conventionalcommits"
lerna sill npa { type: 'tag',
lerna sill npa   registry: true,
lerna sill npa   where: undefined,
lerna sill npa   raw: 'conventional-changelog-conventionalcommits',
lerna sill npa   name: 'conventional-changelog-conventionalcommits',
lerna sill npa   escapedName: 'conventional-changelog-conventionalcommits',
lerna sill npa   scope: undefined,
lerna sill npa   rawSpec: '',
lerna sill npa   saveSpec: null,
lerna sill npa   fetchSpec: 'latest',
lerna sill npa   gitRange: undefined,
lerna sill npa   gitCommittish: undefined,
lerna sill npa   hosted: undefined }
lerna verb getChangelogConfig Attempting to resolve preset "conventional-changelog-conventionalcommits"
lerna info getChangelogConfig Successfully resolved preset "conventional-changelog-conventionalcommits"

It just bumps the version on package.json, does nothing else.

Possible Solution

Related to this commit: conventional-changelog/conventional-changelog@f2fb240

Specially this file: conventional-changelog/conventional-changelog@f2fb240#diff-b79ed7f48102a253b716fdde8b9fbcb7

It introduces some new logic to load the presets. But lerna probably uses it's own custom implementation. 🤔

Context

Wanted to use conventional-changelog-conventionalcommits as command.version.changelogPreset.

Executable Version
lerna --version 3.13, 3.14, 3.15
@michaelwittwer
Copy link

Same issue here.

Steps to reproduce:
run npx lerna version --conventional-commits --changelog-preset conventionalcommits

lerna notice cli v3.15.0
lerna info versioning independent
lerna info Looking for changed packages since @shiftcoders/build-helper@1.1.2
lerna info getChangelogConfig Auto-prefixing conventional-changelog preset "conventionalcommits"
lerna info getChangelogConfig Successfully resolved preset "conventional-changelog-conventionalcommits"

It exits after this line, but the changelog config will never be loaded. (when running with --changelog-preset angular it completes successfully) This is because conventional-changelog-conventionalcommits returns a function instead of an object like conventional-changelog-angular for example.

So this legacy behavior of lerna will fail:

// legacy presets export an errback function instead of Q.all()
if (isFunction(config)) {
  console.log('isFunction')
  config = pify(config)();
}

check here to see how the conventional-changelog-preset-loader was updated.

Maybe the legacy behavior can be removed in favor of the new one. Don't have enough insights to have an opinion on that.
For now it would be great to update the loader to successfully load the config preset, for the future we should think about a new argument (maybe --changelog-config) to be able to actually provide a config when needed.

@evocateur
Copy link
Member

At the time I wrote lerna's preset loader, there wasn't one in conventional-commits yet. We should probably use conventional-changelog-preset-loader somehow.

@antl3x
Copy link

antl3x commented Sep 4, 2019

So we are not able to use conventionalcommits preset?

@thuringia
Copy link

So we are not able to use conventionalcommits preset?

That's right. Unfortunately Lerna is also not creating the changelog correctly even if you use the Angular convention.

@evocateur Could we change the preset loader to use the "conventional" preset in the mean time as a quick win? Changing it to be configurable sounds like some more involved work

@evocateur
Copy link
Member

The preset loader should be fixed, not arbitrarily changed to a different default.

@thuringia
Copy link

I took a look at how the preset loader works internally, but it is quite a bit more complex than I anticipated. Hence my thought of changing the preset as a quick-win.
Obviously, fixing the issue is preferable, to just changing the default

@evocateur
Copy link
Member

I've verified that conventional-changelog-conventionalcommits@next (v4.2.1) currently works with lerna's config loader, no changes necessary.

diff --git a/core/conventional-commits/__tests__/conventional-commits.test.js b/core/conventional-commits/__tests__/conventional-commits.test.js
index 60c8e091..9020a10d 100644
--- a/core/conventional-commits/__tests__/conventional-commits.test.js
+++ b/core/conventional-commits/__tests__/conventional-commits.test.js
@@ -131,6 +131,21 @@ describe("conventional-commits", () => {
       expect(bump).toBe("1.1.0");
     });
 
+    it("supports conventionalcommits preset", async () => {
+      const cwd = await initFixture("fixed");
+      const [pkg1] = await getPackages(cwd);
+
+      // make a change in package-1
+      await pkg1.set("changed", 1).serialize();
+      await gitAdd(cwd, pkg1.manifestLocation);
+      await gitCommit(cwd, "feat!: drop it like it's hot");
+
+      const bump = await recommendVersion(pkg1, "fixed", {
+        changelogPreset: "conventionalcommits",
+      });
+      expect(bump).toBe("2.0.0");
+    });
+
     it("supports custom tagPrefix in fixed mode", async () => {
       const cwd = await initFixture("fixed");
 
diff --git a/package-lock.json b/package-lock.json
index 284b70f9..1208913f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2400,6 +2400,17 @@
         "q": "^1.5.1"
       }
     },
+    "conventional-changelog-conventionalcommits": {
+      "version": "4.2.1",
+      "resolved": "https://registry.npmjs.org/conventional-changelog-conventionalcommits/-/conventional-changelog-conventionalcommits-4.2.1.tgz",
+      "integrity": "sha512-vC02KucnkNNap+foDKFm7BVUSDAXktXrUJqGszUuYnt6T0J2azsbYz/w9TDc3VsrW2v6JOtiQWVcgZnporHr4Q==",
+      "dev": true,
+      "requires": {
+        "compare-func": "^1.3.1",
+        "lodash": "^4.2.1",
+        "q": "^1.5.1"
+      }
+    },
     "conventional-changelog-core": {
       "version": "3.2.2",
       "resolved": "https://registry.npmjs.org/conventional-changelog-core/-/conventional-changelog-core-3.2.2.tgz",
diff --git a/package.json b/package.json
index 9b9f9fa5..03580ca8 100644
--- a/package.json
+++ b/package.json
@@ -59,6 +59,7 @@
     "@lerna-test/update-lerna-config": "file:helpers/update-lerna-config",
     "@zkochan/cmd-shim": "^3.1.0",
     "camelcase": "^5.3.1",
+    "conventional-changelog-conventionalcommits": "^4.2.1",
     "debug": "^4.1.1",
     "eslint": "^5.16.0",
     "eslint-config-airbnb-base": "^13.2.0",

@evocateur
Copy link
Member

upstream fix: conventional-changelog/conventional-changelog#521

@ntucker
Copy link

ntucker commented Nov 17, 2019

If I get rid of this:

if (config.conventionalChangelog) {

it makes it work. Why is lerna trying to ruin the config output by conventional-changelog itself?

@jccr
Copy link

jccr commented Feb 11, 2020

If I get rid of this:

if (config.conventionalChangelog) {

it makes it work. Why is lerna trying to ruin the config output by conventional-changelog itself?

It's true.. I'm not getting the expected output from the convetionalcommits preset until I force the "old" preset API branch to execute.

I'm getting some changelog output, but it's not presented with the proper sections/headings.
I'm not seeing ### ⚠ BREAKING CHANGES or ### Features or ### Bug Fixes or ### Code Refactoring. I'm just seeing a flat (naive) list of commits.

@bertho-zero
Copy link

@jccr It's due to this bug: conventional-changelog/conventional-changelog#618

MunifTanjim added a commit to MunifTanjim/lerna that referenced this issue Apr 17, 2020
MunifTanjim added a commit to MunifTanjim/lerna that referenced this issue Apr 17, 2020
evocateur pushed a commit that referenced this issue May 24, 2020
…2546)

This enables `conventional-changelog-conventionalcommits` via `--changelog-preset`.

Fixes #2138
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants