Skip to content

Commit

Permalink
fix(changed): Copy relevant options from version, do not inherit
Browse files Browse the repository at this point in the history
Among them, `--include-merged-tags` is significant.
  • Loading branch information
evocateur committed Nov 8, 2019
1 parent 287bcd8 commit 6bd77ba
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 10 deletions.
6 changes: 3 additions & 3 deletions commands/changed/README.md
Expand Up @@ -31,9 +31,9 @@ package-2

Unlike `lerna ls`, however, `lerna changed` **does not** support [filter options](https://www.npmjs.com/package/@lerna/filter-options), as filtering is not supported by `lerna version` or `lerna publish`.

`lerna changed` also supports all the flags supported by [`lerna version`](https://github.com/lerna/lerna/tree/master/commands/version#options).

Relevant ones are maybe:
`lerna changed` supports the following options of [`lerna version`](https://github.com/lerna/lerna/tree/master/commands/version#options) (the others are irrelevant):

- [`--conventional-graduate`](https://github.com/lerna/lerna/tree/master/commands/version#--conventional-graduate).
- [`--force-publish`](https://github.com/lerna/lerna/tree/master/commands/version#--force-publish).
- [`--ignore-changes`](https://github.com/lerna/lerna/tree/master/commands/version#--ignore-changes).
- [`--include-merged-tags`](https://github.com/lerna/lerna/tree/master/commands/version#--include-merged-tags).
30 changes: 30 additions & 0 deletions commands/changed/__tests__/changed-command.test.js
Expand Up @@ -6,6 +6,7 @@ const output = require("@lerna/output");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const loggingOutput = require("@lerna-test/logging-output");
const updateLernaConfig = require("@lerna-test/update-lerna-config");

// file under test
Expand Down Expand Up @@ -90,6 +91,35 @@ package-4
);
});

it("passes --include-merged-tags to update collector", async () => {
await lernaChanged(cwd)("--include-merged-tags");

expect(collectUpdates).toHaveBeenLastCalledWith(
expect.any(Array),
expect.any(Object),
expect.objectContaining({ cwd }),
expect.objectContaining({ includeMergedTags: true })
);
});

it("passes --conventional-graduate to update collector", async () => {
await lernaChanged(cwd)("--conventional-graduate=*");

expect(collectUpdates).toHaveBeenLastCalledWith(
expect.any(Array),
expect.any(Object),
expect.objectContaining({ cwd }),
expect.objectContaining({ conventionalGraduate: "*", conventionalCommits: true })
);
});

it("warns when --force-publish superseded by --conventional-graduate", async () => {
await lernaChanged(cwd)("--conventional-graduate", "foo", "--force-publish", "bar");

const [logMessage] = loggingOutput("warn");
expect(logMessage).toBe("--force-publish superseded by --conventional-graduate");
});

it("lists changed private packages with --all", async () => {
collectUpdates.setUpdated(cwd, "package-5");

Expand Down
33 changes: 30 additions & 3 deletions commands/changed/command.js
@@ -1,6 +1,5 @@
"use strict";

const versionOptions = require("@lerna/version/command").builder;
const listable = require("@lerna/listable");

/**
Expand All @@ -13,9 +12,37 @@ exports.aliases = ["updated"];
exports.describe = "List local packages that have changed since the last tagged release";

exports.builder = yargs => {
listable.options(yargs);
const opts = {
// only the relevant bits from `lerna version`
"conventional-commits": {
// fallback for overzealous --conventional-graduate
hidden: true,
type: "boolean",
},
"conventional-graduate": {
describe: "Detect currently prereleased packages that would change to a non-prerelease version.",
// type must remain ambiguous because it is overloaded (boolean _or_ string _or_ array)
},
"force-publish": {
describe: "Always include targeted packages when detecting changed packages, skipping default logic.",
// type must remain ambiguous because it is overloaded (boolean _or_ string _or_ array)
},
"ignore-changes": {
describe: [
"Ignore changes in files matched by glob(s) when detecting changed packages.",
"Pass --no-ignore-changes to completely disable.",
].join("\n"),
type: "array",
},
"include-merged-tags": {
describe: "Include tags from merged branches when detecting changed packages.",
type: "boolean",
},
};

return versionOptions(yargs, "changed");
yargs.options(opts).group(Object.keys(opts), "Command Options:");

return listable.options(yargs, "Output Options:");
};

exports.handler = function handler(argv) {
Expand Down
9 changes: 9 additions & 0 deletions commands/changed/index.js
Expand Up @@ -18,6 +18,15 @@ class ChangedCommand extends Command {
}

initialize() {
if (this.options.conventionalGraduate) {
// provide artificial --conventional-commits so --conventional-graduate works
this.options.conventionalCommits = true;

if (this.options.forcePublish) {
this.logger.warn("option", "--force-publish superseded by --conventional-graduate");
}
}

const updates = collectUpdates(
this.packageGraph.rawPackageList,
this.packageGraph,
Expand Down
3 changes: 1 addition & 2 deletions commands/changed/package.json
Expand Up @@ -35,7 +35,6 @@
"@lerna/collect-updates": "file:../../utils/collect-updates",
"@lerna/command": "file:../../core/command",
"@lerna/listable": "file:../../utils/listable",
"@lerna/output": "file:../../utils/output",
"@lerna/version": "file:../version"
"@lerna/output": "file:../../utils/output"
}
}
3 changes: 1 addition & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6bd77ba

Please sign in to comment.