From 65cafa0eec1df4635231bd7652727b12c2bc9bfa Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Sat, 3 Aug 2019 18:14:27 +0300 Subject: [PATCH] fix(docs-infra): correctly handle multiple occurrences of an option in `NgPackagesInstaller` (#31985) PR Close #31985 --- aio/tools/ng-packages-installer/index.js | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/aio/tools/ng-packages-installer/index.js b/aio/tools/ng-packages-installer/index.js index 0fbc9d9dce..5a27666686 100644 --- a/aio/tools/ng-packages-installer/index.js +++ b/aio/tools/ng-packages-installer/index.js @@ -38,9 +38,9 @@ class NgPackagesInstaller { * * `ignorePackages` (`string[]`) - a collection of names of packages that should not be copied over. */ constructor(projectDir, options = {}) { - this.debug = options.debug; - this.force = options.force; - this.buildPackages = options.buildPackages; + this.debug = this._parseBooleanArg(options.debug); + this.force = this._parseBooleanArg(options.force); + this.buildPackages = this._parseBooleanArg(options.buildPackages); this.ignorePackages = options.ignorePackages || []; this.projectDir = path.resolve(projectDir); this.localMarkerPath = path.resolve(this.projectDir, LOCAL_MARKER_PATH); @@ -264,6 +264,21 @@ class NgPackagesInstaller { } } + /** + * Extract the value for a boolean cli argument/option. When passing an option multiple times, `yargs` parses it as an + * array of boolean values. In that case, we only care about the last occurrence. + * + * This can be useful, for example, when one has a base command with the option turned on and another command + * (building on top of the first one) turning the option off: + * ``` + * "base-command": "my-script --foo --bar", + * "no-bar-command": "yarn base-command --no-bar", + * ``` + */ + _parseBooleanArg(value) { + return Array.isArray(value) ? value.pop() : value; + } + /** * Parse and return a `yarn.lock` file. */