-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnpm-prune.js
64 lines (48 loc) · 1.37 KB
/
npm-prune.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
58
59
60
61
62
63
64
const archiver = require('archiver');
const { prepareEnvironment, runCommand, getOutputStream, getNodeModulesDir, getOutputSize, getFormattedEndTime } = require('./utils');
function cleanDependencies() {
runCommand('npm prune --production --loglevel error');
}
function restoreDependencies() {
runCommand('npm ci');
}
async function zipDependencies() {
const zip = archiver('zip', {
zlib: { level: 9 },
});
const outputStream = getOutputStream('prune.zip');
zip.directory(
getNodeModulesDir(),
'node_modules',
);
await new Promise((resolve, reject) => {
zip
.on('error', err => reject(err))
.pipe(outputStream);
outputStream.on('close', () => resolve());
zip.finalize();
});
}
async function runSuite(skipRestore) {
prepareEnvironment();
const suitName = skipRestore ? 'NpmPrune (skip restore)' : 'NpmPrune';
console.log('Running NpmPrune Suite.');
const time = new Date();
console.time(suitName);
cleanDependencies();
await zipDependencies();
if (!skipRestore)
restoreDependencies();
console.timeEnd(suitName);
console.log(`Finished running ${suitName} Suite.`);
const endTime = new Date() - time;
const outputSize = getOutputSize('prune.zip');
console.log(`OutputSize: ${outputSize}`);
return {
endTime: getFormattedEndTime(endTime),
outputSize,
};
}
module.exports = {
runSuite,
};