From 996257ce280c927e74ac8be64770db701e2ae2f6 Mon Sep 17 00:00:00 2001 From: "Alex.hxy" <1872591453@qq.com> Date: Fri, 3 Jan 2025 10:56:22 +0800 Subject: [PATCH] feat: check lock file --- .husky/pre-commit | 1 + scripts/check-lock.js | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 scripts/check-lock.js diff --git a/.husky/pre-commit b/.husky/pre-commit index 892610a36f..e8da06b624 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,2 +1,3 @@ node ./scripts/verifymail.js +node ./scripts/check-lock.js npx lint-staged diff --git a/scripts/check-lock.js b/scripts/check-lock.js new file mode 100644 index 0000000000..e5be9ae190 --- /dev/null +++ b/scripts/check-lock.js @@ -0,0 +1,10 @@ +const fs = require('fs'); +const path = require('path'); + +const lockFile = path.resolve(__dirname, '../pnpm-lock.yaml'); +const lockStr = fs.readFileSync(lockFile, 'utf8'); +const wrongRegistryMatch = lockStr.match(/tarball: https?:\/\/((?!registry\.npmjs\.org).*?)\//); +if (wrongRegistryMatch) { + console.error(`\nError: Wrong package resolve path! (Found wrong path: ${wrongRegistryMatch[1]}) Please check your npm registry and install again.\n`); + throw new Error(); +} \ No newline at end of file