From b811ad767fbea98f502dcf94abd7103cbde22b61 Mon Sep 17 00:00:00 2001 From: Bucky Maler Date: Sun, 7 Jul 2019 01:26:40 -0500 Subject: [PATCH] fix(nx): npm scripts documentation generation Before, a single instance of yargs was accumulating options, so commands parsed later would have options from prior commands. That's because all yargs options are global by default. Now, a new instance of yargs is required before each command is parsed, so global options aren't accumulated. fixes #1567 --- .../api-workspace/npmscripts/affected-apps.md | 14 ----- .../npmscripts/affected-build.md | 2 - .../npmscripts/affected-dep-graph.md | 14 ----- docs/api-workspace/npmscripts/affected-e2e.md | 14 ----- .../api-workspace/npmscripts/affected-libs.md | 14 ----- .../api-workspace/npmscripts/affected-lint.md | 6 -- .../api-workspace/npmscripts/affected-test.md | 2 - docs/api-workspace/npmscripts/affected.md | 2 - docs/api-workspace/npmscripts/dep-graph.md | 14 ----- docs/api-workspace/npmscripts/format-check.md | 18 ------ docs/api-workspace/npmscripts/format-write.md | 18 ------ .../npmscripts/workspace-lint-files.md | 60 ------------------- .../npmscripts/workspace-schematic-name.md | 60 ------------------- package.json | 1 + .../documentation/generate-npmscripts-data.ts | 5 +- yarn.lock | 20 +++++++ 16 files changed, 24 insertions(+), 240 deletions(-) diff --git a/docs/api-workspace/npmscripts/affected-apps.md b/docs/api-workspace/npmscripts/affected-apps.md index a29eaa2e5dcd8f..c412a69d8fc4c0 100644 --- a/docs/api-workspace/npmscripts/affected-apps.md +++ b/docs/api-workspace/npmscripts/affected-apps.md @@ -36,26 +36,12 @@ Latest commit of the current branch (usually HEAD) Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - ### only-failed Default: `false` Isolate projects which previously failed -### parallel - -Default: `false` - -Parallelize the command - -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/affected-build.md b/docs/api-workspace/npmscripts/affected-build.md index c77628be10cc23..21b0ee5cafe794 100644 --- a/docs/api-workspace/npmscripts/affected-build.md +++ b/docs/api-workspace/npmscripts/affected-build.md @@ -54,8 +54,6 @@ Default: `false` Parallelize the command -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/affected-dep-graph.md b/docs/api-workspace/npmscripts/affected-dep-graph.md index 3b94b748afc4b2..e7b8f8ea279a0c 100644 --- a/docs/api-workspace/npmscripts/affected-dep-graph.md +++ b/docs/api-workspace/npmscripts/affected-dep-graph.md @@ -40,26 +40,12 @@ Latest commit of the current branch (usually HEAD) Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - ### only-failed Default: `false` Isolate projects which previously failed -### parallel - -Default: `false` - -Parallelize the command - -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/affected-e2e.md b/docs/api-workspace/npmscripts/affected-e2e.md index 67197a33b1f466..d744ef6ff61c22 100644 --- a/docs/api-workspace/npmscripts/affected-e2e.md +++ b/docs/api-workspace/npmscripts/affected-e2e.md @@ -36,26 +36,12 @@ Latest commit of the current branch (usually HEAD) Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - ### only-failed Default: `false` Isolate projects which previously failed -### parallel - -Default: `false` - -Parallelize the command - -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/affected-libs.md b/docs/api-workspace/npmscripts/affected-libs.md index 2de64d1053a70f..68225c83c1769a 100644 --- a/docs/api-workspace/npmscripts/affected-libs.md +++ b/docs/api-workspace/npmscripts/affected-libs.md @@ -36,26 +36,12 @@ Latest commit of the current branch (usually HEAD) Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - ### only-failed Default: `false` Isolate projects which previously failed -### parallel - -Default: `false` - -Parallelize the command - -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/affected-lint.md b/docs/api-workspace/npmscripts/affected-lint.md index d00d6a7d338504..f3e4f93b5dcdfc 100644 --- a/docs/api-workspace/npmscripts/affected-lint.md +++ b/docs/api-workspace/npmscripts/affected-lint.md @@ -24,10 +24,6 @@ Default: `` Exclude certain projects from being processed -### file - -output file (e.g. --file=.vis/output.json) - ### files A list of files delimited by commas @@ -58,8 +54,6 @@ Default: `false` Parallelize the command -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/affected-test.md b/docs/api-workspace/npmscripts/affected-test.md index d38fe654751ed1..e5fe986a2ce613 100644 --- a/docs/api-workspace/npmscripts/affected-test.md +++ b/docs/api-workspace/npmscripts/affected-test.md @@ -54,8 +54,6 @@ Default: `false` Parallelize the command -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/affected.md b/docs/api-workspace/npmscripts/affected.md index e21e2cffae1a44..f5178c6d1954a6 100644 --- a/docs/api-workspace/npmscripts/affected.md +++ b/docs/api-workspace/npmscripts/affected.md @@ -54,8 +54,6 @@ Default: `false` Parallelize the command -### quiet - ### target Task to run for affected projects diff --git a/docs/api-workspace/npmscripts/dep-graph.md b/docs/api-workspace/npmscripts/dep-graph.md index 556fe7dfc8a2e5..0673edccf2a8f0 100644 --- a/docs/api-workspace/npmscripts/dep-graph.md +++ b/docs/api-workspace/npmscripts/dep-graph.md @@ -40,26 +40,12 @@ Latest commit of the current branch (usually HEAD) Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - ### only-failed Default: `false` Isolate projects which previously failed -### parallel - -Default: `false` - -Parallelize the command - -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/format-check.md b/docs/api-workspace/npmscripts/format-check.md index 76188acf7a741d..572843415035ff 100644 --- a/docs/api-workspace/npmscripts/format-check.md +++ b/docs/api-workspace/npmscripts/format-check.md @@ -26,10 +26,6 @@ Default: `` Exclude certain projects from being processed -### file - -output file (e.g. --file=.vis/output.json) - ### files A list of files delimited by commas @@ -42,26 +38,12 @@ Latest commit of the current branch (usually HEAD) Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - ### only-failed Default: `false` Isolate projects which previously failed -### parallel - -Default: `false` - -Parallelize the command - -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/format-write.md b/docs/api-workspace/npmscripts/format-write.md index 9cbbf377941e4d..259c22c9c42f3a 100644 --- a/docs/api-workspace/npmscripts/format-write.md +++ b/docs/api-workspace/npmscripts/format-write.md @@ -26,10 +26,6 @@ Default: `` Exclude certain projects from being processed -### file - -output file (e.g. --file=.vis/output.json) - ### files A list of files delimited by commas @@ -42,26 +38,12 @@ Latest commit of the current branch (usually HEAD) Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - ### only-failed Default: `false` Isolate projects which previously failed -### parallel - -Default: `false` - -Parallelize the command - -### quiet - ### uncommitted Uncommitted changes diff --git a/docs/api-workspace/npmscripts/workspace-lint-files.md b/docs/api-workspace/npmscripts/workspace-lint-files.md index 44cf887c1e721a..637d825753608d 100644 --- a/docs/api-workspace/npmscripts/workspace-lint-files.md +++ b/docs/api-workspace/npmscripts/workspace-lint-files.md @@ -10,70 +10,10 @@ workspace-lint [files..] ## Options -### all - -All projects - -### apps-and-libs - -### base - -Base of the current branch (usually master) - -### exclude - -Default: `` - -Exclude certain projects from being processed - -### file - -output file (e.g. --file=.vis/output.json) - -### files - -A list of files delimited by commas - -### head - -Latest commit of the current branch (usually HEAD) - ### help Show help -### maxParallel - -Default: `3` - -Max number of parallel processes - -### only-failed - -Default: `false` - -Isolate projects which previously failed - -### parallel - -Default: `false` - -Parallelize the command - -### quiet - -### uncommitted - -Uncommitted changes - -### untracked - -Untracked changes - -### verbose - -Print additional error stack trace on failure - ### version Show version number diff --git a/docs/api-workspace/npmscripts/workspace-schematic-name.md b/docs/api-workspace/npmscripts/workspace-schematic-name.md index 6706799be8871e..c9b3407b70517f 100644 --- a/docs/api-workspace/npmscripts/workspace-schematic-name.md +++ b/docs/api-workspace/npmscripts/workspace-schematic-name.md @@ -10,34 +10,6 @@ workspace-schematic [name] ## Options -### all - -All projects - -### apps-and-libs - -### base - -Base of the current branch (usually master) - -### exclude - -Default: `` - -Exclude certain projects from being processed - -### file - -output file (e.g. --file=.vis/output.json) - -### files - -A list of files delimited by commas - -### head - -Latest commit of the current branch (usually HEAD) - ### help Show help @@ -46,42 +18,10 @@ Show help List the available workspace-schematics -### maxParallel - -Default: `3` - -Max number of parallel processes - ### name The name of your schematic` -### only-failed - -Default: `false` - -Isolate projects which previously failed - -### parallel - -Default: `false` - -Parallelize the command - -### quiet - -### uncommitted - -Uncommitted changes - -### untracked - -Untracked changes - -### verbose - -Print additional error stack trace on failure - ### version Show version number diff --git a/package.json b/package.json index 8051701ae69fbd..2aeeac71ee7096 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "husky": "^1.0.0-rc.13", "identity-obj-proxy": "3.0.0", "ignore": "^5.0.4", + "import-fresh": "^3.1.0", "jasmine-core": "~2.99.1", "jasmine-marbles": "~0.5.0", "jasmine-spec-reporter": "~4.2.1", diff --git a/scripts/documentation/generate-npmscripts-data.ts b/scripts/documentation/generate-npmscripts-data.ts index dffc19c3a3bbee..05e938d7aa6988 100644 --- a/scripts/documentation/generate-npmscripts-data.ts +++ b/scripts/documentation/generate-npmscripts-data.ts @@ -1,11 +1,12 @@ import * as fs from 'fs-extra'; -import * as yargs from 'yargs'; import * as path from 'path'; import { dedent } from 'tslint/lib/utils'; import { generateFile, sortAlphabeticallyFunction } from './utils'; import { commandsObject } from '../../packages/workspace'; +const importFresh = require('import-fresh'); + const commandsOutputDirectory = path.join( __dirname, '../../docs/api-workspace/npmscripts' @@ -15,7 +16,7 @@ function getCommands(command) { return command.getCommandInstance().getCommandHandlers(); } function parseCommandInstance(name, command) { - const builder = command.builder((yargs).resetOptions()); + const builder = command.builder(importFresh('yargs')().resetOptions()); const builderDescriptions = builder.getUsageInstance().getDescriptions(); const builderDefaultOptions = builder.getOptions().default; return { diff --git a/yarn.lock b/yarn.lock index c2efe6e2e3422c..1617cbb0ac5afe 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6841,6 +6841,14 @@ import-fresh@^2.0.0: caller-path "^2.0.0" resolve-from "^3.0.0" +import-fresh@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/import-fresh/-/import-fresh-3.1.0.tgz#6d33fa1dcef6df930fae003446f33415af905118" + integrity sha512-PpuksHKGt8rXfWEr9m9EHIpgyyaltBy8+eF6GJM0QCAxMgxCfucMF3mjecK2QsJr0amJW7gTqh5/wht0z2UhEQ== + dependencies: + parent-module "^1.0.0" + resolve-from "^4.0.0" + import-from@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/import-from/-/import-from-2.1.0.tgz#335db7f2a7affd53aaa471d4b8021dee36b7f3b1" @@ -10030,6 +10038,13 @@ param-case@2.1.x: dependencies: no-case "^2.2.0" +parent-module@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/parent-module/-/parent-module-1.0.1.tgz#691d2709e78c79fae3a156622452d00762caaaa2" + integrity sha512-GQ2EWRpQV8/o+Aw8YqtfZZPfNRWZYkbidE9k5rpl/hC3vtHHBfGm2Ifi6qWV+coDGkrUKZAxE3Lot5kcsRlh+g== + dependencies: + callsites "^3.0.0" + parse-asn1@^5.0.0: version "5.1.4" resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.4.tgz#37f6628f823fbdeb2273b4d540434a22f3ef1fcc" @@ -11183,6 +11198,11 @@ resolve-from@^3.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-3.0.0.tgz#b22c7af7d9d6881bc8b6e653335eebcb0a188748" integrity sha1-six699nWiBvItuZTM17rywoYh0g= +resolve-from@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6" + integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g== + resolve-url@^0.2.1: version "0.2.1" resolved "https://registry.yarnpkg.com/resolve-url/-/resolve-url-0.2.1.tgz#2c637fe77c893afd2a663fe21aa9080068e2052a"