Add isValidPackcageManager() util

This commit is contained in:
Han Yeong-woo 2023-09-02 06:26:28 +09:00
parent cbe5f5b523
commit f4f2e854d7
No known key found for this signature in database
GPG key ID: A46E340CB4E4D6AD
2 changed files with 14 additions and 0 deletions

View file

@ -4,6 +4,7 @@ import {
checkWorkingDirectory,
detectPackageManager,
getNpxCmd,
isValidPackageManager,
semverCompare,
} from "./utils";
@ -70,3 +71,12 @@ describe("detectPackageManager", () => {
expect(detectPackageManager("test/fixtures/empty")).toBe(null);
});
});
test("isValidPackageManager", () => {
expect(isValidPackageManager("npm")).toBe(true);
expect(isValidPackageManager("pnpm")).toBe(true);
expect(isValidPackageManager("yarn")).toBe(true);
expect(isValidPackageManager("")).toBe(false);
expect(isValidPackageManager("ppnpm")).toBe(false);
});

View file

@ -50,3 +50,7 @@ export function detectPackageManager(
}
return null;
}
export function isValidPackageManager(name: string): name is PackageManager {
return name === "npm" || name === "yarn" || name === "pnpm";
}