forked from electrode-io/electrode-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
yarn-lock-check.js
36 lines (32 loc) · 1.03 KB
/
yarn-lock-check.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const chalk = require('chalk');
const fs = require('fs');
const lockfile = require('@yarnpkg/lockfile');
const path = require('path');
const yarnLockContent = fs.readFileSync('yarn.lock', 'utf8');
const yarnLockParsed = lockfile.parse(yarnLockContent);
const allowedRegistriesRe =
/https:\/\/registry.yarnpkg.com|http:\/\/registry.npmjs.org/;
if (yarnLockParsed && yarnLockParsed.object) {
let incorrectRegistries = [];
for (let key of Object.keys(yarnLockParsed.object)) {
if (yarnLockParsed.object[key]) {
let resolved = yarnLockParsed.object[key].resolved;
if (resolved && !allowedRegistriesRe.exec(resolved)) {
incorrectRegistries.push(resolved);
}
}
}
if (incorrectRegistries.length > 0) {
console.log(
chalk.bold.red(
`yarn.lock contains registry other than https://registry.yarnpkg.com`,
),
);
incorrectRegistries.forEach((item) => {
console.log(chalk.bold.red(item));
});
process.exit(1);
} else {
console.log(chalk.bold.green('✅ success'));
}
}