Skip to content

Commit

Permalink
fix(yarn): support corepack constraint (#23395)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitriy-kudelko committed Jul 18, 2023
1 parent 4c43c0d commit d9a24c5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
59 changes: 59 additions & 0 deletions lib/modules/manager/npm/post-update/yarn.spec.ts
Expand Up @@ -451,6 +451,65 @@ describe('modules/manager/npm/post-update/yarn', () => {
expect(res.lockFile).toBe('package-lock-contents');
});

it('supports customizing corepack version via config constraints', async () => {
process.env.CONTAINERBASE = 'true';

GlobalConfig.set({
localDir: '.',
binarySource: 'install',
cacheDir: '/tmp/cache',
});

Fixtures.mock(
{
'package.json': '{ "packageManager": "yarn@3.0.0" }',
'yarn.lock': 'package-lock-contents',
},
'some-dir'
);

mockedFunction(getPkgReleases).mockResolvedValueOnce({
releases: [
{ version: '0.17.0' },
{ version: '0.17.1' },
{ version: '0.18.0' },
],
});

const execSnapshots = mockExecAll({
stdout: '2.1.0',
stderr: '',
});

const config = partial<PostUpdateConfig<NpmManagerData>>({
managerData: { hasPackageManager: true },
constraints: {
yarn: '^3.0.0',
corepack: '^0.17.0',
},
});

const res = await yarnHelper.generateLockFile('some-dir', {}, config);

expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool node 16.16.0', options: { cwd: 'some-dir' } },
{ cmd: 'install-tool corepack 0.17.1', options: { cwd: 'some-dir' } },
{
cmd: 'yarn install --mode=update-lockfile',
options: {
cwd: 'some-dir',
env: {
YARN_ENABLE_GLOBAL_CACHE: '1',
YARN_ENABLE_IMMUTABLE_INSTALLS: 'false',
YARN_HTTP_TIMEOUT: '100000',
},
},
},
]);

expect(res.lockFile).toBe('package-lock-contents');
});

it('uses slim yarn instead of corepack', async () => {
// sanity check for later refactorings
expect(plocktest1YarnLockV1).toBeTruthy();
Expand Down
5 changes: 4 additions & 1 deletion lib/modules/manager/npm/post-update/yarn.ts
Expand Up @@ -125,7 +125,10 @@ export async function generateLockFile(
!!upgrades[0]?.managerData?.hasPackageManager;

if (!isYarn1 && hasPackageManager) {
toolConstraints.push({ toolName: 'corepack' });
toolConstraints.push({
toolName: 'corepack',
constraint: config.constraints?.corepack,
});
} else {
toolConstraints.push(yarnTool);
if (isYarn1 && minYarnVersion) {
Expand Down

0 comments on commit d9a24c5

Please sign in to comment.