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(yarn): set http proxy config from environment variables #27794

Merged
merged 2 commits into from
Mar 8, 2024
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
34 changes: 34 additions & 0 deletions lib/modules/manager/npm/post-update/yarn.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ describe('modules/manager/npm/post-update/yarn', () => {

beforeEach(() => {
delete process.env.BUILDPACK;
delete process.env.HTTP_PROXY;
delete process.env.HTTPS_PROXY;
Fixtures.reset();
GlobalConfig.set({ localDir: '.', cacheDir: '/tmp/cache' });
removeDockerContainer.mockResolvedValue();
Expand Down Expand Up @@ -147,6 +149,38 @@ describe('modules/manager/npm/post-update/yarn', () => {
expect(fixSnapshots(execSnapshots)).toMatchSnapshot();
});

it('sets http proxy', async () => {
process.env.HTTP_PROXY = 'http://proxy';
process.env.HTTPS_PROXY = 'http://proxy';
GlobalConfig.set({
localDir: '.',
allowScripts: true,
cacheDir: '/tmp/cache',
});
Fixtures.mock(
{
'yarn.lock': 'package-lock-contents',
},
'some-dir',
);
const execSnapshots = mockExecAll({
stdout: '3.0.0',
stderr: '',
});
const config = {
constraints: {
yarn: '3.0.0',
},
};
const res = await yarnHelper.generateLockFile('some-dir', {}, config);
expect(res.lockFile).toBe('package-lock-contents');
expect(fixSnapshots(execSnapshots)).toMatchObject([
{ cmd: 'yarn config set --home httpProxy http://proxy' },
{ cmd: 'yarn config set --home httpsProxy http://proxy' },
{},
]);
});

it('does not use global cache if zero install is detected', async () => {
Fixtures.mock(
{
Expand Down
11 changes: 11 additions & 0 deletions lib/modules/manager/npm/post-update/yarn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ export async function generateLockFile(
commands.push(`yarn set version ${quote(yarnUpdate.newValue!)}`);
}

if (process.env.HTTP_PROXY && !isYarn1) {
commands.push(
`yarn config set --home httpProxy ${quote(process.env.HTTP_PROXY)}`,
);
}
if (process.env.HTTPS_PROXY && !isYarn1) {
commands.push(
`yarn config set --home httpsProxy ${quote(process.env.HTTPS_PROXY)}`,
);
}

// This command updates the lock file based on package.json
commands.push(`yarn install${cmdOptions}`);

Expand Down
12 changes: 12 additions & 0 deletions lib/modules/manager/npm/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@ The following `depTypes` are currently supported by the npm manager :
- `engines` : Renovate will update any `node`, `npm` and `yarn` version specified under `engines`.
- `volta` : Renovate will update any `node`, `npm`, `pnpm` and `yarn` version specified under `volta`.
- `packageManager`

### Yarn

#### Version Selection / Installation

If Renovate detects a `packageManager` setting for Yarn in `package.json` then it will use Corepack to install Yarn.

#### HTTP Proxy Support

Yarn itself does not natively recognize/support the `HTTP_PROXY` and `HTTPS_PROXY` environment variables.
If Renovate detects Yarn 2+, and one or both of those variables are present, then it will run commands like `yarn config set --home httpProxy http://proxy` prior to executing `yarn install`.
This will result in the `~/.yarnrc.yml` file being created or modified with these settings, and the settings are not removed afterwards.
rarkins marked this conversation as resolved.
Show resolved Hide resolved