Skip to content
Merged
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
29 changes: 26 additions & 3 deletions src/bin/check-latest-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,40 @@
* SPDX-License-Identifier: Apache-2.0
*/

import {execSync} from 'node:child_process';
import fs from 'node:fs/promises';
import path from 'node:path';
import process from 'node:process';

const DEFAULT_REGISTRY = 'https://registry.npmjs.org';

function getRegistry(): string {
// Use the user's configured npm registry so update checks work behind
// corporate proxies and private registries. `npm config get registry`
// honors .npmrc files at every scope and respects npm_config_registry,
// so it covers direct CLI invocations as well as `npx` / `npm run`.
try {
const registry = execSync('npm config get registry', {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'ignore'],
timeout: 5000,
})
.trim()
.replace(/\/$/, '');
if (registry && registry !== 'undefined' && /^https?:\/\//.test(registry)) {
return registry;
}
} catch {
// npm not on PATH or other errors, fall back to default.
}
return DEFAULT_REGISTRY;
}

const cachePath = process.argv[2];

if (cachePath) {
try {
const response = await fetch(
'https://registry.npmjs.org/chrome-devtools-mcp/latest',
);
const response = await fetch(`${getRegistry()}/chrome-devtools-mcp/latest`);
const data = response.ok ? await response.json() : null;

if (
Expand Down
Loading