Merge pull request #10617 from backstage/freben/bump-commander
Bump commander to version 9.1.0
This commit is contained in:
@@ -62,7 +62,7 @@
|
||||
"buffer": "^6.0.3",
|
||||
"chalk": "^4.0.0",
|
||||
"chokidar": "^3.3.1",
|
||||
"commander": "^6.1.0",
|
||||
"commander": "^9.1.0",
|
||||
"css-loader": "^6.5.1",
|
||||
"diff": "^5.0.0",
|
||||
"esbuild": "^0.14.10",
|
||||
|
||||
@@ -15,20 +15,20 @@
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { buildBundle } from '../../lib/bundler';
|
||||
import { getEnvironmentParallelism } from '../../lib/parallel';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { paths } from '../../lib/paths';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const { name } = await fs.readJson(paths.resolveTarget('package.json'));
|
||||
await buildBundle({
|
||||
entry: 'src/index',
|
||||
parallelism: getEnvironmentParallelism(),
|
||||
statsJsonEnabled: cmd.stats,
|
||||
statsJsonEnabled: opts.stats,
|
||||
...(await loadCliConfig({
|
||||
args: cmd.config,
|
||||
args: opts.config,
|
||||
fromPackage: name,
|
||||
})),
|
||||
});
|
||||
|
||||
@@ -17,14 +17,14 @@
|
||||
import fs from 'fs-extra';
|
||||
import chalk from 'chalk';
|
||||
import uniq from 'lodash/uniq';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { serveBundle } from '../../lib/bundler';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { Lockfile } from '../../lib/versioning';
|
||||
import { forbiddenDuplicatesFilter, includedFilter } from '../versions/lint';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const lockFilePath = paths.resolveTargetRoot('yarn.lock');
|
||||
if (fs.existsSync(lockFilePath)) {
|
||||
try {
|
||||
@@ -80,9 +80,9 @@ export default async (cmd: Command) => {
|
||||
const { name } = await fs.readJson(paths.resolveTarget('package.json'));
|
||||
const waitForExit = await serveBundle({
|
||||
entry: 'src/index',
|
||||
checksEnabled: cmd.check,
|
||||
checksEnabled: opts.check,
|
||||
...(await loadCliConfig({
|
||||
args: cmd.config,
|
||||
args: opts.config,
|
||||
fromPackage: name,
|
||||
withFilteredKeys: true,
|
||||
})),
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { buildPackage, Output } from '../../lib/builder';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
await buildPackage({
|
||||
outputs: new Set([Output.cjs, Output.types]),
|
||||
minify: cmd.minify,
|
||||
useApiExtractor: cmd.experimentalTypeBuild,
|
||||
minify: opts.minify,
|
||||
useApiExtractor: opts.experimentalTypeBuild,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ import os from 'os';
|
||||
import fs from 'fs-extra';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import tar, { CreateOptions } from 'tar';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { createDistWorkspace } from '../../lib/packager';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { getEnvironmentParallelism } from '../../lib/parallel';
|
||||
@@ -27,7 +27,7 @@ import { buildPackage, Output } from '../../lib/builder';
|
||||
const BUNDLE_FILE = 'bundle.tar.gz';
|
||||
const SKELETON_FILE = 'skeleton.tar.gz';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const targetDir = paths.resolveTarget('dist');
|
||||
const pkg = await fs.readJson(paths.resolveTarget('package.json'));
|
||||
|
||||
@@ -38,7 +38,7 @@ export default async (cmd: Command) => {
|
||||
try {
|
||||
await createDistWorkspace([pkg.name], {
|
||||
targetDir: tmpDir,
|
||||
buildDependencies: Boolean(cmd.buildDependencies),
|
||||
buildDependencies: Boolean(opts.buildDependencies),
|
||||
buildExcludes: [pkg.name],
|
||||
parallelism: getEnvironmentParallelism(),
|
||||
skeleton: SKELETON_FILE,
|
||||
|
||||
@@ -15,11 +15,11 @@
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { serveBackend } from '../../lib/bundler/backend';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
// Cleaning dist/ before we start the dev process helps work around an issue
|
||||
// where we end up with the entrypoint executing multiple times, causing
|
||||
// a port bind conflict among other things.
|
||||
@@ -27,9 +27,9 @@ export default async (cmd: Command) => {
|
||||
|
||||
const waitForExit = await serveBackend({
|
||||
entry: 'src/index',
|
||||
checksEnabled: cmd.check,
|
||||
inspectEnabled: cmd.inspect,
|
||||
inspectBrkEnabled: cmd.inspectBrk,
|
||||
checksEnabled: opts.check,
|
||||
inspectEnabled: opts.inspect,
|
||||
inspectBrkEnabled: opts.inspectBrk,
|
||||
});
|
||||
|
||||
await waitForExit();
|
||||
|
||||
@@ -14,27 +14,27 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { buildPackage, Output } from '../../lib/builder';
|
||||
import { findRoleFromCommand, getRoleInfo } from '../../lib/role';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { buildFrontend } from './buildFrontend';
|
||||
import { buildBackend } from './buildBackend';
|
||||
|
||||
export async function command(cmd: Command): Promise<void> {
|
||||
const role = await findRoleFromCommand(cmd);
|
||||
export async function command(opts: OptionValues): Promise<void> {
|
||||
const role = await findRoleFromCommand(opts);
|
||||
|
||||
if (role === 'frontend') {
|
||||
return buildFrontend({
|
||||
targetDir: paths.targetDir,
|
||||
configPaths: cmd.config as string[],
|
||||
writeStats: Boolean(cmd.stats),
|
||||
configPaths: opts.config as string[],
|
||||
writeStats: Boolean(opts.stats),
|
||||
});
|
||||
}
|
||||
if (role === 'backend') {
|
||||
return buildBackend({
|
||||
targetDir: paths.targetDir,
|
||||
skipBuildDependencies: Boolean(cmd.skipBuildDependencies),
|
||||
skipBuildDependencies: Boolean(opts.skipBuildDependencies),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export async function command(cmd: Command): Promise<void> {
|
||||
|
||||
return buildPackage({
|
||||
outputs,
|
||||
minify: Boolean(cmd.minify),
|
||||
useApiExtractor: Boolean(cmd.experimentalTypeBuild),
|
||||
minify: Boolean(opts.minify),
|
||||
useApiExtractor: Boolean(opts.experimentalTypeBuild),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -15,10 +15,9 @@
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { Command } from 'commander';
|
||||
import { createDistWorkspace } from '../lib/packager';
|
||||
|
||||
export default async (dir: string, _cmd: Command, packages: string[]) => {
|
||||
export default async (dir: string, packages: string[]) => {
|
||||
if (!(await fs.pathExists(dir))) {
|
||||
throw new Error(`Target workspace directory doesn't exist, '${dir}'`);
|
||||
}
|
||||
|
||||
@@ -16,17 +16,17 @@
|
||||
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { mergeConfigSchemas } from '@backstage/config-loader';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { JSONSchema7 as JSONSchema } from 'json-schema';
|
||||
import openBrowser from 'react-dev-utils/openBrowser';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
|
||||
const DOCS_URL = 'https://config.backstage.io';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const { schema: appSchemas } = await loadCliConfig({
|
||||
args: [],
|
||||
fromPackage: cmd.package,
|
||||
fromPackage: opts.package,
|
||||
mockEnv: true,
|
||||
});
|
||||
|
||||
|
||||
@@ -14,36 +14,36 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { stringify as stringifyYaml } from 'yaml';
|
||||
import { AppConfig, ConfigReader } from '@backstage/config';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { ConfigSchema, ConfigVisibility } from '@backstage/config-loader';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const { schema, appConfigs } = await loadCliConfig({
|
||||
args: cmd.config,
|
||||
fromPackage: cmd.package,
|
||||
mockEnv: cmd.lax,
|
||||
fullVisibility: !cmd.frontend,
|
||||
args: opts.config,
|
||||
fromPackage: opts.package,
|
||||
mockEnv: opts.lax,
|
||||
fullVisibility: !opts.frontend,
|
||||
});
|
||||
const visibility = getVisibilityOption(cmd);
|
||||
const visibility = getVisibilityOption(opts);
|
||||
const data = serializeConfigData(appConfigs, schema, visibility);
|
||||
|
||||
if (cmd.format === 'json') {
|
||||
if (opts.format === 'json') {
|
||||
process.stdout.write(`${JSON.stringify(data, null, 2)}\n`);
|
||||
} else {
|
||||
process.stdout.write(`${stringifyYaml(data)}\n`);
|
||||
}
|
||||
};
|
||||
|
||||
function getVisibilityOption(cmd: Command): ConfigVisibility {
|
||||
if (cmd.frontend && cmd.withSecrets) {
|
||||
function getVisibilityOption(opts: OptionValues): ConfigVisibility {
|
||||
if (opts.frontend && opts.withSecrets) {
|
||||
throw new Error('Not allowed to combine frontend and secret config');
|
||||
}
|
||||
if (cmd.frontend) {
|
||||
if (opts.frontend) {
|
||||
return 'frontend';
|
||||
} else if (cmd.withSecrets) {
|
||||
} else if (opts.withSecrets) {
|
||||
return 'secret';
|
||||
}
|
||||
return 'backend';
|
||||
|
||||
@@ -14,17 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { JSONSchema7 as JSONSchema } from 'json-schema';
|
||||
import { stringify as stringifyYaml } from 'yaml';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { JsonObject } from '@backstage/types';
|
||||
import { mergeConfigSchemas } from '@backstage/config-loader';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const { schema } = await loadCliConfig({
|
||||
args: [],
|
||||
fromPackage: cmd.package,
|
||||
fromPackage: opts.package,
|
||||
mockEnv: true,
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ export default async (cmd: Command) => {
|
||||
merged.description =
|
||||
'This is the schema describing the structure of the app-config.yaml configuration file.';
|
||||
|
||||
if (cmd.format === 'json') {
|
||||
if (opts.format === 'json') {
|
||||
process.stdout.write(`${JSON.stringify(merged, null, 2)}\n`);
|
||||
} else {
|
||||
process.stdout.write(`${stringifyYaml(merged)}\n`);
|
||||
|
||||
@@ -14,15 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
await loadCliConfig({
|
||||
args: cmd.config,
|
||||
fromPackage: cmd.package,
|
||||
mockEnv: cmd.lax,
|
||||
fullVisibility: !cmd.frontend,
|
||||
withDeprecatedKeys: cmd.deprecated,
|
||||
args: opts.config,
|
||||
fromPackage: opts.package,
|
||||
mockEnv: opts.lax,
|
||||
fullVisibility: !opts.frontend,
|
||||
withDeprecatedKeys: opts.deprecated,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ import { resolve as resolvePath, join as joinPath } from 'path';
|
||||
import camelCase from 'lodash/camelCase';
|
||||
import upperFirst from 'lodash/upperFirst';
|
||||
import os from 'os';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { assertError } from '@backstage/errors';
|
||||
import {
|
||||
parseOwnerIds,
|
||||
@@ -195,7 +195,7 @@ export async function movePlugin(
|
||||
});
|
||||
}
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const codeownersPath = await getCodeownersFilePath(paths.targetRoot);
|
||||
|
||||
const questions: Question[] = [
|
||||
@@ -242,21 +242,21 @@ export default async (cmd: Command) => {
|
||||
|
||||
const answers: Answers = await inquirer.prompt(questions);
|
||||
const pluginId =
|
||||
cmd.backend && !answers.id.endsWith('-backend')
|
||||
opts.backend && !answers.id.endsWith('-backend')
|
||||
? `${answers.id}-backend`
|
||||
: answers.id;
|
||||
|
||||
const name = cmd.scope
|
||||
? `@${cmd.scope.replace(/^@/, '')}/plugin-${pluginId}`
|
||||
const name = opts.scope
|
||||
? `@${opts.scope.replace(/^@/, '')}/plugin-${pluginId}`
|
||||
: `plugin-${pluginId}`;
|
||||
const pluginVar = `${camelCase(answers.id)}Plugin`;
|
||||
const extensionName = `${upperFirst(camelCase(answers.id))}Page`;
|
||||
const npmRegistry = cmd.npmRegistry && cmd.scope ? cmd.npmRegistry : '';
|
||||
const privatePackage = cmd.private === false ? false : true;
|
||||
const npmRegistry = opts.npmRegistry && opts.scope ? opts.npmRegistry : '';
|
||||
const privatePackage = opts.private === false ? false : true;
|
||||
const isMonoRepo = await fs.pathExists(paths.resolveTargetRoot('lerna.json'));
|
||||
const appPackage = paths.resolveTargetRoot('packages/app');
|
||||
const templateDir = paths.resolveOwn(
|
||||
cmd.backend
|
||||
opts.backend
|
||||
? 'templates/default-backend-plugin'
|
||||
: 'templates/default-plugin',
|
||||
);
|
||||
@@ -309,7 +309,7 @@ export default async (cmd: Command) => {
|
||||
Task.section('Building the plugin');
|
||||
await buildPlugin(pluginDir);
|
||||
|
||||
if ((await fs.pathExists(appPackage)) && !cmd.backend) {
|
||||
if ((await fs.pathExists(appPackage)) && !opts.backend) {
|
||||
Task.section('Adding plugin as dependency in app');
|
||||
await addPluginDependencyToApp(paths.targetRoot, name, pluginVersion);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
import os from 'os';
|
||||
import fs from 'fs-extra';
|
||||
import { join as joinPath } from 'path';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { FactoryRegistry } from '../../lib/create/FactoryRegistry';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { assertError } from '@backstage/errors';
|
||||
@@ -40,12 +40,10 @@ function parseOptions(optionStrings: string[]): Record<string, string> {
|
||||
return options;
|
||||
}
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
const cmdOpts = cmd.opts();
|
||||
export default async (opts: OptionValues) => {
|
||||
const factory = await FactoryRegistry.interactiveSelect(opts.select);
|
||||
|
||||
const factory = await FactoryRegistry.interactiveSelect(cmdOpts.select);
|
||||
|
||||
const providedOptions = parseOptions(cmdOpts.option);
|
||||
const providedOptions = parseOptions(opts.option);
|
||||
const options = await FactoryRegistry.populateOptions(
|
||||
factory,
|
||||
providedOptions,
|
||||
@@ -93,9 +91,9 @@ export default async (cmd: Command) => {
|
||||
await factory.create(options, {
|
||||
isMonoRepo,
|
||||
defaultVersion,
|
||||
scope: cmdOpts.scope?.replace(/^@/, ''),
|
||||
npmRegistry: cmdOpts.npmRegistry,
|
||||
private: Boolean(cmdOpts.private),
|
||||
scope: opts.scope?.replace(/^@/, ''),
|
||||
npmRegistry: opts.npmRegistry,
|
||||
private: Boolean(opts.private),
|
||||
createTemporaryDirectory,
|
||||
markAsModified() {
|
||||
modified = true;
|
||||
|
||||
@@ -15,17 +15,17 @@
|
||||
*/
|
||||
|
||||
import { assertError } from '@backstage/errors';
|
||||
import { CommanderStatic } from 'commander';
|
||||
import { Command } from 'commander';
|
||||
import { exitWithError } from '../lib/errors';
|
||||
|
||||
const configOption = [
|
||||
'--config <path>',
|
||||
'Config files to load instead of app-config.yaml',
|
||||
(opt: string, opts: string[]) => [...opts, opt],
|
||||
(opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]),
|
||||
Array<string>(),
|
||||
] as const;
|
||||
|
||||
export function registerRepoCommand(program: CommanderStatic) {
|
||||
export function registerRepoCommand(program: Command) {
|
||||
const command = program
|
||||
.command('repo [command]')
|
||||
.description('Command that run across an entire Backstage project');
|
||||
@@ -69,7 +69,7 @@ export function registerRepoCommand(program: CommanderStatic) {
|
||||
);
|
||||
}
|
||||
|
||||
export function registerScriptCommand(program: CommanderStatic) {
|
||||
export function registerScriptCommand(program: Command) {
|
||||
const command = program
|
||||
.command('package [command]')
|
||||
.description('Lifecycle scripts for individual packages');
|
||||
@@ -110,13 +110,13 @@ export function registerScriptCommand(program: CommanderStatic) {
|
||||
.option(
|
||||
'--config <path>',
|
||||
'Config files to load instead of app-config.yaml. Applies to app packages only.',
|
||||
(opt: string, opts: string[]) => [...opts, opt],
|
||||
(opt: string, opts: string[]) => (opts ? [...opts, opt] : [opt]),
|
||||
Array<string>(),
|
||||
)
|
||||
.action(lazy(() => import('./build').then(m => m.command)));
|
||||
|
||||
command
|
||||
.command('lint')
|
||||
.command('lint [directories...]')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
@@ -131,7 +131,7 @@ export function registerScriptCommand(program: CommanderStatic) {
|
||||
.allowUnknownOption(true) // Allows the command to run, but we still need to parse raw args
|
||||
.helpOption(', --backstage-cli-help') // Let Jest handle help
|
||||
.description('Run tests, forwarding args to Jest, defaulting to watch mode')
|
||||
.action(lazy(() => import('./testCommand').then(m => m.default)));
|
||||
.action(lazy(() => import('./test').then(m => m.default)));
|
||||
|
||||
command
|
||||
.command('fix', { hidden: true })
|
||||
@@ -155,7 +155,7 @@ export function registerScriptCommand(program: CommanderStatic) {
|
||||
.action(lazy(() => import('./pack').then(m => m.post)));
|
||||
}
|
||||
|
||||
export function registerMigrateCommand(program: CommanderStatic) {
|
||||
export function registerMigrateCommand(program: Command) {
|
||||
const command = program
|
||||
.command('migrate [command]')
|
||||
.description('Migration utilities');
|
||||
@@ -182,7 +182,7 @@ export function registerMigrateCommand(program: CommanderStatic) {
|
||||
);
|
||||
}
|
||||
|
||||
export function registerCommands(program: CommanderStatic) {
|
||||
export function registerCommands(program: Command) {
|
||||
// TODO(Rugvip): Deprecate in favor of package variant
|
||||
program
|
||||
.command('app:build')
|
||||
@@ -302,7 +302,7 @@ export function registerCommands(program: CommanderStatic) {
|
||||
|
||||
// TODO(Rugvip): Deprecate in favor of package variant
|
||||
program
|
||||
.command('lint')
|
||||
.command('lint [directories...]')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
@@ -320,7 +320,7 @@ export function registerCommands(program: CommanderStatic) {
|
||||
.description(
|
||||
'Run tests, forwarding args to Jest, defaulting to watch mode [DEPRECATED]',
|
||||
)
|
||||
.action(lazy(() => import('./testCommand').then(m => m.default)));
|
||||
.action(lazy(() => import('./test').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('config:docs')
|
||||
@@ -423,7 +423,7 @@ export function registerCommands(program: CommanderStatic) {
|
||||
.action(lazy(() => import('./clean/clean').then(m => m.default)));
|
||||
|
||||
program
|
||||
.command('build-workspace <workspace-dir> ...<packages>')
|
||||
.command('build-workspace <workspace-dir> [packages...]')
|
||||
.description('Builds a temporary dist workspace from the provided packages')
|
||||
.action(lazy(() => import('./buildWorkspace').then(m => m.default)));
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
import { fetchPackageInfo } from '../../lib/versioning';
|
||||
import { NotFoundError } from '../../lib/errors';
|
||||
import * as stepDefinitionMap from './steps';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import fs from 'fs-extra';
|
||||
|
||||
const stepDefinitions = Object.values(stepDefinitionMap);
|
||||
@@ -154,7 +154,7 @@ async function loadPeerPluginDeps(
|
||||
}
|
||||
}
|
||||
|
||||
export default async (pluginId?: string, cmd?: Command) => {
|
||||
export default async (pluginId?: string, cmd?: OptionValues) => {
|
||||
const from = pluginId || cmd?.from;
|
||||
// TODO(himanshu): If no plugin id is provided, it should list all plugins available. Maybe in some other command?
|
||||
if (!from) {
|
||||
|
||||
@@ -14,27 +14,29 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { paths } from '../lib/paths';
|
||||
import { ESLint } from 'eslint';
|
||||
|
||||
export default async (cmd: Command, cmdArgs: string[]) => {
|
||||
export default async (directories: string[], opts: OptionValues) => {
|
||||
const eslint = new ESLint({
|
||||
cwd: paths.targetDir,
|
||||
fix: cmd.fix,
|
||||
fix: opts.fix,
|
||||
extensions: ['js', 'jsx', 'ts', 'tsx', 'mjs', 'cjs'],
|
||||
});
|
||||
|
||||
const results = await eslint.lintFiles(cmdArgs ?? ['.']);
|
||||
const results = await eslint.lintFiles(
|
||||
directories.length ? directories : ['.'],
|
||||
);
|
||||
|
||||
if (cmd.fix) {
|
||||
if (opts.fix) {
|
||||
await ESLint.outputFixes(results);
|
||||
}
|
||||
|
||||
const formatter = await eslint.loadFormatter(cmd.format);
|
||||
const formatter = await eslint.loadFormatter(opts.format);
|
||||
|
||||
// This formatter uses the cwd to format file paths, so let's have that happen from the root instead
|
||||
if (cmd.format === 'eslint-formatter-friendly') {
|
||||
if (opts.format === 'eslint-formatter-friendly') {
|
||||
process.chdir(paths.targetRoot);
|
||||
}
|
||||
const resultText = formatter.format(results);
|
||||
|
||||
@@ -15,12 +15,12 @@
|
||||
*/
|
||||
|
||||
import { buildPackage, Output } from '../lib/builder';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
let outputs = new Set<Output>();
|
||||
|
||||
const { outputs: outputsStr } = cmd as { outputs?: string };
|
||||
const { outputs: outputsStr } = opts as { outputs?: string };
|
||||
if (outputsStr) {
|
||||
for (const output of outputsStr.split(',') as (keyof typeof Output)[]) {
|
||||
if (output in Output) {
|
||||
@@ -35,7 +35,7 @@ export default async (cmd: Command) => {
|
||||
|
||||
await buildPackage({
|
||||
outputs,
|
||||
minify: cmd.minify,
|
||||
useApiExtractor: cmd.experimentalTypeBuild,
|
||||
minify: opts.minify,
|
||||
useApiExtractor: opts.experimentalTypeBuild,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { buildPackage, Output } from '../../lib/builder';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
await buildPackage({
|
||||
outputs: new Set([Output.esm, Output.types]),
|
||||
minify: cmd.minify,
|
||||
useApiExtractor: cmd.experimentalTypeBuild,
|
||||
minify: opts.minify,
|
||||
useApiExtractor: opts.experimentalTypeBuild,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import {
|
||||
diffTemplateFiles,
|
||||
handlers,
|
||||
@@ -50,13 +50,13 @@ const fileHandlers = [
|
||||
},
|
||||
];
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
let promptFunc = inquirerPromptFunc;
|
||||
let finalize = () => {};
|
||||
|
||||
if (cmd.check) {
|
||||
if (opts.check) {
|
||||
[promptFunc, finalize] = makeCheckPromptFunc();
|
||||
} else if (cmd.yes) {
|
||||
} else if (opts.yes) {
|
||||
promptFunc = yesPromptFunc;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,18 +15,18 @@
|
||||
*/
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { serveBundle } from '../../lib/bundler';
|
||||
import { loadCliConfig } from '../../lib/config';
|
||||
import { paths } from '../../lib/paths';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const { name } = await fs.readJson(paths.resolveTarget('package.json'));
|
||||
const waitForExit = await serveBundle({
|
||||
entry: 'dev/index',
|
||||
checksEnabled: cmd.check,
|
||||
checksEnabled: opts.check,
|
||||
...(await loadCliConfig({
|
||||
args: cmd.config,
|
||||
args: opts.config,
|
||||
fromPackage: name,
|
||||
withFilteredKeys: true,
|
||||
})),
|
||||
|
||||
+4
-4
@@ -14,16 +14,16 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { run } from '../../lib/run';
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const args = ['test'];
|
||||
|
||||
if (cmd.watch) {
|
||||
if (opts.watch) {
|
||||
args.push('--watch');
|
||||
}
|
||||
if (cmd.coverage) {
|
||||
if (opts.coverage) {
|
||||
args.push('--coverage');
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { Command } from 'commander';
|
||||
import { Command, OptionValues } from 'commander';
|
||||
import { relative as relativePath } from 'path';
|
||||
import { buildPackages, getOutputsForRole } from '../../lib/builder';
|
||||
import { PackageGraph } from '../../lib/monorepo';
|
||||
@@ -60,29 +60,31 @@ function createScriptOptionsParser(anyCmd: Command, commandPath: string[]) {
|
||||
|
||||
// Can't clone or copy or even use commands as prototype, so we mutate
|
||||
// the necessary members instead, and then reset them once we're done
|
||||
const currentOpts = cmd._optionValues;
|
||||
const currentStore = cmd._storeOptionsAsProperties;
|
||||
const currentOpts = (cmd as any)._optionValues;
|
||||
const currentStore = (cmd as any)._storeOptionsAsProperties;
|
||||
|
||||
const result: Record<string, any> = {};
|
||||
cmd._storeOptionsAsProperties = false;
|
||||
cmd._optionValues = result;
|
||||
(cmd as any)._storeOptionsAsProperties = false;
|
||||
(cmd as any)._optionValues = result;
|
||||
|
||||
// Triggers the writing of options to the result object
|
||||
cmd.parseOptions(argsStr.split(' '));
|
||||
|
||||
cmd._storeOptionsAsProperties = currentOpts;
|
||||
cmd._optionValues = currentStore;
|
||||
(cmd as any)._storeOptionsAsProperties = currentOpts;
|
||||
(cmd as any)._optionValues = currentStore;
|
||||
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export async function command(cmd: Command): Promise<void> {
|
||||
export async function command(opts: OptionValues, cmd: Command): Promise<void> {
|
||||
let packages = await PackageGraph.listTargetPackages();
|
||||
|
||||
if (cmd.since) {
|
||||
if (opts.since) {
|
||||
const graph = PackageGraph.fromPackages(packages);
|
||||
const changedPackages = await graph.listChangedPackages({ ref: cmd.since });
|
||||
const changedPackages = await graph.listChangedPackages({
|
||||
ref: opts.since,
|
||||
});
|
||||
const withDevDependents = graph.collectPackageNames(
|
||||
changedPackages.map(pkg => pkg.name),
|
||||
pkg => pkg.localDevDependents.keys(),
|
||||
@@ -137,7 +139,7 @@ export async function command(cmd: Command): Promise<void> {
|
||||
console.log('Building packages');
|
||||
await buildPackages(options);
|
||||
|
||||
if (cmd.all) {
|
||||
if (opts.all) {
|
||||
console.log('Building apps');
|
||||
await runParallelWorkers({
|
||||
items: apps,
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { relative as relativePath } from 'path';
|
||||
import { PackageGraph, ExtendedPackageJSON } from '../../lib/monorepo';
|
||||
import { runWorkerQueueThreads } from '../../lib/parallel';
|
||||
@@ -29,12 +29,12 @@ function depCount(pkg: ExtendedPackageJSON) {
|
||||
return deps + devDeps;
|
||||
}
|
||||
|
||||
export async function command(cmd: Command): Promise<void> {
|
||||
export async function command(opts: OptionValues): Promise<void> {
|
||||
let packages = await PackageGraph.listTargetPackages();
|
||||
|
||||
if (cmd.since) {
|
||||
if (opts.since) {
|
||||
const graph = PackageGraph.fromPackages(packages);
|
||||
packages = await graph.listChangedPackages({ ref: cmd.since });
|
||||
packages = await graph.listChangedPackages({ ref: opts.since });
|
||||
}
|
||||
|
||||
// Packages are ordered from most to least number of dependencies, as a
|
||||
@@ -42,7 +42,7 @@ export async function command(cmd: Command): Promise<void> {
|
||||
packages.sort((a, b) => depCount(b.packageJson) - depCount(a.packageJson));
|
||||
|
||||
// This formatter uses the cwd to format file paths, so let's have that happen from the root instead
|
||||
if (cmd.format === 'eslint-formatter-friendly') {
|
||||
if (opts.format === 'eslint-formatter-friendly') {
|
||||
process.chdir(paths.targetRoot);
|
||||
}
|
||||
|
||||
@@ -57,8 +57,8 @@ export async function command(cmd: Command): Promise<void> {
|
||||
relativeDir: relativePath(paths.targetRoot, pkg.dir),
|
||||
})),
|
||||
workerData: {
|
||||
fix: Boolean(cmd.fix),
|
||||
format: cmd.format as string | undefined,
|
||||
fix: Boolean(opts.fix),
|
||||
format: opts.format as string | undefined,
|
||||
},
|
||||
workerFactory: async ({ fix, format }) => {
|
||||
const { ESLint } = require('eslint');
|
||||
|
||||
@@ -16,12 +16,12 @@
|
||||
|
||||
import chalk from 'chalk';
|
||||
import { ESLint } from 'eslint';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { join as joinPath, relative as relativePath } from 'path';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { PackageGraph } from '../../lib/monorepo';
|
||||
|
||||
export async function command(cmd: Command) {
|
||||
export async function command(opts: OptionValues) {
|
||||
const packages = await PackageGraph.listTargetPackages();
|
||||
|
||||
const eslint = new ESLint({
|
||||
@@ -74,7 +74,7 @@ export async function command(cmd: Command) {
|
||||
stderr.cursorTo(0);
|
||||
}
|
||||
|
||||
if (cmd.json) {
|
||||
if (opts.json) {
|
||||
console.log(JSON.stringify(deprecations, null, 2));
|
||||
} else {
|
||||
for (const d of deprecations) {
|
||||
|
||||
@@ -14,19 +14,19 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { startBackend } from './startBackend';
|
||||
import { startFrontend } from './startFrontend';
|
||||
import { findRoleFromCommand } from '../../lib/role';
|
||||
|
||||
export async function command(cmd: Command): Promise<void> {
|
||||
const role = await findRoleFromCommand(cmd);
|
||||
export async function command(opts: OptionValues): Promise<void> {
|
||||
const role = await findRoleFromCommand(opts);
|
||||
|
||||
const options = {
|
||||
configPaths: cmd.config as string[],
|
||||
checksEnabled: Boolean(cmd.check),
|
||||
inspectEnabled: Boolean(cmd.inspect),
|
||||
inspectBrkEnabled: Boolean(cmd.inspectBrk),
|
||||
configPaths: opts.config as string[],
|
||||
checksEnabled: Boolean(opts.check),
|
||||
inspectEnabled: Boolean(opts.inspect),
|
||||
inspectBrkEnabled: Boolean(opts.inspectBrk),
|
||||
};
|
||||
|
||||
switch (role) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { Command, OptionValues } from 'commander';
|
||||
import { paths } from '../lib/paths';
|
||||
import { runCheck } from '../lib/run';
|
||||
|
||||
@@ -27,14 +27,14 @@ function includesAnyOf(hayStack: string[], ...needles: string[]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (_opts: OptionValues, cmd: Command) => {
|
||||
// all args are forwarded to jest
|
||||
let parent = cmd;
|
||||
while (parent.parent) {
|
||||
parent = parent.parent;
|
||||
}
|
||||
const rawArgs = parent.rawArgs as string[];
|
||||
const args = rawArgs.slice(rawArgs.indexOf('test') + 1);
|
||||
const allArgs = parent.args as string[];
|
||||
const args = allArgs.slice(allArgs.indexOf('test') + 1);
|
||||
|
||||
// Only include our config if caller isn't passing their own config
|
||||
if (!includesAnyOf(args, '-c', '--config')) {
|
||||
@@ -19,7 +19,7 @@ import chalk from 'chalk';
|
||||
import ora from 'ora';
|
||||
import semver from 'semver';
|
||||
import minimatch from 'minimatch';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { isError, NotFoundError } from '@backstage/errors';
|
||||
import { resolve as resolvePath } from 'path';
|
||||
import { run } from '../../lib/run';
|
||||
@@ -55,10 +55,10 @@ type PkgVersionInfo = {
|
||||
location: string;
|
||||
};
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (opts: OptionValues) => {
|
||||
const lockfilePath = paths.resolveTargetRoot('yarn.lock');
|
||||
const lockfile = await Lockfile.load(lockfilePath);
|
||||
let pattern = cmd.pattern;
|
||||
let pattern = opts.pattern;
|
||||
|
||||
if (!pattern) {
|
||||
console.log(`Using default pattern glob ${DEFAULT_PATTERN_GLOB}`);
|
||||
@@ -70,14 +70,14 @@ export default async (cmd: Command) => {
|
||||
let findTargetVersion: (name: string) => Promise<string>;
|
||||
let releaseManifest: ReleaseManifest;
|
||||
// Specific release specified. Be strict when resolving versions
|
||||
if (semver.valid(cmd.release)) {
|
||||
releaseManifest = await getManifestByVersion({ version: cmd.release });
|
||||
if (semver.valid(opts.release)) {
|
||||
releaseManifest = await getManifestByVersion({ version: opts.release });
|
||||
findTargetVersion = createStrictVersionFinder({
|
||||
releaseManifest,
|
||||
});
|
||||
} else {
|
||||
// Release line specified. Be lenient when resolving versions.
|
||||
if (cmd.release === 'next') {
|
||||
if (opts.release === 'next') {
|
||||
const next = await getManifestByReleaseLine({
|
||||
releaseLine: 'next',
|
||||
});
|
||||
@@ -90,11 +90,11 @@ export default async (cmd: Command) => {
|
||||
: main;
|
||||
} else {
|
||||
releaseManifest = await getManifestByReleaseLine({
|
||||
releaseLine: cmd.release,
|
||||
releaseLine: opts.release,
|
||||
});
|
||||
}
|
||||
findTargetVersion = createVersionFinder({
|
||||
releaseLine: cmd.releaseLine,
|
||||
releaseLine: opts.releaseLine,
|
||||
releaseManifest,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { Lockfile } from '../../lib/versioning';
|
||||
import { paths } from '../../lib/paths';
|
||||
import partition from 'lodash/partition';
|
||||
@@ -47,7 +47,7 @@ export const forbiddenDuplicatesFilter = (name: string) =>
|
||||
FORBID_DUPLICATES.some(pattern => pattern.test(name)) &&
|
||||
!ALLOW_DUPLICATES.some(pattern => pattern.test(name));
|
||||
|
||||
export default async (cmd: Command) => {
|
||||
export default async (cmd: OptionValues) => {
|
||||
const fix = Boolean(cmd.fix);
|
||||
|
||||
let success = true;
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
* @packageDocumentation
|
||||
*/
|
||||
|
||||
import program from 'commander';
|
||||
import { program } from 'commander';
|
||||
import chalk from 'chalk';
|
||||
import { exitWithError } from './lib/errors';
|
||||
import { version } from './lib/version';
|
||||
|
||||
@@ -79,9 +79,10 @@ describe('getRoleFromPackage', () => {
|
||||
|
||||
describe('findRoleFromCommand', () => {
|
||||
function mkCommand(args: string) {
|
||||
return new Command()
|
||||
const parsed = new Command()
|
||||
.option('--role <role>', 'test role')
|
||||
.parse(['node', 'entry.js', ...args.split(' ')]) as Command;
|
||||
return parsed.opts();
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import { z } from 'zod';
|
||||
import fs from 'fs-extra';
|
||||
import { Command } from 'commander';
|
||||
import { OptionValues } from 'commander';
|
||||
import { paths } from '../paths';
|
||||
import { PackageRole, PackageRoleInfo } from './types';
|
||||
|
||||
@@ -108,9 +108,11 @@ export function getRoleFromPackage(pkgJson: unknown): PackageRole | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export async function findRoleFromCommand(cmd: Command): Promise<PackageRole> {
|
||||
if (cmd.role) {
|
||||
return getRoleInfo(cmd.role)?.role;
|
||||
export async function findRoleFromCommand(
|
||||
opts: OptionValues,
|
||||
): Promise<PackageRole> {
|
||||
if (opts.role) {
|
||||
return getRoleInfo(opts.role)?.role;
|
||||
}
|
||||
|
||||
const pkg = await fs.readJson(paths.resolveTarget('package.json'));
|
||||
|
||||
Reference in New Issue
Block a user