diff --git a/.changeset/rotten-rockets-deny.md b/.changeset/rotten-rockets-deny.md new file mode 100644 index 0000000000..58dec57c32 --- /dev/null +++ b/.changeset/rotten-rockets-deny.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Running `repo lint` with the `--successCache` flag now respects `.gitinore`, and it ignores projects without a `lint` script. diff --git a/packages/cli/package.json b/packages/cli/package.json index ce7d2d9ac8..5279ba9a70 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -109,6 +109,7 @@ "git-url-parse": "^15.0.0", "glob": "^7.1.7", "global-agent": "^3.0.0", + "globby": "^11.1.0", "handlebars": "^4.7.3", "html-webpack-plugin": "^5.3.1", "inquirer": "^8.2.0", diff --git a/packages/cli/src/commands/repo/lint.ts b/packages/cli/src/commands/repo/lint.ts index 8e1f6d52d7..1895597e96 100644 --- a/packages/cli/src/commands/repo/lint.ts +++ b/packages/cli/src/commands/repo/lint.ts @@ -117,7 +117,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise { cacheContext.lockfile.getDependencyTreeHash(pkg.packageJson.name), ); hash.update('\0'); - hash.update(JSON.stringify(lintOptions)); + hash.update(JSON.stringify(lintOptions ?? {})); hash.update('\0'); hash.update(process.version); // Node.js version hash.update('\0'); @@ -131,18 +131,24 @@ export async function command(opts: OptionValues, cmd: Command): Promise { ); const resultsList = await runWorkerQueueThreads({ - items, + items: items.filter(item => item.lintOptions), // Filter out packages without lint script workerData: { fix: Boolean(opts.fix), format: opts.format as string | undefined, shouldCache: Boolean(cacheContext), successCache: cacheContext?.cache, + rootDir: paths.targetRoot, }, - workerFactory: async ({ fix, format, shouldCache, successCache }) => { + workerFactory: async ({ + fix, + format, + shouldCache, + successCache, + rootDir, + }) => { const { ESLint } = require('eslint') as typeof import('eslint'); const crypto = require('crypto') as typeof import('crypto'); - const recursiveReadDir = - require('recursive-readdir') as typeof import('recursive-readdir'); + const globby = require('globby') as typeof import('globby'); const { readFile } = require('fs/promises') as typeof import('fs/promises'); const { relative: workerRelativePath } = @@ -172,7 +178,11 @@ export async function command(opts: OptionValues, cmd: Command): Promise { let sha: string | undefined = undefined; if (shouldCache) { - const result = await recursiveReadDir(fullDir); + const result = await globby(relativeDir, { + gitignore: true, + onlyFiles: true, + cwd: rootDir, + }); const hash = crypto.createHash('sha1'); hash.update(parentHash!); diff --git a/yarn.lock b/yarn.lock index f998b87e11..6d21299dac 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3991,6 +3991,7 @@ __metadata: git-url-parse: ^15.0.0 glob: ^7.1.7 global-agent: ^3.0.0 + globby: ^11.1.0 handlebars: ^4.7.3 html-webpack-plugin: ^5.3.1 inquirer: ^8.2.0