2022-08-24 19:25:27 +02:00
|
|
|
#!/usr/bin/env node
|
2019-09-25 14:01:10 +02:00
|
|
|
// This script lists all dependencies that have package install scripts
|
2021-02-04 19:15:23 +01:00
|
|
|
const path = require('path');
|
|
|
|
const readInstalled = require('read-installed');
|
2019-09-25 14:01:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const installScripts = ['preinstall', 'install', 'postinstall'];
|
2019-09-25 14:01:10 +02:00
|
|
|
|
|
|
|
readInstalled('./', { dev: true }, function (err, data) {
|
2019-11-20 01:03:20 +01:00
|
|
|
if (err) {
|
2021-02-04 19:15:23 +01:00
|
|
|
throw err;
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2019-09-25 14:01:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const deps = data.dependencies;
|
2019-09-25 14:01:10 +02:00
|
|
|
Object.entries(deps).forEach(([packageName, packageData]) => {
|
2021-02-04 19:15:23 +01:00
|
|
|
const packageScripts = packageData.scripts || {};
|
|
|
|
const scriptKeys = Reflect.ownKeys(packageScripts);
|
2019-09-25 14:01:10 +02:00
|
|
|
|
2020-11-03 00:41:28 +01:00
|
|
|
const hasInstallScript = installScripts.some((installKey) =>
|
|
|
|
scriptKeys.includes(installKey),
|
2021-02-04 19:15:23 +01:00
|
|
|
);
|
2019-11-20 01:03:20 +01:00
|
|
|
if (!hasInstallScript) {
|
2021-02-04 19:15:23 +01:00
|
|
|
return;
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2019-09-25 14:01:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const matchingScripts = {};
|
2019-11-20 01:03:20 +01:00
|
|
|
if (packageScripts.preinstall) {
|
2021-02-04 19:15:23 +01:00
|
|
|
matchingScripts.preinstall = packageScripts.preinstall;
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
|
|
|
if (packageScripts.install) {
|
2021-02-04 19:15:23 +01:00
|
|
|
matchingScripts.install = packageScripts.install;
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
|
|
|
if (packageScripts.postinstall) {
|
2021-02-04 19:15:23 +01:00
|
|
|
matchingScripts.postinstall = packageScripts.postinstall;
|
2019-11-20 01:03:20 +01:00
|
|
|
}
|
2021-02-04 19:15:23 +01:00
|
|
|
const scriptNames = Reflect.ownKeys(matchingScripts);
|
2019-09-25 14:01:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
const relativePath = path.relative(process.cwd(), packageData.path);
|
2019-09-25 14:01:10 +02:00
|
|
|
|
2021-02-04 19:15:23 +01:00
|
|
|
console.log(`${packageName}: ${relativePath} ${scriptNames}`);
|
|
|
|
});
|
|
|
|
});
|