mirror of
https://github.com/actions/setup-node.git
synced 2026-05-24 05:11:53 +00:00
Merge 844d397646 into 670825a89d
This commit is contained in:
commit
6d86084b11
3 changed files with 116 additions and 7 deletions
|
|
@ -40,11 +40,32 @@ export const supportedPackageManagers: SupportedPackageManagers = {
|
|||
name: 'yarn',
|
||||
lockFilePatterns: ['yarn.lock'],
|
||||
getCacheFolderPath: async projectDir => {
|
||||
const yarnVersion = await getCommandOutputNotEmpty(
|
||||
`yarn --version`,
|
||||
'Could not retrieve version of yarn',
|
||||
projectDir
|
||||
);
|
||||
// Try to enable corepack first if available
|
||||
// This helps with yarn v2+ which requires corepack
|
||||
await enableCorepackIfSupported();
|
||||
|
||||
let yarnVersion: string;
|
||||
try {
|
||||
yarnVersion = await getCommandOutputNotEmpty(
|
||||
`yarn --version`,
|
||||
'Could not retrieve version of yarn',
|
||||
projectDir
|
||||
);
|
||||
} catch (err) {
|
||||
// Check if this is a corepack error message
|
||||
const errorMsg = (err as Error).message;
|
||||
if (
|
||||
errorMsg.includes('packageManager') &&
|
||||
errorMsg.includes('Corepack')
|
||||
) {
|
||||
throw new Error(
|
||||
`Yarn v4+ requires corepack to be enabled. Please run 'corepack enable' before using ` +
|
||||
`actions/setup-node with yarn, or disable caching with 'package-manager-cache: false'. ` +
|
||||
`See: https://github.com/actions/setup-node/issues/1027 for more information.`
|
||||
);
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
core.debug(
|
||||
`Consumed yarn version is ${yarnVersion} (working dir: "${
|
||||
|
|
@ -66,6 +87,24 @@ export const supportedPackageManagers: SupportedPackageManagers = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Tries to enable corepack for Node.js versions that support it (16.9+)
|
||||
* This helps with yarn v2+ which requires corepack
|
||||
* See: https://github.com/actions/setup-node/issues/1027
|
||||
*/
|
||||
const enableCorepackIfSupported = async (): Promise<void> => {
|
||||
try {
|
||||
await exec.exec('corepack', ['enable'], {
|
||||
ignoreReturnCode: true,
|
||||
silent: true
|
||||
});
|
||||
core.debug('Corepack enabled successfully');
|
||||
} catch {
|
||||
// Corepack not available or failed silently
|
||||
core.debug('Corepack not available on this system');
|
||||
}
|
||||
};
|
||||
|
||||
export const getCommandOutput = async (
|
||||
toolCommand: string,
|
||||
cwd?: string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue