Skip to content

feat(manager/npm): use volta pins as constraints #35869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions lib/modules/manager/npm/post-update/pnpm.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { GlobalConfig } from '../../../../config/global';
import type { PostUpdateConfig, Upgrade } from '../../types';
import { getNodeToolConstraint } from './node-version';
Expand Down Expand Up @@ -284,6 +285,61 @@ describe('modules/manager/npm/post-update/pnpm', () => {
]);
});

it('uses volta version and puts it into constraint', async () => {
const execSnapshots = mockExecAll();
const configTemp = partial<PostUpdateConfig>();
const fileContent = codeBlock`
{
"name": "parent",
"version": "1.0.0",
"engines": {
"pnpm": "^6.0.0"
},
"engine-strict": true,
"volta": {
"pnpm": "6.15.0"
}
}

`;
fs.readLocalFile
.mockResolvedValueOnce(fileContent)
.mockResolvedValue('package-lock-contents');
const res = await pnpmHelper.generateLockFile(
'some-folder',
{},
configTemp,
[
{
depType: 'volta',
depName: 'pnpm',
},
],
);
expect(fs.readLocalFile).toHaveBeenCalledTimes(2);
expect(res.lockFile).toBe('package-lock-contents');
expect(execSnapshots).toMatchObject([
{
cmd: 'pnpm install --lockfile-only --ignore-scripts --ignore-pnpmfile',
options: {
cwd: 'some-folder',
encoding: 'utf-8',
env: {
HTTP_PROXY: 'http://example.com',
HTTPS_PROXY: 'https://example.com',
NO_PROXY: 'localhost',
HOME: '/home/user',
PATH: '/tmp/path',
LANG: 'en_US.UTF-8',
LC_ALL: 'en_US',
},
maxBuffer: 10485760,
timeout: 900000,
},
},
]);
});

it('uses skips pnpm v7 if lockfileVersion indicates <7', async () => {
mockExecAll();
const configTemp = partial<PostUpdateConfig>();
Expand Down
6 changes: 6 additions & 0 deletions lib/modules/manager/npm/post-update/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ export function getPackageManagerVersion(
name: string,
pkg: PackageJsonSchema,
): string | null {
if (pkg.volta?.[name]) {
const version = pkg.volta[name];
logger.debug(`Found ${name} constraint in package.json volta: ${version}`);

return version;
}
if (pkg.packageManager?.name === name) {
const version = pkg.packageManager.version;
logger.debug(
Expand Down
1 change: 1 addition & 0 deletions lib/modules/manager/npm/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const PackageJsonSchema = z.object({
devDependencies: LooseRecord(z.string()).optional(),
peerDependencies: LooseRecord(z.string()).optional(),
packageManager: PackageManagerSchema.optional(),
volta: LooseRecord(z.string()).optional(),
});

export type PackageJsonSchema = z.infer<typeof PackageJsonSchema>;
Expand Down