feat: add logic to enable corepack on passing optional input
This commit is contained in:
parent
b6efa7f903
commit
53234c232f
|
@ -25,6 +25,9 @@ inputs:
|
|||
description: 'Used to specify a package manager for caching in the default directory. Supported values: npm, yarn, pnpm.'
|
||||
cache-dependency-path:
|
||||
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
|
||||
corepack:
|
||||
description: 'Used to specify whether to enable Corepack. Set to true to enable all package managers or set it to one or more package manager names (separate package manager names by a space. Supported package manager names: npm, yarn, pnpm.'
|
||||
default: 'false'
|
||||
# TODO: add input to control forcing to pull from cloud or dist.
|
||||
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
|
||||
outputs:
|
||||
|
|
|
@ -4,6 +4,7 @@ import * as core from '@actions/core';
|
|||
import * as hc from '@actions/http-client';
|
||||
import * as io from '@actions/io';
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as exec from '@actions/exec';
|
||||
import * as path from 'path';
|
||||
import * as semver from 'semver';
|
||||
import fs from 'fs';
|
||||
|
@ -604,3 +605,21 @@ export function parseNodeVersionFile(contents: string): string {
|
|||
function isLatestSyntax(versionSpec): boolean {
|
||||
return ['current', 'latest', 'node'].includes(versionSpec);
|
||||
}
|
||||
|
||||
export async function enableCorepack(input: string): Promise<void> {
|
||||
let corepackArgs = ['enable'];
|
||||
if (input.length > 0 && input !== 'false') {
|
||||
if (input !== 'true') {
|
||||
const packageManagers = input.split(' ');
|
||||
if (!packageManagers.every(pm => ['npm', 'yarn', 'pnpm'].includes(pm))) {
|
||||
throw new Error(
|
||||
`One or more of the specified package managers [ ${input} ] are not supported by corepack`
|
||||
);
|
||||
}
|
||||
corepackArgs.push(...packageManagers);
|
||||
}
|
||||
await exec.getExecOutput('corepack', corepackArgs, {
|
||||
ignoreReturnCode: true
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,6 +49,9 @@ export async function run() {
|
|||
auth.configAuthentication(registryUrl, alwaysAuth);
|
||||
}
|
||||
|
||||
const corepack = core.getInput('corepack') || 'false';
|
||||
await installer.enableCorepack(corepack);
|
||||
|
||||
if (cache && isCacheFeatureAvailable()) {
|
||||
const cacheDependencyPath = core.getInput('cache-dependency-path');
|
||||
await restoreCache(cache, cacheDependencyPath);
|
||||
|
|
Loading…
Reference in New Issue