-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
145 additions
and
136 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
lib/manager/npm/update/dependency/__snapshots__/index.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`/Users/rhys/src/renovatebot/renovate/lib/manager/npm/update/dependency .updateDependency(fileContent, depType, depName, newValue) replaces a github dependency value 1`] = `"{\\"dependencies\\":{\\"gulp\\":\\"gulpjs/gulp#v4.0.0\\"}}"`; | ||
|
||
exports[`/Users/rhys/src/renovatebot/renovate/lib/manager/npm/update/dependency .updateDependency(fileContent, depType, depName, newValue) replaces a github fully specified version 1`] = `"{\\"dependencies\\":{\\"n\\":\\"git+https://github.com/owner/n#v1.1.0\\"}}"`; | ||
|
||
exports[`/Users/rhys/src/renovatebot/renovate/lib/manager/npm/update/dependency .updateDependency(fileContent, depType, depName, newValue) replaces a github short hash 1`] = `"{\\"dependencies\\":{\\"gulp\\":\\"gulpjs/gulp#0000000\\"}}"`; | ||
|
||
exports[`/Users/rhys/src/renovatebot/renovate/lib/manager/npm/update/dependency .updateDependency(fileContent, depType, depName, newValue) replaces a npm package alias 1`] = `"{\\"dependencies\\":{\\"hapi\\":\\"npm:@hapi/hapi@18.3.1\\"}}"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 3 additions & 54 deletions
57
lib/manager/npm/update.ts → lib/manager/npm/update/dependency/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { bumpPackageVersion } from './package-version'; | ||
export { updateDependency } from './dependency'; |
7 changes: 7 additions & 0 deletions
7
lib/manager/npm/update/package-version/__snapshots__/index.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`/Users/rhys/src/renovatebot/renovate/lib/manager/npm/update/package-version .bumpPackageVersion() increments 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.0.3\\",\\"dependencies\\":{\\"chalk\\":\\"2.4.2\\"}}"`; | ||
|
||
exports[`/Users/rhys/src/renovatebot/renovate/lib/manager/npm/update/package-version .bumpPackageVersion() mirrors 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"2.4.2\\",\\"dependencies\\":{\\"chalk\\":\\"2.4.2\\"}}"`; | ||
|
||
exports[`/Users/rhys/src/renovatebot/renovate/lib/manager/npm/update/package-version .bumpPackageVersion() updates 1`] = `"{\\"name\\":\\"some-package\\",\\"version\\":\\"0.1.0\\",\\"dependencies\\":{\\"chalk\\":\\"2.4.2\\"}}"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as npmUpdater from '.'; | ||
|
||
describe(__dirname, () => { | ||
describe('.bumpPackageVersion()', () => { | ||
const content = JSON.stringify({ | ||
name: 'some-package', | ||
version: '0.0.2', | ||
dependencies: { chalk: '2.4.2' }, | ||
}); | ||
it('mirrors', () => { | ||
const { bumpedContent } = npmUpdater.bumpPackageVersion( | ||
content, | ||
'0.0.2', | ||
'mirror:chalk' | ||
); | ||
expect(bumpedContent).toMatchSnapshot(); | ||
expect(bumpedContent).not.toEqual(content); | ||
}); | ||
it('aborts mirror', () => { | ||
const { bumpedContent } = npmUpdater.bumpPackageVersion( | ||
content, | ||
'0.0.2', | ||
'mirror:a' | ||
); | ||
expect(bumpedContent).toEqual(content); | ||
}); | ||
it('increments', () => { | ||
const { bumpedContent } = npmUpdater.bumpPackageVersion( | ||
content, | ||
'0.0.2', | ||
'patch' | ||
); | ||
expect(bumpedContent).toMatchSnapshot(); | ||
expect(bumpedContent).not.toEqual(content); | ||
}); | ||
it('no ops', () => { | ||
const { bumpedContent } = npmUpdater.bumpPackageVersion( | ||
content, | ||
'0.0.1', | ||
'patch' | ||
); | ||
expect(bumpedContent).toEqual(content); | ||
}); | ||
it('updates', () => { | ||
const { bumpedContent } = npmUpdater.bumpPackageVersion( | ||
content, | ||
'0.0.1', | ||
'minor' | ||
); | ||
expect(bumpedContent).toMatchSnapshot(); | ||
expect(bumpedContent).not.toEqual(content); | ||
}); | ||
it('returns content if bumping errors', async () => { | ||
jest.mock('semver', () => ({ | ||
inc: () => { | ||
throw new Error('semver inc'); | ||
}, | ||
})); | ||
const npmUpdater1 = await import('.'); | ||
const { bumpedContent } = npmUpdater1.bumpPackageVersion( | ||
content, | ||
'0.0.2', | ||
true as any | ||
); | ||
expect(bumpedContent).toEqual(content); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { ReleaseType, inc } from 'semver'; | ||
import { logger } from '../../../../logger'; | ||
import { BumpPackageVersionResult } from '../../../common'; | ||
|
||
export function bumpPackageVersion( | ||
content: string, | ||
currentValue: string, | ||
bumpVersion: ReleaseType | string | ||
): BumpPackageVersionResult { | ||
logger.debug( | ||
{ bumpVersion, currentValue }, | ||
'Checking if we should bump package.json version' | ||
); | ||
let newPjVersion: string; | ||
let bumpedContent = content; | ||
try { | ||
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 { bumpedContent }; | ||
} | ||
} else { | ||
newPjVersion = inc(currentValue, bumpVersion as ReleaseType); | ||
} | ||
logger.debug({ newPjVersion }); | ||
bumpedContent = content.replace( | ||
/("version":\s*")[^"]*/, | ||
`$1${newPjVersion}` | ||
); | ||
if (bumpedContent === content) { | ||
logger.debug('Version was already bumped'); | ||
} else { | ||
logger.debug('Bumped package.json version'); | ||
} | ||
} catch (err) { | ||
logger.warn( | ||
{ | ||
content, | ||
currentValue, | ||
bumpVersion, | ||
}, | ||
'Failed to bumpVersion' | ||
); | ||
} | ||
return { bumpedContent }; | ||
} |