syncpack 9.8.4 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (212) hide show
  1. package/LICENSE +12 -13
  2. package/README.md +17 -19
  3. package/dist/bin-fix-mismatches/fix-mismatches-cli.d.ts +2 -2
  4. package/dist/bin-fix-mismatches/fix-mismatches-cli.js +3 -1
  5. package/dist/bin-fix-mismatches/fix-mismatches.d.ts +2 -2
  6. package/dist/bin-fix-mismatches/fix-mismatches.js +44 -25
  7. package/dist/bin-format/format-cli.d.ts +2 -2
  8. package/dist/bin-format/format-cli.js +2 -1
  9. package/dist/bin-format/format.d.ts +2 -2
  10. package/dist/bin-format/format.js +7 -4
  11. package/dist/bin-lint-semver-ranges/lint-semver-ranges-cli.d.ts +2 -2
  12. package/dist/bin-lint-semver-ranges/lint-semver-ranges-cli.js +2 -1
  13. package/dist/bin-lint-semver-ranges/lint-semver-ranges.d.ts +2 -2
  14. package/dist/bin-lint-semver-ranges/lint-semver-ranges.js +29 -25
  15. package/dist/bin-list/list-cli.d.ts +2 -2
  16. package/dist/bin-list/list-cli.js +2 -1
  17. package/dist/bin-list/list.d.ts +2 -2
  18. package/dist/bin-list/list.js +58 -52
  19. package/dist/bin-list-mismatches/list-mismatches-cli.d.ts +2 -2
  20. package/dist/bin-list-mismatches/list-mismatches-cli.js +2 -1
  21. package/dist/bin-list-mismatches/list-mismatches.d.ts +2 -2
  22. package/dist/bin-list-mismatches/list-mismatches.js +72 -105
  23. package/dist/bin-set-semver-ranges/set-semver-ranges-cli.d.ts +2 -2
  24. package/dist/bin-set-semver-ranges/set-semver-ranges-cli.js +2 -1
  25. package/dist/bin-set-semver-ranges/set-semver-ranges.d.ts +2 -2
  26. package/dist/bin-set-semver-ranges/set-semver-ranges.js +17 -3
  27. package/dist/config/get-custom-types.d.ts +9 -0
  28. package/dist/config/get-custom-types.js +49 -0
  29. package/dist/config/get-enabled-types.d.ts +3 -0
  30. package/dist/config/get-enabled-types.js +48 -0
  31. package/dist/config/get-filter.d.ts +2 -0
  32. package/dist/config/get-filter.js +13 -0
  33. package/dist/config/get-indent.d.ts +2 -0
  34. package/dist/config/get-indent.js +12 -0
  35. package/dist/config/get-semver-range.d.ts +3 -0
  36. package/dist/config/get-semver-range.js +12 -0
  37. package/dist/config/get-sort-az.d.ts +2 -0
  38. package/dist/config/get-sort-az.js +18 -0
  39. package/dist/config/get-sort-first.d.ts +2 -0
  40. package/dist/config/get-sort-first.js +10 -0
  41. package/dist/config/get-source.d.ts +2 -0
  42. package/dist/config/get-source.js +13 -0
  43. package/dist/config/types.d.ts +106 -0
  44. package/dist/constants.d.ts +1 -0
  45. package/dist/constants.js +1 -0
  46. package/dist/get-context/index.d.ts +8 -16
  47. package/dist/get-context/index.js +8 -31
  48. package/dist/get-package-json-files/get-file-paths.d.ts +13 -0
  49. package/dist/get-package-json-files/get-file-paths.js +30 -0
  50. package/dist/get-package-json-files/get-patterns/get-lerna-patterns.d.ts +3 -0
  51. package/dist/get-package-json-files/get-patterns/get-lerna-patterns.js +17 -0
  52. package/dist/get-package-json-files/get-patterns/get-pnpm-patterns.d.ts +3 -0
  53. package/dist/get-package-json-files/get-patterns/get-pnpm-patterns.js +22 -0
  54. package/dist/get-package-json-files/get-patterns/get-yarn-patterns.d.ts +3 -0
  55. package/dist/get-package-json-files/get-patterns/get-yarn-patterns.js +18 -0
  56. package/dist/get-package-json-files/get-patterns/index.d.ts +10 -0
  57. package/dist/get-package-json-files/get-patterns/index.js +35 -0
  58. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/read-json-safe.d.ts +3 -4
  59. package/dist/get-package-json-files/get-patterns/read-json-safe.js +14 -0
  60. package/dist/get-package-json-files/get-patterns/read-yaml-safe.d.ts +3 -0
  61. package/dist/get-package-json-files/get-patterns/read-yaml-safe.js +12 -0
  62. package/dist/get-package-json-files/index.d.ts +6 -0
  63. package/dist/get-package-json-files/index.js +18 -0
  64. package/dist/{get-context/get-package-json-files/package-json-file → get-package-json-files}/instance.d.ts +6 -8
  65. package/dist/get-package-json-files/instance.js +23 -0
  66. package/dist/{get-context/get-package-json-files/package-json-file/index.d.ts → get-package-json-files/package-json-file.d.ts} +7 -9
  67. package/dist/get-package-json-files/package-json-file.js +45 -0
  68. package/dist/get-semver-groups/catch-all.d.ts +4 -0
  69. package/dist/get-semver-groups/catch-all.js +11 -0
  70. package/dist/get-semver-groups/filtered-out.d.ts +13 -0
  71. package/dist/get-semver-groups/filtered-out.js +29 -0
  72. package/dist/get-semver-groups/ignored.d.ts +11 -0
  73. package/dist/get-semver-groups/ignored.js +22 -0
  74. package/dist/get-semver-groups/index.d.ts +32 -0
  75. package/dist/get-semver-groups/index.js +90 -0
  76. package/dist/get-semver-groups/with-range.d.ts +11 -0
  77. package/dist/get-semver-groups/with-range.js +55 -0
  78. package/dist/get-version-groups/banned.d.ts +11 -0
  79. package/dist/get-version-groups/banned.js +24 -0
  80. package/dist/get-version-groups/catch-all.d.ts +4 -0
  81. package/dist/get-version-groups/catch-all.js +11 -0
  82. package/dist/get-version-groups/filtered-out.d.ts +13 -0
  83. package/dist/get-version-groups/filtered-out.js +31 -0
  84. package/dist/get-version-groups/ignored.d.ts +11 -0
  85. package/dist/get-version-groups/ignored.js +24 -0
  86. package/dist/get-version-groups/index.d.ts +57 -0
  87. package/dist/get-version-groups/index.js +119 -0
  88. package/dist/get-version-groups/lib/delete.d.ts +2 -0
  89. package/dist/get-version-groups/lib/delete.js +4 -0
  90. package/dist/get-version-groups/lib/get-highest-version.d.ts +2 -0
  91. package/dist/get-version-groups/lib/get-highest-version.js +13 -0
  92. package/dist/get-version-groups/lib/get-lowest-version.d.ts +2 -0
  93. package/dist/get-version-groups/lib/get-lowest-version.js +13 -0
  94. package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/get-range-score.js +3 -2
  95. package/dist/get-version-groups/lib/get-unique-versions.d.ts +2 -0
  96. package/dist/get-version-groups/lib/get-unique-versions.js +8 -0
  97. package/dist/get-version-groups/lib/group-by.d.ts +1 -0
  98. package/dist/get-version-groups/lib/group-by.js +11 -0
  99. package/dist/get-version-groups/lib/sort.d.ts +1 -0
  100. package/dist/get-version-groups/lib/sort.js +44 -0
  101. package/dist/get-version-groups/pinned.d.ts +11 -0
  102. package/dist/get-version-groups/pinned.js +43 -0
  103. package/dist/get-version-groups/snapped-to.d.ts +11 -0
  104. package/dist/get-version-groups/snapped-to.js +52 -0
  105. package/dist/get-version-groups/standard.d.ts +11 -0
  106. package/dist/get-version-groups/standard.js +95 -0
  107. package/dist/index.d.ts +2 -0
  108. package/dist/lib/$R.d.ts +12 -0
  109. package/dist/lib/$R.js +34 -0
  110. package/dist/lib/disk.d.ts +3 -2
  111. package/dist/lib/disk.js +1 -1
  112. package/dist/lib/exit-if-invalid.d.ts +2 -2
  113. package/dist/lib/is-semver.d.ts +5 -3
  114. package/dist/lib/is-semver.js +18 -4
  115. package/dist/lib/log.d.ts +4 -8
  116. package/dist/lib/log.js +4 -30
  117. package/dist/lib/set-semver-range.d.ts +2 -2
  118. package/dist/lib/write-if-changed.d.ts +2 -2
  119. package/dist/lib/write-if-changed.js +6 -25
  120. package/dist/strategy/lib/get-non-empty-string-prop.d.ts +3 -0
  121. package/dist/strategy/lib/get-non-empty-string-prop.js +12 -0
  122. package/dist/strategy/name-and-version-props.d.ts +12 -0
  123. package/dist/strategy/name-and-version-props.js +50 -0
  124. package/dist/strategy/named-version-string.d.ts +11 -0
  125. package/dist/strategy/named-version-string.js +53 -0
  126. package/dist/strategy/unnamed-version-string.d.ts +11 -0
  127. package/dist/strategy/unnamed-version-string.js +48 -0
  128. package/dist/strategy/versions-by-name.d.ts +11 -0
  129. package/dist/strategy/versions-by-name.js +29 -0
  130. package/package.json +23 -20
  131. package/dist/get-context/$R.d.ts +0 -13
  132. package/dist/get-context/$R.js +0 -34
  133. package/dist/get-context/get-config/get-core-types.d.ts +0 -36
  134. package/dist/get-context/get-config/get-core-types.js +0 -38
  135. package/dist/get-context/get-config/get-custom-types.d.ts +0 -4
  136. package/dist/get-context/get-config/get-custom-types.js +0 -16
  137. package/dist/get-context/get-config/get-enabled-types.d.ts +0 -4
  138. package/dist/get-context/get-config/get-enabled-types.js +0 -17
  139. package/dist/get-context/get-config/index.d.ts +0 -9
  140. package/dist/get-context/get-config/index.js +0 -91
  141. package/dist/get-context/get-config/path-strategy/index.d.ts +0 -8
  142. package/dist/get-context/get-config/path-strategy/index.js +0 -18
  143. package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.d.ts +0 -4
  144. package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.js +0 -11
  145. package/dist/get-context/get-config/path-strategy/name-and-version-props.d.ts +0 -2
  146. package/dist/get-context/get-config/path-strategy/name-and-version-props.js +0 -40
  147. package/dist/get-context/get-config/path-strategy/name-and-version-string.d.ts +0 -2
  148. package/dist/get-context/get-config/path-strategy/name-and-version-string.js +0 -44
  149. package/dist/get-context/get-config/path-strategy/types.d.ts +0 -15
  150. package/dist/get-context/get-config/path-strategy/version-string.d.ts +0 -2
  151. package/dist/get-context/get-config/path-strategy/version-string.js +0 -44
  152. package/dist/get-context/get-config/path-strategy/versions-by-name.d.ts +0 -2
  153. package/dist/get-context/get-config/path-strategy/versions-by-name.js +0 -23
  154. package/dist/get-context/get-config/schema/base-group.d.ts +0 -7
  155. package/dist/get-context/get-config/schema/base-group.js +0 -10
  156. package/dist/get-context/get-config/schema/index.d.ts +0 -1540
  157. package/dist/get-context/get-config/schema/index.js +0 -81
  158. package/dist/get-context/get-config/schema/lib/non-empty-string.d.ts +0 -2
  159. package/dist/get-context/get-config/schema/lib/non-empty-string.js +0 -5
  160. package/dist/get-context/get-config/schema/paths.d.ts +0 -89
  161. package/dist/get-context/get-config/schema/paths.js +0 -33
  162. package/dist/get-context/get-config/schema/semver-group.d.ts +0 -119
  163. package/dist/get-context/get-config/schema/semver-group.js +0 -43
  164. package/dist/get-context/get-config/schema/semver-range.d.ts +0 -2
  165. package/dist/get-context/get-config/schema/semver-range.js +0 -16
  166. package/dist/get-context/get-config/schema/version-group.d.ts +0 -230
  167. package/dist/get-context/get-config/schema/version-group.js +0 -36
  168. package/dist/get-context/get-groups/base-group.d.ts +0 -22
  169. package/dist/get-context/get-groups/base-group.js +0 -39
  170. package/dist/get-context/get-groups/index.d.ts +0 -12
  171. package/dist/get-context/get-groups/index.js +0 -51
  172. package/dist/get-context/get-groups/semver-group.d.ts +0 -15
  173. package/dist/get-context/get-groups/semver-group.js +0 -46
  174. package/dist/get-context/get-groups/version-group/index.d.ts +0 -15
  175. package/dist/get-context/get-groups/version-group/index.js +0 -36
  176. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.d.ts +0 -3
  177. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +0 -42
  178. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.d.ts +0 -3
  179. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.js +0 -44
  180. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +0 -35
  181. package/dist/get-context/get-groups/version-group/instance-group/index.js +0 -88
  182. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +0 -4
  183. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +0 -38
  184. package/dist/get-context/get-package-json-files/get-file-paths.d.ts +0 -14
  185. package/dist/get-context/get-package-json-files/get-file-paths.js +0 -40
  186. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.d.ts +0 -4
  187. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.js +0 -16
  188. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.d.ts +0 -4
  189. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.js +0 -21
  190. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.d.ts +0 -4
  191. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.js +0 -17
  192. package/dist/get-context/get-package-json-files/get-patterns/index.d.ts +0 -11
  193. package/dist/get-context/get-package-json-files/get-patterns/index.js +0 -43
  194. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.d.ts +0 -1
  195. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.js +0 -8
  196. package/dist/get-context/get-package-json-files/get-patterns/props.d.ts +0 -6
  197. package/dist/get-context/get-package-json-files/get-patterns/props.js +0 -24
  198. package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.js +0 -17
  199. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.d.ts +0 -4
  200. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.js +0 -11
  201. package/dist/get-context/get-package-json-files/index.d.ts +0 -7
  202. package/dist/get-context/get-package-json-files/index.js +0 -16
  203. package/dist/get-context/get-package-json-files/package-json-file/index.js +0 -63
  204. package/dist/get-context/get-package-json-files/package-json-file/instance.js +0 -46
  205. package/dist/lib/error.d.ts +0 -12
  206. package/dist/lib/error.js +0 -25
  207. package/dist/types.d.ts +0 -90
  208. /package/dist/{get-context/get-config/path-strategy → config}/types.js +0 -0
  209. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/clean.d.ts +0 -0
  210. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/clean.js +0 -0
  211. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/get-range-score.d.ts +0 -0
  212. /package/dist/{types.js → index.js} +0 -0
@@ -1,40 +1,17 @@
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");
5
- const disk_1 = require("../lib/disk");
6
- const _R_1 = require("./$R");
7
- const get_config_1 = require("./get-config");
8
- const get_groups_1 = require("./get-groups");
9
- const get_package_json_files_1 = require("./get-package-json-files");
10
- /**
11
- * Every command in syncpack should accept the return value of this function as
12
- * its input.
13
- *
14
- * The aim here is to move all disk activity to a single place, so
15
- * that the majority of syncpack and its tests don't have to deal with the file
16
- * system and can focus solely on transformation logic.
17
- */
18
- function getContext(program, disk = disk_1.disk) {
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 }) => ({
4
+ const unwrap_1 = require("tightrope/result/unwrap");
5
+ const get_package_json_files_1 = require("../get-package-json-files");
6
+ function getContext(cli, disk) {
7
+ const rcFile = disk.readConfigFileSync(cli.configPath);
8
+ const config = { cli, rcFile };
9
+ const packageJsonFiles = (0, unwrap_1.unwrap)((0, get_package_json_files_1.getPackageJsonFiles)(disk, config));
10
+ return {
28
11
  config,
29
12
  disk,
30
13
  isInvalid: false,
31
14
  packageJsonFiles,
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);
15
+ };
39
16
  }
40
17
  exports.getContext = getContext;
@@ -0,0 +1,13 @@
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Context } from '../get-context';
3
+ import type { Disk } from '../lib/disk';
4
+ type SafeFilePaths = Result<string[]>;
5
+ /**
6
+ * Using --source options and/or config files on disk from npm/pnpm/yarn/lerna,
7
+ * return an array of absolute paths to every package.json file the user is
8
+ * working with.
9
+ *
10
+ * @returns Array of absolute file paths to package.json files
11
+ */
12
+ export declare function getFilePaths(disk: Disk, config: Context['config']): SafeFilePaths;
13
+ export {};
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFilePaths = void 0;
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");
13
+ const _R_1 = require("../lib/$R");
14
+ const print_strings_1 = require("../lib/print-strings");
15
+ const get_patterns_1 = require("./get-patterns");
16
+ /**
17
+ * Using --source options and/or config files on disk from npm/pnpm/yarn/lerna,
18
+ * return an array of absolute paths to every package.json file the user is
19
+ * working with.
20
+ *
21
+ * @returns Array of absolute file paths to package.json files
22
+ */
23
+ function getFilePaths(disk, config) {
24
+ return (0, pipe_1.pipe)(config, (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
+ }));
29
+ }
30
+ exports.getFilePaths = getFilePaths;
@@ -0,0 +1,3 @@
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Disk } from '../../lib/disk';
3
+ export declare function getLernaPatterns(disk: Disk): () => Result<string[]>;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getLernaPatterns = void 0;
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 constants_1 = require("../../constants");
11
+ const read_json_safe_1 = require("./read-json-safe");
12
+ function getLernaPatterns(disk) {
13
+ return function getLernaPatterns() {
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'));
15
+ };
16
+ }
17
+ exports.getLernaPatterns = getLernaPatterns;
@@ -0,0 +1,3 @@
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Disk } from '../../lib/disk';
3
+ export declare function getPnpmPatterns(disk: Disk): () => Result<string[]>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPnpmPatterns = void 0;
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 constants_1 = require("../../constants");
11
+ const read_yaml_safe_1 = require("./read-yaml-safe");
12
+ function getPnpmPatterns(disk) {
13
+ return function getPnpmPatterns() {
14
+ return (0, pipe_1.pipe)(
15
+ // packages:
16
+ // - "packages/**"
17
+ // - "components/**"
18
+ // - "!**/test/**"
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'));
20
+ };
21
+ }
22
+ exports.getPnpmPatterns = getPnpmPatterns;
@@ -0,0 +1,3 @@
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Disk } from '../../lib/disk';
3
+ export declare function getYarnPatterns(disk: Disk): () => Result<string[]>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getYarnPatterns = void 0;
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");
11
+ const constants_1 = require("../../constants");
12
+ const read_json_safe_1 = require("./read-json-safe");
13
+ function getYarnPatterns(disk) {
14
+ return function getYarnPatterns() {
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'));
16
+ };
17
+ }
18
+ exports.getYarnPatterns = getYarnPatterns;
@@ -0,0 +1,10 @@
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Context } from '../../get-context';
3
+ import type { Disk } from '../../lib/disk';
4
+ /**
5
+ * Find every glob pattern which should be used to find package.json files for
6
+ * this monorepo.
7
+ *
8
+ * @returns `['./package.json', './packages/* /package.json']`
9
+ */
10
+ export declare function getPatterns(disk: Disk): (config: Context['config']) => Result<string[]>;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPatterns = void 0;
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");
10
+ const get_source_1 = require("../../config/get-source");
11
+ const constants_1 = require("../../constants");
12
+ const get_lerna_patterns_1 = require("./get-lerna-patterns");
13
+ const get_pnpm_patterns_1 = require("./get-pnpm-patterns");
14
+ const get_yarn_patterns_1 = require("./get-yarn-patterns");
15
+ /**
16
+ * Find every glob pattern which should be used to find package.json files for
17
+ * this monorepo.
18
+ *
19
+ * @returns `['./package.json', './packages/* /package.json']`
20
+ */
21
+ function getPatterns(disk) {
22
+ return function getPatterns(config) {
23
+ 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)));
24
+ function getCliPatterns() {
25
+ return (0, from_guard_1.fromGuard)(is_array_of_strings_1.isArrayOfStrings, new Error('No --source options provided'), (0, get_source_1.getSource)(config));
26
+ }
27
+ function addRootDir(patterns) {
28
+ return ['package.json', ...patterns];
29
+ }
30
+ function limitToPackageJson(patterns) {
31
+ return patterns.map((pattern) => pattern.includes('package.json') ? pattern : `${pattern}/package.json`);
32
+ }
33
+ };
34
+ }
35
+ exports.getPatterns = getPatterns;
@@ -1,6 +1,5 @@
1
- import { R } from '@mobily/ts-belt';
2
- import type { Disk } from '../../../lib/disk';
3
- import { BaseError } from '../../../lib/error';
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Disk } from '../../lib/disk';
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>>;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readJsonSafe = void 0;
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");
9
+ function readJsonSafe(disk) {
10
+ return function readJsonSafe(filePath) {
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}`)));
12
+ };
13
+ }
14
+ exports.readJsonSafe = readJsonSafe;
@@ -0,0 +1,3 @@
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Disk } from '../../lib/disk';
3
+ export declare function readYamlSafe<T = unknown>(disk: Disk): (filePath: string) => Result<T>;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readYamlSafe = void 0;
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");
7
+ function readYamlSafe(disk) {
8
+ return function readYamlSafe(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}`)));
10
+ };
11
+ }
12
+ exports.readYamlSafe = readYamlSafe;
@@ -0,0 +1,6 @@
1
+ import type { Result } from 'tightrope/result';
2
+ import type { Context } from '../get-context';
3
+ import type { Disk } from '../lib/disk';
4
+ import { PackageJsonFile } from './package-json-file';
5
+ /** Create an API for every package.json file needed. */
6
+ export declare function getPackageJsonFiles(disk: Disk, config: Context['config']): Result<PackageJsonFile[]>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPackageJsonFiles = void 0;
4
+ const flow_1 = require("tightrope/fn/flow");
5
+ const pipe_1 = require("tightrope/fn/pipe");
6
+ const result_1 = require("tightrope/result");
7
+ const and_then_1 = require("tightrope/result/and-then");
8
+ const map_1 = require("tightrope/result/map");
9
+ const or_1 = require("tightrope/result/or");
10
+ const _R_1 = require("../lib/$R");
11
+ const get_file_paths_1 = require("./get-file-paths");
12
+ const read_json_safe_1 = require("./get-patterns/read-json-safe");
13
+ const package_json_file_1 = require("./package-json-file");
14
+ /** Create an API for every package.json file needed. */
15
+ function getPackageJsonFiles(disk, config) {
16
+ return (0, pipe_1.pipe)((0, get_file_paths_1.getFilePaths)(disk, config), (0, and_then_1.andThen)(_R_1.$R.onlyOk((0, flow_1.flow)((0, read_json_safe_1.readJsonSafe)(disk), (0, map_1.map)((jsonFile) => new package_json_file_1.PackageJsonFile(jsonFile, config, disk)), _R_1.$R.tapErrVerbose))), (0, or_1.or)(new result_1.Ok([])));
17
+ }
18
+ exports.getPackageJsonFiles = getPackageJsonFiles;
@@ -1,20 +1,18 @@
1
- import type { PackageJsonFile } from '.';
2
- import type { Syncpack } from '../../../types';
3
- import type { Delete } from '../../get-groups/version-group/instance-group';
1
+ import type { Strategy } from '../config/get-custom-types';
2
+ import type { Delete } from '../get-version-groups/lib/delete';
3
+ import type { PackageJsonFile } from './package-json-file';
4
4
  export declare class Instance {
5
5
  /** the name of this dependency */
6
6
  name: string;
7
7
  /** The package this dependency is installed in this specific time */
8
8
  packageJsonFile: PackageJsonFile;
9
- /** where this dependency is installed */
10
- pathDef: Syncpack.PathDefinition;
9
+ /** locates where in the file this dependency is installed */
10
+ strategy: Strategy.Any;
11
11
  /** The .name property of the package.json file of this instance */
12
12
  pkgName: string;
13
13
  /** the version of this dependency */
14
14
  version: string;
15
- constructor(pathDef: Syncpack.PathDefinition, name: string, packageJsonFile: PackageJsonFile, version: string);
16
- /** Is this instance the package.json file of this package developed in this repo? */
17
- isWorkspace(): boolean;
15
+ constructor(strategy: Strategy.Any, name: string, packageJsonFile: PackageJsonFile, version: string);
18
16
  /**
19
17
  * In the case of banned dependencies, their version is set to `undefined`,
20
18
  * which causes them to be removed by `JSON.stringify`.
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Instance = void 0;
4
+ const pipe_1 = require("tightrope/fn/pipe");
5
+ const _R_1 = require("../lib/$R");
6
+ class Instance {
7
+ constructor(strategy, name, packageJsonFile, version) {
8
+ this.strategy = strategy;
9
+ this.name = name;
10
+ this.packageJsonFile = packageJsonFile;
11
+ this.pkgName = packageJsonFile.contents.name || 'PACKAGE_JSON_HAS_NO_NAME';
12
+ this.version = version;
13
+ }
14
+ /**
15
+ * In the case of banned dependencies, their version is set to `undefined`,
16
+ * which causes them to be removed by `JSON.stringify`.
17
+ */
18
+ setVersion(version) {
19
+ const file = this.packageJsonFile;
20
+ (0, pipe_1.pipe)(this.strategy.write(file, [this.name, version]), _R_1.$R.tapErrVerbose);
21
+ }
22
+ }
23
+ exports.Instance = Instance;
@@ -1,6 +1,7 @@
1
- import type { Disk } from '../../../lib/disk';
2
- import type { Syncpack } from '../../../types';
3
- import type { JsonFile } from '../get-patterns/read-json-safe';
1
+ import type { Strategy } from '../config/get-custom-types';
2
+ import type { Context } from '../get-context';
3
+ import type { Disk } from '../lib/disk';
4
+ import type { JsonFile } from './get-patterns/read-json-safe';
4
5
  import { Instance } from './instance';
5
6
  export interface PackageJson {
6
7
  bugs?: {
@@ -27,7 +28,6 @@ export interface PackageJson {
27
28
  workspaces?: Record<string, string[]> | string[];
28
29
  [otherProps: string]: Record<string, string | string[] | Record<string, string | string[]>> | string | string[] | undefined;
29
30
  }
30
- type Entry = [string, string];
31
31
  export declare class PackageJsonFile {
32
32
  /** parsed JSON contents of the file */
33
33
  contents: PackageJson;
@@ -38,14 +38,12 @@ export declare class PackageJsonFile {
38
38
  /** raw file contents of the file */
39
39
  readonly json: string;
40
40
  /** resolved configuration */
41
- readonly config: Syncpack.Config.Private;
41
+ readonly config: Context['config'];
42
42
  /** relative path on disk to this file */
43
43
  readonly shortPath: string;
44
- constructor(jsonFile: JsonFile<PackageJson>, config: Syncpack.Config.Private, disk: Disk);
44
+ constructor(jsonFile: JsonFile<PackageJson>, config: Context['config'], disk: Disk);
45
45
  hasChanged(): boolean;
46
46
  write(): void;
47
47
  getSource(): string;
48
- getInstances(): Instance[];
49
- getPathEntries(pathDef: Syncpack.PathDefinition, file: PackageJsonFile): Entry[];
48
+ getInstances(enabledTypes: Strategy.Any[]): Instance[];
50
49
  }
51
- export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PackageJsonFile = void 0;
4
+ const path_1 = require("path");
5
+ const pipe_1 = require("tightrope/fn/pipe");
6
+ const map_1 = require("tightrope/result/map");
7
+ const get_indent_1 = require("../config/get-indent");
8
+ const constants_1 = require("../constants");
9
+ const log_1 = require("../lib/log");
10
+ const newlines_1 = require("../lib/newlines");
11
+ const instance_1 = require("./instance");
12
+ class PackageJsonFile {
13
+ constructor(jsonFile, config, disk) {
14
+ this.config = config;
15
+ this.contents = jsonFile.contents;
16
+ this.disk = disk;
17
+ this.filePath = jsonFile.filePath;
18
+ this.json = jsonFile.json;
19
+ this.shortPath = (0, path_1.relative)(constants_1.CWD, jsonFile.filePath);
20
+ }
21
+ hasChanged() {
22
+ return this.json !== this.getSource();
23
+ }
24
+ write() {
25
+ this.disk.writeFileSync(this.filePath, this.getSource());
26
+ }
27
+ getSource() {
28
+ const contents = this.contents;
29
+ const indent = (0, get_indent_1.getIndent)(this.config);
30
+ const EOL = newlines_1.newlines.detect(this.json);
31
+ const source = `${JSON.stringify(contents, null, indent)}${EOL}`;
32
+ return newlines_1.newlines.fix(source, EOL);
33
+ }
34
+ getInstances(enabledTypes) {
35
+ const instances = [];
36
+ enabledTypes.forEach((strategy) => {
37
+ (0, pipe_1.pipe)(strategy.read(this), (0, map_1.map)((entries) => entries.forEach(([name, version]) => {
38
+ (0, log_1.verbose)(`add ${name}@${version} to ${strategy.name}:${strategy._tag} ${this.shortPath}`);
39
+ instances.push(new instance_1.Instance(strategy, name, this, version));
40
+ })));
41
+ });
42
+ return instances;
43
+ }
44
+ }
45
+ exports.PackageJsonFile = PackageJsonFile;
@@ -0,0 +1,4 @@
1
+ import { WithRangeSemverGroup } from './with-range';
2
+ export declare class CatchAllSemverGroup extends WithRangeSemverGroup {
3
+ _tag: string;
4
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CatchAllSemverGroup = void 0;
4
+ const with_range_1 = require("./with-range");
5
+ class CatchAllSemverGroup extends with_range_1.WithRangeSemverGroup {
6
+ constructor() {
7
+ super(...arguments);
8
+ this._tag = 'CatchAll';
9
+ }
10
+ }
11
+ exports.CatchAllSemverGroup = CatchAllSemverGroup;
@@ -0,0 +1,13 @@
1
+ import type { SemverGroupReport } from '.';
2
+ import type { GroupConfig } from '../config/types';
3
+ import type { Context } from '../get-context';
4
+ import type { Instance } from '../get-package-json-files/instance';
5
+ export declare class FilteredOutSemverGroup {
6
+ _tag: string;
7
+ config: GroupConfig;
8
+ filter: string;
9
+ instances: Instance[];
10
+ constructor(ctx: Context);
11
+ canAdd(instance: Instance): boolean;
12
+ inspect(): SemverGroupReport[];
13
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FilteredOutSemverGroup = void 0;
4
+ const get_filter_1 = require("../config/get-filter");
5
+ class FilteredOutSemverGroup {
6
+ constructor(ctx) {
7
+ this._tag = 'FilteredOut';
8
+ this.config = {
9
+ dependencies: ['**'],
10
+ dependencyTypes: [],
11
+ label: 'Filtered out',
12
+ packages: ['**'],
13
+ };
14
+ this.filter = (0, get_filter_1.getFilter)(ctx.config);
15
+ this.instances = [];
16
+ }
17
+ canAdd(instance) {
18
+ return instance.name.search(new RegExp(this.filter)) === -1;
19
+ }
20
+ inspect() {
21
+ return this.instances.map((instance) => ({
22
+ status: 'FILTERED_OUT',
23
+ instance,
24
+ isValid: true,
25
+ name: instance.name,
26
+ }));
27
+ }
28
+ }
29
+ exports.FilteredOutSemverGroup = FilteredOutSemverGroup;
@@ -0,0 +1,11 @@
1
+ import type { SemverGroupReport } from '.';
2
+ import type { SemverGroupConfig } from '../config/types';
3
+ import type { Instance } from '../get-package-json-files/instance';
4
+ export declare class IgnoredSemverGroup {
5
+ _tag: string;
6
+ config: SemverGroupConfig.Ignored;
7
+ instances: Instance[];
8
+ constructor(config: SemverGroupConfig.Ignored);
9
+ canAdd(_: Instance): boolean;
10
+ inspect(): SemverGroupReport[];
11
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IgnoredSemverGroup = void 0;
4
+ class IgnoredSemverGroup {
5
+ constructor(config) {
6
+ this._tag = 'Ignored';
7
+ this.config = config;
8
+ this.instances = [];
9
+ }
10
+ canAdd(_) {
11
+ return true;
12
+ }
13
+ inspect() {
14
+ return this.instances.map((instance) => ({
15
+ status: 'IGNORED',
16
+ instance,
17
+ isValid: true,
18
+ name: instance.name,
19
+ }));
20
+ }
21
+ }
22
+ exports.IgnoredSemverGroup = IgnoredSemverGroup;
@@ -0,0 +1,32 @@
1
+ import type { Context } from '../get-context';
2
+ import type { Instance } from '../get-package-json-files/instance';
3
+ import { CatchAllSemverGroup } from './catch-all';
4
+ import { FilteredOutSemverGroup } from './filtered-out';
5
+ import { IgnoredSemverGroup } from './ignored';
6
+ import { WithRangeSemverGroup } from './with-range';
7
+ export type AnySemverGroup = CatchAllSemverGroup | FilteredOutSemverGroup | IgnoredSemverGroup | WithRangeSemverGroup;
8
+ export type SemverGroupReport = {
9
+ name: string;
10
+ instance: Instance;
11
+ } & ({
12
+ status: 'FILTERED_OUT';
13
+ isValid: true;
14
+ } | {
15
+ status: 'IGNORED';
16
+ isValid: true;
17
+ } | {
18
+ status: 'VALID';
19
+ isValid: true;
20
+ } | {
21
+ status: 'WORKSPACE_SEMVER_RANGE_MISMATCH';
22
+ isValid: false;
23
+ expectedVersion: string;
24
+ } | {
25
+ status: 'SEMVER_RANGE_MISMATCH';
26
+ isValid: false;
27
+ expectedVersion: string;
28
+ } | {
29
+ status: 'UNSUPPORTED_VERSION';
30
+ isValid: false;
31
+ });
32
+ export declare function getSemverGroups(ctx: Context): AnySemverGroup[];