• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

adobe / sizewatcher / 14183043239

31 Mar 2025 10:53PM UTC coverage: 58.38% (+1.3%) from 57.081%
14183043239

Pull #108

github

web-flow
Merge 2e05e84e0 into cf160b76b
Pull Request #108: fix(git): git comparator reporting incorrect deltas

99 of 222 branches covered (44.59%)

Branch coverage included in aggregate %.

32 of 41 new or added lines in 4 files covered. (78.05%)

14 existing lines in 2 files now uncovered.

319 of 494 relevant lines covered (64.57%)

4.84 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

84.38
/lib/comparators/node_modules.js
1
/*
2
 * Copyright 2020 Adobe. All rights reserved.
3
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
 * you may not use this file except in compliance with the License. You may obtain a copy
5
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
 *
7
 * Unless required by applicable law or agreed to in writing, software distributed under
8
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
 * OF ANY KIND, either express or implied. See the License for the specific language
10
 * governing permissions and limitations under the License.
11
 */
12

13
'use strict';
14

15
// comparators/node_modules.js - compares nodejs/npm module dependency size (node_modules folder)
16

17
const debug = require("debug")("sizewatcher:node_modules");
1✔
18
const { execSync } = require("child_process");
1✔
19
const du = require("du");
1✔
20
const path = require("path");
1✔
21
const fs = require("fs");
1✔
22

23
function isEmptyObject(obj) {
24
    return Object.keys(obj).length === 0 && obj.constructor === Object;
1!
25
}
26

27
function hasPackageJson(dir) {
28
    return fs.existsSync(path.join(dir, "package.json"));
22✔
29
}
30

31
async function getSize(dir) {
32
    if (!hasPackageJson(dir)) {
8✔
33
        return 0;
4✔
34
    }
35
    process.chdir(dir);
4✔
36

37
    debug(`installing node dependencies inside ${dir}...`);
4✔
38
    if (fs.existsSync("package-lock.json") || fs.existsSync("npm-shrinkwrap.json")) {
4!
UNCOV
39
        execSync("npm ci");
×
40
    } else {
41
        execSync("npm install");
4✔
42
    }
43

44
    const nodeModules = path.join(dir, "node_modules");
4✔
45
    if (fs.existsSync(nodeModules)) {
4✔
46
        debug(`calculating folder size of ${nodeModules}...`);
2✔
47
        return du(nodeModules);
2✔
48
    } else {
49
        return 0;
2✔
50
    }
51
}
52

53
async function costOfModules(dir) {
54
    if (!hasPackageJson(dir)) {
4✔
55
        return "(no package.json)";
2✔
56
    }
57
    process.chdir(dir);
2✔
58

59
    const pkgJsonPath = path.join(dir, "package.json");
2✔
60
    const pkgJson = require(pkgJsonPath);
2✔
61
    if (!pkgJson.dependencies || isEmptyObject(pkgJson.dependencies)) {
2✔
62
        return "(no production dependencies)";
1✔
63
    }
64

65
    debug(`running cost-of-modules...`);
1✔
66
    try {
1✔
67
        const out = execSync("npx cost-of-modules --less --no-install").toString();
1✔
68
        const PREFIX = "\nCalculating...\n\n\n";
1✔
69
        if (out.startsWith(PREFIX)) {
1!
70
            return out.substring(PREFIX.length);
1✔
71
        }
UNCOV
72
        return out;
×
73
    } catch (e) {
UNCOV
74
        throw new Error(`cost-of-modules failed with: ${e.stdout ? e.stdout.toString() : ""} ${e.stdout ? e.stderr.toString() : ""}`);
×
75
    }
76

77
}
78

79
module.exports = {
1✔
80

81
    shouldRun: async function(beforeDir, afterDir) {
82
        return hasPackageJson(beforeDir) || hasPackageJson(afterDir);
6✔
83
    },
84

85
    compare: async function(before, after) {
86
        const beforeSize = await getSize(before.dir);
4✔
87
        const afterSize = await getSize(after.dir);
4✔
88
        const details = await costOfModules(after.dir);
4✔
89

90
        return {
4✔
91
            beforeSize,
92
            afterSize,
93
            detailsLabel: "Largest production node modules",
94
            details
95
        };
96
    }
97
};
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc