fix: reject flags passed as package manager names in setup-package-manager CLI

When --global or --project was followed by another flag (e.g., --global --project),
the flag was treated as a package manager name. Added pmName.startsWith('-') check
to both handlers. Added 20 tests across 4 test files covering argument validation,
ensureDir error propagation, runCommand stderr handling, and saveAliases failure paths.
This commit is contained in:
Affaan Mustafa
2026-02-13 03:37:46 -08:00
parent b1eb99d961
commit 167b105cac
5 changed files with 220 additions and 2 deletions

View File

@@ -174,7 +174,7 @@ if (args.includes('--list')) {
const globalIdx = args.indexOf('--global');
if (globalIdx !== -1) {
const pmName = args[globalIdx + 1];
if (!pmName) {
if (!pmName || pmName.startsWith('-')) {
console.error('Error: --global requires a package manager name');
process.exit(1);
}
@@ -185,7 +185,7 @@ if (globalIdx !== -1) {
const projectIdx = args.indexOf('--project');
if (projectIdx !== -1) {
const pmName = args[projectIdx + 1];
if (!pmName) {
if (!pmName || pmName.startsWith('-')) {
console.error('Error: --project requires a package manager name');
process.exit(1);
}