Skip to content

Commit

Permalink
feat(repo): add checks for lock files (nrwl#5854)
Browse files Browse the repository at this point in the history
  • Loading branch information
meeroslav authored Jun 1, 2021
1 parent f01bd0c commit 57785b5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/npm-audit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ name: NPM Audit

on:
schedule:
- cron: "0 0 * * *"
- cron: "0 0 * * *"
workflow_dispatch:

jobs:
audit:
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn check-lock-files
yarn check-commit
yarn documentation
yarn pretty-quick --check
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"check-commit": "node ./scripts/commit-lint.js",
"check-format": "nx format:check --all",
"check-imports": "node ./scripts/check-imports.js",
"check-lock-files": "node ./scripts/check-lock-files.js",
"check-internal-links": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/documentation/internal-link-checker.ts",
"check-versions": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/check-versions.ts",
"check-documentation-map": "ts-node -P ./scripts/tsconfig.scripts.json ./scripts/documentation/map-link-checker.ts",
Expand Down
34 changes: 34 additions & 0 deletions scripts/check-lock-files.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const fs = require('fs');

function checkLockFiles() {
const errors = [];
if (fs.existsSync('package-lock.json')) {
errors.push(
'Invalid occurence of "package-lock.json" file. Please remove it and use only "yarn.lock"'
);
}
if (fs.existsSync('pnpm-lock.yaml')) {
errors.push(
'Invalid occurence of "pnpm-lock.yaml" file. Please remove it and use only "yarn.lock"'
);
}
try {
const content = fs.readFileSync('yarn.lock', 'utf-8');
if (content.match(/localhost:487/)) {
errors.push(
'The "yarn.lock" has reference to local yarn repository ("localhost:4873"). Please use "registry.yarnpkg.com" in "yarn.lock"'
);
}
} catch {
errors.push('The "yarn.lock" does not exist or cannot be read');
}
return errors;
}

const invalid = checkLockFiles();
if (invalid.length > 0) {
invalid.forEach((e) => console.log(e));
process.exit(1);
} else {
process.exit(0);
}

0 comments on commit 57785b5

Please sign in to comment.