Skip to content

Commit

Permalink
Workaround for process.argv not set with @salesforce/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Sep 10, 2023
1 parent 5f1c2ca commit a8e10f5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/hardis/lint/access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class Access extends SfdxCommand {
public async run(): Promise<AnyJson> {
const config = await getConfig("user");
this.folder = this.flags.folder || "./force-app";
this.hasToDisplayJsonOnly = process.argv.includes("--json");
this.hasToDisplayJsonOnly = this.argv.includes("--json");

this.ignoreSourceElementsIfDefined();
this.ignoreRightElementsIfDefined(config);
Expand Down
4 changes: 2 additions & 2 deletions src/common/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export async function execCommand(
// Call command (disable color before for json parsing)
const prevForceColor = process.env.FORCE_COLOR;
process.env.FORCE_COLOR = "0";
const output = options.output !== null ? options.output : !process.argv.includes("--json");
const output = options.output !== null ? options.output : !(process?.argv ||[]).includes("--json");
let spinner: any;
if (output && !(options.spinner === false)) {
spinner = ora({ text: commandLog, spinner: "moon" }).start();
Expand Down Expand Up @@ -897,7 +897,7 @@ export function uxLog(commandThis: any, text: string) {
text = text.includes("[sfdx-hardis]") ? text : "[sfdx-hardis]" + (text.startsWith("[") ? "" : " ") + text;
if (commandThis?.ux) {
commandThis.ux.log(text);
} else if (!process.argv.includes("--json")) {
} else if (!(process?.argv ||[]).includes("--json")) {
console.log(text);
}
if (globalThis.hardisLogFileStream) {
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/init/check-local-sfdx-hardis-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const hook = async (options: any) => {
// Skip hooks from other commands than hardis:scratch commands
const commandId = options?.id || "";

if (!process.argv.includes("--json")) {
if (!process?.argv?.includes("--json")) {
await manageGitIgnoreForceIgnore(commandId);
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/init/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ export const hook = async (options: any) => {
const logFileName = (new Date().toJSON().slice(0, 19) + "-" + commandId + ".log").replace(/:/g, "-");
const hardisLogFile = path.resolve(path.join(commandsLogFolder, logFileName));
globalThis.hardisLogFileStream = fs.createWriteStream(hardisLogFile, { flags: "a" });
globalThis.hardisLogFileStream.write(process.argv.join(" "));
globalThis.hardisLogFileStream.write((process?.argv || []).join(" "));
}
};
4 changes: 2 additions & 2 deletions src/hooks/prerun/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const hook = async (options: any) => {
}
// Manage authentication if org is required but current user is disconnected
if (
((options?.Command?.requiresUsername === true && !process.argv.includes("--skipauth")) || options.checkAuth === true) &&
((options?.Command?.requiresUsername === true && !(process?.argv ||[]).includes("--skipauth")) || options.checkAuth === true) &&
!(options.devHub === true)
) {
const orgAlias = options.alias
Expand Down Expand Up @@ -87,7 +87,7 @@ async function authOrg(orgAlias: string, options: any) {
orgDisplayCommand += " --targetusername " + orgAlias;
setDefaultUsername = true;
} else {
if (process.argv.includes("-u") || process.argv.includes("--targetusername")) {
if ((process?.argv ||[]).includes("-u") || (process?.argv ||[]).includes("--targetusername")) {
const posUsername = process.argv.indexOf("-u") > -1 ? process.argv.indexOf("-u") + 1 : process.argv.indexOf("--targetusername") + 1;
orgDisplayCommand += " --targetusername " + process.argv[posUsername];
}
Expand Down

0 comments on commit a8e10f5

Please sign in to comment.