Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(manager/npm): full yarn buildpack support #16986

Merged
merged 3 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/modules/manager/npm/post-update/yarn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import * as docker from '../../../../util/exec/docker';
import { getPkgReleases } from '../../../datasource';
import type { PostUpdateConfig } from '../../types';
import type { NpmManagerData } from '../types';
import { getNodeToolConstraint } from './node-version';
import * as yarnHelper from './yarn';

jest.mock('fs-extra', () =>
Expand Down Expand Up @@ -41,8 +42,12 @@ describe('modules/manager/npm/post-update/yarn', () => {
delete process.env.BUILDPACK;
jest.clearAllMocks();
Fixtures.reset();
docker.resetPrefetchedImages();
GlobalConfig.set({ localDir: '.', cacheDir: '/tmp/cache' });
docker.resetPrefetchedImages();
mockedFunction(getNodeToolConstraint).mockResolvedValueOnce({
toolName: 'node',
constraint: '16.16.0',
});
});

it.each([
Expand Down Expand Up @@ -380,8 +385,8 @@ describe('modules/manager/npm/post-update/yarn', () => {
},
});
const res = await yarnHelper.generateLockFile('some-dir', {}, config);
expect(res.lockFile).toBe('package-lock-contents');
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool node 16.16.0', options: { cwd: 'some-dir' } },
{ cmd: 'install-tool corepack 0.10.0', options: { cwd: 'some-dir' } },
{
cmd: 'yarn install --mode=update-lockfile',
Expand All @@ -395,6 +400,7 @@ describe('modules/manager/npm/post-update/yarn', () => {
},
},
]);
expect(res.lockFile).toBe('package-lock-contents');
});

it('uses slim yarn instead of corepack', async () => {
Expand Down Expand Up @@ -427,6 +433,7 @@ describe('modules/manager/npm/post-update/yarn', () => {
const res = await yarnHelper.generateLockFile('some-dir', {}, config);
expect(res.lockFile).toBe(plocktest1YarnLockV1);
expect(execSnapshots).toMatchObject([
{ cmd: 'install-tool node 16.16.0', options: { cwd: 'some-dir' } },
{ cmd: 'install-tool yarn-slim 1.22.18', options: { cwd: 'some-dir' } },
{
cmd: 'yarn install --ignore-engines --ignore-platform --network-timeout 100000 --ignore-scripts',
Expand Down Expand Up @@ -500,11 +507,13 @@ describe('modules/manager/npm/post-update/yarn', () => {
expect(res.lockFile).toBe(plocktest1YarnLockV1);
const options = { encoding: 'utf-8' };
expect(execSnapshots).toMatchObject([
{ cmd: 'docker pull renovate/node', options },
{ cmd: 'docker pull renovate/sidecar', options },
{
cmd:
`docker run --rm --name=renovate_node --label=renovate_child -v ".":"." -v "/tmp/cache":"/tmp/cache" -e CI -e BUILDPACK_CACHE_DIR -w "some-dir" renovate/node ` +
`docker run --rm --name=renovate_sidecar --label=renovate_child -v ".":"." -v "/tmp/cache":"/tmp/cache" -e CI -e BUILDPACK_CACHE_DIR -w "some-dir" renovate/sidecar ` +
`bash -l -c "` +
`install-tool node 16.16.0` +
` && ` +
`install-tool yarn-slim 1.22.18` +
` && ` +
`sed -i 's/ steps,/ steps.slice(0,1),/' some-dir/.yarn/cli.js || true` +
Expand Down
13 changes: 6 additions & 7 deletions lib/modules/manager/npm/post-update/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { uniqueStrings } from '../../../../util/string';
import { NpmDatasource } from '../../../datasource/npm';
import type { PostUpdateConfig, Upgrade } from '../../types';
import type { NpmManagerData } from '../types';
import { getNodeConstraint, getNodeUpdate } from './node-version';
import { getNodeToolConstraint } from './node-version';
import type { GenerateLockFileResult } from './types';

export async function checkYarnrc(
Expand Down Expand Up @@ -94,7 +94,9 @@ export async function generateLockFile(
logger.debug(`Spawning yarn install to create ${lockFileName}`);
let lockFile: string | null = null;
try {
const toolConstraints: ToolConstraint[] = [];
const toolConstraints: ToolConstraint[] = [
await getNodeToolConstraint(config, upgrades),
];
const yarnUpdate = upgrades.find(isYarnUpdate);
const yarnCompatibility = yarnUpdate
? yarnUpdate.newValue
Expand Down Expand Up @@ -172,15 +174,12 @@ export async function generateLockFile(
extraEnv.YARN_ENABLE_SCRIPTS = '0';
}
}
const tagConstraint =
getNodeUpdate(upgrades) ?? (await getNodeConstraint(config));

const execOptions: ExecOptions = {
cwdFile: lockFileName,
extraEnv,
docker: {
image: 'node',
tagScheme: 'node',
tagConstraint,
image: 'sidecar',
},
toolConstraints,
};
Expand Down