vercel 28.15.3 → 28.15.4

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.
@@ -116,45 +116,10 @@ process.once('message', async msg => {
116
116
  output.debug(`Initializing lock file with pid ${process.pid}`);
117
117
  await writeFile(lockFile, String(process.pid), 'utf-8');
118
118
 
119
- // fetch the latest version from npm
120
- const agent = new https.Agent({
121
- keepAlive: true,
122
- maxSockets: 15, // See: `npm config get maxsockets`
123
- });
124
- const headers = {
125
- accept:
126
- 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
127
- };
128
- const url = `https://registry.npmjs.org/-/package/${name}/dist-tags`;
129
- output.debug(`Fetching ${url}`);
130
-
131
- const tags = await new Promise((resolve, reject) => {
132
- const req = https.get(
133
- url,
134
- {
135
- agent,
136
- headers,
137
- },
138
- res => {
139
- let buf = '';
140
- res.on('data', chunk => {
141
- buf += chunk;
142
- });
143
- res.on('end', () => {
144
- try {
145
- resolve(JSON.parse(buf));
146
- } catch (err) {
147
- reject(err);
148
- }
149
- });
150
- }
151
- );
152
-
153
- req.on('error', reject);
154
- req.end();
155
- });
156
-
119
+ const tags = await fetchDistTags(name);
157
120
  const version = tags[distTag];
121
+ const expireAt = Date.now() + updateCheckInterval;
122
+ const notifyAt = await getNotifyAt(cacheFile, version);
158
123
 
159
124
  if (version) {
160
125
  output.debug(`Found dist tag "${distTag}" with version "${version}"`);
@@ -167,8 +132,8 @@ process.once('message', async msg => {
167
132
  await writeFile(
168
133
  cacheFile,
169
134
  JSON.stringify({
170
- expireAt: Date.now() + updateCheckInterval,
171
- notified: false,
135
+ expireAt,
136
+ notifyAt,
172
137
  version,
173
138
  })
174
139
  );
@@ -223,3 +188,74 @@ async function isRunning(lockFile) {
223
188
  return false;
224
189
  }
225
190
  }
191
+
192
+ /**
193
+ * Attempts to load and return the previous `notifyAt` value.
194
+ *
195
+ * If the latest version is newer than the previous latest version, then
196
+ * return `undefined` to invalidate `notifyAt` which forces the notification
197
+ * to be displayed, otherwise keep the existing `notifyAt`.
198
+ *
199
+ * @param {string} cacheFile The path to the cache file
200
+ * @param {string} version The latest version
201
+ * @returns {number | undefined} The previous notifyAt
202
+ */
203
+ async function getNotifyAt(cacheFile, version) {
204
+ try {
205
+ const old = JSON.parse(await readFile(cacheFile, 'utf-8'));
206
+ if (old?.version && old.version === version) {
207
+ return old.notifyAt;
208
+ }
209
+ } catch (err) {
210
+ // cache does not exist or malformed
211
+ if (err.code !== 'ENOENT') {
212
+ output.debug(`Error reading latest package cache file: ${err}`);
213
+ }
214
+ }
215
+ }
216
+
217
+ /**
218
+ * Fetches the dist tags from npm for a given package.
219
+ *
220
+ * @param {string} name The package name
221
+ * @returns A map of dist tags to versions
222
+ */
223
+ async function fetchDistTags(name) {
224
+ // fetch the latest version from npm
225
+ const agent = new https.Agent({
226
+ keepAlive: true,
227
+ maxSockets: 15, // See: `npm config get maxsockets`
228
+ });
229
+ const headers = {
230
+ accept:
231
+ 'application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*',
232
+ };
233
+ const url = `https://registry.npmjs.org/-/package/${name}/dist-tags`;
234
+ output.debug(`Fetching ${url}`);
235
+
236
+ return new Promise((resolve, reject) => {
237
+ const req = https.get(
238
+ url,
239
+ {
240
+ agent,
241
+ headers,
242
+ },
243
+ res => {
244
+ let buf = '';
245
+ res.on('data', chunk => {
246
+ buf += chunk;
247
+ });
248
+ res.on('end', () => {
249
+ try {
250
+ resolve(JSON.parse(buf));
251
+ } catch (err) {
252
+ reject(err);
253
+ }
254
+ });
255
+ }
256
+ );
257
+
258
+ req.on('error', reject);
259
+ req.end();
260
+ });
261
+ }