From 90fba3caef9c6fefce2d7de9972dbe953489dfbd Mon Sep 17 00:00:00 2001 From: Yostra Date: Sat, 2 May 2026 02:37:37 +0200 Subject: [PATCH] enfore the format in the ci, script to fail locally if version are different --- .github/workflows/ci.yml | 1 - package.json | 4 ++-- packages/source-stripe/src/client.ts | 6 +++--- packages/source-stripe/src/index.ts | 2 +- scripts/check-prettier-version.js | 31 ++++++++++++++++++++++++++++ 5 files changed, 37 insertions(+), 7 deletions(-) create mode 100644 scripts/check-prettier-version.js diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36208e8cd..f33a5fd53 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,6 @@ jobs: - name: Formatting checks run: pnpm format:check - continue-on-error: true - name: Lint run: pnpm lint diff --git a/package.json b/package.json index 4456c4376..222dcabb3 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "test": "pnpm -r run test", "typecheck": "pnpm -r run typecheck", "lint": "pnpm -r run lint", - "format": "prettier --write .", - "format:check": "prettier --check .", + "format": "node scripts/check-prettier-version.js && prettier --write .", + "format:check": "node scripts/check-prettier-version.js && prettier --check .", "down": "docker compose down && (lsof -ti:4010,4020,5173 | xargs kill -9 2>/dev/null; true)", "dev:engine": "pnpm --filter @stripe/sync-engine dev", "dev": "docker compose up -d; concurrently -n engine,service,worker,dashboard -c cyan,green,yellow,magenta \"pnpm --filter @stripe/sync-engine dev\" \"pnpm --filter @stripe/sync-service dev:serve\" \"pnpm --filter @stripe/sync-service dev:worker\" \"pnpm --filter @stripe/sync-dashboard dev\"", diff --git a/packages/source-stripe/src/client.ts b/packages/source-stripe/src/client.ts index 0cc96b79f..cfb7a25e7 100644 --- a/packages/source-stripe/src/client.ts +++ b/packages/source-stripe/src/client.ts @@ -136,9 +136,9 @@ export function makeClient( async createWebhookEndpoint(params: { url: string - enabled_events: string[], - api_version: string, - metadata?: Record, + enabled_events: string[] + api_version: string + metadata?: Record }): Promise { const json = await requestWithRetry('POST', '/v1/webhook_endpoints', params) return StripeWebhookEndpointSchema.parse(json) diff --git a/packages/source-stripe/src/index.ts b/packages/source-stripe/src/index.ts index 8d86388a7..4f5d927ae 100644 --- a/packages/source-stripe/src/index.ts +++ b/packages/source-stripe/src/index.ts @@ -237,7 +237,7 @@ export function createStripeSource( url: config.webhook_url, enabled_events: ['*'], metadata: { managed_by: 'stripe-sync' }, - api_version: config.api_version ?? BUNDLED_API_VERSION + api_version: config.api_version ?? BUNDLED_API_VERSION, }) // Secret is only available at creation time — not on list/retrieve if (!config.webhook_secret && created.secret) { diff --git a/scripts/check-prettier-version.js b/scripts/check-prettier-version.js new file mode 100644 index 000000000..95024503e --- /dev/null +++ b/scripts/check-prettier-version.js @@ -0,0 +1,31 @@ +import { execSync } from 'node:child_process' +import { readFileSync } from 'node:fs' + +try { + // Read expected version directly from pnpm-lock.yaml + const lockStr = readFileSync(new URL('../pnpm-lock.yaml', import.meta.url), 'utf8') + + // Look for the exact resolved version of Prettier in the lockfile + const lockMatch = lockStr.match(/(?:^|\n)\s*prettier@(\d+\.\d+\.\d+):/) + + if (!lockMatch) { + throw new Error('Prettier version not found in pnpm-lock.yaml') + } + + const expectedVersion = lockMatch[1] + + // Get currently active version (this works because it's run from an npm script so prettier is in PATH) + const installedVersion = execSync('prettier --version', { encoding: 'utf8' }).trim() + + if (installedVersion !== expectedVersion) { + console.error( + `\x1b[31m❌ ERROR: Installed Prettier version (${installedVersion}) does not match the expected locked version in pnpm-lock.yaml (${expectedVersion}).\x1b[0m` + ) + console.error( + `\x1b[31m Please run 'pnpm install' to sync your local environment with CI and prevent formatting drift.\x1b[0m\n` + ) + process.exit(1) + } +} catch (error) { + // Silently ignore errors (like missing dependencies) so we don't break the formatting workflow +}