Skip to content

Commit

Permalink
feat(filter-options): Rename --include-filtered-* options
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Oct 15, 2019
1 parent 73badee commit f2c3a92
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 27 deletions.
2 changes: 1 addition & 1 deletion commands/add/README.md
Expand Up @@ -21,7 +21,7 @@ If no `version` specifier is provided, it defaults to the `latest` dist-tag, jus

## Options

`lerna add` respects the `--ignore`, `--scope` and `--include-filtered-dependencies` flags (see [Filter Flags](https://www.npmjs.com/package/@lerna/filter-options)).
`lerna add` respects the `--ignore`, `--scope`, and `--include-dependencies` flags (see [Filter Flags](https://www.npmjs.com/package/@lerna/filter-options)).

### `--dev`

Expand Down
4 changes: 2 additions & 2 deletions commands/add/__tests__/add-command.test.js
Expand Up @@ -291,8 +291,8 @@ describe("AddCommand", () => {
private: undefined,
since: undefined,
excludeDependents: undefined,
includeFilteredDependents: undefined,
includeFilteredDependencies: undefined,
includeDependents: undefined,
includeDependencies: undefined,
})
);
});
Expand Down
4 changes: 2 additions & 2 deletions commands/add/index.js
Expand Up @@ -106,8 +106,8 @@ class AddCommand extends Command {
private: undefined,
since: undefined,
excludeDependents: undefined,
includeFilteredDependents: undefined,
includeFilteredDependencies: undefined,
includeDependents: undefined,
includeDependencies: undefined,
});

return bootstrap(argv);
Expand Down
2 changes: 1 addition & 1 deletion commands/bootstrap/README.md
Expand Up @@ -20,7 +20,7 @@ When run, this command will:
3. `npm run prepublish` in all bootstrapped packages (unless `--ignore-prepublish` is passed).
4. `npm run prepare` in all bootstrapped packages.

`lerna bootstrap` respects the `--ignore`, `--scope` and `--include-filtered-dependencies` flags (see [Filter Flags](https://www.npmjs.com/package/@lerna/filter-options)).
`lerna bootstrap` respects the `--ignore`, `--scope`, and `--include-dependencies` flags (see [Filter Flags](https://www.npmjs.com/package/@lerna/filter-options)).

Pass extra arguments to npm client by placing them after `--`:

Expand Down
8 changes: 4 additions & 4 deletions core/filter-options/README.md
Expand Up @@ -57,11 +57,11 @@ Exclude all transitive dependents when running a command with `--since`, overrid

This flag has no effect without `--since`, and will throw an error in that case.

### `--include-filtered-dependents`
### `--include-dependents`

Include all transitive dependents when running a command regardless of `--scope`, `--ignore`, or `--since`.

### `--include-filtered-dependencies`
### `--include-dependencies`

Include all transitive dependencies when running a command regardless of `--scope`, `--ignore`, or `--since`.

Expand All @@ -75,12 +75,12 @@ Ensures that all dependencies (and dev dependencies) of any scoped packages (eit
This is useful for situations where you want to "set up" a single package that relies on other packages being set up.

```sh
$ lerna bootstrap --scope my-component --include-filtered-dependencies
$ lerna bootstrap --scope my-component --include-dependencies
# my-component and all of its dependencies will be bootstrapped
```

```sh
$ lerna bootstrap --scope "package-*" --ignore "package-util-*" --include-filtered-dependencies
$ lerna bootstrap --scope "package-*" --ignore "package-util-*" --include-dependencies
# all packages matching "package-util-*" will be ignored unless they are
# depended upon by a package whose name matches "package-*"
```
14 changes: 7 additions & 7 deletions core/filter-options/__tests__/get-filtered-packages.test.js
Expand Up @@ -184,32 +184,32 @@ test("--exclude-dependents", async () => {
);
});

test("--exclude-dependents conflicts with --include-filtered-dependents", async () => {
test("--exclude-dependents conflicts with --include-dependents", async () => {
try {
parseOptions("--exclude-dependents", "--include-filtered-dependents");
parseOptions("--exclude-dependents", "--include-dependents");
} catch (err) {
expect(err.message).toMatch("exclude-dependents");
expect(err.message).toMatch("include-filtered-dependents");
expect(err.message).toMatch("include-dependents");
}

expect.hasAssertions();
});

test("--include-filtered-dependents", async () => {
test("--include-dependents", async () => {
const packageGraph = await buildGraph(cwd);
const execOpts = { cwd };
const options = parseOptions("--scope", "package-1", "--include-filtered-dependents");
const options = parseOptions("--scope", "package-1", "--include-dependents");

const result = await getFilteredPackages(packageGraph, execOpts, options);

expect(result.map(pkg => pkg.name)).toEqual(["package-1", "package-2", "package-5", "package-3"]);
expect(collectUpdates).not.toHaveBeenCalled();
});

test("--include-filtered-dependencies", async () => {
test("--include-dependencies", async () => {
const packageGraph = await buildGraph(cwd);
const execOpts = { cwd };
const options = parseOptions("--scope", "package-3", "--include-filtered-dependencies");
const options = parseOptions("--scope", "package-3", "--include-dependencies");

const result = await getFilteredPackages(packageGraph, execOpts, options);

Expand Down
44 changes: 40 additions & 4 deletions core/filter-options/index.js
@@ -1,5 +1,6 @@
"use strict";

const log = require("npmlog");
const dedent = require("dedent");
const getFilteredPackages = require("./lib/get-filtered-packages");

Expand Down Expand Up @@ -40,18 +41,18 @@ function filterOptions(yargs) {
Exclude all transitive dependents when running a command
with --since, overriding the default "changed" algorithm.
`,
conflicts: "include-filtered-dependents",
conflicts: "include-dependents",
type: "boolean",
},
"include-filtered-dependents": {
"include-dependents": {
describe: dedent`
Include all transitive dependents when running a command
regardless of --scope, --ignore, or --since.
`,
conflicts: "exclude-dependents",
type: "boolean",
},
"include-filtered-dependencies": {
"include-dependencies": {
describe: dedent`
Include all transitive dependencies when running a command
regardless of --scope, --ignore, or --since.
Expand All @@ -65,5 +66,40 @@ function filterOptions(yargs) {
},
};

return yargs.options(opts).group(Object.keys(opts), "Filter Options:");
return yargs
.options(opts)
.group(Object.keys(opts), "Filter Options:")
.option("include-filtered-dependents", {
// TODO: remove in next major release
hidden: true,
conflicts: ["exclude-dependents", "include-dependents"],
type: "boolean",
})
.option("include-filtered-dependencies", {
// TODO: remove in next major release
hidden: true,
conflicts: "include-dependencies",
type: "boolean",
})
.check(argv => {
/* eslint-disable no-param-reassign */
if (argv.includeFilteredDependents) {
argv.includeDependents = true;
argv["include-dependents"] = true;
delete argv.includeFilteredDependents;
delete argv["include-filtered-dependents"];
log.warn("deprecated", "--include-filtered-dependents has been renamed --include-dependents");
}

if (argv.includeFilteredDependencies) {
argv.includeDependencies = true;
argv["include-dependencies"] = true;
delete argv.includeFilteredDependencies;
delete argv["include-filtered-dependencies"];
log.warn("deprecated", "--include-filtered-dependencies has been renamed --include-dependencies");
}
/* eslint-enable no-param-reassign */

return argv;
});
}
14 changes: 8 additions & 6 deletions core/filter-options/lib/get-filtered-packages.js
Expand Up @@ -14,8 +14,10 @@ const FilterConfig = figgyPudding({
since: {},
continueIfNoMatch: {},
excludeDependents: {},
includeFilteredDependents: {},
includeFilteredDependencies: {},
includeDependents: {},
includeDependencies: {},
includeFilteredDependents: "includeDependents",
includeFilteredDependencies: "includeDependencies",
log: { default: npmlog },
});

Expand Down Expand Up @@ -58,14 +60,14 @@ function getFilteredPackages(packageGraph, execOpts, opts) {
);
}

if (options.includeFilteredDependents) {
options.log.notice("filter", "including filtered dependents");
if (options.includeDependents) {
options.log.notice("filter", "including dependents");

chain = chain.then(filteredPackages => packageGraph.addDependents(filteredPackages));
}

if (options.includeFilteredDependencies) {
options.log.notice("filter", "including filtered dependencies");
if (options.includeDependencies) {
options.log.notice("filter", "including dependencies");

chain = chain.then(filteredPackages => packageGraph.addDependencies(filteredPackages));
}
Expand Down
12 changes: 12 additions & 0 deletions core/project/lib/deprecate-config.js
Expand Up @@ -6,6 +6,18 @@ const path = require("path");

module.exports = compose(
// add new predicates HERE
remap("command.add.includeFilteredDependencies", "command.add.includeDependencies", { alsoRoot: true }),
remap("command.add.includeFilteredDependents", "command.add.includeDependents", { alsoRoot: true }),
remap("command.bootstrap.includeFilteredDependencies", "command.bootstrap.includeDependencies"),
remap("command.bootstrap.includeFilteredDependents", "command.bootstrap.includeDependents"),
remap("command.clean.includeFilteredDependencies", "command.clean.includeDependencies"),
remap("command.clean.includeFilteredDependents", "command.clean.includeDependents"),
remap("command.exec.includeFilteredDependencies", "command.exec.includeDependencies"),
remap("command.exec.includeFilteredDependents", "command.exec.includeDependents"),
remap("command.list.includeFilteredDependencies", "command.list.includeDependencies"),
remap("command.list.includeFilteredDependents", "command.list.includeDependents"),
remap("command.run.includeFilteredDependencies", "command.run.includeDependencies"),
remap("command.run.includeFilteredDependents", "command.run.includeDependents"),
remap("command.version.githubRelease", "command.version.createRelease", {
toValue: value => value && "github",
}),
Expand Down

0 comments on commit f2c3a92

Please sign in to comment.