-
Notifications
You must be signed in to change notification settings - Fork 30
/
lockFileLint.js
39 lines (34 loc) · 1009 Bytes
/
lockFileLint.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
37
38
39
const { spawnSync } = require('child_process');
// eslint-disable-next-line import/no-extraneous-dependencies
const glob = require('glob');
const lockfileGlob = '**/package-lock.json';
const ignoreGlob = '**/node_modules/**/package-lock.json';
const invalidations = [];
glob(lockfileGlob, { ignore: ignoreGlob }, (globError, lockFiles) => {
if (globError) {
process.stderr.write(globError);
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
lockFiles.forEach(lockPath => {
const { stderr } = spawnSync('./node_modules/.bin/lockfile-lint', [
'-p',
lockPath,
'-t',
'npm',
'-a',
'npm',
'-o',
'https:',
'-c',
'-i',
]);
const error = stderr.toString();
if (error) invalidations.push([lockPath, error].join(':\n\n'));
});
if (invalidations.length > 0) {
process.stderr.write(invalidations.join('\n'));
// eslint-disable-next-line unicorn/no-process-exit
process.exit(1);
}
});