From e9fd938ede557879a08d5a406fe9ef9256787b45 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 23 Jun 2022 14:56:02 +0200 Subject: [PATCH 1/8] scripts/api-extractor: generate API reports for CLI packages Signed-off-by: Patrik Oldsberg --- scripts/api-extractor.ts | 293 +++++++++++++++++++++++++++++++++++---- 1 file changed, 268 insertions(+), 25 deletions(-) diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index 2ca7aef17f..9331edc9a2 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -23,7 +23,7 @@ import { dirname, join, } from 'path'; -import { spawnSync } from 'child_process'; +import { spawnSync, execFile } from 'child_process'; import prettier from 'prettier'; import fs from 'fs-extra'; import { @@ -197,18 +197,6 @@ ApiReportGenerator.generateReviewFileContent = const PACKAGE_ROOTS = ['packages', 'plugins']; -const SKIPPED_PACKAGES = [ - join('packages', 'app'), - join('packages', 'backend'), - join('packages', 'cli'), - join('packages', 'codemods'), - join('packages', 'create-app'), - join('packages', 'e2e-test'), - join('packages', 'techdocs-cli-embedded-app'), - join('packages', 'storybook'), - join('packages', 'techdocs-cli'), -]; - const ALLOW_WARNINGS = [ 'packages/core-components', 'plugins/allure', @@ -303,9 +291,6 @@ async function findSpecificPackageDirs(unresolvedPackageDirs: string[]) { if (!packageDir) { throw new Error(`'${unresolvedPackageDir}' is not a valid package path`); } - if (SKIPPED_PACKAGES.includes(packageDir)) { - throw new Error(`'${packageDir}' does not have an API report`); - } packageDirs.push(packageDir); } @@ -328,9 +313,7 @@ async function findPackageDirs() { continue; } - if (!SKIPPED_PACKAGES.includes(packageDir)) { - packageDirs.push(packageDir); - } + packageDirs.push(packageDir); } } @@ -1065,6 +1048,251 @@ async function buildDocs({ documenter.generateFiles(); } +async function categorizePackageDirs(projectRoot, packageDirs) { + const dirs = packageDirs.slice(); + const tsPackageDirs = new Array(); + const cliPackageDirs = new Array(); + + await Promise.all( + Array(10) + .fill(0) + .map(async () => { + for (;;) { + const dir = dirs.pop(); + if (!dir) { + return; + } + + const pkgJson = await fs + .readJson(resolvePath(projectRoot, dir, 'package.json')) + .catch(error => { + if (error.code === 'ENOENT') { + return undefined; + } + throw error; + }); + const role = pkgJson?.backstage?.role; + if (!role) { + throw new Error(`No backstage.role in ${dir}/package.json`); + } + if (role === 'cli') { + cliPackageDirs.push(dir); + } else if (role !== 'frontend' && role !== 'backend') { + tsPackageDirs.push(dir); + } + } + }), + ); + + return { tsPackageDirs, cliPackageDirs }; +} + +function createBinRunner(cwd: string, path: string) { + return async (...command: string[]) => + new Promise((resolve, reject) => { + execFile( + 'node', + [path, ...command], + { + cwd, + shell: true, + timeout: 5000, + }, + (err, stdout, stderr) => { + if (err) { + reject(err); + } else if (stderr) { + reject(stderr); + } else { + resolve(stdout); + } + }, + ); + }); +} + +function parseHelpPage(helpPageContent: string) { + const [, usage] = helpPageContent.match(/^\s*Usage: (.*)$/im) ?? []; + const lines = helpPageContent.split(/\r?\n/); + + let options = new Array(); + let commands = new Array(); + + while (lines.length > 0) { + while (lines.length > 0 && !lines[0].endsWith(':')) { + lines.shift(); + } + if (lines.length > 0) { + // Start of a new section, e.g. "Options:" + const sectionName = lines.shift(); + // Take lines until we hit the next section or the end + const sectionEndIndex = lines.findIndex( + line => line && !line.match(/^\s/), + ); + const sectionLines = lines.slice(0, sectionEndIndex); + lines.splice(0, sectionLines.length); + + // Trim away documentation + const sectionItems = sectionLines + .map(line => line.match(/^\s{1,8}(.*?)\s\s+/)?.[1]) + .filter(Boolean); + + if (sectionName.toLocaleLowerCase('en-US') === 'options:') { + options = sectionItems; + } else if (sectionName.toLocaleLowerCase('en-US') === 'commands:') { + commands = sectionItems; + } else { + throw new Error(`Unknown CLI section: ${sectionName}`); + } + } + } + + return { + usage, + options, + commands, + }; +} + +// Represents the help page os a CLI command +interface CliHelpPage { + // Path of commands to reach this page + path: string[]; + // Parsed content + usage: string | undefined; + options: string[]; + commands: string[]; +} + +async function exploreCliHelpPages( + run: (...args: string[]) => Promise, +): Promise { + const helpPages = new Array(); + + async function exploreHelpPage(...path: string[]) { + const content = await run(...path, '--help'); + const parsed = parseHelpPage(content); + helpPages.push({ path, ...parsed }); + + await Promise.all( + parsed.commands.map(async fullCommand => { + const command = fullCommand.split(/[|\s]/)[0]; + if (command !== 'help') { + await exploreHelpPage(...path, command); + } + }), + ); + } + + await exploreHelpPage(); + + helpPages.sort((a, b) => a.path.join(' ').localeCompare(b.path.join(' '))); + + return helpPages; +} + +// The API model for a CLI entry point +interface CliModel { + name: string; + helpPages: CliHelpPage[]; +} + +function generateCliReport(name: string, models: CliModel[]): string { + const content = [ + `## CLI Report file for "${name}"`, + '', + '> Do not edit this file. It is a report generated by `yarn build:api-reports`', + '', + ]; + + for (const model of models) { + for (const helpPage of model.helpPages) { + content.push( + `### \`${[model.name, ...helpPage.path].join(' ')}\``, + '', + '```', + `Usage: ${helpPage.usage ?? ''}`, + ); + + if (helpPage.options.length > 0) { + content.push('', 'Options:', ...helpPage.options.map(l => ` ${l}`)); + } + + if (helpPage.commands.length > 0) { + content.push('', 'Commands:', ...helpPage.commands.map(l => ` ${l}`)); + } + content.push('```', ''); + } + } + + return content.join('\n'); +} + +interface CliExtractionOptions { + projectRoot: string; + packageDirs: string[]; + isLocalBuild: boolean; +} + +async function runCliExtraction({ + projectRoot, + packageDirs, + isLocalBuild, +}: CliExtractionOptions) { + for (const packageDir of packageDirs) { + console.log(`## Processing ${packageDir}`); + const fullDir = resolvePath(projectRoot, packageDir); + const pkgJson = await fs.readJson(resolvePath(fullDir, 'package.json')); + + if (!pkgJson.bin) { + throw new Error(`CLI Package in ${packageDir} has no bin field`); + } + const models = new Array(); + for (const [name, path] of Object.entries(pkgJson.bin)) { + const run = createBinRunner(fullDir, path); + const helpPages = await exploreCliHelpPages(run); + models.push({ name, helpPages }); + } + + const report = generateCliReport(pkgJson.name, models); + + const reportPath = resolvePath(fullDir, 'cli-report.md'); + const existingReport = await fs + .readFile(reportPath, 'utf8') + .catch(error => { + if (error.code === 'ENOENT') { + return undefined; + } + throw error; + }); + + if (existingReport !== report) { + if (isLocalBuild) { + console.warn(`CLI report changed for ${packageDir}`); + await fs.writeFile(reportPath, report); + } else { + logApiReportInstructions(); + + if (existingReport) { + console.log(''); + console.log( + `The conflicting file is ${relativePath( + projectRoot, + reportPath, + )}, expecting the following content:`, + ); + console.log(''); + + console.log(report); + + logApiReportInstructions(); + } + throw new Error(`CLI report changed for ${packageDir}, `); + } + } + } +} + async function main() { const projectRoot = resolvePath(__dirname, '..'); const isCiBuild = process.argv.includes('--ci'); @@ -1121,13 +1349,28 @@ async function main() { const packageDirs = selectedPackageDirs ?? (await findPackageDirs()); - console.log('# Generating package API reports'); - await runApiExtraction({ + const { tsPackageDirs, cliPackageDirs } = await categorizePackageDirs( + projectRoot, packageDirs, - outputDir: tmpDir, - isLocalBuild: !isCiBuild, - tsconfigFilePath, - }); + ); + + if (tsPackageDirs.length > 0) { + console.log('# Generating package API reports'); + await runApiExtraction({ + packageDirs: tsPackageDirs, + outputDir: tmpDir, + isLocalBuild: !isCiBuild, + tsconfigFilePath, + }); + } + if (cliPackageDirs.length > 0) { + console.log('# Generating package CLI reports'); + await runCliExtraction({ + projectRoot, + packageDirs: cliPackageDirs, + isLocalBuild: !isCiBuild, + }); + } if (isDocsBuild) { console.log('# Generating package documentation'); From 0bc7eb1642bfdf799a0b9c9a9c8d5ab4fcd1a179 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 23 Jun 2022 14:56:38 +0200 Subject: [PATCH 2/8] generate API reports for CLI packages Signed-off-by: Patrik Oldsberg --- packages/cli/cli-report.md | 425 ++++++++++++++++++++++++++++ packages/codemods/cli-report.md | 61 ++++ packages/create-app/cli-report.md | 15 + packages/e2e-test/cli-report.md | 26 ++ packages/techdocs-cli/cli-report.md | 117 ++++++++ 5 files changed, 644 insertions(+) create mode 100644 packages/cli/cli-report.md create mode 100644 packages/codemods/cli-report.md create mode 100644 packages/create-app/cli-report.md create mode 100644 packages/e2e-test/cli-report.md create mode 100644 packages/techdocs-cli/cli-report.md diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md new file mode 100644 index 0000000000..04f034cee1 --- /dev/null +++ b/packages/cli/cli-report.md @@ -0,0 +1,425 @@ +## CLI Report file for "@backstage/cli" + +> Do not edit this file. It is a report generated by `yarn build:api-reports` + +### `backstage-cli` + +``` +Usage: backstage-cli [options] [command] + +Options: + -V, --version + -h, --help + +Commands: + create [options] + create-plugin [options] + plugin:diff [options] + test + config:docs [options] + config:print [options] + config:check [options] + config:schema [options] + repo [command] + package [command] + migrate [command] + versions:bump [options] + versions:check [options] + clean + build-workspace [packages...] + create-github-app + info + help [command] +``` + +### `backstage-cli build-workspace` + +``` +Usage: backstage-cli build-workspace [options] [packages...] + +Options: + -h, --help +``` + +### `backstage-cli clean` + +``` +Usage: backstage-cli clean [options] + +Options: + -h, --help +``` + +### `backstage-cli config:check` + +``` +Usage: backstage-cli config:check [options] + +Options: + --package + --lax + --frontend + --deprecated + --config + -h, --help +``` + +### `backstage-cli config:docs` + +``` +Usage: backstage-cli config:docs [options] + +Options: + --package + -h, --help +``` + +### `backstage-cli config:print` + +``` +Usage: backstage-cli config:print [options] + +Options: + --package + --lax + --frontend + --with-secrets + --format + --config + -h, --help +``` + +### `backstage-cli config:schema` + +``` +Usage: backstage-cli config:schema [options] + +Options: + --package + --format + -h, --help +``` + +### `backstage-cli create` + +``` +Usage: backstage-cli create [options] + +Options: + --select + --option = + --scope + --npm-registry + --no-private + -h, --help +``` + +### `backstage-cli create-github-app` + +``` +Usage: backstage-cli create-github-app [options] + +Options: + -h, --help +``` + +### `backstage-cli create-plugin` + +``` +Usage: backstage-cli create-plugin [options] + +Options: + --backend + --scope + --npm-registry + --no-private + -h, --help +``` + +### `backstage-cli info` + +``` +Usage: backstage-cli info [options] + +Options: + -h, --help +``` + +### `backstage-cli migrate` + +``` +Usage: backstage-cli migrate [options] [command] [command] + +Options: + -h, --help + +Commands: + package-roles + package-scripts + package-lint-configs + help [command] +``` + +### `backstage-cli migrate package-lint-configs` + +``` +Usage: backstage-cli migrate package-lint-configs [options] + +Options: + -h, --help +``` + +### `backstage-cli migrate package-roles` + +``` +Usage: backstage-cli migrate package-roles [options] + +Options: + -h, --help +``` + +### `backstage-cli migrate package-scripts` + +``` +Usage: backstage-cli migrate package-scripts [options] + +Options: + -h, --help +``` + +### `backstage-cli package` + +``` +Usage: backstage-cli package [options] [command] [command] + +Options: + -h, --help + +Commands: + start [options] + build [options] + lint [options] [directories...] + test + clean + prepack + postpack + help [command] +``` + +### `backstage-cli package build` + +``` +Usage: backstage-cli package build [options] + +Options: + --role + --minify + --experimental-type-build + --skip-build-dependencies + --stats + --config + -h, --help +``` + +### `backstage-cli package clean` + +``` +Usage: backstage-cli package clean [options] + +Options: + -h, --help +``` + +### `backstage-cli package lint` + +``` +Usage: backstage-cli package lint [options] [directories...] + +Options: + --format + --fix + -h, --help +``` + +### `backstage-cli package postpack` + +``` +Usage: backstage-cli package postpack [options] + +Options: + -h, --help +``` + +### `backstage-cli package prepack` + +``` +Usage: backstage-cli package prepack [options] + +Options: + -h, --help +``` + +### `backstage-cli package start` + +``` +Usage: backstage-cli package start [options] + +Options: + --config + --role + --check + --inspect + --inspect-brk + -h, --help +``` + +### `backstage-cli package test` + +``` +Usage: backstage-cli [--config=] [TestPathPattern] + +Options: + -h, --help + -v, --version + --all + --automock + -b, --bail + --cache + --cacheDirectory + --changedFilesWithAncestor + --changedSince + --ci + --clearCache + --clearMocks + --collectCoverage + --collectCoverageFrom + --collectCoverageOnlyFrom + --color + --colors + -c, --config + --coverage + --coverageDirectory + --coveragePathIgnorePatterns + --coverageProvider + --coverageReporters + --coverageThreshold + --debug + --detectLeaks + --detectOpenHandles + --env + --errorOnDeprecated + -e, --expand + --filter + --findRelatedTests + --forceExit +``` + +### `backstage-cli plugin:diff` + +``` +Usage: backstage-cli plugin:diff [options] + +Options: + --check + --yes + -h, --help +``` + +### `backstage-cli repo` + +``` +Usage: backstage-cli repo [options] [command] [command] + +Options: + -h, --help + +Commands: + build [options] + lint [options] + help [command] +``` + +### `backstage-cli repo build` + +``` +Usage: backstage-cli repo build [options] + +Options: + --all + --since + -h, --help +``` + +### `backstage-cli repo lint` + +``` +Usage: backstage-cli repo lint [options] + +Options: + --format + --since + --fix + -h, --help +``` + +### `backstage-cli test` + +``` +Usage: backstage-cli [--config=] [TestPathPattern] + +Options: + -h, --help + -v, --version + --all + --automock + -b, --bail + --cache + --cacheDirectory + --changedFilesWithAncestor + --changedSince + --ci + --clearCache + --clearMocks + --collectCoverage + --collectCoverageFrom + --collectCoverageOnlyFrom + --color + --colors + -c, --config + --coverage + --coverageDirectory + --coveragePathIgnorePatterns + --coverageProvider + --coverageReporters + --coverageThreshold + --debug + --detectLeaks + --detectOpenHandles + --env + --errorOnDeprecated + -e, --expand + --filter + --findRelatedTests + --forceExit +``` + +### `backstage-cli versions:bump` + +``` +Usage: backstage-cli versions:bump [options] + +Options: + --pattern + --release + -h, --help +``` + +### `backstage-cli versions:check` + +``` +Usage: backstage-cli versions:check [options] + +Options: + --fix + -h, --help +``` diff --git a/packages/codemods/cli-report.md b/packages/codemods/cli-report.md new file mode 100644 index 0000000000..57d2198141 --- /dev/null +++ b/packages/codemods/cli-report.md @@ -0,0 +1,61 @@ +## CLI Report file for "@backstage/codemods" + +> Do not edit this file. It is a report generated by `yarn build:api-reports` + +### `backstage-codemods` + +``` +Usage: backstage-codemods [options] [command] + +Options: + -V, --version + -h, --help + +Commands: + apply [target-dirs...] + list + help [command] +``` + +### `backstage-codemods apply` + +``` +Usage: backstage-codemods apply [options] [command] [target-dirs...] + +Options: + -h, --help + +Commands: + core-imports [options] [target-dirs...] + extension-names [options] [target-dirs...] + help [command] +``` + +### `backstage-codemods apply core-imports` + +``` +Usage: backstage-codemods apply core-imports [options] [target-dirs...] + +Options: + -d, --dry + -h, --help +``` + +### `backstage-codemods apply extension-names` + +``` +Usage: backstage-codemods apply extension-names [options] [target-dirs...] + +Options: + -d, --dry + -h, --help +``` + +### `backstage-codemods list` + +``` +Usage: backstage-codemods list [options] + +Options: + -h, --help +``` diff --git a/packages/create-app/cli-report.md b/packages/create-app/cli-report.md new file mode 100644 index 0000000000..1244432c6a --- /dev/null +++ b/packages/create-app/cli-report.md @@ -0,0 +1,15 @@ +## CLI Report file for "@backstage/create-app" + +> Do not edit this file. It is a report generated by `yarn build:api-reports` + +### `backstage-create-app` + +``` +Usage: backstage-create-app [options] + +Options: + -V, --version + --path [directory] + --skip-install + -h, --help +``` diff --git a/packages/e2e-test/cli-report.md b/packages/e2e-test/cli-report.md new file mode 100644 index 0000000000..3a3912b8fc --- /dev/null +++ b/packages/e2e-test/cli-report.md @@ -0,0 +1,26 @@ +## CLI Report file for "e2e-test" + +> Do not edit this file. It is a report generated by `yarn build:api-reports` + +### `e2e-test` + +``` +Usage: e2e-test [options] [command] + +Options: + -V, --version + -h, --help + +Commands: + run + help [command] +``` + +### `e2e-test run` + +``` +Usage: e2e-test run [options] + +Options: + -h, --help +``` diff --git a/packages/techdocs-cli/cli-report.md b/packages/techdocs-cli/cli-report.md new file mode 100644 index 0000000000..64b5e9c090 --- /dev/null +++ b/packages/techdocs-cli/cli-report.md @@ -0,0 +1,117 @@ +## CLI Report file for "@techdocs/cli" + +> Do not edit this file. It is a report generated by `yarn build:api-reports` + +### `techdocs-cli` + +``` +Usage: techdocs-cli [options] [command] + +Options: + -V, --version + -h, --help + +Commands: + generate|build [options] + migrate [options] + publish [options] + serve:mkdocs [options] + serve [options] + help [command] +``` + +### `techdocs-cli generate` + +``` +Usage: techdocs-cli generate|build [options] + +Options: + --source-dir + --output-dir + --docker-image + --no-pull + --no-docker + --techdocs-ref + --etag + -v --verbose + --omitTechdocsCoreMkdocsPlugin + --legacyCopyReadmeMdToIndexMd + -h, --help +``` + +### `techdocs-cli migrate` + +``` +Usage: techdocs-cli migrate [options] + +Options: + --publisher-type + --storage-name + --azureAccountName + --azureAccountKey + --awsRoleArn + --awsEndpoint + --awsS3ForcePathStyle + --awsBucketRootPath + --osCredentialId + --osSecret + --osAuthUrl + --osSwiftUrl + --removeOriginal + --concurrency + -v --verbose + -h, --help +``` + +### `techdocs-cli publish` + +``` +Usage: techdocs-cli publish [options] + +Options: + --publisher-type + --storage-name + --entity + --legacyUseCaseSensitiveTripletPaths + --azureAccountName + --azureAccountKey + --awsRoleArn + --awsEndpoint + --awsS3sse + --awsS3ForcePathStyle + --osCredentialId + --osSecret + --osAuthUrl + --osSwiftUrl + --gcsBucketRootPath + --directory + -h, --help +``` + +### `techdocs-cli serve` + +``` +Usage: techdocs-cli serve [options] + +Options: + -i, --docker-image + --docker-entrypoint + --no-docker + --mkdocs-port + -v --verbose + -h, --help +``` + +### `techdocs-cli serve:mkdocs` + +``` +Usage: techdocs-cli serve:mkdocs [options] + +Options: + -i, --docker-image + --docker-entrypoint + --no-docker + -p, --port + -v --verbose + -h, --help +``` From bbf005fb55f15f51b808fcade0479f6cd96af873 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 23 Jun 2022 16:20:43 +0200 Subject: [PATCH 3/8] scripts/generate-changeset-feedback: ignore cli-report.md Signed-off-by: Patrik Oldsberg --- scripts/generate-changeset-feedback.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/generate-changeset-feedback.js b/scripts/generate-changeset-feedback.js index b614459a0e..b34147798d 100644 --- a/scripts/generate-changeset-feedback.js +++ b/scripts/generate-changeset-feedback.js @@ -42,7 +42,7 @@ function isPublishedPath(path) { return false; } // API report changes by themselves don't count - if (path === 'api-report.md') { + if (path === 'api-report.md' || path === 'cli-report.md') { return false; } // Lint changes don't count From 130ad3f34e6774c315157ec53e641c7d8d218602 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 23 Jun 2022 16:24:28 +0200 Subject: [PATCH 4/8] .prettierignore: add cli-report.md Signed-off-by: Patrik Oldsberg --- .prettierignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.prettierignore b/.prettierignore index 393c35fdbe..8f1fae0456 100644 --- a/.prettierignore +++ b/.prettierignore @@ -5,6 +5,7 @@ coverage *.hbs templates api-report.md +cli-report.md plugins/scaffolder-backend/sample-templates .vscode dist-types From 480dae16c815a5e8eece4bdd0246aec41a03a797 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 23 Jun 2022 16:43:50 +0200 Subject: [PATCH 5/8] scripts/api-extractor: better error reporting for cli errors Signed-off-by: Patrik Oldsberg --- scripts/api-extractor.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index 9331edc9a2..bd3dac2ee8 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -1100,9 +1100,9 @@ function createBinRunner(cwd: string, path: string) { }, (err, stdout, stderr) => { if (err) { - reject(err); + reject(new Error(`${err.message}\n${stderr}`)); } else if (stderr) { - reject(stderr); + reject(new Error(`Command printed error output: ${stderr}`)); } else { resolve(stdout); } From c1f4ad85d58e13c9322af81241fa2e8fefafcef3 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Thu, 23 Jun 2022 16:44:17 +0200 Subject: [PATCH 6/8] scripts/api-extractor: increase cli exec timeout and buffer size Signed-off-by: Patrik Oldsberg --- scripts/api-extractor.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/api-extractor.ts b/scripts/api-extractor.ts index bd3dac2ee8..cfa2fe270e 100644 --- a/scripts/api-extractor.ts +++ b/scripts/api-extractor.ts @@ -1096,7 +1096,8 @@ function createBinRunner(cwd: string, path: string) { { cwd, shell: true, - timeout: 5000, + timeout: 30000, + maxBuffer: 1024 * 1024, }, (err, stdout, stderr) => { if (err) { From f6b6fb7165bec17359a9bd344980daad2bf518a8 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 29 Jun 2022 18:35:59 +0200 Subject: [PATCH 7/8] cli: blocking IO for test --help Signed-off-by: Patrik Oldsberg --- .changeset/smart-elephants-knock.md | 5 +++++ packages/cli/src/commands/test.ts | 4 ++++ 2 files changed, 9 insertions(+) create mode 100644 .changeset/smart-elephants-knock.md diff --git a/.changeset/smart-elephants-knock.md b/.changeset/smart-elephants-knock.md new file mode 100644 index 0000000000..7aed10a71e --- /dev/null +++ b/.changeset/smart-elephants-knock.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +The `test` command now ensures that all IO is flushed before exiting when printing `--help`. diff --git a/packages/cli/src/commands/test.ts b/packages/cli/src/commands/test.ts index f1bfcc356b..88769aec1a 100644 --- a/packages/cli/src/commands/test.ts +++ b/packages/cli/src/commands/test.ts @@ -78,6 +78,10 @@ export default async (_opts: OptionValues, cmd: Command) => { process.env.TZ = 'UTC'; } + if (args.includes('--help')) { + (process.stdout as any)._handle.setBlocking(true); + } + // eslint-disable-next-line jest/no-jest-import await require('jest').run(args); }; From c1f6fcb2e9716dd3def7acfbb179f4e8154f24e3 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Wed, 29 Jun 2022 18:42:36 +0200 Subject: [PATCH 8/8] cli: update cli report Signed-off-by: Patrik Oldsberg --- packages/cli/cli-report.md | 138 +++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/packages/cli/cli-report.md b/packages/cli/cli-report.md index 04f034cee1..8c678d885e 100644 --- a/packages/cli/cli-report.md +++ b/packages/cli/cli-report.md @@ -312,6 +312,75 @@ Options: --filter --findRelatedTests --forceExit + --globalSetup + --globalTeardown + --globals + --haste + --init + --injectGlobals + --json + --lastCommit + --listTests + --logHeapUsage + --maxConcurrency + -w, --maxWorkers + --moduleDirectories + --moduleFileExtensions + --moduleNameMapper + --modulePathIgnorePatterns + --modulePaths + --noStackTrace + --notify + --notifyMode + -o, --onlyChanged + -f, --onlyFailures + --outputFile + --passWithNoTests + --preset + --prettierPath + --projects + --reporters + --resetMocks + --resetModules + --resolver + --restoreMocks + --rootDir + --roots + -i, --runInBand + --runTestsByPath + --runner + --selectProjects + --setupFiles + --setupFilesAfterEnv + --showConfig + --silent + --skipFilter + --snapshotSerializers + --testEnvironment + --testEnvironmentOptions + --testFailureExitCode + --testLocationInResults + --testMatch + -t, --testNamePattern + --testPathIgnorePatterns + --testPathPattern + --testRegex + --testResultsProcessor + --testRunner + --testSequencer + --testTimeout + --testURL + --timers + --transform + --transformIgnorePatterns + --unmockedModulePathPatterns + -u, --updateSnapshot + --useStderr + --verbose + --watch + --watchAll + --watchPathIgnorePatterns + --watchman ``` ### `backstage-cli plugin:diff` @@ -401,6 +470,75 @@ Options: --filter --findRelatedTests --forceExit + --globalSetup + --globalTeardown + --globals + --haste + --init + --injectGlobals + --json + --lastCommit + --listTests + --logHeapUsage + --maxConcurrency + -w, --maxWorkers + --moduleDirectories + --moduleFileExtensions + --moduleNameMapper + --modulePathIgnorePatterns + --modulePaths + --noStackTrace + --notify + --notifyMode + -o, --onlyChanged + -f, --onlyFailures + --outputFile + --passWithNoTests + --preset + --prettierPath + --projects + --reporters + --resetMocks + --resetModules + --resolver + --restoreMocks + --rootDir + --roots + -i, --runInBand + --runTestsByPath + --runner + --selectProjects + --setupFiles + --setupFilesAfterEnv + --showConfig + --silent + --skipFilter + --snapshotSerializers + --testEnvironment + --testEnvironmentOptions + --testFailureExitCode + --testLocationInResults + --testMatch + -t, --testNamePattern + --testPathIgnorePatterns + --testPathPattern + --testRegex + --testResultsProcessor + --testRunner + --testSequencer + --testTimeout + --testURL + --timers + --transform + --transformIgnorePatterns + --unmockedModulePathPatterns + -u, --updateSnapshot + --useStderr + --verbose + --watch + --watchAll + --watchPathIgnorePatterns + --watchman ``` ### `backstage-cli versions:bump`