Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions build/npm/check-allow-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ function checkDirectory(directory: string): CheckResult {
}

function main(): void {
const args = process.argv.slice(2);
const jsonOutput = args.includes('--json');

const packageDirectories = dirs
.map(dir => path.join(root, dir))
.filter(directory => existsSync(path.join(directory, 'package.json')));

const results: CheckResult[] = [];
for (const directory of packageDirectories) {
const result = checkDirectory(directory);
Expand All @@ -72,6 +76,14 @@ function main(): void {
}
}

if (jsonOutput) {
console.log(JSON.stringify(results, null, 2));
if (results.length > 0) {
process.exitCode = 1;
}
return;
}

if (results.length === 0) {
console.log(`Checked ${packageDirectories.length} package.json files: all install scripts are covered by allowScripts.`);
return;
Expand All @@ -87,5 +99,3 @@ function main(): void {
console.error('\nRun `npm approve-scripts <pkg>` in each directory to review the pending install scripts.');
process.exitCode = 1;
}
Comment thread
denizguney marked this conversation as resolved.

main();