Skip to content

Commit

Permalink
feat(yarn): set http proxy config from environment variables (#27794)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Mar 8, 2024
1 parent 5715892 commit 049c59c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/modules/manager/npm/post-update/yarn.spec.ts
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
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
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.

0 comments on commit 049c59c

Please sign in to comment.