diff --git a/.gitignore b/.gitignore index b827ee5e1..462b6735b 100644 --- a/.gitignore +++ b/.gitignore @@ -52,3 +52,5 @@ dist/ # Conformance test results results/ + +.lefthook-local.yml diff --git a/lefthook-local.example.yml b/lefthook-local.example.yml new file mode 100644 index 000000000..9bbfcc44c --- /dev/null +++ b/lefthook-local.example.yml @@ -0,0 +1,24 @@ +# Optional local lefthook configuration +# To enable this: +# cp lefthook-local.example.yml lefthook-local.yml + +pre-commit: + parallel: true + jobs: + - name: 'Typecheck' + run: pnpm typecheck:all + stage_fixed: true + + - name: 'Lint Fix & Format' + run: pnpm lint:fix:all + stage_fixed: true + +post-checkout: + jobs: + - name: 'Install Dependencies' + run: pnpm install + +post-merge: + jobs: + - name: 'Install Dependencies' + run: pnpm install diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 000000000..016a5b0f8 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,47 @@ +# lefthook.yml +# Configuration reference: https://lefthook.dev/configuration/ + +assert_lefthook_installed: true + +output: + - meta # Print lefthook version + - summary # Print summary block (successful and failed steps) + - empty_summary # Print summary heading when there are no steps to run + - success # Print successful steps + - failure # Print failed steps printing + - execution # Print any execution logs (but prints if the execution failed) + - execution_out # Print execution output (but still prints failed commands output) + - execution_info # Print `EXECUTE > ...` logging + - skips # Print "skip" (i.e. no files matched) + +pre-push: + follow: true + parallel: true + jobs: + - name: 'Typecheck' + run: pnpm run typecheck:all + fail_text: | + 💡 To catch typechecking issues earlier, enable the pre-commit hook: + cp lefthook-local.example.yml lefthook-local.yml + + - name: 'Lint' + run: pnpm run lint:all + fail_text: | + 💡 To catch linting issues earlier, enable the pre-commit hook: + cp lefthook-local.example.yml lefthook-local.yml + + - name: 'Build' + run: pnpm run build:all + fail_text: | + 💡 To catch build issues earlier, enable the pre-commit hook: + cp lefthook-local.example.yml lefthook-local.yml + +post-checkout: + jobs: + - name: 'Install Dependencies' + run: pnpm install + +post-merge: + jobs: + - name: 'Install Dependencies' + run: pnpm install diff --git a/package.json b/package.json index b389c51a7..025709b2e 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "lint:fix:all": "pnpm sync:snippets && pnpm -r lint:fix", "check:all": "pnpm -r typecheck && pnpm -r lint && pnpm run docs:check", "test:all": "pnpm -r test", + "prepare": "npx --no-install lefthook install", "test:conformance:client": "pnpm --filter @modelcontextprotocol/test-conformance run test:conformance:client", "test:conformance:client:all": "pnpm --filter @modelcontextprotocol/test-conformance run test:conformance:client:all", "test:conformance:client:run": "pnpm --filter @modelcontextprotocol/test-conformance run test:conformance:client:run", @@ -43,6 +44,7 @@ "test:conformance:all": "pnpm run test:conformance:client:all && pnpm run test:conformance:server:all" }, "devDependencies": { + "lefthook": "^2.0.16", "@cfworker/json-schema": "catalog:runtimeShared", "@changesets/changelog-github": "^0.5.2", "@changesets/cli": "^2.29.8", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cc778c3cf..b6df12303 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -194,6 +194,9 @@ importers: fast-glob: specifier: ^3.3.3 version: 3.3.3 + lefthook: + specifier: ^2.0.16 + version: 2.0.16 prettier: specifier: catalog:devTools version: 3.6.2 @@ -3601,6 +3604,60 @@ packages: resolution: {integrity: sha512-3BeXMoiOhpOwu62CiVpO6lxfq4eS6KMYfQdMsN/2kUCRNuF2YiEr7u0HLHaQU+O4Xu8YXE3bHVkwaQ85i72EuA==} engines: {node: '>=20.0.0'} + lefthook-darwin-arm64@2.0.16: + resolution: {integrity: sha512-kjVHkD7rfPa7M0aKJSx/yatdV9uC6o3cJyzM9zk7cg5HD7alSwchFalgF/P0w6nt7C02rAUx8C05qiWCDWaKeA==} + cpu: [arm64] + os: [darwin] + + lefthook-darwin-x64@2.0.16: + resolution: {integrity: sha512-tbJ0mdT49DNRLqknro0BvWrYNC23TTcqBJFQnQ32pq1/H9B87bTNKvKKAtogp/saxfHUzkIq1i3twZlBZ3G3Xw==} + cpu: [x64] + os: [darwin] + + lefthook-freebsd-arm64@2.0.16: + resolution: {integrity: sha512-wa1KFD5tSUhw3tuetVef/BCSxbbmS7auTDNdoLx3WFeuN5RS15woSN9+E8GPGOOY1g2HCsgdLrhrexEomulfjQ==} + cpu: [arm64] + os: [freebsd] + + lefthook-freebsd-x64@2.0.16: + resolution: {integrity: sha512-UXowfn2e94AwNk9UuoePRK+qiF15jZsssiyA15VK5GTtxpn6Sn+Z2QFciofxJczXXxM4abaf7qgx2OoJBt32VA==} + cpu: [x64] + os: [freebsd] + + lefthook-linux-arm64@2.0.16: + resolution: {integrity: sha512-U355elz4Z0AHSVqxfcglN09TGR86ov/GtYlliDknci2mmz6EWLiD3dTYnqJiwa4dYxqmuCDc/DvAL9rgb3YJiQ==} + cpu: [arm64] + os: [linux] + + lefthook-linux-x64@2.0.16: + resolution: {integrity: sha512-7eAvBeWGAgjOKZ23OQbjJINLPImDIuDeX8dXOfk+aI6IFt2X6KCzRkp+ASUvGQtrPuNZQZT43EhW0/1jZU14ZQ==} + cpu: [x64] + os: [linux] + + lefthook-openbsd-arm64@2.0.16: + resolution: {integrity: sha512-Fcd+E17ZkWGnRSQINb5gf+rNy2So5PYn5mBljiC31dl+TgWM8Wy46mSEGveHo7lKCO3q+DkmHIa50Qm58G03AQ==} + cpu: [arm64] + os: [openbsd] + + lefthook-openbsd-x64@2.0.16: + resolution: {integrity: sha512-uL5nOkz8eBtQHped0/tB5X8clZ5kfnyjQrv1fpKbGAjeFHI2J+GmRqcn6Awq2IeuBbQvkyV6jDjpATyHBp5mCA==} + cpu: [x64] + os: [openbsd] + + lefthook-windows-arm64@2.0.16: + resolution: {integrity: sha512-U61bNWzD6Vd2kjuJ7b4voPfTQ4mlBFOyTpCU3k/h0YjpKDQEFT1T5fDKkDothdnw/JVDSgrclIcfAY7Jyr/UIg==} + cpu: [arm64] + os: [win32] + + lefthook-windows-x64@2.0.16: + resolution: {integrity: sha512-dCHi2+hebhPI0LQUGRNjPMsGRyXhrTN3Y/b8M4HO8KVyGamKB3Yemf67ya81tZopDkxNVy5XUBXLYWKGhnAfLQ==} + cpu: [x64] + os: [win32] + + lefthook@2.0.16: + resolution: {integrity: sha512-ABs3M5V9c4nqxFnZO509HXuQTu8GM8hmqc9ruV0acQ81yKlxEq70MRoYP5Z1dr5le326X8vA5qj3arJA36yE3A==} + hasBin: true + levn@0.4.1: resolution: {integrity: sha512-+bT2uH4E5LGE7h/n3evcS/sQlJXCpIp6ym8OWJ5eV6+67Dsql/LaaT7qJBAt2rzfoa/5QBGBhxDix1dMt2kQKQ==} engines: {node: '>= 0.8.0'} @@ -7126,6 +7183,49 @@ snapshots: kysely@0.28.9: {} + lefthook-darwin-arm64@2.0.16: + optional: true + + lefthook-darwin-x64@2.0.16: + optional: true + + lefthook-freebsd-arm64@2.0.16: + optional: true + + lefthook-freebsd-x64@2.0.16: + optional: true + + lefthook-linux-arm64@2.0.16: + optional: true + + lefthook-linux-x64@2.0.16: + optional: true + + lefthook-openbsd-arm64@2.0.16: + optional: true + + lefthook-openbsd-x64@2.0.16: + optional: true + + lefthook-windows-arm64@2.0.16: + optional: true + + lefthook-windows-x64@2.0.16: + optional: true + + lefthook@2.0.16: + optionalDependencies: + lefthook-darwin-arm64: 2.0.16 + lefthook-darwin-x64: 2.0.16 + lefthook-freebsd-arm64: 2.0.16 + lefthook-freebsd-x64: 2.0.16 + lefthook-linux-arm64: 2.0.16 + lefthook-linux-x64: 2.0.16 + lefthook-openbsd-arm64: 2.0.16 + lefthook-openbsd-x64: 2.0.16 + lefthook-windows-arm64: 2.0.16 + lefthook-windows-x64: 2.0.16 + levn@0.4.1: dependencies: prelude-ls: 1.2.1