Skip to content

Commit

Permalink
Merge pull request #4306 from dmichon-msft/run-before-install
Browse files Browse the repository at this point in the history
[rush] Support "disableBuildCache" option in phased command schema
  • Loading branch information
dmichon-msft committed Sep 5, 2023
2 parents a2a8de9 + 61dbd96 commit 32ad677
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Add the \"disableBuildCache\" option to the schema for phased commands (it is already present for bulk commands). Update the behavior of the \"disableBuildCache\" flag to also disable the legacy skip detection, in the event that the build cache is not configured.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
42 changes: 26 additions & 16 deletions libraries/rush-lib/src/cli/scriptActions/PhasedScriptAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ interface IPhasedCommandTelemetry {
* "build" script for each project.
*/
export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
/**
* @internal
*/
public _runsBeforeInstall: boolean | undefined;
public readonly hooks: PhasedCommandHooks;

private readonly _enableParallelism: boolean;
Expand Down Expand Up @@ -137,6 +141,7 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
this._watchDebounceMs = options.watchDebounceMs ?? RushConstants.defaultWatchDebounceMs;
this._alwaysWatch = options.alwaysWatch;
this._alwaysInstall = options.alwaysInstall;
this._runsBeforeInstall = false;
this._knownPhases = options.phases;

this.hooks = new PhasedCommandHooks();
Expand Down Expand Up @@ -253,15 +258,17 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
});
}

// TODO: Replace with last-install.flag when "rush link" and "rush unlink" are deprecated
const lastLinkFlag: LastLinkFlag = LastLinkFlagFactory.getCommonTempFlag(this.rushConfiguration);
if (!lastLinkFlag.isValid()) {
const useWorkspaces: boolean =
this.rushConfiguration.pnpmOptions && this.rushConfiguration.pnpmOptions.useWorkspaces;
if (useWorkspaces) {
throw new Error('Link flag invalid.\nDid you run "rush install" or "rush update"?');
} else {
throw new Error('Link flag invalid.\nDid you run "rush link"?');
if (!this._runsBeforeInstall) {
// TODO: Replace with last-install.flag when "rush link" and "rush unlink" are removed
const lastLinkFlag: LastLinkFlag = LastLinkFlagFactory.getCommonTempFlag(this.rushConfiguration);
if (!lastLinkFlag.isValid()) {
const useWorkspaces: boolean =
this.rushConfiguration.pnpmOptions && this.rushConfiguration.pnpmOptions.useWorkspaces;
if (useWorkspaces) {
throw new Error('Link flag invalid.\nDid you run "rush install" or "rush update"?');
} else {
throw new Error('Link flag invalid.\nDid you run "rush link"?');
}
}
}

Expand Down Expand Up @@ -350,20 +357,23 @@ export class PhasedScriptAction extends BaseScriptAction<IPhasedCommandConfig> {
cobuildConfiguration,
terminal
}).apply(this.hooks);
} else {
} else if (!this._disableBuildCache) {
// Explicitly disabling the build cache also disables legacy skip detection.
new LegacySkipPlugin({
terminal,
changedProjectsOnly,
isIncrementalBuildAllowed: this._isIncrementalBuildAllowed
}).apply(this.hooks);
}

const projectConfigurations: ReadonlyMap<RushConfigurationProject, RushProjectConfiguration> =
await RushProjectConfiguration.tryLoadAndValidateForProjectsAsync(
projectSelection,
this._initialPhases,
terminal
);
const projectConfigurations: ReadonlyMap<RushConfigurationProject, RushProjectConfiguration> = this
._runsBeforeInstall
? new Map()
: await RushProjectConfiguration.tryLoadAndValidateForProjectsAsync(
projectSelection,
this._initialPhases,
terminal
);

const projectChangeAnalyzer: ProjectChangeAnalyzer = new ProjectChangeAnalyzer(this.rushConfiguration);
const initialCreateOperationsContext: ICreateOperationsContext = {
Expand Down
7 changes: 6 additions & 1 deletion libraries/rush-lib/src/schemas/command-line.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
},
"disableBuildCache": {
"title": "Disable build cache.",
"description": "Disable build cache for this action. This may be useful if this command affects state outside of projects' own folders.",
"description": "Disable build cache for this action. This may be useful if this command affects state outside of projects' own folders. If the build cache is not configured, this also disables the legacy skip detection logic.",
"type": "boolean"
}
}
Expand Down Expand Up @@ -194,6 +194,11 @@
"type": "string"
}
},
"disableBuildCache": {
"title": "Disable build cache.",
"description": "Disable build cache for this action. This may be useful if this command affects state outside of projects' own folders. If the build cache is not configured, this also disables the legacy skip detection logic.",
"type": "boolean"
},
"watchOptions": {
"title": "Watch Options",
"description": "Controls the file watching behavior of this command. If not specified, this command does not watch files.",
Expand Down

0 comments on commit 32ad677

Please sign in to comment.