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(); +}