Skip to content

Commit 065ef10

Browse files
Copilotdmichon-msft
andcommitted
Refactor to eliminate code duplication in parameter collection
Co-authored-by: dmichon-msft <[email protected]>
1 parent d684dca commit 065ef10

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,21 @@ export interface ICustomParameterValuesForOperation {
135135
ignoredParameterNames: ReadonlyArray<string>;
136136
}
137137

138+
/**
139+
* Helper function to collect all parameter arguments for a phase
140+
*/
141+
function collectPhaseParameterArguments(phase: IPhase): Set<string> {
142+
const customParameterSet: Set<string> = new Set();
143+
for (const tsCommandLineParameter of phase.associatedParameters) {
144+
const tempArgs: string[] = [];
145+
tsCommandLineParameter.appendToArgList(tempArgs);
146+
for (const arg of tempArgs) {
147+
customParameterSet.add(arg);
148+
}
149+
}
150+
return customParameterSet;
151+
}
152+
138153
/**
139154
* Memoizer for custom parameter values by phase
140155
* @returns A function that returns the custom parameter values for a given phase
@@ -145,12 +160,7 @@ export function getCustomParameterValuesByPhase(): (phase: IPhase) => ReadonlyAr
145160
function getCustomParameterValuesForPhase(phase: IPhase): ReadonlyArray<string> {
146161
let customParameterSet: Set<string> | undefined = customParametersByPhase.get(phase);
147162
if (!customParameterSet) {
148-
const customParameterValues: string[] = [];
149-
for (const tsCommandLineParameter of phase.associatedParameters) {
150-
tsCommandLineParameter.appendToArgList(customParameterValues);
151-
}
152-
153-
customParameterSet = new Set(customParameterValues);
163+
customParameterSet = collectPhaseParameterArguments(phase);
154164
customParametersByPhase.set(phase, customParameterSet);
155165
}
156166

@@ -176,15 +186,7 @@ export function getCustomParameterValuesForOperation(): (
176186
// Get or compute the set of all custom parameters for this phase
177187
let customParameterSet: Set<string> | undefined = customParametersByPhase.get(phase);
178188
if (!customParameterSet) {
179-
customParameterSet = new Set();
180-
for (const tsCommandLineParameter of phase.associatedParameters) {
181-
const tempArgs: string[] = [];
182-
tsCommandLineParameter.appendToArgList(tempArgs);
183-
for (const arg of tempArgs) {
184-
customParameterSet.add(arg);
185-
}
186-
}
187-
189+
customParameterSet = collectPhaseParameterArguments(phase);
188190
customParametersByPhase.set(phase, customParameterSet);
189191
}
190192

0 commit comments

Comments
 (0)