Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion dist/cache-save/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44172,7 +44172,24 @@ exports.supportedPackageManagers = {
name: 'yarn',
lockFilePatterns: ['yarn.lock'],
getCacheFolderPath: async (projectDir) => {
const yarnVersion = await (0, exports.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;
try {
yarnVersion = await (0, exports.getCommandOutputNotEmpty)(`yarn --version`, 'Could not retrieve version of yarn', projectDir);
}
catch (err) {
// Check if this is a corepack error message
const errorMsg = err.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: "${projectDir || ''}")`);
const stdOut = yarnVersion.startsWith('1.')
? await (0, exports.getCommandOutput)('yarn cache dir', projectDir)
Expand All @@ -44184,6 +44201,24 @@ exports.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 () => {
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');
}
};
const getCommandOutput = async (toolCommand, cwd) => {
let { stdout, stderr, exitCode } = await exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true, ...(cwd && { cwd }) });
if (exitCode) {
Expand Down
37 changes: 36 additions & 1 deletion dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53810,7 +53810,24 @@ exports.supportedPackageManagers = {
name: 'yarn',
lockFilePatterns: ['yarn.lock'],
getCacheFolderPath: async (projectDir) => {
const yarnVersion = await (0, exports.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;
try {
yarnVersion = await (0, exports.getCommandOutputNotEmpty)(`yarn --version`, 'Could not retrieve version of yarn', projectDir);
}
catch (err) {
// Check if this is a corepack error message
const errorMsg = err.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: "${projectDir || ''}")`);
const stdOut = yarnVersion.startsWith('1.')
? await (0, exports.getCommandOutput)('yarn cache dir', projectDir)
Expand All @@ -53822,6 +53839,24 @@ exports.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 () => {
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');
}
};
const getCommandOutput = async (toolCommand, cwd) => {
let { stdout, stderr, exitCode } = await exec.getExecOutput(toolCommand, undefined, { ignoreReturnCode: true, ...(cwd && { cwd }) });
if (exitCode) {
Expand Down
49 changes: 44 additions & 5 deletions src/cache-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: "${
Expand All @@ -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
Expand Down