diff --git a/lib/manager/npm/update.js b/lib/manager/npm/update.js index e518fd67335009386a0b795fc716c760398c3ea0..05419bb6e489072d47e6af64e6d5b694146a51f9 100644 --- a/lib/manager/npm/update.js +++ b/lib/manager/npm/update.js @@ -152,8 +152,23 @@ function bumpPackageVersion(content, currentValue, bumpVersion) { { bumpVersion, currentValue }, 'Checking if we should bump package.json version' ); + let newPjVersion; try { - const newPjVersion = semver.inc(currentValue, bumpVersion); + if (bumpVersion.startsWith('mirror:')) { + const mirrorPackage = bumpVersion.replace('mirror:', ''); + const parsedContent = JSON.parse(content); + newPjVersion = + (parsedContent.dependencies || {})[mirrorPackage] || + (parsedContent.devDependencies || {})[mirrorPackage] || + (parsedContent.optionalDependencies || {})[mirrorPackage] || + (parsedContent.peerDependencies || {})[mirrorPackage]; + if (!newPjVersion) { + logger.warn('bumpVersion mirror package not found: ', mirrorPackage); + return content; + } + } else { + newPjVersion = semver.inc(currentValue, bumpVersion); + } logger.debug({ newPjVersion }); const bumpedContent = content.replace( /("version":\s*")[^"]*/, diff --git a/test/manager/npm/__snapshots__/update.spec.js.snap b/test/manager/npm/__snapshots__/update.spec.js.snap index 95785e2f7e0f978cdb267678ab1b674b9d08ffd3..21bae2617951adc179befb7f9884699b6c1d6477 100644 --- a/test/manager/npm/__snapshots__/update.spec.js.snap +++ b/test/manager/npm/__snapshots__/update.spec.js.snap @@ -1,8 +1,10 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`workers/branch/package-json .bumpPackageVersion() increments 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.0.3\\"}"`; +exports[`workers/branch/package-json .bumpPackageVersion() increments 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.0.3\\",\\"dependencies\\":{\\"chalk\\":\\"2.4.2\\"}}"`; -exports[`workers/branch/package-json .bumpPackageVersion() updates 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.1.0\\"}"`; +exports[`workers/branch/package-json .bumpPackageVersion() mirrors 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"2.4.2\\",\\"dependencies\\":{\\"chalk\\":\\"2.4.2\\"}}"`; + +exports[`workers/branch/package-json .bumpPackageVersion() updates 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.1.0\\",\\"dependencies\\":{\\"chalk\\":\\"2.4.2\\"}}"`; exports[`workers/branch/package-json .updateDependency(fileContent, depType, depName, newValue) replaces a github dependency value 1`] = `"{\\"dependencies\\":{\\"gulp\\":\\"gulpjs/gulp#v4.0.0\\"}}"`; diff --git a/test/manager/npm/update.spec.js b/test/manager/npm/update.spec.js index b53582f58ce1b6bb05227f6c8c53dbc4b608925d..b95bba759c817ae9f5a6169fe063e955cf5190e6 100644 --- a/test/manager/npm/update.spec.js +++ b/test/manager/npm/update.spec.js @@ -123,7 +123,24 @@ describe('workers/branch/package-json', () => { }); }); describe('.bumpPackageVersion()', () => { - const content = JSON.stringify({ name: 'some-package', version: '0.0.2' }); + const content = JSON.stringify({ + name: 'some-package', + version: '0.0.2', + dependencies: { chalk: '2.4.2' }, + }); + it('mirrors', () => { + const res = npmUpdater.bumpPackageVersion( + content, + '0.0.2', + 'mirror:chalk' + ); + expect(res).toMatchSnapshot(); + expect(res).not.toEqual(content); + }); + it('aborts mirror', () => { + const res = npmUpdater.bumpPackageVersion(content, '0.0.2', 'mirror:a'); + expect(res).toEqual(content); + }); it('increments', () => { const res = npmUpdater.bumpPackageVersion(content, '0.0.2', 'patch'); expect(res).toMatchSnapshot(); diff --git a/website/docs/configuration-options.md b/website/docs/configuration-options.md index 7c13e6767d8df3c48d65f1d0351ae97666e6f488..ced14bafd63e6e786b07268c830cda994860fdc0 100644 --- a/website/docs/configuration-options.md +++ b/website/docs/configuration-options.md @@ -90,6 +90,8 @@ This field is combined with `branchPrefix` and `managerBranchPrefix` to form the Set this value to 'patch', 'minor' or 'major' to have Renovate update the version in your edited `package.json`. e.g. if you wish Renovate to always increase the target `package.json` version with a patch update, set this to `patch`. +You can also set this field to `"mirror:x"` where `x` is the name of a package in the `package.json`. Doing so means that the `package.json` `version` field will mirror whatever is the version for `x` dependened on. Make sure that version is a pinned version of course, as otherwise it won't be valid. + ## circleci ## commitBody