3
0
Fork 0
mirror of https://gitea.com/actions/setup-node.git synced 2024-11-24 11:09:33 +01:00

Add support for specifying versions for package managers (#529)

This commit is contained in:
Haneen Mahdin 2022-07-30 09:48:07 +05:30
parent 7884734703
commit 5a3778b347

View file

@ -47,17 +47,35 @@ export const getCommandOutput = async (toolCommand: string) => {
return stdout.trim();
};
const resolvePackageManagerVersionInput = (
packageManager: string
): string | undefined => {
let version = core.getInput(`${packageManager}-version`);
if (version !== '') {
core.info(`Using ${packageManager} with version ${version}.`);
return version;
}
};
const getPackageManagerVersion = async (
packageManager: string,
command: string
) => {
const stdOut = await getCommandOutput(`${packageManager} ${command}`);
let packageManagerVersion = resolvePackageManagerVersionInput(packageManager);
if (!stdOut) {
throw new Error(`Could not retrieve version of ${packageManager}`);
if (packageManagerVersion) {
return packageManagerVersion;
} else {
const stdOut = await getCommandOutput(`${packageManager} ${command}`);
if (!stdOut) {
throw new Error(`Could not retrieve version of ${packageManager}`);
}
return stdOut;
}
return stdOut;
};
export const getPackageManagerInfo = async (packageManager: string) => {