Skip to content
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

feat(npm): support binarySource=install for pnpm #13723

Merged
merged 2 commits into from Jan 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 6 additions & 12 deletions lib/manager/npm/post-update/pnpm.ts
@@ -1,11 +1,9 @@
import semver from 'semver';
import { quote } from 'shlex';
import upath from 'upath';
import { GlobalConfig } from '../../../config/global';
import { TEMPORARY_ERROR } from '../../../constants/error-messages';
import { logger } from '../../../logger';
import { exec } from '../../../util/exec';
import type { ExecOptions } from '../../../util/exec/types';
import type { ExecOptions, ToolConstraint } from '../../../util/exec/types';
import { readFile, remove } from '../../../util/fs';
import type { PostUpdateConfig, Upgrade } from '../../types';
import { getNodeConstraint } from './node-version';
Expand All @@ -24,18 +22,14 @@ export async function generateLockFile(
let stderr: string;
let cmd = 'pnpm';
try {
let installPnpm = 'npm i -g pnpm';
const pnpmUpdate = upgrades.find(
(upgrade) =>
upgrade.depType === 'packageManager' && upgrade.depName === 'pnpm'
);
const pnpmCompatibility = pnpmUpdate
? pnpmUpdate.newValue
: config.constraints?.pnpm;
if (semver.validRange(pnpmCompatibility)) {
installPnpm += `@${quote(pnpmCompatibility)}`;
}
const preCommands = [installPnpm];
const pnpmToolConstraint: ToolConstraint = {
toolName: 'pnpm',
constraint: pnpmUpdate ? pnpmUpdate.newValue : config.constraints?.pnpm,
};
const tagConstraint = await getNodeConstraint(config);
const execOptions: ExecOptions = {
cwd,
Expand All @@ -48,7 +42,7 @@ export async function generateLockFile(
tagScheme: 'node',
tagConstraint,
},
preCommands,
toolConstraints: [pnpmToolConstraint],
};
// istanbul ignore if
if (GlobalConfig.get('exposeAllEnv')) {
Expand Down
5 changes: 5 additions & 0 deletions lib/util/exec/buildpack.ts
Expand Up @@ -25,6 +25,11 @@ const allToolConfig: Record<string, ToolConfig> = {
hash: true,
versioning: npmVersioningId,
},
pnpm: {
datasource: 'npm',
depName: 'pnpm',
versioning: npmVersioningId,
},
};

export function supportsDynamicInstall(toolName: string): boolean {
Expand Down