Skip to content

Commit

Permalink
fix(npm): issue with npm lerna deleting unrelated lockfile files (#17233
Browse files Browse the repository at this point in the history
)
  • Loading branch information
PhilipAbed committed Aug 18, 2022
1 parent b45ed09 commit 189e39b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/modules/manager/npm/post-update/index.spec.ts
Expand Up @@ -78,6 +78,16 @@ describe('modules/manager/npm/post-update/index', () => {
npmLock: 'package-lock.json',
rangeStrategy: 'widen',
},
{
depName: 'core-js',
isRemediation: true,
managerData: {
lernaJsonFile: 'lerna.json',
},
npmLock: 'randomFolder/package-lock.json',
lockFiles: ['randomFolder/package-lock.json'],
rangeStrategy: 'pin',
},
{
isLockfileUpdate: true,
npmLock: 'package-lock.json',
Expand Down Expand Up @@ -209,6 +219,19 @@ describe('modules/manager/npm/post-update/index', () => {
]);
});

it('works only on relevant folders', async () => {
git.getFile.mockResolvedValueOnce(
Fixtures.get('update-lockfile-massage-1/package-lock.json')
);
await expect(
writeExistingFiles(updateConfig, additionalFiles)
).resolves.toBeUndefined();

expect(fs.writeLocalFile).toHaveBeenCalledTimes(2);
expect(fs.deleteLocalFile).not.toHaveBeenCalled();
expect(git.getFile).toHaveBeenCalledOnce();
});

it('has no npm files', async () => {
await expect(writeExistingFiles(baseConfig, {})).toResolve();
});
Expand Down
3 changes: 3 additions & 0 deletions lib/modules/manager/npm/post-update/index.ts
Expand Up @@ -180,6 +180,9 @@ export async function writeExistingFiles(
const widens: string[] = [];
let lockFileChanged = false;
for (const upgrade of config.upgrades) {
if (upgrade.lockFiles && !upgrade.lockFiles.includes(npmLock)) {
continue;
}
if (
upgrade.rangeStrategy === 'widen' &&
upgrade.npmLock === npmLock
Expand Down

0 comments on commit 189e39b

Please sign in to comment.