buddy-workbench 0.1.59 → 0.1.60

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "buddy-workbench",
3
- "version": "0.1.59",
3
+ "version": "0.1.60",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -83,19 +83,26 @@ function buildReleaseList(metadata) {
83
83
  }
84
84
 
85
85
  async function readNpmPackageMetadata() {
86
- const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
87
- const { stdout } = await execFileAsync(
88
- npmCommand,
89
- ['view', `${PACKAGE_NAME}@latest`, 'version', 'time', 'devbuddyChangelog', '--json'],
90
- {
91
- timeout: 8000,
92
- maxBuffer: 1024 * 1024,
93
- shell: process.platform === 'win32',
94
- windowsHide: true
95
- }
96
- );
97
- const metadata = JSON.parse(stdout);
98
- if (!metadata || typeof metadata !== 'object' || !metadata.version) {
86
+ // Do not depend on npm being present in the server process PATH. On Windows,
87
+ // a UI launched from a shortcut often has a reduced PATH and `npm.cmd view`
88
+ // fails even though npm works in an interactive terminal.
89
+ const registry = String(process.env.npm_config_registry || 'https://registry.npmjs.org/')
90
+ .trim()
91
+ .replace(/\/+$/, '');
92
+ const response = await fetch(`${registry}/${encodeURIComponent(PACKAGE_NAME)}`, {
93
+ headers: { Accept: 'application/json' },
94
+ signal: AbortSignal.timeout(8000)
95
+ });
96
+ if (!response.ok) {
97
+ throw new Error(`The configured npm registry returned HTTP ${response.status}.`);
98
+ }
99
+ const packageMetadata = await response.json();
100
+ const metadata = {
101
+ version: packageMetadata?.['dist-tags']?.latest,
102
+ time: packageMetadata?.time,
103
+ devbuddyChangelog: packageMetadata?.devbuddyChangelog
104
+ };
105
+ if (!metadata.version) {
99
106
  throw new Error('The configured npm registry did not return package version metadata.');
100
107
  }
101
108
  return metadata;
@@ -157,17 +164,19 @@ process.exitCode = failed ? 1 : 0;`;
157
164
 
158
165
  router.get('/', async (req, res) => {
159
166
  const forceRefresh = req.query.refresh === '1';
160
- if (!forceRefresh && cachedResult && Date.now() - cachedAt < CACHE_TTL_MS) {
167
+ if (!forceRefresh && cachedResult && !cachedResult.sourceUnavailable && Date.now() - cachedAt < CACHE_TTL_MS) {
161
168
  return res.json(cachedResult);
162
169
  }
163
170
 
164
171
  try {
165
172
  cachedResult = await checkForUpdates();
173
+ cachedAt = Date.now();
174
+ return res.json(cachedResult);
166
175
  } catch {
167
- cachedResult = unavailableResult();
176
+ // A transient startup/network failure must not poison the 15-minute cache.
177
+ // The next normal request should be allowed to try the registry again.
178
+ return res.json(unavailableResult());
168
179
  }
169
- cachedAt = Date.now();
170
- return res.json(cachedResult);
171
180
  });
172
181
 
173
182
  router.post('/self-update', async (req, res) => {