Skip to content

Commit b384e85

Browse files
committed
fix: let prerelease builds follow their own channel
A nightly build's update notice checks and recommends the nightly dist-tag. A prerelease Android helper takes its base release's versionCode instead of 1, so a nightly or -dev helper replaces an older release on the device.
1 parent 441cd1a commit b384e85

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

‎scripts/build-android-helper.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,11 @@ for BUILD_TOOL in aapt2 d8 zipalign apksigner; do
9696
fi
9797
done
9898

99+
# A prerelease shares its base release's code, so a nightly or -dev helper replaces an older
100+
# release; an equal code reinstalls by checksum.
99101
VERSION_CODE="$(
100102
printf '%s\n' "$VERSION" | awk -F. '
101-
/^[0-9]+[.][0-9]+[.][0-9]+$/ {
103+
/^[0-9]+[.][0-9]+[.][0-9]+(-[0-9A-Za-z.-]+)?$/ {
102104
print ($1 * 1000000) + ($2 * 1000) + $3
103105
next
104106
}

‎src/__tests__/update-check.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,33 @@ test('worker resets prompted state when it discovers a newer version', async ()
188188
assert.equal(cache.latestVersion, '0.13.0');
189189
assert.equal(cache.prompted, false);
190190
});
191+
192+
test('a nightly build checks and recommends the nightly dist-tag', async () => {
193+
const stateDir = makeTempStateDir();
194+
cleanupPaths.push(stateDir);
195+
const cachePath = path.join(stateDir, 'update-check.json');
196+
const fetchMock = vi.fn().mockResolvedValue({
197+
ok: true,
198+
json: async () => ({ version: '0.12.0-nightly.20261011.8' }),
199+
});
200+
vi.stubGlobal('fetch', fetchMock);
201+
202+
await runUpdateCheckWorker({ cachePath, currentVersion: '0.12.0-nightly.20261010.7' });
203+
204+
assert.equal(fetchMock.mock.calls[0]?.[0], 'https://registry.npmjs.org/agent-device/nightly');
205+
let stderr = '';
206+
vi.spyOn(process.stderr, 'write').mockImplementation(((chunk: unknown) => {
207+
stderr += String(chunk);
208+
return true;
209+
}) as typeof process.stderr.write);
210+
maybeRunUpgradeNotifier({
211+
command: 'devices',
212+
currentVersion: '0.12.0-nightly.20261010.7',
213+
stateDir,
214+
flags: {},
215+
});
216+
assert.match(
217+
stderr,
218+
/-> 0\.12\.0-nightly\.20261011\.8\. Run `npm install -g agent-device@nightly`/,
219+
);
220+
});

‎src/cli/update-check.ts‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function maybeRunUpgradeNotifier(options: UpgradeNotifierOptions): void {
4242
if (shouldShowUpgradeNotice(cache, options.currentVersion)) {
4343
process.stderr.write(
4444
`Update available: ${PACKAGE_NAME} ${options.currentVersion} -> ${cache.latestVersion}. ` +
45-
`Run \`npm install -g ${PACKAGE_NAME}@latest\` to upgrade the CLI.\n`,
45+
`Run \`npm install -g ${PACKAGE_NAME}@${distTagFor(options.currentVersion)}\` to upgrade the CLI.\n`,
4646
);
4747
writeUpdateCheckCache(cachePath, {
4848
...cache,
@@ -60,7 +60,8 @@ export async function runUpdateCheckWorker(options: UpdateCheckWorkerOptions): P
6060
const cache = readUpdateCheckCache(options.cachePath);
6161

6262
try {
63-
const latestVersion = (await fetchLatestPackageVersion()) ?? undefined;
63+
const latestVersion =
64+
(await fetchLatestPackageVersion(distTagFor(options.currentVersion))) ?? undefined;
6465
if (!latestVersion || compareVersions(latestVersion, options.currentVersion) <= 0) {
6566
writeUpdateCheckCache(options.cachePath, { checkedAt: new Date(now).toISOString() });
6667
return;
@@ -150,8 +151,13 @@ function spawnBackgroundUpdateCheck(cachePath: string, currentVersion: string):
150151
]);
151152
}
152153

153-
async function fetchLatestPackageVersion(): Promise<string | undefined> {
154-
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/latest`, {
154+
/** A nightly build follows the `nightly` dist-tag; every other build follows `latest`. */
155+
function distTagFor(version: string): 'latest' | 'nightly' {
156+
return version.includes('-nightly.') ? 'nightly' : 'latest';
157+
}
158+
159+
async function fetchLatestPackageVersion(distTag: string): Promise<string | undefined> {
160+
const response = await fetch(`https://registry.npmjs.org/${PACKAGE_NAME}/${distTag}`, {
155161
signal: AbortSignal.timeout(UPDATE_CHECK_TIMEOUT_MS),
156162
headers: { accept: 'application/json' },
157163
});

0 commit comments

Comments
 (0)