Skip to content

Commit 42866f2

Browse files
authored
Fixed an issue that prevented fresh latest versions to be installed after installing dev versions of the runtime (#629)
1 parent 9019fef commit 42866f2

File tree

5 files changed

+47
-31
lines changed

5 files changed

+47
-31
lines changed

.changeset/calm-insects-sell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"replayio": patch
3+
---
4+
5+
Fixed an issue that prevented fresh latest versions to be installed after installing dev versions of the runtime

packages/replayio/src/commands/update.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { registerCommand } from "../utils/commander/registerCommand";
55
import { checkForNpmUpdate } from "../utils/initialization/checkForNpmUpdate";
66
import { checkForRuntimeUpdate } from "../utils/initialization/checkForRuntimeUpdate";
77
import { promptForNpmUpdate } from "../utils/initialization/promptForNpmUpdate";
8-
import { installLatestRelease } from "../utils/installation/installLatestRelease";
8+
import { installRelease } from "../utils/installation/installRelease";
99

1010
registerCommand("update", {
1111
checkForRuntimeUpdate: false,
@@ -18,14 +18,12 @@ registerCommand("update", {
1818
async function update() {
1919
try {
2020
const [runtimeUpdateCheck, npmUpdateCheck] = await Promise.all([
21-
process.env.RECORD_REPLAY_CHROMIUM_DOWNLOAD_FILE
22-
? { hasUpdate: true }
23-
: checkForRuntimeUpdate(),
21+
checkForRuntimeUpdate(),
2422
checkForNpmUpdate(),
2523
]);
2624

2725
if (runtimeUpdateCheck.hasUpdate && npmUpdateCheck.hasUpdate) {
28-
await installLatestRelease();
26+
await installRelease(runtimeUpdateCheck.toVersion);
2927
await promptForNpmUpdate(npmUpdateCheck, false);
3028
} else if (npmUpdateCheck.hasUpdate) {
3129
console.log(statusSuccess("✔"), "You have the latest version of the Replay Browser");
@@ -34,7 +32,7 @@ async function update() {
3432
} else if (runtimeUpdateCheck.hasUpdate) {
3533
console.log(statusSuccess("✔"), "You have the latest version of replayio");
3634

37-
await installLatestRelease();
35+
await installRelease(runtimeUpdateCheck.toVersion);
3836
} else {
3937
console.log(
4038
statusSuccess("✔"),

packages/replayio/src/utils/initialization/checkForRuntimeUpdate.ts

+18-5
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,24 @@ const PROMPT_ID = "runtime-update";
1212

1313
export type Version = {
1414
buildId: Release["buildId"];
15-
version: Release["version"];
15+
forkedVersion: Release["version"];
1616
};
1717

1818
export const checkForRuntimeUpdate = createAsyncFunctionWithTracking(
1919
async function checkForRuntimeUpdate(): Promise<UpdateCheck<Version>> {
20+
if (process.env.RECORD_REPLAY_CHROMIUM_DOWNLOAD_FILE) {
21+
const { buildId: currentBuildId } = getCurrentRuntimeMetadata("chromium") ?? {};
22+
const requestedBuildId = process.env.RECORD_REPLAY_CHROMIUM_DOWNLOAD_FILE
23+
// strip extension
24+
.replace(/\..+$/, "");
25+
logDebug("CheckForRuntimeUpdate:CurrentBuild", { currentBuildId, requestedBuildId });
26+
return {
27+
hasUpdate: true,
28+
fromVersion: currentBuildId ? { buildId: currentBuildId, forkedVersion: null } : undefined,
29+
shouldShowPrompt: false,
30+
toVersion: { buildId: requestedBuildId, forkedVersion: "dev" },
31+
};
32+
}
2033
let latestRelease: Release;
2134
let latestBuildId: string;
2235
try {
@@ -42,7 +55,7 @@ export const checkForRuntimeUpdate = createAsyncFunctionWithTracking(
4255
hasUpdate: true,
4356
fromVersion: undefined,
4457
shouldShowPrompt: true,
45-
toVersion: { buildId: latestBuildId, version: latestRelease.version },
58+
toVersion: { buildId: latestBuildId, forkedVersion: latestRelease.version },
4659
};
4760
}
4861

@@ -51,19 +64,19 @@ export const checkForRuntimeUpdate = createAsyncFunctionWithTracking(
5164

5265
return {
5366
hasUpdate: currentBuildId !== latestBuildId,
54-
fromVersion: currentBuildId ? { buildId: currentBuildId, version: null } : undefined,
67+
fromVersion: currentBuildId ? { buildId: currentBuildId, forkedVersion: null } : undefined,
5568
shouldShowPrompt: shouldPrompt({
5669
id: PROMPT_ID,
5770
metadata: latestBuildId,
5871
}),
59-
toVersion: { buildId: latestBuildId, version: latestRelease.version },
72+
toVersion: { buildId: latestBuildId, forkedVersion: latestRelease.version },
6073
};
6174
},
6275
"update.runtime.check",
6376
result => ({
6477
hasUpdate: result?.hasUpdate,
6578
newBuildId: result?.hasUpdate ? result?.toVersion.buildId : null,
66-
newRuntimeVersion: result?.hasUpdate ? result?.toVersion.version : null,
79+
newRuntimeVersion: result?.hasUpdate ? result?.toVersion.forkedVersion : null,
6780
shouldShowPrompt: !!(result?.hasUpdate && result?.shouldShowPrompt),
6881
})
6982
);

packages/replayio/src/utils/initialization/promptForRuntimeUpdate.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { trackEvent } from "@replay-cli/shared/mixpanelClient";
22
import { emphasize } from "@replay-cli/shared/theme";
33
import { name as packageName } from "../../../package.json";
4-
import { installLatestRelease } from "../installation/installLatestRelease";
4+
import { installRelease } from "../installation/installRelease";
55
import { prompt } from "../prompt/prompt";
66
import { updateCachedPromptData } from "../prompt/updateCachedPromptData";
77
import { Version } from "./checkForRuntimeUpdate";
88
import { UpdateCheckResult } from "./types";
9+
import { getLatestRelease } from "../installation/getLatestReleases";
910

1011
const PROMPT_ID = "runtime-update";
1112

@@ -44,7 +45,11 @@ export async function promptForRuntimeUpdate(updateCheck: UpdateCheckResult<Vers
4445

4546
if (confirmed) {
4647
try {
47-
await installLatestRelease();
48+
const latestRelease = await getLatestRelease();
49+
await installRelease({
50+
buildId: latestRelease.buildId,
51+
forkedVersion: latestRelease.version,
52+
});
4853
} catch (error) {
4954
// A failed update is not a critical error;
5055
// A failed install will be handled later

packages/replayio/src/utils/installation/installLatestRelease.ts packages/replayio/src/utils/installation/installRelease.ts

+13-18
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@ import { get } from "https";
1111
import { join } from "path";
1212
import { logAsyncOperation } from "../async/logAsyncOperation";
1313
import { metadataPath, runtimeMetadata } from "./config";
14-
import { getLatestRelease } from "./getLatestReleases";
1514
import { MetadataJSON } from "./types";
1615

1716
const MAX_DOWNLOAD_ATTEMPTS = 5;
1817

19-
type Result = {
18+
type ReleaseSpec = {
2019
buildId: string;
2120
forkedVersion: string | null;
2221
};
2322

24-
export const installLatestRelease = createAsyncFunctionWithTracking(
25-
async function installLatestRelease(): Promise<Result | undefined> {
26-
logInfo("InstallLatestRelease:Start");
23+
export const installRelease = createAsyncFunctionWithTracking(
24+
async function installRelease(releaseSpec: ReleaseSpec): Promise<ReleaseSpec | undefined> {
25+
logInfo("InstallRelease:Start");
2726
const runtimeBaseDir = getReplayPath("runtimes");
2827
const runtimePath = getReplayPath("runtimes", runtimeMetadata.destinationName);
2928
const downloadFilePath = getReplayPath("runtimes", runtimeMetadata.downloadFileName);
@@ -39,17 +38,17 @@ export const installLatestRelease = createAsyncFunctionWithTracking(
3938

4039
progress.setPending("Processing downloaded browser archive");
4140

42-
logInfo("InstallLatestRelease:RemovingPreviousInstallation", { runtimePath });
41+
logInfo("InstallRelease:RemovingPreviousInstallation", { runtimePath });
4342
rmSync(runtimePath, { force: true, recursive: true });
4443

4544
ensureDirSync(runtimeBaseDir);
4645

47-
logInfo("InstallLatestRelease:WritingDownloadFile", { downloadFilePath });
46+
logInfo("InstallRelease:WritingDownloadFile", { downloadFilePath });
4847
writeFileSync(downloadFilePath, buffers);
4948

5049
extractBrowserArchive(runtimeBaseDir, runtimePath);
5150

52-
logInfo("InstallLatestRelease:DeletingDownloadedFile", { downloadFilePath });
51+
logInfo("InstallRelease:DeletingDownloadedFile", { downloadFilePath });
5352
unlinkSync(downloadFilePath);
5453

5554
// This seems unnecessary, but we've always done it (and changing it would break legacy CLI compat)
@@ -62,28 +61,24 @@ export const installLatestRelease = createAsyncFunctionWithTracking(
6261
);
6362
}
6463

65-
const latestRelease = await getLatestRelease();
66-
const latestBuildId = latestRelease.buildId;
67-
const latestVersion = latestRelease.version;
68-
6964
// Write version metadata to disk so we can compare against the latest release and prompt to update
70-
logInfo("InstallLatestRelease:SavingMetadata", { metadataPath });
65+
logInfo("InstallRelease:SavingMetadata", { metadataPath });
7166
writeToCache<MetadataJSON>(metadataPath, {
7267
chromium: {
73-
buildId: latestBuildId,
74-
forkedVersion: latestVersion,
68+
buildId: releaseSpec.buildId,
69+
forkedVersion: releaseSpec.forkedVersion,
7570
installDate: new Date().toISOString(),
7671
},
7772
});
7873

7974
progress.setSuccess("Replay browser has been updated.");
8075

8176
return {
82-
buildId: latestBuildId,
83-
forkedVersion: latestVersion,
77+
buildId: releaseSpec.buildId,
78+
forkedVersion: releaseSpec.forkedVersion,
8479
};
8580
} catch (error) {
86-
logError("InstallLatestRelease:Failed", { error });
81+
logError("InstallRelease:Failed", { error });
8782

8883
progress.setFailed("Something went wrong installing the Replay browser.");
8984
throw error;

0 commit comments

Comments
 (0)