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(npm): support updating packageManager field and Yarn binary #12088

Merged
merged 13 commits into from
Nov 1, 2021
Merged
44 changes: 44 additions & 0 deletions lib/manager/npm/__fixtures__/inputs/01-package-manager.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "renovate",
"description": "Client node modules for renovate",
"version": "1.0.0",
"author": "Rhys Arkins <rhys@keylocation.sg>",
"bugs": "https://github.com/singapore/renovate/issues",
"contributors": [
{
"name": "Rhys Arkins"
}
],
"packageManager": "yarn@3.0.0",
"dependencies": {
"autoprefixer": "6.5.0",
"bower": "~1.6.0",
"browserify": "13.1.0",
"browserify-css": "0.9.2",
"cheerio": "=0.22.0",
"config": "1.21.0"
},
"devDependencies": {
"enabled": false,
"angular": "^1.5.8",
"angular-touch": "1.5.8",
"angular-sanitize": "1.5.8",
"@angular/core": "4.0.0-beta.1"
},
"resolutions": {
"config": "1.21.0",
"**/@angular/cli": "8.0.0",
"**/angular": "1.33.0",
"config/glob": "1.0.0"
},
"homepage": "https://keylocation.sg",
"keywords": [
"Key Location",
"Singapore"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "http://github.com/singapore/renovate.git"
}
}
44 changes: 44 additions & 0 deletions lib/manager/npm/__fixtures__/outputs/014.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "renovate",
"description": "Client node modules for renovate",
"version": "1.0.0",
"author": "Rhys Arkins <rhys@keylocation.sg>",
"bugs": "https://github.com/singapore/renovate/issues",
"contributors": [
{
"name": "Rhys Arkins"
}
],
"packageManager": "yarn@3.1.0",
"dependencies": {
"autoprefixer": "6.5.0",
"bower": "~1.6.0",
"browserify": "13.1.0",
"browserify-css": "0.9.2",
"cheerio": "=0.22.0",
"config": "1.21.0"
},
"devDependencies": {
"enabled": false,
"angular": "^1.5.8",
"angular-touch": "1.5.8",
"angular-sanitize": "1.5.8",
"@angular/core": "4.0.0-beta.1"
},
"resolutions": {
"config": "1.21.0",
"**/@angular/cli": "8.0.0",
"**/angular": "1.33.0",
"config/glob": "1.0.0"
},
"homepage": "https://keylocation.sg",
"keywords": [
"Key Location",
"Singapore"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "http://github.com/singapore/renovate.git"
}
}
33 changes: 33 additions & 0 deletions lib/manager/npm/extract/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,39 @@ Object {
}
`;

exports[`manager/npm/extract/index .extractPackageFile() extracts packageManager 1`] = `
Object {
"constraints": Object {
"yarn": "3.0.0",
},
"deps": Array [
Object {
"commitMessageTopic": "Yarn",
"currentValue": "3.0.0",
"datasource": "npm",
"depName": "yarn",
"depType": "packageManager",
"prettyDepType": "packageManager",
},
],
"lernaClient": undefined,
"lernaPackages": undefined,
"managerData": Object {
"lernaJsonFile": undefined,
"yarnZeroInstall": false,
},
"npmLock": undefined,
"npmrc": undefined,
"packageFileVersion": undefined,
"packageJsonName": undefined,
"packageJsonType": "app",
"pnpmShrinkwrap": undefined,
"skipInstalls": true,
"yarnLock": undefined,
"yarnWorkspacesPackages": undefined,
}
`;

exports[`manager/npm/extract/index .extractPackageFile() extracts volta 1`] = `
Object {
"constraints": Object {
Expand Down
27 changes: 27 additions & 0 deletions lib/manager/npm/extract/__snapshots__/locked-versions.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ Array [
"depType": "engines",
"lockedVersion": undefined,
},
Object {
"currentValue": "1.22.0",
"depName": "yarn",
"depType": "packageManager",
"lockedVersion": undefined,
},
],
"lockFiles": Array [
"yarn.lock",
Expand Down Expand Up @@ -152,6 +158,13 @@ Array [
"lockedVersion": undefined,
"lookupName": "@yarnpkg/cli",
},
Object {
"currentValue": "2.1.0",
"depName": "yarn",
"depType": "packageManager",
"lockedVersion": undefined,
"lookupName": "@yarnpkg/cli",
},
],
"lockFiles": Array [
"yarn.lock",
Expand Down Expand Up @@ -186,6 +199,13 @@ Array [
"lockedVersion": undefined,
"lookupName": "@yarnpkg/cli",
},
Object {
"currentValue": "2.2.0",
"depName": "yarn",
"depType": "packageManager",
"lockedVersion": undefined,
"lookupName": "@yarnpkg/cli",
},
],
"lockFiles": Array [
"yarn.lock",
Expand Down Expand Up @@ -220,6 +240,13 @@ Array [
"lockedVersion": undefined,
"lookupName": "@yarnpkg/cli",
},
Object {
"currentValue": "3.0.0",
"depName": "yarn",
"depType": "packageManager",
"lockedVersion": undefined,
"lookupName": "@yarnpkg/cli",
},
],
"lockFiles": Array [
"yarn.lock",
Expand Down
14 changes: 14 additions & 0 deletions lib/manager/npm/extract/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,20 @@ describe('manager/npm/extract/index', () => {
);
expect(res).toMatchSnapshot();
});

it('extracts packageManager', async () => {
const pJson = {
packageManager: 'yarn@3.0.0',
};
const pJsonStr = JSON.stringify(pJson);
const res = await npmExtract.extractPackageFile(
pJsonStr,
'package.json',
defaultConfig
);
// FIXME: explicit assert condition
expect(res).toMatchSnapshot();
});
});
describe('.postExtract()', () => {
it('runs', async () => {
Expand Down
17 changes: 14 additions & 3 deletions lib/manager/npm/extract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { id as npmId } from '../../../datasource/npm';
import { logger } from '../../../logger';
import { SkipReason } from '../../../types';
import { getSiblingFileName, readLocalFile } from '../../../util/fs';
import { regEx } from '../../../util/regex';
import * as nodeVersioning from '../../../versioning/node';
import { isValid, isVersion } from '../../../versioning/npm';
import type {
Expand Down Expand Up @@ -160,6 +161,7 @@ export async function extractPackageFile(
engines: 'engine',
volta: 'volta',
resolutions: 'resolutions',
packageManager: 'packageManager',
};

const constraints: Record<string, any> = {};
Expand All @@ -179,7 +181,7 @@ export async function extractPackageFile(
return dep;
}
dep.currentValue = input.trim();
if (depType === 'engines') {
if (depType === 'engines' || depType === 'packageManager') {
if (depName === 'node') {
dep.datasource = datasourceGithubTags.id;
dep.lookupName = 'nodejs/node';
Expand Down Expand Up @@ -321,10 +323,19 @@ export async function extractPackageFile(
}

for (const depType of Object.keys(depTypes)) {
if (packageJson[depType]) {
let dependencies = packageJson[depType];
if (dependencies) {
try {
if (depType === 'packageManager') {
const match = regEx('^(?<name>.+)@(?<range>.+)$').exec(dependencies);
// istanbul ignore next
if (!match) {
break;
}
dependencies = { [match.groups.name]: match.groups.range };
}
for (const [key, val] of Object.entries(
packageJson[depType] as NpmPackageDependency
dependencies as NpmPackageDependency
)) {
const depName = parseDepName(depType, key);
let dep: PackageDependency = {
Expand Down
5 changes: 5 additions & 0 deletions lib/manager/npm/extract/locked-versions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ describe('manager/npm/extract/locked-versions', () => {
depName: 'yarn',
currentValue: `^${yarnVersion}`,
},
{
depType: 'packageManager',
depName: 'yarn',
currentValue: `${yarnVersion}`,
},
],
},
];
Expand Down
6 changes: 5 additions & 1 deletion lib/manager/npm/extract/locked-versions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ export async function getLockedVersions(
lockFileCache[yarnLock].lockedVersions[
`${dep.depName}@${dep.currentValue}`
];
if (dep.depType === 'engines' && dep.depName === 'yarn' && !isYarn1) {
if (
(dep.depType === 'engines' || dep.depType === 'packageManager') &&
dep.depName === 'yarn' &&
!isYarn1
) {
dep.lookupName = '@yarnpkg/cli';
}
}
Expand Down
49 changes: 49 additions & 0 deletions lib/manager/npm/post-update/__snapshots__/index.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`manager/npm/post-update/index updateYarnBinary() should return .yarnrc.yml content if it has been overwritten 1`] = `
"yarnPath: .yarn/releases/yarn-3.0.2.cjs
a: b
"
`;

exports[`manager/npm/post-update/index updateYarnBinary() should return .yarnrc.yml content if it has been overwritten 2`] = `
Array [
Object {
"contents": "yarnPath: .yarn/releases/yarn-3.0.2.cjs
a: b
",
"name": "path/to/lockfile/.yarnrc.yml",
},
Object {
"contents": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs",
"name": "|delete|",
},
Object {
"contents": "new yarn
",
"executable": true,
"name": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs",
},
]
`;

exports[`manager/npm/post-update/index updateYarnBinary() should update the Yarn binary 1`] = `
Array [
Object {
"contents": "yarnPath: .yarn/releases/yarn-3.0.2.cjs
a: b
",
"name": "path/to/lockfile/.yarnrc.yml",
},
Object {
"contents": "path/to/lockfile/.yarn/releases/yarn-3.0.1.cjs",
"name": "|delete|",
},
Object {
"contents": "new yarn
",
"executable": true,
"name": "path/to/lockfile/.yarn/releases/yarn-3.0.2.cjs",
},
]
`;
23 changes: 23 additions & 0 deletions lib/manager/npm/post-update/__snapshots__/pnpm.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,26 @@ Array [
},
]
`;

exports[`manager/npm/post-update/pnpm uses the new version if packageManager is updated 1`] = `
Array [
Object {
"cmd": "pnpm install --recursive --lockfile-only --ignore-scripts --ignore-pnpmfile",
"options": Object {
"cwd": "some-dir",
"encoding": "utf-8",
"env": Object {
"HOME": "/home/user",
"HTTPS_PROXY": "https://example.com",
"HTTP_PROXY": "http://example.com",
"LANG": "en_US.UTF-8",
"LC_ALL": "en_US",
"NO_PROXY": "localhost",
"PATH": "/tmp/path",
},
"maxBuffer": 10485760,
"timeout": 900000,
},
},
]
`;
Loading