UNPKG

3.12 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6
7var _misc;
8
9function _load_misc() {
10 return _misc = require('./util/misc.js');
11}
12
13class PackageReference {
14 constructor(request, info, remote) {
15 this.resolver = request.resolver;
16 this.lockfile = request.lockfile;
17 this.requests = [];
18 this.config = request.config;
19 this.hint = request.hint;
20
21 this.isPlugnplay = false;
22
23 this.registry = remote.registry;
24 this.version = info.version;
25 this.name = info.name;
26 this.uid = info._uid;
27
28 this.remote = remote;
29
30 this.dependencies = [];
31
32 this.permissions = {};
33 this.patterns = [];
34 this.optional = null;
35 this.level = Infinity;
36 this.ignore = false;
37 this.incompatible = false;
38 this.fresh = false;
39 this.locations = [];
40 this.addRequest(request);
41 }
42
43 setFresh(fresh) {
44 this.fresh = fresh;
45 }
46
47 addLocation(loc) {
48 if (this.locations.indexOf(loc) === -1) {
49 this.locations.push(loc);
50 }
51 }
52
53 addRequest(request) {
54 this.requests.push(request);
55
56 this.level = Math.min(this.level, request.parentNames.length);
57 }
58
59 prune() {
60 for (var _iterator = this.patterns, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
61 var _ref;
62
63 if (_isArray) {
64 if (_i >= _iterator.length) break;
65 _ref = _iterator[_i++];
66 } else {
67 _i = _iterator.next();
68 if (_i.done) break;
69 _ref = _i.value;
70 }
71
72 const selfPattern = _ref;
73
74 // remove ourselves from the resolver
75 this.resolver.removePattern(selfPattern);
76 }
77 }
78
79 addDependencies(deps) {
80 this.dependencies = this.dependencies.concat(deps);
81 }
82
83 setPermission(key, val) {
84 this.permissions[key] = val;
85 }
86
87 hasPermission(key) {
88 if (key in this.permissions) {
89 return this.permissions[key];
90 } else {
91 return false;
92 }
93 }
94
95 addPattern(pattern, manifest) {
96 this.resolver.addPattern(pattern, manifest);
97
98 this.patterns.push(pattern);
99
100 const shrunk = this.lockfile.getLocked(pattern);
101 if (shrunk && shrunk.permissions) {
102 for (var _iterator2 = (0, (_misc || _load_misc()).entries)(shrunk.permissions), _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) {
103 var _ref3;
104
105 if (_isArray2) {
106 if (_i2 >= _iterator2.length) break;
107 _ref3 = _iterator2[_i2++];
108 } else {
109 _i2 = _iterator2.next();
110 if (_i2.done) break;
111 _ref3 = _i2.value;
112 }
113
114 const _ref2 = _ref3;
115 const key = _ref2[0];
116 const perm = _ref2[1];
117
118 this.setPermission(key, perm);
119 }
120 }
121 }
122
123 addOptional(optional) {
124 if (this.optional == null) {
125 // optional is uninitialised
126 this.optional = optional;
127 } else if (!optional) {
128 // otherwise, ignore all subsequent optional assignments and only accept ones making
129 // this not optional
130 this.optional = false;
131 }
132 }
133}
134exports.default = PackageReference;
\No newline at end of file