syncpack 9.0.0 → 9.1.2

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 (32) hide show
  1. package/README.md +24 -764
  2. package/dist/bin-fix-mismatches/fix-mismatches.js +16 -39
  3. package/dist/bin-lint-semver-ranges/lint-semver-ranges.js +2 -5
  4. package/dist/bin-list/list.js +33 -17
  5. package/dist/bin-list-mismatches/list-mismatches.js +59 -30
  6. package/dist/bin-set-semver-ranges/set-semver-ranges.js +1 -1
  7. package/dist/get-context/get-groups/base-group.d.ts +19 -0
  8. package/dist/get-context/get-groups/base-group.js +40 -0
  9. package/dist/get-context/get-groups/index.d.ts +8 -0
  10. package/dist/get-context/get-groups/index.js +47 -0
  11. package/dist/get-context/get-groups/semver-group.d.ts +16 -0
  12. package/dist/get-context/get-groups/semver-group.js +89 -0
  13. package/dist/get-context/get-groups/version-group/index.d.ts +9 -26
  14. package/dist/get-context/get-groups/version-group/index.js +67 -15
  15. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +10 -20
  16. package/dist/get-context/get-groups/version-group/instance-group/index.js +49 -53
  17. package/dist/get-context/get-package-json-files/get-file-paths.js +2 -1
  18. package/dist/get-context/get-package-json-files/package-json-file/index.js +3 -2
  19. package/dist/get-context/get-package-json-files/package-json-file/instance.d.ts +2 -5
  20. package/dist/get-context/get-package-json-files/package-json-file/instance.js +3 -19
  21. package/dist/get-context/index.js +2 -4
  22. package/dist/lib/print-strings.d.ts +1 -0
  23. package/dist/lib/print-strings.js +7 -0
  24. package/dist/option.d.ts +1 -1
  25. package/dist/option.js +1 -0
  26. package/package.json +3 -1
  27. package/dist/get-context/get-groups/get-semver-groups.d.ts +0 -4
  28. package/dist/get-context/get-groups/get-semver-groups.js +0 -46
  29. package/dist/get-context/get-groups/get-version-groups.d.ts +0 -4
  30. package/dist/get-context/get-groups/get-version-groups.js +0 -72
  31. package/dist/get-context/get-groups/semver-group/index.d.ts +0 -29
  32. package/dist/get-context/get-groups/semver-group/index.js +0 -56
@@ -2,33 +2,23 @@ import type { VersionGroup } from '..';
2
2
  import type { Instance } from '../../../get-package-json-files/package-json-file/instance';
3
3
  /** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
4
4
  export declare class InstanceGroup {
5
- /** 1+ `Instance` has a version which does not follow the rules */
6
- hasMismatches: boolean;
7
5
  /** Every package/pathName location where this dependency was found */
8
6
  instances: Instance[];
9
- /** */
10
- hasWorkspaceInstance: boolean;
11
- /** Syncpack must report or fix this groups mismatches */
12
- isInvalid: boolean;
13
- /** 1+ `Instance` has a version not matching `VersionGroup.pinVersion` */
14
- isUnpinned: boolean;
15
7
  /** @example `"lodash"` */
16
8
  name: string;
17
- /** All `Instance` versions, with duplicates removed */
18
- uniques: string[];
19
9
  /** The `VersionGroup` which this `InstanceGroup` belongs to */
20
10
  versionGroup: VersionGroup;
21
11
  constructor(versionGroup: VersionGroup, name: string, instances: Instance[]);
12
+ hasUnsupportedVersion(): boolean;
13
+ getUniqueVersions(): string[];
14
+ hasMismatchingVersions(): boolean;
15
+ isInvalid(): boolean;
22
16
  getExpectedVersion(): string | undefined;
23
- getPinnedVersion(): string;
24
- /**
25
- * If this dependency is a package developed locally, we should use its
26
- * version as the source of truth.
27
- */
28
- getWorkspaceVersion(): string;
29
- /**
30
- * Find instance of this dependency which is a package developed locally in
31
- * this monorepo.
32
- */
17
+ getHighestVersion(): string;
18
+ isUnpinned(): boolean;
19
+ /** Get version of dependency which is developed in this monorepo */
20
+ getWorkspaceVersion(): string | undefined;
21
+ /** Find instance of this dependency which is developed in this monorepo */
33
22
  getWorkspaceInstance(): Instance | undefined;
23
+ hasWorkspaceInstance(): boolean;
34
24
  }
@@ -1,80 +1,76 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
2
  exports.__esModule = true;
19
3
  exports.InstanceGroup = void 0;
20
- var expect_more_1 = require("expect-more");
4
+ var error_1 = require("../../../../lib/error");
5
+ var is_semver_1 = require("../../../../lib/is-semver");
6
+ var print_strings_1 = require("../../../../lib/print-strings");
21
7
  var get_highest_version_1 = require("./get-highest-version");
22
8
  /** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
23
9
  var InstanceGroup = /** @class */ (function () {
24
10
  function InstanceGroup(versionGroup, name, instances) {
25
- var pinnedVersion = versionGroup.pinVersion;
26
- var isBanned = versionGroup.isBanned === true;
27
- var isIgnored = versionGroup.isIgnored === true;
28
- var hasPinnedVersion = (0, expect_more_1.isNonEmptyString)(pinnedVersion);
29
- var versions = instances.map(function (_a) {
30
- var version = _a.version;
31
- return version;
32
- });
33
- var uniques = Array.from(new Set(versions)).sort();
34
- var _a = __read(uniques, 1), version = _a[0];
35
- var isUnpinned = hasPinnedVersion && version !== pinnedVersion;
36
- var hasMismatches = isBanned || isUnpinned || uniques.length > 1;
37
- var isInvalid = !isIgnored && hasMismatches;
38
11
  this.instances = instances;
39
- this.hasMismatches = hasMismatches;
40
- this.hasWorkspaceInstance = Boolean(this.getWorkspaceVersion());
41
- this.isInvalid = isInvalid;
42
- this.isUnpinned = isUnpinned;
43
12
  this.name = name;
44
- this.uniques = uniques;
45
13
  this.versionGroup = versionGroup;
46
14
  }
15
+ InstanceGroup.prototype.hasUnsupportedVersion = function () {
16
+ return this.instances.some(function (obj) { return !(0, is_semver_1.isSemver)(obj.version); });
17
+ };
18
+ InstanceGroup.prototype.getUniqueVersions = function () {
19
+ return Array.from(new Set(this.instances.map(function (obj) { return obj.version; }))).sort();
20
+ };
21
+ InstanceGroup.prototype.hasMismatchingVersions = function () {
22
+ return this.getUniqueVersions().length > 1;
23
+ };
24
+ InstanceGroup.prototype.isInvalid = function () {
25
+ return this.versionGroup.isIgnored()
26
+ ? false
27
+ : this.versionGroup.isBanned() ||
28
+ this.versionGroup.isUnpinned() ||
29
+ this.hasMismatchingVersions();
30
+ };
47
31
  InstanceGroup.prototype.getExpectedVersion = function () {
48
- // remove this dependency
49
- if (this.versionGroup.isBanned)
50
- return undefined;
51
- if (this.isUnpinned)
52
- return this.getPinnedVersion();
53
- if (this.hasWorkspaceInstance)
32
+ var versionGroup = this.versionGroup;
33
+ var REMOVE_DEPENDENCY = undefined;
34
+ if (versionGroup.isBanned())
35
+ return REMOVE_DEPENDENCY;
36
+ if (versionGroup.isUnpinned())
37
+ return versionGroup.getPinnedVersion();
38
+ if (this.hasWorkspaceInstance())
54
39
  return this.getWorkspaceVersion();
55
- return (0, get_highest_version_1.getHighestVersion)(this.uniques);
40
+ if (this.hasUnsupportedVersion()) {
41
+ throw new error_1.BaseError("".concat(this.name, " contains unsupported versions: ").concat((0, print_strings_1.printStrings)(this.getUniqueVersions())));
42
+ }
43
+ return this.getHighestVersion();
56
44
  };
57
- InstanceGroup.prototype.getPinnedVersion = function () {
58
- return this.versionGroup.pinVersion || '';
45
+ InstanceGroup.prototype.getHighestVersion = function () {
46
+ return (0, get_highest_version_1.getHighestVersion)(this.getUniqueVersions());
59
47
  };
60
- /**
61
- * If this dependency is a package developed locally, we should use its
62
- * version as the source of truth.
63
- */
48
+ InstanceGroup.prototype.isUnpinned = function () {
49
+ var _this = this;
50
+ return (this.versionGroup.hasPinnedVersion() &&
51
+ this.instances.some(function (_a) {
52
+ var version = _a.version;
53
+ return version !== _this.versionGroup.getPinnedVersion();
54
+ }));
55
+ };
56
+ /** Get version of dependency which is developed in this monorepo */
64
57
  InstanceGroup.prototype.getWorkspaceVersion = function () {
65
58
  var _a;
66
- return ((_a = this.getWorkspaceInstance()) === null || _a === void 0 ? void 0 : _a.packageJsonFile.contents.version) || '';
59
+ if (this.hasWorkspaceInstance()) {
60
+ return (_a = this.getWorkspaceInstance()) === null || _a === void 0 ? void 0 : _a.packageJsonFile.contents.version;
61
+ }
62
+ throw new error_1.BaseError('getWorkspaceVersion invoked when there is none');
67
63
  };
68
- /**
69
- * Find instance of this dependency which is a package developed locally in
70
- * this monorepo.
71
- */
64
+ /** Find instance of this dependency which is developed in this monorepo */
72
65
  InstanceGroup.prototype.getWorkspaceInstance = function () {
73
66
  return this.instances.find(function (_a) {
74
67
  var pathDef = _a.pathDef;
75
68
  return pathDef.name === 'workspace';
76
69
  });
77
70
  };
71
+ InstanceGroup.prototype.hasWorkspaceInstance = function () {
72
+ return this.getWorkspaceInstance() !== undefined;
73
+ };
78
74
  return InstanceGroup;
79
75
  }());
80
76
  exports.InstanceGroup = InstanceGroup;
@@ -5,6 +5,7 @@ var ts_belt_1 = require("@mobily/ts-belt");
5
5
  var expect_more_1 = require("expect-more");
6
6
  var _R_1 = require("../$R");
7
7
  var error_1 = require("../../lib/error");
8
+ var print_strings_1 = require("../../lib/print-strings");
8
9
  var get_patterns_1 = require("./get-patterns");
9
10
  /**
10
11
  * Using --source options and/or config files on disk from npm/pnpm/yarn/lerna,
@@ -16,7 +17,7 @@ var get_patterns_1 = require("./get-patterns");
16
17
  function getFilePaths(disk, program) {
17
18
  return (0, ts_belt_1.pipe)(program, (0, get_patterns_1.getPatterns)(disk), ts_belt_1.R.flatMap(resolvePatterns));
18
19
  function resolvePatterns(patterns) {
19
- var quoted = patterns.map(function (p) { return "\"".concat(p, "\""); }).join(', ');
20
+ var quoted = (0, print_strings_1.printStrings)(patterns);
20
21
  var ERR_NO_MATCH = "No package.json files matched the patterns: ".concat(quoted);
21
22
  return (0, ts_belt_1.pipe)(patterns, _R_1.$R.onlyOk(resolvePattern), ts_belt_1.R.mapError(error_1.BaseError.map(ERR_NO_MATCH)), ts_belt_1.R.map((0, ts_belt_1.flow)(ts_belt_1.A.flat, ts_belt_1.A.uniq, removeReadonlyType)));
22
23
  }
@@ -57,8 +57,9 @@ var PackageJsonFile = /** @class */ (function () {
57
57
  })
58
58
  .filter(function (instance) {
59
59
  var pathDef = instance.pathDef, name = instance.name, version = instance.version;
60
- if (name.search(new RegExp(_this.config.filter)) === -1) {
61
- (0, log_1.verbose)('skip instance, name does not match filter', instance);
60
+ var filter = _this.config.filter;
61
+ if (name.search(new RegExp(filter)) === -1) {
62
+ (0, log_1.verbose)("skip, name \"".concat(name, "\" does not match filter \"").concat(filter, "\""));
62
63
  return false;
63
64
  }
64
65
  (0, log_1.verbose)("add ".concat(name, "@").concat(version, " to ").concat(pathDef.name, ":").concat(pathDef.strategy, " ").concat(_this.shortPath));
@@ -1,7 +1,5 @@
1
1
  import type { PackageJsonFile } from '.';
2
2
  import type { Syncpack } from '../../../types';
3
- import type { SemverGroup } from '../../get-groups/semver-group';
4
- import type { VersionGroup } from '../../get-groups/version-group';
5
3
  export declare class Instance {
6
4
  /** the name of this dependency */
7
5
  name: string;
@@ -14,12 +12,11 @@ export declare class Instance {
14
12
  /** the version of this dependency */
15
13
  version: string;
16
14
  constructor(pathDef: Syncpack.PathDefinition, name: string, packageJsonFile: PackageJsonFile, version: string);
17
- hasRange(range: Syncpack.Config.SemverRange.Value): boolean;
18
- setRange(range: Syncpack.Config.SemverRange.Value): void;
15
+ /** Is this instance the package.json file of this package developed in this repo? */
16
+ isWorkspace(): boolean;
19
17
  /**
20
18
  * In the case of banned dependencies, their version is set to `undefined`,
21
19
  * which causes them to be removed by `JSON.stringify`.
22
20
  */
23
21
  setVersion(version: string | undefined): void;
24
- matchesGroup(group: SemverGroup | VersionGroup): boolean;
25
22
  }
@@ -1,14 +1,8 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  exports.__esModule = true;
6
3
  exports.Instance = void 0;
7
4
  var ts_belt_1 = require("@mobily/ts-belt");
8
- var expect_more_1 = require("expect-more");
9
- var minimatch_1 = __importDefault(require("minimatch"));
10
5
  var _R_1 = require("../../$R");
11
- var set_semver_range_1 = require("../../../lib/set-semver-range");
12
6
  var path_strategy_1 = require("../../get-config/path-strategy");
13
7
  var Instance = /** @class */ (function () {
14
8
  function Instance(pathDef, name, packageJsonFile, version) {
@@ -18,12 +12,9 @@ var Instance = /** @class */ (function () {
18
12
  this.pkgName = packageJsonFile.contents.name || 'PACKAGE_JSON_HAS_NO_NAME';
19
13
  this.version = version;
20
14
  }
21
- Instance.prototype.hasRange = function (range) {
22
- return (this.pathDef.name !== 'workspace' &&
23
- this.version === (0, set_semver_range_1.setSemverRange)(range, this.version));
24
- };
25
- Instance.prototype.setRange = function (range) {
26
- this.setVersion((0, set_semver_range_1.setSemverRange)(range, this.version));
15
+ /** Is this instance the package.json file of this package developed in this repo? */
16
+ Instance.prototype.isWorkspace = function () {
17
+ return this.pathDef.name === 'workspace';
27
18
  };
28
19
  /**
29
20
  * In the case of banned dependencies, their version is set to `undefined`,
@@ -50,13 +41,6 @@ var Instance = /** @class */ (function () {
50
41
  return (0, path_strategy_1.exhaustiveCheck)(strategyName);
51
42
  }
52
43
  };
53
- Instance.prototype.matchesGroup = function (group) {
54
- var _this = this;
55
- return (group.packages.some(function (pattern) { return (0, minimatch_1["default"])(_this.pkgName, pattern); }) &&
56
- group.dependencies.some(function (pattern) { return (0, minimatch_1["default"])(_this.name, pattern); }) &&
57
- (!(0, expect_more_1.isNonEmptyArray)(group.dependencyTypes) ||
58
- group.dependencyTypes.includes(this.pathDef.name)));
59
- };
60
44
  return Instance;
61
45
  }());
62
46
  exports.Instance = Instance;
@@ -15,8 +15,7 @@ exports.getContext = void 0;
15
15
  var disk_1 = require("../lib/disk");
16
16
  var get_all_instances_1 = require("./get-all-instances");
17
17
  var get_config_1 = require("./get-config");
18
- var get_semver_groups_1 = require("./get-groups/get-semver-groups");
19
- var get_version_groups_1 = require("./get-groups/get-version-groups");
18
+ var get_groups_1 = require("./get-groups");
20
19
  var get_package_json_files_1 = require("./get-package-json-files");
21
20
  /**
22
21
  * Every command in syncpack should accept the return value of this function as
@@ -31,8 +30,7 @@ function getContext(program, disk) {
31
30
  var config = (0, get_config_1.getConfig)(disk, program);
32
31
  var packageJsonFiles = (0, get_package_json_files_1.getPackageJsonFiles)(disk, config);
33
32
  var instances = (0, get_all_instances_1.getAllInstances)(packageJsonFiles);
34
- var semverGroups = (0, get_semver_groups_1.getSemverGroups)(config, instances);
35
- var versionGroups = (0, get_version_groups_1.getVersionGroups)(config, instances);
33
+ var _a = (0, get_groups_1.getGroups)(config, instances), semverGroups = _a.semverGroups, versionGroups = _a.versionGroups;
36
34
  return __assign(__assign({}, config), { disk: disk, isInvalid: false, packageJsonFiles: packageJsonFiles, semverGroups: semverGroups, versionGroups: versionGroups });
37
35
  }
38
36
  exports.getContext = getContext;
@@ -0,0 +1 @@
1
+ export declare function printStrings(strings: string[]): string;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.printStrings = void 0;
4
+ function printStrings(strings) {
5
+ return strings.map(function (str) { return "\"".concat(str, "\""); }).join(', ');
6
+ }
7
+ exports.printStrings = printStrings;
package/dist/option.d.ts CHANGED
@@ -3,7 +3,7 @@ export declare const option: {
3
3
  readonly filter: readonly ["-f, --filter [pattern]", string];
4
4
  readonly indent: readonly ["-i, --indent [value]", "override indentation. defaults to \" \""];
5
5
  readonly semverRange: readonly ["-r, --semver-range <range>", "see supported ranges below. defaults to \"\""];
6
- readonly source: readonly ["-s, --source [pattern]", "glob pattern for package.json files to read from", typeof collect];
6
+ readonly source: readonly ["-s, --source [pattern]", "glob pattern for package.json files to read from", typeof collect, string[]];
7
7
  readonly types: readonly ["-t, --types <names>", string];
8
8
  };
9
9
  declare function collect(value: string, previous: string[]): string[];
package/dist/option.js CHANGED
@@ -28,6 +28,7 @@ exports.option = {
28
28
  '-s, --source [pattern]',
29
29
  'glob pattern for package.json files to read from',
30
30
  collect,
31
+ [],
31
32
  ],
32
33
  types: [
33
34
  '-t, --types <names>',
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "syncpack",
3
3
  "description": "Manage multiple package.json files, such as in Lerna Monorepos and Yarn/Pnpm Workspaces",
4
- "version": "9.0.0",
4
+ "version": "9.1.2",
5
5
  "author": "Jamie Mason <jamie@foldleft.io> (https://github.com/JamieMason)",
6
6
  "bin": {
7
7
  "syncpack": "dist/bin.js",
@@ -48,11 +48,13 @@
48
48
  "@typescript-eslint/parser": "5.51.0",
49
49
  "eslint": "8.33.0",
50
50
  "eslint-plugin-import": "2.27.5",
51
+ "eslint-plugin-jest": "27.2.1",
51
52
  "expect-more-jest": "5.5.0",
52
53
  "jest": "29.4.1",
53
54
  "prettier": "2.8.3",
54
55
  "rimraf": "4.1.2",
55
56
  "ts-jest": "29.0.5",
57
+ "ts-node": "10.9.1",
56
58
  "typescript": "4.9.5"
57
59
  },
58
60
  "engines": {
@@ -1,4 +0,0 @@
1
- import type { Syncpack } from '../../types';
2
- import type { Instance } from '../get-package-json-files/package-json-file/instance';
3
- import { SemverGroup } from './semver-group';
4
- export declare function getSemverGroups(input: Syncpack.Config.Private, instances: Instance[]): SemverGroup[];
@@ -1,46 +0,0 @@
1
- "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- exports.__esModule = true;
14
- exports.getSemverGroups = void 0;
15
- var semver_group_1 = require("./semver-group");
16
- function getSemverGroups(input, instances) {
17
- var semverGroups = input.semverGroups.map(function (semverGroup) { return new semver_group_1.SemverGroup(input, semverGroup); });
18
- instances.forEach(function (instance) {
19
- var e_1, _a;
20
- var _b;
21
- var name = instance.name, pkgName = instance.pkgName;
22
- try {
23
- for (var semverGroups_1 = __values(semverGroups), semverGroups_1_1 = semverGroups_1.next(); !semverGroups_1_1.done; semverGroups_1_1 = semverGroups_1.next()) {
24
- var semverGroup = semverGroups_1_1.value;
25
- if (instance.matchesGroup(semverGroup)) {
26
- if (!semverGroup.instancesByName[name]) {
27
- semverGroup.instancesByName[name] = [];
28
- }
29
- (_b = semverGroup.instancesByName[name]) === null || _b === void 0 ? void 0 : _b.push(instance);
30
- semverGroup.instances.push(instance);
31
- return;
32
- }
33
- }
34
- }
35
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
36
- finally {
37
- try {
38
- if (semverGroups_1_1 && !semverGroups_1_1.done && (_a = semverGroups_1["return"])) _a.call(semverGroups_1);
39
- }
40
- finally { if (e_1) throw e_1.error; }
41
- }
42
- throw new Error("".concat(name, " in ").concat(pkgName, " did not match any semverGroups"));
43
- });
44
- return semverGroups;
45
- }
46
- exports.getSemverGroups = getSemverGroups;
@@ -1,4 +0,0 @@
1
- import type { Syncpack } from '../../types';
2
- import type { Instance } from '../get-package-json-files/package-json-file/instance';
3
- import { VersionGroup } from './version-group';
4
- export declare function getVersionGroups(input: Syncpack.Config.Private, instances: Instance[]): VersionGroup[];
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __values = (this && this.__values) || function(o) {
3
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
4
- if (m) return m.call(o);
5
- if (o && typeof o.length === "number") return {
6
- next: function () {
7
- if (o && i >= o.length) o = void 0;
8
- return { value: o && o[i++], done: !o };
9
- }
10
- };
11
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
12
- };
13
- var __read = (this && this.__read) || function (o, n) {
14
- var m = typeof Symbol === "function" && o[Symbol.iterator];
15
- if (!m) return o;
16
- var i = m.call(o), r, ar = [], e;
17
- try {
18
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
- }
20
- catch (error) { e = { error: error }; }
21
- finally {
22
- try {
23
- if (r && !r.done && (m = i["return"])) m.call(i);
24
- }
25
- finally { if (e) throw e.error; }
26
- }
27
- return ar;
28
- };
29
- exports.__esModule = true;
30
- exports.getVersionGroups = void 0;
31
- var version_group_1 = require("./version-group");
32
- var instance_group_1 = require("./version-group/instance-group");
33
- function getVersionGroups(input, instances) {
34
- var versionGroups = input.versionGroups.map(function (versionGroup) { return new version_group_1.VersionGroup(input, versionGroup); });
35
- instances.forEach(function (instance) {
36
- var e_1, _a;
37
- var _b;
38
- var name = instance.name, pkgName = instance.pkgName;
39
- try {
40
- for (var versionGroups_1 = __values(versionGroups), versionGroups_1_1 = versionGroups_1.next(); !versionGroups_1_1.done; versionGroups_1_1 = versionGroups_1.next()) {
41
- var versionGroup = versionGroups_1_1.value;
42
- if (instance.matchesGroup(versionGroup)) {
43
- if (!versionGroup.instancesByName[name]) {
44
- versionGroup.instancesByName[name] = [];
45
- }
46
- (_b = versionGroup.instancesByName[name]) === null || _b === void 0 ? void 0 : _b.push(instance);
47
- versionGroup.instances.push(instance);
48
- return;
49
- }
50
- }
51
- }
52
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
53
- finally {
54
- try {
55
- if (versionGroups_1_1 && !versionGroups_1_1.done && (_a = versionGroups_1["return"])) _a.call(versionGroups_1);
56
- }
57
- finally { if (e_1) throw e_1.error; }
58
- }
59
- throw new Error("".concat(name, " in ").concat(pkgName, " did not match any versionGroups"));
60
- });
61
- versionGroups.forEach(function (versionGroup) {
62
- versionGroup.instanceGroups = getInstanceGroups(versionGroup);
63
- });
64
- return versionGroups;
65
- }
66
- exports.getVersionGroups = getVersionGroups;
67
- function getInstanceGroups(versionGroup) {
68
- return Object.entries(versionGroup.instancesByName).map(function (_a) {
69
- var _b = __read(_a, 2), name = _b[0], instances = _b[1];
70
- return new instance_group_1.InstanceGroup(versionGroup, name, instances);
71
- });
72
- }
@@ -1,29 +0,0 @@
1
- import type { Syncpack } from '../../../types';
2
- import type { Instance } from '../../get-package-json-files/package-json-file/instance';
3
- export declare class SemverGroup {
4
- /** */
5
- dependencies: string[];
6
- /** Optionally limit this group to dependencies at these named paths */
7
- dependencyTypes: Syncpack.TypeName[];
8
- /** */
9
- input: Syncpack.Config.Private;
10
- /** */
11
- instances: Instance[];
12
- /** */
13
- instancesByName: Record<string, Instance[]>;
14
- /** */
15
- isDefault: boolean;
16
- /** Optionally force syncpack to ignore all dependencies in this group */
17
- isIgnored: boolean;
18
- /** */
19
- packages: string[];
20
- /** The semver range which dependencies in this group should use */
21
- range: Syncpack.Config.SemverRange.Value;
22
- constructor(input: Syncpack.Config.Private, semverGroup: Syncpack.Config.SemverGroup.Any);
23
- /** Does this `Instance` not follow the rules of this group? */
24
- isMismatch(instance: Instance): boolean;
25
- /** 1+ `Instance` has a version which does not follow the rules */
26
- hasMismatches(): boolean;
27
- /** Get every `Instance` with a version which does not follow the rules */
28
- getMismatches(): [string, Instance[]][];
29
- }
@@ -1,56 +0,0 @@
1
- "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- exports.__esModule = true;
19
- exports.SemverGroup = void 0;
20
- var SemverGroup = /** @class */ (function () {
21
- function SemverGroup(input, semverGroup) {
22
- this.dependencies = semverGroup.dependencies;
23
- this.dependencyTypes = semverGroup.dependencyTypes;
24
- this.input = input;
25
- this.instances = [];
26
- this.instancesByName = {};
27
- this.isDefault = semverGroup === input.defaultSemverGroup;
28
- this.isIgnored = semverGroup.isIgnored === true;
29
- this.packages = semverGroup.packages;
30
- this.range = semverGroup.range;
31
- this.isMismatch = this.isMismatch.bind(this);
32
- }
33
- /** Does this `Instance` not follow the rules of this group? */
34
- SemverGroup.prototype.isMismatch = function (instance) {
35
- return !instance.hasRange(this.range);
36
- };
37
- /** 1+ `Instance` has a version which does not follow the rules */
38
- SemverGroup.prototype.hasMismatches = function () {
39
- return !this.isIgnored && this.instances.some(this.isMismatch);
40
- };
41
- /** Get every `Instance` with a version which does not follow the rules */
42
- SemverGroup.prototype.getMismatches = function () {
43
- var _this = this;
44
- return Object.entries(this.instancesByName)
45
- .filter(function (_a) {
46
- var _b = __read(_a, 2), instances = _b[1];
47
- return instances.some(_this.isMismatch);
48
- })
49
- .map(function (_a) {
50
- var _b = __read(_a, 2), name = _b[0], instances = _b[1];
51
- return [name, instances.filter(_this.isMismatch)];
52
- });
53
- };
54
- return SemverGroup;
55
- }());
56
- exports.SemverGroup = SemverGroup;