@monorepolint/rules 0.5.0-alpha.98 → 0.5.0-beta.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.
Files changed (156) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +47 -26
  3. package/src/__tests__/alphabeticalScripts.spec.ts +6 -5
  4. package/src/__tests__/bannedDependencies.spec.ts +5 -7
  5. package/src/__tests__/consistentDependencies.spec.ts +6 -5
  6. package/src/__tests__/consistentVersions.spec.ts +5 -4
  7. package/src/__tests__/fileContents.spec.ts +44 -17
  8. package/src/__tests__/mustSatisfyPeerDependencies.spec.ts +39 -38
  9. package/src/__tests__/nestedWorkspaces.spec.ts +5 -4
  10. package/src/__tests__/packageEntry.spec.ts +43 -32
  11. package/src/__tests__/packageOrder.spec.ts +23 -14
  12. package/src/__tests__/packageScript.spec.ts +61 -43
  13. package/src/__tests__/requireDependency.spec.ts +8 -7
  14. package/src/__tests__/utils.ts +8 -4
  15. package/src/alphabeticalDependencies.ts +7 -12
  16. package/src/alphabeticalScripts.ts +7 -12
  17. package/src/bannedDependencies.ts +9 -12
  18. package/src/consistentDependencies.ts +9 -10
  19. package/src/consistentVersions.ts +6 -8
  20. package/src/fileContents.ts +17 -16
  21. package/src/index.ts +13 -13
  22. package/src/mustSatisfyPeerDependencies.ts +16 -17
  23. package/src/nestedWorkspaces.ts +10 -12
  24. package/src/packageEntry.ts +7 -9
  25. package/src/packageOrder.ts +12 -10
  26. package/src/packageScript.ts +12 -19
  27. package/src/public/util.ts +1 -0
  28. package/src/requireDependency.ts +9 -10
  29. package/src/standardTsconfig.ts +10 -11
  30. package/src/util/checkAlpha.ts +1 -1
  31. package/src/util/makeRule.ts +29 -0
  32. package/src/util/packageDependencyGraphService.ts +2 -2
  33. package/tsconfig.json +7 -2
  34. package/lib/__tests__/alphabeticalScripts.spec.d.ts +0 -8
  35. package/lib/__tests__/alphabeticalScripts.spec.d.ts.map +0 -1
  36. package/lib/__tests__/alphabeticalScripts.spec.js +0 -61
  37. package/lib/__tests__/alphabeticalScripts.spec.js.map +0 -1
  38. package/lib/__tests__/bannedDependencies.spec.d.ts +0 -2
  39. package/lib/__tests__/bannedDependencies.spec.d.ts.map +0 -1
  40. package/lib/__tests__/bannedDependencies.spec.js +0 -161
  41. package/lib/__tests__/bannedDependencies.spec.js.map +0 -1
  42. package/lib/__tests__/consistentDependencies.spec.d.ts +0 -2
  43. package/lib/__tests__/consistentDependencies.spec.d.ts.map +0 -1
  44. package/lib/__tests__/consistentDependencies.spec.js +0 -115
  45. package/lib/__tests__/consistentDependencies.spec.js.map +0 -1
  46. package/lib/__tests__/consistentVersions.spec.d.ts +0 -8
  47. package/lib/__tests__/consistentVersions.spec.d.ts.map +0 -1
  48. package/lib/__tests__/consistentVersions.spec.js +0 -183
  49. package/lib/__tests__/consistentVersions.spec.js.map +0 -1
  50. package/lib/__tests__/fileContents.spec.d.ts +0 -8
  51. package/lib/__tests__/fileContents.spec.d.ts.map +0 -1
  52. package/lib/__tests__/fileContents.spec.js +0 -59
  53. package/lib/__tests__/fileContents.spec.js.map +0 -1
  54. package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts +0 -8
  55. package/lib/__tests__/mustSatisfyPeerDependencies.spec.d.ts.map +0 -1
  56. package/lib/__tests__/mustSatisfyPeerDependencies.spec.js +0 -1063
  57. package/lib/__tests__/mustSatisfyPeerDependencies.spec.js.map +0 -1
  58. package/lib/__tests__/nestedWorkspaces.spec.d.ts +0 -2
  59. package/lib/__tests__/nestedWorkspaces.spec.d.ts.map +0 -1
  60. package/lib/__tests__/nestedWorkspaces.spec.js +0 -124
  61. package/lib/__tests__/nestedWorkspaces.spec.js.map +0 -1
  62. package/lib/__tests__/packageEntry.spec.d.ts +0 -8
  63. package/lib/__tests__/packageEntry.spec.d.ts.map +0 -1
  64. package/lib/__tests__/packageEntry.spec.js +0 -144
  65. package/lib/__tests__/packageEntry.spec.js.map +0 -1
  66. package/lib/__tests__/packageOrder.spec.d.ts +0 -8
  67. package/lib/__tests__/packageOrder.spec.d.ts.map +0 -1
  68. package/lib/__tests__/packageOrder.spec.js +0 -116
  69. package/lib/__tests__/packageOrder.spec.js.map +0 -1
  70. package/lib/__tests__/packageScript.spec.d.ts +0 -8
  71. package/lib/__tests__/packageScript.spec.d.ts.map +0 -1
  72. package/lib/__tests__/packageScript.spec.js +0 -171
  73. package/lib/__tests__/packageScript.spec.js.map +0 -1
  74. package/lib/__tests__/requireDependency.spec.d.ts +0 -2
  75. package/lib/__tests__/requireDependency.spec.d.ts.map +0 -1
  76. package/lib/__tests__/requireDependency.spec.js +0 -123
  77. package/lib/__tests__/requireDependency.spec.js.map +0 -1
  78. package/lib/__tests__/utils.d.ts +0 -76
  79. package/lib/__tests__/utils.d.ts.map +0 -1
  80. package/lib/__tests__/utils.js +0 -83
  81. package/lib/__tests__/utils.js.map +0 -1
  82. package/lib/alphabeticalDependencies.d.ts +0 -23
  83. package/lib/alphabeticalDependencies.d.ts.map +0 -1
  84. package/lib/alphabeticalDependencies.js +0 -24
  85. package/lib/alphabeticalDependencies.js.map +0 -1
  86. package/lib/alphabeticalScripts.d.ts +0 -23
  87. package/lib/alphabeticalScripts.d.ts.map +0 -1
  88. package/lib/alphabeticalScripts.js +0 -22
  89. package/lib/alphabeticalScripts.js.map +0 -1
  90. package/lib/bannedDependencies.d.ts +0 -134
  91. package/lib/bannedDependencies.d.ts.map +0 -1
  92. package/lib/bannedDependencies.js +0 -133
  93. package/lib/bannedDependencies.js.map +0 -1
  94. package/lib/consistentDependencies.d.ts +0 -38
  95. package/lib/consistentDependencies.d.ts.map +0 -1
  96. package/lib/consistentDependencies.js +0 -77
  97. package/lib/consistentDependencies.js.map +0 -1
  98. package/lib/consistentVersions.d.ts +0 -47
  99. package/lib/consistentVersions.d.ts.map +0 -1
  100. package/lib/consistentVersions.js +0 -96
  101. package/lib/consistentVersions.js.map +0 -1
  102. package/lib/fileContents.d.ts +0 -111
  103. package/lib/fileContents.d.ts.map +0 -1
  104. package/lib/fileContents.js +0 -84
  105. package/lib/fileContents.js.map +0 -1
  106. package/lib/index.d.ts +0 -20
  107. package/lib/index.d.ts.map +0 -1
  108. package/lib/index.js +0 -49
  109. package/lib/index.js.map +0 -1
  110. package/lib/mustSatisfyPeerDependencies.d.ts +0 -721
  111. package/lib/mustSatisfyPeerDependencies.d.ts.map +0 -1
  112. package/lib/mustSatisfyPeerDependencies.js +0 -638
  113. package/lib/mustSatisfyPeerDependencies.js.map +0 -1
  114. package/lib/nestedWorkspaces.d.ts +0 -24
  115. package/lib/nestedWorkspaces.d.ts.map +0 -1
  116. package/lib/nestedWorkspaces.js +0 -52
  117. package/lib/nestedWorkspaces.js.map +0 -1
  118. package/lib/packageEntry.d.ts +0 -115
  119. package/lib/packageEntry.d.ts.map +0 -1
  120. package/lib/packageEntry.js +0 -77
  121. package/lib/packageEntry.js.map +0 -1
  122. package/lib/packageOrder.d.ts +0 -33
  123. package/lib/packageOrder.d.ts.map +0 -1
  124. package/lib/packageOrder.js +0 -105
  125. package/lib/packageOrder.js.map +0 -1
  126. package/lib/packageScript.d.ts +0 -102
  127. package/lib/packageScript.d.ts.map +0 -1
  128. package/lib/packageScript.js +0 -92
  129. package/lib/packageScript.js.map +0 -1
  130. package/lib/requireDependency.d.ts +0 -99
  131. package/lib/requireDependency.d.ts.map +0 -1
  132. package/lib/requireDependency.js +0 -67
  133. package/lib/requireDependency.js.map +0 -1
  134. package/lib/standardTsconfig.d.ts +0 -113
  135. package/lib/standardTsconfig.d.ts.map +0 -1
  136. package/lib/standardTsconfig.js +0 -118
  137. package/lib/standardTsconfig.js.map +0 -1
  138. package/lib/util/checkAlpha.d.ts +0 -10
  139. package/lib/util/checkAlpha.d.ts.map +0 -1
  140. package/lib/util/checkAlpha.js +0 -51
  141. package/lib/util/checkAlpha.js.map +0 -1
  142. package/lib/util/createNewRuleConversion.d.ts +0 -30
  143. package/lib/util/createNewRuleConversion.d.ts.map +0 -1
  144. package/lib/util/createNewRuleConversion.js +0 -33
  145. package/lib/util/createNewRuleConversion.js.map +0 -1
  146. package/lib/util/makeDirectory.d.ts +0 -8
  147. package/lib/util/makeDirectory.d.ts.map +0 -1
  148. package/lib/util/makeDirectory.js +0 -28
  149. package/lib/util/makeDirectory.js.map +0 -1
  150. package/lib/util/packageDependencyGraphService.d.ts +0 -37
  151. package/lib/util/packageDependencyGraphService.d.ts.map +0 -1
  152. package/lib/util/packageDependencyGraphService.js +0 -70
  153. package/lib/util/packageDependencyGraphService.js.map +0 -1
  154. package/src/util/createNewRuleConversion.ts +0 -38
  155. package/tsconfig.tsbuildinfo +0 -1
  156. /package/{jest.config.js → jest.config.cjs} +0 -0
@@ -1,1063 +0,0 @@
1
- "use strict";
2
- /*!
3
- * Copyright 2020 Palantir Technologies, Inc.
4
- *
5
- * Licensed under the MIT license. See LICENSE file in the project root for details.
6
- *
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- const tslib_1 = require("tslib");
10
- const core_1 = require("@monorepolint/core");
11
- const utils_1 = require("@monorepolint/utils");
12
- const path = tslib_1.__importStar(require("path"));
13
- const tmp = tslib_1.__importStar(require("tmp"));
14
- const mustSatisfyPeerDependencies_1 = require("../mustSatisfyPeerDependencies");
15
- const makeDirectory_1 = require("../util/makeDirectory");
16
- const doesASatisfyB = (a, b) => {
17
- if (!(0, mustSatisfyPeerDependencies_1.isValidRange)(a)) {
18
- throw new Error(`${a} is not a valid range.`);
19
- }
20
- if (!(0, mustSatisfyPeerDependencies_1.isValidRange)(b)) {
21
- throw new Error(`${b} is not a valid range.`);
22
- }
23
- return (0, mustSatisfyPeerDependencies_1.doesASatisfyB)(a, b);
24
- };
25
- const findIntersection = (a, b) => {
26
- if (!(0, mustSatisfyPeerDependencies_1.isValidRange)(a)) {
27
- throw new Error(`${a} is not a valid range.`);
28
- }
29
- if (!(0, mustSatisfyPeerDependencies_1.isValidRange)(b)) {
30
- throw new Error(`${b} is not a valid range.`);
31
- }
32
- return (0, mustSatisfyPeerDependencies_1.findIntersection)(a, b);
33
- };
34
- describe("mustSatisfyPeerDependencies", () => {
35
- tmp.setGracefulCleanup();
36
- let cleanupJobs = [];
37
- let cwd;
38
- beforeEach(() => {
39
- const dir = tmp.dirSync({ unsafeCleanup: true });
40
- cleanupJobs.push(() => dir.removeCallback());
41
- cwd = dir.name;
42
- const spy = jest.spyOn(process, "cwd");
43
- spy.mockReturnValue(cwd);
44
- });
45
- afterEach(() => {
46
- for (const cleanupJob of cleanupJobs) {
47
- cleanupJob();
48
- }
49
- cleanupJobs = [];
50
- });
51
- function makeWorkspace(fix = false) {
52
- const host = new utils_1.SimpleHost();
53
- const workspaceContext = new core_1.WorkspaceContextImpl(cwd, {
54
- rules: [],
55
- fix,
56
- verbose: false,
57
- silent: true,
58
- }, host);
59
- const addErrorSpy = jest.spyOn(workspaceContext, "addError");
60
- function check(options) {
61
- mustSatisfyPeerDependencies_1.mustSatisfyPeerDependencies.check(workspaceContext, options);
62
- }
63
- return { addErrorSpy, check, host };
64
- }
65
- function addPackageJson(host, filePath, packageJson) {
66
- const dirPath = path.resolve(cwd, path.dirname(filePath));
67
- const resolvedFilePath = path.resolve(cwd, filePath);
68
- (0, makeDirectory_1.makeDirectoryRecursively)(dirPath);
69
- host.writeJson(resolvedFilePath, packageJson);
70
- return () => {
71
- return host.readJson(resolvedFilePath);
72
- };
73
- }
74
- describe("regex tests", () => {
75
- const anyVersionRangePassTests = ["*", "x"];
76
- const greaterOrEqualVersionRangePassTests = [
77
- ">=15",
78
- ">= 15",
79
- ">=15.2",
80
- ">= 15.2",
81
- ">=15.2.2",
82
- ">= 15.2.2",
83
- ">=15.2.2-0",
84
- ">= 15.2.2-0",
85
- ">=15.2.2-alpha",
86
- ">= 15.2.2-alpha",
87
- ">=15.2.2-alpha.1",
88
- ">= 15.2.2-alpha.1",
89
- ">=15.2.2-alpha.beta",
90
- ">= 15.2.2-alpha.beta",
91
- ">=15.2.2-beta",
92
- ">= 15.2.2-beta",
93
- ">=15.2.2-beta.2",
94
- ">= 15.2.2-beta.2",
95
- ">=15.2.2-beta.11",
96
- ">= 15.2.2-beta.11",
97
- ">=15.2.2-rc",
98
- ">= 15.2.2-rc",
99
- ">=15.2.2-rc.1",
100
- ">= 15.2.2-rc.1",
101
- ">=15.2.2-rc.1+001",
102
- ">= 15.2.2-rc.1+001",
103
- ">=15.2.2+20130313144700",
104
- ">= 15.2.2+20130313144700",
105
- ">=15.2.2+20130313144700.sha",
106
- ">= 15.2.2+20130313144700.sha",
107
- ">=15.2.2-rc.1+exp.sha.5114f85",
108
- ">= 15.2.2-rc.1+exp.sha.5114f85",
109
- ">=15.2.2+sha-1",
110
- ">= 15.2.2+sha-1",
111
- ];
112
- const majorVersionRangePassTests = [
113
- "15",
114
- "^15",
115
- "15.x",
116
- "^15.x",
117
- "15.x.x",
118
- "^15.x.x",
119
- "^15.2",
120
- "^15.2.x",
121
- "^15.2.2",
122
- "^15.2.2-0",
123
- "^15.2.2-alpha",
124
- "^15.2.2-alpha.1",
125
- "^15.2.2-alpha.beta",
126
- "^15.2.2-beta",
127
- "^15.2.2-beta.2",
128
- "^15.2.2-beta.11",
129
- "^15.2.2-rc",
130
- "^15.2.2-rc.1",
131
- "^15.2.2-rc.1+001",
132
- "^15.2.2+20130313144700",
133
- "^15.2.2+20130313144700.sha",
134
- "^15.2.2-rc.1+exp.sha.5114f85",
135
- "^15.2.2+sha-1",
136
- ];
137
- const failEverythingTests = [
138
- "",
139
- ".",
140
- "xx",
141
- "x.x",
142
- "^x",
143
- "*x",
144
- "x.*",
145
- "x.2",
146
- "^x.2",
147
- "^.2",
148
- "15.xx",
149
- "15^",
150
- "15.x.2",
151
- "15.x.2-0",
152
- "15.x.2+0",
153
- "15.x.2 || 16.2",
154
- "15.x.2 || 16.2-0",
155
- "15.x.2 || 16.2+0",
156
- "^15.x.2 || 16.2",
157
- "15.x.2 || ^16.2",
158
- "^15.x.2 || ^16.2",
159
- "15 || x",
160
- "15 || x+0",
161
- "15.x || x",
162
- "15 | 16",
163
- "15sha | 16",
164
- "15.alpha | 16",
165
- "15+rc | 16",
166
- "15.x.16.x",
167
- ">15",
168
- "^>=15",
169
- ">=^15",
170
- "^ >=15",
171
- ];
172
- it("Properly matches any version range regex", async () => {
173
- const passTests = [...anyVersionRangePassTests];
174
- for (const passTest of passTests) {
175
- expect(mustSatisfyPeerDependencies_1.MATCH_ANY_VERSION_RANGE.test(passTest)).toBeTruthy();
176
- }
177
- const failTests = [
178
- ...greaterOrEqualVersionRangePassTests,
179
- ...majorVersionRangePassTests,
180
- ...failEverythingTests,
181
- "* || x",
182
- "* || *",
183
- "x || x",
184
- "x || 4",
185
- "4",
186
- "4.2",
187
- "^4",
188
- "^4.2",
189
- "4.x",
190
- "^4.x",
191
- "4.2.x",
192
- "^4.2.x",
193
- ];
194
- for (const failTest of failTests) {
195
- expect(mustSatisfyPeerDependencies_1.MATCH_ANY_VERSION_RANGE.test(failTest)).toBeFalsy();
196
- }
197
- });
198
- it("Properly matches greator or equal version range regex", async () => {
199
- const passTests = [...greaterOrEqualVersionRangePassTests];
200
- for (const passTest of passTests) {
201
- expect(mustSatisfyPeerDependencies_1.MATCH_GREATER_OR_EQUAL_VERSION_RANGE.test(passTest)).toBeTruthy();
202
- }
203
- const failTests = [
204
- ...anyVersionRangePassTests,
205
- ...majorVersionRangePassTests,
206
- ...failEverythingTests,
207
- ">=",
208
- ">=x",
209
- ">=4.x",
210
- ">=4.x.x",
211
- ">=4 || 5",
212
- ">=4 || *",
213
- "4.2.x",
214
- "4.2.2",
215
- "4.2.2-0",
216
- "4.2.2-rc",
217
- "4.2.2-rc.0",
218
- "4.2.2-alpha.beta",
219
- "4.2.2+sha",
220
- ];
221
- for (const failTest of failTests) {
222
- expect(mustSatisfyPeerDependencies_1.MATCH_GREATER_OR_EQUAL_VERSION_RANGE.test(failTest)).toBeFalsy();
223
- }
224
- });
225
- it("Properly matches major version range regex", async () => {
226
- const passTests = [...majorVersionRangePassTests];
227
- for (const passTest of passTests) {
228
- expect(mustSatisfyPeerDependencies_1.MATCH_MAJOR_VERSION_RANGE.test(passTest)).toBeTruthy();
229
- }
230
- const failTests = [
231
- ...anyVersionRangePassTests,
232
- ...greaterOrEqualVersionRangePassTests,
233
- ...failEverythingTests,
234
- "4.2.x",
235
- "4.2.2",
236
- "4.2.2-0",
237
- "4.2.2-rc",
238
- "4.2.2-rc.0",
239
- "4.2.2-alpha.beta",
240
- "4.2.2+sha",
241
- ];
242
- for (const failTest of failTests) {
243
- expect(mustSatisfyPeerDependencies_1.MATCH_MAJOR_VERSION_RANGE.test(failTest)).toBeFalsy();
244
- }
245
- });
246
- it("Properly matches allowed range regex", async () => {
247
- const passTests = [
248
- ...anyVersionRangePassTests,
249
- ...greaterOrEqualVersionRangePassTests,
250
- ...majorVersionRangePassTests,
251
- "15.2",
252
- "15.2.3",
253
- "15.2.3-0",
254
- "15.2.3+0",
255
- "15.2.3-rc",
256
- "15.2.3-rc.0",
257
- "15.2.3+sha",
258
- "15.2.3+sha.1234.9999",
259
- "15.2.3-0+sha",
260
- "15 || 16",
261
- "^15 || 16",
262
- "15 || ^16",
263
- "^15 || ^16",
264
- "15.2 || 16",
265
- "^15.2 || 16",
266
- "15.2 || ^16",
267
- "15.x || 16",
268
- "^15.x || 16",
269
- "15.x || ^16",
270
- "^15.x || ^16",
271
- "15.2.x || 16.2",
272
- "^15.2.x || 16.2",
273
- "15.2.x || ^16.2",
274
- "^15.2.x || ^16.2",
275
- "15 || 16 || 17",
276
- "15 || ^16 || 17",
277
- "15 || 16 || 17.2.x",
278
- "15 || ^16 || 17.2.x",
279
- "15 || 16 || ^17.2.x",
280
- "15.2 || 16 || 17.2.x",
281
- "15.2.2 || 16 || 17.2.x",
282
- "15.2.2-0 || 16 || 17.2.x",
283
- "15.2.2-rc || 16 || 17.2.x",
284
- "15.2.2-rc.0 || 16 || 17.2.x",
285
- "15.2.2+sha || 16 || 17.2.x",
286
- "15.2.2-rc.0 || 16.6.6 || 17.2.x",
287
- "15.2.2-rc.0 || 16.6.6-0 || 17.2.x",
288
- "15.2.2-rc.0 || 16.6.6-rc || 17.2.x",
289
- "15.2.2-rc.0 || 16.6.6-rc.0 || 17.2.x",
290
- "15.2.2-rc.0 || 16.6.6+sha || 17.2.x",
291
- "15.2 || ^16 || ^17.2.x",
292
- "15.2.2 || ^16 || ^17.2.x",
293
- "15.2.2-0 || ^16 || ^17.2.x",
294
- "15.2.2-rc || ^16 || ^17.2.x",
295
- "15.2.2-rc.0 || ^16 || ^17.2.x",
296
- "15.2.2+sha || ^16 || ^17.2.x",
297
- "15.2.2-rc.0 || ^16.6.6 || ^17.2.x",
298
- "15.2.2-rc.0 || ^16.6.6-0 || ^17.2.x",
299
- "15.2.2-rc.0 || ^16.6.6-rc || ^17.2.x",
300
- "15.2.2-rc.0 || ^16.6.6-rc.0 || ^17.2.x",
301
- "15.2.2-rc.0 || ^16.6.6+sha || ^17.2.x",
302
- "^15.2 || ^16 || ^17.2.x",
303
- ];
304
- for (const passTest of passTests) {
305
- expect(mustSatisfyPeerDependencies_1.RANGE_REGEX.test(passTest)).toBeTruthy();
306
- }
307
- const failTests = [...failEverythingTests];
308
- for (const failTest of failTests) {
309
- expect(mustSatisfyPeerDependencies_1.RANGE_REGEX.test(failTest)).toBeFalsy();
310
- }
311
- });
312
- });
313
- describe("Determines dependencies satisfaction correctly", () => {
314
- it("version is version", async () => {
315
- const version = "15.0.0";
316
- expect(doesASatisfyB(version, version)).toBeTruthy();
317
- });
318
- it("version satisfies a range", async () => {
319
- const version = "15.0.0";
320
- const range = "15";
321
- expect(doesASatisfyB(version, range)).toBeTruthy();
322
- expect(doesASatisfyB(range, version)).toBeFalsy();
323
- const equivalentRange1 = "^15";
324
- expect(doesASatisfyB(version, equivalentRange1)).toBeTruthy();
325
- expect(doesASatisfyB(equivalentRange1, version)).toBeFalsy();
326
- const equivalentRange2 = "^15.0.0";
327
- expect(doesASatisfyB(version, equivalentRange2)).toBeTruthy();
328
- expect(doesASatisfyB(equivalentRange2, version)).toBeFalsy();
329
- const equivalentRange3 = "15.x";
330
- expect(doesASatisfyB(version, equivalentRange3)).toBeTruthy();
331
- expect(doesASatisfyB(equivalentRange3, version)).toBeFalsy();
332
- const equivalentRange4 = "^15.x";
333
- expect(doesASatisfyB(version, equivalentRange4)).toBeTruthy();
334
- expect(doesASatisfyB(equivalentRange4, version)).toBeFalsy();
335
- const equivalentRange5 = "15.x.x";
336
- expect(doesASatisfyB(version, equivalentRange5)).toBeTruthy();
337
- expect(doesASatisfyB(equivalentRange5, version)).toBeFalsy();
338
- const equivalentRange6 = "^15.x.x";
339
- expect(doesASatisfyB(version, equivalentRange6)).toBeTruthy();
340
- expect(doesASatisfyB(equivalentRange6, version)).toBeFalsy();
341
- });
342
- it("higher version satisfies a range", async () => {
343
- const higherVersion = "15.0.2";
344
- const range = "15";
345
- expect(doesASatisfyB(higherVersion, range)).toBeTruthy();
346
- expect(doesASatisfyB(range, higherVersion)).toBeFalsy();
347
- const equivalentRange1 = "^15";
348
- expect(doesASatisfyB(higherVersion, equivalentRange1)).toBeTruthy();
349
- expect(doesASatisfyB(equivalentRange1, higherVersion)).toBeFalsy();
350
- const equivalentRange2 = "^15.0.0";
351
- expect(doesASatisfyB(higherVersion, equivalentRange2)).toBeTruthy();
352
- expect(doesASatisfyB(equivalentRange2, higherVersion)).toBeFalsy();
353
- const equivalentRange3 = "15.x";
354
- expect(doesASatisfyB(higherVersion, equivalentRange3)).toBeTruthy();
355
- expect(doesASatisfyB(equivalentRange3, higherVersion)).toBeFalsy();
356
- const equivalentRange4 = "^15.x";
357
- expect(doesASatisfyB(higherVersion, equivalentRange4)).toBeTruthy();
358
- expect(doesASatisfyB(equivalentRange4, higherVersion)).toBeFalsy();
359
- const equivalentRange5 = "15.x.x";
360
- expect(doesASatisfyB(higherVersion, equivalentRange5)).toBeTruthy();
361
- expect(doesASatisfyB(equivalentRange5, higherVersion)).toBeFalsy();
362
- const equivalentRange6 = "^15.x.x";
363
- expect(doesASatisfyB(higherVersion, equivalentRange6)).toBeTruthy();
364
- expect(doesASatisfyB(equivalentRange6, higherVersion)).toBeFalsy();
365
- });
366
- it("version satisfies a greator or equal version range", async () => {
367
- const version = "15.0.0";
368
- const range = ">=15";
369
- expect(doesASatisfyB(version, range)).toBeTruthy();
370
- expect(doesASatisfyB(range, version)).toBeFalsy();
371
- const equivalentRange1 = ">=15.0";
372
- expect(doesASatisfyB(version, equivalentRange1)).toBeTruthy();
373
- expect(doesASatisfyB(equivalentRange1, version)).toBeFalsy();
374
- const equivalentRange2 = ">=15.0.0";
375
- expect(doesASatisfyB(version, equivalentRange2)).toBeTruthy();
376
- expect(doesASatisfyB(equivalentRange2, version)).toBeFalsy();
377
- });
378
- it("higher version satisfies a greator or equal version range", async () => {
379
- const higherVersion = "15.0.2";
380
- const range = ">=15";
381
- expect(doesASatisfyB(higherVersion, range)).toBeTruthy();
382
- expect(doesASatisfyB(range, higherVersion)).toBeFalsy();
383
- const equivalentRange1 = ">=15.0";
384
- expect(doesASatisfyB(higherVersion, equivalentRange1)).toBeTruthy();
385
- expect(doesASatisfyB(equivalentRange1, higherVersion)).toBeFalsy();
386
- const equivalentRange2 = ">=15.0.0";
387
- expect(doesASatisfyB(higherVersion, equivalentRange2)).toBeTruthy();
388
- expect(doesASatisfyB(equivalentRange2, higherVersion)).toBeFalsy();
389
- });
390
- it("version satisfies 'any' range", async () => {
391
- const version = "15.0.0";
392
- const anyRange = "*";
393
- expect(doesASatisfyB(version, anyRange)).toBeTruthy();
394
- expect(doesASatisfyB(anyRange, version)).toBeFalsy();
395
- const equivalentRange = "x";
396
- expect(doesASatisfyB(version, equivalentRange)).toBeTruthy();
397
- expect(doesASatisfyB(equivalentRange, version)).toBeFalsy();
398
- });
399
- it("greator or equal version range satisfies 'any' range", async () => {
400
- const range = ">=15";
401
- const anyRange = "*";
402
- expect(doesASatisfyB(range, anyRange)).toBeTruthy();
403
- expect(doesASatisfyB(anyRange, range)).toBeFalsy();
404
- const equivalentRange = "x";
405
- expect(doesASatisfyB(range, equivalentRange)).toBeTruthy();
406
- expect(doesASatisfyB(equivalentRange, range)).toBeFalsy();
407
- });
408
- it("range satisfies 'any' range", async () => {
409
- const range = "^15";
410
- const anyRange = "*";
411
- expect(doesASatisfyB(range, anyRange)).toBeTruthy();
412
- expect(doesASatisfyB(anyRange, range)).toBeFalsy();
413
- const equivalentRange = "x";
414
- expect(doesASatisfyB(range, equivalentRange)).toBeTruthy();
415
- expect(doesASatisfyB(equivalentRange, range)).toBeFalsy();
416
- });
417
- it("union range satisfies 'any' range", async () => {
418
- const unionRange = "^15 || ^16";
419
- const anyRange = "*";
420
- expect(doesASatisfyB(unionRange, anyRange)).toBeTruthy();
421
- expect(doesASatisfyB(anyRange, unionRange)).toBeFalsy();
422
- const equivalentRange = "x";
423
- expect(doesASatisfyB(unionRange, equivalentRange)).toBeTruthy();
424
- expect(doesASatisfyB(equivalentRange, unionRange)).toBeFalsy();
425
- });
426
- it("version found in union start", async () => {
427
- const version = "15.0.0";
428
- const versionVersionUnion = "15.0.0 || 16.0.0";
429
- expect(doesASatisfyB(version, versionVersionUnion)).toBeTruthy();
430
- expect(doesASatisfyB(versionVersionUnion, version)).toBeFalsy();
431
- const versionRangeUnion = "15.0.0 || ^16";
432
- expect(doesASatisfyB(version, versionRangeUnion)).toBeTruthy();
433
- expect(doesASatisfyB(versionRangeUnion, version)).toBeFalsy();
434
- });
435
- it("version found in union end", async () => {
436
- const version = "15.0.0";
437
- const versionVersionUnion = "14.0.0 || 15.0.0";
438
- expect(doesASatisfyB(version, versionVersionUnion)).toBeTruthy();
439
- expect(doesASatisfyB(versionVersionUnion, version)).toBeFalsy();
440
- const rangeVersionUnion = "^14 || 15.0.0";
441
- expect(doesASatisfyB(version, rangeVersionUnion)).toBeTruthy();
442
- expect(doesASatisfyB(rangeVersionUnion, version)).toBeFalsy();
443
- });
444
- it("version satisfies a range in union start", async () => {
445
- const version = "15.0.0";
446
- const rangeVersionUnion = "^15 || 16.0.0";
447
- expect(doesASatisfyB(version, rangeVersionUnion)).toBeTruthy();
448
- expect(doesASatisfyB(rangeVersionUnion, version)).toBeFalsy();
449
- const rangeRangeUnion = "^15 || ^16";
450
- expect(doesASatisfyB(version, rangeRangeUnion)).toBeTruthy();
451
- expect(doesASatisfyB(rangeRangeUnion, version)).toBeFalsy();
452
- });
453
- it("version satisfies a range in union end", async () => {
454
- const version = "15.0.0";
455
- const versionRangeUnion = "14.0.0 || ^15";
456
- expect(doesASatisfyB(version, versionRangeUnion)).toBeTruthy();
457
- expect(doesASatisfyB(versionRangeUnion, version)).toBeFalsy();
458
- const rangeRangeUnion = "^14 || ^15";
459
- expect(doesASatisfyB(version, rangeRangeUnion)).toBeTruthy();
460
- expect(doesASatisfyB(rangeRangeUnion, version)).toBeFalsy();
461
- });
462
- it("higher version satisfies a range in union start", async () => {
463
- const higherVersion = "15.0.2";
464
- const rangeVersionUnion = "^15 || 16.0.0";
465
- expect(doesASatisfyB(higherVersion, rangeVersionUnion)).toBeTruthy();
466
- expect(doesASatisfyB(rangeVersionUnion, higherVersion)).toBeFalsy();
467
- const rangeRangeUnion = "^15 || ^16";
468
- expect(doesASatisfyB(higherVersion, rangeRangeUnion)).toBeTruthy();
469
- expect(doesASatisfyB(rangeRangeUnion, higherVersion)).toBeFalsy();
470
- });
471
- it("higher version satisfies a range in union end", async () => {
472
- const higherVersion = "15.0.2";
473
- const versionRangeUnion = "14.0.0 || ^15";
474
- expect(doesASatisfyB(higherVersion, versionRangeUnion)).toBeTruthy();
475
- expect(doesASatisfyB(versionRangeUnion, higherVersion)).toBeFalsy();
476
- const rangeRangeUnion = "^14 || ^15";
477
- expect(doesASatisfyB(higherVersion, rangeRangeUnion)).toBeTruthy();
478
- expect(doesASatisfyB(rangeRangeUnion, higherVersion)).toBeFalsy();
479
- });
480
- it("range found in union start", async () => {
481
- const range = "^15";
482
- const rangeVersionUnion = "^15 || 16.0.0";
483
- expect(doesASatisfyB(range, rangeVersionUnion)).toBeTruthy();
484
- expect(doesASatisfyB(rangeVersionUnion, range)).toBeFalsy();
485
- const rangeRangeUnion = "^15 || ^16";
486
- expect(doesASatisfyB(range, rangeRangeUnion)).toBeTruthy();
487
- expect(doesASatisfyB(rangeRangeUnion, range)).toBeFalsy();
488
- });
489
- it("range found in union end", async () => {
490
- const range = "^15";
491
- const versionRangeUnion = "14.0.0 || ^15";
492
- expect(doesASatisfyB(range, versionRangeUnion)).toBeTruthy();
493
- expect(doesASatisfyB(versionRangeUnion, range)).toBeFalsy();
494
- const rangeRangeUnion = "^14 || ^15";
495
- expect(doesASatisfyB(range, rangeRangeUnion)).toBeTruthy();
496
- expect(doesASatisfyB(rangeRangeUnion, range)).toBeFalsy();
497
- });
498
- it("union satisfies greator or equal version range", async () => {
499
- const rangeVersionUnion = "^15 || 16.0.0";
500
- const range = ">=15";
501
- expect(doesASatisfyB(rangeVersionUnion, range)).toBeTruthy();
502
- expect(doesASatisfyB(range, rangeVersionUnion)).toBeFalsy();
503
- const rangeRangeUnion = "^15 || ^16";
504
- expect(doesASatisfyB(rangeRangeUnion, range)).toBeTruthy();
505
- expect(doesASatisfyB(range, rangeRangeUnion)).toBeFalsy();
506
- });
507
- it("greator or equal version range satisfies greator or equal version range", async () => {
508
- const range = ">=15";
509
- expect(doesASatisfyB(range, range)).toBeTruthy();
510
- const stricterRange = ">=16";
511
- expect(doesASatisfyB(stricterRange, range)).toBeTruthy();
512
- expect(doesASatisfyB(range, stricterRange)).toBeFalsy();
513
- });
514
- it("equivalent greator or equal version ranges satisfy each other", async () => {
515
- const rangeA = ">=15";
516
- const rangeB = ">=15.0";
517
- const rangeC = ">=15.0.0";
518
- expect(doesASatisfyB(rangeA, rangeB)).toBeTruthy();
519
- expect(doesASatisfyB(rangeB, rangeA)).toBeTruthy();
520
- expect(doesASatisfyB(rangeA, rangeC)).toBeTruthy();
521
- expect(doesASatisfyB(rangeC, rangeA)).toBeTruthy();
522
- expect(doesASatisfyB(rangeB, rangeC)).toBeTruthy();
523
- expect(doesASatisfyB(rangeC, rangeB)).toBeTruthy();
524
- });
525
- it("higher range satisfies a range in union start", async () => {
526
- const higherRange = "^15.2";
527
- const rangeVersionUnion = "^15 || 16.0.0";
528
- expect(doesASatisfyB(higherRange, rangeVersionUnion)).toBeTruthy();
529
- expect(doesASatisfyB(rangeVersionUnion, higherRange)).toBeFalsy();
530
- const rangeRangeUnion = "^15 || ^16";
531
- expect(doesASatisfyB(higherRange, rangeRangeUnion)).toBeTruthy();
532
- expect(doesASatisfyB(rangeRangeUnion, higherRange)).toBeFalsy();
533
- });
534
- it("higher range satisfies a range in union end", async () => {
535
- const higherRange = "^15.2";
536
- const versionRangeUnion = "14.0.0 || ^15";
537
- expect(doesASatisfyB(higherRange, versionRangeUnion)).toBeTruthy();
538
- expect(doesASatisfyB(versionRangeUnion, higherRange)).toBeFalsy();
539
- const rangeRangeUnion = "^14 || ^15";
540
- expect(doesASatisfyB(higherRange, rangeRangeUnion)).toBeTruthy();
541
- expect(doesASatisfyB(rangeRangeUnion, higherRange)).toBeFalsy();
542
- });
543
- it("equivalent 'any' ranges satisfy each other", async () => {
544
- const rangeA = "*";
545
- const rangeB = "x";
546
- expect(doesASatisfyB(rangeA, rangeB)).toBeTruthy();
547
- expect(doesASatisfyB(rangeB, rangeA)).toBeTruthy();
548
- });
549
- it("equivalent major ranges satisfy each other", async () => {
550
- const rangeA = "15";
551
- const rangeB = "^15";
552
- const rangeC = "^15.0.0";
553
- const rangeD = "15.x";
554
- const rangeE = "^15.x";
555
- const rangeF = "15.x.x";
556
- const rangeG = "^15.x.x";
557
- expect(doesASatisfyB(rangeA, rangeB)).toBeTruthy();
558
- expect(doesASatisfyB(rangeB, rangeA)).toBeTruthy();
559
- expect(doesASatisfyB(rangeA, rangeC)).toBeTruthy();
560
- expect(doesASatisfyB(rangeC, rangeA)).toBeTruthy();
561
- expect(doesASatisfyB(rangeA, rangeD)).toBeTruthy();
562
- expect(doesASatisfyB(rangeD, rangeA)).toBeTruthy();
563
- expect(doesASatisfyB(rangeA, rangeE)).toBeTruthy();
564
- expect(doesASatisfyB(rangeE, rangeA)).toBeTruthy();
565
- expect(doesASatisfyB(rangeA, rangeF)).toBeTruthy();
566
- expect(doesASatisfyB(rangeF, rangeA)).toBeTruthy();
567
- expect(doesASatisfyB(rangeA, rangeG)).toBeTruthy();
568
- expect(doesASatisfyB(rangeG, rangeA)).toBeTruthy();
569
- expect(doesASatisfyB(rangeB, rangeC)).toBeTruthy();
570
- expect(doesASatisfyB(rangeC, rangeB)).toBeTruthy();
571
- expect(doesASatisfyB(rangeB, rangeD)).toBeTruthy();
572
- expect(doesASatisfyB(rangeD, rangeB)).toBeTruthy();
573
- expect(doesASatisfyB(rangeB, rangeE)).toBeTruthy();
574
- expect(doesASatisfyB(rangeE, rangeB)).toBeTruthy();
575
- expect(doesASatisfyB(rangeB, rangeF)).toBeTruthy();
576
- expect(doesASatisfyB(rangeF, rangeB)).toBeTruthy();
577
- expect(doesASatisfyB(rangeB, rangeG)).toBeTruthy();
578
- expect(doesASatisfyB(rangeG, rangeB)).toBeTruthy();
579
- expect(doesASatisfyB(rangeC, rangeD)).toBeTruthy();
580
- expect(doesASatisfyB(rangeD, rangeC)).toBeTruthy();
581
- expect(doesASatisfyB(rangeC, rangeE)).toBeTruthy();
582
- expect(doesASatisfyB(rangeE, rangeC)).toBeTruthy();
583
- expect(doesASatisfyB(rangeC, rangeF)).toBeTruthy();
584
- expect(doesASatisfyB(rangeF, rangeC)).toBeTruthy();
585
- expect(doesASatisfyB(rangeC, rangeG)).toBeTruthy();
586
- expect(doesASatisfyB(rangeG, rangeC)).toBeTruthy();
587
- expect(doesASatisfyB(rangeD, rangeE)).toBeTruthy();
588
- expect(doesASatisfyB(rangeE, rangeD)).toBeTruthy();
589
- expect(doesASatisfyB(rangeD, rangeF)).toBeTruthy();
590
- expect(doesASatisfyB(rangeF, rangeD)).toBeTruthy();
591
- expect(doesASatisfyB(rangeD, rangeG)).toBeTruthy();
592
- expect(doesASatisfyB(rangeG, rangeD)).toBeTruthy();
593
- expect(doesASatisfyB(rangeE, rangeF)).toBeTruthy();
594
- expect(doesASatisfyB(rangeF, rangeE)).toBeTruthy();
595
- expect(doesASatisfyB(rangeE, rangeG)).toBeTruthy();
596
- expect(doesASatisfyB(rangeG, rangeE)).toBeTruthy();
597
- expect(doesASatisfyB(rangeF, rangeG)).toBeTruthy();
598
- expect(doesASatisfyB(rangeG, rangeF)).toBeTruthy();
599
- });
600
- it("version missing in union", async () => {
601
- const version = "14";
602
- const versionVersionUnion = "15 || 16";
603
- expect(doesASatisfyB(version, versionVersionUnion)).toBeFalsy();
604
- expect(doesASatisfyB(versionVersionUnion, version)).toBeFalsy();
605
- });
606
- it("range missing in union", async () => {
607
- const range = "^14";
608
- const versionVersionUnion = "15 || 16";
609
- expect(doesASatisfyB(range, versionVersionUnion)).toBeFalsy();
610
- expect(doesASatisfyB(versionVersionUnion, range)).toBeFalsy();
611
- const versionRangeUnion = "15 || ^16";
612
- expect(doesASatisfyB(range, versionRangeUnion)).toBeFalsy();
613
- expect(doesASatisfyB(versionRangeUnion, range)).toBeFalsy();
614
- const rangeRangeUnion = "^15 || ^16";
615
- expect(doesASatisfyB(range, rangeRangeUnion)).toBeFalsy();
616
- expect(doesASatisfyB(rangeRangeUnion, range)).toBeFalsy();
617
- });
618
- });
619
- describe("Determines dependencies intersections correctly", () => {
620
- it("equivalence", () => {
621
- const exactVersion = "15.1.0";
622
- expect(findIntersection(exactVersion, exactVersion)).toEqual(exactVersion);
623
- const majorVersion1 = "^15";
624
- expect(findIntersection(majorVersion1, majorVersion1)).toEqual(majorVersion1);
625
- const majorVersion2 = "^15.2";
626
- expect(findIntersection(majorVersion2, majorVersion2)).toEqual(majorVersion2);
627
- const greaterOrEqualVersion = ">=1";
628
- expect(findIntersection(greaterOrEqualVersion, greaterOrEqualVersion)).toEqual(greaterOrEqualVersion);
629
- });
630
- it("exact vs any", () => {
631
- const exactVersion = "15.1.0";
632
- const anyVersion = "*";
633
- expect(findIntersection(exactVersion, anyVersion)).toEqual(exactVersion);
634
- expect(findIntersection(anyVersion, exactVersion)).toEqual(exactVersion);
635
- });
636
- it("major vs any", () => {
637
- const majorVersion = "^15";
638
- const anyVersion = "*";
639
- expect(findIntersection(majorVersion, anyVersion)).toEqual(majorVersion);
640
- expect(findIntersection(anyVersion, majorVersion)).toEqual(majorVersion);
641
- });
642
- it("greater or equal vs any", () => {
643
- const greaterOrEqualVersion = ">=15";
644
- const anyVersion = "*";
645
- expect(findIntersection(greaterOrEqualVersion, anyVersion)).toEqual(greaterOrEqualVersion);
646
- expect(findIntersection(anyVersion, greaterOrEqualVersion)).toEqual(greaterOrEqualVersion);
647
- });
648
- it("any vs any", () => {
649
- const anyVersion = "*";
650
- expect(findIntersection(anyVersion, anyVersion)).toEqual(anyVersion);
651
- });
652
- it("exact vs greater or equal", () => {
653
- const exactVersion = "15.1.0";
654
- const greaterOrEqualVersion1 = ">=1";
655
- expect(findIntersection(exactVersion, greaterOrEqualVersion1)).toEqual(exactVersion);
656
- expect(findIntersection(greaterOrEqualVersion1, exactVersion)).toEqual(exactVersion);
657
- const greaterOrEqualVersion2 = ">=15";
658
- expect(findIntersection(exactVersion, greaterOrEqualVersion2)).toEqual(exactVersion);
659
- expect(findIntersection(greaterOrEqualVersion2, exactVersion)).toEqual(exactVersion);
660
- const greaterOrEqualVersion3 = ">=100";
661
- expect(findIntersection(exactVersion, greaterOrEqualVersion3)).toBeUndefined();
662
- expect(findIntersection(greaterOrEqualVersion3, exactVersion)).toBeUndefined();
663
- });
664
- it("major vs greater or equal", () => {
665
- const majorVersion = "^15";
666
- const greaterOrEqualVersion1 = ">=1";
667
- expect(findIntersection(majorVersion, greaterOrEqualVersion1)).toEqual(majorVersion);
668
- expect(findIntersection(greaterOrEqualVersion1, majorVersion)).toEqual(majorVersion);
669
- const greaterOrEqualVersion2 = ">=15";
670
- expect(findIntersection(majorVersion, greaterOrEqualVersion2)).toEqual(majorVersion);
671
- expect(findIntersection(greaterOrEqualVersion2, majorVersion)).toEqual(majorVersion);
672
- const greaterOrEqualVersion3 = ">=100";
673
- expect(findIntersection(majorVersion, greaterOrEqualVersion3)).toBeUndefined();
674
- expect(findIntersection(greaterOrEqualVersion3, majorVersion)).toBeUndefined();
675
- const greaterOrEqualVersion4 = ">=15.2.3";
676
- expect(findIntersection(majorVersion, greaterOrEqualVersion4)).toEqual("^15.2.3");
677
- expect(findIntersection(greaterOrEqualVersion4, majorVersion)).toEqual("^15.2.3");
678
- });
679
- it("greater or equal vs greater or equal", () => {
680
- const greaterOrEqualVersion1 = ">=1";
681
- const greaterOrEqualVersion2 = ">=15";
682
- expect(findIntersection(greaterOrEqualVersion1, greaterOrEqualVersion2)).toEqual(greaterOrEqualVersion2);
683
- expect(findIntersection(greaterOrEqualVersion2, greaterOrEqualVersion1)).toEqual(greaterOrEqualVersion2);
684
- });
685
- it("exact vs major", () => {
686
- expect(findIntersection("15.1.0", "^15")).toEqual("15.1.0");
687
- const exactVersion = "15.1.0";
688
- const majorVersion1 = "^15";
689
- expect(findIntersection(exactVersion, majorVersion1)).toEqual(exactVersion);
690
- expect(findIntersection(majorVersion1, exactVersion)).toEqual(exactVersion);
691
- const majorVersion2 = "^14";
692
- expect(findIntersection(exactVersion, majorVersion2)).toBeUndefined();
693
- expect(findIntersection(majorVersion2, exactVersion)).toBeUndefined();
694
- const majorVersion3 = "^16";
695
- expect(findIntersection(exactVersion, majorVersion3)).toBeUndefined();
696
- expect(findIntersection(majorVersion3, exactVersion)).toBeUndefined();
697
- });
698
- it("major vs major", () => {
699
- const majorVersion1 = "^15";
700
- const majorVersion2 = "^15.2";
701
- expect(findIntersection(majorVersion1, majorVersion2)).toEqual(majorVersion2);
702
- expect(findIntersection(majorVersion2, majorVersion1)).toEqual(majorVersion2);
703
- const majorVersion3 = "15";
704
- expect(findIntersection(majorVersion3, majorVersion2)).toEqual(majorVersion2);
705
- expect(findIntersection(majorVersion2, majorVersion3)).toEqual(majorVersion2);
706
- const majorVersion4 = "16";
707
- expect(findIntersection(majorVersion4, majorVersion2)).toBeUndefined();
708
- expect(findIntersection(majorVersion2, majorVersion4)).toBeUndefined();
709
- });
710
- it("exact vs union", () => {
711
- const exactVersion = "15.1.0";
712
- const unionVersion1 = "^15 || ^16";
713
- expect(findIntersection(exactVersion, unionVersion1)).toEqual(exactVersion);
714
- expect(findIntersection(unionVersion1, exactVersion)).toEqual(exactVersion);
715
- const unionVersion2 = "^14 || ^15";
716
- expect(findIntersection(exactVersion, unionVersion2)).toEqual(exactVersion);
717
- expect(findIntersection(unionVersion2, exactVersion)).toEqual(exactVersion);
718
- const unionVersion3 = "^16 || ^17";
719
- expect(findIntersection(exactVersion, unionVersion3)).toBeUndefined();
720
- expect(findIntersection(unionVersion3, exactVersion)).toBeUndefined();
721
- });
722
- it("major vs union", () => {
723
- const majorVersion = "^15.2";
724
- const unionVersion1 = "^15 || ^16";
725
- expect(findIntersection(majorVersion, unionVersion1)).toEqual(majorVersion);
726
- expect(findIntersection(unionVersion1, majorVersion)).toEqual(majorVersion);
727
- const unionVersion2 = "^14 || ^15";
728
- expect(findIntersection(majorVersion, unionVersion2)).toEqual(majorVersion);
729
- expect(findIntersection(unionVersion2, majorVersion)).toEqual(majorVersion);
730
- const unionVersion3 = "^16 || ^17";
731
- expect(findIntersection(majorVersion, unionVersion3)).toBeUndefined();
732
- expect(findIntersection(unionVersion3, majorVersion)).toBeUndefined();
733
- });
734
- it("union vs union", () => {
735
- const unionVersion1 = "^15.2 || ^16";
736
- const unionVersion2 = "^15 || ^16";
737
- expect(findIntersection(unionVersion1, unionVersion2)).toEqual("^15.2 || ^16");
738
- expect(findIntersection(unionVersion2, unionVersion1)).toEqual("^15.2 || ^16");
739
- const unionVersion3 = "^15 || ^16.4";
740
- expect(findIntersection(unionVersion1, unionVersion3)).toEqual("^15.2 || ^16.4");
741
- expect(findIntersection(unionVersion3, unionVersion1)).toEqual("^15.2 || ^16.4");
742
- const unionVersion4 = "14 || 15";
743
- expect(findIntersection(unionVersion1, unionVersion4)).toEqual("^15.2");
744
- expect(findIntersection(unionVersion4, unionVersion1)).toEqual("^15.2");
745
- const unionVersion5 = "14 || ^15.6";
746
- expect(findIntersection(unionVersion1, unionVersion5)).toEqual("^15.6");
747
- expect(findIntersection(unionVersion5, unionVersion1)).toEqual("^15.6");
748
- const unionVersion6 = "13 || 14";
749
- expect(findIntersection(unionVersion1, unionVersion6)).toBeUndefined();
750
- expect(findIntersection(unionVersion6, unionVersion1)).toBeUndefined();
751
- });
752
- });
753
- it("Flags overloaded dependency (entry in regular dependencies and peer dependencies)", async () => {
754
- const { addErrorSpy, check, host } = makeWorkspace();
755
- const testPackageJson = {
756
- name: "test",
757
- dependencies: {
758
- greatLib: "^15",
759
- },
760
- peerDependencies: {
761
- greatLib: "15",
762
- },
763
- };
764
- addPackageJson(host, "./package.json", testPackageJson);
765
- const greatLibPackageJson = {
766
- name: "greatLib",
767
- };
768
- addPackageJson(host, "./node_modules/greatLib/package.json", greatLibPackageJson);
769
- check({});
770
- expect(addErrorSpy).toHaveBeenCalledTimes(1);
771
- expect(addErrorSpy.mock.calls[0][0].message).toEqual(`[0] Package ${testPackageJson.name} has overloaded greatLib dependencies.\n\t` +
772
- `Peer dependency '${testPackageJson.peerDependencies.greatLib}' and regular dependency '${testPackageJson.dependencies.greatLib}'.`);
773
- });
774
- it("Flags conflicting peer dependencies", async () => {
775
- const { addErrorSpy, check, host } = makeWorkspace();
776
- const testPackageJson = {
777
- name: "test",
778
- dependencies: {
779
- aaa: "0.0.1",
780
- bbb: "0.0.1",
781
- },
782
- peerDependencies: {
783
- greatLib: "15",
784
- greatestLib: "100",
785
- },
786
- devDependencies: {
787
- ccc: "0.0.1",
788
- },
789
- };
790
- addPackageJson(host, "./package.json", testPackageJson);
791
- const aaaPackageJson = {
792
- name: "a",
793
- peerDependencies: {
794
- greatLib: "15",
795
- greatestLib: "100",
796
- },
797
- };
798
- addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
799
- const bbbPackageJson = {
800
- name: "b",
801
- peerDependencies: {
802
- greatLib: "16",
803
- },
804
- };
805
- addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
806
- const cccPackageJson = {
807
- name: "c",
808
- peerDependencies: {
809
- greatestLib: "200",
810
- },
811
- };
812
- addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
813
- check({});
814
- expect(addErrorSpy).toHaveBeenCalledTimes(1);
815
- expect(addErrorSpy.mock.calls[0][0].message).toEqual(`[1] Package ${testPackageJson.name} has conflicting inherited greatLib peer dependencies.\n\t` +
816
- `Dependency ${bbbPackageJson.name} requires '${bbbPackageJson.peerDependencies.greatLib}' but\n\t` +
817
- `Dependency ${aaaPackageJson.name} requires '${aaaPackageJson.peerDependencies.greatLib}'.`);
818
- addErrorSpy.mockReset();
819
- check({ enforceForDevDependencies: true });
820
- expect(addErrorSpy).toHaveBeenCalledTimes(2);
821
- expect(addErrorSpy.mock.calls[1][0].message).toEqual(`[1] Package ${testPackageJson.name} has conflicting inherited greatestLib peer dependencies.\n\t` +
822
- `Dependency ${cccPackageJson.name} requires '${cccPackageJson.peerDependencies.greatestLib}' but\n\t` +
823
- `Dependency ${aaaPackageJson.name} requires '${aaaPackageJson.peerDependencies.greatestLib}'.`);
824
- addErrorSpy.mockReset();
825
- });
826
- it("Flags unsatisfied peer dependencies (test package has regular dep)", async () => {
827
- const { addErrorSpy, check, host } = makeWorkspace();
828
- const testPackageJson = {
829
- name: "test",
830
- dependencies: {
831
- aaa: "0.0.1",
832
- bbb: "0.0.1",
833
- greatLib: "^15",
834
- },
835
- devDependencies: {
836
- ccc: "0.0.1",
837
- },
838
- };
839
- addPackageJson(host, "./package.json", testPackageJson);
840
- const greatLibPackageJson = {
841
- name: "greatLib",
842
- };
843
- addPackageJson(host, "./node_modules/greatLib/package.json", greatLibPackageJson);
844
- const aaaPackageJson = {
845
- name: "a",
846
- peerDependencies: {
847
- greatLib: "^15.2 || ^16",
848
- },
849
- };
850
- addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
851
- const bbbPackageJson = {
852
- name: "b",
853
- peerDependencies: {
854
- greatLib: "^15.2.3 || ^16",
855
- },
856
- };
857
- addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
858
- const cccPackageJson = {
859
- name: "c",
860
- peerDependencies: {
861
- greatLib: "^15.8",
862
- },
863
- };
864
- addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
865
- check({});
866
- expect(addErrorSpy).toHaveBeenCalledTimes(1);
867
- expect(addErrorSpy.mock.calls[0][0].message).toEqual(`[2] Package ${testPackageJson.name} dependency on greatLib '${testPackageJson.dependencies.greatLib}' does not satisfy inherited peer dependencies.\n\t` +
868
- `Dependency ${bbbPackageJson.name} requires '${bbbPackageJson.peerDependencies.greatLib}'.`);
869
- addErrorSpy.mockReset();
870
- check({ enforceForDevDependencies: true });
871
- expect(addErrorSpy).toHaveBeenCalledTimes(1);
872
- expect(addErrorSpy.mock.calls[0][0].message).toEqual(`[2] Package ${testPackageJson.name} dependency on greatLib '${testPackageJson.dependencies.greatLib}' does not satisfy inherited peer dependencies.\n\t` +
873
- `Dependency ${cccPackageJson.name} requires '${cccPackageJson.peerDependencies.greatLib}'.`);
874
- addErrorSpy.mockReset();
875
- });
876
- it("Flags missing peer dependencies (NO regular dependency present)", async () => {
877
- const { addErrorSpy, check, host } = makeWorkspace(true);
878
- const testPackageJson = {
879
- name: "test",
880
- dependencies: {
881
- aaa: "0.0.1",
882
- bbb: "0.0.1",
883
- },
884
- devDependencies: {
885
- ccc: "0.0.1",
886
- },
887
- };
888
- const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
889
- const aaaPackageJson = {
890
- name: "a",
891
- peerDependencies: {
892
- greatLib: "15 || ^16.2",
893
- },
894
- };
895
- addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
896
- const bbbPackageJson = {
897
- name: "b",
898
- peerDependencies: {
899
- greatLib: "^16",
900
- },
901
- };
902
- addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
903
- const cccPackageJson = {
904
- name: "c",
905
- peerDependencies: {
906
- greatestLib: "100",
907
- },
908
- };
909
- addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
910
- check({});
911
- expect(addErrorSpy).toHaveBeenCalledTimes(1);
912
- expect(addErrorSpy.mock.calls[0][0].message).toEqual(`[3] Package ${testPackageJson.name} is missing required greatLib dependency.\n\t` +
913
- `Dependencies [${aaaPackageJson.name}, ${bbbPackageJson.name}] require ` +
914
- `['${aaaPackageJson.peerDependencies.greatLib}', '${bbbPackageJson.peerDependencies.greatLib}'] ` +
915
- `respectively, resolving to '^16.2'.`);
916
- expect(readTestPackageJson().peerDependencies.greatLib).toEqual("^16.2");
917
- addErrorSpy.mockReset();
918
- check({ enforceForDevDependencies: true });
919
- expect(addErrorSpy).toHaveBeenCalledTimes(2);
920
- expect(addErrorSpy.mock.calls[1][0].message).toEqual(`[3] Package ${testPackageJson.name} is missing required greatestLib dependency.\n\t` +
921
- `Dependency ${cccPackageJson.name} requires '${cccPackageJson.peerDependencies.greatestLib}'.`);
922
- addErrorSpy.mockReset();
923
- });
924
- it("Flags unsatisfied peer dependencies (test package has peer dep)", async () => {
925
- const { addErrorSpy, check, host } = makeWorkspace(true);
926
- const testPackageJson = {
927
- name: "test",
928
- dependencies: {
929
- aaa: "0.0.1",
930
- bbb: "0.0.1",
931
- },
932
- peerDependencies: {
933
- greatLib: "^15 || ^16",
934
- },
935
- devDependencies: {
936
- ccc: "0.0.1",
937
- },
938
- };
939
- const readTestPackageJson = addPackageJson(host, "./package.json", testPackageJson);
940
- const aaaPackageJson = {
941
- name: "a",
942
- peerDependencies: {
943
- greatLib: "15 || ^16",
944
- },
945
- };
946
- addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
947
- const bbbPackageJson = {
948
- name: "b",
949
- peerDependencies: {
950
- greatLib: "^16",
951
- },
952
- };
953
- addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
954
- const cccPackageJson = {
955
- name: "c",
956
- peerDependencies: {
957
- greatLib: "^16.2",
958
- },
959
- };
960
- addPackageJson(host, "./node_modules/ccc/package.json", cccPackageJson);
961
- check({});
962
- expect(addErrorSpy).toHaveBeenCalledTimes(1);
963
- expect(addErrorSpy.mock.calls[0][0].message).toEqual(`[4] Package ${testPackageJson.name} peer dependency on greatLib '${testPackageJson.peerDependencies.greatLib}' is not strict enough.\n\t` +
964
- `Dependency ${bbbPackageJson.name} requires '${bbbPackageJson.peerDependencies.greatLib}'.`);
965
- expect(readTestPackageJson().peerDependencies.greatLib).toEqual(bbbPackageJson.peerDependencies.greatLib);
966
- addErrorSpy.mockReset();
967
- check({ enforceForDevDependencies: true });
968
- expect(addErrorSpy).toHaveBeenCalledTimes(1);
969
- expect(addErrorSpy.mock.calls[0][0].message).toEqual(`[4] Package ${testPackageJson.name} peer dependency on greatLib '${testPackageJson.peerDependencies.greatLib}' is not strict enough.\n\t` +
970
- `Dependency ${cccPackageJson.name} requires '${cccPackageJson.peerDependencies.greatLib}'.`);
971
- addErrorSpy.mockReset();
972
- });
973
- it("Honors dependencyWhitelist", async () => {
974
- const { addErrorSpy, check, host } = makeWorkspace();
975
- const testPackageJson = {
976
- name: "test",
977
- dependencies: {
978
- aaa: "0.0.1",
979
- bbb: "0.0.1",
980
- greatLib: "^15",
981
- },
982
- peerDependencies: {
983
- startHere: "15",
984
- greatLib: "15",
985
- },
986
- };
987
- addPackageJson(host, "./package.json", testPackageJson);
988
- const startHerePackageJson = {
989
- name: "startHere",
990
- };
991
- addPackageJson(host, "./node_modules/startHere/package.json", startHerePackageJson);
992
- const greatLibPackageJson = {
993
- name: "greatLib",
994
- };
995
- addPackageJson(host, "./node_modules/greatLib/package.json", greatLibPackageJson);
996
- const aaaPackageJson = {
997
- name: "a",
998
- peerDependencies: {
999
- greatLib: "15",
1000
- },
1001
- };
1002
- addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
1003
- const bbbPackageJson = {
1004
- name: "b",
1005
- peerDependencies: {
1006
- greatLib: "16",
1007
- },
1008
- };
1009
- addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
1010
- check({ dependencyWhitelist: ["startHere"] });
1011
- expect(addErrorSpy).toHaveBeenCalledTimes(0);
1012
- check({ dependencyWhitelist: ["startHere", "greatLib"] });
1013
- expect(addErrorSpy).toHaveBeenCalledTimes(2);
1014
- });
1015
- it("Honors dependencyBlacklist", async () => {
1016
- const { addErrorSpy, check, host } = makeWorkspace();
1017
- const testPackageJson = {
1018
- name: "test",
1019
- dependencies: {
1020
- aaa: "0.0.1",
1021
- bbb: "0.0.1",
1022
- greatLib: "^15",
1023
- },
1024
- peerDependencies: {
1025
- startHere: "15",
1026
- greatLib: "15",
1027
- },
1028
- };
1029
- addPackageJson(host, "./package.json", testPackageJson);
1030
- const startHerePackageJson = {
1031
- name: "startHere",
1032
- };
1033
- addPackageJson(host, "./node_modules/startHere/package.json", startHerePackageJson);
1034
- const greatLibPackageJson = {
1035
- name: "greatLib",
1036
- };
1037
- addPackageJson(host, "./node_modules/greatLib/package.json", greatLibPackageJson);
1038
- const aaaPackageJson = {
1039
- name: "a",
1040
- peerDependencies: {
1041
- greatLib: "15",
1042
- },
1043
- };
1044
- addPackageJson(host, "./node_modules/aaa/package.json", aaaPackageJson);
1045
- const bbbPackageJson = {
1046
- name: "b",
1047
- peerDependencies: {
1048
- greatLib: "16",
1049
- },
1050
- };
1051
- addPackageJson(host, "./node_modules/bbb/package.json", bbbPackageJson);
1052
- check({ dependencyBlacklist: ["greatLib"] });
1053
- expect(addErrorSpy).toHaveBeenCalledTimes(0);
1054
- addErrorSpy.mockReset();
1055
- check({ dependencyBlacklist: ["greatLib"], dependencyWhitelist: ["greatLib"] });
1056
- expect(addErrorSpy).toHaveBeenCalledTimes(0);
1057
- addErrorSpy.mockReset();
1058
- check({});
1059
- expect(addErrorSpy).toHaveBeenCalledTimes(2);
1060
- addErrorSpy.mockReset();
1061
- });
1062
- });
1063
- //# sourceMappingURL=mustSatisfyPeerDependencies.spec.js.map