occam-verify-cli 0.0.706 → 0.0.708

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.
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+
3
+ import { last } from "../utilities/array";
4
+
5
+ export default function createReleaseContext(dependency, dependentNames, context, callback) {
6
+ const { log, releaseContextMap } = context,
7
+ dependencyName = dependency.getName(),
8
+ releaseName = dependencyName, ///
9
+ releaseContext = releaseContextMap[releaseName] || null;
10
+
11
+ if (releaseContext !== null) {
12
+ const error = null;
13
+
14
+ callback(error);
15
+
16
+ return;
17
+ }
18
+
19
+ const dependencyString = dependency.asString();
20
+
21
+ log.info(`Creating the '${releaseName}' context from the '${dependencyString}' dependency...`)
22
+
23
+ const { releaseContextFromDependency } = context;
24
+
25
+ releaseContextFromDependency(dependency, context, (error, releaseContext) => {
26
+ if (error) {
27
+ callback(error);
28
+
29
+ return;
30
+ }
31
+
32
+ const releaseContextCreated = checkReleaseContextCreated(releaseContext, dependency, context);
33
+
34
+ if (!releaseContextCreated) {
35
+ const error = null;
36
+
37
+ callback(error);
38
+
39
+ return;
40
+ }
41
+
42
+ const releaseMatchesDependency = checkReleaseMatchesDependency(releaseContext, dependency, dependentNames, context);
43
+
44
+ if (!releaseMatchesDependency) {
45
+ const error = null;
46
+
47
+ callback(error);
48
+
49
+ return;
50
+ }
51
+
52
+ releaseContextMap[releaseName] = releaseContext;
53
+
54
+ createDependencyReleaseContexts(dependency, dependentNames, context, callback);
55
+
56
+ log.info(`...creating the '${releaseName}' context.`)
57
+ }, context);
58
+ }
59
+
60
+ function checkReleaseContextCreated(releaseContext, dependency, context) {
61
+ const releaseContextCreated = (releaseContext !== null);
62
+
63
+ if (!releaseContextCreated) {
64
+ const { log } = context,
65
+ dependencyName = dependency.getName(),
66
+ releaseName = dependencyName; ///
67
+
68
+ log.error(`The '${releaseName}' context could not be created.`);
69
+ }
70
+
71
+ return releaseContextCreated;
72
+ }
73
+
74
+ function checkCyclicDependencyExists(dependency, dependentNames, context) {
75
+ const dependencyName = dependency.getName(),
76
+ dependentNamesIncludesDependencyName = dependentNames.includes(dependencyName),
77
+ cyclicDependencyExists = dependentNamesIncludesDependencyName; ///
78
+
79
+ if (cyclicDependencyExists) {
80
+ const { log } = context,
81
+ firstDependentName = first(dependentNames),
82
+ dependencyNames = [ ///
83
+ ...dependentNames,
84
+ firstDependentName
85
+ ],
86
+ dependencyNamesString = dependencyNames.join(`' -> '`);
87
+
88
+ log.error(`There is a cyclic dependency: '${dependencyNamesString}'.`);
89
+ }
90
+
91
+ return cyclicDependencyExists;
92
+ }
93
+
94
+ function checkReleaseMatchesDependency(releaseContext, dependency, dependentNames, context) {
95
+ let releaseMatchesDependency = true;
96
+
97
+ const entries = releaseContext.getEntries(),
98
+ shortenedVersion = dependency.getShortedVersion();
99
+
100
+ if (shortenedVersion !== null) {
101
+ const entriesMatchShortenedVersion = entries.matchShortenedVersion(shortenedVersion);
102
+
103
+ if (!entriesMatchShortenedVersion) {
104
+ const { log } = context,
105
+ version = releaseContext.getVersion(),
106
+ versionString = version.toString(),
107
+ lastDependentName = last(dependentNames),
108
+ dependentName = lastDependentName, ///
109
+ dependencyName = dependency.getName(),
110
+ shortenedVersion = dependency.getShortedVersion(),
111
+ shortenedVersionString = shortenedVersion.toString();
112
+
113
+ log.error(`Version mismatch: '${dependentName}' requires '${dependencyName}' to be version ${shortenedVersionString}.0 or higher but version ${versionString} has been supplied.`);
114
+
115
+ releaseMatchesDependency = false;
116
+ }
117
+ }
118
+
119
+ return releaseMatchesDependency;
120
+ }
121
+
122
+ function createDependencyReleaseContexts(dependency, dependentNames, context, callback) {
123
+ const { releaseContextMap } = context,
124
+ dependencyName = dependency.getName(),
125
+ releaseName = dependencyName, ///
126
+ releaseContext = releaseContextMap[releaseName],
127
+ dependencies = releaseContext.getDependencies();
128
+
129
+ dependentNames = [ ...dependentNames, dependencyName ]; ///
130
+
131
+ dependencies.asynchronousForEachDependency((dependency, next, done) => {
132
+ const cyclicDependencyExists = checkCyclicDependencyExists(dependency, dependentNames);
133
+
134
+ if (cyclicDependencyExists) {
135
+ const error = null;
136
+
137
+ callback(error);
138
+
139
+ return;
140
+ }
141
+
142
+ createReleaseContext(dependency, dependentNames, context, (error) => {
143
+ if (error) {
144
+ callback(error);
145
+
146
+ return;
147
+ }
148
+
149
+ next();
150
+ });
151
+ }, done);
152
+
153
+ function done() {
154
+ const error = null;
155
+
156
+ callback(error);
157
+ }
158
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ export default function initialiseReleaseContext(dependency, dependentName, dependentReleased, context) {
4
+ let releaseContextInitialised = false;
5
+
6
+ const { releaseContextMap } = context,
7
+ dependencyName = dependency.getName(),
8
+ releaseName = dependencyName, ///
9
+ releaseContext = releaseContextMap[releaseName] || null;
10
+
11
+ if (releaseContext === null) {
12
+ const { log } = context;
13
+
14
+ log.error(`Unable to initialise the '${dependencyName}' dependency's context because it has not been created.`);
15
+ } else {
16
+ const initialised = releaseContext.isInitialised();
17
+
18
+ if (initialised) {
19
+ releaseContextInitialised = true;
20
+ } else {
21
+ const released = releaseContext.isReleased();
22
+
23
+ if (!released && dependentReleased) {
24
+ const { log } = context;
25
+
26
+ log.error(`Unable to initialise the '${dependencyName}' dependency's context because its '${dependentName}' dependent is a package.`);
27
+ } else {
28
+ const dependencies = releaseContext.getDependencies();
29
+
30
+ dependentName = dependencyName; ///
31
+
32
+ dependentReleased = released; ///
33
+
34
+ releaseContextInitialised = dependencies.everyDependency((dependency) => { ///
35
+ const releaseContextInitialised = initialiseReleaseContext(dependency, dependentName, dependentReleased, context);
36
+
37
+ if (releaseContextInitialised) {
38
+ return true;
39
+ }
40
+ });
41
+
42
+ if (releaseContextInitialised) {
43
+ const releaseContexts = retrieveReleaseContexts(releaseContext, releaseContextMap);
44
+
45
+ releaseContext.initialise(releaseContexts);
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ return releaseContextInitialised;
52
+ }
53
+
54
+ function retrieveReleaseContexts(releaseContext, releaseContextMap) {
55
+ const releaseContexts = [],
56
+ remainingReleaseContext = releaseContext, ///
57
+ remainingReleaseContexts = [
58
+ remainingReleaseContext
59
+ ];
60
+
61
+ let remainingReleaseContextsLength = remainingReleaseContexts.length;
62
+
63
+ while (remainingReleaseContextsLength > 0) {
64
+ const remainingReleaseContext = remainingReleaseContexts.shift(),
65
+ releaseContext = remainingReleaseContext; ///
66
+
67
+ releaseContexts.push(releaseContext);
68
+
69
+ const dependencies = releaseContext.getDependencies();
70
+
71
+ dependencies.forEachDependency((dependency) => {
72
+ const dependencyName = dependency.getName(),
73
+ releaseName = dependencyName, ///
74
+ releaseContext = releaseContextMap[releaseName],
75
+ releaseContextsIncludesReleaseContext = releaseContexts.includes(releaseContext),
76
+ remainingReleaseContextsIncludesReleaseContext = remainingReleaseContexts.includes(releaseContext);
77
+
78
+ if (!releaseContextsIncludesReleaseContext && !remainingReleaseContextsIncludesReleaseContext) {
79
+ const remainingReleaseContext = releaseContext; ///
80
+
81
+ remainingReleaseContexts.push(remainingReleaseContext);
82
+ }
83
+ });
84
+
85
+ remainingReleaseContextsLength = remainingReleaseContexts.length;
86
+ }
87
+
88
+ return releaseContexts;
89
+ }
@@ -1,181 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- createReleaseContext: function() {
13
- return createReleaseContext;
14
- },
15
- default: function() {
16
- return _default;
17
- },
18
- initialiseReleaseContext: function() {
19
- return initialiseReleaseContext;
20
- }
21
- });
22
- var _array = require("../utilities/array");
23
- function _array_like_to_array(arr, len) {
24
- if (len == null || len > arr.length) len = arr.length;
25
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
26
- return arr2;
27
- }
28
- function _array_without_holes(arr) {
29
- if (Array.isArray(arr)) return _array_like_to_array(arr);
30
- }
31
- function _iterable_to_array(iter) {
32
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
33
- }
34
- function _non_iterable_spread() {
35
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
36
- }
37
- function _to_consumable_array(arr) {
38
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
39
- }
40
- function _unsupported_iterable_to_array(o, minLen) {
41
- if (!o) return;
42
- if (typeof o === "string") return _array_like_to_array(o, minLen);
43
- var n = Object.prototype.toString.call(o).slice(8, -1);
44
- if (n === "Object" && o.constructor) n = o.constructor.name;
45
- if (n === "Map" || n === "Set") return Array.from(n);
46
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
47
- }
48
- function createReleaseContext(dependency, dependentNames, context, callback) {
49
- var releaseContextMap = context.releaseContextMap, dependencyName = dependency.getName(), releaseName = dependencyName, releaseContext = releaseContextMap[releaseName] || null;
50
- if (releaseContext !== null) {
51
- var error = checkReleaseMatchesDependency(dependency, dependentNames, releaseContext);
52
- callback(error);
53
- return;
54
- }
55
- var releaseContextFromDependency = context.releaseContextFromDependency;
56
- releaseContextFromDependency(dependency, context, function(error, releaseContext) {
57
- if (error) {
58
- callback(error);
59
- return;
60
- }
61
- if (releaseContext === null) {
62
- var _$error = "The '".concat(releaseName, "' package could not be created.");
63
- callback(_$error);
64
- return;
65
- }
66
- error = checkReleaseMatchesDependency(dependency, dependentNames, releaseContext);
67
- if (error) {
68
- callback(error);
69
- return;
70
- }
71
- releaseContextMap[releaseName] = releaseContext;
72
- createDependencyReleaseContexts(dependency, dependentNames, context, callback);
73
- }, context);
74
- }
75
- function initialiseReleaseContext(dependency, dependentName, dependentReleased, context, callback) {
76
- var error = null;
77
- var releaseContextMap = context.releaseContextMap, name = dependency.getName(), releaseName = name, releaseContext = releaseContextMap[releaseName] || null;
78
- if (releaseContext === null) {
79
- callback(error);
80
- return;
81
- }
82
- var released = releaseContext.isReleased(), initialised = releaseContext.isInitialised();
83
- if (initialised) {
84
- callback(error);
85
- return;
86
- }
87
- if (!released) {
88
- if (dependentReleased) {
89
- error = "Unable to initialise the '".concat(name, "' dependency's context because its '").concat(dependentName, "' dependent is a package.");
90
- callback(error);
91
- return;
92
- }
93
- }
94
- dependentName = name; ///
95
- dependentReleased = released; ///
96
- var dependencies = releaseContext.getDependencies();
97
- dependencies.asynchronousForEachDependency(function(dependency, next, done) {
98
- initialiseReleaseContext(dependency, dependentName, dependentReleased, context, function(error) {
99
- if (error) {
100
- callback(error);
101
- return;
102
- }
103
- next();
104
- });
105
- }, done);
106
- function done() {
107
- var dependencyReleaseContexts = retrieveDependencyReleaseContexts(dependency, context);
108
- releaseContext.initialise(dependencyReleaseContexts);
109
- callback(error);
110
- }
111
- }
112
- var _default = {
113
- createReleaseContext: createReleaseContext,
114
- initialiseReleaseContext: initialiseReleaseContext
115
- };
116
- function checkCyclicDependencyExists(dependency, dependentNames) {
117
- var error = null;
118
- var dependencyName = dependency.getName(), dependentNamesIncludesDependencyName = dependentNames.includes(dependencyName), cyclicDependencyExists = dependentNamesIncludesDependencyName; ///
119
- if (cyclicDependencyExists) {
120
- var firstDependentName = first(dependentNames), dependencyNames = _to_consumable_array(dependentNames).concat([
121
- firstDependentName
122
- ]), dependencyNamesString = dependencyNames.join("' -> '");
123
- error = "There is a cyclic dependency: '".concat(dependencyNamesString, "'.");
124
- }
125
- return error;
126
- }
127
- function checkReleaseMatchesDependency(dependency, dependentNames, releaseContext) {
128
- var error = null;
129
- var entries = releaseContext.getEntries(), shortenedVersion = dependency.getShortedVersion();
130
- if (shortenedVersion !== null) {
131
- var entriesMatchShortenedVersion = entries.matchShortenedVersion(shortenedVersion);
132
- if (!entriesMatchShortenedVersion) {
133
- var version = releaseContext.getVersion(), versionString = version.toString(), lastDependentName = (0, _array.last)(dependentNames), dependentName = lastDependentName, dependencyName = dependency.getName(), shortenedVersion1 = dependency.getShortedVersion(), shortenedVersionString = shortenedVersion1.toString();
134
- error = "Version mismatch: '".concat(dependentName, "' requires '").concat(dependencyName, "' to be version ").concat(shortenedVersionString, ".0 or higher but version ").concat(versionString, " has been supplied.");
135
- }
136
- }
137
- return error;
138
- }
139
- function createDependencyReleaseContexts(dependency, dependentNames, context, callback) {
140
- var releaseContextMap = context.releaseContextMap, dependencyName = dependency.getName(), releaseName = dependencyName, releaseContext = releaseContextMap[releaseName], dependencies = releaseContext.getDependencies();
141
- dependentNames = _to_consumable_array(dependentNames).concat([
142
- dependencyName
143
- ]); ///
144
- dependencies.asynchronousForEachDependency(function(dependency, next, done) {
145
- var error = checkCyclicDependencyExists(dependency, dependentNames);
146
- if (error) {
147
- callback(error);
148
- return;
149
- }
150
- createReleaseContext(dependency, dependentNames, context, function(error) {
151
- if (error) {
152
- callback(error);
153
- return;
154
- }
155
- next();
156
- });
157
- }, done);
158
- function done() {
159
- var error = null;
160
- callback(error);
161
- }
162
- }
163
- function retrieveDependencyReleaseContexts(dependency, context) {
164
- var dependencyReleaseContexts = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
165
- var releaseContextMap = context.releaseContextMap, dependencyName = dependency.getName(), releaseName = dependencyName, releaseContext = releaseContextMap[releaseName], dependencies = releaseContext.getDependencies();
166
- dependencies.forEachDependency(function(dependency) {
167
- var dependencyName = dependency.getName(), releaseName = dependencyName, releaseContext = releaseContextMap[releaseName] || null;
168
- if (releaseContext === null) {
169
- return;
170
- }
171
- var dependencyReleaseContextsIncludesReleaseContext = dependencyReleaseContexts.includes(releaseContext);
172
- if (dependencyReleaseContextsIncludesReleaseContext) {
173
- return;
174
- }
175
- retrieveDependencyReleaseContexts(dependency, context, dependencyReleaseContexts);
176
- dependencyReleaseContexts.push(releaseContext);
177
- });
178
- return dependencyReleaseContexts;
179
- }
180
-
181
- //# sourceMapp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TSxBQUFFckIsb0JBQXNCRixRQUF0QkUsbUJBQ0ZDLGlCQUFpQkwsV0FBV00sT0FBTyxJQUNuQ0MsY0FBY0YsZ0JBQ2RHLGlCQUFpQkosaUJBQWlCLENBQUNHLFlBQVksRUFDL0NhLGVBQWVaLGVBQWVhLGVBQWU7SUFFbkRELGFBQWE4QixpQkFBaUIsQ0FBQyxTQUFDbEQ7UUFDOUIsSUFBTUssaUJBQWlCTCxXQUFXTSxPQUFPLElBQ25DQyxjQUFjRixnQkFDZEcsaUJBQWlCSixpQkFBaUIsQ0FBQ0csWUFBWSxJQUFJO1FBRXpELElBQUlDLG1CQUFtQixNQUFNO1lBQzNCO1FBQ0Y7UUFFQSxJQUFNMkMsa0RBQWtEMUIsMEJBQTBCSyxRQUFRLENBQUN0QjtRQUUzRixJQUFJMkMsaURBQWlEO1lBQ25EO1FBQ0Y7UUFFQXpCLGtDQUFrQzFCLFlBQVlFLFNBQVN1QjtRQUV2REEsMEJBQTBCMkIsSUFBSSxDQUFDNUM7SUFDakM7SUFFQSxPQUFPaUI7QUFDVCJ9
@@ -1,225 +0,0 @@
1
- "use strict";
2
-
3
- import { last } from "../utilities/array";
4
-
5
- export function createReleaseContext(dependency, dependentNames, context, callback) {
6
- const { releaseContextMap } = context,
7
- dependencyName = dependency.getName(),
8
- releaseName = dependencyName, ///
9
- releaseContext = releaseContextMap[releaseName] || null;
10
-
11
- if (releaseContext !== null) {
12
- const error = checkReleaseMatchesDependency(dependency, dependentNames, releaseContext);
13
-
14
- callback(error);
15
-
16
- return;
17
- }
18
-
19
- const { releaseContextFromDependency } = context;
20
-
21
- releaseContextFromDependency(dependency, context, (error, releaseContext) => {
22
- if (error) {
23
- callback(error);
24
-
25
- return;
26
- }
27
-
28
- if (releaseContext === null) {
29
- const error = `The '${releaseName}' package could not be created.`;
30
-
31
- callback(error);
32
-
33
- return;
34
- }
35
-
36
- error = checkReleaseMatchesDependency(dependency, dependentNames, releaseContext);
37
-
38
- if (error) {
39
- callback(error);
40
-
41
- return;
42
- }
43
-
44
- releaseContextMap[releaseName] = releaseContext;
45
-
46
- createDependencyReleaseContexts(dependency, dependentNames, context, callback);
47
- }, context);
48
- }
49
-
50
- export function initialiseReleaseContext(dependency, dependentName, dependentReleased, context, callback) {
51
- let error = null;
52
-
53
- const { releaseContextMap } = context,
54
- name = dependency.getName(),
55
- releaseName = name, ///
56
- releaseContext = releaseContextMap[releaseName] || null;
57
-
58
- if (releaseContext === null) {
59
- callback(error);
60
-
61
- return;
62
- }
63
-
64
- const released = releaseContext.isReleased(),
65
- initialised = releaseContext.isInitialised();
66
-
67
- if (initialised) {
68
- callback(error);
69
-
70
- return;
71
- }
72
-
73
- if (!released) {
74
- if (dependentReleased) {
75
- error = `Unable to initialise the '${name}' dependency's context because its '${dependentName}' dependent is a package.`;
76
-
77
- callback(error);
78
-
79
- return;
80
- }
81
- }
82
-
83
- dependentName = name; ///
84
-
85
- dependentReleased = released; ///
86
-
87
- const dependencies = releaseContext.getDependencies();
88
-
89
- dependencies.asynchronousForEachDependency((dependency, next, done) => {
90
- initialiseReleaseContext(dependency, dependentName, dependentReleased, context, (error) => {
91
- if (error) {
92
- callback(error);
93
-
94
- return;
95
- }
96
-
97
- next();
98
- });
99
- }, done);
100
-
101
- function done() {
102
- const dependencyReleaseContexts = retrieveDependencyReleaseContexts(dependency, context);
103
-
104
- releaseContext.initialise(dependencyReleaseContexts);
105
-
106
- callback(error);
107
- }
108
- }
109
-
110
- export default {
111
- createReleaseContext,
112
- initialiseReleaseContext
113
- };
114
-
115
- function checkCyclicDependencyExists(dependency, dependentNames) {
116
- let error = null;
117
-
118
- const dependencyName = dependency.getName(),
119
- dependentNamesIncludesDependencyName = dependentNames.includes(dependencyName),
120
- cyclicDependencyExists = dependentNamesIncludesDependencyName; ///
121
-
122
- if (cyclicDependencyExists) {
123
- const firstDependentName = first(dependentNames),
124
- dependencyNames = [ ///
125
- ...dependentNames,
126
- firstDependentName
127
- ],
128
- dependencyNamesString = dependencyNames.join(`' -> '`);
129
-
130
- error =`There is a cyclic dependency: '${dependencyNamesString}'.`;
131
- }
132
-
133
- return error;
134
- }
135
-
136
- function checkReleaseMatchesDependency(dependency, dependentNames, releaseContext) {
137
- let error = null;
138
-
139
- const entries = releaseContext.getEntries(),
140
- shortenedVersion = dependency.getShortedVersion();
141
-
142
- if (shortenedVersion !== null) {
143
- const entriesMatchShortenedVersion = entries.matchShortenedVersion(shortenedVersion);
144
-
145
- if (!entriesMatchShortenedVersion) {
146
- const version = releaseContext.getVersion(),
147
- versionString = version.toString(),
148
- lastDependentName = last(dependentNames),
149
- dependentName = lastDependentName, ///
150
- dependencyName = dependency.getName(),
151
- shortenedVersion = dependency.getShortedVersion(),
152
- shortenedVersionString = shortenedVersion.toString();
153
-
154
- error = `Version mismatch: '${dependentName}' requires '${dependencyName}' to be version ${shortenedVersionString}.0 or higher but version ${versionString} has been supplied.`;
155
- }
156
- }
157
-
158
- return error;
159
- }
160
-
161
- function createDependencyReleaseContexts(dependency, dependentNames, context, callback) {
162
- const { releaseContextMap } = context,
163
- dependencyName = dependency.getName(),
164
- releaseName = dependencyName, ///
165
- releaseContext = releaseContextMap[releaseName],
166
- dependencies = releaseContext.getDependencies();
167
-
168
- dependentNames = [ ...dependentNames, dependencyName ]; ///
169
-
170
- dependencies.asynchronousForEachDependency((dependency, next, done) => {
171
- const error = checkCyclicDependencyExists(dependency, dependentNames);
172
-
173
- if (error) {
174
- callback(error);
175
-
176
- return;
177
- }
178
-
179
- createReleaseContext(dependency, dependentNames, context, (error) => {
180
- if (error) {
181
- callback(error);
182
-
183
- return;
184
- }
185
-
186
- next();
187
- });
188
- }, done);
189
-
190
- function done() {
191
- const error = null;
192
-
193
- callback(error);
194
- }
195
- }
196
-
197
- function retrieveDependencyReleaseContexts(dependency, context, dependencyReleaseContexts = []) {
198
- const { releaseContextMap } = context,
199
- dependencyName = dependency.getName(),
200
- releaseName = dependencyName, ///
201
- releaseContext = releaseContextMap[releaseName],
202
- dependencies = releaseContext.getDependencies();
203
-
204
- dependencies.forEachDependency((dependency) => {
205
- const dependencyName = dependency.getName(),
206
- releaseName = dependencyName, ///
207
- releaseContext = releaseContextMap[releaseName] || null;
208
-
209
- if (releaseContext === null) {
210
- return;
211
- }
212
-
213
- const dependencyReleaseContextsIncludesReleaseContext = dependencyReleaseContexts.includes(releaseContext);
214
-
215
- if (dependencyReleaseContextsIncludesReleaseContext) {
216
- return;
217
- }
218
-
219
- retrieveDependencyReleaseContexts(dependency, context, dependencyReleaseContexts);
220
-
221
- dependencyReleaseContexts.push(releaseContext);
222
- });
223
-
224
- return dependencyReleaseContexts;
225
- }