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

[rush] Add --from to rush install #2435

Merged
merged 4 commits into from
Jan 29, 2021
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
22 changes: 21 additions & 1 deletion apps/rush-lib/src/cli/actions/InstallAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import { RushCommandLineParser } from '../RushCommandLineParser';

export class InstallAction extends BaseInstallAction {
protected _toFlag!: CommandLineStringListParameter;
protected _fromFlag!: CommandLineStringListParameter;
protected _toVersionPolicy!: CommandLineStringListParameter;
protected _fromVersionPolicy!: CommandLineStringListParameter;

public constructor(parser: RushCommandLineParser) {
super({
Expand Down Expand Up @@ -44,13 +46,30 @@ export class InstallAction extends BaseInstallAction {
'to specify the project in the current working directory. This argument is only valid in workspace ' +
'environments.'
});
this._fromFlag = this.defineStringListParameter({
parameterLongName: '--from',
parameterShortName: '-f',
argumentName: 'PROJECT2',
description:
'Run install in the specified project and all projects that directly or indirectly depend on the ' +
'specified project. "." can be used as shorthand to specify the project in the current working directory.' +
' This argument is only valid in workspace environments.'
});
this._toVersionPolicy = this.defineStringListParameter({
parameterLongName: '--to-version-policy',
argumentName: 'VERSION_POLICY_NAME',
description:
'Run install in all projects with the specified version policy and all of their dependencies. ' +
'This argument is only valid in workspace environments.'
});
this._fromVersionPolicy = this.defineStringListParameter({
parameterLongName: '--from-version-policy',
argumentName: 'VERSION_POLICY_NAME',
description:
'Run command in all projects with the specified version policy ' +
'and all projects that directly or indirectly depend on projects with the specified version policy.' +
' This argument is only valid in workspace environments.'
});
}

protected buildInstallOptions(): IInstallManagerOptions {
Expand All @@ -67,7 +86,8 @@ export class InstallAction extends BaseInstallAction {
// Because the 'defaultValue' option on the _maxInstallAttempts parameter is set,
// it is safe to assume that the value is not null
maxInstallAttempts: this._maxInstallAttempts.value!,
toProjects: this.mergeProjectsWithVersionPolicy(this._toFlag, this._toVersionPolicy)
toProjects: this.mergeProjectsWithVersionPolicy(this._toFlag, this._toVersionPolicy),
fromProjects: this.mergeProjectsWithVersionPolicy(this._fromFlag, this._fromVersionPolicy)
};
}
}
3 changes: 2 additions & 1 deletion apps/rush-lib/src/cli/actions/UpdateAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ export class UpdateAction extends BaseInstallAction {
// Because the 'defaultValue' option on the _maxInstallAttempts parameter is set,
// it is safe to assume that the value is not null
maxInstallAttempts: this._maxInstallAttempts.value!,
toProjects: []
toProjects: [],
fromProjects: []
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,9 @@ exports[`CommandLineHelp prints the help for each action: install 1`] = `
"usage: rush install [-h] [-p] [--bypass-policy] [--no-link]
[--network-concurrency COUNT] [--debug-package-manager]
[--max-install-attempts NUMBER] [--ignore-hooks]
[--variant VARIANT] [-t PROJECT1]
[--variant VARIANT] [-t PROJECT1] [-f PROJECT2]
[--to-version-policy VERSION_POLICY_NAME]
[--from-version-policy VERSION_POLICY_NAME]


The \\"rush install\\" command installs package dependencies for all your
Expand Down Expand Up @@ -450,10 +451,22 @@ Optional arguments:
dependencies. \\".\\" can be used as shorthand to specify
the project in the current working directory. This
argument is only valid in workspace environments.
-f PROJECT2, --from PROJECT2
Run install in the specified project and all projects
that directly or indirectly depend on the specified
project. \\".\\" can be used as shorthand to specify the
project in the current working directory. This
argument is only valid in workspace environments.
--to-version-policy VERSION_POLICY_NAME
Run install in all projects with the specified
version policy and all of their dependencies. This
argument is only valid in workspace environments.
--from-version-policy VERSION_POLICY_NAME
Run command in all projects with the specified
version policy and all projects that directly or
indirectly depend on projects with the specified
version policy. This argument is only valid in
workspace environments.
"
`;

Expand Down
3 changes: 2 additions & 1 deletion apps/rush-lib/src/logic/PackageJsonUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export class PackageJsonUpdater {
collectLogFile: false,
variant: variant,
maxInstallAttempts: RushConstants.defaultMaxInstallAttempts,
toProjects: []
toProjects: [],
fromProjects: []
};
const installManager: BaseInstallManager = InstallManagerFactory.getInstallManager(
this._rushConfiguration,
Expand Down
8 changes: 7 additions & 1 deletion apps/rush-lib/src/logic/base/BaseInstallManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ export interface IInstallManagerOptions {
* The list of projects that should be installed, along with project dependencies.
*/
toProjects: ReadonlyArray<RushConfigurationProject>;

/**
* The list of projects that should be installed, along with dependencies of the project.
*/
fromProjects: ReadonlyArray<RushConfigurationProject>;
}

/**
Expand Down Expand Up @@ -148,7 +153,8 @@ export abstract class BaseInstallManager {
}

public async doInstall(): Promise<void> {
const isFilteredInstall: boolean = this.options.toProjects.length > 0;
const isFilteredInstall: boolean =
this.options.toProjects.length > 0 || this.options.fromProjects.length > 0;
const useWorkspaces: boolean =
this.rushConfiguration.pnpmOptions && this.rushConfiguration.pnpmOptions.useWorkspaces;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ export class WorkspaceInstallManager extends BaseInstallManager {
if (!workspaceImporter) {
// Filtered installs will not contain all projects in the shrinkwrap, but if one is
// missing during a full install, something has gone wrong
if (this.options.toProjects.length === 0) {
if (this.options.toProjects.length === 0 && this.options.fromProjects.length === 0) {
throw new InternalError(
`Cannot find shrinkwrap entry using importer key for workspace project: ${importerKey}`
);
Expand Down Expand Up @@ -591,6 +591,11 @@ export class WorkspaceInstallManager extends BaseInstallManager {
for (const toProject of this.options.toProjects) {
args.push('--filter', `${toProject.packageName}...`);
}

// ..."<package>" selects the specified package and all direct and indirect dependents of that package
for (const fromProject of this.options.fromProjects) {
args.push('--filter', `...${fromProject.packageName}`);
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions common/changes/@microsoft/rush/from-flag_2021-01-13-20-47.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add support for --from flag for filtered installs when using workspaces",
"type": "none"
}
],
"packageName": "@microsoft/rush",
"email": "[email protected]"
}