forked from MetaMask/metamask-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshow-deps-install-scripts.js
executable file
·41 lines (34 loc) · 1.22 KB
/
show-deps-install-scripts.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
#!/usr/bin/env node
// This script lists all dependencies that have package install scripts
const path = require('path');
const readInstalled = require('read-installed');
const installScripts = ['preinstall', 'install', 'postinstall'];
readInstalled('./', { dev: true }, function (err, data) {
if (err) {
throw err;
}
const deps = data.dependencies;
Object.entries(deps).forEach(([packageName, packageData]) => {
const packageScripts = packageData.scripts || {};
const scriptKeys = Reflect.ownKeys(packageScripts);
const hasInstallScript = installScripts.some((installKey) =>
scriptKeys.includes(installKey),
);
if (!hasInstallScript) {
return;
}
const matchingScripts = {};
if (packageScripts.preinstall) {
matchingScripts.preinstall = packageScripts.preinstall;
}
if (packageScripts.install) {
matchingScripts.install = packageScripts.install;
}
if (packageScripts.postinstall) {
matchingScripts.postinstall = packageScripts.postinstall;
}
const scriptNames = Reflect.ownKeys(matchingScripts);
const relativePath = path.relative(process.cwd(), packageData.path);
console.log(`${packageName}: ${relativePath} ${scriptNames}`);
});
});