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

fix(volta): make sure volta uses the same yarn package overwrite #18893

Merged
merged 12 commits into from Nov 16, 2022
54 changes: 54 additions & 0 deletions lib/modules/manager/npm/extract/__snapshots__/index.spec.ts.snap
Expand Up @@ -480,6 +480,60 @@ exports[`modules/manager/npm/extract/index .extractPackageFile() extracts volta
}
`;

exports[`modules/manager/npm/extract/index .extractPackageFile() extracts volta yarn higher than 1 1`] = `
{
"constraints": {
"node": "16.0.0",
},
"deps": [
{
"commitMessageTopic": "Node.js",
"currentValue": "16.0.0",
"datasource": "github-tags",
"depName": "node",
"depType": "engines",
"packageName": "nodejs/node",
"prettyDepType": "engine",
"versioning": "node",
},
{
"commitMessageTopic": "Node.js",
"currentValue": "16.0.0",
"datasource": "github-tags",
"depName": "node",
"depType": "volta",
"packageName": "nodejs/node",
"prettyDepType": "volta",
"versioning": "node",
},
{
"commitMessageTopic": "Yarn",
"currentValue": "3.2.4",
"datasource": "npm",
"depName": "yarn",
"depType": "volta",
"packageName": "@yarnpkg/cli",
"prettyDepType": "volta",
},
],
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": {
"hasPackageManager": false,
"lernaJsonFile": undefined,
"yarnZeroInstall": false,
},
"npmLock": undefined,
"npmrc": undefined,
"packageFileVersion": undefined,
"packageJsonName": undefined,
"pnpmShrinkwrap": undefined,
"skipInstalls": true,
"yarnLock": undefined,
"yarnWorkspacesPackages": undefined,
}
`;

exports[`modules/manager/npm/extract/index .extractPackageFile() extracts volta yarn unknown-version 1`] = `
{
"constraints": {
Expand Down
42 changes: 42 additions & 0 deletions lib/modules/manager/npm/extract/index.spec.ts
Expand Up @@ -483,6 +483,48 @@ describe('modules/manager/npm/extract/index', () => {
});
});

it('extracts volta yarn higher than 1', async () => {
const pJson = {
main: 'index.js',
engines: {
node: '16.0.0',
},
volta: {
node: '16.0.0',
yarn: '3.2.4',
},
};
const pJsonStr = JSON.stringify(pJson);
const res = await npmExtract.extractPackageFile(
pJsonStr,
'package.json',
defaultConfig
);
expect(res).toMatchObject({
deps: [
{},
{
commitMessageTopic: 'Node.js',
currentValue: '16.0.0',
datasource: 'github-tags',
depName: 'node',
depType: 'volta',
packageName: 'nodejs/node',
prettyDepType: 'volta',
versioning: 'node',
},
{
commitMessageTopic: 'Yarn',
currentValue: '3.2.4',
datasource: 'npm',
depName: 'yarn',
pataar marked this conversation as resolved.
Show resolved Hide resolved
depType: 'volta',
prettyDepType: 'volta',
},
],
});
});

it('extracts non-npmjs', async () => {
const pJson = {
dependencies: {
Expand Down
11 changes: 9 additions & 2 deletions lib/modules/manager/npm/extract/index.ts
@@ -1,4 +1,5 @@
import is from '@sindresorhus/is';
import semver from 'semver';
pataar marked this conversation as resolved.
Show resolved Hide resolved
import validateNpmPackageName from 'validate-npm-package-name';
import { GlobalConfig } from '../../../../config/global';
import { CONFIG_VALIDATION } from '../../../../constants/error-messages';
Expand Down Expand Up @@ -201,8 +202,8 @@ export async function extractPackageFile(
dep.commitMessageTopic = 'Yarn';
constraints.yarn = dep.currentValue;
if (
dep.currentValue.startsWith('2') ||
dep.currentValue.startsWith('3')
semver.valid(dep.currentValue) &&
semver.major(dep.currentValue) > 1
pataar marked this conversation as resolved.
Show resolved Hide resolved
) {
dep.packageName = '@yarnpkg/cli';
}
Expand Down Expand Up @@ -235,6 +236,12 @@ export async function extractPackageFile(
} else if (depName === 'yarn') {
dep.datasource = NpmDatasource.id;
dep.commitMessageTopic = 'Yarn';
if (
semver.valid(dep.currentValue) &&
semver.major(dep.currentValue) > 1
) {
dep.packageName = '@yarnpkg/cli';
}
} else if (depName === 'npm') {
dep.datasource = NpmDatasource.id;
} else {
Expand Down