Skip to content

Commit

Permalink
Merge pull request #3586 from dmichon-msft/watch-perf
Browse files Browse the repository at this point in the history
[rush] Allow configuration of watch debounce timeout
  • Loading branch information
iclanton authored Aug 17, 2022
2 parents 0a38e48 + 68f7bfe commit ca05a9f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 4 deletions.
10 changes: 10 additions & 0 deletions common/changes/@microsoft/rush/watch-perf_2022-08-12-22-50.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add ability to configure watch debounce timeout as \"watchOptions.debounceMilliseconds\" in phased commands.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
5 changes: 5 additions & 0 deletions libraries/rush-lib/src/api/CommandLineConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ export interface IPhasedCommandConfig extends IPhasedCommandWithoutPhasesJson, I
* The set of phases to execute when running this phased command in watch mode.
*/
watchPhases: Set<IPhase>;
/**
* How many milliseconds to wait after receiving a file system notification before executing in watch mode.
*/
watchDebounceMilliseconds?: number;
/**
* If set to `true`, then this phased command will always perform an install before executing, regardless of CLI flags.
* If set to `false`, then Rush will define a built-in "--install" CLI flag for this command.
Expand Down Expand Up @@ -326,6 +330,7 @@ export class CommandLineConfiguration {

if (watchOptions) {
normalizedCommand.alwaysWatch = watchOptions.alwaysWatch;
normalizedCommand.watchDebounceMilliseconds = watchOptions.debounceMilliseconds;

// No implicit phase dependency expansion for watch mode.
for (const phaseName of watchOptions.watchPhases) {
Expand Down
1 change: 1 addition & 0 deletions libraries/rush-lib/src/api/CommandLineJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface IPhasedCommandJson extends IPhasedCommandWithoutPhasesJson {
phases: string[];
watchOptions?: {
alwaysWatch: boolean;
debounceMilliseconds?: number;
watchPhases: string[];
};
installOptions?: {
Expand Down
1 change: 1 addition & 0 deletions libraries/rush-lib/src/cli/RushCommandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ export class RushCommandLineParser extends CommandLineParser {

initialPhases: command.phases,
watchPhases: command.watchPhases,
watchDebounceMilliseconds: command.watchDebounceMilliseconds ?? 1000,
phases: commandLineConfiguration.phases,

alwaysWatch: command.alwaysWatch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { IExecutionResult } from '../../logic/operations/IOperationExecutionResu
import { OperationResultSummarizerPlugin } from '../../logic/operations/OperationResultSummarizerPlugin';

/**
* Constructor parameters for BulkScriptAction.
* Constructor parameters for PhasedScriptAction.
*/
export interface IPhasedScriptActionOptions extends IBaseScriptActionOptions<IPhasedCommandConfig> {
enableParallelism: boolean;
Expand All @@ -51,6 +51,8 @@ export interface IPhasedScriptActionOptions extends IBaseScriptActionOptions<IPh

alwaysWatch: boolean;
alwaysInstall: boolean | undefined;

watchDebounceMilliseconds: number | undefined;
}

interface IRunPhasesOptions {
Expand Down Expand Up @@ -101,6 +103,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
private readonly _disableBuildCache: boolean;
private readonly _initialPhases: ReadonlySet<IPhase>;
private readonly _watchPhases: ReadonlySet<IPhase>;
private readonly _watchDebounceMilliseconds: number;
private readonly _alwaysWatch: boolean;
private readonly _alwaysInstall: boolean | undefined;
private readonly _knownPhases: ReadonlyMap<string, IPhase>;
Expand All @@ -121,6 +124,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
this._disableBuildCache = options.disableBuildCache;
this._initialPhases = options.initialPhases;
this._watchPhases = options.watchPhases;
this._watchDebounceMilliseconds = options.watchDebounceMilliseconds ?? 1000;
this._alwaysWatch = options.alwaysWatch;
this._alwaysInstall = options.alwaysInstall;
this._knownPhases = options.phases;
Expand Down Expand Up @@ -304,7 +308,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
const { ProjectWatcher } = await import('../../logic/ProjectWatcher');

const projectWatcher: typeof ProjectWatcher.prototype = new ProjectWatcher({
debounceMilliseconds: 1000,
debounceMilliseconds: this._watchDebounceMilliseconds,
rushConfiguration: this.rushConfiguration,
projectsToWatch,
terminal,
Expand Down
4 changes: 2 additions & 2 deletions libraries/rush-lib/src/logic/ProjectChangeAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,11 @@ export class ProjectChangeAnalyzer {
let i: number = 0;
for (const projectDeps of projectHashDeps.values()) {
const projectDependencyManifestPath: string = projectDependencyManifestPaths[i];
if (!hashes.has(projectDependencyManifestPath)) {
const hash: string | undefined = hashes.get(projectDependencyManifestPath);
if (hash === undefined) {
throw new InternalError(`Expected to get a hash for ${projectDependencyManifestPath}`);
}

const hash: string = hashes.get(projectDependencyManifestPath)!;
projectDeps.set(projectDependencyManifestPath, hash);
i++;
}
Expand Down
5 changes: 5 additions & 0 deletions libraries/rush-lib/src/schemas/command-line.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@
"description": "Indicates that this command will always watch for changes after the initial execution, as if the \"--watch\" CLI flag was passed.",
"type": "boolean"
},
"debounceMilliseconds": {
"title": "Debounce Timeout in Milliseconds",
"description": "When watching, how long to wait after the last encountered file system event before execution. If another file system event occurs in this interval, the timeout will reset.",
"type": "number"
},
"watchPhases": {
"title": "Watch Phases",
"description": "List *exactly* the phases that should be run in watch mode for this command. If this property is specified and non-empty, after the phases defined in the \"phases\" property run, a file watcher will be started to watch projects for changes, and will run the phases listed in this property on changed projects.",
Expand Down

0 comments on commit ca05a9f

Please sign in to comment.