Skip to content

Commit

Permalink
fix(yarn): do not set registryUrls from yarnrc on non-npm dependencies (
Browse files Browse the repository at this point in the history
  • Loading branch information
ahippler committed Oct 11, 2023
1 parent 9395a12 commit e33def6
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
56 changes: 56 additions & 0 deletions lib/modules/manager/npm/extract/__snapshots__/index.spec.ts.snap
Expand Up @@ -26,6 +26,62 @@ exports[`modules/manager/npm/extract/index .extractPackageFile() catches invalid
}
`;

exports[`modules/manager/npm/extract/index .extractPackageFile() does not set registryUrls for non-npmjs 1`] = `
{
"deps": [
{
"currentRawValue": "github:owner/a#v1.1.0",
"currentValue": "v1.1.0",
"datasource": "github-tags",
"depName": "a",
"depType": "dependencies",
"gitRef": true,
"packageName": "owner/a",
"pinDigests": false,
"prettyDepType": "dependency",
"sourceUrl": "https://github.com/owner/a",
},
{
"commitMessageTopic": "Node.js",
"currentValue": "8.9.2",
"datasource": "github-tags",
"depName": "node",
"depType": "engines",
"packageName": "nodejs/node",
"prettyDepType": "engine",
"versioning": "node",
},
{
"commitMessageTopic": "Yarn",
"currentValue": "3.2.4",
"datasource": "npm",
"depName": "yarn",
"depType": "volta",
"packageName": "@yarnpkg/cli",
"prettyDepType": "volta",
"registryUrls": [
"https://registry.example.com",
],
},
],
"extractedConstraints": {
"node": "8.9.2",
},
"managerData": {
"hasPackageManager": false,
"npmLock": undefined,
"packageJsonName": undefined,
"pnpmShrinkwrap": undefined,
"workspacesPackages": undefined,
"yarnLock": undefined,
"yarnZeroInstall": false,
},
"npmrc": undefined,
"packageFileVersion": undefined,
"skipInstalls": true,
}
`;

exports[`modules/manager/npm/extract/index .extractPackageFile() extracts engines 1`] = `
{
"deps": [
Expand Down
57 changes: 57 additions & 0 deletions lib/modules/manager/npm/extract/index.spec.ts
Expand Up @@ -646,6 +646,63 @@ describe('modules/manager/npm/extract/index', () => {
});
});

it('does not set registryUrls for non-npmjs', async () => {
fs.readLocalFile.mockImplementation((fileName): Promise<any> => {
if (fileName === '.yarnrc.yml') {
return Promise.resolve(
'npmRegistryServer: https://registry.example.com'
);
}
return Promise.resolve(null);
});
const pJson = {
dependencies: {
a: 'github:owner/a#v1.1.0',
},
engines: {
node: '8.9.2',
},
volta: {
yarn: '3.2.4',
},
};
const pJsonStr = JSON.stringify(pJson);
const res = await npmExtract.extractPackageFile(
pJsonStr,
'package.json',
defaultExtractConfig
);
expect(res).toMatchSnapshot({
deps: [
{
depName: 'a',
currentValue: 'v1.1.0',
datasource: 'github-tags',
sourceUrl: 'https://github.com/owner/a',
},
{
commitMessageTopic: 'Node.js',
currentValue: '8.9.2',
datasource: 'github-tags',
depName: 'node',
depType: 'engines',
packageName: 'nodejs/node',
prettyDepType: 'engine',
versioning: 'node',
},
{
commitMessageTopic: 'Yarn',
currentValue: '3.2.4',
datasource: 'npm',
depName: 'yarn',
depType: 'volta',
prettyDepType: 'volta',
packageName: '@yarnpkg/cli',
},
],
});
});

it('extracts npm package alias', async () => {
fs.readLocalFile.mockImplementation((fileName: string): Promise<any> => {
if (fileName === 'package-lock.json') {
Expand Down
3 changes: 2 additions & 1 deletion lib/modules/manager/npm/extract/index.ts
Expand Up @@ -3,6 +3,7 @@ import { GlobalConfig } from '../../../../config/global';
import { logger } from '../../../../logger';
import { getSiblingFileName, readLocalFile } from '../../../../util/fs';
import { newlineRegex, regEx } from '../../../../util/regex';
import { NpmDatasource } from '../../../datasource/npm';

import type {
ExtractConfig,
Expand Down Expand Up @@ -179,7 +180,7 @@ export async function extractPackageFile(
dep.depName,
yarnConfig
);
if (registryUrlFromYarnConfig) {
if (registryUrlFromYarnConfig && dep.datasource === NpmDatasource.id) {
dep.registryUrls = [registryUrlFromYarnConfig];
}
}
Expand Down

0 comments on commit e33def6

Please sign in to comment.