豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 3f0cf10

Browse files
fix: avoid showing update notification for local builds (#1889)
Previously, we would show the notification if the local version string was *different* from the latest version string published to npm. With this patch, we actually check if the npm-published version is newer and avoid showing the notification otherwise. Closes #1886
1 parent 796d6f2 commit 3f0cf10

File tree

6 files changed

+58
-25
lines changed

6 files changed

+58
-25
lines changed

package-lock.json

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"@types/debug": "^4.1.12",
5757
"@types/filesystem": "^0.0.36",
5858
"@types/node": "^25.0.0",
59+
"@types/semver": "^7.7.1",
5960
"@types/sinon": "^21.0.0",
6061
"@types/yargs": "^17.0.33",
6162
"@typescript-eslint/eslint-plugin": "^8.43.0",
@@ -73,6 +74,7 @@
7374
"rollup": "4.60.1",
7475
"rollup-plugin-cleanup": "^3.2.1",
7576
"rollup-plugin-license": "^3.6.0",
77+
"semver": "^7.7.4",
7678
"sinon": "^21.0.0",
7779
"tiktoken": "^1.0.22",
7880
"typescript": "^6.0.2",

src/third_party/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type {Flags, Result, RunnerResult, OutputMode};
1616
export type {Options as YargsOptions} from 'yargs';
1717
export {default as yargs} from 'yargs';
1818
export {hideBin} from 'yargs/helpers';
19+
export {default as semver} from 'semver';
1920
export {default as debug} from 'debug';
2021
export type {Debugger} from 'debug';
2122
export {McpServer} from '@modelcontextprotocol/sdk/server/mcp.js';

src/utils/check-for-updates.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import os from 'node:os';
1010
import path from 'node:path';
1111
import process from 'node:process';
1212

13+
import {semver} from '../third_party/index.js';
1314
import {VERSION} from '../version.js';
1415

1516
/**
@@ -46,7 +47,7 @@ export async function checkForUpdates(message: string) {
4647
// Ignore errors reading cache.
4748
}
4849

49-
if (cachedVersion && cachedVersion !== VERSION) {
50+
if (cachedVersion && semver.lt(VERSION, cachedVersion)) {
5051
console.warn(
5152
`\nUpdate available: ${VERSION} -> ${cachedVersion}\n${message}\n`,
5253
);

tests/check-for-updates.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ describe('checkForUpdates', () => {
7373
assert.ok(spawnStub.notCalled);
7474
});
7575

76+
it('does not notify if incoming version is older than current version', async () => {
77+
sinon.stub(os, 'homedir').returns('/home/user');
78+
sinon.stub(fs, 'stat').resolves({mtimeMs: Date.now()} as unknown as Stats);
79+
sinon.stub(fs, 'readFile').callsFake(async filePath => {
80+
if (filePath.toString().includes('latest.json')) {
81+
return JSON.stringify({
82+
version: '0.0.1',
83+
});
84+
}
85+
throw new Error(`File not found: ${filePath}`);
86+
});
87+
const warnStub = sinon.stub(console, 'warn');
88+
const spawnStub = sinon.stub(child_process, 'spawn');
89+
90+
await checkForUpdates('Run `npm update` to update.');
91+
92+
assert.ok(warnStub.notCalled);
93+
assert.ok(spawnStub.notCalled);
94+
});
95+
7696
it('does not spawn fetch process if cache is fresh', async () => {
7797
sinon.stub(os, 'homedir').returns('/home/user');
7898
sinon.stub(fs, 'stat').resolves({mtimeMs: Date.now()} as unknown as Stats);

tests/third_party_notices.test.js.snapshot

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,30 @@ Permission to use, copy, modify, and/or distribute this software for any purpose
294294
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
295295

296296

297+
-------------------- DEPENDENCY DIVIDER --------------------
298+
299+
Name: semver
300+
URL: git+https://github.com/npm/node-semver.git
301+
Version: <VERSION>
302+
License: ISC
303+
304+
The ISC License
305+
306+
Copyright (c) Isaac Z. Schlueter and Contributors
307+
308+
Permission to use, copy, modify, and/or distribute this software for any
309+
purpose with or without fee is hereby granted, provided that the above
310+
copyright notice and this permission notice appear in all copies.
311+
312+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
313+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
314+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
315+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
316+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
317+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
318+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
319+
320+
297321
-------------------- DEPENDENCY DIVIDER --------------------
298322

299323
Name: debug
@@ -829,30 +853,6 @@ URL: https://github.com/puppeteer/puppeteer/tree/main/packages/browsers
829853
Version: <VERSION>
830854
License: Apache-2.0
831855

832-
-------------------- DEPENDENCY DIVIDER --------------------
833-
834-
Name: semver
835-
URL: git+https://github.com/npm/node-semver.git
836-
Version: <VERSION>
837-
License: ISC
838-
839-
The ISC License
840-
841-
Copyright (c) Isaac Z. Schlueter and Contributors
842-
843-
Permission to use, copy, modify, and/or distribute this software for any
844-
purpose with or without fee is hereby granted, provided that the above
845-
copyright notice and this permission notice appear in all copies.
846-
847-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
848-
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
849-
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
850-
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
851-
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
852-
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
853-
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
854-
855-
856856
-------------------- DEPENDENCY DIVIDER --------------------
857857

858858
Name: proxy-agent

0 commit comments

Comments
 (0)