eslint-plugin-node-dependencies 1.3.0 → 2.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.
Files changed (57) hide show
  1. package/README.md +10 -66
  2. package/dist/chunk-C7Uep-_p.mjs +20 -0
  3. package/dist/index.d.mts +28 -0
  4. package/dist/index.mjs +1633 -0
  5. package/dist/worker.d.mts +7 -0
  6. package/dist/worker.mjs +30 -0
  7. package/package.json +17 -11
  8. package/dist/configs/flat/recommended.d.ts +0 -17
  9. package/dist/configs/flat/recommended.js +0 -57
  10. package/dist/configs/recommended.d.ts +0 -9
  11. package/dist/configs/recommended.js +0 -15
  12. package/dist/configs/rules/recommended.d.ts +0 -5
  13. package/dist/configs/rules/recommended.js +0 -9
  14. package/dist/index.d.ts +0 -34
  15. package/dist/index.js +0 -54
  16. package/dist/meta.d.ts +0 -1
  17. package/dist/meta.js +0 -5
  18. package/dist/rules/absolute-version.d.ts +0 -2
  19. package/dist/rules/absolute-version.js +0 -161
  20. package/dist/rules/compat-engines.d.ts +0 -2
  21. package/dist/rules/compat-engines.js +0 -263
  22. package/dist/rules/no-deprecated.d.ts +0 -2
  23. package/dist/rules/no-deprecated.js +0 -63
  24. package/dist/rules/no-dupe-deps.d.ts +0 -2
  25. package/dist/rules/no-dupe-deps.js +0 -90
  26. package/dist/rules/no-restricted-deps.d.ts +0 -2
  27. package/dist/rules/no-restricted-deps.js +0 -259
  28. package/dist/rules/prefer-caret-range-version.d.ts +0 -2
  29. package/dist/rules/prefer-caret-range-version.js +0 -99
  30. package/dist/rules/prefer-tilde-range-version.d.ts +0 -2
  31. package/dist/rules/prefer-tilde-range-version.js +0 -100
  32. package/dist/rules/require-provenance-deps.d.ts +0 -2
  33. package/dist/rules/require-provenance-deps.js +0 -98
  34. package/dist/rules/valid-engines.d.ts +0 -2
  35. package/dist/rules/valid-engines.js +0 -11
  36. package/dist/rules/valid-semver.d.ts +0 -2
  37. package/dist/rules/valid-semver.js +0 -78
  38. package/dist/types.d.ts +0 -51
  39. package/dist/types.js +0 -2
  40. package/dist/utils/ast-utils.d.ts +0 -3
  41. package/dist/utils/ast-utils.js +0 -24
  42. package/dist/utils/index.d.ts +0 -5
  43. package/dist/utils/index.js +0 -72
  44. package/dist/utils/meta.d.ts +0 -30
  45. package/dist/utils/meta.js +0 -269
  46. package/dist/utils/package-json/index.d.ts +0 -1
  47. package/dist/utils/package-json/index.js +0 -17
  48. package/dist/utils/package-json/worker.d.mts +0 -1
  49. package/dist/utils/package-json/worker.mjs +0 -26
  50. package/dist/utils/regexp.d.ts +0 -3
  51. package/dist/utils/regexp.js +0 -20
  52. package/dist/utils/rules.d.ts +0 -2
  53. package/dist/utils/rules.js +0 -28
  54. package/dist/utils/semver-range.d.ts +0 -7
  55. package/dist/utils/semver-range.js +0 -37
  56. package/dist/utils/semver.d.ts +0 -7
  57. package/dist/utils/semver.js +0 -204
@@ -1,269 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || (function () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __importDefault = (this && this.__importDefault) || function (mod) {
36
- return (mod && mod.__esModule) ? mod : { "default": mod };
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.getMetaFromNodeModules = getMetaFromNodeModules;
40
- exports.getMetaFromNpm = getMetaFromNpm;
41
- exports.getEngines = getEngines;
42
- exports.getDependencies = getDependencies;
43
- const module_1 = __importDefault(require("module"));
44
- const path_1 = __importStar(require("path"));
45
- const fs_1 = __importDefault(require("fs"));
46
- const semver_1 = require("./semver");
47
- const semver_2 = require("semver");
48
- const npm_package_arg_1 = __importDefault(require("npm-package-arg"));
49
- const package_json_1 = require("./package-json");
50
- const eslint_compat_utils_1 = require("eslint-compat-utils");
51
- const TTL = 1000 * 60 * 60;
52
- const CACHE_VERSION = 2;
53
- const CACHED_META_ROOT = path_1.default.join(__dirname, `../../.cached_meta`);
54
- function getMetaFromNodeModules(name, ver, options) {
55
- try {
56
- const ownerJsonPath = options.ownerPackageJsonPath || (0, eslint_compat_utils_1.getFilename)(options.context);
57
- const relativeTo = path_1.default.join(ownerJsonPath && path_1.default.isAbsolute(ownerJsonPath)
58
- ? (0, path_1.dirname)(ownerJsonPath)
59
- : (0, eslint_compat_utils_1.getCwd)(options.context), "__placeholder__.js");
60
- const req = module_1.default.createRequire(relativeTo);
61
- const where = req.resolve(`${name}/package.json`);
62
- const pkg = req(where);
63
- if (maybeMeta(pkg)) {
64
- const vr = (0, semver_1.getSemverRange)(ver);
65
- if (typeof pkg.version === "string" &&
66
- (!vr || (0, semver_2.satisfies)(pkg.version, vr))) {
67
- pkg._where = where;
68
- return pkg;
69
- }
70
- }
71
- }
72
- catch (_a) {
73
- }
74
- return null;
75
- }
76
- function getMetaFromNpm(name, ver) {
77
- var _a;
78
- const trimmed = ver.trim();
79
- if (trimmed.startsWith("npm:")) {
80
- let parsed = null;
81
- try {
82
- parsed = (0, npm_package_arg_1.default)(`${trimmed.slice(4).trim()}`);
83
- }
84
- catch (_b) {
85
- }
86
- if (parsed &&
87
- (parsed.type === "range" ||
88
- parsed.type === "version" ||
89
- parsed.type === "tag")) {
90
- return getMetaFromNameAndSpec(parsed.name, (_a = parsed.fetchSpec) === null || _a === void 0 ? void 0 : _a.trim());
91
- }
92
- }
93
- if (trimmed.includes("/") || trimmed.includes(":")) {
94
- return { cache: [], get: () => [] };
95
- }
96
- return getMetaFromNameAndSpec(name, ver.trim());
97
- }
98
- function getMetaFromNameAndSpec(name, verOrTag) {
99
- const cachedFilePath = path_1.default.join(CACHED_META_ROOT, `${name}.json`);
100
- const { cache, get } = getMetaFromName(name, cachedFilePath);
101
- let isTargetVersion;
102
- let hasUnknown = false;
103
- const range = (0, semver_1.getSemverRange)(verOrTag || "*");
104
- if (range) {
105
- isTargetVersion = (meta) => {
106
- if (!meta.version) {
107
- return true;
108
- }
109
- return range.test(meta.version);
110
- };
111
- }
112
- else {
113
- const parsed = npm_package_arg_1.default.resolve(name, verOrTag);
114
- if (parsed.type === "tag") {
115
- isTargetVersion = (meta) => {
116
- var _a;
117
- if (!meta.version) {
118
- return true;
119
- }
120
- const v = (_a = meta["dist-tags"]) === null || _a === void 0 ? void 0 : _a[parsed.fetchSpec];
121
- if (v == null) {
122
- hasUnknown = true;
123
- }
124
- return v === meta.version;
125
- };
126
- }
127
- else {
128
- return {
129
- cache: [],
130
- get: () => null,
131
- };
132
- }
133
- }
134
- if (cache) {
135
- let alive = cache.alive;
136
- if (!alive && range) {
137
- const maxNext = (0, semver_1.maxNextVersion)(range);
138
- if (maxNext) {
139
- alive = cache.data.meta.some((m) => m.version && maxNext.compare(m.version) <= 0);
140
- }
141
- }
142
- const metaList = cache.data.meta.filter(isTargetVersion);
143
- if (alive) {
144
- return {
145
- cache: metaList,
146
- get: () => (hasUnknown ? null : metaList),
147
- };
148
- }
149
- return {
150
- cache: metaList,
151
- get: () => {
152
- var _a, _b;
153
- const list = (_b = (_a = get()) === null || _a === void 0 ? void 0 : _a.filter(isTargetVersion)) !== null && _b !== void 0 ? _b : null;
154
- return hasUnknown && !(list === null || list === void 0 ? void 0 : list.length) ? null : list;
155
- },
156
- };
157
- }
158
- return {
159
- cache: [],
160
- get: () => {
161
- var _a, _b;
162
- const list = (_b = (_a = get()) === null || _a === void 0 ? void 0 : _a.filter(isTargetVersion)) !== null && _b !== void 0 ? _b : null;
163
- return hasUnknown && !(list === null || list === void 0 ? void 0 : list.length) ? null : list;
164
- },
165
- };
166
- }
167
- function getMetaFromName(name, cachedFilePath) {
168
- const cache = getCache();
169
- return {
170
- cache,
171
- get: () => {
172
- return getMetaFromNameWithoutCache(name, cachedFilePath);
173
- },
174
- };
175
- function getCache() {
176
- makeDirs(path_1.default.dirname(cachedFilePath));
177
- if (!fs_1.default.existsSync(cachedFilePath)) {
178
- return null;
179
- }
180
- const data = require(cachedFilePath);
181
- if (!data || data.meta == null) {
182
- return null;
183
- }
184
- if (data.v !== CACHE_VERSION) {
185
- return null;
186
- }
187
- const alive = Boolean((typeof data.expired === "number" && data.expired >= Date.now()) ||
188
- (typeof data.timestamp === "number" &&
189
- data.timestamp + TTL >= Date.now()) ||
190
- (data.meta.length === 1 && data.meta[0].deprecated));
191
- return {
192
- data,
193
- alive,
194
- };
195
- }
196
- }
197
- function getMetaFromNameWithoutCache(name, cachedFilePath) {
198
- let meta = [];
199
- try {
200
- const allMeta = (0, package_json_1.syncPackageJson)(name);
201
- meta = Object.values(allMeta.versions).map((vm) => {
202
- return {
203
- version: vm.version,
204
- engines: vm.engines,
205
- dependencies: vm.dependencies,
206
- peerDependencies: vm.peerDependencies,
207
- optionalDependencies: vm.optionalDependencies,
208
- "dist-tags": allMeta["dist-tags"],
209
- deprecated: vm.deprecated,
210
- dist: vm.dist,
211
- };
212
- });
213
- }
214
- catch (_a) {
215
- return null;
216
- }
217
- const timestamp = Date.now();
218
- const content = {
219
- v: CACHE_VERSION,
220
- meta,
221
- timestamp,
222
- expired: timestamp + Math.floor(Math.random() * 1000 * 60),
223
- };
224
- fs_1.default.writeFileSync(cachedFilePath, JSON.stringify(content));
225
- delete require.cache[cachedFilePath];
226
- return meta;
227
- }
228
- function getEngines(meta) {
229
- if (!maybeMeta(meta)) {
230
- return new Map();
231
- }
232
- return getStrMap(meta.engines);
233
- }
234
- function getDependencies(meta, kind) {
235
- if (!maybeMeta(meta)) {
236
- return new Map();
237
- }
238
- return getStrMap(meta[kind]);
239
- }
240
- function getStrMap(maybeObject) {
241
- const map = new Map();
242
- if (typeof maybeObject !== "object" ||
243
- !maybeObject ||
244
- Array.isArray(maybeObject)) {
245
- return map;
246
- }
247
- for (const [key, val] of Object.entries(maybeObject)) {
248
- if (val != null) {
249
- map.set(key, `${val}`);
250
- }
251
- }
252
- return map;
253
- }
254
- function maybeMeta(json) {
255
- if (typeof json !== "object" || !json || Array.isArray(json)) {
256
- return false;
257
- }
258
- return true;
259
- }
260
- function makeDirs(dir) {
261
- const dirs = [dir];
262
- while (!fs_1.default.existsSync(dirs[0])) {
263
- dirs.unshift(path_1.default.dirname(dirs[0]));
264
- }
265
- dirs.shift();
266
- for (const d of dirs) {
267
- fs_1.default.mkdirSync(d);
268
- }
269
- }
@@ -1 +0,0 @@
1
- export declare const syncPackageJson: (name: string) => import("package-json").AbbreviatedMetadata;
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.syncPackageJson = void 0;
4
- const synckit_1 = require("synckit");
5
- const module_1 = require("module");
6
- exports.syncPackageJson = (0, synckit_1.createSyncFn)(getWorkerPath(), {
7
- timeout: 10000,
8
- });
9
- function getWorkerPath() {
10
- try {
11
- return require.resolve("./worker.mjs");
12
- }
13
- catch (_a) {
14
- }
15
- const r = (0, module_1.createRequire)(__filename);
16
- return r.resolve("./worker.mts");
17
- }
@@ -1 +0,0 @@
1
- export declare function setupProxy(): void;
@@ -1,26 +0,0 @@
1
- import packageJson from "package-json";
2
- import { runAsWorker } from "synckit";
3
- import { ProxyAgent, setGlobalDispatcher } from "undici";
4
- let proxySet = false;
5
- const PROXY_ENV = [
6
- "https_proxy",
7
- "HTTPS_PROXY",
8
- "http_proxy",
9
- "HTTP_PROXY",
10
- "npm_config_https_proxy",
11
- "npm_config_http_proxy",
12
- ];
13
- export function setupProxy() {
14
- if (proxySet) {
15
- return;
16
- }
17
- proxySet = true;
18
- const proxy = PROXY_ENV.map((k) => process.env[k]).find((v) => v);
19
- if (proxy) {
20
- setGlobalDispatcher(new ProxyAgent(proxy));
21
- }
22
- }
23
- runAsWorker((packageName) => {
24
- setupProxy();
25
- return packageJson(packageName, { allVersions: true });
26
- });
@@ -1,3 +0,0 @@
1
- export declare function toRegExp(str: string): {
2
- test(s: string): boolean;
3
- };
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toRegExp = toRegExp;
4
- function toRegExp(str) {
5
- const regexp = parseRegExp(str);
6
- if (regexp) {
7
- return regexp;
8
- }
9
- return { test: (s) => s === str };
10
- }
11
- function parseRegExp(str) {
12
- if (!str.startsWith("/")) {
13
- return null;
14
- }
15
- const lastSlashIndex = str.lastIndexOf("/");
16
- if (lastSlashIndex <= 1) {
17
- return null;
18
- }
19
- return new RegExp(str.slice(1, lastSlashIndex), str.slice(lastSlashIndex + 1));
20
- }
@@ -1,2 +0,0 @@
1
- import type { RuleModule } from "../types";
2
- export declare const rules: RuleModule[];
@@ -1,28 +0,0 @@
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.rules = void 0;
7
- const absolute_version_1 = __importDefault(require("../rules/absolute-version"));
8
- const compat_engines_1 = __importDefault(require("../rules/compat-engines"));
9
- const no_deprecated_1 = __importDefault(require("../rules/no-deprecated"));
10
- const no_dupe_deps_1 = __importDefault(require("../rules/no-dupe-deps"));
11
- const no_restricted_deps_1 = __importDefault(require("../rules/no-restricted-deps"));
12
- const prefer_caret_range_version_1 = __importDefault(require("../rules/prefer-caret-range-version"));
13
- const prefer_tilde_range_version_1 = __importDefault(require("../rules/prefer-tilde-range-version"));
14
- const require_provenance_deps_1 = __importDefault(require("../rules/require-provenance-deps"));
15
- const valid_engines_1 = __importDefault(require("../rules/valid-engines"));
16
- const valid_semver_1 = __importDefault(require("../rules/valid-semver"));
17
- exports.rules = [
18
- absolute_version_1.default,
19
- compat_engines_1.default,
20
- no_deprecated_1.default,
21
- no_dupe_deps_1.default,
22
- no_restricted_deps_1.default,
23
- prefer_caret_range_version_1.default,
24
- prefer_tilde_range_version_1.default,
25
- require_provenance_deps_1.default,
26
- valid_engines_1.default,
27
- valid_semver_1.default,
28
- ];
@@ -1,7 +0,0 @@
1
- import type { Comparator } from "semver";
2
- export type RangeResult = {
3
- value: string;
4
- comparators: readonly Comparator[];
5
- range: readonly [number, number];
6
- };
7
- export declare function iterateSemverRanges(versionRanges: string): Iterable<RangeResult>;
@@ -1,37 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.iterateSemverRanges = iterateSemverRanges;
4
- const semver_1 = require("./semver");
5
- function* iterateSemverRanges(versionRanges) {
6
- let startOffset = 0;
7
- for (const strRange of versionRanges.split("||")) {
8
- const result = toRangeResult(strRange, startOffset);
9
- if (result) {
10
- yield result;
11
- }
12
- startOffset += strRange.length + 2;
13
- }
14
- }
15
- function toRangeResult(strRange, startOffset) {
16
- let start = 0;
17
- while (strRange.length > start && !strRange[start].trim()) {
18
- start++;
19
- }
20
- let end = strRange.length;
21
- while (end > start && !strRange[end - 1].trim()) {
22
- end--;
23
- }
24
- const value = strRange.slice(start, end);
25
- const range = (0, semver_1.getSemverRange)(value);
26
- if (!range) {
27
- return null;
28
- }
29
- if (range.set.length !== 1) {
30
- return null;
31
- }
32
- return {
33
- value,
34
- comparators: range.set[0],
35
- range: [startOffset + start, startOffset + end],
36
- };
37
- }
@@ -1,7 +0,0 @@
1
- import type { Comparator } from "semver";
2
- import { Range, SemVer } from "semver";
3
- export declare function getSemverRange(value: string | undefined | null): Range | null;
4
- export declare function normalizeVer(ver: Range): string;
5
- export declare function normalizeSemverRange(...values: Range[]): Range | null;
6
- export declare function maxNextVersion(range: Range): SemVer | null;
7
- export declare function isAnyComparator(comparator: Comparator): boolean;
@@ -1,204 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getSemverRange = getSemverRange;
4
- exports.normalizeVer = normalizeVer;
5
- exports.normalizeSemverRange = normalizeSemverRange;
6
- exports.maxNextVersion = maxNextVersion;
7
- exports.isAnyComparator = isAnyComparator;
8
- const semver_1 = require("semver");
9
- function getSemverRange(value) {
10
- if (value == null) {
11
- return null;
12
- }
13
- try {
14
- return new semver_1.Range(value);
15
- }
16
- catch (_a) {
17
- return null;
18
- }
19
- }
20
- function normalizeVer(ver) {
21
- const n = normalizeSemverRange(ver);
22
- if (n) {
23
- return n.raw;
24
- }
25
- return ver.raw;
26
- }
27
- function normalizeSemverRange(...values) {
28
- const map = new Map();
29
- for (const ver of values) {
30
- for (const comparators of ver.set) {
31
- const normalized = normalizeComparators(comparators);
32
- if (map.has(normalized)) {
33
- continue;
34
- }
35
- const normalizedVer = getSemverRange(normalized);
36
- if (!normalizedVer) {
37
- continue;
38
- }
39
- let consume = false;
40
- let target = { range: normalizedVer, comparators };
41
- for (const [k, data] of map) {
42
- if ((0, semver_1.subset)(target.range, data.range)) {
43
- consume = true;
44
- break;
45
- }
46
- if ((0, semver_1.subset)(data.range, target.range)) {
47
- map.delete(k);
48
- }
49
- if ((0, semver_1.intersects)(target.range, data.range)) {
50
- const newComparators = joinComparators(comparators, data.comparators);
51
- if (newComparators) {
52
- target = {
53
- range: new semver_1.Range(normalizeComparators(newComparators)),
54
- comparators: newComparators,
55
- };
56
- map.delete(k);
57
- }
58
- }
59
- }
60
- if (consume) {
61
- continue;
62
- }
63
- map.set(target.range.raw, target);
64
- }
65
- }
66
- const ranges = [...map]
67
- .sort(([, a], [, b]) => {
68
- const aVer = getMinVer(a.comparators);
69
- const bVer = getMinVer(b.comparators);
70
- return aVer.compare(bVer);
71
- })
72
- .map(([v]) => v);
73
- return getSemverRange(ranges.join("||"));
74
- function getMinVer(comparators) {
75
- let min = null;
76
- for (const comp of comparators) {
77
- if (!min || comp.semver.compare(min) < 0) {
78
- min = comp.semver;
79
- }
80
- }
81
- return min;
82
- }
83
- }
84
- function normalizeComparators(comparators) {
85
- const rangeComparator = toRangeComparator(comparators);
86
- if (rangeComparator && rangeComparator.min && rangeComparator.max) {
87
- if (rangeComparator.min.operator === ">=" &&
88
- rangeComparator.max.operator === "<") {
89
- if (rangeComparator.min.semver.major !== 0 &&
90
- (0, semver_1.inc)(rangeComparator.min.semver.version, "premajor") ===
91
- rangeComparator.max.semver.version)
92
- return `^${rangeComparator.min.semver.version}`;
93
- if ((0, semver_1.inc)(rangeComparator.min.semver.version, "preminor") ===
94
- rangeComparator.max.semver.version)
95
- return `~${rangeComparator.min.semver.version}`;
96
- }
97
- }
98
- return comparators.map(normalizeComparator).join(" ");
99
- }
100
- function normalizeComparator(comparator) {
101
- if (comparator.operator === "") {
102
- return comparator.value || "*";
103
- }
104
- return comparator.value;
105
- }
106
- function joinComparators(a, b) {
107
- const aRangeComparator = toRangeComparator(a);
108
- const bRangeComparator = toRangeComparator(b);
109
- if (aRangeComparator && bRangeComparator) {
110
- const comparators = [];
111
- if (aRangeComparator.min && bRangeComparator.min) {
112
- comparators.push(aRangeComparator.min.semver.compare(bRangeComparator.min.semver) <= 0
113
- ? aRangeComparator.min
114
- : bRangeComparator.min);
115
- }
116
- if (aRangeComparator.max && bRangeComparator.max) {
117
- comparators.push(aRangeComparator.max.semver.compare(bRangeComparator.max.semver) >= 0
118
- ? aRangeComparator.max
119
- : bRangeComparator.max);
120
- }
121
- if (comparators.length === 0) {
122
- return new semver_1.Range("*").set[0];
123
- }
124
- return comparators;
125
- }
126
- return null;
127
- }
128
- function toRangeComparator(comparators) {
129
- if (comparators.length === 2) {
130
- if (comparators[0].operator === ">" || comparators[0].operator === ">=") {
131
- if (comparators[1].operator === "<" || comparators[1].operator === "<=") {
132
- return {
133
- min: comparators[0],
134
- max: comparators[1],
135
- };
136
- }
137
- }
138
- else if (comparators[0].operator === "<" ||
139
- comparators[0].operator === "<=") {
140
- if (comparators[1].operator === ">" || comparators[1].operator === ">=") {
141
- return {
142
- min: comparators[1],
143
- max: comparators[0],
144
- };
145
- }
146
- }
147
- }
148
- if (comparators.length === 1) {
149
- if (comparators[0].operator === ">" || comparators[0].operator === ">=") {
150
- return {
151
- min: comparators[0],
152
- max: null,
153
- };
154
- }
155
- else if (comparators[0].operator === "<" ||
156
- comparators[0].operator === "<=") {
157
- return {
158
- min: null,
159
- max: comparators[0],
160
- };
161
- }
162
- }
163
- return null;
164
- }
165
- function maxNextVersion(range) {
166
- let maxVer = null;
167
- for (const comparators of range.set) {
168
- let max = null;
169
- let hasMin = false;
170
- for (const comparator of comparators) {
171
- if (isAnyComparator(comparator)) {
172
- return null;
173
- }
174
- const compVer = new semver_1.SemVer(comparator.semver.version);
175
- if (comparator.operator === "<=" ||
176
- comparator.operator === "<" ||
177
- comparator.operator === "") {
178
- if (comparator.operator === "<=") {
179
- compVer.inc("prerelease");
180
- }
181
- if (!max || (0, semver_1.lt)(max, compVer)) {
182
- max = compVer;
183
- }
184
- }
185
- else if (comparator.operator === ">=" || comparator.operator === ">") {
186
- hasMin = true;
187
- }
188
- }
189
- if (max) {
190
- if (!maxVer || (0, semver_1.lt)(maxVer, max)) {
191
- maxVer = max;
192
- }
193
- }
194
- else {
195
- if (hasMin) {
196
- return null;
197
- }
198
- }
199
- }
200
- return maxVer;
201
- }
202
- function isAnyComparator(comparator) {
203
- return !comparator.semver.version;
204
- }