Skip to content

Commit a277db6

Browse files
feat(rush): add support for resolution only mode with pnpm (#4893)
* feat(rush): add support for resolution only mode with pnpm * add changeset * Update common/config/rush/experiments.json * only enable resolution only for pnpm * fix if statement * fix snapshots * allow rush config to be nullable and adjust message * update snapshots --------- Co-authored-by: Aramis Sennyey <[email protected]>
1 parent 756a999 commit a277db6

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft/rush",
5+
"comment": "Add support for `--resolution-only` to `rush install` to enforce strict peer dependency resolution.",
6+
"type": "none"
7+
}
8+
],
9+
"packageName": "@microsoft/rush"
10+
}

libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ Object {
462462
"required": false,
463463
"shortName": undefined,
464464
},
465+
Object {
466+
"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.",
467+
"environmentVariable": undefined,
468+
"kind": "Flag",
469+
"longName": "--resolution-only",
470+
"required": false,
471+
"shortName": undefined,
472+
},
465473
],
466474
},
467475
Object {

libraries/rush-lib/src/cli/actions/InstallAction.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import type { RushConfigurationProject } from '../../api/RushConfigurationProjec
1111

1212
export class InstallAction extends BaseInstallAction {
1313
private readonly _checkOnlyParameter: CommandLineFlagParameter;
14+
private readonly _resolutionOnlyParameter: CommandLineFlagParameter | undefined;
1415

1516
public constructor(parser: RushCommandLineParser) {
1617
super({
@@ -45,6 +46,13 @@ export class InstallAction extends BaseInstallAction {
4546
parameterLongName: '--check-only',
4647
description: `Only check the validity of the shrinkwrap file without performing an install.`
4748
});
49+
50+
if (this.rushConfiguration?.packageManager === 'pnpm') {
51+
this._resolutionOnlyParameter = this.defineFlagParameter({
52+
parameterLongName: '--resolution-only',
53+
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.`
54+
});
55+
}
4856
}
4957

5058
protected async buildInstallOptionsAsync(): Promise<Omit<IInstallManagerOptions, 'subspace'>> {
@@ -71,6 +79,7 @@ export class InstallAction extends BaseInstallAction {
7179
pnpmFilterArgumentValues:
7280
(await this._selectionParameters?.getPnpmFilterArgumentValuesAsync(this._terminal)) ?? [],
7381
checkOnly: this._checkOnlyParameter.value,
82+
resolutionOnly: this._resolutionOnlyParameter?.value,
7483
beforeInstallAsync: () => this.rushSession.hooks.beforeInstall.promise(this),
7584
terminal: this._terminal
7685
};

libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,7 @@ exports[`CommandLineHelp prints the help for each action: install 1`] = `
627627
[--to-version-policy VERSION_POLICY_NAME]
628628
[--from-version-policy VERSION_POLICY_NAME]
629629
[--subspace SUBSPACE_NAME] [--check-only]
630+
[--resolution-only]
630631
631632
632633
The \\"rush install\\" command installs package dependencies for all your
@@ -755,6 +756,10 @@ Optional arguments:
755756
be enabled in subspaces.json.
756757
--check-only Only check the validity of the shrinkwrap file
757758
without performing an install.
759+
--resolution-only Only perform dependency resolution, useful for
760+
ensuring peer dependendencies are up to date. Note
761+
that this flag is only supported when using the pnpm
762+
package manager.
758763
"
759764
`;
760765

libraries/rush-lib/src/logic/base/BaseInstallManager.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,12 +745,18 @@ ${gitLfsHookHandling}
745745
pnpmFilterArgumentValues,
746746
onlyShrinkwrap,
747747
networkConcurrency,
748-
allowShrinkwrapUpdates
748+
allowShrinkwrapUpdates,
749+
resolutionOnly
749750
} = options;
750751

751752
if (offline && this.rushConfiguration.packageManager !== 'pnpm') {
752753
throw new Error('The "--offline" parameter is only supported when using the PNPM package manager.');
753754
}
755+
if (resolutionOnly && this.rushConfiguration.packageManager !== 'pnpm') {
756+
throw new Error(
757+
'The "--resolution-only" parameter is only supported when using the PNPM package manager.'
758+
);
759+
}
754760
if (this.rushConfiguration.packageManager === 'npm') {
755761
if (semver.lt(this.rushConfiguration.packageManagerToolVersion, '5.0.0')) {
756762
// NOTE:
@@ -842,6 +848,10 @@ ${gitLfsHookHandling}
842848
args.push('--strict-peer-dependencies');
843849
}
844850

851+
if (resolutionOnly) {
852+
args.push('--resolution-only');
853+
}
854+
845855
/*
846856
If user set auto-install-peers in pnpm-config.json only, use the value in pnpm-config.json
847857
If user set auto-install-peers in pnpm-config.json and .npmrc, use the value in pnpm-config.json

libraries/rush-lib/src/logic/base/BaseInstallManagerTypes.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ export interface IInstallManagerOptions {
2222
*/
2323
checkOnly: boolean;
2424

25+
/**
26+
* Whether to only run resolutions. Only supported for PNPM.
27+
*/
28+
resolutionOnly?: boolean;
29+
2530
/**
2631
* Whether a "--bypass-policy" flag can be specified.
2732
*/

0 commit comments

Comments
 (0)