syncpack 9.7.4 → 9.8.4

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 (34) hide show
  1. package/dist/bin-fix-mismatches/fix-mismatches.js +5 -2
  2. package/dist/bin-format/format.js +2 -1
  3. package/dist/bin-list/list.js +11 -7
  4. package/dist/bin-list-mismatches/list-mismatches.js +15 -11
  5. package/dist/get-context/get-config/index.d.ts +3 -1
  6. package/dist/get-context/get-config/index.js +9 -3
  7. package/dist/get-context/get-config/schema/index.d.ts +38 -0
  8. package/dist/get-context/get-config/schema/index.js +7 -7
  9. package/dist/get-context/get-config/schema/lib/non-empty-string.d.ts +2 -0
  10. package/dist/get-context/get-config/schema/lib/non-empty-string.js +5 -0
  11. package/dist/get-context/get-config/schema/version-group.d.ts +13 -1
  12. package/dist/get-context/get-config/schema/version-group.js +14 -8
  13. package/dist/get-context/get-groups/index.d.ts +6 -3
  14. package/dist/get-context/get-groups/index.js +12 -2
  15. package/dist/get-context/get-groups/version-group/index.d.ts +6 -4
  16. package/dist/get-context/get-groups/version-group/index.js +12 -12
  17. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +1 -1
  18. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.d.ts +3 -0
  19. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.js +44 -0
  20. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +16 -6
  21. package/dist/get-context/get-groups/version-group/instance-group/index.js +32 -28
  22. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +3 -1
  23. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +20 -4
  24. package/dist/get-context/get-package-json-files/index.d.ts +3 -1
  25. package/dist/get-context/get-package-json-files/index.js +2 -2
  26. package/dist/get-context/get-package-json-files/package-json-file/instance.d.ts +2 -1
  27. package/dist/get-context/get-package-json-files/package-json-file/instance.js +2 -1
  28. package/dist/get-context/index.d.ts +3 -2
  29. package/dist/get-context/index.js +19 -10
  30. package/dist/lib/log.js +6 -1
  31. package/dist/types.d.ts +1 -1
  32. package/package.json +1 -1
  33. package/dist/get-context/get-all-instances.d.ts +0 -3
  34. package/dist/get-context/get-all-instances.js +0 -8
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fixMismatches = void 0;
4
+ const ts_belt_1 = require("@mobily/ts-belt");
4
5
  const is_object_1 = require("expect-more/dist/is-object");
5
6
  const is_undefined_1 = require("expect-more/dist/is-undefined");
7
+ const _R_1 = require("../get-context/$R");
6
8
  function fixMismatches(ctx) {
7
9
  ctx.versionGroups.forEach((versionGroup) => {
8
10
  const invalidGroups = versionGroup.getInvalidInstanceGroups();
@@ -12,8 +14,9 @@ function fixMismatches(ctx) {
12
14
  // Set the correct version on each instance.
13
15
  invalidGroups.forEach((instanceGroup) => {
14
16
  if (!instanceGroup.hasUnsupportedVersion()) {
15
- const nextVersion = instanceGroup.getExpectedVersion();
16
- instanceGroup.instances.forEach((instance) => instance.setVersion(nextVersion));
17
+ (0, ts_belt_1.pipe)(instanceGroup.getExpectedVersion(), ts_belt_1.R.tap((nextVersion) => {
18
+ instanceGroup.instances.forEach((instance) => instance.setVersion(nextVersion));
19
+ }), _R_1.$R.tapErrVerbose);
17
20
  }
18
21
  });
19
22
  });
@@ -5,7 +5,8 @@ const is_array_1 = require("expect-more/dist/is-array");
5
5
  const is_non_empty_string_1 = require("expect-more/dist/is-non-empty-string");
6
6
  const is_object_1 = require("expect-more/dist/is-object");
7
7
  function format(ctx) {
8
- const { sortAz, sortFirst, packageJsonFiles } = ctx;
8
+ const { packageJsonFiles } = ctx;
9
+ const { sortAz, sortFirst } = ctx.config;
9
10
  packageJsonFiles.forEach((packageJsonFile) => {
10
11
  const { contents } = packageJsonFile;
11
12
  const sortedKeys = Object.keys(contents).sort();
@@ -27,8 +27,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.list = void 0;
30
+ const ts_belt_1 = require("@mobily/ts-belt");
30
31
  const chalk_1 = __importDefault(require("chalk"));
31
32
  const constants_1 = require("../constants");
33
+ const _R_1 = require("../get-context/$R");
32
34
  const log = __importStar(require("../lib/log"));
33
35
  function list(ctx) {
34
36
  const hasUserGroups = ctx.versionGroups.length > 1;
@@ -63,12 +65,14 @@ function list(ctx) {
63
65
  console.log((0, chalk_1.default) `{dim -} {white ${instanceGroup.name}} {dim ${instanceGroup.getUniqueVersions()}}`);
64
66
  }
65
67
  function logVersionMismatch(instanceGroup) {
66
- console.log((0, chalk_1.default) `{red ${constants_1.ICON.cross} ${instanceGroup.name}} ${instanceGroup
67
- .getUniqueVersions()
68
- .map((version) => version === instanceGroup.getExpectedVersion()
69
- ? chalk_1.default.green(version)
70
- : chalk_1.default.red(version))
71
- .join(chalk_1.default.dim(', '))}`);
68
+ (0, ts_belt_1.pipe)(instanceGroup.getExpectedVersion(), ts_belt_1.R.tap((expectedVersion) => {
69
+ const uniqueVersions = instanceGroup.getUniqueVersions();
70
+ console.log((0, chalk_1.default) `{red ${constants_1.ICON.cross} ${instanceGroup.name}} ${uniqueVersions
71
+ .map((version) => version === expectedVersion
72
+ ? chalk_1.default.green(version)
73
+ : chalk_1.default.red(version))
74
+ .join(chalk_1.default.dim(', '))}`);
75
+ }), _R_1.$R.tapErrVerbose);
72
76
  }
73
77
  function logIgnored(instanceGroup) {
74
78
  console.log((0, chalk_1.default) `{dim ${constants_1.ICON.skip} ${instanceGroup.name}} is ignored in this version group`);
@@ -77,7 +81,7 @@ function list(ctx) {
77
81
  console.log((0, chalk_1.default) `{red ${constants_1.ICON.cross} ${instanceGroup.name}} {dim.red is banned in this version group}`);
78
82
  }
79
83
  function logUnpinned(instanceGroup) {
80
- const pinVersion = instanceGroup.versionGroup.getPinnedVersion();
84
+ const pinVersion = ts_belt_1.O.getExn(instanceGroup.versionGroup.getPinnedVersion());
81
85
  console.log((0, chalk_1.default) `{red ${constants_1.ICON.cross} ${instanceGroup.name}} {dim.red is pinned to ${pinVersion} in this version group}`);
82
86
  }
83
87
  function logUnsupportedMismatches(instanceGroup) {
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.listMismatches = void 0;
30
+ const ts_belt_1 = require("@mobily/ts-belt");
30
31
  const chalk_1 = __importDefault(require("chalk"));
31
32
  const log = __importStar(require("../lib/log"));
32
33
  function listMismatches(ctx) {
@@ -54,7 +55,7 @@ function listMismatches(ctx) {
54
55
  if (instanceGroup.hasWorkspaceInstance()) {
55
56
  return logWorkspaceMismatch(instanceGroup);
56
57
  }
57
- logHighestVersionMismatch(instanceGroup);
58
+ logHighLowVersionMismatch(instanceGroup);
58
59
  });
59
60
  });
60
61
  return ctx;
@@ -76,7 +77,7 @@ function listMismatches(ctx) {
76
77
  }
77
78
  function logUnpinned(instanceGroup) {
78
79
  const name = instanceGroup.name;
79
- const pinVersion = instanceGroup.versionGroup.getPinnedVersion();
80
+ const pinVersion = ts_belt_1.O.getExn(instanceGroup.versionGroup.getPinnedVersion());
80
81
  log.invalid(name, (0, chalk_1.default) `is pinned in this version group at {reset.green ${pinVersion}}`);
81
82
  // Log each of the dependencies mismatches
82
83
  instanceGroup.instances.forEach((instance) => {
@@ -88,10 +89,10 @@ function listMismatches(ctx) {
88
89
  function logSnappedTo(instanceGroup) {
89
90
  const name = instanceGroup.name;
90
91
  const versionGroup = instanceGroup.versionGroup;
91
- const snappedVersion = instanceGroup.getSnappedVersion();
92
- const packages = versionGroup.getSnappedToPackages().join(' || ');
93
- const version = instanceGroup.getExpectedVersion();
94
- log.invalid(name, (0, chalk_1.default) `should snap to {reset.green ${version}}, used by ${packages}`);
92
+ const snappedVersion = ts_belt_1.R.getExn(instanceGroup.getSnappedVersion());
93
+ const snappedToPackages = ts_belt_1.O.getExn(versionGroup.getSnappedToPackages()).join(' || ');
94
+ const version = ts_belt_1.R.getExn(instanceGroup.getExpectedVersion());
95
+ log.invalid(name, (0, chalk_1.default) `should snap to {reset.green ${version}}, used by ${snappedToPackages}`);
95
96
  // Log each of the dependencies mismatches
96
97
  instanceGroup.instances.forEach((instance) => {
97
98
  if (instance.version !== snappedVersion) {
@@ -101,9 +102,9 @@ function listMismatches(ctx) {
101
102
  }
102
103
  function logWorkspaceMismatch(instanceGroup) {
103
104
  const name = instanceGroup.name;
104
- const workspaceInstance = instanceGroup.getWorkspaceInstance();
105
+ const workspaceInstance = ts_belt_1.O.getExn(instanceGroup.getWorkspaceInstance());
105
106
  const shortPath = workspaceInstance?.packageJsonFile.shortPath;
106
- const expected = instanceGroup.getExpectedVersion();
107
+ const expected = ts_belt_1.R.getExn(instanceGroup.getExpectedVersion());
107
108
  log.invalid(name, (0, chalk_1.default) `{reset.green ${expected}} {dim is developed in this repo at ${shortPath}}`);
108
109
  // Log each of the dependencies mismatches
109
110
  instanceGroup.instances.forEach((instance) => {
@@ -112,10 +113,13 @@ function listMismatches(ctx) {
112
113
  }
113
114
  });
114
115
  }
115
- function logHighestVersionMismatch(instanceGroup) {
116
+ function logHighLowVersionMismatch(instanceGroup) {
116
117
  const name = instanceGroup.name;
117
- const expected = instanceGroup.getExpectedVersion();
118
- log.invalid(name, (0, chalk_1.default) `{reset.green ${expected}} {dim is the highest valid semver version in use}`);
118
+ const preference = instanceGroup.versionGroup
119
+ .groupConfig.preferVersion;
120
+ const direction = preference === 'highestSemver' ? 'highest' : 'lowest';
121
+ const expected = ts_belt_1.R.getExn(instanceGroup.getExpectedVersion());
122
+ log.invalid(name, (0, chalk_1.default) `{reset.green ${expected}} {dim is the ${direction} valid semver version in use}`);
119
123
  // Log each of the dependencies mismatches
120
124
  instanceGroup.instances.forEach((instance) => {
121
125
  if (instance.version !== expected) {
@@ -1,7 +1,9 @@
1
+ import { R } from '@mobily/ts-belt';
1
2
  import type { Disk } from '../../lib/disk';
3
+ import { BaseError } from '../../lib/error';
2
4
  import type { Syncpack } from '../../types';
3
5
  /**
4
6
  * Take all configuration from the command line and config file, combine it, and
5
7
  * set defaults for anything which hasn't been defined.
6
8
  */
7
- export declare const getConfig: (disk: Disk, fromCli: Partial<Syncpack.Config.Cli>) => Syncpack.Config.Private;
9
+ export declare function getConfig(disk: Disk, fromCli: Partial<Syncpack.Config.Cli>): R.Result<Syncpack.Config.Private, BaseError>;
@@ -24,6 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getConfig = void 0;
27
+ const ts_belt_1 = require("@mobily/ts-belt");
28
+ const error_1 = require("../../lib/error");
27
29
  const log_1 = require("../../lib/log");
28
30
  const get_core_types_1 = require("./get-core-types");
29
31
  const get_custom_types_1 = require("./get-custom-types");
@@ -33,7 +35,12 @@ const ConfigSchema = __importStar(require("./schema"));
33
35
  * Take all configuration from the command line and config file, combine it, and
34
36
  * set defaults for anything which hasn't been defined.
35
37
  */
36
- const getConfig = (disk, fromCli) => {
38
+ function getConfig(disk, fromCli) {
39
+ const ERR_READING_CONFIG = 'Error reading config';
40
+ return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => unSafeGetConfig(disk, fromCli)), ts_belt_1.R.mapError(error_1.BaseError.map(ERR_READING_CONFIG)));
41
+ }
42
+ exports.getConfig = getConfig;
43
+ function unSafeGetConfig(disk, fromCli) {
37
44
  (0, log_1.verbose)('cli arguments:', fromCli);
38
45
  const fromRcFile = disk.readConfigFileSync(fromCli.configPath);
39
46
  (0, log_1.verbose)('rcfile contents:', fromRcFile);
@@ -81,5 +88,4 @@ const getConfig = (disk, fromCli) => {
81
88
  if (typeof fromRcFile[name] !== 'undefined')
82
89
  return fromRcFile[name];
83
90
  }
84
- };
85
- exports.getConfig = getConfig;
91
+ }
@@ -106,6 +106,7 @@ export declare const Private: z.ZodObject<{
106
106
  sortAz: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
107
107
  sortFirst: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
108
108
  versionGroups: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodObject<{
109
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
109
110
  dependencies: z.ZodArray<z.ZodString, "many">;
110
111
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
111
112
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -115,9 +116,11 @@ export declare const Private: z.ZodObject<{
115
116
  label?: string | undefined;
116
117
  dependencies: string[];
117
118
  packages: string[];
119
+ preferVersion: "highestSemver" | "lowestSemver";
118
120
  }, {
119
121
  dependencyTypes?: string[] | undefined;
120
122
  label?: string | undefined;
123
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
121
124
  dependencies: string[];
122
125
  packages: string[];
123
126
  }>, z.ZodObject<{
@@ -194,6 +197,7 @@ export declare const Private: z.ZodObject<{
194
197
  snapTo: string[];
195
198
  }>, z.ZodObject<{
196
199
  isDefault: z.ZodLiteral<true>;
200
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
197
201
  dependencies: z.ZodArray<z.ZodString, "many">;
198
202
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
199
203
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -204,9 +208,11 @@ export declare const Private: z.ZodObject<{
204
208
  isDefault: true;
205
209
  dependencies: string[];
206
210
  packages: string[];
211
+ preferVersion: "highestSemver" | "lowestSemver";
207
212
  }, {
208
213
  dependencyTypes?: string[] | undefined;
209
214
  label?: string | undefined;
215
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
210
216
  isDefault: true;
211
217
  dependencies: string[];
212
218
  packages: string[];
@@ -329,6 +335,7 @@ export declare const Private: z.ZodObject<{
329
335
  }>;
330
336
  defaultVersionGroup: z.ZodObject<{
331
337
  isDefault: z.ZodLiteral<true>;
338
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
332
339
  dependencies: z.ZodArray<z.ZodString, "many">;
333
340
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
334
341
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -339,9 +346,11 @@ export declare const Private: z.ZodObject<{
339
346
  isDefault: true;
340
347
  dependencies: string[];
341
348
  packages: string[];
349
+ preferVersion: "highestSemver" | "lowestSemver";
342
350
  }, {
343
351
  dependencyTypes?: string[] | undefined;
344
352
  label?: string | undefined;
353
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
345
354
  isDefault: true;
346
355
  dependencies: string[];
347
356
  packages: string[];
@@ -395,11 +404,13 @@ export declare const Private: z.ZodObject<{
395
404
  isDefault: true;
396
405
  dependencies: string[];
397
406
  packages: string[];
407
+ preferVersion: "highestSemver" | "lowestSemver";
398
408
  } | {
399
409
  dependencyTypes?: string[] | undefined;
400
410
  label?: string | undefined;
401
411
  dependencies: string[];
402
412
  packages: string[];
413
+ preferVersion: "highestSemver" | "lowestSemver";
403
414
  } | {
404
415
  dependencyTypes?: string[] | undefined;
405
416
  label?: string | undefined;
@@ -472,6 +483,7 @@ export declare const Private: z.ZodObject<{
472
483
  isDefault: true;
473
484
  dependencies: string[];
474
485
  packages: string[];
486
+ preferVersion: "highestSemver" | "lowestSemver";
475
487
  };
476
488
  }, {
477
489
  filter?: string | undefined;
@@ -518,12 +530,14 @@ export declare const Private: z.ZodObject<{
518
530
  versionGroups?: ({
519
531
  dependencyTypes?: string[] | undefined;
520
532
  label?: string | undefined;
533
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
521
534
  isDefault: true;
522
535
  dependencies: string[];
523
536
  packages: string[];
524
537
  } | {
525
538
  dependencyTypes?: string[] | undefined;
526
539
  label?: string | undefined;
540
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
527
541
  dependencies: string[];
528
542
  packages: string[];
529
543
  } | {
@@ -596,6 +610,7 @@ export declare const Private: z.ZodObject<{
596
610
  defaultVersionGroup: {
597
611
  dependencyTypes?: string[] | undefined;
598
612
  label?: string | undefined;
613
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
599
614
  isDefault: true;
600
615
  dependencies: string[];
601
616
  packages: string[];
@@ -708,6 +723,7 @@ export declare const SyncpackRc: z.ZodObject<{
708
723
  sortAz: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
709
724
  sortFirst: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
710
725
  versionGroups: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodObject<{
726
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
711
727
  dependencies: z.ZodArray<z.ZodString, "many">;
712
728
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
713
729
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -717,9 +733,11 @@ export declare const SyncpackRc: z.ZodObject<{
717
733
  label?: string | undefined;
718
734
  dependencies: string[];
719
735
  packages: string[];
736
+ preferVersion: "highestSemver" | "lowestSemver";
720
737
  }, {
721
738
  dependencyTypes?: string[] | undefined;
722
739
  label?: string | undefined;
740
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
723
741
  dependencies: string[];
724
742
  packages: string[];
725
743
  }>, z.ZodObject<{
@@ -796,6 +814,7 @@ export declare const SyncpackRc: z.ZodObject<{
796
814
  snapTo: string[];
797
815
  }>, z.ZodObject<{
798
816
  isDefault: z.ZodLiteral<true>;
817
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
799
818
  dependencies: z.ZodArray<z.ZodString, "many">;
800
819
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
801
820
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -806,9 +825,11 @@ export declare const SyncpackRc: z.ZodObject<{
806
825
  isDefault: true;
807
826
  dependencies: string[];
808
827
  packages: string[];
828
+ preferVersion: "highestSemver" | "lowestSemver";
809
829
  }, {
810
830
  dependencyTypes?: string[] | undefined;
811
831
  label?: string | undefined;
832
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
812
833
  isDefault: true;
813
834
  dependencies: string[];
814
835
  packages: string[];
@@ -861,11 +882,13 @@ export declare const SyncpackRc: z.ZodObject<{
861
882
  isDefault: true;
862
883
  dependencies: string[];
863
884
  packages: string[];
885
+ preferVersion: "highestSemver" | "lowestSemver";
864
886
  } | {
865
887
  dependencyTypes?: string[] | undefined;
866
888
  label?: string | undefined;
867
889
  dependencies: string[];
868
890
  packages: string[];
891
+ preferVersion: "highestSemver" | "lowestSemver";
869
892
  } | {
870
893
  dependencyTypes?: string[] | undefined;
871
894
  label?: string | undefined;
@@ -936,12 +959,14 @@ export declare const SyncpackRc: z.ZodObject<{
936
959
  versionGroups?: ({
937
960
  dependencyTypes?: string[] | undefined;
938
961
  label?: string | undefined;
962
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
939
963
  isDefault: true;
940
964
  dependencies: string[];
941
965
  packages: string[];
942
966
  } | {
943
967
  dependencyTypes?: string[] | undefined;
944
968
  label?: string | undefined;
969
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
945
970
  dependencies: string[];
946
971
  packages: string[];
947
972
  } | {
@@ -1099,6 +1124,7 @@ export declare const Public: z.ZodObject<Omit<{
1099
1124
  sortAz: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
1100
1125
  sortFirst: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
1101
1126
  versionGroups: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodObject<{
1127
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
1102
1128
  dependencies: z.ZodArray<z.ZodString, "many">;
1103
1129
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
1104
1130
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -1108,9 +1134,11 @@ export declare const Public: z.ZodObject<Omit<{
1108
1134
  label?: string | undefined;
1109
1135
  dependencies: string[];
1110
1136
  packages: string[];
1137
+ preferVersion: "highestSemver" | "lowestSemver";
1111
1138
  }, {
1112
1139
  dependencyTypes?: string[] | undefined;
1113
1140
  label?: string | undefined;
1141
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
1114
1142
  dependencies: string[];
1115
1143
  packages: string[];
1116
1144
  }>, z.ZodObject<{
@@ -1187,6 +1215,7 @@ export declare const Public: z.ZodObject<Omit<{
1187
1215
  snapTo: string[];
1188
1216
  }>, z.ZodObject<{
1189
1217
  isDefault: z.ZodLiteral<true>;
1218
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
1190
1219
  dependencies: z.ZodArray<z.ZodString, "many">;
1191
1220
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
1192
1221
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -1197,9 +1226,11 @@ export declare const Public: z.ZodObject<Omit<{
1197
1226
  isDefault: true;
1198
1227
  dependencies: string[];
1199
1228
  packages: string[];
1229
+ preferVersion: "highestSemver" | "lowestSemver";
1200
1230
  }, {
1201
1231
  dependencyTypes?: string[] | undefined;
1202
1232
  label?: string | undefined;
1233
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
1203
1234
  isDefault: true;
1204
1235
  dependencies: string[];
1205
1236
  packages: string[];
@@ -1322,6 +1353,7 @@ export declare const Public: z.ZodObject<Omit<{
1322
1353
  }>;
1323
1354
  defaultVersionGroup: z.ZodObject<{
1324
1355
  isDefault: z.ZodLiteral<true>;
1356
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
1325
1357
  dependencies: z.ZodArray<z.ZodString, "many">;
1326
1358
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
1327
1359
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -1332,9 +1364,11 @@ export declare const Public: z.ZodObject<Omit<{
1332
1364
  isDefault: true;
1333
1365
  dependencies: string[];
1334
1366
  packages: string[];
1367
+ preferVersion: "highestSemver" | "lowestSemver";
1335
1368
  }, {
1336
1369
  dependencyTypes?: string[] | undefined;
1337
1370
  label?: string | undefined;
1371
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
1338
1372
  isDefault: true;
1339
1373
  dependencies: string[];
1340
1374
  packages: string[];
@@ -1388,11 +1422,13 @@ export declare const Public: z.ZodObject<Omit<{
1388
1422
  isDefault: true;
1389
1423
  dependencies: string[];
1390
1424
  packages: string[];
1425
+ preferVersion: "highestSemver" | "lowestSemver";
1391
1426
  } | {
1392
1427
  dependencyTypes?: string[] | undefined;
1393
1428
  label?: string | undefined;
1394
1429
  dependencies: string[];
1395
1430
  packages: string[];
1431
+ preferVersion: "highestSemver" | "lowestSemver";
1396
1432
  } | {
1397
1433
  dependencyTypes?: string[] | undefined;
1398
1434
  label?: string | undefined;
@@ -1464,12 +1500,14 @@ export declare const Public: z.ZodObject<Omit<{
1464
1500
  versionGroups?: ({
1465
1501
  dependencyTypes?: string[] | undefined;
1466
1502
  label?: string | undefined;
1503
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
1467
1504
  isDefault: true;
1468
1505
  dependencies: string[];
1469
1506
  packages: string[];
1470
1507
  } | {
1471
1508
  dependencyTypes?: string[] | undefined;
1472
1509
  label?: string | undefined;
1510
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
1473
1511
  dependencies: string[];
1474
1512
  packages: string[];
1475
1513
  } | {
@@ -26,38 +26,38 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.Public = exports.Cli = exports.SyncpackRc = exports.Private = void 0;
27
27
  const zod_1 = require("zod");
28
28
  const constants_1 = require("../../../constants");
29
+ const non_empty_string_1 = require("./lib/non-empty-string");
29
30
  const paths = __importStar(require("./paths"));
30
31
  const semverGroup = __importStar(require("./semver-group"));
31
32
  const semverRange = __importStar(require("./semver-range"));
32
33
  const versionGroup = __importStar(require("./version-group"));
33
- const nonEmptyString = zod_1.z.string().trim().min(1);
34
34
  const cliOnly = {
35
35
  configPath: zod_1.z.string().optional(),
36
36
  types: zod_1.z.string().default(''),
37
37
  };
38
38
  const syncpackRcOnly = {
39
39
  customTypes: paths.pathConfigByName.optional(),
40
- dependencyTypes: zod_1.z.array(nonEmptyString).default([]),
40
+ dependencyTypes: zod_1.z.array(non_empty_string_1.nonEmptyString).default([]),
41
41
  semverGroups: zod_1.z
42
42
  .array(semverGroup.any)
43
43
  .default([...constants_1.DEFAULT_CONFIG.semverGroups]),
44
- sortAz: zod_1.z.array(nonEmptyString).default([...constants_1.DEFAULT_CONFIG.sortAz]),
45
- sortFirst: zod_1.z.array(nonEmptyString).default([...constants_1.DEFAULT_CONFIG.sortFirst]),
44
+ sortAz: zod_1.z.array(non_empty_string_1.nonEmptyString).default([...constants_1.DEFAULT_CONFIG.sortAz]),
45
+ sortFirst: zod_1.z.array(non_empty_string_1.nonEmptyString).default([...constants_1.DEFAULT_CONFIG.sortFirst]),
46
46
  versionGroups: zod_1.z
47
47
  .array(versionGroup.any)
48
48
  .default([...constants_1.DEFAULT_CONFIG.versionGroups]),
49
49
  };
50
50
  const cliAndRcFile = {
51
- filter: nonEmptyString.default(constants_1.DEFAULT_CONFIG.filter),
51
+ filter: non_empty_string_1.nonEmptyString.default(constants_1.DEFAULT_CONFIG.filter),
52
52
  indent: zod_1.z.string().default(constants_1.DEFAULT_CONFIG.indent),
53
53
  semverRange: semverRange.value.default(constants_1.DEFAULT_CONFIG.semverRange),
54
- source: zod_1.z.array(nonEmptyString).default([...constants_1.DEFAULT_CONFIG.source]),
54
+ source: zod_1.z.array(non_empty_string_1.nonEmptyString).default([...constants_1.DEFAULT_CONFIG.source]),
55
55
  };
56
56
  const privateOnly = {
57
57
  allTypes: zod_1.z.array(paths.pathDefinition),
58
58
  enabledTypes: zod_1.z.array(paths.pathDefinition),
59
59
  defaultSemverGroup: semverGroup.base,
60
- defaultVersionGroup: versionGroup.base,
60
+ defaultVersionGroup: versionGroup.defaultGroup,
61
61
  };
62
62
  exports.Private = zod_1.z.object({
63
63
  ...privateOnly,
@@ -0,0 +1,2 @@
1
+ import { z } from 'zod';
2
+ export declare const nonEmptyString: z.ZodString;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nonEmptyString = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.nonEmptyString = zod_1.z.string().trim().min(1);
@@ -1,5 +1,6 @@
1
1
  import { z } from 'zod';
2
2
  export declare const standard: z.ZodObject<{
3
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
3
4
  dependencies: z.ZodArray<z.ZodString, "many">;
4
5
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
5
6
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -9,9 +10,11 @@ export declare const standard: z.ZodObject<{
9
10
  label?: string | undefined;
10
11
  dependencies: string[];
11
12
  packages: string[];
13
+ preferVersion: "highestSemver" | "lowestSemver";
12
14
  }, {
13
15
  dependencyTypes?: string[] | undefined;
14
16
  label?: string | undefined;
17
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
15
18
  dependencies: string[];
16
19
  packages: string[];
17
20
  }>;
@@ -91,8 +94,9 @@ export declare const snappedTo: z.ZodObject<{
91
94
  packages: string[];
92
95
  snapTo: string[];
93
96
  }>;
94
- export declare const base: z.ZodObject<{
97
+ export declare const defaultGroup: z.ZodObject<{
95
98
  isDefault: z.ZodLiteral<true>;
99
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
96
100
  dependencies: z.ZodArray<z.ZodString, "many">;
97
101
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
98
102
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -103,14 +107,17 @@ export declare const base: z.ZodObject<{
103
107
  isDefault: true;
104
108
  dependencies: string[];
105
109
  packages: string[];
110
+ preferVersion: "highestSemver" | "lowestSemver";
106
111
  }, {
107
112
  dependencyTypes?: string[] | undefined;
108
113
  label?: string | undefined;
114
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
109
115
  isDefault: true;
110
116
  dependencies: string[];
111
117
  packages: string[];
112
118
  }>;
113
119
  export declare const any: z.ZodUnion<[z.ZodObject<{
120
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
114
121
  dependencies: z.ZodArray<z.ZodString, "many">;
115
122
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
116
123
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -120,9 +127,11 @@ export declare const any: z.ZodUnion<[z.ZodObject<{
120
127
  label?: string | undefined;
121
128
  dependencies: string[];
122
129
  packages: string[];
130
+ preferVersion: "highestSemver" | "lowestSemver";
123
131
  }, {
124
132
  dependencyTypes?: string[] | undefined;
125
133
  label?: string | undefined;
134
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
126
135
  dependencies: string[];
127
136
  packages: string[];
128
137
  }>, z.ZodObject<{
@@ -199,6 +208,7 @@ export declare const any: z.ZodUnion<[z.ZodObject<{
199
208
  snapTo: string[];
200
209
  }>, z.ZodObject<{
201
210
  isDefault: z.ZodLiteral<true>;
211
+ preferVersion: z.ZodDefault<z.ZodOptional<z.ZodEnum<["highestSemver", "lowestSemver"]>>>;
202
212
  dependencies: z.ZodArray<z.ZodString, "many">;
203
213
  dependencyTypes: z.ZodOptional<z.ZodDefault<z.ZodArray<z.ZodString, "many">>>;
204
214
  label: z.ZodOptional<z.ZodDefault<z.ZodString>>;
@@ -209,9 +219,11 @@ export declare const any: z.ZodUnion<[z.ZodObject<{
209
219
  isDefault: true;
210
220
  dependencies: string[];
211
221
  packages: string[];
222
+ preferVersion: "highestSemver" | "lowestSemver";
212
223
  }, {
213
224
  dependencyTypes?: string[] | undefined;
214
225
  label?: string | undefined;
226
+ preferVersion?: "highestSemver" | "lowestSemver" | undefined;
215
227
  isDefault: true;
216
228
  dependencies: string[];
217
229
  packages: string[];
@@ -1,10 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.any = exports.base = exports.snappedTo = exports.pinned = exports.ignored = exports.banned = exports.standard = void 0;
3
+ exports.any = exports.defaultGroup = exports.snappedTo = exports.pinned = exports.ignored = exports.banned = exports.standard = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const base_group_1 = require("./base-group");
6
- const nonEmptyString = zod_1.z.string().trim().min(1);
7
- exports.standard = zod_1.z.object(base_group_1.baseGroupFields).strict();
6
+ const non_empty_string_1 = require("./lib/non-empty-string");
7
+ const preferVersion = zod_1.z
8
+ .enum(['highestSemver', 'lowestSemver'])
9
+ .optional()
10
+ .default('highestSemver');
11
+ exports.standard = zod_1.z
12
+ .object({ ...base_group_1.baseGroupFields, preferVersion })
13
+ .strict();
8
14
  exports.banned = zod_1.z
9
15
  .object({ ...base_group_1.baseGroupFields, isBanned: zod_1.z.literal(true) })
10
16
  .strict();
@@ -12,13 +18,13 @@ exports.ignored = zod_1.z
12
18
  .object({ ...base_group_1.baseGroupFields, isIgnored: zod_1.z.literal(true) })
13
19
  .strict();
14
20
  exports.pinned = zod_1.z
15
- .object({ ...base_group_1.baseGroupFields, pinVersion: nonEmptyString })
21
+ .object({ ...base_group_1.baseGroupFields, pinVersion: non_empty_string_1.nonEmptyString })
16
22
  .strict();
17
23
  exports.snappedTo = zod_1.z
18
- .object({ ...base_group_1.baseGroupFields, snapTo: zod_1.z.array(nonEmptyString) })
24
+ .object({ ...base_group_1.baseGroupFields, snapTo: zod_1.z.array(non_empty_string_1.nonEmptyString) })
19
25
  .strict();
20
- exports.base = zod_1.z
21
- .object({ ...base_group_1.baseGroupFields, isDefault: zod_1.z.literal(true) })
26
+ exports.defaultGroup = zod_1.z
27
+ .object({ ...base_group_1.baseGroupFields, isDefault: zod_1.z.literal(true), preferVersion })
22
28
  .strict();
23
29
  exports.any = zod_1.z.union([
24
30
  exports.standard,
@@ -26,5 +32,5 @@ exports.any = zod_1.z.union([
26
32
  exports.ignored,
27
33
  exports.pinned,
28
34
  exports.snappedTo,
29
- exports.base,
35
+ exports.defaultGroup,
30
36
  ]);
@@ -1,9 +1,12 @@
1
+ import { R } from '@mobily/ts-belt';
2
+ import { BaseError } from '../../lib/error';
1
3
  import type { Syncpack } from '../../types';
2
4
  import type { PackageJsonFile } from '../get-package-json-files/package-json-file';
3
- import type { Instance } from '../get-package-json-files/package-json-file/instance';
4
5
  import { SemverGroup } from './semver-group';
5
6
  import { VersionGroup } from './version-group';
6
- export declare function getGroups(config: Syncpack.Config.Private, instances: Instance[], packageJsonFiles: PackageJsonFile[]): {
7
+ interface GroupsByPropName {
7
8
  semverGroups: SemverGroup[];
8
9
  versionGroups: VersionGroup[];
9
- };
10
+ }
11
+ export declare function getGroups(config: Syncpack.Config.Private, packageJsonFiles: PackageJsonFile[]): R.Result<GroupsByPropName, BaseError>;
12
+ export {};
@@ -1,15 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getGroups = void 0;
4
+ const ts_belt_1 = require("@mobily/ts-belt");
5
+ const error_1 = require("../../lib/error");
4
6
  const log_1 = require("../../lib/log");
7
+ const sort_by_name_1 = require("../../lib/sort-by-name");
5
8
  const semver_group_1 = require("./semver-group");
6
9
  const version_group_1 = require("./version-group");
7
- function getGroups(config, instances, packageJsonFiles) {
10
+ function getGroups(config, packageJsonFiles) {
11
+ const ERR_CREATING_GROUPS = 'Error creating semver and version groups';
12
+ return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => unsafeGetGroups(config, packageJsonFiles)), ts_belt_1.R.mapError(error_1.BaseError.map(ERR_CREATING_GROUPS)));
13
+ }
14
+ exports.getGroups = getGroups;
15
+ function unsafeGetGroups(config, packageJsonFiles) {
8
16
  const groupsByName = {
9
17
  semverGroups: config.semverGroups.map((group) => new semver_group_1.SemverGroup(config, group, packageJsonFiles)),
10
18
  versionGroups: config.versionGroups.map((group) => new version_group_1.VersionGroup(config, group, packageJsonFiles)),
11
19
  };
12
20
  const groupNames = Object.keys(groupsByName);
21
+ const instances = packageJsonFiles
22
+ .flatMap((pkg) => pkg.getInstances())
23
+ .sort(sort_by_name_1.sortByName);
13
24
  instances.forEach((instance) => {
14
25
  const { name, pkgName } = instance;
15
26
  groupNames.forEach((key) => {
@@ -38,4 +49,3 @@ function getGroups(config, instances, packageJsonFiles) {
38
49
  }
39
50
  return groupsByName;
40
51
  }
41
- exports.getGroups = getGroups;
@@ -1,13 +1,15 @@
1
+ import { O } from '@mobily/ts-belt';
1
2
  import type { Syncpack } from '../../../types';
2
3
  import { BaseGroup } from '../base-group';
3
4
  import { InstanceGroup } from './instance-group';
4
5
  export declare class VersionGroup extends BaseGroup<Syncpack.Config.VersionGroup.Any> {
5
- getAllInstanceGroups(): InstanceGroup[];
6
- getInvalidInstanceGroups(): InstanceGroup[];
7
6
  isBanned(): boolean;
8
7
  isIgnored(): boolean;
9
8
  hasSnappedToPackages(): boolean;
10
- getSnappedToPackages(): string[];
11
- getPinnedVersion(): string;
9
+ getSnappedToPackages(): O.Option<string[]>;
10
+ getAllInstanceGroups(): InstanceGroup[];
11
+ getInvalidInstanceGroups(): InstanceGroup[];
12
+ getPinnedVersion(): O.Option<string>;
13
+ /** Is `pinVersion` defined and this group does not match that version? */
12
14
  isUnpinned(): boolean;
13
15
  }
@@ -1,17 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VersionGroup = void 0;
4
+ const ts_belt_1 = require("@mobily/ts-belt");
4
5
  const expect_more_1 = require("expect-more");
5
6
  const is_non_empty_string_1 = require("expect-more/dist/is-non-empty-string");
6
7
  const base_group_1 = require("../base-group");
7
8
  const instance_group_1 = require("./instance-group");
8
9
  class VersionGroup extends base_group_1.BaseGroup {
9
- getAllInstanceGroups() {
10
- return Object.entries(this.instancesByName).map(([name, instances]) => new instance_group_1.InstanceGroup(this, name, instances));
11
- }
12
- getInvalidInstanceGroups() {
13
- return this.getAllInstanceGroups().filter((group) => group.isInvalid());
14
- }
15
10
  isBanned() {
16
11
  return this.groupConfig.isBanned === true;
17
12
  }
@@ -19,18 +14,23 @@ class VersionGroup extends base_group_1.BaseGroup {
19
14
  return this.groupConfig.isIgnored === true;
20
15
  }
21
16
  hasSnappedToPackages() {
22
- return (0, expect_more_1.isArrayOfStrings)(this.groupConfig.snapTo);
17
+ return ts_belt_1.O.isSome(this.getSnappedToPackages());
23
18
  }
24
19
  getSnappedToPackages() {
25
- return this.groupConfig.snapTo;
20
+ return ts_belt_1.O.fromPredicate(this.groupConfig.snapTo, expect_more_1.isArrayOfStrings);
21
+ }
22
+ getAllInstanceGroups() {
23
+ return Object.entries(this.instancesByName).map(([name, instances]) => new instance_group_1.InstanceGroup(this, name, instances));
24
+ }
25
+ getInvalidInstanceGroups() {
26
+ return this.getAllInstanceGroups().filter((group) => group.isInvalid());
26
27
  }
27
28
  getPinnedVersion() {
28
- return this.groupConfig.pinVersion;
29
+ return ts_belt_1.O.fromPredicate(this.groupConfig.pinVersion, is_non_empty_string_1.isNonEmptyString);
29
30
  }
31
+ /** Is `pinVersion` defined and this group does not match that version? */
30
32
  isUnpinned() {
31
- const { pinVersion } = this.groupConfig;
32
- return ((0, is_non_empty_string_1.isNonEmptyString)(pinVersion) &&
33
- this.instances.some(({ version }) => version !== pinVersion));
33
+ return (0, ts_belt_1.pipe)(this.getPinnedVersion(), ts_belt_1.O.map((pinVersion) => this.instances.some((o) => o.version !== pinVersion)), ts_belt_1.O.getWithDefault(false));
34
34
  }
35
35
  }
36
36
  exports.VersionGroup = VersionGroup;
@@ -9,7 +9,7 @@ const get_range_score_1 = require("./lib/get-range-score");
9
9
  function getHighestVersion(versions) {
10
10
  let highest;
11
11
  for (const withRange of versions) {
12
- switch ((0, compare_semver_1.compareSemver)(withRange, highest?.semver)) {
12
+ switch ((0, compare_semver_1.compareGt)(withRange, highest?.semver)) {
13
13
  // highest possible, quit early
14
14
  case '*': {
15
15
  return ts_belt_1.R.Ok(withRange);
@@ -0,0 +1,3 @@
1
+ import { R } from '@mobily/ts-belt';
2
+ import { BaseError } from '../../../../lib/error';
3
+ export declare function getLowestVersion(versions: string[]): R.Result<string, BaseError>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLowestVersion = void 0;
4
+ const ts_belt_1 = require("@mobily/ts-belt");
5
+ const error_1 = require("../../../../lib/error");
6
+ const clean_1 = require("./lib/clean");
7
+ const compare_semver_1 = require("./lib/compare-semver");
8
+ const get_range_score_1 = require("./lib/get-range-score");
9
+ function getLowestVersion(versions) {
10
+ let lowest;
11
+ for (const withRange of versions) {
12
+ switch ((0, compare_semver_1.compareLt)(withRange, lowest?.semver)) {
13
+ // lowest possible, quit early
14
+ case '*': {
15
+ if (!lowest)
16
+ lowest = { withRange: '*', semver: '*' };
17
+ continue;
18
+ }
19
+ // impossible to know how the user wants to resolve unsupported versions
20
+ case 'invalid': {
21
+ return ts_belt_1.R.Error(new error_1.BaseError(`"${withRange}" is not supported`));
22
+ }
23
+ // we found a new lowest version
24
+ case 'lt': {
25
+ lowest = newLowestVersion(withRange);
26
+ continue;
27
+ }
28
+ // versions are the same, but one range might be greedier than another
29
+ case 'eq': {
30
+ const score = (0, get_range_score_1.getRangeScore)(withRange);
31
+ const lowestScore = (0, get_range_score_1.getRangeScore)(`${lowest?.withRange}`);
32
+ if (score < lowestScore)
33
+ lowest = newLowestVersion(withRange);
34
+ }
35
+ }
36
+ }
37
+ return lowest && lowest.withRange
38
+ ? ts_belt_1.R.Ok(lowest.withRange)
39
+ : ts_belt_1.R.Error(new error_1.BaseError(`getLowestVersion(): did not return a version`));
40
+ }
41
+ exports.getLowestVersion = getLowestVersion;
42
+ function newLowestVersion(withRange) {
43
+ return { withRange, semver: (0, clean_1.clean)(withRange) };
44
+ }
@@ -1,5 +1,9 @@
1
+ import { O, R } from '@mobily/ts-belt';
1
2
  import type { VersionGroup } from '..';
3
+ import { BaseError } from '../../../../lib/error';
2
4
  import type { Instance } from '../../../get-package-json-files/package-json-file/instance';
5
+ export declare const DELETE: unique symbol;
6
+ export type Delete = typeof DELETE;
3
7
  /** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
4
8
  export declare class InstanceGroup {
5
9
  /** Every package/pathName location where this dependency was found */
@@ -13,13 +17,19 @@ export declare class InstanceGroup {
13
17
  getUniqueVersions(): string[];
14
18
  hasMismatchingVersions(): boolean;
15
19
  isInvalid(): boolean;
16
- getExpectedVersion(): string | undefined;
17
- getHighestVersion(): string;
18
- getSnappedVersion(): string;
19
- isUnsnapped(): boolean;
20
+ getExpectedVersion(): R.Result<string | Delete, BaseError>;
21
+ /** If all versions are valid semver, return the newest one */
22
+ getHighestVersion(): R.Result<string, BaseError>;
23
+ /** If all versions are valid semver, return the lowest one */
24
+ getLowestVersion(): R.Result<string, BaseError>;
25
+ /** Get the first version matched by the `snapTo` packages */
26
+ getSnappedVersion(): R.Result<string, BaseError>;
27
+ /** Is `snapTo` defined and this group does not match that version? */
28
+ isUnsnapped(): R.Result<boolean, BaseError>;
20
29
  /** Get version of dependency which is developed in this monorepo */
21
- getWorkspaceVersion(): string | undefined;
30
+ getWorkspaceVersion(): R.Result<string, BaseError>;
22
31
  /** Find instance of this dependency which is developed in this monorepo */
23
- getWorkspaceInstance(): Instance | undefined;
32
+ getWorkspaceInstance(): O.Option<Instance>;
33
+ /** Is an instance of this dependency developed in this monorepo? */
24
34
  hasWorkspaceInstance(): boolean;
25
35
  }
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InstanceGroup = void 0;
3
+ exports.InstanceGroup = exports.DELETE = void 0;
4
4
  const ts_belt_1 = require("@mobily/ts-belt");
5
+ const expect_more_1 = require("expect-more");
5
6
  const error_1 = require("../../../../lib/error");
6
7
  const is_semver_1 = require("../../../../lib/is-semver");
7
8
  const print_strings_1 = require("../../../../lib/print-strings");
9
+ const props_1 = require("../../../get-package-json-files/get-patterns/props");
8
10
  const get_highest_version_1 = require("./get-highest-version");
11
+ const get_lowest_version_1 = require("./get-lowest-version");
12
+ exports.DELETE = Symbol('DELETE');
9
13
  /** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
10
14
  class InstanceGroup {
11
15
  constructor(versionGroup, name, instances) {
@@ -31,54 +35,54 @@ class InstanceGroup {
31
35
  }
32
36
  getExpectedVersion() {
33
37
  const versionGroup = this.versionGroup;
34
- const REMOVE_DEPENDENCY = undefined;
35
38
  if (versionGroup.isBanned())
36
- return REMOVE_DEPENDENCY;
39
+ return ts_belt_1.R.Ok(exports.DELETE);
37
40
  if (versionGroup.isUnpinned())
38
- return versionGroup.getPinnedVersion();
39
- if (this.isUnsnapped())
41
+ return (0, ts_belt_1.pipe)(versionGroup.getPinnedVersion(), ts_belt_1.O.toResult(new error_1.BaseError(`${this.name} is in a versionGroup with pinVersion configuration, but the pinVersion value is not valid`)));
42
+ if (versionGroup.hasSnappedToPackages() && ts_belt_1.R.getExn(this.isUnsnapped()))
40
43
  return this.getSnappedVersion();
41
44
  if (this.hasWorkspaceInstance())
42
45
  return this.getWorkspaceVersion();
43
46
  if (this.hasUnsupportedVersion()) {
44
- throw new error_1.BaseError(`${this.name} contains unsupported versions: ${(0, print_strings_1.printStrings)(this.getUniqueVersions())}`);
47
+ return ts_belt_1.R.Error(new error_1.BaseError(`${this.name} contains unsupported versions: ${(0, print_strings_1.printStrings)(this.getUniqueVersions())}`));
45
48
  }
46
- return this.getHighestVersion();
49
+ return versionGroup.groupConfig.preferVersion ===
50
+ 'lowestSemver'
51
+ ? this.getLowestVersion()
52
+ : this.getHighestVersion();
47
53
  }
54
+ /** If all versions are valid semver, return the newest one */
48
55
  getHighestVersion() {
49
- return (0, ts_belt_1.pipe)((0, get_highest_version_1.getHighestVersion)(this.getUniqueVersions()), ts_belt_1.R.getExn);
56
+ return (0, get_highest_version_1.getHighestVersion)(this.getUniqueVersions());
50
57
  }
58
+ /** If all versions are valid semver, return the lowest one */
59
+ getLowestVersion() {
60
+ return (0, get_lowest_version_1.getLowestVersion)(this.getUniqueVersions());
61
+ }
62
+ /** Get the first version matched by the `snapTo` packages */
51
63
  getSnappedVersion() {
52
- const snapTo = this.versionGroup.getSnappedToPackages();
53
- const version = this.instances
54
- .filter(({ pkgName }) => snapTo.includes(pkgName))
55
- .map((instance) => instance.version)
56
- .find(Boolean);
57
- if (!version) {
58
- const pkgNames = (0, print_strings_1.printStrings)(snapTo);
59
- throw new error_1.BaseError(`${this.name} is in a versionGroup with snapTo:[${pkgNames}], but ${this.name} was not found in those packages`);
60
- }
61
- return version;
64
+ return (0, ts_belt_1.pipe)(this.versionGroup.getSnappedToPackages(), ts_belt_1.O.flatMap((pkgNames) => ts_belt_1.O.fromFalsy(this.instances
65
+ .filter(({ pkgName }) => pkgNames.includes(pkgName))
66
+ .map(({ version }) => version)
67
+ .find(Boolean))), ts_belt_1.O.filter(expect_more_1.isNonEmptyString), ts_belt_1.O.toResult(new error_1.BaseError(`${this.name} is in a versionGroup with snapTo configuration, but ${this.name} was not found in those packages`)));
62
68
  }
69
+ /** Is `snapTo` defined and this group does not match that version? */
63
70
  isUnsnapped() {
64
- if (!this.versionGroup.hasSnappedToPackages())
65
- return false;
66
- const targetVersion = this.getSnappedVersion();
67
- return this.instances.some(({ version }) => version !== targetVersion);
71
+ return this.versionGroup.hasSnappedToPackages()
72
+ ? (0, ts_belt_1.pipe)(this.getSnappedVersion(), ts_belt_1.R.map((nextVersion) => this.instances.some(({ version }) => version !== nextVersion)))
73
+ : ts_belt_1.R.Ok(false);
68
74
  }
69
75
  /** Get version of dependency which is developed in this monorepo */
70
76
  getWorkspaceVersion() {
71
- if (this.hasWorkspaceInstance()) {
72
- return this.getWorkspaceInstance()?.packageJsonFile.contents.version;
73
- }
74
- throw new error_1.BaseError('getWorkspaceVersion invoked when there is none');
77
+ return (0, ts_belt_1.pipe)(this.getWorkspaceInstance(), (0, props_1.props)('packageJsonFile.contents.version', expect_more_1.isNonEmptyString), ts_belt_1.O.toResult(new error_1.BaseError(`Expected to find a package.json file developed in this monorepo with a "name" property of "${this.name}" and a valid "version" property`)));
75
78
  }
76
79
  /** Find instance of this dependency which is developed in this monorepo */
77
80
  getWorkspaceInstance() {
78
- return this.instances.find(({ pathDef }) => pathDef.name === 'workspace');
81
+ return ts_belt_1.O.fromFalsy(this.instances.find(({ pathDef }) => pathDef.name === 'workspace'));
79
82
  }
83
+ /** Is an instance of this dependency developed in this monorepo? */
80
84
  hasWorkspaceInstance() {
81
- return this.getWorkspaceInstance() !== undefined;
85
+ return (0, ts_belt_1.pipe)(this.getWorkspaceInstance(), ts_belt_1.O.toUndefined) !== undefined;
82
86
  }
83
87
  }
84
88
  exports.InstanceGroup = InstanceGroup;
@@ -1,2 +1,4 @@
1
1
  /** Is this next version to be inspected higher than the current highest? */
2
- export declare function compareSemver(next: string, highest: string | undefined): '*' | 'invalid' | 'gt' | 'lt' | 'eq';
2
+ export declare function compareGt(next: string, highest: string | undefined): '*' | 'invalid' | 'gt' | 'lt' | 'eq';
3
+ /** Is this next version to be inspected lower than the current lowest? */
4
+ export declare function compareLt(next: string, lowest: string | undefined): '*' | 'invalid' | 'gt' | 'lt' | 'eq';
@@ -3,20 +3,36 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.compareSemver = void 0;
6
+ exports.compareLt = exports.compareGt = void 0;
7
7
  const gt_1 = __importDefault(require("semver/functions/gt"));
8
+ const lt_1 = __importDefault(require("semver/functions/lt"));
8
9
  const is_semver_1 = require("../../../../../lib/is-semver");
9
10
  const clean_1 = require("./clean");
10
11
  /** Is this next version to be inspected higher than the current highest? */
11
- function compareSemver(next, highest) {
12
+ function compareGt(next, highest) {
12
13
  if (next === '*')
13
14
  return '*';
14
15
  if (!(0, is_semver_1.isSemver)(next))
15
16
  return 'invalid';
16
17
  if (!highest || (0, gt_1.default)((0, clean_1.clean)(next), highest))
17
18
  return 'gt';
18
- if ((0, gt_1.default)((0, clean_1.clean)(next), highest))
19
+ if ((0, lt_1.default)((0, clean_1.clean)(next), highest))
19
20
  return 'lt';
20
21
  return 'eq';
21
22
  }
22
- exports.compareSemver = compareSemver;
23
+ exports.compareGt = compareGt;
24
+ /** Is this next version to be inspected lower than the current lowest? */
25
+ function compareLt(next, lowest) {
26
+ if (next === '*')
27
+ return '*';
28
+ if (!(0, is_semver_1.isSemver)(next))
29
+ return 'invalid';
30
+ if (lowest === '*')
31
+ return 'lt';
32
+ if (!lowest || (0, lt_1.default)((0, clean_1.clean)(next), lowest))
33
+ return 'lt';
34
+ if ((0, gt_1.default)((0, clean_1.clean)(next), lowest))
35
+ return 'gt';
36
+ return 'eq';
37
+ }
38
+ exports.compareLt = compareLt;
@@ -1,5 +1,7 @@
1
+ import { R } from '@mobily/ts-belt';
1
2
  import type { Disk } from '../../lib/disk';
3
+ import type { BaseError } from '../../lib/error';
2
4
  import type { Syncpack } from '../../types';
3
5
  import { PackageJsonFile } from './package-json-file';
4
6
  /** Create an API for every package.json file needed. */
5
- export declare function getPackageJsonFiles(disk: Disk, config: Syncpack.Config.Private): PackageJsonFile[];
7
+ export declare function getPackageJsonFiles(disk: Disk, config: Syncpack.Config.Private): R.Result<PackageJsonFile[], BaseError>;
@@ -8,9 +8,9 @@ const read_json_safe_1 = require("./get-patterns/read-json-safe");
8
8
  const package_json_file_1 = require("./package-json-file");
9
9
  /** Create an API for every package.json file needed. */
10
10
  function getPackageJsonFiles(disk, config) {
11
- return (0, ts_belt_1.pipe)((0, get_file_paths_1.getFilePaths)(disk, config), ts_belt_1.R.flatMap(_R_1.$R.onlyOk(resolvePackageJson(disk))), ts_belt_1.R.getWithDefault([]));
11
+ return (0, ts_belt_1.pipe)((0, get_file_paths_1.getFilePaths)(disk, config), ts_belt_1.R.flatMap(_R_1.$R.onlyOk(resolvePackageJson(disk))), ts_belt_1.R.recover([]));
12
12
  function resolvePackageJson(disk) {
13
- return (0, ts_belt_1.flow)((0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.map((jsonFile) => new package_json_file_1.PackageJsonFile(jsonFile, config, disk)));
13
+ return (0, ts_belt_1.flow)((0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.map((jsonFile) => new package_json_file_1.PackageJsonFile(jsonFile, config, disk)), _R_1.$R.tapErrVerbose);
14
14
  }
15
15
  }
16
16
  exports.getPackageJsonFiles = getPackageJsonFiles;
@@ -1,5 +1,6 @@
1
1
  import type { PackageJsonFile } from '.';
2
2
  import type { Syncpack } from '../../../types';
3
+ import type { Delete } from '../../get-groups/version-group/instance-group';
3
4
  export declare class Instance {
4
5
  /** the name of this dependency */
5
6
  name: string;
@@ -18,5 +19,5 @@ export declare class Instance {
18
19
  * In the case of banned dependencies, their version is set to `undefined`,
19
20
  * which causes them to be removed by `JSON.stringify`.
20
21
  */
21
- setVersion(version: string | undefined): void;
22
+ setVersion(version: string | Delete): void;
22
23
  }
@@ -4,6 +4,7 @@ exports.Instance = void 0;
4
4
  const ts_belt_1 = require("@mobily/ts-belt");
5
5
  const _R_1 = require("../../$R");
6
6
  const path_strategy_1 = require("../../get-config/path-strategy");
7
+ const instance_group_1 = require("../../get-groups/version-group/instance-group");
7
8
  class Instance {
8
9
  constructor(pathDef, name, packageJsonFile, version) {
9
10
  this.pathDef = pathDef;
@@ -22,7 +23,7 @@ class Instance {
22
23
  */
23
24
  setVersion(version) {
24
25
  const strategyName = this.pathDef.strategy;
25
- const entry = [this.name, version];
26
+ const entry = [this.name, version === instance_group_1.DELETE ? undefined : version];
26
27
  const file = this.packageJsonFile;
27
28
  switch (strategyName) {
28
29
  case 'name@version':
@@ -3,13 +3,14 @@ import type { Syncpack } from '../types';
3
3
  import type { SemverGroup } from './get-groups/semver-group';
4
4
  import type { VersionGroup } from './get-groups/version-group';
5
5
  import type { PackageJsonFile } from './get-package-json-files/package-json-file';
6
- export type Context = Omit<Syncpack.Config.Private, 'semverGroups' | 'versionGroups'> & {
6
+ export interface Context {
7
+ config: Syncpack.Config.Private;
7
8
  disk: Disk;
8
9
  isInvalid: boolean;
9
10
  packageJsonFiles: PackageJsonFile[];
10
11
  semverGroups: SemverGroup[];
11
12
  versionGroups: VersionGroup[];
12
- };
13
+ }
13
14
  /**
14
15
  * Every command in syncpack should accept the return value of this function as
15
16
  * its input.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getContext = void 0;
4
+ const ts_belt_1 = require("@mobily/ts-belt");
4
5
  const disk_1 = require("../lib/disk");
5
- const get_all_instances_1 = require("./get-all-instances");
6
+ const _R_1 = require("./$R");
6
7
  const get_config_1 = require("./get-config");
7
8
  const get_groups_1 = require("./get-groups");
8
9
  const get_package_json_files_1 = require("./get-package-json-files");
@@ -15,17 +16,25 @@ const get_package_json_files_1 = require("./get-package-json-files");
15
16
  * system and can focus solely on transformation logic.
16
17
  */
17
18
  function getContext(program, disk = disk_1.disk) {
18
- const config = (0, get_config_1.getConfig)(disk, program);
19
- const packageJsonFiles = (0, get_package_json_files_1.getPackageJsonFiles)(disk, config);
20
- const instances = (0, get_all_instances_1.getAllInstances)(packageJsonFiles);
21
- const groups = (0, get_groups_1.getGroups)(config, instances, packageJsonFiles);
22
- return {
23
- ...config,
19
+ return (0, ts_belt_1.pipe)(
20
+ // merge CLI options, .syncpackrc contents, and default config
21
+ (0, get_config_1.getConfig)(disk, program), ts_belt_1.R.flatMap((config) => (0, ts_belt_1.pipe)(
22
+ // get the package.json file which match the globs in config
23
+ (0, get_package_json_files_1.getPackageJsonFiles)(disk, config), ts_belt_1.R.flatMap((packageJsonFiles) => (0, ts_belt_1.pipe)(
24
+ // allocate dependencies into semver and version groups
25
+ (0, get_groups_1.getGroups)(config, packageJsonFiles),
26
+ // combine everything into the final config
27
+ ts_belt_1.R.map(({ semverGroups, versionGroups }) => ({
28
+ config,
24
29
  disk,
25
30
  isInvalid: false,
26
31
  packageJsonFiles,
27
- semverGroups: groups.semverGroups,
28
- versionGroups: groups.versionGroups,
29
- };
32
+ semverGroups,
33
+ versionGroups,
34
+ })))))),
35
+ // if anything errored at any stage, log it when in verbose mode
36
+ _R_1.$R.tapErrVerbose,
37
+ // throw if anything errored, can't do anything without this data
38
+ ts_belt_1.R.getExn);
30
39
  }
31
40
  exports.getContext = getContext;
package/dist/lib/log.js CHANGED
@@ -13,7 +13,12 @@ function verbose(...values) {
13
13
  if (process.env.SYNCPACK_VERBOSE) {
14
14
  console.info(chalk_1.default.yellow(constants_1.ICON.debug), ...values.map((value) => (0, is_string_1.isString)(value)
15
15
  ? chalk_1.default.yellow(value)
16
- : (0, util_1.inspect)(value, { showHidden: false, colors: true, depth: 20 })));
16
+ : (0, util_1.inspect)(value, {
17
+ colors: true,
18
+ compact: true,
19
+ depth: 20,
20
+ showHidden: false,
21
+ })));
17
22
  }
18
23
  }
19
24
  exports.verbose = verbose;
package/dist/types.d.ts CHANGED
@@ -81,7 +81,7 @@ export declare namespace Syncpack {
81
81
  /** Use these named packages as the source of truth for versions */
82
82
  export type SnappedTo = z.infer<T['snappedTo']>;
83
83
  /** @private */
84
- export type Default = z.infer<T['base']>;
84
+ export type Default = z.infer<T['defaultGroup']>;
85
85
  /** Every valid type of VersionGroup */
86
86
  export type Any = z.infer<T['any']>;
87
87
  export {};
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.7.4",
4
+ "version": "9.8.4",
5
5
  "author": "Jamie Mason <jamie@foldleft.io> (https://github.com/JamieMason)",
6
6
  "bin": {
7
7
  "syncpack": "dist/bin.js",
@@ -1,3 +0,0 @@
1
- import type { PackageJsonFile } from './get-package-json-files/package-json-file';
2
- import type { Instance } from './get-package-json-files/package-json-file/instance';
3
- export declare function getAllInstances(packageJsonFiles: PackageJsonFile[]): Instance[];
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getAllInstances = void 0;
4
- const sort_by_name_1 = require("../lib/sort-by-name");
5
- function getAllInstances(packageJsonFiles) {
6
- return packageJsonFiles.flatMap((pkg) => pkg.getInstances()).sort(sort_by_name_1.sortByName);
7
- }
8
- exports.getAllInstances = getAllInstances;