From 0c5429ea2d5a43ee22c901ccc1ace4665b893536 Mon Sep 17 00:00:00 2001 From: Jacek Radko Date: Fri, 15 Nov 2024 14:05:28 -0600 Subject: [PATCH] fix(repo): PR linter optimization (#4584) --- .github/workflows/pr-title-linter.yml | 9 +++------ commitlint.config.ts | 26 +++++++++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr-title-linter.yml b/.github/workflows/pr-title-linter.yml index 3578692135..974d90c9d0 100644 --- a/.github/workflows/pr-title-linter.yml +++ b/.github/workflows/pr-title-linter.yml @@ -20,14 +20,11 @@ jobs: show-progress: false sparse-checkout: | commitlint.config.ts - package.json packages/*/package.json sparse-checkout-cone-mode: false - - name: Install PNPM - uses: pnpm/action-setup@v4 - - name: Lint Pull Request Title run: | - pnpm install - echo '${{ github.event.pull_request.title }}' | pnpm commitlint --config commitlint.config.ts + npm init --scope=clerk --yes + npm i --save-dev @commitlint/config-conventional @commitlint/cli globby --audit=false --fund=false + echo '${{ github.event.pull_request.title }}' | npm exec @commitlint/cli -- --config commitlint.config.ts \ No newline at end of file diff --git a/commitlint.config.ts b/commitlint.config.ts index c187987d0a..17a8e933ac 100644 --- a/commitlint.config.ts +++ b/commitlint.config.ts @@ -1,11 +1,27 @@ // All imports must be accounted for per `npm i` in .github/workflows/pr-title-linter.yml -import { globbySync } from 'globby'; -import { readFileSync } from 'node:fs'; +import { readdirSync, readFileSync, statSync } from 'node:fs'; +import { join } from 'node:path'; const getPackageNames = () => { - const files = globbySync('./packages/*/package.json'); - const names = files.map(f => JSON.parse(readFileSync(f, 'utf8')).name as string); - return names.map(n => n.split('/').pop()); + const packagesDir = './packages'; + const entries = readdirSync(packagesDir); + const packageNames = entries + .filter(entry => { + const fullPath = join(packagesDir, entry); + return statSync(fullPath).isDirectory(); + }) + .map(dir => { + const packageJsonPath = join(packagesDir, dir, 'package.json'); + try { + const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf8')); + return packageJson.name.split('/').pop(); + } catch { + // Ignore directories without a package.json + return null; + } + }) + .filter(Boolean); + return packageNames; }; const Configuration = {