Repository navigation
Expand file tree
/
Copy pathRushReporterCommandLine.ts
More file actions
61 lines (55 loc) · 2.21 KB
/
Copy pathRushReporterCommandLine.ts
File metadata and controls
61 lines (55 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
import * as path from 'node:path';
import { RushConfiguration } from '@microsoft/rush-lib';
import { CommandLineConfiguration, type Command } from '@microsoft/rush-lib/lib/api/CommandLineConfiguration';
import { RushConstants, NATIVE_RUSH_COMMANDS } from '@microsoft/rush-lib/lib/logic/RushConstants';
import { RushPluginsConfiguration } from '@microsoft/rush-lib/lib/api/RushPluginsConfiguration';
export interface IReporterCommandLineOwnership {
readonly known: boolean;
readonly parameters: ReadonlySet<string>;
}
export function getReporterCommandLineOwnership(
actionName: string | undefined,
cwd: string
): IReporterCommandLineOwnership {
const parameters: Set<string> = new Set();
if (!actionName) {
return { known: false, parameters };
}
if (NATIVE_RUSH_COMMANDS.has(actionName)) {
if (actionName === 'check') {
parameters.add('--verbose');
}
return { known: true, parameters };
}
const rushJsonPath: string | undefined = RushConfiguration.tryFindRushJsonLocation({
startingFolder: cwd,
showVerbose: false
});
const configFolder: string | undefined = rushJsonPath
? path.join(path.dirname(rushJsonPath), RushConstants.commonFolderName, 'config', 'rush')
: undefined;
if (
configFolder &&
new RushPluginsConfiguration(path.join(configFolder, 'rush-plugins.json')).configuration.plugins.length >
0
) {
// The selected engine resolves plugin command definitions; do not claim their parameters here.
return { known: false, parameters };
}
const configuration: CommandLineConfiguration = CommandLineConfiguration.loadFromFileOrDefault(
configFolder && path.join(configFolder, RushConstants.commandLineFilename)
);
const command: Command | undefined = configuration.commands.get(actionName);
if (!command) {
return { known: false, parameters };
}
for (const parameter of command.associatedParameters) {
parameters.add(parameter.longName);
}
if (command.commandKind === RushConstants.phasedCommandKind) {
parameters.add('--verbose');
}
return { known: true, parameters };
}