mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-10 05:56: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);
|
expect(testContent).toEqual(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it.failing('replaces package', () => {
|
it('replaces package', () => {
|
||||||
const upgrade = {
|
const upgrade = {
|
||||||
depType: 'pnpm.catalog',
|
depType: 'pnpm.catalog',
|
||||||
depName: 'config',
|
depName: 'config',
|
||||||
newName: 'abc',
|
newName: 'abc',
|
||||||
newValue: '2.0.0',
|
newValue: '2.0.0',
|
||||||
|
managerData: {
|
||||||
|
catalogName: 'default',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
const pnpmWorkspaceYaml = yamlCodeBlock`
|
const pnpmWorkspaceYaml = yamlCodeBlock`
|
||||||
packages:
|
packages:
|
||||||
|
|
|
@ -58,19 +58,47 @@ export function updatePnpmCatalogDependency({
|
||||||
return fileContent;
|
return fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle depName === oldValue
|
// Update the value
|
||||||
// The old value is the name of the dependency itself
|
const path = getDepPath({
|
||||||
|
depName: depName!,
|
||||||
|
catalogName,
|
||||||
|
usesImplicitDefaultCatalog,
|
||||||
|
});
|
||||||
|
|
||||||
if (oldVersion === undefined) {
|
if (!document.hasIn(path)) {
|
||||||
// There is some subtlety here
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (catalogName === 'default' && usesImplicitDefaultCatalog) {
|
document.setIn(path, newValue);
|
||||||
document.setIn(['catalog', depName], newValue);
|
|
||||||
} else {
|
// Update the name, for replacements
|
||||||
document.setIn(['catalogs', catalogName, depName], newValue);
|
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);
|
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