Skip to content

Commit

Permalink
Fix an issue where Rush would attempt to open a project's log file fo…
Browse files Browse the repository at this point in the history
…r writing twice.
  • Loading branch information
iclanton committed Jun 14, 2023
1 parent e5c0fc5 commit be9b01a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@microsoft/rush",
"comment": "Fix an issue where Rush would attempt to open a project's log file for writing twice.",
"type": "none"
}
],
"packageName": "@microsoft/rush"
}
52 changes: 26 additions & 26 deletions libraries/rush-lib/src/logic/operations/ProjectLogWritable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,39 +60,39 @@ export class ProjectLogWritable extends TerminalWritable {
}

const projectFolder: string = this._project.projectFolder;
const {
logPath: legacyLogPath,
errorLogPath: legacyErrorLogPath,
relativeLogPath: legacyRelativeLogPath,
relativeErrorLogPath: legacyRelativeErrorLogPath
} = getLogFilePaths(projectFolder, 'build');
// Delete the legacy logs
const { logPath: legacyLogPath, errorLogPath: legacyErrorLogPath } = getLogFilePaths(
projectFolder,
'build'
);
FileSystem.deleteFile(legacyLogPath);
FileSystem.deleteFile(legacyErrorLogPath);

// If the phased commands experiment is enabled, put logs under `rush-logs`
let logFolder: string | undefined;
if (project.rushConfiguration.experimentsConfiguration.configuration.phasedCommands) {
// Delete the legacy logs
FileSystem.deleteFile(legacyLogPath);
FileSystem.deleteFile(legacyErrorLogPath);

const logPathPrefix: string = `${projectFolder}/${RushConstants.rushLogsFolderName}`;
FileSystem.ensureFolder(logPathPrefix);
logFolder = RushConstants.rushLogsFolderName;
}

const { logPath, errorLogPath, relativeLogPath, relativeErrorLogPath } = getLogFilePaths(
projectFolder,
logFilenameIdentifier,
RushConstants.rushLogsFolderName
);
this.logPath = logPath;
this.errorLogPath = errorLogPath;
this.relativeLogPath = relativeLogPath;
this.relativeErrorLogPath = relativeErrorLogPath;
} else {
this.logPath = legacyLogPath;
this.errorLogPath = legacyErrorLogPath;
this.relativeLogPath = legacyRelativeLogPath;
this.relativeErrorLogPath = legacyRelativeErrorLogPath;
const { logPath, errorLogPath, relativeLogPath, relativeErrorLogPath } = getLogFilePaths(
projectFolder,
logFilenameIdentifier,
logFolder
);
this.logPath = logPath;
this.errorLogPath = errorLogPath;
this.relativeLogPath = relativeLogPath;
this.relativeErrorLogPath = relativeErrorLogPath;

if (legacyLogPath !== this.logPath) {
FileSystem.deleteFile(this.logPath);
}

FileSystem.deleteFile(this.logPath);
FileSystem.deleteFile(this.errorLogPath);
if (legacyErrorLogPath !== this.errorLogPath) {
FileSystem.deleteFile(this.errorLogPath);
}

this._logWriter = FileWriter.open(this.logPath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class ShellOperationRunner implements IOperationRunner {
private async _executeAsync(context: IOperationRunnerContext): Promise<OperationStatus> {
// Only open the *.cache.log file(s) if the cache is enabled.
const cacheProjectLogWritable: ProjectLogWritable | undefined = this._buildCacheConfiguration
?.buildCacheEnabled
? new ProjectLogWritable(
this._rushProject,
context.collatedWriter.terminal,
Expand Down

0 comments on commit be9b01a

Please sign in to comment.