-
Notifications
You must be signed in to change notification settings - Fork 0
/
limitation.js
executable file
·57 lines (42 loc) · 1.58 KB
/
limitation.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env node
const { execSync } = require('child_process');
const pkg = require('./package.json');
pkg.dependencies = pkg.dependencies || {};
pkg.devDependencies = pkg.devDependencies || {};
let violations = 0;
const limits = pkg.limits;
if (!limits) {
process.exit(0);
}
if (('packedSize' in limits) || ('unpackedSize' in limits)) {
const { size, unpackedSize } = JSON.parse(execSync(`npm pack --dry-run --json`).toString())[0];
console.log(` Packed Size: ${size}\n Unpacked Size: ${unpackedSize}`);
if ('packedSize' in limits && size > limits.packedSize) {
violations++;
console.error(`The packed size of ${size} exceeds the limit of ${limits.packedSize}!`);
}
if ('unpackedSize' in limits && unpackedSize > limits.unpackedSize) {
violations++;
console.error(`The unpacked size of ${unpackedSize} exceeds the limit of ${limits.unpackedSize}!`);
}
}
const depCount = Object.keys(pkg.dependencies).length;
console.log(` Dependencies: ${depCount}`);
if ('maxDependencies' in limits) {
if (depCount > limits.maxDependencies) {
violations++;
console.error(`The dependency count of ${depCount} exceeds the limit of ${limits.maxDependencies}!`);
}
}
const devDepCount = Object.keys(pkg.devDependencies).length;
console.log(`Dev Dependencies: ${devDepCount}`);
if ('maxDevDependencies' in limits) {
if (devDepCount > limits.maxDevDependencies) {
violations++;
console.error(`The dev dependency count of ${devDepCount} exceeds the limit of ${limits.maxDevDependencies}!`);
}
}
if (violations > 0) {
process.exit(1);
}
console.log('OK');