Skip to content

[rush-lib] Supports the rush install-autoinstaller command #4823

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
merged 21 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 19 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add a new `rush install-autoinstaller` command that ensures that the specified autoinstaller is installed.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,24 @@ Object {
},
],
},
Object {
"actionName": "install-autoinstaller",
"parameters": Array [
Object {
"description": "The name of the autoinstaller, which must be one of the folders under common/autoinstallers.",
"environmentVariable": undefined,
"kind": "String",
"longName": "--name",
"required": true,
"shortName": undefined,
},
],
},
Object {
"actionName": "update-autoinstaller",
"parameters": Array [
Object {
"description": "Specifies the name of the autoinstaller, which must be one of the folders under common/autoinstallers.",
"description": "The name of the autoinstaller, which must be one of the folders under common/autoinstallers.",
"environmentVariable": undefined,
"kind": "String",
"longName": "--name",
Expand Down
2 changes: 2 additions & 0 deletions libraries/rush-lib/src/cli/RushCommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ import { PhasedScriptAction } from './scriptActions/PhasedScriptAction';
import type { IBuiltInPluginConfiguration } from '../pluginFramework/PluginLoader/BuiltInPluginLoader';
import { InitSubspaceAction } from './actions/InitSubspaceAction';
import { RushAlerts } from '../utilities/RushAlerts';
import { InstallAutoinstallerAction } from './actions/InstallAutoinstallerAction';

/**
* Options for `RushCommandLineParser`.
Expand Down Expand Up @@ -313,6 +314,7 @@ export class RushCommandLineParser extends CommandLineParser {
this.addAction(new SetupAction(this));
this.addAction(new UnlinkAction(this));
this.addAction(new UpdateAction(this));
this.addAction(new InstallAutoinstallerAction(this));
this.addAction(new UpdateAutoinstallerAction(this));
this.addAction(new UpdateCloudCredentialsAction(this));
this.addAction(new UpgradeInteractiveAction(this));
Expand Down
43 changes: 43 additions & 0 deletions libraries/rush-lib/src/cli/actions/BaseAutoinstallerAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import type { IRequiredCommandLineStringParameter } from '@rushstack/ts-command-line';
import type { ITerminal } from '@rushstack/terminal';

import { BaseRushAction, type IBaseRushActionOptions } from './BaseRushAction';
import { Autoinstaller } from '../../logic/Autoinstaller';

export abstract class BaseAutoinstallerAction extends BaseRushAction {
protected readonly _name: IRequiredCommandLineStringParameter;
protected readonly _terminal: ITerminal;

public constructor(options: IBaseRushActionOptions) {
super(options);

this._name = this.defineStringParameter({
parameterLongName: '--name',
argumentName: 'AUTOINSTALLER_NAME',
required: true,
description:
'The name of the autoinstaller, which must be one of the folders under common/autoinstallers.'
});

this._terminal = this.parser.terminal;
}

protected abstract prepareAsync(autoinstaller: Autoinstaller): Promise<void>;

protected async runAsync(): Promise<void> {
const autoinstallerName: string = this._name.value;
const autoinstaller: Autoinstaller = new Autoinstaller({
autoinstallerName,
rushConfiguration: this.rushConfiguration,
rushGlobalFolder: this.rushGlobalFolder
});

await this.prepareAsync(autoinstaller);

this._terminal.writeLine();
this._terminal.writeLine('Success.');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import type { Autoinstaller } from '../../logic/Autoinstaller';
import type { RushCommandLineParser } from '../RushCommandLineParser';
import { BaseAutoinstallerAction } from './BaseAutoinstallerAction';

export class InstallAutoinstallerAction extends BaseAutoinstallerAction {
public constructor(parser: RushCommandLineParser) {
super({
actionName: 'install-autoinstaller',
summary: 'Install autoinstaller package dependencies',
documentation: 'Use this command to install dependencies for an autoinstaller folder.',
parser
});
}

protected async prepareAsync(autoinstaller: Autoinstaller): Promise<void> {
await autoinstaller.prepareAsync();
}
}
31 changes: 4 additions & 27 deletions libraries/rush-lib/src/cli/actions/UpdateAutoinstallerAction.ts
Original file line number Diff line number Diff line change
@@ -1,47 +1,24 @@
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.

import type { IRequiredCommandLineStringParameter } from '@rushstack/ts-command-line';

import { BaseRushAction } from './BaseRushAction';
import type { RushCommandLineParser } from '../RushCommandLineParser';
import { Autoinstaller } from '../../logic/Autoinstaller';

export class UpdateAutoinstallerAction extends BaseRushAction {
private readonly _name: IRequiredCommandLineStringParameter;
import type { Autoinstaller } from '../../logic/Autoinstaller';
import { BaseAutoinstallerAction } from './BaseAutoinstallerAction';

export class UpdateAutoinstallerAction extends BaseAutoinstallerAction {
public constructor(parser: RushCommandLineParser) {
super({
actionName: 'update-autoinstaller',
summary: 'Updates autoinstaller package dependencies',
documentation: 'Use this command to regenerate the shrinkwrap file for an autoinstaller folder.',
parser
});

this._name = this.defineStringParameter({
parameterLongName: '--name',
argumentName: 'AUTOINSTALLER_NAME',
required: true,
description:
'Specifies the name of the autoinstaller, which must be one of the folders under common/autoinstallers.'
});
}

protected async runAsync(): Promise<void> {
const autoinstallerName: string = this._name.value;
const autoinstaller: Autoinstaller = new Autoinstaller({
autoinstallerName,
rushConfiguration: this.rushConfiguration,
rushGlobalFolder: this.rushGlobalFolder
});

protected async prepareAsync(autoinstaller: Autoinstaller): Promise<void> {
// Do not run `autoinstaller.prepareAsync` here. It tries to install the autoinstaller with
// --frozen-lockfile or equivalent, which will fail if the autoinstaller's dependencies
// have been changed.

await autoinstaller.updateAsync();

// eslint-disable-next-line no-console
console.log('\nSuccess.');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Positional arguments:
update Install package dependencies for all projects in the
repo, and create or update the shrinkwrap file as
needed
install-autoinstaller
Install autoinstaller package dependencies
update-autoinstaller
Updates autoinstaller package dependencies
update-cloud-credentials
Expand Down Expand Up @@ -758,6 +760,19 @@ Optional arguments:
"
`;

exports[`CommandLineHelp prints the help for each action: install-autoinstaller 1`] = `
"usage: rush install-autoinstaller [-h] --name AUTOINSTALLER_NAME

Use this command to install dependencies for an autoinstaller folder.

Optional arguments:
-h, --help Show this help message and exit.
--name AUTOINSTALLER_NAME
The name of the autoinstaller, which must be one of
the folders under common/autoinstallers.
"
`;

exports[`CommandLineHelp prints the help for each action: link 1`] = `
"usage: rush link [-h] [-f]

Expand Down Expand Up @@ -1279,8 +1294,8 @@ folder.
Optional arguments:
-h, --help Show this help message and exit.
--name AUTOINSTALLER_NAME
Specifies the name of the autoinstaller, which must
be one of the folders under common/autoinstallers.
The name of the autoinstaller, which must be one of
the folders under common/autoinstallers.
"
`;

Expand Down
8 changes: 7 additions & 1 deletion libraries/rush-lib/src/logic/Autoinstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ import { LastInstallFlag } from '../api/LastInstallFlag';
import { RushCommandLineParser } from '../cli/RushCommandLineParser';
import type { PnpmPackageManager } from '../api/packageManager/PnpmPackageManager';

interface IAutoinstallerOptions {
/**
* @beta
*/
export interface IAutoinstallerOptions {
autoinstallerName: string;
rushConfiguration: RushConfiguration;
rushGlobalFolder: RushGlobalFolder;
restrictConsoleOutput?: boolean;
}

/**
* @beta
*/
export class Autoinstaller {
public readonly name: string;

Expand Down
Loading