mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
feat(manager/npm): support pnpmDedupe (#20392)
Co-authored-by: Rhys Arkins <rhys@arkins.net>
This commit is contained in:
parent
634eb8f8e3
commit
2235659b18
4 changed files with 33 additions and 1 deletions
|
@ -2168,6 +2168,7 @@ Table with options:
|
||||||
| `gomodTidyE` | Run `go mod tidy -e` after Go module updates. |
|
| `gomodTidyE` | Run `go mod tidy -e` after Go module updates. |
|
||||||
| `gomodUpdateImportPaths` | Update source import paths on major module updates, using [mod](https://github.com/marwan-at-work/mod). |
|
| `gomodUpdateImportPaths` | Update source import paths on major module updates, using [mod](https://github.com/marwan-at-work/mod). |
|
||||||
| `npmDedupe` | Run `npm dedupe` after `package-lock.json` updates. |
|
| `npmDedupe` | Run `npm dedupe` after `package-lock.json` updates. |
|
||||||
|
| `pnpmDedupe` | Run `pnpm dedupe` after `pnpm-lock.yaml` updates. |
|
||||||
| `yarnDedupeFewer` | Run `yarn-deduplicate --strategy fewer` after `yarn.lock` updates. |
|
| `yarnDedupeFewer` | Run `yarn-deduplicate --strategy fewer` after `yarn.lock` updates. |
|
||||||
| `yarnDedupeHighest` | Run `yarn-deduplicate --strategy highest` (`yarn dedupe --strategy highest` for Yarn >=2.2.0) after `yarn.lock` updates. |
|
| `yarnDedupeHighest` | Run `yarn-deduplicate --strategy highest` (`yarn dedupe --strategy highest` for Yarn >=2.2.0) after `yarn.lock` updates. |
|
||||||
|
|
||||||
|
|
|
@ -1996,6 +1996,7 @@ const options: RenovateOptions[] = [
|
||||||
'gomodTidy1.17',
|
'gomodTidy1.17',
|
||||||
'gomodTidyE',
|
'gomodTidyE',
|
||||||
'npmDedupe',
|
'npmDedupe',
|
||||||
|
'pnpmDedupe',
|
||||||
'yarnDedupeFewer',
|
'yarnDedupeFewer',
|
||||||
'yarnDedupeHighest',
|
'yarnDedupeHighest',
|
||||||
],
|
],
|
||||||
|
|
|
@ -69,6 +69,27 @@ describe('modules/manager/npm/post-update/pnpm', () => {
|
||||||
expect(execSnapshots).toMatchSnapshot();
|
expect(execSnapshots).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('performs dedupe', async () => {
|
||||||
|
const execSnapshots = mockExecAll();
|
||||||
|
fs.readLocalFile.mockResolvedValue('package-lock-contents');
|
||||||
|
const postUpdateOptions = ['pnpmDedupe'];
|
||||||
|
const res = await pnpmHelper.generateLockFile(
|
||||||
|
'some-dir',
|
||||||
|
{},
|
||||||
|
{ ...config, postUpdateOptions }
|
||||||
|
);
|
||||||
|
expect(fs.readLocalFile).toHaveBeenCalledTimes(1);
|
||||||
|
expect(res.lockFile).toBe('package-lock-contents');
|
||||||
|
expect(execSnapshots).toMatchObject([
|
||||||
|
{
|
||||||
|
cmd: 'pnpm install --recursive --lockfile-only --ignore-scripts --ignore-pnpmfile',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cmd: 'pnpm dedupe',
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it('uses the new version if packageManager is updated', async () => {
|
it('uses the new version if packageManager is updated', async () => {
|
||||||
const execSnapshots = mockExecAll();
|
const execSnapshots = mockExecAll();
|
||||||
fs.readLocalFile.mockResolvedValue('package-lock-contents');
|
fs.readLocalFile.mockResolvedValue('package-lock-contents');
|
||||||
|
|
|
@ -53,6 +53,8 @@ export async function generateLockFile(
|
||||||
extraEnv.NPM_AUTH = env.NPM_AUTH;
|
extraEnv.NPM_AUTH = env.NPM_AUTH;
|
||||||
extraEnv.NPM_EMAIL = env.NPM_EMAIL;
|
extraEnv.NPM_EMAIL = env.NPM_EMAIL;
|
||||||
}
|
}
|
||||||
|
const commands: string[] = [];
|
||||||
|
|
||||||
cmd = 'pnpm';
|
cmd = 'pnpm';
|
||||||
let args = 'install --recursive --lockfile-only';
|
let args = 'install --recursive --lockfile-only';
|
||||||
if (!GlobalConfig.get('allowScripts') || config.ignoreScripts) {
|
if (!GlobalConfig.get('allowScripts') || config.ignoreScripts) {
|
||||||
|
@ -60,6 +62,13 @@ export async function generateLockFile(
|
||||||
args += ' --ignore-pnpmfile';
|
args += ' --ignore-pnpmfile';
|
||||||
}
|
}
|
||||||
logger.trace({ cmd, args }, 'pnpm command');
|
logger.trace({ cmd, args }, 'pnpm command');
|
||||||
|
commands.push(`${cmd} ${args}`);
|
||||||
|
|
||||||
|
// postUpdateOptions
|
||||||
|
if (config.postUpdateOptions?.includes('pnpmDedupe')) {
|
||||||
|
logger.debug('Performing pnpm dedupe');
|
||||||
|
commands.push('pnpm dedupe');
|
||||||
|
}
|
||||||
|
|
||||||
if (upgrades.find((upgrade) => upgrade.isLockFileMaintenance)) {
|
if (upgrades.find((upgrade) => upgrade.isLockFileMaintenance)) {
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
@ -75,7 +84,7 @@ export async function generateLockFile(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await exec(`${cmd} ${args}`, execOptions);
|
await exec(commands, execOptions);
|
||||||
lockFile = await readLocalFile(lockFileName, 'utf8');
|
lockFile = await readLocalFile(lockFileName, 'utf8');
|
||||||
} catch (err) /* istanbul ignore next */ {
|
} catch (err) /* istanbul ignore next */ {
|
||||||
if (err.message === TEMPORARY_ERROR) {
|
if (err.message === TEMPORARY_ERROR) {
|
||||||
|
|
Loading…
Reference in a new issue