0
0
Fork 0
mirror of https://github.com/renovatebot/renovate.git synced 2025-03-13 07:43:27 +00:00

feat(yarn): set http proxy config from environment variables ()

This commit is contained in:
Rhys Arkins 2024-03-08 12:30:29 +01:00 committed by GitHub
parent 571589262c
commit 049c59c096
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 0 deletions
lib/modules/manager/npm

View file

@ -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();
@ -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(
{

View file

@ -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}`);

View file

@ -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.