@pnpm/lockfile.preferred-versions 1000.0.32 → 1100.0.0

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/lib/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import { type PackageSnapshots } from '@pnpm/lockfile.utils';
2
- import { type PreferredVersions } from '@pnpm/resolver-base';
3
- import { type DependencyManifest, type ProjectManifest } from '@pnpm/types';
2
+ import { type PreferredVersions } from '@pnpm/resolving.resolver-base';
3
+ import type { DependencyManifest, ProjectManifest } from '@pnpm/types';
4
4
  export declare function getPreferredVersionsFromLockfileAndManifests(snapshots: PackageSnapshots | undefined, manifests: Array<DependencyManifest | ProjectManifest>): PreferredVersions;
package/lib/index.js CHANGED
@@ -1,25 +1,19 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getPreferredVersionsFromLockfileAndManifests = getPreferredVersionsFromLockfileAndManifests;
7
- const lockfile_utils_1 = require("@pnpm/lockfile.utils");
8
- const manifest_utils_1 = require("@pnpm/manifest-utils");
9
- const resolver_base_1 = require("@pnpm/resolver-base");
10
- const version_selector_type_1 = __importDefault(require("version-selector-type"));
11
- function getPreferredVersionsFromLockfileAndManifests(snapshots, manifests) {
1
+ import { nameVerFromPkgSnapshot } from '@pnpm/lockfile.utils';
2
+ import { getAllDependenciesFromManifest } from '@pnpm/pkg-manifest.utils';
3
+ import { DIRECT_DEP_SELECTOR_WEIGHT, EXISTING_VERSION_SELECTOR_WEIGHT, } from '@pnpm/resolving.resolver-base';
4
+ import getVersionSelectorType from 'version-selector-type';
5
+ export function getPreferredVersionsFromLockfileAndManifests(snapshots, manifests) {
12
6
  const preferredVersions = {};
13
7
  for (const manifest of manifests) {
14
- const specs = (0, manifest_utils_1.getAllDependenciesFromManifest)(manifest);
8
+ const specs = getAllDependenciesFromManifest(manifest);
15
9
  for (const [name, spec] of Object.entries(specs)) {
16
- const selector = (0, version_selector_type_1.default)(spec);
10
+ const selector = getVersionSelectorType(spec);
17
11
  if (!selector)
18
12
  continue;
19
13
  preferredVersions[name] = preferredVersions[name] ?? {};
20
14
  preferredVersions[name][spec] = {
21
15
  selectorType: selector.type,
22
- weight: resolver_base_1.DIRECT_DEP_SELECTOR_WEIGHT,
16
+ weight: DIRECT_DEP_SELECTOR_WEIGHT,
23
17
  };
24
18
  }
25
19
  }
@@ -29,14 +23,46 @@ function getPreferredVersionsFromLockfileAndManifests(snapshots, manifests) {
29
23
  return preferredVersions;
30
24
  }
31
25
  function addPreferredVersionsFromLockfile(snapshots, preferredVersions) {
26
+ // The snapshots object can contain multiple entries with the same package
27
+ // name and version. This is because a dependency can appear multiple times
28
+ // with the same version in the lockfile due to peer dependency resolution. To
29
+ // avoid inflating the weight of package versions that appear multiple times,
30
+ // generate a map with only the unique set to iterate over.
31
+ const uniqueNameVersions = {};
32
32
  for (const [depPath, snapshot] of Object.entries(snapshots)) {
33
- const { name, version } = (0, lockfile_utils_1.nameVerFromPkgSnapshot)(depPath, snapshot);
34
- if (!preferredVersions[name]) {
35
- preferredVersions[name] = { [version]: 'version' };
36
- }
37
- else if (!preferredVersions[name][version]) {
38
- preferredVersions[name][version] = 'version';
33
+ const { name, version } = nameVerFromPkgSnapshot(depPath, snapshot);
34
+ uniqueNameVersions[name] ??= new Set();
35
+ uniqueNameVersions[name].add(version);
36
+ }
37
+ for (const [name, versions] of Object.entries(uniqueNameVersions)) {
38
+ for (const version of versions) {
39
+ preferredVersions[name] ??= {};
40
+ const existingSelector = preferredVersions[name][version];
41
+ if (existingSelector == null) {
42
+ preferredVersions[name][version] = { selectorType: 'version', weight: EXISTING_VERSION_SELECTOR_WEIGHT };
43
+ continue;
44
+ }
45
+ // The lookup for this selector was for an exact version and not a range
46
+ // or tag. If there's an existing selector and it's not for a version,
47
+ // that's unexpected and our program state is corrupted.
48
+ const existingSelectorType = typeof existingSelector === 'string'
49
+ ? existingSelector
50
+ : existingSelector.selectorType;
51
+ if (existingSelectorType !== 'version') {
52
+ throw new Error(`Encountered unexpected version selector '${existingSelectorType}' for dependency '${name}@${version}'`);
53
+ }
54
+ // There might be an existing selector on this exact version from a direct
55
+ // dependency. If so, we should increase its weight. This allows a version
56
+ // present in the lockfile that's also used by a direct dependency to be
57
+ // considered at a higher priority than a package with only one of the two
58
+ // criteria.
59
+ preferredVersions[name][version] = addWeightToVersionSelector(existingSelector, EXISTING_VERSION_SELECTOR_WEIGHT);
39
60
  }
40
61
  }
41
62
  }
63
+ function addWeightToVersionSelector(selector, weight) {
64
+ return typeof selector === 'string'
65
+ ? { selectorType: selector, weight: weight + 1 }
66
+ : { selectorType: selector.selectorType, weight: selector.weight + weight };
67
+ }
42
68
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@pnpm/lockfile.preferred-versions",
3
- "version": "1000.0.32",
3
+ "version": "1100.0.0",
4
4
  "description": "Get preferred version from lockfile",
5
5
  "keywords": [
6
6
  "pnpm",
7
- "pnpm10",
7
+ "pnpm11",
8
8
  "lockfile",
9
9
  "shrinkwrap"
10
10
  ],
@@ -15,7 +15,7 @@
15
15
  "bugs": {
16
16
  "url": "https://github.com/pnpm/pnpm/issues"
17
17
  },
18
- "type": "commonjs",
18
+ "type": "module",
19
19
  "main": "lib/index.js",
20
20
  "types": "lib/index.d.ts",
21
21
  "exports": {
@@ -27,23 +27,23 @@
27
27
  ],
28
28
  "dependencies": {
29
29
  "version-selector-type": "^3.0.0",
30
- "@pnpm/lockfile.utils": "1004.0.3",
31
- "@pnpm/manifest-utils": "1002.0.5",
32
- "@pnpm/resolver-base": "1005.4.1",
33
- "@pnpm/types": "1001.3.0"
30
+ "@pnpm/lockfile.utils": "1100.0.0",
31
+ "@pnpm/pkg-manifest.utils": "1100.0.0",
32
+ "@pnpm/types": "1100.0.0",
33
+ "@pnpm/resolving.resolver-base": "1100.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@pnpm/lockfile.preferred-versions": "1000.0.32"
36
+ "@pnpm/lockfile.preferred-versions": "1100.0.0"
37
37
  },
38
38
  "engines": {
39
- "node": ">=18.12"
39
+ "node": ">=22.13"
40
40
  },
41
41
  "jest": {
42
42
  "preset": "@pnpm/jest-config"
43
43
  },
44
44
  "scripts": {
45
45
  "lint": "eslint \"src/**/*.ts\"",
46
- "test": "pnpm run compile",
47
- "compile": "tsc --build && pnpm run lint --fix"
46
+ "test": "pn compile",
47
+ "compile": "tsgo --build && pn lint --fix"
48
48
  }
49
49
  }
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAMA,oGAoBC;AA1BD,yDAAoF;AACpF,yDAAqE;AACrE,uDAAwF;AAExF,kFAA0D;AAE1D,SAAgB,4CAA4C,CAC1D,SAAuC,EACvC,SAAsD;IAEtD,MAAM,iBAAiB,GAAsB,EAAE,CAAA;IAC/C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;QACjC,MAAM,KAAK,GAAG,IAAA,+CAA8B,EAAC,QAAQ,CAAC,CAAA;QACtD,KAAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YACjD,MAAM,QAAQ,GAAG,IAAA,+BAAsB,EAAC,IAAI,CAAC,CAAA;YAC7C,IAAI,CAAC,QAAQ;gBAAE,SAAQ;YACvB,iBAAiB,CAAC,IAAI,CAAC,GAAG,iBAAiB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAA;YACvD,iBAAiB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG;gBAC9B,YAAY,EAAE,QAAQ,CAAC,IAAI;gBAC3B,MAAM,EAAE,0CAA0B;aACnC,CAAA;QACH,CAAC;IACH,CAAC;IACD,IAA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