@vltpkg/pick-manifest 1.3.4 → 1.3.6

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.
Files changed (2) hide show
  1. package/dist/index.js +22 -5
  2. package/package.json +5 -5
package/dist/index.js CHANGED
@@ -4,6 +4,19 @@ import { Spec } from '@vltpkg/spec';
4
4
  import { isSpec } from '@vltpkg/spec/browser';
5
5
  import { readFileSync } from 'node:fs';
6
6
  const parsedNodeVersion = Version.parse(process.version);
7
+ // Parsed versions by string, so each is parsed once across picks.
8
+ const versionCache = new Map();
9
+ const MAX_VERSION_CACHE = 32_768;
10
+ const parsedVersion = (ver) => {
11
+ const cached = versionCache.get(ver);
12
+ if (cached !== undefined || versionCache.has(ver))
13
+ return cached;
14
+ const parsed = parse(ver);
15
+ if (versionCache.size >= MAX_VERSION_CACHE)
16
+ versionCache.clear();
17
+ versionCache.set(ver, parsed);
18
+ return parsed;
19
+ };
7
20
  const isBefore = (version, before, verTimes) => {
8
21
  if (!verTimes || !version || !before)
9
22
  return true;
@@ -240,17 +253,21 @@ export function pickManifest(packument, wanted, opts = {}) {
240
253
  return versions[defaultVer];
241
254
  }
242
255
  // ok, actually have to scan the list
243
- const entries = Object.entries(versions);
244
- if (!entries.length) {
256
+ const keys = Object.keys(versions);
257
+ if (!keys.length) {
245
258
  return undefined;
246
259
  }
247
260
  let found = undefined;
248
261
  let foundIsDefTag = false;
249
- for (const [ver, mani] of entries) {
250
- if (time && verTimes && !isBefore(ver, time, verTimes)) {
262
+ for (const ver of keys) {
263
+ // skip versions the time map leaves out, and with a cutoff, those
264
+ // published after it
265
+ if (verTimes &&
266
+ (before ? !isBefore(ver, time, verTimes) : !verTimes[ver])) {
251
267
  continue;
252
268
  }
253
- const version = parse(ver);
269
+ const mani = versions[ver];
270
+ const version = parsedVersion(ver);
254
271
  if (!version?.satisfies(range)) {
255
272
  continue;
256
273
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/pick-manifest",
3
3
  "description": "Choose a manifest from a packument",
4
- "version": "1.3.4",
4
+ "version": "1.3.6",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,10 +13,10 @@
13
13
  "url": "http://vlt.sh"
14
14
  },
15
15
  "dependencies": {
16
- "@vltpkg/error-cause": "1.3.4",
17
- "@vltpkg/semver": "1.3.4",
18
- "@vltpkg/spec": "1.3.4",
19
- "@vltpkg/types": "1.3.4"
16
+ "@vltpkg/error-cause": "1.3.6",
17
+ "@vltpkg/semver": "1.3.6",
18
+ "@vltpkg/spec": "1.3.6",
19
+ "@vltpkg/types": "1.3.6"
20
20
  },
21
21
  "devDependencies": {
22
22
  "@eslint/js": "^9.39.1",