@virmator/deps 14.23.0 → 14.23.1

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/README.md CHANGED
@@ -47,9 +47,7 @@ A default plugin for [virmator](https://www.npmjs.com/package/virmator).
47
47
 
48
48
  Force regeneration of all all dependencies by deleting all node_modules directories and package-lock.json and then running 'npm i'.
49
49
 
50
- If npm's effective 'min-release-age' is set (resolved across project, user, and global config), any direct dependency that matches the deps-regen allow list but currently pins a too-recent version is temporarily downgraded to the most recent version that satisfies 'min-release-age' so the install succeeds. After regeneration, each such dependency is re-installed at its original version with '--min-release-age=0' (in its own package, or the mono-repo root) and its original 'package.json' version is restored.
51
-
52
- The allow list defaults to 'configs/deps-regen.config.ts' (as placed by 'virmator init'); a missing default config is silently skipped. Override it with '--config <path>'; an explicitly-provided config that does not exist is an error.
50
+ Reads 'configs/deps-regen.config.ts' for intelligently working around min-release-age for explicitly allowed packages.
53
51
 
54
52
  - Examples
55
53
  - `virmator deps regen`
@@ -21,6 +21,7 @@ const electrovirPackages: RecentDepsAllowList = [
21
21
  'element-vir',
22
22
  'execute-in-browser',
23
23
  'i18n-vir',
24
+ 'indexed-vir',
24
25
  'istanbul-smart-text-reporter',
25
26
  'lit-css-vars',
26
27
  'local-db-client',
package/dist/deps.d.ts CHANGED
@@ -122,7 +122,7 @@ export declare const virmatorDepsPlugin: Readonly<Readonly<{
122
122
  };
123
123
  readonly regen: {
124
124
  readonly doc: {
125
- readonly sections: readonly ["\n Force regeneration of all all dependencies by deleting all\n node_modules directories and package-lock.json and then\n running 'npm i'.\n ", "\n If npm's effective 'min-release-age' is set (resolved across\n project, user, and global config), any direct dependency that\n matches the deps-regen allow list but currently pins a too-recent\n version is temporarily downgraded to the most recent version that\n satisfies 'min-release-age' so the install succeeds. After\n regeneration, each such dependency is re-installed at its original\n version with '--min-release-age=0' (in its own package, or the\n mono-repo root) and its original 'package.json' version is\n restored.\n ", "\n The allow list defaults to 'configs/deps-regen.config.ts' (as\n placed by 'virmator init'); a missing default config is silently\n skipped. Override it with '--config <path>'; an explicitly-provided\n config that does not exist is an error.\n "];
125
+ readonly sections: readonly ["\n Force regeneration of all all dependencies by deleting all\n node_modules directories and package-lock.json and then\n running 'npm i'.\n ", "\n Reads 'configs/deps-regen.config.ts' for intelligently working\n around min-release-age for explicitly allowed packages.\n "];
126
126
  readonly examples: readonly [{
127
127
  readonly content: "virmator deps regen";
128
128
  }, {
@@ -256,7 +256,7 @@ export declare const virmatorDepsPlugin: Readonly<Readonly<{
256
256
  };
257
257
  readonly regen: {
258
258
  readonly doc: {
259
- readonly sections: readonly ["\n Force regeneration of all all dependencies by deleting all\n node_modules directories and package-lock.json and then\n running 'npm i'.\n ", "\n If npm's effective 'min-release-age' is set (resolved across\n project, user, and global config), any direct dependency that\n matches the deps-regen allow list but currently pins a too-recent\n version is temporarily downgraded to the most recent version that\n satisfies 'min-release-age' so the install succeeds. After\n regeneration, each such dependency is re-installed at its original\n version with '--min-release-age=0' (in its own package, or the\n mono-repo root) and its original 'package.json' version is\n restored.\n ", "\n The allow list defaults to 'configs/deps-regen.config.ts' (as\n placed by 'virmator init'); a missing default config is silently\n skipped. Override it with '--config <path>'; an explicitly-provided\n config that does not exist is an error.\n "];
259
+ readonly sections: readonly ["\n Force regeneration of all all dependencies by deleting all\n node_modules directories and package-lock.json and then\n running 'npm i'.\n ", "\n Reads 'configs/deps-regen.config.ts' for intelligently working\n around min-release-age for explicitly allowed packages.\n "];
260
260
  readonly examples: readonly [{
261
261
  readonly content: "virmator deps regen";
262
262
  }, {
package/dist/deps.js CHANGED
@@ -178,21 +178,8 @@ export const virmatorDepsPlugin = defineVirmatorPlugin(import.meta.dirname, {
178
178
  running 'npm i'.
179
179
  `,
180
180
  `
181
- If npm's effective 'min-release-age' is set (resolved across
182
- project, user, and global config), any direct dependency that
183
- matches the deps-regen allow list but currently pins a too-recent
184
- version is temporarily downgraded to the most recent version that
185
- satisfies 'min-release-age' so the install succeeds. After
186
- regeneration, each such dependency is re-installed at its original
187
- version with '--min-release-age=0' (in its own package, or the
188
- mono-repo root) and its original 'package.json' version is
189
- restored.
190
- `,
191
- `
192
- The allow list defaults to 'configs/deps-regen.config.ts' (as
193
- placed by 'virmator init'); a missing default config is silently
194
- skipped. Override it with '--config <path>'; an explicitly-provided
195
- config that does not exist is an error.
181
+ Reads 'configs/deps-regen.config.ts' for intelligently working
182
+ around min-release-age for explicitly allowed packages.
196
183
  `,
197
184
  ],
198
185
  examples: [
@@ -39,18 +39,24 @@ export type RecentDepViolator = {
39
39
  originalVersionValue: string;
40
40
  /** The leading non-numeric prefix of the original version (e.g. `^` or `~` or `''`). */
41
41
  versionPrefix: string;
42
- /** The most recent published version that does _not_ violate min-release-age. */
43
- safeVersion: string;
42
+ /**
43
+ * The most recent published version that does _not_ violate min-release-age, to temporarily
44
+ * downgrade to. `undefined` when _no_ published version is old enough (e.g. a brand-new
45
+ * package); in that case the dep is temporarily removed for the regen install instead, then
46
+ * re-added by the bypass reinstall.
47
+ */
48
+ safeVersion: string | undefined;
44
49
  };
45
50
  export type RegistryInfo = {
46
51
  /** Map of published version (and `created`/`modified`) to ISO publish date. */
47
52
  time: Record<string, string>;
48
53
  };
49
- /** A single `package.json` dependency version change applied by {@link updatePackageJsonVersions}. */
54
+ /** A single `package.json` dependency change applied by {@link updatePackageJsonVersions}. */
50
55
  export type VersionUpdate = {
51
56
  dependencyKey: PackageJsonDependencyKey;
52
57
  depName: string;
53
- version: string;
58
+ /** The new version range, or `undefined` to remove the dependency entry entirely. */
59
+ version: string | undefined;
54
60
  };
55
61
  /** A direct dependency name paired with its installable, non-workspace usages. */
56
62
  export type CandidateDepUsage = {
@@ -68,11 +74,11 @@ export type RecentDepsIo = {
68
74
  listDirectDeps: (rootPath: string) => Promise<NpmDeps>;
69
75
  queryRegistry: (depName: string, cwd: string) => Promise<RegistryInfo | undefined>;
70
76
  /**
71
- * Resolves the given range to the newest published version satisfying it (ignoring
72
- * min-release-age) — i.e. what gets installed once min-release-age is bypassed — or `undefined`
73
- * if the range matches nothing.
77
+ * Returns every published version satisfying the given range (ignoring min-release-age), or
78
+ * `undefined` if the range matches nothing. Used to decide whether a cooldown-respecting
79
+ * install could find an old-enough version.
74
80
  */
75
- queryResolvedVersion: (depName: string, range: string, cwd: string) => Promise<string | undefined>;
81
+ queryInRangeVersions: (depName: string, range: string, cwd: string) => Promise<string[] | undefined>;
76
82
  updatePackageJsonVersions: (packageJsonPath: string, updates: ReadonlyArray<VersionUpdate>) => Promise<void>;
77
83
  };
78
84
  /** Parses the output of `npm config get min-release-age` into a positive day count, or `undefined`. */
@@ -88,12 +94,16 @@ export declare function loadAllowList(configPath: string): Promise<RecentDepsAll
88
94
  /** Parses the JSON time map output of `npm view <pkg> time --json` into a {@link RegistryInfo}. */
89
95
  export declare function parseRegistryTime(stdout: string): RegistryInfo | undefined;
90
96
  /**
91
- * Parses the JSON output of `npm view <pkg>@<range> version --json` into the newest matching
92
- * version (the last entry, since npm sorts ascending), or `undefined` if nothing matched / the
93
- * output was unusable.
97
+ * Parses the JSON output of `npm view <pkg>@<range> version --json` into the list of published
98
+ * versions that satisfy the range (npm returns a single string when only one matches, an array
99
+ * otherwise). `undefined` if nothing matched / the output was unusable.
100
+ */
101
+ export declare function parseInRangeVersions(stdout: string): string[] | undefined;
102
+ /**
103
+ * Reads, applies the given dependency changes to, and re-writes a `package.json` file in place. A
104
+ * `string` version sets (or re-adds) the entry; an `undefined` version removes it. Sections that
105
+ * don't exist are left untouched.
94
106
  */
95
- export declare function parseResolvedVersion(stdout: string): string | undefined;
96
- /** Reads, mutates the given dependency versions in, and re-writes a `package.json` file in place. */
97
107
  export declare function updatePackageJsonVersions(packageJsonPath: string, updates: ReadonlyArray<VersionUpdate>): Promise<void>;
98
108
  /**
99
109
  * Drops workspace-internal deps, non-installable sections (e.g. `overrides`), and any dependency
@@ -104,28 +114,27 @@ export declare function getCandidateDepUsages(allDirectDeps: Readonly<NpmDeps>):
104
114
  /** The lookup key for a specific dependency range (or version). */
105
115
  export declare function depRangeKey(depName: string, range: string): string;
106
116
  /**
107
- * Returns the `{depName, range}` pairs whose newest-in-range version must be resolved (to check
108
- * recency against the version that will actually be installed): only for allow-list-matched
109
- * candidates with a parseable range. Deduped.
117
+ * Returns the `{depName, range}` pairs whose in-range versions must be looked up (to decide whether
118
+ * a cooldown-respecting install could satisfy the range): only for allow-list-matched candidates
119
+ * with a parseable range. Deduped.
110
120
  */
111
121
  export declare function getResolveTargets(candidateUsages: ReadonlyArray<CandidateDepUsage>, allowList: RecentDepsAllowList): {
112
122
  depName: string;
113
123
  range: string;
114
124
  }[];
115
125
  /**
116
- * Pure detection of every direct dependency usage that both matches the allow list and pins a
117
- * version too recent for the min-release-age threshold, paired with the safe version it should be
118
- * temporarily downgraded to.
126
+ * Pure detection of every direct dependency usage that both matches the allow list and whose range
127
+ * _cannot_ be satisfied by an old-enough version (so a cooldown-respecting `npm i` would fail),
128
+ * paired with the safe version it should be temporarily downgraded to (or `undefined` to remove).
129
+ * Deps whose range already has an old-enough version are left alone — `npm i` installs that
130
+ * itself.
119
131
  */
120
- export declare function computeRecentDepViolators({ candidateUsages, allowList, registryByName, resolvedByRange, threshold, }: {
132
+ export declare function computeRecentDepViolators({ candidateUsages, allowList, registryByName, inRangeVersionsByRange, threshold, }: {
121
133
  candidateUsages: ReadonlyArray<CandidateDepUsage>;
122
134
  allowList: RecentDepsAllowList;
123
135
  registryByName: ReadonlyMap<string, RegistryInfo | undefined>;
124
- /**
125
- * The resolved newest-in-range version per `${depName}@${range}`. Recency is checked against
126
- * this (the version that will actually be installed), not the pinned floor.
127
- */
128
- resolvedByRange: ReadonlyMap<string, string | undefined>;
136
+ /** The published versions satisfying each `${depName}@${range}` (ignoring min-release-age). */
137
+ inRangeVersionsByRange: ReadonlyMap<string, string[] | undefined>;
129
138
  /** The min-release-age cutoff: a version published after this is too recent. */
130
139
  threshold: FullDate;
131
140
  }): RecentDepViolator[];
@@ -121,16 +121,23 @@ export function parseRegistryTime(stdout) {
121
121
  };
122
122
  }
123
123
  /**
124
- * Parses the JSON output of `npm view <pkg>@<range> version --json` into the newest matching
125
- * version (the last entry, since npm sorts ascending), or `undefined` if nothing matched / the
126
- * output was unusable.
124
+ * Parses the JSON output of `npm view <pkg>@<range> version --json` into the list of published
125
+ * versions that satisfy the range (npm returns a single string when only one matches, an array
126
+ * otherwise). `undefined` if nothing matched / the output was unusable.
127
127
  */
128
- export function parseResolvedVersion(stdout) {
128
+ export function parseInRangeVersions(stdout) {
129
129
  const parsed = wrapInTry(() => JSON.parse(stdout), {
130
130
  fallbackValue: undefined,
131
131
  });
132
- const newest = check.isArray(parsed) ? parsed[parsed.length - 1] : parsed;
133
- return check.isString(newest) ? newest : undefined;
132
+ if (check.isString(parsed)) {
133
+ return [
134
+ parsed,
135
+ ];
136
+ }
137
+ else if (check.isArray(parsed)) {
138
+ return parsed.filter(check.isString);
139
+ }
140
+ return undefined;
134
141
  }
135
142
  /* node:coverage disable -- thin network wrappers around the npm registry; parsing lives in the parse* helpers */
136
143
  async function queryRegistry(depName, cwd) {
@@ -142,14 +149,14 @@ async function queryRegistry(depName, cwd) {
142
149
  }
143
150
  return parseRegistryTime(result.stdout);
144
151
  }
145
- async function queryResolvedVersion(depName, range, cwd) {
152
+ async function queryInRangeVersions(depName, range, cwd) {
146
153
  const result = await runShellCommand(`npm view '${depName}@${range}' version --json`, {
147
154
  cwd,
148
155
  });
149
156
  if (result.exitCode) {
150
157
  return undefined;
151
158
  }
152
- return parseResolvedVersion(result.stdout);
159
+ return parseInRangeVersions(result.stdout);
153
160
  }
154
161
  /* node:coverage enable */
155
162
  /** Whether a dependency name matches any allow-list entry (exact string or RegExp pattern). */
@@ -171,30 +178,30 @@ function parseVersionValue(versionValue) {
171
178
  version: match[2],
172
179
  };
173
180
  }
174
- /** Whether the given publish date is more recent than `threshold` (the min-release-age cutoff). */
175
- function isVersionTooRecent(publishDateString, threshold) {
181
+ /**
182
+ * Whether the given publish date is old enough to satisfy `threshold` (the min-release-age cutoff)
183
+ * — i.e. a cooldown-respecting `npm i` would be allowed to install it. Missing/invalid dates are
184
+ * treated as not old enough.
185
+ */
186
+ function isVersionOldEnough(publishDateString, threshold) {
176
187
  if (!publishDateString || !isValidIsoString(publishDateString)) {
177
188
  return false;
178
189
  }
179
- return isDateAfter({
190
+ return !isDateAfter({
180
191
  fullDate: createUtcFullDate(publishDateString),
181
192
  relativeTo: threshold,
182
193
  });
183
194
  }
184
- /** Finds the most recently published stable version that is no newer than `threshold`. */
195
+ /** Finds the most recently published stable version that is old enough to satisfy `threshold`. */
185
196
  function findMostRecentSafeVersion(time, threshold) {
186
197
  const safeVersions = getObjectTypedEntries(time)
187
- .filter(([version, dateString,]) => /^\d+\.\d+\.\d+$/.test(version) && isValidIsoString(dateString))
198
+ .filter(([version, dateString,]) => /^\d+\.\d+\.\d+$/.test(version) && isVersionOldEnough(dateString, threshold))
188
199
  .map(([version, dateString,]) => {
189
200
  return {
190
201
  version,
191
202
  date: createUtcFullDate(dateString),
192
203
  };
193
- })
194
- .filter(({ date }) => !isDateAfter({
195
- fullDate: date,
196
- relativeTo: threshold,
197
- }));
204
+ });
198
205
  if (!safeVersions.length) {
199
206
  return undefined;
200
207
  }
@@ -205,7 +212,11 @@ function findMostRecentSafeVersion(time, threshold) {
205
212
  ? current
206
213
  : mostRecent).version;
207
214
  }
208
- /** Reads, mutates the given dependency versions in, and re-writes a `package.json` file in place. */
215
+ /**
216
+ * Reads, applies the given dependency changes to, and re-writes a `package.json` file in place. A
217
+ * `string` version sets (or re-adds) the entry; an `undefined` version removes it. Sections that
218
+ * don't exist are left untouched.
219
+ */
209
220
  export async function updatePackageJsonVersions(packageJsonPath, updates) {
210
221
  const originalContents = await readFile(packageJsonPath, 'utf8');
211
222
  const indent = /\n([ \t]+)\S/.exec(originalContents)?.[1] || ' ';
@@ -213,7 +224,13 @@ export async function updatePackageJsonVersions(packageJsonPath, updates) {
213
224
  const parsed = JSON.parse(originalContents);
214
225
  updates.forEach(({ dependencyKey, depName, version }) => {
215
226
  const section = parsed[dependencyKey];
216
- if (check.isObject(section) && depName in section) {
227
+ if (!check.isObject(section)) {
228
+ return;
229
+ }
230
+ if (version == undefined) {
231
+ delete section[depName];
232
+ }
233
+ else {
217
234
  section[depName] = version;
218
235
  }
219
236
  });
@@ -257,9 +274,9 @@ function rangeOfUsage(versionValue) {
257
274
  return parsedVersion ? `${parsedVersion.prefix}${parsedVersion.version}` : undefined;
258
275
  }
259
276
  /**
260
- * Returns the `{depName, range}` pairs whose newest-in-range version must be resolved (to check
261
- * recency against the version that will actually be installed): only for allow-list-matched
262
- * candidates with a parseable range. Deduped.
277
+ * Returns the `{depName, range}` pairs whose in-range versions must be looked up (to decide whether
278
+ * a cooldown-respecting install could satisfy the range): only for allow-list-matched candidates
279
+ * with a parseable range. Deduped.
263
280
  */
264
281
  export function getResolveTargets(candidateUsages, allowList) {
265
282
  const targets = new Map();
@@ -280,11 +297,13 @@ export function getResolveTargets(candidateUsages, allowList) {
280
297
  return Array.from(targets.values());
281
298
  }
282
299
  /**
283
- * Pure detection of every direct dependency usage that both matches the allow list and pins a
284
- * version too recent for the min-release-age threshold, paired with the safe version it should be
285
- * temporarily downgraded to.
300
+ * Pure detection of every direct dependency usage that both matches the allow list and whose range
301
+ * _cannot_ be satisfied by an old-enough version (so a cooldown-respecting `npm i` would fail),
302
+ * paired with the safe version it should be temporarily downgraded to (or `undefined` to remove).
303
+ * Deps whose range already has an old-enough version are left alone — `npm i` installs that
304
+ * itself.
286
305
  */
287
- export function computeRecentDepViolators({ candidateUsages, allowList, registryByName, resolvedByRange, threshold, }) {
306
+ export function computeRecentDepViolators({ candidateUsages, allowList, registryByName, inRangeVersionsByRange, threshold, }) {
288
307
  return candidateUsages.flatMap(({ depName, usages }) => {
289
308
  const registry = registryByName.get(depName);
290
309
  if (!registry || !matchesAllowList(allowList, depName)) {
@@ -296,15 +315,23 @@ export function computeRecentDepViolators({ candidateUsages, allowList, registry
296
315
  return [];
297
316
  }
298
317
  const range = `${parsedVersion.prefix}${parsedVersion.version}`;
299
- const resolvedVersion = resolvedByRange.get(depRangeKey(depName, range));
300
- if (!resolvedVersion ||
301
- !isVersionTooRecent(registry.time[resolvedVersion], threshold)) {
318
+ const inRangeVersions = inRangeVersionsByRange.get(depRangeKey(depName, range));
319
+ /**
320
+ * Leave the dep alone when its range matches nothing (a plain install would fail with a
321
+ * clear error of its own) or when some in-range version is old enough (a plain install
322
+ * resolves the range to that version on its own — no downgrade needed).
323
+ */
324
+ if (!inRangeVersions?.length ||
325
+ inRangeVersions.some((version) => isVersionOldEnough(registry.time[version], threshold))) {
302
326
  return [];
303
327
  }
328
+ /**
329
+ * No in-range version is old enough, so a cooldown-respecting install can't satisfy the
330
+ * range. Downgrade to the most recent old-enough version overall, or — when there is no
331
+ * old-enough version at all (a brand-new package) — `undefined`, meaning the dep is
332
+ * temporarily removed for the regen install rather than downgraded.
333
+ */
304
334
  const safeVersion = findMostRecentSafeVersion(registry.time, threshold);
305
- if (!safeVersion) {
306
- return [];
307
- }
308
335
  return [
309
336
  {
310
337
  packageJsonPath: usage.requiredBy,
@@ -325,7 +352,7 @@ export const defaultRecentDepsIo = {
325
352
  loadAllowList,
326
353
  listDirectDeps: listAllDirectNpmDeps,
327
354
  queryRegistry,
328
- queryResolvedVersion,
355
+ queryInRangeVersions,
329
356
  updatePackageJsonVersions,
330
357
  };
331
358
  /**
@@ -360,26 +387,30 @@ export async function prepareRecentDepDowngrades({ monoRepoRootPath, configPath,
360
387
  depName,
361
388
  await io.queryRegistry(depName, monoRepoRootPath),
362
389
  ]));
363
- const resolvedByRange = new Map(await awaitedBlockingMap(resolveTargets, async ({ depName, range }) => [
390
+ const inRangeVersionsByRange = new Map(await awaitedBlockingMap(resolveTargets, async ({ depName, range }) => [
364
391
  depRangeKey(depName, range),
365
- await io.queryResolvedVersion(depName, range, monoRepoRootPath),
392
+ await io.queryInRangeVersions(depName, range, monoRepoRootPath),
366
393
  ]));
367
394
  const violators = computeRecentDepViolators({
368
395
  candidateUsages,
369
396
  allowList,
370
397
  registryByName,
371
- resolvedByRange,
398
+ inRangeVersionsByRange,
372
399
  threshold,
373
400
  });
374
401
  await awaitedBlockingMap(Array.from(groupByPackageJson(violators).entries()), async ([packageJsonPath, packageViolators,]) => {
375
402
  packageViolators.forEach((violator) => {
376
- log.faint(`Temporarily downgrading ${violator.depName} from ${violator.originalVersionValue} to ${violator.versionPrefix}${violator.safeVersion} for regen.`);
403
+ log.faint(violator.safeVersion == undefined
404
+ ? `Temporarily removing ${violator.depName} (no version old enough) for regen.`
405
+ : `Temporarily downgrading ${violator.depName} from ${violator.originalVersionValue} to ${violator.versionPrefix}${violator.safeVersion} for regen.`);
377
406
  });
378
407
  await io.updatePackageJsonVersions(packageJsonPath, packageViolators.map((violator) => {
379
408
  return {
380
409
  dependencyKey: violator.dependencyKey,
381
410
  depName: violator.depName,
382
- version: `${violator.versionPrefix}${violator.safeVersion}`,
411
+ version: violator.safeVersion == undefined
412
+ ? undefined
413
+ : `${violator.versionPrefix}${violator.safeVersion}`,
383
414
  };
384
415
  }));
385
416
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@virmator/deps",
3
- "version": "14.23.0",
3
+ "version": "14.23.1",
4
4
  "description": "Default TS deps plugin for virmator.",
5
5
  "keywords": [
6
6
  "virmator",
@@ -38,7 +38,7 @@
38
38
  "@augment-vir/common": "^31.71.3",
39
39
  "@augment-vir/node": "^31.71.3",
40
40
  "@npm/types": "^2.1.0",
41
- "@virmator/core": "^14.23.0",
41
+ "@virmator/core": "^14.23.1",
42
42
  "date-vir": "^8.3.2",
43
43
  "mri": "^1.2.0"
44
44
  },