Skip to content

feat(rush): add support for resolution only mode with pnpm #4893

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add support for `--resolution-only` to `rush install` to enforce strict peer dependency resolution.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ Object {
"required": false,
"shortName": undefined,
},
Object {
"description": "Only perform dependency resolution, useful for ensuring peer dependendencies are up to date. Note that this flag is only supported when using the pnpm package manager.",
"environmentVariable": undefined,
"kind": "Flag",
"longName": "--resolution-only",
"required": false,
"shortName": undefined,
},
],
},
Object {
Expand Down
9 changes: 9 additions & 0 deletions libraries/rush-lib/src/cli/actions/InstallAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { RushConfigurationProject } from '../../api/RushConfigurationProjec

export class InstallAction extends BaseInstallAction {
private readonly _checkOnlyParameter: CommandLineFlagParameter;
private readonly _resolutionOnlyParameter: CommandLineFlagParameter | undefined;

public constructor(parser: RushCommandLineParser) {
super({
Expand Down Expand Up @@ -45,6 +46,13 @@ export class InstallAction extends BaseInstallAction {
parameterLongName: '--check-only',
description: `Only check the validity of the shrinkwrap file without performing an install.`
});

if (this.rushConfiguration?.packageManager === 'pnpm') {
this._resolutionOnlyParameter = this.defineFlagParameter({
parameterLongName: '--resolution-only',
description: `Only perform dependency resolution, useful for ensuring peer dependendencies are up to date. Note that this flag is only supported when using the pnpm package manager.`
});
}
}

protected async buildInstallOptionsAsync(): Promise<Omit<IInstallManagerOptions, 'subspace'>> {
Expand All @@ -71,6 +79,7 @@ export class InstallAction extends BaseInstallAction {
pnpmFilterArgumentValues:
(await this._selectionParameters?.getPnpmFilterArgumentValuesAsync(this._terminal)) ?? [],
checkOnly: this._checkOnlyParameter.value,
resolutionOnly: this._resolutionOnlyParameter?.value,
beforeInstallAsync: () => this.rushSession.hooks.beforeInstall.promise(this),
terminal: this._terminal
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,7 @@ exports[`CommandLineHelp prints the help for each action: install 1`] = `
[--to-version-policy VERSION_POLICY_NAME]
[--from-version-policy VERSION_POLICY_NAME]
[--subspace SUBSPACE_NAME] [--check-only]
[--resolution-only]


The \\"rush install\\" command installs package dependencies for all your
Expand Down Expand Up @@ -755,6 +756,10 @@ Optional arguments:
be enabled in subspaces.json.
--check-only Only check the validity of the shrinkwrap file
without performing an install.
--resolution-only Only perform dependency resolution, useful for
ensuring peer dependendencies are up to date. Note
that this flag is only supported when using the pnpm
package manager.
"
`;

Expand Down
12 changes: 11 additions & 1 deletion libraries/rush-lib/src/logic/base/BaseInstallManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -745,12 +745,18 @@ ${gitLfsHookHandling}
pnpmFilterArgumentValues,
onlyShrinkwrap,
networkConcurrency,
allowShrinkwrapUpdates
allowShrinkwrapUpdates,
resolutionOnly
} = options;

if (offline && this.rushConfiguration.packageManager !== 'pnpm') {
throw new Error('The "--offline" parameter is only supported when using the PNPM package manager.');
}
if (resolutionOnly && this.rushConfiguration.packageManager !== 'pnpm') {
throw new Error(
'The "--resolution-only" parameter is only supported when using the PNPM package manager.'
);
}
if (this.rushConfiguration.packageManager === 'npm') {
if (semver.lt(this.rushConfiguration.packageManagerToolVersion, '5.0.0')) {
// NOTE:
Expand Down Expand Up @@ -842,6 +848,10 @@ ${gitLfsHookHandling}
args.push('--strict-peer-dependencies');
}

if (resolutionOnly) {
args.push('--resolution-only');
}

/*
If user set auto-install-peers in pnpm-config.json only, use the value in pnpm-config.json
If user set auto-install-peers in pnpm-config.json and .npmrc, use the value in pnpm-config.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ export interface IInstallManagerOptions {
*/
checkOnly: boolean;

/**
* Whether to only run resolutions. Only supported for PNPM.
*/
resolutionOnly?: boolean;

/**
* Whether a "--bypass-policy" flag can be specified.
*/
Expand Down
Loading