mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-09 13:36:26 +00:00
feat(npm): implement replacement for pnpm catalog updates
This commit is contained in:
parent
ea5c14f003
commit
e50bc2f9b5
2 changed files with 40 additions and 9 deletions
|
@ -115,12 +115,15 @@ describe('modules/manager/npm/update/dependency/pnpm', () => {
|
|||
expect(testContent).toEqual(expected);
|
||||
});
|
||||
|
||||
it.failing('replaces package', () => {
|
||||
it('replaces package', () => {
|
||||
const upgrade = {
|
||||
depType: 'pnpm.catalog',
|
||||
depName: 'config',
|
||||
newName: 'abc',
|
||||
newValue: '2.0.0',
|
||||
managerData: {
|
||||
catalogName: 'default',
|
||||
},
|
||||
};
|
||||
const pnpmWorkspaceYaml = yamlCodeBlock`
|
||||
packages:
|
||||
|
|
|
@ -58,19 +58,47 @@ export function updatePnpmCatalogDependency({
|
|||
return fileContent;
|
||||
}
|
||||
|
||||
// TODO: handle depName === oldValue
|
||||
// The old value is the name of the dependency itself
|
||||
// Update the value
|
||||
const path = getDepPath({
|
||||
depName: depName!,
|
||||
catalogName,
|
||||
usesImplicitDefaultCatalog,
|
||||
});
|
||||
|
||||
if (oldVersion === undefined) {
|
||||
// There is some subtlety here
|
||||
if (!document.hasIn(path)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (catalogName === 'default' && usesImplicitDefaultCatalog) {
|
||||
document.setIn(['catalog', depName], newValue);
|
||||
} else {
|
||||
document.setIn(['catalogs', catalogName, depName], newValue);
|
||||
document.setIn(path, newValue);
|
||||
|
||||
// Update the name, for replacements
|
||||
if (upgrade.newName) {
|
||||
const newPath = getDepPath({
|
||||
depName: upgrade.newName,
|
||||
catalogName,
|
||||
usesImplicitDefaultCatalog,
|
||||
});
|
||||
const oldValue = document.getIn(path);
|
||||
|
||||
document.deleteIn(path);
|
||||
document.setIn(newPath, oldValue);
|
||||
}
|
||||
|
||||
return stringify(document);
|
||||
}
|
||||
|
||||
function getDepPath({
|
||||
catalogName,
|
||||
depName,
|
||||
usesImplicitDefaultCatalog,
|
||||
}: {
|
||||
usesImplicitDefaultCatalog: boolean;
|
||||
catalogName: string;
|
||||
depName: string;
|
||||
}): string[] {
|
||||
if (catalogName === 'default' && usesImplicitDefaultCatalog) {
|
||||
return ['catalog', depName];
|
||||
} else {
|
||||
return ['catalogs', catalogName, depName];
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue