Skip to content
Merged
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions src/support/writeReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import { EOL } from "os";
import { join } from "path";
import * as vscode from "vscode";
import { Logger } from "../logger/logger";
import { reportObj } from "./types";

export async function writeTextReport(
Expand Down Expand Up @@ -217,7 +216,7 @@
if (logFileExists) {
const logFileContent = await readFile(logFile, "utf8");
output += `----------------------------------------------------------- Logfile -----------------------------------------------------------------${EOL}`;
output += logFileContent + EOL + lineBreak;
output += replaceUserPathInStr(logFileContent) + EOL + lineBreak;
}
const resultFile = join(context.extensionPath, "report.txt");
await writeFile(resultFile, output);
Expand All @@ -232,13 +231,23 @@
const strReport = JSON.stringify(report);

// Replacing all home paths (based on OS) with '...' using es6 syntax. Can be replaced with one line using .replaceAll() when we will update the version of ECMAScript to 2021 or higher
let re = new RegExp(process.env.HOME, "g");
if (process.env.windir) {
const reWin = new RegExp("\\\\", "g");
const result = process.env.HOMEPATH.replace(reWin, "\\\\\\\\");
re = new RegExp(result, "g");
}
const parsedReport = strReport.replace(re, "<HOMEPATH>");
const parsedReport = replaceUserPathInStr(strReport);

return JSON.parse(parsedReport);
}

function replaceUserPathInStr(strReport: string) {
if (process.env.windir) {
const homePath = process.env.HOMEPATH;
const pattern = `(${homePath.replace(/\\/g, "\\\\\\\\")}|${homePath.replace(
/\\/g,
"/"
)})`;
const re = new RegExp(pattern, "g");
return strReport.replace(re, "<HOMEPATH>");
} else {
// For non-Windows systems, just replace the home directory
const re = new RegExp(process.env.HOME, "g");
return strReport.replace(re, "<HOMEPATH>");
}
}