-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache_checker.js
More file actions
47 lines (40 loc) · 1.39 KB
/
cache_checker.js
File metadata and controls
47 lines (40 loc) · 1.39 KB
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
const fs = require('fs');
const { PrintHelper } = require('./utils');
const { whybundled } = require("./whybundled/cli");
const gitDiffFilename = process.argv[2];
const importsFound = {};
const nonWebpackImportsFound = {};
const ph = new PrintHelper();
const addToImports = (key, filename) => {
if (importsFound[key]) {
importsFound[key].push(filename);
} else {
importsFound[key] = [filename];
}
};
const addToNonWebpackImports = (key, filename) => {
if (nonWebpackImportsFound[key]) {
nonWebpackImportsFound[key].push(filename);
} else {
nonWebpackImportsFound[key] = [filename];
}
};
// Read files that have changed
const readGitDiff = () => {
const {modules, chunks} = whybundled('stats.json');
fs.readFileSync(gitDiffFilename).toString().split('\n').forEach((changedFilePath) => {
const strippedChangedFilePath = changedFilePath.replace(/ /g, '');
if (!strippedChangedFilePath.length) return;
if (strippedChangedFilePath.indexOf('tests') !== -1) return;
const module = modules[`./${strippedChangedFilePath}`];
if (module) {
module.chunks.forEach(chunk => {
addToImports(chunks[chunk].names[0], strippedChangedFilePath)
})
} else if (strippedChangedFilePath.endsWith('.js')) {
addToNonWebpackImports(strippedChangedFilePath, strippedChangedFilePath)
}
});
};
readGitDiff();
ph.printResults(importsFound, nonWebpackImportsFound);