From 556056ab8eeaa07c52e17446424232df2b39b7bf Mon Sep 17 00:00:00 2001 From: Daniel Stockman <5605+evocateur@users.noreply.github.com> Date: Thu, 10 Dec 2020 10:48:59 -0800 Subject: [PATCH] refactor(child-process): Centralize ExecOpts type --- commands/diff/lib/get-last-commit.js | 4 ++-- commands/diff/lib/has-commit.js | 2 +- commands/publish/lib/get-current-sha.js | 2 +- commands/publish/lib/get-current-tags.js | 2 +- commands/publish/lib/get-tagged-packages.js | 2 +- commands/publish/lib/git-checkout.js | 2 +- core/child-process/index.js | 6 ++++++ core/command/index.js | 2 ++ core/filter-options/lib/get-filtered-packages.js | 2 +- utils/collect-updates/collect-updates.js | 2 +- utils/collect-updates/lib/has-tags.js | 2 +- utils/collect-updates/lib/make-diff-predicate.js | 4 ++-- 12 files changed, 20 insertions(+), 12 deletions(-) diff --git a/commands/diff/lib/get-last-commit.js b/commands/diff/lib/get-last-commit.js index de8911b567..d22144a9a5 100644 --- a/commands/diff/lib/get-last-commit.js +++ b/commands/diff/lib/get-last-commit.js @@ -6,7 +6,7 @@ const childProcess = require("@lerna/child-process"); module.exports.getLastCommit = getLastCommit; /** - * @param {{ cwd: string }} execOpts + * @param {import("@lerna/child-process").ExecOpts} execOpts */ function getLastCommit(execOpts) { if (hasTags(execOpts)) { @@ -20,7 +20,7 @@ function getLastCommit(execOpts) { } /** - * @param {{ cwd: string }} opts + * @param {import("@lerna/child-process").ExecOpts} opts */ function hasTags(opts) { let result = false; diff --git a/commands/diff/lib/has-commit.js b/commands/diff/lib/has-commit.js index 657553195f..c7488f1fa5 100644 --- a/commands/diff/lib/has-commit.js +++ b/commands/diff/lib/has-commit.js @@ -6,7 +6,7 @@ const childProcess = require("@lerna/child-process"); module.exports.hasCommit = hasCommit; /** - * @param {{ cwd: string }} opts + * @param {import("@lerna/child-process").ExecOpts} opts */ function hasCommit(opts) { log.silly("hasCommit"); diff --git a/commands/publish/lib/get-current-sha.js b/commands/publish/lib/get-current-sha.js index 67f09d129d..12c03ad3b1 100644 --- a/commands/publish/lib/get-current-sha.js +++ b/commands/publish/lib/get-current-sha.js @@ -7,7 +7,7 @@ module.exports.getCurrentSHA = getCurrentSHA; /** * Retrieve current SHA from git. - * @param {CommandExecOpts} opts + * @param {import("@lerna/child-process").ExecOpts} opts */ function getCurrentSHA(opts) { log.silly("getCurrentSHA"); diff --git a/commands/publish/lib/get-current-tags.js b/commands/publish/lib/get-current-tags.js index eb9dcb30aa..c666ed4587 100644 --- a/commands/publish/lib/get-current-tags.js +++ b/commands/publish/lib/get-current-tags.js @@ -8,7 +8,7 @@ module.exports.getCurrentTags = getCurrentTags; /** * Retrieve a list of git tags pointing to the current HEAD that match the provided pattern. - * @param {CommandExecOpts} execOpts + * @param {import("@lerna/child-process").ExecOpts} execOpts * @param {string} matchingPattern * @returns {string[]} */ diff --git a/commands/publish/lib/get-tagged-packages.js b/commands/publish/lib/get-tagged-packages.js index fcb0b1f65f..3d931cbee1 100644 --- a/commands/publish/lib/get-tagged-packages.js +++ b/commands/publish/lib/get-tagged-packages.js @@ -10,7 +10,7 @@ module.exports.getTaggedPackages = getTaggedPackages; * Retrieve a list of graph nodes for packages that were tagged in a non-independent release. * @param {import("@lerna/package-graph").PackageGraph} packageGraph * @param {string} rootPath - * @param {{ cwd: string }} execOpts + * @param {import("@lerna/child-process").ExecOpts} execOpts * @returns {Promise} */ function getTaggedPackages(packageGraph, rootPath, execOpts) { diff --git a/commands/publish/lib/git-checkout.js b/commands/publish/lib/git-checkout.js index 484757349f..303e43e58f 100644 --- a/commands/publish/lib/git-checkout.js +++ b/commands/publish/lib/git-checkout.js @@ -9,7 +9,7 @@ module.exports.gitCheckout = gitCheckout; * Reset files modified by publish steps. * @param {string[]} stagedFiles * @param {{ granularPathspec: boolean; }} gitOpts - * @param {CommandExecOpts} execOpts + * @param {import("@lerna/child-process").ExecOpts} execOpts */ function gitCheckout(stagedFiles, gitOpts, execOpts) { const files = gitOpts.granularPathspec ? stagedFiles : "."; diff --git a/core/child-process/index.js b/core/child-process/index.js index c1703fe385..d2cdeae938 100644 --- a/core/child-process/index.js +++ b/core/child-process/index.js @@ -138,3 +138,9 @@ exports.spawn = spawn; exports.spawnStreaming = spawnStreaming; exports.getChildProcessCount = getChildProcessCount; exports.getExitCode = getExitCode; + +/** + * @typedef {object} ExecOpts Provided to any execa-based call + * @property {string} cwd + * @property {number} [maxBuffer] + */ diff --git a/core/command/index.js b/core/command/index.js index d51731785e..6b1ae27ca4 100644 --- a/core/command/index.js +++ b/core/command/index.js @@ -178,6 +178,8 @@ class Command { this.concurrency = Math.max(1, +concurrency || DEFAULT_CONCURRENCY); this.toposort = sort === undefined || sort; + + /** @type {import("@lerna/child-process").ExecOpts} */ this.execOpts = { cwd: this.project.rootPath, maxBuffer, diff --git a/core/filter-options/lib/get-filtered-packages.js b/core/filter-options/lib/get-filtered-packages.js index 0ada2f5c0d..ef52b45e62 100644 --- a/core/filter-options/lib/get-filtered-packages.js +++ b/core/filter-options/lib/get-filtered-packages.js @@ -23,7 +23,7 @@ module.exports.getFilteredPackages = getFilteredPackages; /** * Retrieve a list of Package instances filtered by various options. * @param {import("@lerna/package-graph").PackageGraph} packageGraph - * @param {{ cwd: string }} execOpts + * @param {import("@lerna/child-process").ExecOpts} execOpts * @param {Partial} opts * @returns {Promise} */ diff --git a/utils/collect-updates/collect-updates.js b/utils/collect-updates/collect-updates.js index 36855a6ba2..353ed9364f 100644 --- a/utils/collect-updates/collect-updates.js +++ b/utils/collect-updates/collect-updates.js @@ -34,7 +34,7 @@ module.exports.getPackagesForOption = getPackagesForOption; * Create a list of graph nodes representing packages changed since the previous release, tagged or otherwise. * @param {import("@lerna/package").Package[]} filteredPackages * @param {import("@lerna/package-graph").PackageGraph} packageGraph - * @param {{ cwd: string }} execOpts + * @param {import("@lerna/child-process").ExecOpts} execOpts * @param {UpdateCollectorOptions} commandOptions */ function collectUpdates(filteredPackages, packageGraph, execOpts, commandOptions) { diff --git a/utils/collect-updates/lib/has-tags.js b/utils/collect-updates/lib/has-tags.js index 1d19ee8303..8f63cba894 100644 --- a/utils/collect-updates/lib/has-tags.js +++ b/utils/collect-updates/lib/has-tags.js @@ -7,7 +7,7 @@ module.exports.hasTags = hasTags; /** * Determine if any git tags are reachable. - * @param {{ cwd: string }} opts + * @param {import("@lerna/child-process").ExecOpts} opts */ function hasTags(opts) { log.silly("hasTags"); diff --git a/utils/collect-updates/lib/make-diff-predicate.js b/utils/collect-updates/lib/make-diff-predicate.js index 233ddd9b3a..592181e415 100644 --- a/utils/collect-updates/lib/make-diff-predicate.js +++ b/utils/collect-updates/lib/make-diff-predicate.js @@ -10,7 +10,7 @@ module.exports.makeDiffPredicate = makeDiffPredicate; /** * @param {string} committish - * @param {{ cwd: string }} execOpts + * @param {import("@lerna/child-process").ExecOpts} execOpts * @param {string[]} ignorePatterns */ function makeDiffPredicate(committish, execOpts, ignorePatterns = []) { @@ -60,7 +60,7 @@ function makeDiffPredicate(committish, execOpts, ignorePatterns = []) { /** * @param {string} committish * @param {string} location - * @param {{ cwd: string }} opts + * @param {import("@lerna/child-process").ExecOpts} opts */ function diffSinceIn(committish, location, opts) { const args = ["diff", "--name-only", committish];