Skip to content

Commit

Permalink
fix: Setup instance.filteredPackages explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Aug 20, 2018
1 parent e863c28 commit 32357f8
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 46 deletions.
6 changes: 6 additions & 0 deletions commands/add/index.js
Expand Up @@ -11,6 +11,7 @@ const Command = require("@lerna/command");
const npmConf = require("@lerna/npm-conf");
const bootstrap = require("@lerna/bootstrap");
const ValidationError = require("@lerna/validation-error");
const { getFilteredPackages } = require("@lerna/filter-options");
const getRangeToReference = require("./lib/get-range-to-reference");

module.exports = factory;
Expand Down Expand Up @@ -52,6 +53,11 @@ class AddCommand extends Command {
this.spec.version = version;
});

chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
chain = chain.then(filteredPackages => {
this.filteredPackages = filteredPackages;
});

chain = chain.then(() => this.collectPackagesToChange());
chain = chain.then(packagesToChange => {
this.packagesToChange = packagesToChange;
Expand Down
45 changes: 29 additions & 16 deletions commands/bootstrap/index.js
Expand Up @@ -20,6 +20,7 @@ const runParallelBatches = require("@lerna/run-parallel-batches");
const symlinkBinary = require("@lerna/symlink-binary");
const symlinkDependencies = require("@lerna/symlink-dependencies");
const ValidationError = require("@lerna/validation-error");
const { getFilteredPackages } = require("@lerna/filter-options");
const hasDependencyInstalled = require("./lib/has-dependency-installed");
const isHoistedPackage = require("./lib/is-hoisted-package");

Expand All @@ -35,9 +36,7 @@ class BootstrapCommand extends Command {
}

initialize() {
const { registry, rejectCycles, npmClient = "npm", npmClientArgs, mutex, hoist } = this.options;
const filteredLength = this.filteredPackages.length;
this.packageCountLabel = `${filteredLength} package${filteredLength > 1 ? "s" : ""}`;
const { registry, npmClient = "npm", npmClientArgs, mutex, hoist } = this.options;

if (npmClient === "yarn" && hoist) {
throw new ValidationError(
Expand Down Expand Up @@ -81,30 +80,44 @@ class BootstrapCommand extends Command {
this.npmConfig.npmClientArgs = [...(npmClientArgs || []), ...doubleDashArgs];
}

this.batchedPackages = this.toposort
? batchPackages(this.filteredPackages, rejectCycles)
: [this.filteredPackages];
let chain = Promise.resolve();

if (npmClient === "yarn" && !mutex) {
return getPort({ port: 42424, host: "0.0.0.0" }).then(port => {
this.npmConfig.mutex = `network:${port}`;
this.logger.silly("npmConfig", this.npmConfig);
});
}
chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
chain = chain.then(filteredPackages => {
this.filteredPackages = filteredPackages;
});

chain = chain.then(() => this.validatePackageNames());

chain = chain.then(() => {
this.batchedPackages = this.toposort
? batchPackages(this.filteredPackages, this.options.rejectCycles)
: [this.filteredPackages];

this.validatePackageNames();
if (npmClient === "yarn" && !mutex) {
return getPort({ port: 42424, host: "0.0.0.0" }).then(port => {
this.npmConfig.mutex = `network:${port}`;
this.logger.silly("npmConfig", this.npmConfig);
});
}

this.logger.silly("npmConfig", this.npmConfig);
});

this.logger.silly("npmConfig", this.npmConfig);
return chain;
}

execute() {
if (this.options.useWorkspaces || this.rootHasLocalFileDependencies()) {
return this.installRootPackageOnly();
}

const filteredLength = this.filteredPackages.length;
const packageCountLabel = `${filteredLength} package${filteredLength > 1 ? "s" : ""}`;

// root install does not need progress bar
this.enableProgressBar();
this.logger.info("", `Bootstrapping ${this.packageCountLabel}`);
this.logger.info("", `Bootstrapping ${packageCountLabel}`);

const tasks = [
() => this.getDependenciesToInstall(),
Expand All @@ -124,7 +137,7 @@ class BootstrapCommand extends Command {
}

return pWaterfall(tasks).then(() => {
this.logger.success("", `Bootstrapped ${this.packageCountLabel}`);
this.logger.success("", `Bootstrapped ${packageCountLabel}`);
});
}

Expand Down
28 changes: 18 additions & 10 deletions commands/clean/index.js
Expand Up @@ -6,6 +6,7 @@ const pMap = require("p-map");
const Command = require("@lerna/command");
const rimrafDir = require("@lerna/rimraf-dir");
const PromptUtilities = require("@lerna/prompt");
const { getFilteredPackages } = require("@lerna/filter-options");

module.exports = factory;

Expand All @@ -19,19 +20,26 @@ class CleanCommand extends Command {
}

initialize() {
this.directoriesToDelete = this.filteredPackages.map(pkg => pkg.nodeModulesLocation);
let chain = Promise.resolve();

if (this.options.yes) {
return true;
}
chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
chain = chain.then(filteredPackages => {
this.directoriesToDelete = filteredPackages.map(pkg => pkg.nodeModulesLocation);
});

return chain.then(() => {
if (this.options.yes) {
return true;
}

this.logger.info("", "Removing the following directories:");
this.logger.info(
"clean",
this.directoriesToDelete.map(dir => path.relative(this.project.rootPath, dir)).join("\n")
);
this.logger.info("", "Removing the following directories:");
this.logger.info(
"clean",
this.directoriesToDelete.map(dir => path.relative(this.project.rootPath, dir)).join("\n")
);

return PromptUtilities.confirm("Proceed?");
return PromptUtilities.confirm("Proceed?");
});
}

execute() {
Expand Down
19 changes: 14 additions & 5 deletions commands/exec/index.js
Expand Up @@ -5,6 +5,7 @@ const Command = require("@lerna/command");
const batchPackages = require("@lerna/batch-packages");
const runParallelBatches = require("@lerna/run-parallel-batches");
const ValidationError = require("@lerna/validation-error");
const { getFilteredPackages } = require("@lerna/filter-options");

module.exports = factory;

Expand All @@ -27,8 +28,6 @@ class ExecCommand extends Command {
throw new ValidationError("ENOCOMMAND", "A command to execute is required");
}

this.count = this.filteredPackages.length;

// inverted boolean options
this.bail = this.options.bail !== false;
this.prefix = this.options.prefix !== false;
Expand All @@ -37,9 +36,19 @@ class ExecCommand extends Command {
// so cache it here to reduce churn during tighter loops
this.env = Object.assign({}, process.env);

this.batchedPackages = this.toposort
? batchPackages(this.filteredPackages, this.options.rejectCycles)
: [this.filteredPackages];
let chain = Promise.resolve();

chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
chain = chain.then(filteredPackages => {
this.filteredPackages = filteredPackages;
});

return chain.then(() => {
this.count = this.filteredPackages.length;
this.batchedPackages = this.toposort
? batchPackages(this.filteredPackages, this.options.rejectCycles)
: [this.filteredPackages];
});
}

execute() {
Expand Down
10 changes: 9 additions & 1 deletion commands/list/index.js
Expand Up @@ -3,6 +3,7 @@
const Command = require("@lerna/command");
const listable = require("@lerna/listable");
const output = require("@lerna/output");
const { getFilteredPackages } = require("@lerna/filter-options");

module.exports = factory;

Expand All @@ -16,7 +17,14 @@ class ListCommand extends Command {
}

initialize() {
this.result = listable.format(this.filteredPackages, this.options);
let chain = Promise.resolve();

chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
chain = chain.then(filteredPackages => {
this.result = listable.format(filteredPackages, this.options);
});

return chain;
}

execute() {
Expand Down
35 changes: 21 additions & 14 deletions commands/run/index.js
Expand Up @@ -8,6 +8,7 @@ const batchPackages = require("@lerna/batch-packages");
const runParallelBatches = require("@lerna/run-parallel-batches");
const output = require("@lerna/output");
const ValidationError = require("@lerna/validation-error");
const { getFilteredPackages } = require("@lerna/filter-options");

module.exports = factory;

Expand Down Expand Up @@ -35,24 +36,30 @@ class RunCommand extends Command {
this.bail = this.options.bail !== false;
this.prefix = this.options.prefix !== false;

if (script === "env") {
this.packagesWithScript = this.filteredPackages;
} else {
this.packagesWithScript = this.filteredPackages.filter(pkg => pkg.scripts && pkg.scripts[script]);
}
let chain = Promise.resolve();

chain = chain.then(() => getFilteredPackages(this.packageGraph, this.execOpts, this.options));
chain = chain.then(filteredPackages => {
this.packagesWithScript =
script === "env"
? filteredPackages
: filteredPackages.filter(pkg => pkg.scripts && pkg.scripts[script]);
});

this.count = this.packagesWithScript.length;
return chain.then(() => {
this.count = this.packagesWithScript.length;

if (!this.count) {
this.logger.success("run", `No packages found with the lifecycle script '${script}'`);
if (!this.count) {
this.logger.success("run", `No packages found with the lifecycle script '${script}'`);

// still exits zero, aka "ok"
return false;
}
// still exits zero, aka "ok"
return false;
}

this.batchedPackages = this.toposort
? batchPackages(this.packagesWithScript, this.options.rejectCycles)
: [this.packagesWithScript];
this.batchedPackages = this.toposort
? batchPackages(this.packagesWithScript, this.options.rejectCycles)
: [this.packagesWithScript];
});
}

execute() {
Expand Down

0 comments on commit 32357f8

Please sign in to comment.