Skip to content

Commit

Permalink
fix(command): Remove redundant filteredPackages calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Aug 20, 2018
1 parent 2e2abdc commit e0a361f
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 131 deletions.
94 changes: 0 additions & 94 deletions core/command/__tests__/command.test.js
Expand Up @@ -2,25 +2,17 @@

"use strict";

// we're actually testing integration with git
jest.unmock("@lerna/collect-updates");

const fs = require("fs-extra");
const execa = require("execa");
const log = require("npmlog");
const path = require("path");
const tempy = require("tempy");
const touch = require("touch");

// partially mocked
const ChildProcessUtilities = require("@lerna/child-process");

// helpers
const initFixture = require("@lerna-test/init-fixture")(__dirname);
const loggingOutput = require("@lerna-test/logging-output");
const gitAdd = require("@lerna-test/git-add");
const gitCommit = require("@lerna-test/git-commit");
const gitTag = require("@lerna-test/git-tag");
const updateLernaConfig = require("@lerna-test/update-lerna-config");

// file under test
Expand Down Expand Up @@ -232,92 +224,6 @@ describe("core-command", () => {
});
});

describe(".filteredPackages", () => {
it("--scope should filter packages", async () => {
const cwd = await initFixture("filtering");

const command = testFactory({
cwd,
scope: ["package-2", "package-4"],
});
await command;

expect(command.filteredPackages).toHaveLength(2);
expect(command.filteredPackages[0].name).toEqual("package-2");
expect(command.filteredPackages[1].name).toEqual("package-4");
});

it("--since should return all packages if no tag is found", async () => {
const cwd = await initFixture("filtering");

const command = testFactory({ cwd, since: "" });
await command;

expect(command.filteredPackages).toHaveLength(5);
});

it("--since should return packages updated since the last tag", async () => {
const cwd = await initFixture("filtering");

await gitTag(cwd, "v1.0.0");
await touch(path.join(cwd, "packages/package-2/random-file"));
await gitAdd(cwd, "-A");
await gitCommit(cwd, "test");

const command = testFactory({ cwd, since: "" });
await command;

expect(command.filteredPackages).toHaveLength(2);
expect(command.filteredPackages[0].name).toEqual("package-2");
expect(command.filteredPackages[1].name).toEqual("package-3");
});

it('--since "ref" should return packages updated since the specified ref', async () => {
const cwd = await initFixture("filtering");

// We first tag, then modify master to ensure that specifying --since will override checking against
// the latest tag.
await gitTag(cwd, "v1.0.0");

await touch(path.join(cwd, "packages/package-1/random-file"));
await gitAdd(cwd, "-A");
await gitCommit(cwd, "test");

// Then we can checkout a new branch, update and commit.
await execa("git", ["checkout", "-b", "test"], { cwd });

await touch(path.join(cwd, "packages/package-2/random-file"));
await gitAdd(cwd, "-A");
await gitCommit(cwd, "test");

const command = testFactory({ cwd, since: "master" });
await command;

expect(command.filteredPackages).toHaveLength(2);
expect(command.filteredPackages[0].name).toEqual("package-2");
expect(command.filteredPackages[1].name).toEqual("package-3");
});

it("should respect --scope and --since when used together", async () => {
const cwd = await initFixture("filtering");

await execa("git", ["checkout", "-b", "test"], { cwd });
await touch(path.join(cwd, "packages/package-4/random-file"));
await gitAdd(cwd, "-A");
await gitCommit(cwd, "test");

const command = testFactory({
cwd,
scope: ["package-2", "package-3", "package-4"],
since: "master",
});
await command;

expect(command.filteredPackages).toHaveLength(1);
expect(command.filteredPackages[0].name).toEqual("package-4");
});
});

describe(".options", () => {
class TestACommand extends Command {}
class TestBCommand extends Command {}
Expand Down
33 changes: 0 additions & 33 deletions core/command/index.js
Expand Up @@ -8,8 +8,6 @@ const log = require("npmlog");
const PackageGraph = require("@lerna/package-graph");
const Project = require("@lerna/project");
const writeLogFile = require("@lerna/write-log-file");
const collectUpdates = require("@lerna/collect-updates");
const filterPackages = require("@lerna/filter-packages");
const ValidationError = require("@lerna/validation-error");

const cleanStack = require("./lib/clean-stack");
Expand Down Expand Up @@ -207,39 +205,8 @@ class Command {
chain = chain.then(() => this.project.getPackages());
chain = chain.then(packages => {
this.packageGraph = new PackageGraph(packages);
this.filteredPackages = filterPackages(
packages,
this.options.scope,
this.options.ignore,
this.options.private
);
});

// collectUpdates requires that filteredPackages be present prior to checking for
// updates. That's okay because it further filters based on what's already been filtered.
if (this.options.since !== undefined) {
chain = chain.then(() =>
collectUpdates(this.filteredPackages, this.packageGraph, this.execOpts, this.options)
);
chain = chain.then(updates => {
const updated = new Set(updates.map(({ pkg }) => pkg.name));

this.filteredPackages = this.filteredPackages.filter(pkg => updated.has(pkg.name));
});
}

if (this.options.includeFilteredDependents) {
chain = chain.then(() => {
this.filteredPackages = this.packageGraph.addDependents(this.filteredPackages);
});
}

if (this.options.includeFilteredDependencies) {
chain = chain.then(() => {
this.filteredPackages = this.packageGraph.addDependencies(this.filteredPackages);
});
}

return chain;
}

Expand Down
2 changes: 0 additions & 2 deletions core/command/package.json
Expand Up @@ -32,8 +32,6 @@
},
"dependencies": {
"@lerna/child-process": "file:../child-process",
"@lerna/collect-updates": "file:../../utils/collect-updates",
"@lerna/filter-packages": "file:../../utils/filter-packages",
"@lerna/package-graph": "file:../package-graph",
"@lerna/project": "file:../project",
"@lerna/validation-error": "file:../validation-error",
Expand Down
2 changes: 0 additions & 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 e0a361f

Please sign in to comment.