From 407245eb4eef8ce3018476847938f9824e7ca0bc Mon Sep 17 00:00:00 2001 From: Konstantin Konstantinov Date: Fri, 3 Oct 2025 13:57:21 +0300 Subject: [PATCH 1/2] add lefthook - lint fix, code format, build and test pre-commit, auto npm install on checkout and merge --- lefthook.yml | 51 ++++++++++++++ package-lock.json | 164 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 5 +- 3 files changed, 219 insertions(+), 1 deletion(-) create mode 100644 lefthook.yml diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 00000000..4814f968 --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,51 @@ +# 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-commit: + follow: true + parallel: true + jobs: + - name: 'Lint' + run: npx --no-install eslint --fix "{staged_files}" + glob: + - '*.ts' + - '*.js' + - '*.tsx' + - '*.jsx' + stage_fixed: true + + - name: 'Code Formatting' + run: npx --no-install prettier --write --ignore-unknown "{staged_files}" + stage_fixed: true + + - name: 'Build' + run: npm run build + stage_fixed: true + + - name: 'Test' + run: npm run fetch:spec-types && npx --no-install jest --passWithNoTests "{staged_files}" + glob: '*.{ts,js,json}' + stage_fixed: true + +post-checkout: + jobs: + - name: 'Install Dependencies' + run: npm install + +post-merge: + jobs: + - name: 'Install Dependencies' + run: npm install diff --git a/package-lock.json b/package-lock.json index f400735f..3e1368e5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -38,6 +38,7 @@ "eslint": "^9.8.0", "eslint-config-prettier": "^10.1.8", "jest": "^29.7.0", + "lefthook": "^1.13.6", "prettier": "3.6.2", "supertest": "^7.0.0", "ts-jest": "^29.2.4", @@ -4956,6 +4957,169 @@ "node": ">=6" } }, + "node_modules/lefthook": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook/-/lefthook-1.13.6.tgz", + "integrity": "sha512-ojj4/4IJ29Xn4drd5emqVgilegAPN3Kf0FQM2p/9+lwSTpU+SZ1v4Ig++NF+9MOa99UKY8bElmVrLhnUUNFh5g==", + "dev": true, + "hasInstallScript": true, + "license": "MIT", + "bin": { + "lefthook": "bin/index.js" + }, + "optionalDependencies": { + "lefthook-darwin-arm64": "1.13.6", + "lefthook-darwin-x64": "1.13.6", + "lefthook-freebsd-arm64": "1.13.6", + "lefthook-freebsd-x64": "1.13.6", + "lefthook-linux-arm64": "1.13.6", + "lefthook-linux-x64": "1.13.6", + "lefthook-openbsd-arm64": "1.13.6", + "lefthook-openbsd-x64": "1.13.6", + "lefthook-windows-arm64": "1.13.6", + "lefthook-windows-x64": "1.13.6" + } + }, + "node_modules/lefthook-darwin-arm64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-darwin-arm64/-/lefthook-darwin-arm64-1.13.6.tgz", + "integrity": "sha512-m6Lb77VGc84/Qo21Lhq576pEvcgFCnvloEiP02HbAHcIXD0RTLy9u2yAInrixqZeaz13HYtdDaI7OBYAAdVt8A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/lefthook-darwin-x64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-darwin-x64/-/lefthook-darwin-x64-1.13.6.tgz", + "integrity": "sha512-CoRpdzanu9RK3oXR1vbEJA5LN7iB+c7hP+sONeQJzoOXuq4PNKVtEaN84Gl1BrVtCNLHWFAvCQaZPPiiXSy8qg==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ] + }, + "node_modules/lefthook-freebsd-arm64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-freebsd-arm64/-/lefthook-freebsd-arm64-1.13.6.tgz", + "integrity": "sha512-X4A7yfvAJ68CoHTqP+XvQzdKbyd935sYy0bQT6Ajz7FL1g7hFiro8dqHSdPdkwei9hs8hXeV7feyTXbYmfjKQQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/lefthook-freebsd-x64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-freebsd-x64/-/lefthook-freebsd-x64-1.13.6.tgz", + "integrity": "sha512-ai2m+Sj2kGdY46USfBrCqLKe9GYhzeq01nuyDYCrdGISePeZ6udOlD1k3lQKJGQCHb0bRz4St0r5nKDSh1x/2A==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "freebsd" + ] + }, + "node_modules/lefthook-linux-arm64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-linux-arm64/-/lefthook-linux-arm64-1.13.6.tgz", + "integrity": "sha512-cbo4Wtdq81GTABvikLORJsAWPKAJXE8Q5RXsICFUVznh5PHigS9dFW/4NXywo0+jfFPCT6SYds2zz4tCx6DA0Q==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/lefthook-linux-x64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-linux-x64/-/lefthook-linux-x64-1.13.6.tgz", + "integrity": "sha512-uJl9vjCIIBTBvMZkemxCE+3zrZHlRO7Oc+nZJ+o9Oea3fu+W82jwX7a7clw8jqNfaeBS+8+ZEQgiMHWCloTsGw==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "linux" + ] + }, + "node_modules/lefthook-openbsd-arm64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-openbsd-arm64/-/lefthook-openbsd-arm64-1.13.6.tgz", + "integrity": "sha512-7r153dxrNRQ9ytRs2PmGKKkYdvZYFPre7My7XToSTiRu5jNCq++++eAKVkoyWPduk97dGIA+YWiEr5Noe0TK2A==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/lefthook-openbsd-x64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-openbsd-x64/-/lefthook-openbsd-x64-1.13.6.tgz", + "integrity": "sha512-Z+UhLlcg1xrXOidK3aLLpgH7KrwNyWYE3yb7ITYnzJSEV8qXnePtVu8lvMBHs/myzemjBzeIr/U/+ipjclR06g==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "openbsd" + ] + }, + "node_modules/lefthook-windows-arm64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-windows-arm64/-/lefthook-windows-arm64-1.13.6.tgz", + "integrity": "sha512-Uxef6qoDxCmUNQwk8eBvddYJKSBFglfwAY9Y9+NnnmiHpWTjjYiObE9gT2mvGVpEgZRJVAatBXc+Ha5oDD/OgQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, + "node_modules/lefthook-windows-x64": { + "version": "1.13.6", + "resolved": "https://registry.npmjs.org/lefthook-windows-x64/-/lefthook-windows-x64-1.13.6.tgz", + "integrity": "sha512-mOZoM3FQh3o08M8PQ/b3IYuL5oo36D9ehczIw1dAgp1Ly+Tr4fJ96A+4SEJrQuYeRD4mex9bR7Ps56I73sBSZA==", + "cpu": [ + "x64" + ], + "dev": true, + "license": "MIT", + "optional": true, + "os": [ + "win32" + ] + }, "node_modules/leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", diff --git a/package.json b/package.json index 93efd9a6..80434200 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,8 @@ "examples:simple-server:w": "tsx --watch src/examples/server/simpleStreamableHttp.ts --oauth", "prepack": "npm run build:esm && npm run build:cjs", "lint": "eslint src/ && prettier --check .", + "lint:fix": "eslint src/ --fix && prettier --write .", + "prepare": "npx --no-install lefthook install", "test": "npm run fetch:spec-types && jest", "start": "npm run server", "server": "tsx watch --clear-screen=false src/cli.ts server", @@ -90,8 +92,9 @@ "@types/ws": "^8.5.12", "eslint": "^9.8.0", "eslint-config-prettier": "^10.1.8", - "prettier": "3.6.2", "jest": "^29.7.0", + "lefthook": "^1.13.6", + "prettier": "3.6.2", "supertest": "^7.0.0", "ts-jest": "^29.2.4", "tsx": "^4.16.5", From 1b5319ec448b19ce55ea9a83e0abe8ccf4e11df3 Mon Sep 17 00:00:00 2001 From: Konstantin Konstantinov Date: Wed, 8 Oct 2025 08:53:08 +0300 Subject: [PATCH 2/2] move pre-commit to pre-push --- lefthook.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lefthook.yml b/lefthook.yml index 4814f968..04158edf 100644 --- a/lefthook.yml +++ b/lefthook.yml @@ -14,7 +14,7 @@ output: - execution_info # Print `EXECUTE > ...` logging - skips # Print "skip" (i.e. no files matched) -pre-commit: +pre-push: follow: true parallel: true jobs: