UNPKG

2.44 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.LockfileResolver = void 0;
4const tslib_1 = require("tslib");
5const structUtils = tslib_1.__importStar(require("./structUtils"));
6class LockfileResolver {
7 supportsDescriptor(descriptor, opts) {
8 const resolution = opts.project.storedResolutions.get(descriptor.descriptorHash);
9 if (resolution)
10 return true;
11 // If the descriptor matches a package that's already been used, we can just use it even if we never resolved the range before
12 // Ex: foo depends on bar@^1.0.0 that we resolved to foo@1.1.0, then we add a package qux that depends on foo@1.1.0 (without the caret)
13 if (opts.project.originalPackages.has(structUtils.convertDescriptorToLocator(descriptor).locatorHash))
14 return true;
15 return false;
16 }
17 supportsLocator(locator, opts) {
18 if (opts.project.originalPackages.has(locator.locatorHash))
19 return true;
20 return false;
21 }
22 shouldPersistResolution(locator, opts) {
23 throw new Error(`The shouldPersistResolution method shouldn't be called on the lockfile resolver, which would always answer yes`);
24 }
25 bindDescriptor(descriptor, fromLocator, opts) {
26 return descriptor;
27 }
28 getResolutionDependencies(descriptor, opts) {
29 return [];
30 }
31 async getCandidates(descriptor, dependencies, opts) {
32 let pkg = opts.project.originalPackages.get(structUtils.convertDescriptorToLocator(descriptor).locatorHash);
33 if (pkg)
34 return [pkg];
35 const resolution = opts.project.storedResolutions.get(descriptor.descriptorHash);
36 if (!resolution)
37 throw new Error(`Expected the resolution to have been successful - resolution not found`);
38 pkg = opts.project.originalPackages.get(resolution);
39 if (!pkg)
40 throw new Error(`Expected the resolution to have been successful - package not found`);
41 return [pkg];
42 }
43 async getSatisfying(descriptor, references, opts) {
44 return null;
45 }
46 async resolve(locator, opts) {
47 const pkg = opts.project.originalPackages.get(locator.locatorHash);
48 if (!pkg)
49 throw new Error(`The lockfile resolver isn't meant to resolve packages - they should already have been stored into a cache`);
50 return pkg;
51 }
52}
53exports.LockfileResolver = LockfileResolver;