syncpack 9.7.4 → 9.8.6

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 (70) hide show
  1. package/LICENSE +12 -13
  2. package/dist/bin-fix-mismatches/fix-mismatches.js +8 -4
  3. package/dist/bin-format/format.js +5 -4
  4. package/dist/bin-list/list.js +13 -7
  5. package/dist/bin-list-mismatches/list-mismatches.js +16 -11
  6. package/dist/get-context/$R.d.ts +8 -9
  7. package/dist/get-context/$R.js +13 -12
  8. package/dist/get-context/get-config/get-custom-types.js +1 -1
  9. package/dist/get-context/get-config/get-enabled-types.js +3 -3
  10. package/dist/get-context/get-config/index.d.ts +2 -1
  11. package/dist/get-context/get-config/index.js +28 -15
  12. package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.d.ts +2 -3
  13. package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.js +6 -4
  14. package/dist/get-context/get-config/path-strategy/name-and-version-props.js +15 -11
  15. package/dist/get-context/get-config/path-strategy/name-and-version-string.js +17 -12
  16. package/dist/get-context/get-config/path-strategy/types.d.ts +3 -4
  17. package/dist/get-context/get-config/path-strategy/version-string.js +17 -12
  18. package/dist/get-context/get-config/path-strategy/versions-by-name.js +10 -12
  19. package/dist/get-context/get-config/schema/index.d.ts +294 -256
  20. package/dist/get-context/get-config/schema/index.js +7 -7
  21. package/dist/get-context/get-config/schema/lib/non-empty-string.d.ts +2 -0
  22. package/dist/get-context/get-config/schema/lib/non-empty-string.js +5 -0
  23. package/dist/get-context/get-config/schema/semver-group.d.ts +18 -18
  24. package/dist/get-context/get-config/schema/version-group.d.ts +49 -37
  25. package/dist/get-context/get-config/schema/version-group.js +14 -8
  26. package/dist/get-context/get-groups/base-group.js +1 -1
  27. package/dist/get-context/get-groups/index.d.ts +5 -3
  28. package/dist/get-context/get-groups/index.js +14 -2
  29. package/dist/get-context/get-groups/version-group/index.d.ts +6 -4
  30. package/dist/get-context/get-groups/version-group/index.js +18 -14
  31. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.d.ts +2 -3
  32. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +6 -6
  33. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.d.ts +2 -0
  34. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.js +44 -0
  35. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +15 -6
  36. package/dist/get-context/get-groups/version-group/instance-group/index.js +49 -30
  37. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +3 -1
  38. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +20 -4
  39. package/dist/get-context/get-package-json-files/get-file-paths.d.ts +2 -3
  40. package/dist/get-context/get-package-json-files/get-file-paths.js +14 -24
  41. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.d.ts +2 -3
  42. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.js +6 -5
  43. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.d.ts +2 -3
  44. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.js +7 -6
  45. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.d.ts +2 -3
  46. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.js +7 -6
  47. package/dist/get-context/get-package-json-files/get-patterns/index.d.ts +2 -3
  48. package/dist/get-context/get-package-json-files/get-patterns/index.js +8 -17
  49. package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.d.ts +2 -3
  50. package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.js +6 -9
  51. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.d.ts +2 -3
  52. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.js +4 -3
  53. package/dist/get-context/get-package-json-files/index.d.ts +2 -1
  54. package/dist/get-context/get-package-json-files/index.js +7 -5
  55. package/dist/get-context/get-package-json-files/package-json-file/index.js +7 -5
  56. package/dist/get-context/get-package-json-files/package-json-file/instance.d.ts +2 -1
  57. package/dist/get-context/get-package-json-files/package-json-file/instance.js +7 -6
  58. package/dist/get-context/index.d.ts +3 -2
  59. package/dist/get-context/index.js +22 -10
  60. package/dist/lib/disk.js +1 -1
  61. package/dist/lib/is-semver.js +1 -1
  62. package/dist/lib/log.js +7 -2
  63. package/dist/types.d.ts +1 -1
  64. package/package.json +17 -18
  65. package/dist/get-context/get-all-instances.d.ts +0 -3
  66. package/dist/get-context/get-all-instances.js +0 -8
  67. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.d.ts +0 -1
  68. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.js +0 -8
  69. package/dist/get-context/get-package-json-files/get-patterns/props.d.ts +0 -6
  70. package/dist/get-context/get-package-json-files/get-patterns/props.js +0 -24
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getHighestVersion = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
4
+ const result_1 = require("tightrope/result");
5
5
  const error_1 = require("../../../../lib/error");
6
6
  const clean_1 = require("./lib/clean");
7
7
  const compare_semver_1 = require("./lib/compare-semver");
@@ -9,14 +9,14 @@ 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
- return ts_belt_1.R.Ok(withRange);
15
+ return new result_1.Ok(withRange);
16
16
  }
17
17
  // impossible to know how the user wants to resolve unsupported versions
18
18
  case 'invalid': {
19
- return ts_belt_1.R.Error(new error_1.BaseError(`"${withRange}" is not supported`));
19
+ return new result_1.Err(new error_1.BaseError(`"${withRange}" is not supported`));
20
20
  }
21
21
  // we found a new highest version
22
22
  case 'gt': {
@@ -33,8 +33,8 @@ function getHighestVersion(versions) {
33
33
  }
34
34
  }
35
35
  return highest && highest.withRange
36
- ? ts_belt_1.R.Ok(highest.withRange)
37
- : ts_belt_1.R.Error(new error_1.BaseError(`getHighestVersion(): did not return a version`));
36
+ ? new result_1.Ok(highest.withRange)
37
+ : new result_1.Err(new error_1.BaseError(`getHighestVersion(): did not return a version`));
38
38
  }
39
39
  exports.getHighestVersion = getHighestVersion;
40
40
  function newHighestVersion(withRange) {
@@ -0,0 +1,2 @@
1
+ import type { Result } from 'tightrope/result';
2
+ export declare function getLowestVersion(versions: string[]): Result<string>;
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLowestVersion = void 0;
4
+ const result_1 = require("tightrope/result");
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 new result_1.Err(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
+ ? new result_1.Ok(lowest.withRange)
39
+ : new result_1.Err(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,8 @@
1
+ import type { Result } from 'tightrope/result';
1
2
  import type { VersionGroup } from '..';
2
3
  import type { Instance } from '../../../get-package-json-files/package-json-file/instance';
4
+ export declare const DELETE: unique symbol;
5
+ export type Delete = typeof DELETE;
3
6
  /** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
4
7
  export declare class InstanceGroup {
5
8
  /** Every package/pathName location where this dependency was found */
@@ -13,13 +16,19 @@ export declare class InstanceGroup {
13
16
  getUniqueVersions(): string[];
14
17
  hasMismatchingVersions(): boolean;
15
18
  isInvalid(): boolean;
16
- getExpectedVersion(): string | undefined;
17
- getHighestVersion(): string;
18
- getSnappedVersion(): string;
19
- isUnsnapped(): boolean;
19
+ getExpectedVersion(): Result<string | Delete>;
20
+ /** If all versions are valid semver, return the newest one */
21
+ getHighestVersion(): Result<string>;
22
+ /** If all versions are valid semver, return the lowest one */
23
+ getLowestVersion(): Result<string>;
24
+ /** Get the first version matched by the `snapTo` packages */
25
+ getSnappedVersion(): Result<string>;
26
+ /** Is `snapTo` defined and this group does not match that version? */
27
+ isUnsnapped(): Result<boolean>;
20
28
  /** Get version of dependency which is developed in this monorepo */
21
- getWorkspaceVersion(): string | undefined;
29
+ getWorkspaceVersion(): Result<string>;
22
30
  /** Find instance of this dependency which is developed in this monorepo */
23
- getWorkspaceInstance(): Instance | undefined;
31
+ getWorkspaceInstance(): Result<Instance>;
32
+ /** Is an instance of this dependency developed in this monorepo? */
24
33
  hasWorkspaceInstance(): boolean;
25
34
  }
@@ -1,11 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InstanceGroup = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
3
+ exports.InstanceGroup = exports.DELETE = void 0;
4
+ const uniq_1 = require("tightrope/array/uniq");
5
+ const get_1 = require("tightrope/fn/get");
6
+ const identity_1 = require("tightrope/fn/identity");
7
+ const pipe_1 = require("tightrope/fn/pipe");
8
+ const is_non_empty_string_1 = require("tightrope/guard/is-non-empty-string");
9
+ const filter_1 = require("tightrope/option/filter");
10
+ const map_1 = require("tightrope/option/map");
11
+ const ok_or_1 = require("tightrope/option/ok-or");
12
+ const result_1 = require("tightrope/result");
13
+ const and_then_1 = require("tightrope/result/and-then");
14
+ const filter_2 = require("tightrope/result/filter");
15
+ const is_ok_1 = require("tightrope/result/is-ok");
16
+ const map_2 = require("tightrope/result/map");
17
+ const map_err_1 = require("tightrope/result/map-err");
18
+ const unwrap_1 = require("tightrope/result/unwrap");
5
19
  const error_1 = require("../../../../lib/error");
6
20
  const is_semver_1 = require("../../../../lib/is-semver");
7
21
  const print_strings_1 = require("../../../../lib/print-strings");
8
22
  const get_highest_version_1 = require("./get-highest-version");
23
+ const get_lowest_version_1 = require("./get-lowest-version");
24
+ exports.DELETE = Symbol('DELETE');
9
25
  /** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
10
26
  class InstanceGroup {
11
27
  constructor(versionGroup, name, instances) {
@@ -17,7 +33,7 @@ class InstanceGroup {
17
33
  return this.instances.some((obj) => !(0, is_semver_1.isSemver)(obj.version));
18
34
  }
19
35
  getUniqueVersions() {
20
- return Array.from(new Set(this.instances.map((obj) => obj.version))).sort();
36
+ return (0, uniq_1.uniq)(this.instances.map((obj) => obj.version)).sort();
21
37
  }
22
38
  hasMismatchingVersions() {
23
39
  return this.getUniqueVersions().length > 1;
@@ -31,54 +47,57 @@ class InstanceGroup {
31
47
  }
32
48
  getExpectedVersion() {
33
49
  const versionGroup = this.versionGroup;
34
- const REMOVE_DEPENDENCY = undefined;
35
50
  if (versionGroup.isBanned())
36
- return REMOVE_DEPENDENCY;
51
+ return new result_1.Ok(exports.DELETE);
37
52
  if (versionGroup.isUnpinned())
38
- return versionGroup.getPinnedVersion();
39
- if (this.isUnsnapped())
53
+ return (0, pipe_1.pipe)(versionGroup.getPinnedVersion(), (0, ok_or_1.okOr)(new error_1.BaseError(`${this.name} is in a versionGroup with pinVersion configuration, but the pinVersion value is not valid`)));
54
+ if (versionGroup.hasSnappedToPackages() && (0, unwrap_1.unwrap)(this.isUnsnapped()))
40
55
  return this.getSnappedVersion();
41
56
  if (this.hasWorkspaceInstance())
42
57
  return this.getWorkspaceVersion();
43
58
  if (this.hasUnsupportedVersion()) {
44
- throw new error_1.BaseError(`${this.name} contains unsupported versions: ${(0, print_strings_1.printStrings)(this.getUniqueVersions())}`);
59
+ return new result_1.Err(new error_1.BaseError(`${this.name} contains unsupported versions: ${(0, print_strings_1.printStrings)(this.getUniqueVersions())}`));
45
60
  }
46
- return this.getHighestVersion();
61
+ return versionGroup.groupConfig.preferVersion ===
62
+ 'lowestSemver'
63
+ ? this.getLowestVersion()
64
+ : this.getHighestVersion();
47
65
  }
66
+ /** If all versions are valid semver, return the newest one */
48
67
  getHighestVersion() {
49
- return (0, ts_belt_1.pipe)((0, get_highest_version_1.getHighestVersion)(this.getUniqueVersions()), ts_belt_1.R.getExn);
68
+ return (0, get_highest_version_1.getHighestVersion)(this.getUniqueVersions());
50
69
  }
70
+ /** If all versions are valid semver, return the lowest one */
71
+ getLowestVersion() {
72
+ return (0, get_lowest_version_1.getLowestVersion)(this.getUniqueVersions());
73
+ }
74
+ /** Get the first version matched by the `snapTo` packages */
51
75
  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;
76
+ return (0, pipe_1.pipe)(this.versionGroup.getSnappedToPackages(), (0, map_1.map)((pkgNames) => this.instances
77
+ .filter(({ pkgName }) => pkgNames.includes(pkgName))
78
+ .map(({ version }) => version)
79
+ .find(Boolean) || ''), (0, filter_1.filter)(is_non_empty_string_1.isNonEmptyString), (0, ok_or_1.okOr)(new error_1.BaseError(`${this.name} is in a versionGroup with snapTo configuration, but ${this.name} was not found in those packages`)));
62
80
  }
81
+ /** Is `snapTo` defined and this group does not match that version? */
63
82
  isUnsnapped() {
64
- if (!this.versionGroup.hasSnappedToPackages())
65
- return false;
66
- const targetVersion = this.getSnappedVersion();
67
- return this.instances.some(({ version }) => version !== targetVersion);
83
+ return this.versionGroup.hasSnappedToPackages()
84
+ ? (0, pipe_1.pipe)(this.getSnappedVersion(), (0, map_2.map)((nextVersion) => this.instances.some(({ version }) => version !== nextVersion)))
85
+ : new result_1.Ok(false);
68
86
  }
69
87
  /** Get version of dependency which is developed in this monorepo */
70
88
  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');
89
+ return (0, pipe_1.pipe)(this.getWorkspaceInstance(), (0, and_then_1.andThen)((instance) => (0, get_1.get)(instance, 'packageJsonFile', 'contents', 'version')), (0, filter_2.filter)(is_non_empty_string_1.isNonEmptyString, ''), identity_1.identity, (0, map_err_1.mapErr)(() => 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
90
  }
76
91
  /** Find instance of this dependency which is developed in this monorepo */
77
92
  getWorkspaceInstance() {
78
- return this.instances.find(({ pathDef }) => pathDef.name === 'workspace');
93
+ const instance = this.instances.find(({ pathDef }) => pathDef.name === 'workspace');
94
+ return instance
95
+ ? new result_1.Ok(instance)
96
+ : new result_1.Err(new error_1.BaseError('Workspace instance not found'));
79
97
  }
98
+ /** Is an instance of this dependency developed in this monorepo? */
80
99
  hasWorkspaceInstance() {
81
- return this.getWorkspaceInstance() !== undefined;
100
+ return (0, is_ok_1.isOk)(this.getWorkspaceInstance());
82
101
  }
83
102
  }
84
103
  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,8 +1,7 @@
1
- import { R } from '@mobily/ts-belt';
1
+ import type { Result } from 'tightrope/result';
2
2
  import type { Disk } from '../../lib/disk';
3
- import { BaseError } from '../../lib/error';
4
3
  import type { Syncpack } from '../../types';
5
- type SafeFilePaths = R.Result<string[], BaseError>;
4
+ type SafeFilePaths = Result<string[]>;
6
5
  /**
7
6
  * Using --source options and/or config files on disk from npm/pnpm/yarn/lerna,
8
7
  * return an array of absolute paths to every package.json file the user is
@@ -1,11 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFilePaths = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
- const is_array_of_strings_1 = require("expect-more/dist/is-array-of-strings");
6
- const is_empty_array_1 = require("expect-more/dist/is-empty-array");
4
+ const flat_1 = require("tightrope/array/flat");
5
+ const uniq_1 = require("tightrope/array/uniq");
6
+ const pipe_1 = require("tightrope/fn/pipe");
7
+ const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
8
+ const and_then_1 = require("tightrope/result/and-then");
9
+ const filter_1 = require("tightrope/result/filter");
10
+ const from_try_1 = require("tightrope/result/from-try");
11
+ const map_1 = require("tightrope/result/map");
12
+ const map_err_1 = require("tightrope/result/map-err");
7
13
  const _R_1 = require("../$R");
8
- const error_1 = require("../../lib/error");
9
14
  const print_strings_1 = require("../../lib/print-strings");
10
15
  const get_patterns_1 = require("./get-patterns");
11
16
  /**
@@ -16,25 +21,10 @@ const get_patterns_1 = require("./get-patterns");
16
21
  * @returns Array of absolute file paths to package.json files
17
22
  */
18
23
  function getFilePaths(disk, program) {
19
- return (0, ts_belt_1.pipe)(program, (0, get_patterns_1.getPatterns)(disk), ts_belt_1.R.flatMap(resolvePatterns));
20
- function resolvePatterns(patterns) {
21
- const quoted = (0, print_strings_1.printStrings)(patterns);
22
- const ERR_NO_MATCH = `No package.json files matched the patterns: ${quoted}`;
23
- 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)));
24
- }
25
- function resolvePattern(pattern) {
26
- const ERR_GLOB_MISS = `No package.json files match pattern "${pattern}"`;
27
- const ERR_INVALID = `"glob" returned unexpected data on pattern "${pattern}"`;
28
- const ERR_GLOB_THROW = `"glob" threw on pattern "${pattern}"`;
29
- return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => disk.globSync(pattern)), ts_belt_1.R.mapError(error_1.BaseError.map(ERR_GLOB_THROW)), ts_belt_1.R.flatMap((filePaths) => (0, is_empty_array_1.isEmptyArray)(filePaths)
30
- ? ts_belt_1.R.Error(new error_1.BaseError(ERR_GLOB_MISS))
31
- : (0, is_array_of_strings_1.isArrayOfStrings)(filePaths)
32
- ? ts_belt_1.R.Ok((0, ts_belt_1.pipe)(filePaths, ts_belt_1.A.flat, ts_belt_1.A.uniq, removeReadonlyType))
33
- : ts_belt_1.R.Error(new error_1.BaseError(ERR_INVALID))));
34
- }
35
- /** Remove unwanted readonly type */
36
- function removeReadonlyType(value) {
37
- return value;
38
- }
24
+ return (0, pipe_1.pipe)(program, (0, get_patterns_1.getPatterns)(disk), (0, and_then_1.andThen)(function resolvePatterns(patterns) {
25
+ return (0, pipe_1.pipe)(patterns, _R_1.$R.onlyOk(function resolvePattern(pattern) {
26
+ return (0, pipe_1.pipe)((0, from_try_1.fromTry)(() => disk.globSync(pattern)), (0, filter_1.filter)(is_array_of_strings_1.isArrayOfStrings, `"glob" did not match "${pattern}"`), (0, map_1.map)(flat_1.flat), (0, map_1.map)(uniq_1.uniq), _R_1.$R.tapErrVerbose);
27
+ }), (0, map_1.map)(flat_1.flat), (0, map_1.map)(uniq_1.uniq), (0, map_err_1.mapErr)(() => new Error(`No files matched ${(0, print_strings_1.printStrings)(patterns)}`)));
28
+ }));
39
29
  }
40
30
  exports.getFilePaths = getFilePaths;
@@ -1,4 +1,3 @@
1
- import { R } from '@mobily/ts-belt';
1
+ import type { Result } from 'tightrope/result';
2
2
  import type { Disk } from '../../../lib/disk';
3
- import { BaseError } from '../../../lib/error';
4
- export declare function getLernaPatterns(disk: Disk): () => R.Result<string[], BaseError>;
3
+ export declare function getLernaPatterns(disk: Disk): () => Result<string[]>;
@@ -1,16 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getLernaPatterns = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
4
  const path_1 = require("path");
5
+ const get_1 = require("tightrope/fn/get");
6
+ const pipe_1 = require("tightrope/fn/pipe");
7
+ const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
8
+ const and_then_1 = require("tightrope/result/and-then");
9
+ const filter_1 = require("tightrope/result/filter");
6
10
  const constants_1 = require("../../../constants");
7
- const error_1 = require("../../../lib/error");
8
- const get_array_of_strings_1 = require("./lib/get-array-of-strings");
9
11
  const read_json_safe_1 = require("./read-json-safe");
10
12
  function getLernaPatterns(disk) {
11
- const getPackages = (0, get_array_of_strings_1.getArrayOfStrings)('packages');
12
13
  return function getLernaPatterns() {
13
- return (0, ts_belt_1.pipe)((0, path_1.join)(constants_1.CWD, 'lerna.json'), (0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.flatMap(({ contents }) => (0, ts_belt_1.pipe)(getPackages(contents), ts_belt_1.O.toResult(new error_1.BaseError('no lerna patterns found')))));
14
+ return (0, pipe_1.pipe)((0, path_1.join)(constants_1.CWD, 'lerna.json'), (0, read_json_safe_1.readJsonSafe)(disk), (0, and_then_1.andThen)((file) => (0, get_1.get)(file, 'contents', 'packages')), (0, filter_1.filter)(is_array_of_strings_1.isArrayOfStrings, 'no lerna patterns found'));
14
15
  };
15
16
  }
16
17
  exports.getLernaPatterns = getLernaPatterns;
@@ -1,4 +1,3 @@
1
- import { R } from '@mobily/ts-belt';
1
+ import type { Result } from 'tightrope/result';
2
2
  import type { Disk } from '../../../lib/disk';
3
- import { BaseError } from '../../../lib/error';
4
- export declare function getPnpmPatterns(disk: Disk): () => R.Result<string[], BaseError>;
3
+ export declare function getPnpmPatterns(disk: Disk): () => Result<string[]>;
@@ -1,21 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPnpmPatterns = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
4
  const path_1 = require("path");
5
+ const get_1 = require("tightrope/fn/get");
6
+ const pipe_1 = require("tightrope/fn/pipe");
7
+ const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
8
+ const and_then_1 = require("tightrope/result/and-then");
9
+ const filter_1 = require("tightrope/result/filter");
6
10
  const constants_1 = require("../../../constants");
7
- const error_1 = require("../../../lib/error");
8
- const get_array_of_strings_1 = require("./lib/get-array-of-strings");
9
11
  const read_yaml_safe_1 = require("./read-yaml-safe");
10
- const getPackages = (0, get_array_of_strings_1.getArrayOfStrings)('packages');
11
12
  function getPnpmPatterns(disk) {
12
13
  return function getPnpmPatterns() {
13
- return (0, ts_belt_1.pipe)(
14
+ return (0, pipe_1.pipe)(
14
15
  // packages:
15
16
  // - "packages/**"
16
17
  // - "components/**"
17
18
  // - "!**/test/**"
18
- (0, path_1.join)(constants_1.CWD, 'pnpm-workspace.yaml'), (0, read_yaml_safe_1.readYamlSafe)(disk), ts_belt_1.R.flatMap((packageJson) => (0, ts_belt_1.pipe)(getPackages(packageJson), ts_belt_1.O.match(ts_belt_1.F.identity, () => getPackages(packageJson)), ts_belt_1.O.toResult(new error_1.BaseError('no pnpm patterns found')))));
19
+ (0, path_1.join)(constants_1.CWD, 'pnpm-workspace.yaml'), (0, read_yaml_safe_1.readYamlSafe)(disk), (0, and_then_1.andThen)((file) => (0, get_1.get)(file, 'packages')), (0, filter_1.filter)(is_array_of_strings_1.isArrayOfStrings, 'no pnpm patterns found'));
19
20
  };
20
21
  }
21
22
  exports.getPnpmPatterns = getPnpmPatterns;
@@ -1,4 +1,3 @@
1
- import { R } from '@mobily/ts-belt';
1
+ import type { Result } from 'tightrope/result';
2
2
  import type { Disk } from '../../../lib/disk';
3
- import { BaseError } from '../../../lib/error';
4
- export declare function getYarnPatterns(disk: Disk): () => R.Result<string[], BaseError>;
3
+ export declare function getYarnPatterns(disk: Disk): () => Result<string[]>;
@@ -1,17 +1,18 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getYarnPatterns = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
4
  const path_1 = require("path");
5
+ const get_1 = require("tightrope/fn/get");
6
+ const pipe_1 = require("tightrope/fn/pipe");
7
+ const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
8
+ const and_then_1 = require("tightrope/result/and-then");
9
+ const filter_1 = require("tightrope/result/filter");
10
+ const or_else_1 = require("tightrope/result/or-else");
6
11
  const constants_1 = require("../../../constants");
7
- const error_1 = require("../../../lib/error");
8
- const get_array_of_strings_1 = require("./lib/get-array-of-strings");
9
12
  const read_json_safe_1 = require("./read-json-safe");
10
13
  function getYarnPatterns(disk) {
11
- const getPackages = (0, get_array_of_strings_1.getArrayOfStrings)('workspaces');
12
- const getPackagesNested = (0, get_array_of_strings_1.getArrayOfStrings)('workspaces.packages');
13
14
  return function getYarnPatterns() {
14
- return (0, ts_belt_1.pipe)((0, path_1.join)(constants_1.CWD, 'package.json'), (0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.flatMap(({ contents }) => (0, ts_belt_1.pipe)(getPackages(contents), ts_belt_1.O.match(ts_belt_1.F.identity, () => getPackagesNested(contents)), ts_belt_1.O.toResult(new error_1.BaseError('no yarn patterns found')))));
15
+ return (0, pipe_1.pipe)((0, path_1.join)(constants_1.CWD, 'package.json'), (0, read_json_safe_1.readJsonSafe)(disk), (0, and_then_1.andThen)((file) => (0, pipe_1.pipe)((0, get_1.get)(file, 'contents', 'workspaces', 'packages'), (0, or_else_1.orElse)(() => (0, get_1.get)(file, 'contents', 'workspaces')))), (0, filter_1.filter)(is_array_of_strings_1.isArrayOfStrings, 'no yarn patterns found'));
15
16
  };
16
17
  }
17
18
  exports.getYarnPatterns = getYarnPatterns;
@@ -1,6 +1,5 @@
1
- import { R } from '@mobily/ts-belt';
1
+ import type { Result } from 'tightrope/result';
2
2
  import type { Disk } from '../../../lib/disk';
3
- import { BaseError } from '../../../lib/error';
4
3
  import type { Syncpack } from '../../../types';
5
4
  /**
6
5
  * Find every glob pattern which should be used to find package.json files for
@@ -8,4 +7,4 @@ import type { Syncpack } from '../../../types';
8
7
  *
9
8
  * @returns `['./package.json', './packages/* /package.json']`
10
9
  */
11
- export declare function getPatterns(disk: Disk): (program: Syncpack.Config.SyncpackRc) => R.Result<string[], BaseError>;
10
+ export declare function getPatterns(disk: Disk): (program: Syncpack.Config.SyncpackRc) => Result<string[]>;
@@ -1,10 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPatterns = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
- const is_array_of_strings_1 = require("expect-more/dist/is-array-of-strings");
4
+ const pipe_1 = require("tightrope/fn/pipe");
5
+ const is_array_of_strings_1 = require("tightrope/guard/is-array-of-strings");
6
+ const result_1 = require("tightrope/result");
7
+ const from_guard_1 = require("tightrope/result/from-guard");
8
+ const map_1 = require("tightrope/result/map");
9
+ const or_else_1 = require("tightrope/result/or-else");
6
10
  const constants_1 = require("../../../constants");
7
- const error_1 = require("../../../lib/error");
8
11
  const get_lerna_patterns_1 = require("./get-lerna-patterns");
9
12
  const get_pnpm_patterns_1 = require("./get-pnpm-patterns");
10
13
  const get_yarn_patterns_1 = require("./get-yarn-patterns");
@@ -16,21 +19,9 @@ const get_yarn_patterns_1 = require("./get-yarn-patterns");
16
19
  */
17
20
  function getPatterns(disk) {
18
21
  return function getPatterns(program) {
19
- const getters = [
20
- getCliPatterns,
21
- (0, get_yarn_patterns_1.getYarnPatterns)(disk),
22
- (0, get_pnpm_patterns_1.getPnpmPatterns)(disk),
23
- (0, get_lerna_patterns_1.getLernaPatterns)(disk),
24
- ];
25
- const initialResult = ts_belt_1.R.Error(new error_1.BaseError('getPatterns did not try any sources'));
26
- const res = ts_belt_1.A.reduce(getters, initialResult, (previousResult, getNextResult) => {
27
- if (ts_belt_1.R.isOk(previousResult))
28
- return previousResult;
29
- return getNextResult();
30
- });
31
- return (0, ts_belt_1.pipe)(res, ts_belt_1.R.map(addRootDir), ts_belt_1.R.map(limitToPackageJson), ts_belt_1.R.handleError(() => constants_1.DEFAULT_SOURCES), ts_belt_1.R.mapError(ts_belt_1.F.identity));
22
+ return (0, pipe_1.pipe)(getCliPatterns(), (0, or_else_1.orElse)((0, get_yarn_patterns_1.getYarnPatterns)(disk)), (0, or_else_1.orElse)((0, get_pnpm_patterns_1.getPnpmPatterns)(disk)), (0, or_else_1.orElse)((0, get_lerna_patterns_1.getLernaPatterns)(disk)), (0, map_1.map)(addRootDir), (0, map_1.map)(limitToPackageJson), (0, or_else_1.orElse)(() => new result_1.Ok(constants_1.DEFAULT_SOURCES)));
32
23
  function getCliPatterns() {
33
- return ts_belt_1.R.fromPredicate(program.source, is_array_of_strings_1.isArrayOfStrings, new error_1.BaseError('No --source options provided'));
24
+ return (0, from_guard_1.fromGuard)(is_array_of_strings_1.isArrayOfStrings, new Error('No --source options provided'), program.source);
34
25
  }
35
26
  function addRootDir(patterns) {
36
27
  return ['package.json', ...patterns];
@@ -1,6 +1,5 @@
1
- import { R } from '@mobily/ts-belt';
1
+ import type { Result } from 'tightrope/result';
2
2
  import type { Disk } from '../../../lib/disk';
3
- import { BaseError } from '../../../lib/error';
4
3
  export interface JsonFile<T> {
5
4
  /** absolute path on disk to this file */
6
5
  readonly filePath: string;
@@ -9,4 +8,4 @@ export interface JsonFile<T> {
9
8
  /** raw file contents of the file */
10
9
  readonly json: string;
11
10
  }
12
- export declare function readJsonSafe<T>(disk: Disk): (filePath: string) => R.Result<JsonFile<T>, BaseError>;
11
+ export declare function readJsonSafe<T>(disk: Disk): (filePath: string) => Result<JsonFile<T>>;
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readJsonSafe = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
- const error_1 = require("../../../lib/error");
4
+ const pipe_1 = require("tightrope/fn/pipe");
5
+ const and_then_1 = require("tightrope/result/and-then");
6
+ const from_try_1 = require("tightrope/result/from-try");
7
+ const map_1 = require("tightrope/result/map");
8
+ const map_err_1 = require("tightrope/result/map-err");
6
9
  function readJsonSafe(disk) {
7
10
  return function readJsonSafe(filePath) {
8
- return (0, ts_belt_1.pipe)(readFileSafe(filePath), ts_belt_1.R.flatMap((0, ts_belt_1.flow)((parseJsonSafe), ts_belt_1.R.mapError(error_1.BaseError.map(`Failed to parse JSON file at ${filePath}`)), ts_belt_1.R.map(({ contents, json }) => ({ contents, filePath, json })))));
11
+ return (0, pipe_1.pipe)((0, from_try_1.fromTry)(() => disk.readFileSync(filePath)), (0, and_then_1.andThen)((json) => (0, pipe_1.pipe)((0, from_try_1.fromTry)(() => JSON.parse(json)), (0, map_1.map)((contents) => ({ contents, json })))), (0, map_1.map)(({ contents, json }) => ({ contents, filePath, json })), (0, map_err_1.mapErr)(() => new Error(`Failed to read JSON file at ${filePath}`)));
9
12
  };
10
- function readFileSafe(filePath) {
11
- return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => disk.readFileSync(filePath)), ts_belt_1.R.mapError(error_1.BaseError.map(`Failed to read JSON file at ${filePath}`)));
12
- }
13
13
  }
14
14
  exports.readJsonSafe = readJsonSafe;
15
- function parseJsonSafe(json) {
16
- return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => JSON.parse(json)), ts_belt_1.R.mapError(error_1.BaseError.map('Failed to parse JSON')), ts_belt_1.R.map((contents) => ({ contents, json })));
17
- }
@@ -1,4 +1,3 @@
1
- import { R } from '@mobily/ts-belt';
1
+ import type { Result } from 'tightrope/result';
2
2
  import type { Disk } from '../../../lib/disk';
3
- import { BaseError } from '../../../lib/error';
4
- export declare function readYamlSafe<T = unknown>(disk: Disk): (filePath: string) => R.Result<T, BaseError>;
3
+ export declare function readYamlSafe<T = unknown>(disk: Disk): (filePath: string) => Result<T>;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readYamlSafe = void 0;
4
- const ts_belt_1 = require("@mobily/ts-belt");
5
- const error_1 = require("../../../lib/error");
4
+ const pipe_1 = require("tightrope/fn/pipe");
5
+ const from_try_1 = require("tightrope/result/from-try");
6
+ const map_err_1 = require("tightrope/result/map-err");
6
7
  function readYamlSafe(disk) {
7
8
  return function readYamlSafe(filePath) {
8
- return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => disk.readYamlFileSync(filePath)), ts_belt_1.R.mapError(error_1.BaseError.map(`Failed to read YAML file at ${filePath}`)));
9
+ return (0, pipe_1.pipe)((0, from_try_1.fromTry)(() => disk.readYamlFileSync(filePath)), (0, map_err_1.mapErr)(() => new Error(`Failed to read YAML file at ${filePath}`)));
9
10
  };
10
11
  }
11
12
  exports.readYamlSafe = readYamlSafe;
@@ -1,5 +1,6 @@
1
+ import type { Result } from 'tightrope/result';
1
2
  import type { Disk } from '../../lib/disk';
2
3
  import type { Syncpack } from '../../types';
3
4
  import { PackageJsonFile } from './package-json-file';
4
5
  /** Create an API for every package.json file needed. */
5
- export declare function getPackageJsonFiles(disk: Disk, config: Syncpack.Config.Private): PackageJsonFile[];
6
+ export declare function getPackageJsonFiles(disk: Disk, config: Syncpack.Config.Private): Result<PackageJsonFile[]>;