@pnpm/lockfile.preferred-versions 0.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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2016 Rico Sta. Cruz and other contributors
4
+ Copyright (c) 2016-2024 Zoltan Kochan and other contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @pnpm/lockfile.preferred-versions
2
+
3
+ > Get preferred version from lockfile
4
+
5
+ ## Install
6
+
7
+ ```
8
+ pnpm add @pnpm/lockfile.preferred-versions
9
+ ```
10
+
11
+ ## License
12
+
13
+ [MIT](LICENSE)
package/lib/index.d.ts ADDED
@@ -0,0 +1,4 @@
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';
4
+ export declare function getPreferredVersionsFromLockfileAndManifests(snapshots: PackageSnapshots | undefined, manifests: Array<DependencyManifest | ProjectManifest>): PreferredVersions;
package/lib/index.js ADDED
@@ -0,0 +1,43 @@
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 = void 0;
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) {
12
+ const preferredVersions = {};
13
+ for (const manifest of manifests) {
14
+ const specs = (0, manifest_utils_1.getAllDependenciesFromManifest)(manifest);
15
+ for (const [name, spec] of Object.entries(specs)) {
16
+ const selector = (0, version_selector_type_1.default)(spec);
17
+ if (!selector)
18
+ continue;
19
+ preferredVersions[name] = preferredVersions[name] ?? {};
20
+ preferredVersions[name][spec] = {
21
+ selectorType: selector.type,
22
+ weight: resolver_base_1.DIRECT_DEP_SELECTOR_WEIGHT,
23
+ };
24
+ }
25
+ }
26
+ if (!snapshots)
27
+ return preferredVersions;
28
+ addPreferredVersionsFromLockfile(snapshots, preferredVersions);
29
+ return preferredVersions;
30
+ }
31
+ exports.getPreferredVersionsFromLockfileAndManifests = getPreferredVersionsFromLockfileAndManifests;
32
+ function addPreferredVersionsFromLockfile(snapshots, preferredVersions) {
33
+ for (const [depPath, snapshot] of Object.entries(snapshots)) {
34
+ const { name, version } = (0, lockfile_utils_1.nameVerFromPkgSnapshot)(depPath, snapshot);
35
+ if (!preferredVersions[name]) {
36
+ preferredVersions[name] = { [version]: 'version' };
37
+ }
38
+ else if (!preferredVersions[name][version]) {
39
+ preferredVersions[name][version] = 'version';
40
+ }
41
+ }
42
+ }
43
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,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,IAAI,CAAC,SAAS;QAAE,OAAO,iBAAiB,CAAA;IACxC,gCAAgC,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAA;IAC9D,OAAO,iBAAiB,CAAA;AAC1B,CAAC;AApBD,oGAoBC;AAED,SAAS,gCAAgC,CAAE,SAA2B,EAAE,iBAAoC;IAC1G,KAAK,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5D,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,IAAA,uCAAsB,EAAC,OAAO,EAAE,QAAQ,CAAC,CAAA;QACnE,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,iBAAiB,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,SAAS,EAAE,CAAA;QACpD,CAAC;aAAM,IAAI,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,iBAAiB,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,SAAS,CAAA;QAC9C,CAAC;IACH,CAAC;AACH,CAAC"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@pnpm/lockfile.preferred-versions",
3
+ "version": "0.0.0",
4
+ "description": "Get preferred version from lockfile",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "engines": {
8
+ "node": ">=18.12"
9
+ },
10
+ "files": [
11
+ "lib",
12
+ "!*.map"
13
+ ],
14
+ "repository": "https://github.com/pnpm/pnpm/blob/main/lockfile/preferred-versions",
15
+ "keywords": [
16
+ "pnpm9",
17
+ "pnpm",
18
+ "shrinkwrap",
19
+ "lockfile"
20
+ ],
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/pnpm/pnpm/issues"
24
+ },
25
+ "homepage": "https://github.com/pnpm/pnpm/blob/main/lockfile/preferred-versions#readme",
26
+ "devDependencies": {
27
+ "@pnpm/lockfile.preferred-versions": "0.0.0"
28
+ },
29
+ "dependencies": {
30
+ "version-selector-type": "^3.0.0",
31
+ "@pnpm/lockfile-utils": "9.0.5",
32
+ "@pnpm/manifest-utils": "5.0.7",
33
+ "@pnpm/resolver-base": "11.1.0",
34
+ "@pnpm/types": "9.4.2"
35
+ },
36
+ "funding": "https://opencollective.com/pnpm",
37
+ "exports": {
38
+ ".": "./lib/index.js"
39
+ },
40
+ "scripts": {
41
+ "lint": "eslint \"src/**/*.ts\"",
42
+ "test": "pnpm run compile",
43
+ "compile": "tsc --build && pnpm run lint --fix"
44
+ }
45
+ }