Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
- summary: |
Fix stale docs preview bundle on Windows by fully removing old bundle before
extracting and deferring ETag write until all post-processing succeeds.
type: fix
18 changes: 7 additions & 11 deletions packages/cli/docs-preview/src/downloadLocalDocsBundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { execSync } from "child_process";
import cliProgress from "cli-progress";
import decompress from "decompress";
import { cpSync, existsSync, lstatSync, mkdirSync, symlinkSync } from "fs";
import { mkdir, readFile, rename, rm, writeFile } from "fs/promises";
import { mkdir, readFile, rm, writeFile } from "fs/promises";
import { homedir } from "os";
import path from "path";
import tmp from "tmp-promise";
Expand Down Expand Up @@ -354,14 +354,8 @@ export async function downloadBundle({

const absolutePathToPreviewFolder = getPathToPreviewFolder({ app });
if (await doesPathExist(absolutePathToPreviewFolder)) {
const oldBundlePath = AbsoluteFilePath.of(`${absolutePathToPreviewFolder}-old-${Date.now()}`);
logger.debug(`Moving previously cached bundle to: ${oldBundlePath}`);
await rename(absolutePathToPreviewFolder, oldBundlePath);

// Delete the old bundle asynchronously so it doesn't block the rest of the setup
rm(oldBundlePath, { recursive: true }).catch((error) => {
logger.debug(`Failed to remove old bundle at ${oldBundlePath}: ${error}`);
});
logger.debug(`Removing previously cached bundle at: ${absolutePathToPreviewFolder}`);
await rm(absolutePathToPreviewFolder, { recursive: true, force: true });
}
await mkdir(absolutePathToPreviewFolder, { recursive: true });

Expand Down Expand Up @@ -447,8 +441,6 @@ export async function downloadBundle({
}
}

// write etag
await writeFile(eTagFilepath, eTag);
logger.debug(`Downloaded bundle to ${absolutePathToBundleFolder}`);

if (app) {
Expand Down Expand Up @@ -542,6 +534,10 @@ export async function downloadBundle({
}
}

// Write etag only after all post-processing succeeds, so a failed
// extraction won't be treated as cached on the next run.
await writeFile(eTagFilepath, eTag);

return {
type: "success"
};
Expand Down
Loading