From ed94e5dba167934f977dd815760984715273aa65 Mon Sep 17 00:00:00 2001 From: taoyiyue Date: Wed, 28 Feb 2024 19:54:54 +0800 Subject: [PATCH] chore: add package-lock checking --- husky.config.js | 3 ++- scripts/dev/check-lock.js | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 scripts/dev/check-lock.js diff --git a/husky.config.js b/husky.config.js index 8c5a3304..3031fc80 100644 --- a/husky.config.js +++ b/husky.config.js @@ -8,6 +8,7 @@ module.exports = { 'commit-msg': isWindows ? '' : `[[ -n $HUSKY_BYPASS ]] || commitlint -e $HUSKY_GIT_PARAMS --config ${commitLintConfig}`, - 'pre-commit': 'node ./scripts/dev/generate-all.js && npm run lint-staged && git add -A', + 'pre-commit': + 'node ./scripts/dev/check-lock.js && node ./scripts/dev/generate-all.js && npm run lint-staged && git add -A', }, }; diff --git a/scripts/dev/check-lock.js b/scripts/dev/check-lock.js new file mode 100644 index 00000000..b7a317d5 --- /dev/null +++ b/scripts/dev/check-lock.js @@ -0,0 +1,10 @@ +const fs = require('fs'); +const path = require('path'); + +const lockFile = path.resolve(__dirname, '../../package-lock.json'); +const lockStr = fs.readFileSync(lockFile, 'utf8'); +const wrongRegistryMatch = lockStr.match(/"resolved": "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(); +}