diff --git a/.changeset/popular-zebras-reply.md b/.changeset/popular-zebras-reply.md new file mode 100644 index 0000000000..80d6da993b --- /dev/null +++ b/.changeset/popular-zebras-reply.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Internal change to migrate `lint` to the new module system. diff --git a/packages/cli/src/alpha.ts b/packages/cli/src/alpha.ts index d6189a4256..49e739bbdc 100644 --- a/packages/cli/src/alpha.ts +++ b/packages/cli/src/alpha.ts @@ -29,5 +29,6 @@ import chalk from 'chalk'; initializer.add(import('./modules/build/alpha')); initializer.add(import('./modules/migrate/alpha')); initializer.add(import('./modules/test/alpha')); + initializer.add(import('./modules/lint/alpha')); await initializer.run(); })(); diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index ee73c071f8..9a76711d08 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -31,6 +31,10 @@ import { registerRepoCommands as registerRepoTestCommands, registerPackageCommands as registerPackageTestCommands, } from '../modules/test'; +import { + registerPackageCommands as registerPackageLintCommands, + registerRepoCommands as registerRepoLintCommands, +} from '../modules/lint'; export function registerRepoCommand(program: Command) { const command = program @@ -39,33 +43,7 @@ export function registerRepoCommand(program: Command) { registerRepoBuildCommands(command); registerRepoTestCommands(command); - - command - .command('lint') - .description('Lint all packages in the project') - .option( - '--format ', - 'Lint report output format', - 'eslint-formatter-friendly', - ) - .option( - '--output-file ', - 'Write the lint report to a file instead of stdout', - ) - .option( - '--since ', - 'Only lint packages that changed since the specified ref', - ) - .option( - '--successCache', - 'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run', - ) - .option( - '--successCacheDir ', - 'Set the success cache location, (default: node_modules/.cache/backstage-cli)', - ) - .option('--fix', 'Attempt to automatically fix violations') - .action(lazy(() => import('./repo/lint'), 'command')); + registerRepoLintCommands(command); command .command('fix') @@ -115,25 +93,7 @@ export function registerScriptCommand(program: Command) { registerPackageBuildCommands(command); registerPackageTestCommands(command); - command - .command('lint [directories...]') - .option( - '--format ', - 'Lint report output format', - 'eslint-formatter-friendly', - ) - .option( - '--output-file ', - 'Write the lint report to a file instead of stdout', - ) - .option('--fix', 'Attempt to automatically fix violations') - .option( - '--max-warnings ', - 'Fail if more than this number of warnings. -1 allows warnings. (default: -1)', - ) - .description('Lint a package') - .action(lazy(() => import('./lint'), 'default')); - + registerPackageLintCommands(command); command .command('clean') .description('Delete cache directories') diff --git a/packages/cli/src/modules/lint/alpha.ts b/packages/cli/src/modules/lint/alpha.ts new file mode 100644 index 0000000000..8703e73b5e --- /dev/null +++ b/packages/cli/src/modules/lint/alpha.ts @@ -0,0 +1,86 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { createCliPlugin } from '../../wiring/factory'; +import { Command } from 'commander'; +import { lazy } from '../../lib/lazy'; + +export default createCliPlugin({ + pluginId: 'lint', + init: async reg => { + reg.addCommand({ + path: ['package', 'lint'], + description: 'Lint a package', + execute: async ({ args }) => { + const command = new Command(); + command.arguments('[directories...]'); + command.option('--fix', 'Attempt to automatically fix violations'); + command.option( + '--format ', + 'Lint report output format', + 'eslint-formatter-friendly', + ); + command.option( + '--output-file ', + 'Write the lint report to a file instead of stdout', + ); + command.option( + '--max-warnings ', + 'Fail if more than this number of warnings. -1 allows warnings. (default: 0)', + ); + command.description('Lint a package'); + command.action( + lazy(() => import('./commands/package/lint'), 'default'), + ); + + await command.parseAsync(args, { from: 'user' }); + }, + }); + + reg.addCommand({ + path: ['repo', 'lint'], + description: 'Lint a repository', + execute: async ({ args }) => { + const command = new Command(); + command.option('--fix', 'Attempt to automatically fix violations'); + command.option( + '--format ', + 'Lint report output format', + 'eslint-formatter-friendly', + ); + command.option( + '--output-file ', + 'Write the lint report to a file instead of stdout', + ); + command.option( + '--successCache', + 'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run', + ); + command.option( + '--successCacheDir ', + 'Set the success cache location, (default: node_modules/.cache/backstage-cli)', + ); + command.option( + '--since ', + 'Only lint packages that changed since the specified ref', + ); + command.description('Lint a repository'); + command.action(lazy(() => import('./commands/repo/lint'), 'command')); + + await command.parseAsync(args, { from: 'user' }); + }, + }); + }, +}); diff --git a/packages/cli/src/commands/lint.ts b/packages/cli/src/modules/lint/commands/package/lint.ts similarity index 97% rename from packages/cli/src/commands/lint.ts rename to packages/cli/src/modules/lint/commands/package/lint.ts index cd5c265e72..a1e45c0113 100644 --- a/packages/cli/src/commands/lint.ts +++ b/packages/cli/src/modules/lint/commands/package/lint.ts @@ -16,7 +16,7 @@ import fs from 'fs-extra'; import { OptionValues } from 'commander'; -import { paths } from '../lib/paths'; +import { paths } from '../../../../lib/paths'; import { ESLint } from 'eslint'; export default async (directories: string[], opts: OptionValues) => { diff --git a/packages/cli/src/commands/repo/lint.ts b/packages/cli/src/modules/lint/commands/repo/lint.ts similarity index 96% rename from packages/cli/src/commands/repo/lint.ts rename to packages/cli/src/modules/lint/commands/repo/lint.ts index f78b51ea5d..15a3584020 100644 --- a/packages/cli/src/commands/repo/lint.ts +++ b/packages/cli/src/modules/lint/commands/repo/lint.ts @@ -24,10 +24,10 @@ import { BackstagePackageJson, Lockfile, } from '@backstage/cli-node'; -import { paths } from '../../lib/paths'; -import { runWorkerQueueThreads } from '../../lib/parallel'; -import { createScriptOptionsParser } from './optionsParser'; -import { SuccessCache } from '../../lib/cache/SuccessCache'; +import { paths } from '../../../../lib/paths'; +import { runWorkerQueueThreads } from '../../../../lib/parallel'; +import { createScriptOptionsParser } from '../../../../commands/repo/optionsParser'; +import { SuccessCache } from '../../../../lib/cache/SuccessCache'; function depCount(pkg: BackstagePackageJson) { const deps = pkg.dependencies ? Object.keys(pkg.dependencies).length : 0; diff --git a/packages/cli/src/modules/lint/index.ts b/packages/cli/src/modules/lint/index.ts new file mode 100644 index 0000000000..e2bfcd0779 --- /dev/null +++ b/packages/cli/src/modules/lint/index.ts @@ -0,0 +1,67 @@ +/* + * Copyright 2025 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Command } from 'commander'; +import { lazy } from '../../lib/lazy'; + +export function registerPackageCommands(command: Command) { + command + .command('lint [directories...]') + .option( + '--format ', + 'Lint report output format', + 'eslint-formatter-friendly', + ) + .option( + '--output-file ', + 'Write the lint report to a file instead of stdout', + ) + .option('--fix', 'Attempt to automatically fix violations') + .option( + '--max-warnings ', + 'Fail if more than this number of warnings. -1 allows warnings. (default: 0)', + ) + .description('Lint a package') + .action(lazy(() => import('./commands/package/lint'), 'default')); +} + +export function registerRepoCommands(command: Command) { + command + .command('lint') + .description('Lint all packages in the project') + .option( + '--format ', + 'Lint report output format', + 'eslint-formatter-friendly', + ) + .option( + '--output-file ', + 'Write the lint report to a file instead of stdout', + ) + .option( + '--since ', + 'Only lint packages that changed since the specified ref', + ) + .option( + '--successCache', + 'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run', + ) + .option( + '--successCacheDir ', + 'Set the success cache location, (default: node_modules/.cache/backstage-cli)', + ) + .option('--fix', 'Attempt to automatically fix violations') + .action(lazy(() => import('./commands/repo/lint'), 'command')); +}