Skip to content

Commit c3fdcc9

Browse files
author
Ben Keen
committed
code review feedback
1 parent 2c1f883 commit c3fdcc9

File tree

8 files changed

+185
-120
lines changed

8 files changed

+185
-120
lines changed

common/reviews/api/rush-lib.api.md

Lines changed: 86 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,92 @@ export class Operation {
946946
weight: number;
947947
}
948948

949+
// Warning: (ae-internal-missing-underscore) The name "OperationBuildCache" should be prefixed with an underscore because the declaration is marked as @internal
950+
//
951+
// @internal (undocumented)
952+
export class OperationBuildCache {
953+
// (undocumented)
954+
get cacheId(): string | undefined;
955+
// Warning: (ae-forgotten-export) The symbol "IOperationBuildCacheOptions" needs to be exported by the entry point index.d.ts
956+
//
957+
// (undocumented)
958+
static forOperation(operation: OperationExecutionRecord, options: IOperationBuildCacheOptions): OperationBuildCache;
959+
// Warning: (ae-forgotten-export) The symbol "IProjectBuildCacheOptions" needs to be exported by the entry point index.d.ts
960+
//
961+
// (undocumented)
962+
static getProjectBuildCache(options: IProjectBuildCacheOptions): OperationBuildCache;
963+
// (undocumented)
964+
tryRestoreFromCacheAsync(terminal: ITerminal, specifiedCacheId?: string): Promise<boolean>;
965+
// (undocumented)
966+
trySetCacheEntryAsync(terminal: ITerminal, specifiedCacheId?: string): Promise<boolean>;
967+
}
968+
969+
// Warning: (ae-internal-missing-underscore) The name "OperationExecutionRecord" should be prefixed with an underscore because the declaration is marked as @internal
970+
//
971+
// @internal
972+
export class OperationExecutionRecord implements IOperationRunnerContext, IOperationExecutionResult {
973+
// Warning: (ae-forgotten-export) The symbol "IOperationExecutionRecordContext" needs to be exported by the entry point index.d.ts
974+
constructor(operation: Operation, context: IOperationExecutionRecordContext);
975+
// (undocumented)
976+
readonly associatedPhase: IPhase;
977+
// (undocumented)
978+
readonly associatedProject: RushConfigurationProject;
979+
// (undocumented)
980+
get cobuildRunnerId(): string | undefined;
981+
// (undocumented)
982+
get collatedWriter(): CollatedWriter;
983+
readonly consumers: Set<OperationExecutionRecord>;
984+
criticalPathLength: number | undefined;
985+
// (undocumented)
986+
get debugMode(): boolean;
987+
readonly dependencies: Set<OperationExecutionRecord>;
988+
// (undocumented)
989+
get environment(): IEnvironment | undefined;
990+
error: Error | undefined;
991+
// (undocumented)
992+
executeAsync({ onStart, onResult }: {
993+
onStart: (record: OperationExecutionRecord) => Promise<OperationStatus | undefined>;
994+
onResult: (record: OperationExecutionRecord) => Promise<void>;
995+
}): Promise<void>;
996+
// (undocumented)
997+
getStateHash(): string;
998+
// (undocumented)
999+
getStateHashComponents(): ReadonlyArray<string>;
1000+
// (undocumented)
1001+
get isTerminal(): boolean;
1002+
// (undocumented)
1003+
logFilePaths: ILogFilePaths | undefined;
1004+
// (undocumented)
1005+
get metadataFolderPath(): string | undefined;
1006+
// (undocumented)
1007+
get name(): string;
1008+
// (undocumented)
1009+
get nonCachedDurationMs(): number | undefined;
1010+
readonly operation: Operation;
1011+
// (undocumented)
1012+
readonly _operationMetadataManager: _OperationMetadataManager;
1013+
// (undocumented)
1014+
get quietMode(): boolean;
1015+
// (undocumented)
1016+
readonly runner: IOperationRunner;
1017+
runWithTerminalAsync<T>(callback: (terminal: ITerminal, terminalProvider: ITerminalProvider) => Promise<T>, options: {
1018+
createLogFile: boolean;
1019+
logFileSuffix: string;
1020+
}): Promise<T>;
1021+
// (undocumented)
1022+
get silent(): boolean;
1023+
get status(): OperationStatus;
1024+
set status(newStatus: OperationStatus);
1025+
// (undocumented)
1026+
readonly stdioSummarizer: StdioSummarizer;
1027+
// Warning: (ae-forgotten-export) The symbol "Stopwatch" needs to be exported by the entry point index.d.ts
1028+
//
1029+
// (undocumented)
1030+
readonly stopwatch: Stopwatch;
1031+
// (undocumented)
1032+
get weight(): number;
1033+
}
1034+
9491035
// @internal
9501036
export class _OperationMetadataManager {
9511037
constructor(options: _IOperationMetadataManagerOptions);
@@ -1128,27 +1214,6 @@ export type PnpmStoreLocation = 'local' | 'global';
11281214
// @public @deprecated (undocumented)
11291215
export type PnpmStoreOptions = PnpmStoreLocation;
11301216

1131-
// Warning: (ae-internal-missing-underscore) The name "ProjectBuildCache" should be prefixed with an underscore because the declaration is marked as @internal
1132-
//
1133-
// @internal (undocumented)
1134-
export class ProjectBuildCache {
1135-
// (undocumented)
1136-
get cacheId(): string | undefined;
1137-
// Warning: (ae-forgotten-export) The symbol "OperationExecutionRecord" needs to be exported by the entry point index.d.ts
1138-
// Warning: (ae-forgotten-export) The symbol "IOperationBuildCacheOptions" needs to be exported by the entry point index.d.ts
1139-
//
1140-
// (undocumented)
1141-
static forOperation(operation: OperationExecutionRecord, options: IOperationBuildCacheOptions): ProjectBuildCache;
1142-
// Warning: (ae-forgotten-export) The symbol "IProjectBuildCacheOptions" needs to be exported by the entry point index.d.ts
1143-
//
1144-
// (undocumented)
1145-
static getProjectBuildCache(options: IProjectBuildCacheOptions): ProjectBuildCache;
1146-
// (undocumented)
1147-
tryRestoreFromCacheAsync(terminal: ITerminal, specifiedCacheId?: string): Promise<boolean>;
1148-
// (undocumented)
1149-
trySetCacheEntryAsync(terminal: ITerminal, specifiedCacheId?: string): Promise<boolean>;
1150-
}
1151-
11521217
// @beta (undocumented)
11531218
export class ProjectChangeAnalyzer {
11541219
constructor(rushConfiguration: RushConfiguration);

libraries/rush-lib/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export type {
135135
IExecutionResult,
136136
IOperationExecutionResult
137137
} from './logic/operations/IOperationExecutionResult';
138+
export type { OperationExecutionRecord } from './logic/operations/OperationExecutionRecord';
138139
export { type IOperationOptions, Operation } from './logic/operations/Operation';
139140
export { OperationStatus } from './logic/operations/OperationStatus';
140141
export type { ILogFilePaths } from './logic/operations/ProjectLogWritable';
@@ -198,4 +199,4 @@ export {
198199
type IRushCommandLineAction
199200
} from './api/RushCommandLine';
200201

201-
export { ProjectBuildCache } from './logic/buildCache/ProjectBuildCache';
202+
export { ProjectBuildCache as OperationBuildCache } from './logic/buildCache/ProjectBuildCache';

libraries/rush-lib/src/logic/operations/ShardedPhaseOperationPlugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ function spliceShards(existingOperations: Set<Operation>, context: ICreateOperat
128128
];
129129

130130
const { scripts } = project.packageJson;
131+
132+
//
131133
const commandToRun: string | undefined = phase.shellCommand ?? scripts?.[phase.name];
132134

133135
operation.logFilenameIdentifier = `${baseLogFilenameIdentifier}_collate`;
Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,45 @@
11
# @rushstack/rush-bridge-cache-plugin
22

3-
This plugin allows for interaction with the Rush cache. It exposes some methods to set the cache.
3+
This is a Rush plugin that adds an optional `--set-cache-only` flag to Rush's phased commands, so you can other tools to actual run the scripts and generate the build artifacts on disk, then separately populate the Rush cache for particular actions(s). For integrations with other build orchestrators, this allows the best of both worlds: using a different build tool to orchestrate the work, but still populate the Rush cache for benefiting local use of Rush.
44

5+
## Here be dragons!
56

6-
## Installation
7-
8-
`npm install @rushstack/rush-bridge-cache-plugin`
7+
This is a power-user sort of plugin. It assumes that the work for a particular task has already been completed and the build artifacts have been generated on disk. **If you run this command on a package where the command hasn't already been ran and the build artifacts are missing or incorrect, you will cache invalid content**. Be careful and beware!
98

10-
<!--
11-
## Usage
12-
The package contains a binary you can run from the command line. It will auto-detect the location of your rush.json file.
139

14-
`populate-rush-cache --packageName=[package name] --phase=test:unit`
10+
## Installation
1511

16-
- `--packageName` (required) - this should map to the `packageName` entry in your `rush.json` file.
17-
- `--phase` (required): the name of the phased command whose command has already been ran, and you want to cache the result on disk.
18-
-->
12+
(TODO)
1913

20-
--------------------
14+
`npm install @rushstack/rush-bridge-cache-plugin`
2115

22-
So this will:
23-
- tap into the hooks and do all the necessary shit to figure out how to po
24-
- expose a simple API for external users to tap into, e.g. if you want to populate the cache externally you'd import this plugin and use the methods to do so. You could then wrap that in a rush function, or however you want to do it.
2516

17+
## Configuration
2618

19+
First you need to update your `command-line.json` file to add the new flag. Configure it to target whatever specific commands you want to have this feature. Example:
2720

21+
```json
22+
{
23+
"associatedCommands": ["build", "test", "lint", "a11y", "typecheck"],
24+
"description": "When the flag is added to any associated command, it'll bypass running the command itself, but cache the result of a previous run. Beware! Only run when you know the build artifacts are in a valid state for the command.",
25+
"parameterKind": "flag",
26+
"longName": "--set-cache-only",
27+
"required": false
28+
}
29+
```
2830

2931

30-
--------------------
32+
## Usage
3133

32-
Discussion about the solution for BuildXL here:
33-
https://teams.microsoft.com/l/message/19:d85f52548ec74e8f8a0f107bd4e5ceb6@thread.v2/1740610046597?context=%7B%22contextType%22%3A%22chat%22%7D
34+
Any of the rush command can now just be given a `--set-cache-only` property, e.g.
3435

36+
`rush build --to your-packageX --set-cache-only`
3537

36-
"populate-cache": "..." <--- called after any cacheable unit of work is complete
38+
That will examine `your-packageX` and all of its dependencies, then populate the cache.
3739

38-
OperationExecutionRecord -> the smallest unit of work to be done.
39-
- looks like it's strongly coupled to the runner. We need one-off method calls.
4040

41-
CacheableOperationPlugin
42-
_tryGetProjectBuildCache() -> this returns the project build cache
41+
## Performance
4342

43+
When running within a pipeline, you'll want to populate the cache as fast as possible. So instead of waiting until the full build graph has been processed, you'll wnt to run it after each successful task. For that, just use Rush's `--only` and target whatever task had just completed, for example:
4444

45+
`rush lint --only your-packageY --set-cache-only`

rush-plugins/rush-bridge-cache-plugin/command-line.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

rush-plugins/rush-bridge-cache-plugin/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "@rushstack/rush-bridge-cache-plugin",
33
"version": "0.0.1",
44
"private": true,
5-
"description": "A plugin to expose methods to interact with the Rush cache.",
5+
"description": "Rush plugin that provides a --set-cache-only command flag to populates the cache from previous runs.",
66
"license": "MIT",
77
"main": "./lib/index.js",
88
"repository": {

rush-plugins/rush-bridge-cache-plugin/rush-plugin-manifest.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
"plugins": [
44
{
55
"pluginName": "rush-bridge-cache-plugin",
6-
"description": "Rush plugin to allow interactions with the Rush cache.",
7-
"entryPoint": "./lib/index.js",
8-
"commandLineJsonFilePath": "./command-line.json"
6+
"description": "Rush plugin that provides a --set-cache-only command flag to populates the cache from previous runs.",
7+
"entryPoint": "./lib/index.js"
98
}
109
]
1110
}

0 commit comments

Comments
 (0)