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
package/server/routes/updates.js
CHANGED
|
@@ -83,19 +83,26 @@ function buildReleaseList(metadata) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
async function readNpmPackageMetadata() {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)
|
|
97
|
-
|
|
98
|
-
|
|
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
|
-
|
|
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) => {
|