mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 15:06:27 +00:00
feat: update yarn resolutions
Detect if the upgraded dependency was already in “resolutions” and update it too if it was an exact match. Warn if it was not. Closes #1318
This commit is contained in:
parent
3c4f46b3b2
commit
163ce43a27
6 changed files with 63 additions and 0 deletions
|
@ -51,6 +51,47 @@ function setNewValue(currentFileContent, depType, depName, newVersion) {
|
||||||
);
|
);
|
||||||
return currentFileContent;
|
return currentFileContent;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
parsedContents &&
|
||||||
|
parsedContents.resolutions &&
|
||||||
|
parsedContents.resolutions[depName]
|
||||||
|
) {
|
||||||
|
if (parsedContents.resolutions[depName] === oldVersion) {
|
||||||
|
// Update the file = this is what we want
|
||||||
|
parsedContents.resolutions[depName] = newVersion;
|
||||||
|
// Look for the old version number
|
||||||
|
const oldResolution = `"${oldVersion}"`;
|
||||||
|
const newResolution = `"${newVersion}"`;
|
||||||
|
// Skip ahead to depType section
|
||||||
|
searchIndex = newFileContent.indexOf(`"resolutions"`);
|
||||||
|
logger.debug(`Starting search at index ${searchIndex}`);
|
||||||
|
// Iterate through the rest of the file
|
||||||
|
for (; searchIndex < newFileContent.length; searchIndex += 1) {
|
||||||
|
// First check if we have a hit for the old version
|
||||||
|
if (matchAt(newFileContent, searchIndex, oldResolution)) {
|
||||||
|
logger.debug(`Found match at index ${searchIndex}`);
|
||||||
|
// Now test if the result matches
|
||||||
|
const testContent = replaceAt(
|
||||||
|
newFileContent,
|
||||||
|
searchIndex,
|
||||||
|
oldResolution,
|
||||||
|
newResolution
|
||||||
|
);
|
||||||
|
// Compare the parsed JSON structure of old and new
|
||||||
|
if (_.isEqual(parsedContents, JSON.parse(testContent))) {
|
||||||
|
newFileContent = testContent;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// istanbul ignore next
|
||||||
|
logger.warn(
|
||||||
|
{ parsedContents },
|
||||||
|
'Upgraded dependency exists in yarn resolutions but is different version'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
return newFileContent;
|
return newFileContent;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.info({ err }, 'setNewValue error');
|
logger.info({ err }, 'setNewValue error');
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
"angular-sanitize": "1.5.8",
|
"angular-sanitize": "1.5.8",
|
||||||
"@angular/core": "4.0.0-beta.1"
|
"@angular/core": "4.0.0-beta.1"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"config": "1.21.0"
|
||||||
|
},
|
||||||
"homepage": "https://keylocation.sg",
|
"homepage": "https://keylocation.sg",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Key Location",
|
"Key Location",
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
"angular-sanitize": "1.5.8",
|
"angular-sanitize": "1.5.8",
|
||||||
"@angular/core": "4.0.0-beta.1"
|
"@angular/core": "4.0.0-beta.1"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"config": "1.21.0"
|
||||||
|
},
|
||||||
"homepage": "https://keylocation.sg",
|
"homepage": "https://keylocation.sg",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Key Location",
|
"Key Location",
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
"angular-sanitize": "1.5.8",
|
"angular-sanitize": "1.5.8",
|
||||||
"@angular/core": "4.0.0-beta.1"
|
"@angular/core": "4.0.0-beta.1"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"config": "1.21.0"
|
||||||
|
},
|
||||||
"homepage": "https://keylocation.sg",
|
"homepage": "https://keylocation.sg",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Key Location",
|
"Key Location",
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
"angular-sanitize": "1.6.1",
|
"angular-sanitize": "1.6.1",
|
||||||
"@angular/core": "4.0.0-beta.1"
|
"@angular/core": "4.0.0-beta.1"
|
||||||
},
|
},
|
||||||
|
"resolutions": {
|
||||||
|
"config": "1.21.0"
|
||||||
|
},
|
||||||
"homepage": "https://keylocation.sg",
|
"homepage": "https://keylocation.sg",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"Key Location",
|
"Key Location",
|
||||||
|
|
|
@ -23,6 +23,16 @@ describe('workers/branch/package-json', () => {
|
||||||
);
|
);
|
||||||
testContent.should.equal(outputContent);
|
testContent.should.equal(outputContent);
|
||||||
});
|
});
|
||||||
|
it('updates resolutions too', () => {
|
||||||
|
const testContent = npmUpdater.setNewValue(
|
||||||
|
input01Content,
|
||||||
|
'dependencies',
|
||||||
|
'config',
|
||||||
|
'1.22.0'
|
||||||
|
);
|
||||||
|
expect(JSON.parse(testContent).dependencies.config).toEqual('1.22.0');
|
||||||
|
expect(JSON.parse(testContent).resolutions.config).toEqual('1.22.0');
|
||||||
|
});
|
||||||
it('replaces only the first instance of a value', () => {
|
it('replaces only the first instance of a value', () => {
|
||||||
const outputContent = readFixture('outputs/012.json');
|
const outputContent = readFixture('outputs/012.json');
|
||||||
const testContent = npmUpdater.setNewValue(
|
const testContent = npmUpdater.setNewValue(
|
||||||
|
|
Loading…
Reference in a new issue