syncpack 9.8.6 → 10.1.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 (191) hide show
  1. package/README.md +22 -19
  2. package/dist/bin-fix-mismatches/fix-mismatches-cli.d.ts +2 -2
  3. package/dist/bin-fix-mismatches/fix-mismatches-cli.js +3 -1
  4. package/dist/bin-fix-mismatches/fix-mismatches.d.ts +2 -2
  5. package/dist/bin-fix-mismatches/fix-mismatches.js +42 -24
  6. package/dist/bin-format/format-cli.d.ts +2 -2
  7. package/dist/bin-format/format-cli.js +2 -1
  8. package/dist/bin-format/format.d.ts +2 -2
  9. package/dist/bin-format/format.js +4 -1
  10. package/dist/bin-lint/index.d.ts +2 -0
  11. package/dist/bin-lint/index.js +39 -0
  12. package/dist/bin-lint/lint-cli.d.ts +3 -0
  13. package/dist/bin-lint/lint-cli.js +11 -0
  14. package/dist/bin-lint/lint.d.ts +2 -0
  15. package/dist/bin-lint/lint.js +116 -0
  16. package/dist/bin-lint-semver-ranges/lint-semver-ranges-cli.d.ts +2 -2
  17. package/dist/bin-lint-semver-ranges/lint-semver-ranges-cli.js +2 -1
  18. package/dist/bin-lint-semver-ranges/lint-semver-ranges.d.ts +2 -2
  19. package/dist/bin-lint-semver-ranges/lint-semver-ranges.js +29 -25
  20. package/dist/bin-list/list-cli.d.ts +2 -2
  21. package/dist/bin-list/list-cli.js +2 -1
  22. package/dist/bin-list/list.d.ts +2 -2
  23. package/dist/bin-list/list.js +58 -54
  24. package/dist/bin-list-mismatches/list-mismatches-cli.d.ts +2 -2
  25. package/dist/bin-list-mismatches/list-mismatches-cli.js +2 -1
  26. package/dist/bin-list-mismatches/list-mismatches.d.ts +2 -2
  27. package/dist/bin-list-mismatches/list-mismatches.js +72 -106
  28. package/dist/bin-set-semver-ranges/set-semver-ranges-cli.d.ts +2 -2
  29. package/dist/bin-set-semver-ranges/set-semver-ranges-cli.js +2 -1
  30. package/dist/bin-set-semver-ranges/set-semver-ranges.d.ts +2 -2
  31. package/dist/bin-set-semver-ranges/set-semver-ranges.js +17 -3
  32. package/dist/bin.js +3 -0
  33. package/dist/config/get-custom-types.d.ts +9 -0
  34. package/dist/config/get-custom-types.js +49 -0
  35. package/dist/config/get-enabled-types.d.ts +3 -0
  36. package/dist/config/get-enabled-types.js +48 -0
  37. package/dist/config/get-filter.d.ts +2 -0
  38. package/dist/config/get-filter.js +13 -0
  39. package/dist/config/get-indent.d.ts +2 -0
  40. package/dist/config/get-indent.js +12 -0
  41. package/dist/config/get-semver-range.d.ts +3 -0
  42. package/dist/config/get-semver-range.js +12 -0
  43. package/dist/config/get-sort-az.d.ts +2 -0
  44. package/dist/config/get-sort-az.js +18 -0
  45. package/dist/config/get-sort-first.d.ts +2 -0
  46. package/dist/config/get-sort-first.js +10 -0
  47. package/dist/config/get-source.d.ts +2 -0
  48. package/dist/config/get-source.js +13 -0
  49. package/dist/config/types.d.ts +106 -0
  50. package/dist/constants.d.ts +1 -0
  51. package/dist/constants.js +1 -0
  52. package/dist/get-context/index.d.ts +8 -16
  53. package/dist/get-context/index.js +7 -33
  54. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-file-paths.d.ts +3 -3
  55. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-file-paths.js +4 -4
  56. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/get-lerna-patterns.d.ts +1 -1
  57. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/get-lerna-patterns.js +1 -1
  58. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/get-pnpm-patterns.d.ts +1 -1
  59. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/get-pnpm-patterns.js +1 -1
  60. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/get-yarn-patterns.d.ts +1 -1
  61. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/get-yarn-patterns.js +1 -1
  62. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/index.d.ts +3 -3
  63. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/index.js +4 -3
  64. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/read-json-safe.d.ts +1 -1
  65. package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/read-yaml-safe.d.ts +1 -1
  66. package/dist/{get-context/get-package-json-files → get-package-json-files}/index.d.ts +3 -3
  67. package/dist/{get-context/get-package-json-files → get-package-json-files}/index.js +1 -1
  68. package/dist/{get-context/get-package-json-files/package-json-file → get-package-json-files}/instance.d.ts +6 -8
  69. package/dist/get-package-json-files/instance.js +23 -0
  70. 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
  71. package/dist/get-package-json-files/package-json-file.js +45 -0
  72. package/dist/get-semver-groups/catch-all.d.ts +4 -0
  73. package/dist/get-semver-groups/catch-all.js +11 -0
  74. package/dist/get-semver-groups/filtered-out.d.ts +13 -0
  75. package/dist/get-semver-groups/filtered-out.js +29 -0
  76. package/dist/get-semver-groups/ignored.d.ts +11 -0
  77. package/dist/get-semver-groups/ignored.js +22 -0
  78. package/dist/get-semver-groups/index.d.ts +32 -0
  79. package/dist/get-semver-groups/index.js +90 -0
  80. package/dist/get-semver-groups/with-range.d.ts +11 -0
  81. package/dist/get-semver-groups/with-range.js +55 -0
  82. package/dist/get-version-groups/banned.d.ts +11 -0
  83. package/dist/get-version-groups/banned.js +24 -0
  84. package/dist/get-version-groups/catch-all.d.ts +4 -0
  85. package/dist/get-version-groups/catch-all.js +11 -0
  86. package/dist/get-version-groups/filtered-out.d.ts +13 -0
  87. package/dist/get-version-groups/filtered-out.js +31 -0
  88. package/dist/get-version-groups/ignored.d.ts +11 -0
  89. package/dist/get-version-groups/ignored.js +24 -0
  90. package/dist/get-version-groups/index.d.ts +57 -0
  91. package/dist/get-version-groups/index.js +119 -0
  92. package/dist/get-version-groups/lib/delete.d.ts +2 -0
  93. package/dist/get-version-groups/lib/delete.js +4 -0
  94. package/dist/get-version-groups/lib/get-highest-version.js +13 -0
  95. package/dist/get-version-groups/lib/get-lowest-version.js +13 -0
  96. package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/get-range-score.js +3 -2
  97. package/dist/get-version-groups/lib/get-unique-versions.d.ts +2 -0
  98. package/dist/get-version-groups/lib/get-unique-versions.js +8 -0
  99. package/dist/get-version-groups/lib/group-by.d.ts +1 -0
  100. package/dist/get-version-groups/lib/group-by.js +11 -0
  101. package/dist/get-version-groups/lib/sort.d.ts +1 -0
  102. package/dist/get-version-groups/lib/sort.js +44 -0
  103. package/dist/get-version-groups/pinned.d.ts +11 -0
  104. package/dist/get-version-groups/pinned.js +43 -0
  105. package/dist/get-version-groups/snapped-to.d.ts +11 -0
  106. package/dist/get-version-groups/snapped-to.js +52 -0
  107. package/dist/get-version-groups/standard.d.ts +11 -0
  108. package/dist/get-version-groups/standard.js +95 -0
  109. package/dist/index.d.ts +2 -0
  110. package/dist/{get-context → lib}/$R.d.ts +2 -2
  111. package/dist/{get-context → lib}/$R.js +3 -4
  112. package/dist/lib/disk.d.ts +3 -2
  113. package/dist/lib/exit-if-invalid.d.ts +2 -2
  114. package/dist/lib/is-semver.d.ts +5 -3
  115. package/dist/lib/is-semver.js +17 -3
  116. package/dist/lib/log.d.ts +4 -8
  117. package/dist/lib/log.js +3 -29
  118. package/dist/lib/set-semver-range.d.ts +2 -2
  119. package/dist/lib/write-if-changed.d.ts +2 -2
  120. package/dist/lib/write-if-changed.js +6 -25
  121. package/dist/{get-context/get-config/path-strategy → strategy}/lib/get-non-empty-string-prop.d.ts +1 -1
  122. package/dist/{get-context/get-config/path-strategy → strategy}/lib/get-non-empty-string-prop.js +1 -2
  123. package/dist/strategy/name-and-version-props.d.ts +12 -0
  124. package/dist/strategy/name-and-version-props.js +50 -0
  125. package/dist/strategy/named-version-string.d.ts +11 -0
  126. package/dist/{get-context/get-config/path-strategy/name-and-version-string.js → strategy/named-version-string.js} +26 -22
  127. package/dist/strategy/unnamed-version-string.d.ts +11 -0
  128. package/dist/strategy/unnamed-version-string.js +48 -0
  129. package/dist/strategy/versions-by-name.d.ts +11 -0
  130. package/dist/strategy/versions-by-name.js +29 -0
  131. package/package.json +8 -4
  132. package/dist/get-context/get-config/get-core-types.d.ts +0 -36
  133. package/dist/get-context/get-config/get-core-types.js +0 -38
  134. package/dist/get-context/get-config/get-custom-types.d.ts +0 -4
  135. package/dist/get-context/get-config/get-custom-types.js +0 -16
  136. package/dist/get-context/get-config/get-enabled-types.d.ts +0 -4
  137. package/dist/get-context/get-config/get-enabled-types.js +0 -17
  138. package/dist/get-context/get-config/index.d.ts +0 -8
  139. package/dist/get-context/get-config/index.js +0 -98
  140. package/dist/get-context/get-config/path-strategy/index.d.ts +0 -8
  141. package/dist/get-context/get-config/path-strategy/index.js +0 -18
  142. package/dist/get-context/get-config/path-strategy/name-and-version-props.d.ts +0 -2
  143. package/dist/get-context/get-config/path-strategy/name-and-version-props.js +0 -44
  144. package/dist/get-context/get-config/path-strategy/name-and-version-string.d.ts +0 -2
  145. package/dist/get-context/get-config/path-strategy/types.d.ts +0 -14
  146. package/dist/get-context/get-config/path-strategy/version-string.d.ts +0 -2
  147. package/dist/get-context/get-config/path-strategy/version-string.js +0 -49
  148. package/dist/get-context/get-config/path-strategy/versions-by-name.d.ts +0 -2
  149. package/dist/get-context/get-config/path-strategy/versions-by-name.js +0 -21
  150. package/dist/get-context/get-config/schema/base-group.d.ts +0 -7
  151. package/dist/get-context/get-config/schema/base-group.js +0 -10
  152. package/dist/get-context/get-config/schema/index.d.ts +0 -1540
  153. package/dist/get-context/get-config/schema/index.js +0 -81
  154. package/dist/get-context/get-config/schema/lib/non-empty-string.d.ts +0 -2
  155. package/dist/get-context/get-config/schema/lib/non-empty-string.js +0 -5
  156. package/dist/get-context/get-config/schema/paths.d.ts +0 -89
  157. package/dist/get-context/get-config/schema/paths.js +0 -33
  158. package/dist/get-context/get-config/schema/semver-group.d.ts +0 -119
  159. package/dist/get-context/get-config/schema/semver-group.js +0 -43
  160. package/dist/get-context/get-config/schema/semver-range.d.ts +0 -2
  161. package/dist/get-context/get-config/schema/semver-range.js +0 -16
  162. package/dist/get-context/get-config/schema/version-group.d.ts +0 -230
  163. package/dist/get-context/get-config/schema/version-group.js +0 -36
  164. package/dist/get-context/get-groups/base-group.d.ts +0 -22
  165. package/dist/get-context/get-groups/base-group.js +0 -39
  166. package/dist/get-context/get-groups/index.d.ts +0 -11
  167. package/dist/get-context/get-groups/index.js +0 -53
  168. package/dist/get-context/get-groups/semver-group.d.ts +0 -15
  169. package/dist/get-context/get-groups/semver-group.js +0 -46
  170. package/dist/get-context/get-groups/version-group/index.d.ts +0 -15
  171. package/dist/get-context/get-groups/version-group/index.js +0 -40
  172. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +0 -42
  173. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.js +0 -44
  174. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +0 -34
  175. package/dist/get-context/get-groups/version-group/instance-group/index.js +0 -103
  176. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +0 -4
  177. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +0 -38
  178. package/dist/get-context/get-package-json-files/package-json-file/index.js +0 -65
  179. package/dist/get-context/get-package-json-files/package-json-file/instance.js +0 -46
  180. package/dist/lib/error.d.ts +0 -12
  181. package/dist/lib/error.js +0 -25
  182. package/dist/types.d.ts +0 -90
  183. /package/dist/{get-context/get-config/path-strategy → config}/types.js +0 -0
  184. /package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/read-json-safe.js +0 -0
  185. /package/dist/{get-context/get-package-json-files → get-package-json-files}/get-patterns/read-yaml-safe.js +0 -0
  186. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/clean.d.ts +0 -0
  187. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/clean.js +0 -0
  188. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups/lib}/get-highest-version.d.ts +0 -0
  189. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups/lib}/get-lowest-version.d.ts +0 -0
  190. /package/dist/{get-context/get-groups/version-group/instance-group → get-version-groups}/lib/get-range-score.d.ts +0 -0
  191. /package/dist/{types.js → index.js} +0 -0
package/README.md CHANGED
@@ -10,28 +10,31 @@ npm install --save-dev syncpack
10
10
 
11
11
  ## Documentation
12
12
 
13
- Full information can be found in the documentation at
14
- https://jamiemason.github.io/syncpack/.
13
+ Full information can be found in the documentation at https://jamiemason.github.io/syncpack/.
15
14
 
16
15
  ## Commands
17
16
 
18
17
  ### [fix-mismatches](https://jamiemason.github.io/syncpack/fix-mismatches)
19
18
 
20
- Ensure that multiple packages requiring the same dependency define the same
21
- version, so that every package requires eg. `react@16.4.2`, instead of a
22
- combination of `react@16.4.2`, `react@0.15.9`, and `react@16.0.0`.
19
+ Ensure that multiple packages requiring the same dependency define the same version, so that every
20
+ package requires eg. `react@16.4.2`, instead of a combination of `react@16.4.2`, `react@0.15.9`, and
21
+ `react@16.0.0`.
23
22
 
24
23
  ### [format](https://jamiemason.github.io/syncpack/format)
25
24
 
26
- Organise package.json files according to a conventional format, where fields
27
- appear in a predictable order and nested fields are ordered alphabetically.
28
- Shorthand properties are used where available, such as the `"repository"` and
29
- `"bugs"` fields.
25
+ Organise package.json files according to a conventional format, where fields appear in a predictable
26
+ order and nested fields are ordered alphabetically. Shorthand properties are used where available,
27
+ such as the `"repository"` and `"bugs"` fields.
28
+
29
+ ### [lint](https://jamiemason.github.io/syncpack/lint)
30
+
31
+ Lint all versions and ranges and exit with 0 or 1 based on whether all files match your Syncpack
32
+ configuration file.
30
33
 
31
34
  ### [lint-semver-ranges](https://jamiemason.github.io/syncpack/lint-semver-ranges)
32
35
 
33
- Check whether dependency versions used within "dependencies", "devDependencies",
34
- etc follow a consistent format.
36
+ Check whether dependency versions used within "dependencies", "devDependencies", etc follow a
37
+ consistent format.
35
38
 
36
39
  ### [list](https://jamiemason.github.io/syncpack/list)
37
40
 
@@ -39,20 +42,20 @@ List all dependencies required by your packages.
39
42
 
40
43
  ### [list-mismatches](https://jamiemason.github.io/syncpack/list-mismatches)
41
44
 
42
- List dependencies which are required by multiple packages, where the version is
43
- not the same across every package.
45
+ List dependencies which are required by multiple packages, where the version is not the same across
46
+ every package.
44
47
 
45
48
  ### [set-semver-ranges](https://jamiemason.github.io/syncpack/set-semver-ranges)
46
49
 
47
- Ensure dependency versions used within `"dependencies"`, `"devDependencies"` etc
48
- follow a consistent format.
50
+ Ensure dependency versions used within `"dependencies"`, `"devDependencies"` etc follow a consistent
51
+ format.
49
52
 
50
53
  ## Breaking Changes
51
54
 
52
- Version [9.0.0](https://github.com/JamieMason/syncpack/releases/tag/9.0.0)
53
- required some breaking API changes to add support for a new
54
- [`customTypes`](https://jamiemason.github.io/syncpack/config/custom-types)
55
- feature, but they are very simple to make.
55
+ Version [9.0.0](https://github.com/JamieMason/syncpack/releases/tag/9.0.0) required some breaking
56
+ API changes to add support for a new
57
+ [`customTypes`](https://jamiemason.github.io/syncpack/config/custom-types) feature, but they are
58
+ very simple to make.
56
59
 
57
60
  ## Badges
58
61
 
@@ -1,3 +1,3 @@
1
+ import type { CliConfig } from '../config/types';
1
2
  import type { Disk } from '../lib/disk';
2
- import type { Syncpack } from '../types';
3
- export declare function fixMismatchesCli(input: Partial<Syncpack.Config.Cli>, disk: Disk): void;
3
+ export declare function fixMismatchesCli(input: Partial<CliConfig>, disk: Disk): void;
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fixMismatchesCli = void 0;
4
+ const pipe_1 = require("tightrope/fn/pipe");
4
5
  const get_context_1 = require("../get-context");
6
+ const exit_if_invalid_1 = require("../lib/exit-if-invalid");
5
7
  const write_if_changed_1 = require("../lib/write-if-changed");
6
8
  const fix_mismatches_1 = require("./fix-mismatches");
7
9
  function fixMismatchesCli(input, disk) {
8
- (0, write_if_changed_1.writeIfChanged)((0, fix_mismatches_1.fixMismatches)((0, get_context_1.getContext)(input, disk)));
10
+ (0, pipe_1.pipe)((0, get_context_1.getContext)(input, disk), fix_mismatches_1.fixMismatches, write_if_changed_1.writeIfChanged, exit_if_invalid_1.exitIfInvalid);
9
11
  }
10
12
  exports.fixMismatchesCli = fixMismatchesCli;
@@ -1,2 +1,2 @@
1
- import type { Syncpack } from '../types';
2
- export declare function fixMismatches(ctx: Syncpack.Ctx): Syncpack.Ctx;
1
+ import type { Context } from '../get-context';
2
+ export declare function fixMismatches(ctx: Context): Context;
@@ -1,37 +1,55 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.fixMismatches = void 0;
4
- const pipe_1 = require("tightrope/fn/pipe");
5
4
  const is_object_1 = require("tightrope/guard/is-object");
6
5
  const is_undefined_1 = require("tightrope/guard/is-undefined");
7
- const tap_1 = require("tightrope/result/tap");
8
- const _R_1 = require("../get-context/$R");
6
+ const get_version_groups_1 = require("../get-version-groups");
7
+ const delete_1 = require("../get-version-groups/lib/delete");
9
8
  function fixMismatches(ctx) {
10
- ctx.versionGroups.forEach((versionGroup) => {
11
- const invalidGroups = versionGroup.getInvalidInstanceGroups();
12
- // Nothing to do if there are no mismatches
13
- if (invalidGroups.length === 0)
14
- return;
15
- // Set the correct version on each instance.
16
- invalidGroups.forEach((instanceGroup) => {
17
- if (!instanceGroup.hasUnsupportedVersion()) {
18
- (0, pipe_1.pipe)(instanceGroup.getExpectedVersion(), (0, tap_1.tap)((nextVersion) => {
19
- instanceGroup.instances.forEach((instance) => instance.setVersion(nextVersion));
20
- }), _R_1.$R.tapErrVerbose);
9
+ const versionGroups = (0, get_version_groups_1.getVersionGroups)(ctx);
10
+ let shouldPruneEmpty = false;
11
+ versionGroups.forEach((versionGroup) => {
12
+ versionGroup.inspect().forEach((outcome) => {
13
+ if (!outcome.isValid) {
14
+ outcome.instances.forEach((instance) => {
15
+ switch (outcome.status) {
16
+ case 'HIGHEST_SEMVER_MISMATCH':
17
+ case 'LOWEST_SEMVER_MISMATCH':
18
+ case 'PINNED_MISMATCH':
19
+ case 'SNAPPED_TO_MISMATCH':
20
+ case 'WORKSPACE_MISMATCH': {
21
+ instance.setVersion(outcome.expectedVersion);
22
+ break;
23
+ }
24
+ case 'BANNED': {
25
+ shouldPruneEmpty = true;
26
+ instance.setVersion(delete_1.DELETE);
27
+ break;
28
+ }
29
+ case 'UNSUPPORTED_MISMATCH': {
30
+ // @TODO Output something when fix-mismatches faces an unsupported mismatch
31
+ ctx.isInvalid = true;
32
+ break;
33
+ }
34
+ // @TODO case 'SEMVER_UNSATISFIED': break;
35
+ // @TODO case 'WORKSPACE_UNSATISFIED': break;
36
+ }
37
+ });
21
38
  }
22
39
  });
23
40
  });
24
- /** Remove eg `{"dependencies": {}, "devDependencies": {}}` */
25
- ctx.packageJsonFiles.forEach((packageJsonFile) => {
26
- const contents = packageJsonFile.contents;
27
- Object.keys(contents).forEach((key) => {
28
- const value = contents[key];
29
- if ((0, is_object_1.isObject)(value) &&
30
- Object.values(value).every(is_undefined_1.isUndefined)) {
31
- delete contents[key];
32
- }
41
+ /** Remove empty objects such as `{"dependencies": {}}` left after deleting */
42
+ if (shouldPruneEmpty) {
43
+ ctx.packageJsonFiles.forEach((packageJsonFile) => {
44
+ const contents = packageJsonFile.contents;
45
+ Object.keys(contents).forEach((key) => {
46
+ const value = contents[key];
47
+ if ((0, is_object_1.isObject)(value) && Object.values(value).every(is_undefined_1.isUndefined)) {
48
+ delete contents[key];
49
+ }
50
+ });
33
51
  });
34
- });
52
+ }
35
53
  return ctx;
36
54
  }
37
55
  exports.fixMismatches = fixMismatches;
@@ -1,3 +1,3 @@
1
+ import type { CliConfig } from '../config/types';
1
2
  import type { Disk } from '../lib/disk';
2
- import type { Syncpack } from '../types';
3
- export declare function formatCli(input: Partial<Syncpack.Config.Cli>, disk: Disk): void;
3
+ export declare function formatCli(input: Partial<CliConfig>, disk: Disk): void;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.formatCli = void 0;
4
+ const pipe_1 = require("tightrope/fn/pipe");
4
5
  const get_context_1 = require("../get-context");
5
6
  const write_if_changed_1 = require("../lib/write-if-changed");
6
7
  const format_1 = require("./format");
7
8
  function formatCli(input, disk) {
8
- (0, write_if_changed_1.writeIfChanged)((0, format_1.format)((0, get_context_1.getContext)(input, disk)));
9
+ (0, pipe_1.pipe)((0, get_context_1.getContext)(input, disk), format_1.format, write_if_changed_1.writeIfChanged);
9
10
  }
10
11
  exports.formatCli = formatCli;
@@ -1,2 +1,2 @@
1
- import type { Syncpack } from '../types';
2
- export declare function format(ctx: Syncpack.Ctx): Syncpack.Ctx;
1
+ import type { Context } from '../get-context';
2
+ export declare function format(ctx: Context): Context;
@@ -4,9 +4,12 @@ exports.format = void 0;
4
4
  const is_array_1 = require("tightrope/guard/is-array");
5
5
  const is_non_empty_string_1 = require("tightrope/guard/is-non-empty-string");
6
6
  const is_object_1 = require("tightrope/guard/is-object");
7
+ const get_sort_az_1 = require("../config/get-sort-az");
8
+ const get_sort_first_1 = require("../config/get-sort-first");
7
9
  function format(ctx) {
8
10
  const { packageJsonFiles } = ctx;
9
- const { sortAz, sortFirst } = ctx.config;
11
+ const sortAz = (0, get_sort_az_1.getSortAz)(ctx.config);
12
+ const sortFirst = (0, get_sort_first_1.getSortFirst)(ctx.config);
10
13
  packageJsonFiles.forEach((packageJsonFile) => {
11
14
  const { contents } = packageJsonFile;
12
15
  const sortedKeys = Object.keys(contents).sort();
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const commander_1 = require("commander");
9
+ const disk_1 = require("../lib/disk");
10
+ const show_help_on_error_1 = require("../lib/show-help-on-error");
11
+ const option_1 = require("../option");
12
+ const lint_cli_1 = require("./lint-cli");
13
+ commander_1.program.description(' lint all versions and ranges');
14
+ commander_1.program.on('--help', () => {
15
+ console.log((0, chalk_1.default) `
16
+ Examples:
17
+ {dim # uses config file for resolving packages}
18
+ syncpack lint
19
+ {dim # uses config file defined by --config when provided}
20
+ syncpack lint --config {yellow ./config/.syncpackrc}
21
+
22
+ Resolving Packages:
23
+ 1. If using Pnpm Workspaces, read {yellow packages} from {yellow pnpm-workspace.yaml} in the root of the project.
24
+ 2. If using Yarn Workspaces, read {yellow workspaces} from {yellow package.json}.
25
+ 3. If using Lerna, read {yellow packages} from {yellow lerna.json}.
26
+ 4. Default to {yellow "package.json"} and {yellow "packages/*/package.json"}.
27
+
28
+ Reference:
29
+ globs {blue.underline https://github.com/isaacs/node-glob#glob-primer}
30
+ lerna.json {blue.underline https://github.com/lerna/lerna#lernajson}
31
+ Yarn Workspaces {blue.underline https://yarnpkg.com/lang/en/docs/workspaces}
32
+ Pnpm Workspaces {blue.underline https://pnpm.js.org/en/workspaces}
33
+ `);
34
+ });
35
+ (0, show_help_on_error_1.showHelpOnError)(commander_1.program);
36
+ commander_1.program.option(...option_1.option.config).parse(process.argv);
37
+ (0, lint_cli_1.lintCli)({
38
+ configPath: commander_1.program.opts().config,
39
+ }, disk_1.disk);
@@ -0,0 +1,3 @@
1
+ import type { CliConfig } from '../config/types';
2
+ import type { Disk } from '../lib/disk';
3
+ export declare function lintCli(input: Partial<CliConfig>, disk: Disk): void;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.lintCli = void 0;
4
+ const pipe_1 = require("tightrope/fn/pipe");
5
+ const get_context_1 = require("../get-context");
6
+ const exit_if_invalid_1 = require("../lib/exit-if-invalid");
7
+ const lint_1 = require("./lint");
8
+ function lintCli(input, disk) {
9
+ (0, pipe_1.pipe)((0, get_context_1.getContext)(input, disk), lint_1.lint, exit_if_invalid_1.exitIfInvalid);
10
+ }
11
+ exports.lintCli = lintCli;
@@ -0,0 +1,2 @@
1
+ import type { Context } from '../get-context';
2
+ export declare function lint(ctx: Context): Context;
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.lint = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const constants_1 = require("../constants");
9
+ const get_semver_groups_1 = require("../get-semver-groups");
10
+ const get_version_groups_1 = require("../get-version-groups");
11
+ function lint(ctx) {
12
+ let totalInstances = 0;
13
+ const instanceCounts = {};
14
+ const versionGroups = (0, get_version_groups_1.getVersionGroups)(ctx);
15
+ const versionCounts = {
16
+ BANNED: 0,
17
+ FILTERED_OUT: 0,
18
+ HIGHEST_SEMVER_MISMATCH: 0,
19
+ IGNORED: 0,
20
+ LOWEST_SEMVER_MISMATCH: 0,
21
+ PINNED_MISMATCH: 0,
22
+ SEMVER_UNSATISFIED: 0,
23
+ SNAPPED_TO_MISMATCH: 0,
24
+ UNSUPPORTED_MISMATCH: 0,
25
+ VALID: 0,
26
+ WORKSPACE_MISMATCH: 0,
27
+ WORKSPACE_UNSATISFIED: 0,
28
+ };
29
+ versionGroups.forEach((group) => {
30
+ group.inspect().forEach((report) => {
31
+ if (!report.isValid)
32
+ ctx.isInvalid = true;
33
+ if (!versionCounts[report.status]) {
34
+ versionCounts[report.status] = 0;
35
+ }
36
+ versionCounts[report.status]++;
37
+ });
38
+ });
39
+ const semverGroups = (0, get_semver_groups_1.getSemverGroups)(ctx);
40
+ const semverCounts = {
41
+ FILTERED_OUT: 0,
42
+ IGNORED: 0,
43
+ VALID: 0,
44
+ WORKSPACE_SEMVER_RANGE_MISMATCH: 0,
45
+ SEMVER_RANGE_MISMATCH: 0,
46
+ UNSUPPORTED_VERSION: 0,
47
+ };
48
+ semverGroups.forEach((group) => {
49
+ group.inspect().forEach((report) => {
50
+ const status = report.status;
51
+ const strategyName = report.instance.strategy.name;
52
+ if (!report.isValid)
53
+ ctx.isInvalid = true;
54
+ if (!semverCounts[status])
55
+ semverCounts[status] = 0;
56
+ semverCounts[status]++;
57
+ if (!instanceCounts[strategyName])
58
+ instanceCounts[strategyName] = 0;
59
+ instanceCounts[strategyName]++;
60
+ totalInstances++;
61
+ });
62
+ });
63
+ const fileCount = ctx.packageJsonFiles.length;
64
+ info(fileCount, `package.json file${fileCount > 1 ? 's' : ''}`);
65
+ info(totalInstances, 'total dependences');
66
+ Object.entries(instanceCounts).forEach(([name, count]) => {
67
+ info(count, `in package.${name
68
+ .replace(/^dev$/, 'devDependencies')
69
+ .replace(/^peer$/, 'peerDependencies')
70
+ .replace(/^pnpmOverrides$/, 'pnpm.overrides')
71
+ .replace(/^prod$/, 'dependencies')
72
+ .replace(/^workspace$/, 'version')}`);
73
+ });
74
+ console.log(chalk_1.default.blue('Version mismatches'));
75
+ expectSome(versionCounts.VALID, 'are valid');
76
+ expectNone(versionCounts.HIGHEST_SEMVER_MISMATCH, 'should have matching versions (prefer highest semver)');
77
+ expectNone(versionCounts.LOWEST_SEMVER_MISMATCH, 'should have matching versions (prefer lowest semver)');
78
+ expectNone(versionCounts.WORKSPACE_MISMATCH, 'should match workspace package version');
79
+ expectNone(versionCounts.BANNED, 'are banned from use');
80
+ expectNone(versionCounts.PINNED_MISMATCH, 'should be pinned to a specific version');
81
+ expectNone(versionCounts.SNAPPED_TO_MISMATCH, 'should snap to version used by another package');
82
+ info(versionCounts.FILTERED_OUT, 'are filtered out');
83
+ info(versionCounts.IGNORED, 'are ignored');
84
+ info(versionCounts.UNSUPPORTED_MISMATCH, 'have unsupported version format');
85
+ console.log(chalk_1.default.blue('Semver range mismatches'));
86
+ expectSome(semverCounts.VALID, 'are valid');
87
+ expectNone(semverCounts.SEMVER_RANGE_MISMATCH, 'should use specific semver range');
88
+ expectNone(semverCounts.WORKSPACE_SEMVER_RANGE_MISMATCH, 'should use exact version in version property of package.json');
89
+ info(semverCounts.FILTERED_OUT, 'are filtered out');
90
+ info(semverCounts.IGNORED, 'are ignored');
91
+ info(semverCounts.UNSUPPORTED_VERSION, 'have unsupported version format');
92
+ return ctx;
93
+ function expectNone(count = 0, ...rest) {
94
+ if (count === 0) {
95
+ console.log(chalk_1.default.dim(constants_1.ICON.skip), pad(count), ...rest);
96
+ }
97
+ else {
98
+ console.log(chalk_1.default.red(constants_1.ICON.cross, pad(count), ...rest));
99
+ }
100
+ }
101
+ function expectSome(count = 0, ...rest) {
102
+ if (count > 0) {
103
+ console.log(chalk_1.default.dim(constants_1.ICON.skip), pad(count), ...rest);
104
+ }
105
+ else {
106
+ console.log(chalk_1.default.red(constants_1.ICON.cross, pad(count), ...rest));
107
+ }
108
+ }
109
+ function info(count = 0, ...rest) {
110
+ console.log(chalk_1.default.dim(constants_1.ICON.skip), pad(count), ...rest);
111
+ }
112
+ function pad(count) {
113
+ return String(count).padStart(String(totalInstances).length, ' ');
114
+ }
115
+ }
116
+ exports.lint = lint;
@@ -1,3 +1,3 @@
1
+ import type { CliConfig } from '../config/types';
1
2
  import type { Disk } from '../lib/disk';
2
- import type { Syncpack } from '../types';
3
- export declare function lintSemverRangesCli(input: Partial<Syncpack.Config.Cli>, disk: Disk): void;
3
+ export declare function lintSemverRangesCli(input: Partial<CliConfig>, disk: Disk): void;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.lintSemverRangesCli = void 0;
4
+ const pipe_1 = require("tightrope/fn/pipe");
4
5
  const get_context_1 = require("../get-context");
5
6
  const exit_if_invalid_1 = require("../lib/exit-if-invalid");
6
7
  const lint_semver_ranges_1 = require("./lint-semver-ranges");
7
8
  function lintSemverRangesCli(input, disk) {
8
- (0, exit_if_invalid_1.exitIfInvalid)((0, lint_semver_ranges_1.lintSemverRanges)((0, get_context_1.getContext)(input, disk)));
9
+ (0, pipe_1.pipe)((0, get_context_1.getContext)(input, disk), lint_semver_ranges_1.lintSemverRanges, exit_if_invalid_1.exitIfInvalid);
9
10
  }
10
11
  exports.lintSemverRangesCli = lintSemverRangesCli;
@@ -1,2 +1,2 @@
1
- import type { Syncpack } from '../types';
2
- export declare function lintSemverRanges(ctx: Syncpack.Ctx): Syncpack.Ctx;
1
+ import type { Context } from '../get-context';
2
+ export declare function lintSemverRanges(ctx: Context): Context;
@@ -28,36 +28,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.lintSemverRanges = void 0;
30
30
  const chalk_1 = __importDefault(require("chalk"));
31
+ const is_non_empty_array_1 = require("tightrope/guard/is-non-empty-array");
31
32
  const constants_1 = require("../constants");
33
+ const get_semver_groups_1 = require("../get-semver-groups");
32
34
  const log = __importStar(require("../lib/log"));
35
+ const sort_by_name_1 = require("../lib/sort-by-name");
33
36
  function lintSemverRanges(ctx) {
34
- const hasUserGroups = ctx.semverGroups.length > 1;
35
- ctx.semverGroups.forEach((semverGroup, i) => {
36
- // Nothing to do if there are no mismatches
37
- if (!semverGroup.hasMismatches())
38
- return;
39
- // Record that this project has mismatches, so that eg. the CLI can exit
40
- // with the correct status code.
41
- ctx.isInvalid = true;
42
- // Annotate each group
43
- hasUserGroups && log.semverGroupHeader(semverGroup, i);
44
- // Log each group which has mismatches
45
- semverGroup.getMismatches().forEach(([name, mismatches]) => {
46
- // Log the dependency name
47
- log.invalid(name);
48
- // Log each of the dependencies mismatches
49
- mismatches.forEach((instance) => {
50
- logSemverRangeMismatch(instance, semverGroup);
51
- });
37
+ const semverGroups = (0, get_semver_groups_1.getSemverGroups)(ctx);
38
+ const hasUserGroups = (0, is_non_empty_array_1.isNonEmptyArray)(ctx.config.rcFile.semverGroups);
39
+ semverGroups.forEach((semverGroup, i) => {
40
+ semverGroup
41
+ .inspect()
42
+ .sort(sort_by_name_1.sortByName)
43
+ .forEach((report, ii) => {
44
+ // Allow eg. CLI to exit with the correct status code.
45
+ if (!report.isValid)
46
+ ctx.isInvalid = true;
47
+ switch (report.status) {
48
+ case 'WORKSPACE_SEMVER_RANGE_MISMATCH':
49
+ case 'SEMVER_RANGE_MISMATCH': {
50
+ // Annotate each group
51
+ if (ii === 0 && hasUserGroups)
52
+ log.semverGroupHeader(semverGroup, i);
53
+ console.log((0, chalk_1.default) `{red %s} %s {red %s} %s {green %s} {dim in %s of %s}`, constants_1.ICON.cross, report.name, report.instance.version, constants_1.ICON.rightArrow, report.expectedVersion, report.instance.strategy.path, report.instance.packageJsonFile.shortPath);
54
+ break;
55
+ }
56
+ case 'IGNORED':
57
+ case 'UNSUPPORTED_VERSION':
58
+ case 'VALID': {
59
+ // no action needed
60
+ break;
61
+ }
62
+ }
52
63
  });
53
64
  });
54
65
  return ctx;
55
66
  }
56
67
  exports.lintSemverRanges = lintSemverRanges;
57
- function logSemverRangeMismatch(instance, semverGroup) {
58
- const path = instance.pathDef.path;
59
- const shortPath = instance.packageJsonFile.shortPath;
60
- const actual = instance.version;
61
- const expected = semverGroup.getExpectedVersion(instance);
62
- console.log((0, chalk_1.default) ` {red ${actual}} ${constants_1.ICON.rightArrow} {green ${expected}} {dim in ${path} of ${shortPath}}`);
63
- }
@@ -1,3 +1,3 @@
1
+ import type { CliConfig } from '../config/types';
1
2
  import type { Disk } from '../lib/disk';
2
- import type { Syncpack } from '../types';
3
- export declare function listCli(input: Partial<Syncpack.Config.Cli>, disk: Disk): void;
3
+ export declare function listCli(input: Partial<CliConfig>, disk: Disk): void;
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.listCli = void 0;
4
+ const pipe_1 = require("tightrope/fn/pipe");
4
5
  const get_context_1 = require("../get-context");
5
6
  const exit_if_invalid_1 = require("../lib/exit-if-invalid");
6
7
  const list_1 = require("./list");
7
8
  function listCli(input, disk) {
8
- (0, exit_if_invalid_1.exitIfInvalid)((0, list_1.list)((0, get_context_1.getContext)(input, disk)));
9
+ (0, pipe_1.pipe)((0, get_context_1.getContext)(input, disk), list_1.list, exit_if_invalid_1.exitIfInvalid);
9
10
  }
10
11
  exports.listCli = listCli;
@@ -1,2 +1,2 @@
1
- import type { Syncpack } from '../types';
2
- export declare function list(ctx: Syncpack.Ctx): Syncpack.Ctx;
1
+ import type { Context } from '../get-context';
2
+ export declare function list(ctx: Context): Context;