From 0563d10687da15237d330d0a55542142592a8804 Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Fri, 16 Aug 2024 12:10:48 -0400 Subject: [PATCH 1/8] feat(rush): add support for resolution only mode with pnpm --- common/config/rush/experiments.json | 2 +- .../test/__snapshots__/RushCommandLine.test.ts.snap | 8 ++++++++ libraries/rush-lib/src/cli/actions/InstallAction.ts | 7 +++++++ .../test/__snapshots__/CommandLineHelp.test.ts.snap | 3 +++ .../rush-lib/src/logic/base/BaseInstallManager.ts | 12 +++++++++++- .../src/logic/base/BaseInstallManagerTypes.ts | 5 +++++ 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/common/config/rush/experiments.json b/common/config/rush/experiments.json index 282d389ba0b..d435696f3fd 100644 --- a/common/config/rush/experiments.json +++ b/common/config/rush/experiments.json @@ -9,7 +9,7 @@ * By default, 'rush install' passes --no-prefer-frozen-lockfile to 'pnpm install'. * Set this option to true to pass '--frozen-lockfile' instead for faster installs. */ - "usePnpmFrozenLockfileForRushInstall": true, + // "usePnpmFrozenLockfileForRushInstall": true, /** * By default, 'rush update' passes --no-prefer-frozen-lockfile to 'pnpm install'. diff --git a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap index 1176f03cc55..082f73814e1 100644 --- a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap +++ b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap @@ -462,6 +462,14 @@ Object { "required": false, "shortName": undefined, }, + Object { + "description": "Only perform dependency resolution, useful for ensuring peer dependendencies are up to date.", + "environmentVariable": undefined, + "kind": "Flag", + "longName": "--resolution-only", + "required": false, + "shortName": undefined, + }, ], }, Object { diff --git a/libraries/rush-lib/src/cli/actions/InstallAction.ts b/libraries/rush-lib/src/cli/actions/InstallAction.ts index 97598c95a16..58313a2c217 100644 --- a/libraries/rush-lib/src/cli/actions/InstallAction.ts +++ b/libraries/rush-lib/src/cli/actions/InstallAction.ts @@ -11,6 +11,7 @@ import type { RushConfigurationProject } from '../../api/RushConfigurationProjec export class InstallAction extends BaseInstallAction { private readonly _checkOnlyParameter: CommandLineFlagParameter; + private readonly _resolutionOnlyParameter: CommandLineFlagParameter; public constructor(parser: RushCommandLineParser) { super({ @@ -45,6 +46,11 @@ export class InstallAction extends BaseInstallAction { parameterLongName: '--check-only', description: `Only check the validity of the shrinkwrap file without performing an install.` }); + + this._resolutionOnlyParameter = this.defineFlagParameter({ + parameterLongName: '--resolution-only', + description: `Only perform dependency resolution, useful for ensuring peer dependendencies are up to date.` + }); } protected async buildInstallOptionsAsync(): Promise> { @@ -71,6 +77,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 }; diff --git a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 6d7ef926f75..901fb6b0894 100644 --- a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -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 @@ -755,6 +756,8 @@ 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. " `; diff --git a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts index 8ce864ed08e..336e0514cc8 100644 --- a/libraries/rush-lib/src/logic/base/BaseInstallManager.ts +++ b/libraries/rush-lib/src/logic/base/BaseInstallManager.ts @@ -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: @@ -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 diff --git a/libraries/rush-lib/src/logic/base/BaseInstallManagerTypes.ts b/libraries/rush-lib/src/logic/base/BaseInstallManagerTypes.ts index e9241c6fbb4..051c96105d6 100644 --- a/libraries/rush-lib/src/logic/base/BaseInstallManagerTypes.ts +++ b/libraries/rush-lib/src/logic/base/BaseInstallManagerTypes.ts @@ -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. */ From 9824c0defe07467194d1854e91e276e6d882747b Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Fri, 16 Aug 2024 12:39:03 -0400 Subject: [PATCH 2/8] add changeset --- ...a-resolution-only-for-install_2024-08-16-16-38.json | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 common/changes/@microsoft/rush/sennyeya-resolution-only-for-install_2024-08-16-16-38.json diff --git a/common/changes/@microsoft/rush/sennyeya-resolution-only-for-install_2024-08-16-16-38.json b/common/changes/@microsoft/rush/sennyeya-resolution-only-for-install_2024-08-16-16-38.json new file mode 100644 index 00000000000..ed63aa17b99 --- /dev/null +++ b/common/changes/@microsoft/rush/sennyeya-resolution-only-for-install_2024-08-16-16-38.json @@ -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" +} \ No newline at end of file From c2b8aa0b01a4eed94e98188d2c91b9d00d246089 Mon Sep 17 00:00:00 2001 From: Aramis Sennyey <159921952+aramissennyeydd@users.noreply.github.com> Date: Mon, 19 Aug 2024 13:32:57 -0400 Subject: [PATCH 3/8] Update common/config/rush/experiments.json --- common/config/rush/experiments.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/config/rush/experiments.json b/common/config/rush/experiments.json index d435696f3fd..282d389ba0b 100644 --- a/common/config/rush/experiments.json +++ b/common/config/rush/experiments.json @@ -9,7 +9,7 @@ * By default, 'rush install' passes --no-prefer-frozen-lockfile to 'pnpm install'. * Set this option to true to pass '--frozen-lockfile' instead for faster installs. */ - // "usePnpmFrozenLockfileForRushInstall": true, + "usePnpmFrozenLockfileForRushInstall": true, /** * By default, 'rush update' passes --no-prefer-frozen-lockfile to 'pnpm install'. From 0226e5fb1e87e6c3f638b68eaa470f4f8dd7a8d1 Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Mon, 19 Aug 2024 14:07:22 -0400 Subject: [PATCH 4/8] only enable resolution only for pnpm --- .../__snapshots__/RushCommandLine.test.ts.snap | 8 -------- .../rush-lib/src/cli/actions/InstallAction.ts | 14 ++++++++------ .../__snapshots__/CommandLineHelp.test.ts.snap | 3 --- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap index 082f73814e1..1176f03cc55 100644 --- a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap +++ b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap @@ -462,14 +462,6 @@ Object { "required": false, "shortName": undefined, }, - Object { - "description": "Only perform dependency resolution, useful for ensuring peer dependendencies are up to date.", - "environmentVariable": undefined, - "kind": "Flag", - "longName": "--resolution-only", - "required": false, - "shortName": undefined, - }, ], }, Object { diff --git a/libraries/rush-lib/src/cli/actions/InstallAction.ts b/libraries/rush-lib/src/cli/actions/InstallAction.ts index 58313a2c217..62ddc64a568 100644 --- a/libraries/rush-lib/src/cli/actions/InstallAction.ts +++ b/libraries/rush-lib/src/cli/actions/InstallAction.ts @@ -11,7 +11,7 @@ import type { RushConfigurationProject } from '../../api/RushConfigurationProjec export class InstallAction extends BaseInstallAction { private readonly _checkOnlyParameter: CommandLineFlagParameter; - private readonly _resolutionOnlyParameter: CommandLineFlagParameter; + private readonly _resolutionOnlyParameter: CommandLineFlagParameter | undefined; public constructor(parser: RushCommandLineParser) { super({ @@ -47,10 +47,12 @@ export class InstallAction extends BaseInstallAction { description: `Only check the validity of the shrinkwrap file without performing an install.` }); - this._resolutionOnlyParameter = this.defineFlagParameter({ - parameterLongName: '--resolution-only', - description: `Only perform dependency resolution, useful for ensuring peer dependendencies are up to date.` - }); + 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.` + }); + } } protected async buildInstallOptionsAsync(): Promise> { @@ -77,7 +79,7 @@ export class InstallAction extends BaseInstallAction { pnpmFilterArgumentValues: (await this._selectionParameters?.getPnpmFilterArgumentValuesAsync(this._terminal)) ?? [], checkOnly: this._checkOnlyParameter.value, - resolutionOnly: this._resolutionOnlyParameter.value, + resolutionOnly: this._resolutionOnlyParameter?.value, beforeInstallAsync: () => this.rushSession.hooks.beforeInstall.promise(this), terminal: this._terminal }; diff --git a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 901fb6b0894..6d7ef926f75 100644 --- a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -627,7 +627,6 @@ 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 @@ -756,8 +755,6 @@ 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. " `; From ed52de41b6d42be7f33d6c33ae15d075149f8c92 Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Mon, 19 Aug 2024 15:45:59 -0400 Subject: [PATCH 5/8] fix if statement --- libraries/rush-lib/src/cli/actions/InstallAction.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/rush-lib/src/cli/actions/InstallAction.ts b/libraries/rush-lib/src/cli/actions/InstallAction.ts index 62ddc64a568..fcb400341f9 100644 --- a/libraries/rush-lib/src/cli/actions/InstallAction.ts +++ b/libraries/rush-lib/src/cli/actions/InstallAction.ts @@ -47,7 +47,7 @@ export class InstallAction extends BaseInstallAction { description: `Only check the validity of the shrinkwrap file without performing an install.` }); - if (this.rushConfiguration.packageManager !== 'pnpm') { + 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.` From 73535ac53625e89836b525220e657556aaa203fb Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Mon, 19 Aug 2024 16:01:55 -0400 Subject: [PATCH 6/8] fix snapshots --- .../api/test/__snapshots__/RushCommandLine.test.ts.snap | 8 ++++++++ .../cli/test/__snapshots__/CommandLineHelp.test.ts.snap | 3 +++ 2 files changed, 11 insertions(+) diff --git a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap index 1176f03cc55..082f73814e1 100644 --- a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap +++ b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap @@ -462,6 +462,14 @@ Object { "required": false, "shortName": undefined, }, + Object { + "description": "Only perform dependency resolution, useful for ensuring peer dependendencies are up to date.", + "environmentVariable": undefined, + "kind": "Flag", + "longName": "--resolution-only", + "required": false, + "shortName": undefined, + }, ], }, Object { diff --git a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 6d7ef926f75..901fb6b0894 100644 --- a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -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 @@ -755,6 +756,8 @@ 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. " `; From 1675c6a69b31a069bf76de7478e25a7288b277dc Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Wed, 21 Aug 2024 10:05:09 -0400 Subject: [PATCH 7/8] allow rush config to be nullable and adjust message --- libraries/rush-lib/src/cli/actions/InstallAction.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/rush-lib/src/cli/actions/InstallAction.ts b/libraries/rush-lib/src/cli/actions/InstallAction.ts index fcb400341f9..63925b70fc6 100644 --- a/libraries/rush-lib/src/cli/actions/InstallAction.ts +++ b/libraries/rush-lib/src/cli/actions/InstallAction.ts @@ -47,10 +47,10 @@ export class InstallAction extends BaseInstallAction { description: `Only check the validity of the shrinkwrap file without performing an install.` }); - if (this.rushConfiguration.packageManager === 'pnpm') { + 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.` + 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.` }); } } From 8704cf9ad2b7b26e495162639056249bdc9a4d09 Mon Sep 17 00:00:00 2001 From: Aramis Sennyey Date: Wed, 21 Aug 2024 10:06:14 -0400 Subject: [PATCH 8/8] update snapshots --- .../src/api/test/__snapshots__/RushCommandLine.test.ts.snap | 2 +- .../src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap index 082f73814e1..64f648883b6 100644 --- a/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap +++ b/libraries/rush-lib/src/api/test/__snapshots__/RushCommandLine.test.ts.snap @@ -463,7 +463,7 @@ Object { "shortName": undefined, }, Object { - "description": "Only perform dependency resolution, useful for ensuring peer dependendencies are up to date.", + "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", diff --git a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap index 901fb6b0894..bab50aaa6b9 100644 --- a/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap +++ b/libraries/rush-lib/src/cli/test/__snapshots__/CommandLineHelp.test.ts.snap @@ -757,7 +757,9 @@ Optional arguments: --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. + ensuring peer dependendencies are up to date. Note + that this flag is only supported when using the pnpm + package manager. " `;