syncpack 12.2.0 → 12.3.1
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.
- package/README.md +5 -5
- package/dist/bin-fix-mismatches/fix-mismatches.d.ts +9 -9
- package/dist/bin-fix-mismatches/fix-mismatches.js +43 -54
- package/dist/bin-fix-mismatches/index.js +26 -31
- package/dist/bin-format/format.d.ts +6 -4
- package/dist/bin-format/format.js +78 -53
- package/dist/bin-format/index.js +20 -25
- package/dist/bin-lint/index.js +15 -20
- package/dist/bin-lint/lint.d.ts +4 -4
- package/dist/bin-lint/lint.js +51 -19
- package/dist/bin-lint-semver-ranges/index.js +24 -29
- package/dist/bin-lint-semver-ranges/lint-semver-ranges.d.ts +8 -8
- package/dist/bin-lint-semver-ranges/lint-semver-ranges.js +34 -44
- package/dist/bin-list/index.js +24 -29
- package/dist/bin-list/list.d.ts +7 -7
- package/dist/bin-list/list.js +55 -64
- package/dist/bin-list-mismatches/index.js +24 -29
- package/dist/bin-list-mismatches/list-mismatches.d.ts +10 -10
- package/dist/bin-list-mismatches/list-mismatches.js +62 -70
- package/dist/bin-prompt/index.js +26 -31
- package/dist/bin-prompt/prompt.d.ts +4 -4
- package/dist/bin-prompt/prompt.js +41 -48
- package/dist/bin-set-semver-ranges/index.js +26 -31
- package/dist/bin-set-semver-ranges/set-semver-ranges.d.ts +4 -4
- package/dist/bin-set-semver-ranges/set-semver-ranges.js +26 -30
- package/dist/bin-update/effects.d.ts +18 -18
- package/dist/bin-update/effects.js +77 -106
- package/dist/bin-update/index.js +23 -28
- package/dist/bin-update/update.d.ts +5 -5
- package/dist/bin-update/update.js +37 -45
- package/dist/bin.js +8 -5
- package/dist/config/get-custom-types.d.ts +9 -9
- package/dist/config/get-custom-types.js +22 -27
- package/dist/config/get-enabled-types.d.ts +8 -8
- package/dist/config/get-enabled-types.js +42 -48
- package/dist/config/get-filter.d.ts +1 -1
- package/dist/config/get-filter.js +6 -9
- package/dist/config/get-indent.d.ts +1 -1
- package/dist/config/get-indent.js +6 -9
- package/dist/config/get-sort-az.d.ts +1 -1
- package/dist/config/get-sort-az.js +6 -17
- package/dist/config/get-sort-exports.d.ts +2 -0
- package/dist/config/get-sort-exports.js +8 -0
- package/dist/config/get-sort-first.d.ts +1 -1
- package/dist/config/get-sort-first.js +6 -8
- package/dist/config/get-source.d.ts +1 -1
- package/dist/config/get-source.js +4 -8
- package/dist/config/tag.d.ts +1 -1
- package/dist/config/tag.js +2 -5
- package/dist/config/types.d.ts +16 -5
- package/dist/config/types.js +1 -2
- package/dist/constants.d.ts +7 -0
- package/dist/constants.js +25 -10
- package/dist/error-handlers/default-error-handlers.d.ts +10 -10
- package/dist/error-handlers/default-error-handlers.js +55 -61
- package/dist/get-context/index.d.ts +5 -5
- package/dist/get-context/index.js +13 -17
- package/dist/get-context/lib/key-by.js +1 -5
- package/dist/get-instances/index.d.ts +7 -7
- package/dist/get-instances/index.js +19 -23
- package/dist/get-instances/instance.d.ts +7 -7
- package/dist/get-instances/instance.js +4 -8
- package/dist/get-package-json-files/get-file-paths.d.ts +7 -7
- package/dist/get-package-json-files/get-file-paths.js +10 -15
- package/dist/get-package-json-files/get-patterns/get-lerna-patterns.d.ts +2 -2
- package/dist/get-package-json-files/get-patterns/get-lerna-patterns.js +8 -12
- package/dist/get-package-json-files/get-patterns/get-pnpm-patterns.d.ts +2 -2
- package/dist/get-package-json-files/get-patterns/get-pnpm-patterns.js +8 -12
- package/dist/get-package-json-files/get-patterns/get-yarn-patterns.d.ts +2 -2
- package/dist/get-package-json-files/get-patterns/get-yarn-patterns.js +14 -18
- package/dist/get-package-json-files/get-patterns/index.d.ts +3 -3
- package/dist/get-package-json-files/get-patterns/index.js +11 -15
- package/dist/get-package-json-files/index.d.ts +8 -8
- package/dist/get-package-json-files/index.js +6 -10
- package/dist/get-package-json-files/package-json-file.d.ts +6 -6
- package/dist/get-package-json-files/package-json-file.js +8 -12
- package/dist/guards/can-add-to-group.d.ts +4 -4
- package/dist/guards/can-add-to-group.js +10 -14
- package/dist/guards/is-semver.js +3 -7
- package/dist/guards/is-valid-semver-range.d.ts +1 -1
- package/dist/guards/is-valid-semver-range.js +12 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -2
- package/dist/io/ask-for-choice.d.ts +5 -5
- package/dist/io/ask-for-choice.js +5 -9
- package/dist/io/ask-for-input.d.ts +5 -5
- package/dist/io/ask-for-input.js +5 -9
- package/dist/io/exit-if-invalid.d.ts +3 -3
- package/dist/io/exit-if-invalid.js +5 -9
- package/dist/io/glob-sync.d.ts +5 -5
- package/dist/io/glob-sync.js +4 -9
- package/dist/io/index.d.ts +8 -8
- package/dist/io/index.js +12 -38
- package/dist/io/read-config-file.d.ts +7 -0
- package/dist/io/read-config-file.js +22 -0
- package/dist/io/read-file-sync.d.ts +5 -5
- package/dist/io/read-file-sync.js +4 -9
- package/dist/io/read-json-file-sync.d.ts +8 -8
- package/dist/io/read-json-file-sync.js +10 -16
- package/dist/io/read-yaml-file-sync.d.ts +5 -5
- package/dist/io/read-yaml-file-sync.js +4 -8
- package/dist/io/to-json.d.ts +9 -0
- package/dist/io/to-json.js +29 -0
- package/dist/io/write-file-sync.d.ts +5 -5
- package/dist/io/write-file-sync.js +5 -10
- package/dist/io/write-if-changed.d.ts +4 -10
- package/dist/io/write-if-changed.js +9 -44
- package/dist/lib/format-repository-url.js +1 -5
- package/dist/lib/get-group-header.d.ts +2 -2
- package/dist/lib/get-group-header.js +4 -12
- package/dist/lib/get.d.ts +10 -10
- package/dist/lib/get.js +15 -19
- package/dist/lib/pad-start.js +1 -5
- package/dist/lib/ring-buffer.js +1 -5
- package/dist/lib/set-semver-range.d.ts +1 -1
- package/dist/lib/set-semver-range.js +8 -12
- package/dist/lib/show-help-on-error.js +3 -10
- package/dist/lib/sort-by-name.js +1 -5
- package/dist/lib/with-logger.d.ts +1 -1
- package/dist/lib/with-logger.js +17 -24
- package/dist/option.d.ts +1 -1
- package/dist/option.js +8 -14
- package/dist/report.d.ts +2 -2
- package/dist/report.js +2 -5
- package/dist/schema.json +24 -0
- package/dist/semver-group/create-semver-groups.d.ts +3 -3
- package/dist/semver-group/create-semver-groups.js +28 -32
- package/dist/semver-group/disabled.d.ts +11 -11
- package/dist/semver-group/disabled.js +6 -10
- package/dist/semver-group/filtered-out.d.ts +12 -12
- package/dist/semver-group/filtered-out.js +8 -12
- package/dist/semver-group/ignored.d.ts +11 -11
- package/dist/semver-group/ignored.js +6 -10
- package/dist/semver-group/index.d.ts +6 -7
- package/dist/semver-group/index.js +4 -7
- package/dist/semver-group/with-range.d.ts +11 -11
- package/dist/semver-group/with-range.js +13 -17
- package/dist/specifier/alias.d.ts +5 -5
- package/dist/specifier/alias.js +9 -13
- package/dist/specifier/base.d.ts +7 -7
- package/dist/specifier/base.js +9 -13
- package/dist/specifier/delete.d.ts +5 -5
- package/dist/specifier/delete.js +5 -9
- package/dist/specifier/exact.d.ts +6 -6
- package/dist/specifier/exact.js +7 -11
- package/dist/specifier/file.d.ts +1 -1
- package/dist/specifier/file.js +2 -6
- package/dist/specifier/hosted-git.d.ts +5 -5
- package/dist/specifier/hosted-git.js +9 -13
- package/dist/specifier/index.d.ts +13 -13
- package/dist/specifier/index.js +28 -31
- package/dist/specifier/latest.d.ts +6 -6
- package/dist/specifier/latest.js +7 -11
- package/dist/specifier/lib/non-semver-error.d.ts +5 -5
- package/dist/specifier/lib/non-semver-error.js +3 -7
- package/dist/specifier/lib/parse-specifier.d.ts +1 -1
- package/dist/specifier/lib/parse-specifier.js +4 -11
- package/dist/specifier/lib/specific-registry-result.js +1 -2
- package/dist/specifier/range.d.ts +6 -6
- package/dist/specifier/range.js +7 -11
- package/dist/specifier/tag.d.ts +2 -2
- package/dist/specifier/tag.js +2 -6
- package/dist/specifier/unsupported.d.ts +1 -1
- package/dist/specifier/unsupported.js +2 -6
- package/dist/specifier/url.d.ts +1 -1
- package/dist/specifier/url.js +2 -6
- package/dist/specifier/workspace-protocol.d.ts +7 -7
- package/dist/specifier/workspace-protocol.js +9 -13
- package/dist/strategy/lib/get-non-empty-string-prop.d.ts +2 -2
- package/dist/strategy/lib/get-non-empty-string-prop.js +6 -10
- package/dist/strategy/name-and-version-props.d.ts +4 -4
- package/dist/strategy/name-and-version-props.js +19 -23
- package/dist/strategy/named-version-string.d.ts +4 -4
- package/dist/strategy/named-version-string.js +20 -24
- package/dist/strategy/unnamed-version-string.d.ts +4 -4
- package/dist/strategy/unnamed-version-string.js +17 -21
- package/dist/strategy/versions-by-name.d.ts +4 -4
- package/dist/strategy/versions-by-name.js +11 -15
- package/dist/version-group/banned.d.ts +7 -7
- package/dist/version-group/banned.js +8 -12
- package/dist/version-group/create-version-groups.d.ts +3 -3
- package/dist/version-group/create-version-groups.js +34 -38
- package/dist/version-group/filtered-out.d.ts +8 -8
- package/dist/version-group/filtered-out.js +8 -12
- package/dist/version-group/ignored.d.ts +7 -7
- package/dist/version-group/ignored.js +6 -10
- package/dist/version-group/index.d.ts +9 -10
- package/dist/version-group/index.js +4 -7
- package/dist/version-group/lib/clean.js +4 -11
- package/dist/version-group/lib/delete.js +1 -4
- package/dist/version-group/lib/get-highest-version.d.ts +2 -2
- package/dist/version-group/lib/get-highest-version.js +3 -7
- package/dist/version-group/lib/get-lowest-version.d.ts +2 -2
- package/dist/version-group/lib/get-lowest-version.js +3 -7
- package/dist/version-group/lib/get-preferred-version.d.ts +4 -4
- package/dist/version-group/lib/get-preferred-version.js +17 -24
- package/dist/version-group/lib/get-range-score.js +13 -17
- package/dist/version-group/lib/group-by.js +1 -5
- package/dist/version-group/pinned.d.ts +7 -7
- package/dist/version-group/pinned.js +8 -12
- package/dist/version-group/same-range.d.ts +8 -8
- package/dist/version-group/same-range.js +23 -30
- package/dist/version-group/snapped-to.d.ts +7 -7
- package/dist/version-group/snapped-to.js +20 -24
- package/dist/version-group/standard.d.ts +7 -7
- package/dist/version-group/standard.js +29 -33
- package/package.json +30 -37
- package/dist/io/read-config-file-sync.d.ts +0 -7
- package/dist/io/read-config-file-sync.js +0 -26
package/README.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# syncpack
|
|
2
2
|
|
|
3
|
-
<center>
|
|
4
|
-
<img src="https://jamiemason.github.io/syncpack/logo.svg" width="200" height="179" alt=""
|
|
5
|
-
<
|
|
6
|
-
<
|
|
7
|
-
</
|
|
3
|
+
<p align="center">
|
|
4
|
+
<img src="https://jamiemason.github.io/syncpack/logo.svg" width="200" height="179" alt="">
|
|
5
|
+
<br>Consistent dependency versions in large JavaScript Monorepos.
|
|
6
|
+
<br><a href="https://jamiemason.github.io/syncpack">https://jamiemason.github.io/syncpack</a>
|
|
7
|
+
</p>
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { type CliConfig } from '../config/types';
|
|
3
|
-
import type { ErrorHandlers } from '../error-handlers/default-error-handlers';
|
|
4
|
-
import type { Io } from '../io';
|
|
5
|
-
import type { Report } from '../report';
|
|
2
|
+
import { type CliConfig } from '../config/types.js';
|
|
3
|
+
import type { ErrorHandlers } from '../error-handlers/default-error-handlers.js';
|
|
4
|
+
import type { Io } from '../io/index.js';
|
|
5
|
+
import type { Report } from '../report.js';
|
|
6
6
|
interface Input {
|
|
7
7
|
io: Io;
|
|
8
8
|
cli: Partial<CliConfig>;
|
|
9
9
|
errorHandlers?: ErrorHandlers;
|
|
10
10
|
}
|
|
11
|
-
export declare function fixMismatches({ io, cli, errorHandlers }: Input): Effect.Effect<
|
|
12
|
-
export declare function fixMismatch(report: Report.Version.Fixable.Any): Effect.Effect<
|
|
13
|
-
export declare function logAlreadyValidSize(amount: number): Effect.Effect<
|
|
14
|
-
export declare function logFixedSize(amount: number): Effect.Effect<
|
|
15
|
-
export declare function logUnfixableSize(amount: number): Effect.Effect<
|
|
11
|
+
export declare function fixMismatches({ io, cli, errorHandlers }: Input): Effect.Effect<unknown, never, never>;
|
|
12
|
+
export declare function fixMismatch(report: Report.Version.Fixable.Any): Effect.Effect<import("../get-package-json-files/package-json-file.js").PackageJsonFile, never, never>;
|
|
13
|
+
export declare function logAlreadyValidSize(amount: number): Effect.Effect<void, never, never>;
|
|
14
|
+
export declare function logFixedSize(amount: number): Effect.Effect<void, never, never>;
|
|
15
|
+
export declare function logUnfixableSize(amount: number): Effect.Effect<void, never, never>;
|
|
16
16
|
export {};
|
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
const pad_start_1 = require("../lib/pad-start");
|
|
23
|
-
const with_logger_1 = require("../lib/with-logger");
|
|
24
|
-
const delete_1 = require("../version-group/lib/delete");
|
|
25
|
-
function fixMismatches({ io, cli, errorHandlers = default_error_handlers_1.defaultErrorHandlers }) {
|
|
26
|
-
return (0, effect_1.pipe)((0, get_context_1.getContext)({ io, cli, errorHandlers }), effect_1.Effect.flatMap((ctx) => (0, effect_1.pipe)(effect_1.Effect.gen(function* ($) {
|
|
27
|
-
const { versionGroups } = yield* $((0, get_instances_1.getInstances)(ctx, io, errorHandlers));
|
|
1
|
+
import chalk from 'chalk-template';
|
|
2
|
+
import { Context, Effect, flow, pipe } from 'effect';
|
|
3
|
+
import { isObject } from 'tightrope/guard/is-object.js';
|
|
4
|
+
import { isUndefined } from 'tightrope/guard/is-undefined.js';
|
|
5
|
+
import { logIgnoredSize } from '../bin-lint-semver-ranges/lint-semver-ranges.js';
|
|
6
|
+
import { logMissingLocalVersion, logMissingSnappedToMismatch, logSameRangeMismatch, logUnsupportedMismatch, } from '../bin-list-mismatches/list-mismatches.js';
|
|
7
|
+
import { CliConfigTag } from '../config/tag.js';
|
|
8
|
+
import { ICON } from '../constants.js';
|
|
9
|
+
import { defaultErrorHandlers } from '../error-handlers/default-error-handlers.js';
|
|
10
|
+
import { getContext } from '../get-context/index.js';
|
|
11
|
+
import { getInstances } from '../get-instances/index.js';
|
|
12
|
+
import { exitIfInvalid } from '../io/exit-if-invalid.js';
|
|
13
|
+
import { IoTag } from '../io/index.js';
|
|
14
|
+
import { writeIfChanged } from '../io/write-if-changed.js';
|
|
15
|
+
import { getVersionGroupHeader } from '../lib/get-group-header.js';
|
|
16
|
+
import { padStart } from '../lib/pad-start.js';
|
|
17
|
+
import { withLogger } from '../lib/with-logger.js';
|
|
18
|
+
import { DELETE } from '../version-group/lib/delete.js';
|
|
19
|
+
export function fixMismatches({ io, cli, errorHandlers = defaultErrorHandlers }) {
|
|
20
|
+
return pipe(getContext({ io, cli, errorHandlers }), Effect.flatMap((ctx) => pipe(Effect.gen(function* ($) {
|
|
21
|
+
const { versionGroups } = yield* $(getInstances(ctx, io, errorHandlers));
|
|
28
22
|
let index = 0;
|
|
29
23
|
for (const group of versionGroups) {
|
|
30
24
|
const groupSize = group.instances.length;
|
|
@@ -35,9 +29,9 @@ function fixMismatches({ io, cli, errorHandlers = default_error_handlers_1.defau
|
|
|
35
29
|
index++;
|
|
36
30
|
continue;
|
|
37
31
|
}
|
|
38
|
-
yield* $(
|
|
32
|
+
yield* $(Effect.logInfo(getVersionGroupHeader({ group, index })));
|
|
39
33
|
if (group._tag === 'Ignored') {
|
|
40
|
-
yield* $(
|
|
34
|
+
yield* $(logIgnoredSize(groupSize));
|
|
41
35
|
index++;
|
|
42
36
|
continue;
|
|
43
37
|
}
|
|
@@ -55,16 +49,16 @@ function fixMismatches({ io, cli, errorHandlers = default_error_handlers_1.defau
|
|
|
55
49
|
unfixableCount++;
|
|
56
50
|
}
|
|
57
51
|
if (report._tag === 'MissingLocalVersion') {
|
|
58
|
-
yield* $(
|
|
52
|
+
yield* $(logMissingLocalVersion(report));
|
|
59
53
|
}
|
|
60
54
|
else if (report._tag === 'MissingSnappedToMismatch') {
|
|
61
|
-
yield* $(
|
|
55
|
+
yield* $(logMissingSnappedToMismatch(report));
|
|
62
56
|
}
|
|
63
57
|
else if (report._tag === 'UnsupportedMismatch') {
|
|
64
|
-
yield* $(
|
|
58
|
+
yield* $(logUnsupportedMismatch(report));
|
|
65
59
|
}
|
|
66
60
|
else if (report._tag === 'SameRangeMismatch') {
|
|
67
|
-
yield* $(
|
|
61
|
+
yield* $(logSameRangeMismatch(report));
|
|
68
62
|
}
|
|
69
63
|
}
|
|
70
64
|
}
|
|
@@ -78,44 +72,39 @@ function fixMismatches({ io, cli, errorHandlers = default_error_handlers_1.defau
|
|
|
78
72
|
}
|
|
79
73
|
yield* $(removeEmptyObjects(ctx));
|
|
80
74
|
return ctx;
|
|
81
|
-
}),
|
|
82
|
-
WriteFileError:
|
|
75
|
+
}), Effect.flatMap(writeIfChanged), Effect.catchTags({
|
|
76
|
+
WriteFileError: flow(errorHandlers.WriteFileError, Effect.map(() => {
|
|
83
77
|
ctx.isInvalid = true;
|
|
84
78
|
return ctx;
|
|
85
79
|
})),
|
|
86
|
-
}),
|
|
80
|
+
}), Effect.flatMap(exitIfInvalid))), Effect.provide(pipe(Context.empty(), Context.add(CliConfigTag, cli), Context.add(IoTag, io))), withLogger);
|
|
87
81
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return report.fixable.instance.write(report._tag === 'Banned' ? delete_1.DELETE : report.fixable.raw);
|
|
82
|
+
export function fixMismatch(report) {
|
|
83
|
+
return report.fixable.instance.write(report._tag === 'Banned' ? DELETE : report.fixable.raw);
|
|
91
84
|
}
|
|
92
|
-
exports.fixMismatch = fixMismatch;
|
|
93
85
|
/** Remove empty objects such as `{"dependencies": {}}` left after deleting */
|
|
94
86
|
function removeEmptyObjects(ctx) {
|
|
95
|
-
return
|
|
87
|
+
return Effect.sync(() => {
|
|
96
88
|
ctx.packageJsonFiles.forEach((file) => {
|
|
97
89
|
const contents = file.jsonFile.contents;
|
|
98
90
|
Object.keys(contents).forEach((key) => {
|
|
99
91
|
const value = contents[key];
|
|
100
|
-
if (
|
|
92
|
+
if (isObject(value) && value && Object.values(value).every(isUndefined)) {
|
|
101
93
|
delete contents[key];
|
|
102
94
|
}
|
|
103
95
|
});
|
|
104
96
|
});
|
|
105
97
|
});
|
|
106
98
|
}
|
|
107
|
-
function logAlreadyValidSize(amount) {
|
|
108
|
-
const msg =
|
|
109
|
-
return
|
|
99
|
+
export function logAlreadyValidSize(amount) {
|
|
100
|
+
const msg = chalk `${padStart(amount)} {green ${ICON.tick}} already valid`;
|
|
101
|
+
return Effect.logInfo(msg);
|
|
110
102
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return effect_1.Effect.logInfo(msg);
|
|
103
|
+
export function logFixedSize(amount) {
|
|
104
|
+
const msg = chalk `${padStart(amount)} {green ${ICON.tick}} fixed`;
|
|
105
|
+
return Effect.logInfo(msg);
|
|
115
106
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return effect_1.Effect.logInfo(msg);
|
|
107
|
+
export function logUnfixableSize(amount) {
|
|
108
|
+
const msg = chalk `{red ${padStart(amount)} ${ICON.panic} can be fixed manually using} {blue syncpack prompt}`;
|
|
109
|
+
return Effect.logInfo(msg);
|
|
120
110
|
}
|
|
121
|
-
exports.logUnfixableSize = logUnfixableSize;
|
|
@@ -1,22 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const io_1 = require("../io");
|
|
11
|
-
const show_help_on_error_1 = require("../lib/show-help-on-error");
|
|
12
|
-
const option_1 = require("../option");
|
|
13
|
-
const fix_mismatches_1 = require("./fix-mismatches");
|
|
14
|
-
commander_1.program.description((0, chalk_1.default) `
|
|
2
|
+
import chalk from 'chalk-template';
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import { Effect } from 'effect';
|
|
5
|
+
import { io } from '../io/index.js';
|
|
6
|
+
import { showHelpOnError } from '../lib/show-help-on-error.js';
|
|
7
|
+
import { option } from '../option.js';
|
|
8
|
+
import { fixMismatches } from './fix-mismatches.js';
|
|
9
|
+
program.description(chalk `
|
|
15
10
|
Ensure that multiple packages requiring the same dependency define the same
|
|
16
11
|
version, so that every package requires eg. {yellow react@16.4.2}, instead of a
|
|
17
12
|
combination of {yellow react@16.4.2}, {yellow react@0.15.9}, and {yellow react@16.0.0}.`.replace(/^\n/, ''));
|
|
18
|
-
|
|
19
|
-
console.log(
|
|
13
|
+
program.on('--help', () => {
|
|
14
|
+
console.log(chalk `
|
|
20
15
|
Resolving Packages:
|
|
21
16
|
1. If {yellow --source} globs are provided, use those.
|
|
22
17
|
2. If using Pnpm Workspaces, read {yellow packages} from {yellow pnpm-workspace.yaml} in the root of the project.
|
|
@@ -47,23 +42,23 @@ Reference:
|
|
|
47
42
|
Pnpm Workspaces {blue.underline https://pnpm.js.org/en/workspaces}
|
|
48
43
|
`);
|
|
49
44
|
});
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
.option(...
|
|
53
|
-
.option(...
|
|
54
|
-
.option(...
|
|
55
|
-
.option(...
|
|
56
|
-
.option(...
|
|
57
|
-
.option(...
|
|
45
|
+
showHelpOnError(program);
|
|
46
|
+
program
|
|
47
|
+
.option(...option.source)
|
|
48
|
+
.option(...option.filter)
|
|
49
|
+
.option(...option.specs)
|
|
50
|
+
.option(...option.types)
|
|
51
|
+
.option(...option.config)
|
|
52
|
+
.option(...option.indent)
|
|
58
53
|
.parse(process.argv);
|
|
59
|
-
|
|
60
|
-
io
|
|
54
|
+
Effect.runPromise(fixMismatches({
|
|
55
|
+
io,
|
|
61
56
|
cli: {
|
|
62
|
-
configPath:
|
|
63
|
-
filter:
|
|
64
|
-
indent:
|
|
65
|
-
source:
|
|
66
|
-
specs:
|
|
67
|
-
types:
|
|
57
|
+
configPath: program.opts().config,
|
|
58
|
+
filter: program.opts().filter,
|
|
59
|
+
indent: program.opts().indent,
|
|
60
|
+
source: program.opts().source,
|
|
61
|
+
specs: program.opts().specs,
|
|
62
|
+
types: program.opts().types,
|
|
68
63
|
},
|
|
69
64
|
}));
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { type CliConfig } from '../config/types';
|
|
3
|
-
import type { ErrorHandlers } from '../error-handlers/default-error-handlers';
|
|
4
|
-
import type {
|
|
2
|
+
import { type CliConfig } from '../config/types.js';
|
|
3
|
+
import type { ErrorHandlers } from '../error-handlers/default-error-handlers.js';
|
|
4
|
+
import type { Ctx } from '../get-context/index.js';
|
|
5
|
+
import type { Io } from '../io/index.js';
|
|
5
6
|
interface Input {
|
|
6
7
|
io: Io;
|
|
7
8
|
cli: Partial<CliConfig>;
|
|
8
9
|
errorHandlers?: ErrorHandlers;
|
|
9
10
|
}
|
|
10
|
-
export declare function format({ io, cli, errorHandlers }: Input): Effect.Effect<
|
|
11
|
+
export declare function format({ io, cli, errorHandlers }: Input): Effect.Effect<unknown, never, never>;
|
|
12
|
+
export declare function pipeline(ctx: Ctx): Effect.Effect<Ctx>;
|
|
11
13
|
export {};
|
|
@@ -1,64 +1,89 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
import { Context, Effect, flow, pipe } from 'effect';
|
|
2
|
+
import { isArray } from 'tightrope/guard/is-array.js';
|
|
3
|
+
import { isNonEmptyString } from 'tightrope/guard/is-non-empty-string.js';
|
|
4
|
+
import { isObject } from 'tightrope/guard/is-object.js';
|
|
5
|
+
import { getSortAz } from '../config/get-sort-az.js';
|
|
6
|
+
import { getSortExports } from '../config/get-sort-exports.js';
|
|
7
|
+
import { getSortFirst } from '../config/get-sort-first.js';
|
|
8
|
+
import { CliConfigTag } from '../config/tag.js';
|
|
9
|
+
import { defaultErrorHandlers } from '../error-handlers/default-error-handlers.js';
|
|
10
|
+
import { getContext } from '../get-context/index.js';
|
|
11
|
+
import { exitIfInvalid } from '../io/exit-if-invalid.js';
|
|
12
|
+
import { IoTag } from '../io/index.js';
|
|
13
|
+
import { writeIfChanged } from '../io/write-if-changed.js';
|
|
14
|
+
import { withLogger } from '../lib/with-logger.js';
|
|
15
|
+
export function format({ io, cli, errorHandlers = defaultErrorHandlers }) {
|
|
16
|
+
return pipe(getContext({ io, cli, errorHandlers }), Effect.flatMap(pipeline), Effect.flatMap((ctx) => pipe(writeIfChanged(ctx), Effect.catchTags({
|
|
17
|
+
WriteFileError: flow(errorHandlers.WriteFileError, Effect.map(() => {
|
|
18
|
+
ctx.isInvalid = true;
|
|
19
|
+
return ctx;
|
|
20
|
+
})),
|
|
21
|
+
}))), Effect.flatMap(exitIfInvalid), Effect.provide(pipe(Context.empty(), Context.add(CliConfigTag, cli), Context.add(IoTag, io))), withLogger);
|
|
22
|
+
}
|
|
23
|
+
export function pipeline(ctx) {
|
|
24
|
+
const { config, packageJsonFiles } = ctx;
|
|
25
|
+
const sortAz = getSortAz(config);
|
|
26
|
+
const sortExports = getSortExports(config);
|
|
27
|
+
const sortFirst = getSortFirst(config);
|
|
28
|
+
const sortPackages = config.rcFile.sortPackages !== false;
|
|
29
|
+
const formatBugs = config.rcFile.formatBugs !== false;
|
|
30
|
+
const formatRepository = config.rcFile.formatRepository !== false;
|
|
31
|
+
packageJsonFiles.forEach((file) => {
|
|
32
|
+
const { contents } = file.jsonFile;
|
|
33
|
+
const chain = contents;
|
|
34
|
+
if (formatBugs) {
|
|
35
|
+
const bugsUrl = chain?.bugs?.url;
|
|
30
36
|
if (bugsUrl) {
|
|
31
37
|
contents.bugs = bugsUrl;
|
|
32
38
|
}
|
|
33
|
-
|
|
39
|
+
}
|
|
40
|
+
if (formatRepository) {
|
|
41
|
+
const repoUrl = chain?.repository?.url;
|
|
42
|
+
const repoDir = chain?.repository?.directory;
|
|
43
|
+
if (isNonEmptyString(repoUrl) && !isNonEmptyString(repoDir)) {
|
|
34
44
|
contents.repository = repoUrl.includes('github.com')
|
|
35
45
|
? repoUrl.replace(/^.+github\.com\//, '')
|
|
36
46
|
: repoUrl;
|
|
37
47
|
}
|
|
48
|
+
}
|
|
49
|
+
if (sortExports.length > 0) {
|
|
50
|
+
visitExports(sortExports, contents.exports);
|
|
51
|
+
}
|
|
52
|
+
if (sortAz.length > 0) {
|
|
38
53
|
sortAz.forEach((key) => sortAlphabetically(contents[key]));
|
|
39
|
-
sortObject(keys, contents);
|
|
40
|
-
});
|
|
41
|
-
return ctx;
|
|
42
|
-
function sortObject(sortedKeys, obj) {
|
|
43
|
-
sortedKeys.forEach((key) => {
|
|
44
|
-
const value = obj[key];
|
|
45
|
-
delete obj[key];
|
|
46
|
-
obj[key] = value;
|
|
47
|
-
});
|
|
48
54
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
else if ((0, is_object_1.isObject)(value)) {
|
|
54
|
-
sortObject(Object.keys(value).sort(), value);
|
|
55
|
-
}
|
|
55
|
+
if (sortPackages) {
|
|
56
|
+
const sortedKeys = Object.keys(contents).sort();
|
|
57
|
+
sortObject(sortedKeys, contents);
|
|
56
58
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
})
|
|
59
|
+
if (sortFirst.length > 0) {
|
|
60
|
+
const otherKeys = Object.keys(contents);
|
|
61
|
+
const sortedKeys = new Set([...sortFirst, ...otherKeys]);
|
|
62
|
+
sortObject(sortedKeys, contents);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return Effect.succeed(ctx);
|
|
66
|
+
}
|
|
67
|
+
function visitExports(sortExports, value) {
|
|
68
|
+
if (isObject(value)) {
|
|
69
|
+
const otherKeys = Object.keys(value);
|
|
70
|
+
const sortedKeys = new Set([...sortExports, ...otherKeys]);
|
|
71
|
+
sortObject(sortedKeys, value);
|
|
72
|
+
Object.values(value).forEach((nextValue) => visitExports(sortExports, nextValue));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function sortObject(sortedKeys, obj) {
|
|
76
|
+
sortedKeys.forEach((key) => {
|
|
77
|
+
const value = obj[key];
|
|
78
|
+
delete obj[key];
|
|
79
|
+
obj[key] = value;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
function sortAlphabetically(value) {
|
|
83
|
+
if (isArray(value)) {
|
|
84
|
+
value.sort();
|
|
85
|
+
}
|
|
86
|
+
else if (isObject(value)) {
|
|
87
|
+
sortObject(Object.keys(value).sort(), value);
|
|
88
|
+
}
|
|
63
89
|
}
|
|
64
|
-
exports.format = format;
|
package/dist/bin-format/index.js
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const io_1 = require("../io");
|
|
11
|
-
const show_help_on_error_1 = require("../lib/show-help-on-error");
|
|
12
|
-
const option_1 = require("../option");
|
|
13
|
-
const format_1 = require("./format");
|
|
14
|
-
commander_1.program.description((0, chalk_1.default) `
|
|
2
|
+
import chalk from 'chalk-template';
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import { Effect } from 'effect';
|
|
5
|
+
import { io } from '../io/index.js';
|
|
6
|
+
import { showHelpOnError } from '../lib/show-help-on-error.js';
|
|
7
|
+
import { option } from '../option.js';
|
|
8
|
+
import { format } from './format.js';
|
|
9
|
+
program.description(chalk `
|
|
15
10
|
Organise package.json files according to a conventional format, where fields
|
|
16
11
|
appear in a predictable order and nested fields are ordered alphabetically.
|
|
17
12
|
Shorthand properties are used where available, such as the {yellow repository} and
|
|
18
13
|
{yellow bugs} fields.`.replace(/^\n/, ''));
|
|
19
|
-
|
|
20
|
-
console.log(
|
|
14
|
+
program.on('--help', () => {
|
|
15
|
+
console.log(chalk `
|
|
21
16
|
Examples:
|
|
22
17
|
{dim # uses defaults for resolving packages}
|
|
23
18
|
syncpack format
|
|
@@ -42,17 +37,17 @@ Reference:
|
|
|
42
37
|
Pnpm Workspaces {blue.underline https://pnpm.js.org/en/workspaces}
|
|
43
38
|
`);
|
|
44
39
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.option(...
|
|
48
|
-
.option(...
|
|
49
|
-
.option(...
|
|
40
|
+
showHelpOnError(program);
|
|
41
|
+
program
|
|
42
|
+
.option(...option.source)
|
|
43
|
+
.option(...option.config)
|
|
44
|
+
.option(...option.indent)
|
|
50
45
|
.parse(process.argv);
|
|
51
|
-
|
|
52
|
-
io
|
|
46
|
+
Effect.runPromise(format({
|
|
47
|
+
io,
|
|
53
48
|
cli: {
|
|
54
|
-
configPath:
|
|
55
|
-
indent:
|
|
56
|
-
source:
|
|
49
|
+
configPath: program.opts().config,
|
|
50
|
+
indent: program.opts().indent,
|
|
51
|
+
source: program.opts().source,
|
|
57
52
|
},
|
|
58
53
|
}));
|
package/dist/bin-lint/index.js
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const option_1 = require("../option");
|
|
13
|
-
const lint_1 = require("./lint");
|
|
14
|
-
commander_1.program.description(' lint all versions and ranges');
|
|
15
|
-
commander_1.program.on('--help', () => {
|
|
16
|
-
console.log((0, chalk_1.default) `
|
|
2
|
+
import chalk from 'chalk-template';
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import { Effect } from 'effect';
|
|
5
|
+
import { io } from '../io/index.js';
|
|
6
|
+
import { showHelpOnError } from '../lib/show-help-on-error.js';
|
|
7
|
+
import { option } from '../option.js';
|
|
8
|
+
import { lint } from './lint.js';
|
|
9
|
+
program.description(' lint all versions and ranges');
|
|
10
|
+
program.on('--help', () => {
|
|
11
|
+
console.log(chalk `
|
|
17
12
|
Examples:
|
|
18
13
|
{dim # uses config file for resolving packages}
|
|
19
14
|
syncpack lint
|
|
@@ -33,11 +28,11 @@ Reference:
|
|
|
33
28
|
Pnpm Workspaces {blue.underline https://pnpm.js.org/en/workspaces}
|
|
34
29
|
`);
|
|
35
30
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
io
|
|
31
|
+
showHelpOnError(program);
|
|
32
|
+
program.option(...option.config).parse(process.argv);
|
|
33
|
+
Effect.runPromise(lint({
|
|
34
|
+
io,
|
|
40
35
|
cli: {
|
|
41
|
-
configPath:
|
|
36
|
+
configPath: program.opts().config,
|
|
42
37
|
},
|
|
43
38
|
}));
|
package/dist/bin-lint/lint.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Effect } from 'effect';
|
|
2
|
-
import { type CliConfig } from '../config/types';
|
|
3
|
-
import type { ErrorHandlers } from '../error-handlers/default-error-handlers';
|
|
4
|
-
import type { Io } from '../io';
|
|
2
|
+
import { type CliConfig } from '../config/types.js';
|
|
3
|
+
import type { ErrorHandlers } from '../error-handlers/default-error-handlers.js';
|
|
4
|
+
import type { Io } from '../io/index.js';
|
|
5
5
|
interface Input {
|
|
6
6
|
io: Io;
|
|
7
7
|
cli: Partial<CliConfig>;
|
|
8
8
|
errorHandlers?: ErrorHandlers;
|
|
9
9
|
}
|
|
10
|
-
export declare function lint({ io, cli, errorHandlers }: Input): Effect.Effect<
|
|
10
|
+
export declare function lint({ io, cli, errorHandlers }: Input): Effect.Effect<unknown, never, never>;
|
|
11
11
|
export {};
|