syncpack 9.3.2 → 9.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin-fix-mismatches/fix-mismatches-cli.js +4 -4
- package/dist/bin-fix-mismatches/fix-mismatches.js +17 -15
- package/dist/bin-fix-mismatches/index.js +50 -48
- package/dist/bin-format/format-cli.js +4 -4
- package/dist/bin-format/format.js +20 -18
- package/dist/bin-format/index.js +43 -46
- package/dist/bin-lint-semver-ranges/index.js +59 -48
- package/dist/bin-lint-semver-ranges/lint-semver-ranges-cli.js +4 -4
- package/dist/bin-lint-semver-ranges/lint-semver-ranges.js +13 -35
- package/dist/bin-list/index.js +43 -46
- package/dist/bin-list/list-cli.js +4 -4
- package/dist/bin-list/list.js +26 -29
- package/dist/bin-list-mismatches/index.js +46 -47
- package/dist/bin-list-mismatches/list-mismatches-cli.js +4 -4
- package/dist/bin-list-mismatches/list-mismatches.js +55 -40
- package/dist/bin-set-semver-ranges/index.js +62 -49
- package/dist/bin-set-semver-ranges/set-semver-ranges-cli.js +4 -4
- package/dist/bin-set-semver-ranges/set-semver-ranges.js +4 -4
- package/dist/bin.js +8 -8
- package/dist/constants.d.ts +2 -1
- package/dist/constants.js +6 -5
- package/dist/get-context/$R.js +14 -36
- package/dist/get-context/get-config/get-core-types.js +11 -41
- package/dist/get-context/get-config/get-custom-types.js +7 -19
- package/dist/get-context/get-config/get-enabled-types.js +9 -11
- package/dist/get-context/get-config/index.d.ts +3 -1
- package/dist/get-context/get-config/index.js +37 -61
- package/dist/get-context/get-config/path-strategy/index.js +8 -8
- package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.js +6 -6
- package/dist/get-context/get-config/path-strategy/name-and-version-props.js +23 -49
- package/dist/get-context/get-config/path-strategy/name-and-version-string.js +26 -42
- package/dist/get-context/get-config/path-strategy/types.js +1 -1
- package/dist/get-context/get-config/path-strategy/version-string.js +25 -41
- package/dist/get-context/get-config/path-strategy/versions-by-name.js +14 -30
- package/dist/get-context/get-config/schema/base-group.d.ts +2 -2
- package/dist/get-context/get-config/schema/base-group.js +5 -5
- package/dist/get-context/get-config/schema/index.d.ts +292 -164
- package/dist/get-context/get-config/schema/index.js +40 -63
- package/dist/get-context/get-config/schema/lib/non-empty-string.d.ts +2 -0
- package/dist/get-context/get-config/schema/lib/non-empty-string.js +5 -0
- package/dist/get-context/get-config/schema/paths.js +12 -12
- package/dist/get-context/get-config/schema/semver-group.d.ts +24 -24
- package/dist/get-context/get-config/schema/semver-group.js +11 -18
- package/dist/get-context/get-config/schema/semver-range.js +4 -4
- package/dist/get-context/get-config/schema/version-group.d.ts +90 -41
- package/dist/get-context/get-config/schema/version-group.js +28 -23
- package/dist/get-context/get-groups/base-group.d.ts +4 -1
- package/dist/get-context/get-groups/base-group.js +18 -19
- package/dist/get-context/get-groups/index.d.ts +7 -3
- package/dist/get-context/get-groups/index.js +42 -38
- package/dist/get-context/get-groups/semver-group.d.ts +0 -1
- package/dist/get-context/get-groups/semver-group.js +23 -66
- package/dist/get-context/get-groups/version-group/index.d.ts +7 -4
- package/dist/get-context/get-groups/version-group/index.js +31 -70
- package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.d.ts +3 -1
- package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +36 -45
- package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.d.ts +3 -0
- package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.js +44 -0
- package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +16 -5
- package/dist/get-context/get-groups/version-group/instance-group/index.js +66 -54
- package/dist/get-context/get-groups/version-group/instance-group/lib/clean.d.ts +2 -0
- package/dist/get-context/get-groups/version-group/instance-group/lib/clean.js +13 -0
- package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +4 -0
- package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +38 -0
- package/dist/get-context/get-groups/version-group/instance-group/lib/get-range-score.d.ts +2 -0
- package/dist/get-context/get-groups/version-group/instance-group/lib/get-range-score.js +23 -0
- package/dist/get-context/get-package-json-files/get-file-paths.js +18 -19
- package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.js +9 -12
- package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.js +9 -11
- package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.js +10 -13
- package/dist/get-context/get-package-json-files/get-patterns/index.js +15 -42
- package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.js +4 -6
- package/dist/get-context/get-package-json-files/get-patterns/props.js +9 -33
- package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.js +6 -9
- package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.js +4 -4
- package/dist/get-context/get-package-json-files/index.d.ts +3 -1
- package/dist/get-context/get-package-json-files/index.js +8 -8
- package/dist/get-context/get-package-json-files/package-json-file/index.js +32 -55
- package/dist/get-context/get-package-json-files/package-json-file/instance.d.ts +2 -1
- package/dist/get-context/get-package-json-files/package-json-file/instance.js +15 -15
- package/dist/get-context/index.d.ts +3 -2
- package/dist/get-context/index.js +28 -24
- package/dist/lib/disk.js +28 -29
- package/dist/lib/error.js +13 -31
- package/dist/lib/exit-if-invalid.js +1 -1
- package/dist/lib/is-semver.d.ts +1 -1
- package/dist/lib/is-semver.js +15 -7
- package/dist/lib/log.js +38 -58
- package/dist/lib/newlines.js +11 -11
- package/dist/lib/print-strings.js +2 -2
- package/dist/lib/set-semver-range.js +8 -8
- package/dist/lib/show-help-on-error.js +31 -8
- package/dist/lib/sort-by-name.js +1 -1
- package/dist/lib/write-if-changed.js +3 -3
- package/dist/option.js +8 -13
- package/dist/types.d.ts +3 -1
- package/dist/types.js +1 -1
- package/package.json +20 -16
- package/dist/get-context/get-all-instances.d.ts +0 -3
- package/dist/get-context/get-all-instances.js +0 -8
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { O, R } from '@mobily/ts-belt';
|
|
1
2
|
import type { VersionGroup } from '..';
|
|
3
|
+
import { BaseError } from '../../../../lib/error';
|
|
2
4
|
import type { Instance } from '../../../get-package-json-files/package-json-file/instance';
|
|
5
|
+
export declare const DELETE: unique symbol;
|
|
6
|
+
export type Delete = typeof DELETE;
|
|
3
7
|
/** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
|
|
4
8
|
export declare class InstanceGroup {
|
|
5
9
|
/** Every package/pathName location where this dependency was found */
|
|
@@ -13,12 +17,19 @@ export declare class InstanceGroup {
|
|
|
13
17
|
getUniqueVersions(): string[];
|
|
14
18
|
hasMismatchingVersions(): boolean;
|
|
15
19
|
isInvalid(): boolean;
|
|
16
|
-
getExpectedVersion(): string |
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
getExpectedVersion(): R.Result<string | Delete, BaseError>;
|
|
21
|
+
/** If all versions are valid semver, return the newest one */
|
|
22
|
+
getHighestVersion(): R.Result<string, BaseError>;
|
|
23
|
+
/** If all versions are valid semver, return the lowest one */
|
|
24
|
+
getLowestVersion(): R.Result<string, BaseError>;
|
|
25
|
+
/** Get the first version matched by the `snapTo` packages */
|
|
26
|
+
getSnappedVersion(): R.Result<string, BaseError>;
|
|
27
|
+
/** Is `snapTo` defined and this group does not match that version? */
|
|
28
|
+
isUnsnapped(): R.Result<boolean, BaseError>;
|
|
19
29
|
/** Get version of dependency which is developed in this monorepo */
|
|
20
|
-
getWorkspaceVersion(): string
|
|
30
|
+
getWorkspaceVersion(): R.Result<string, BaseError>;
|
|
21
31
|
/** Find instance of this dependency which is developed in this monorepo */
|
|
22
|
-
getWorkspaceInstance(): Instance
|
|
32
|
+
getWorkspaceInstance(): O.Option<Instance>;
|
|
33
|
+
/** Is an instance of this dependency developed in this monorepo? */
|
|
23
34
|
hasWorkspaceInstance(): boolean;
|
|
24
35
|
}
|
|
@@ -1,76 +1,88 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
3
|
-
exports.InstanceGroup = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InstanceGroup = exports.DELETE = void 0;
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const expect_more_1 = require("expect-more");
|
|
6
|
+
const error_1 = require("../../../../lib/error");
|
|
7
|
+
const is_semver_1 = require("../../../../lib/is-semver");
|
|
8
|
+
const print_strings_1 = require("../../../../lib/print-strings");
|
|
9
|
+
const props_1 = require("../../../get-package-json-files/get-patterns/props");
|
|
10
|
+
const get_highest_version_1 = require("./get-highest-version");
|
|
11
|
+
const get_lowest_version_1 = require("./get-lowest-version");
|
|
12
|
+
exports.DELETE = Symbol('DELETE');
|
|
8
13
|
/** Every `Instance` of eg `"lodash"` for a given `VersionGroup` */
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
class InstanceGroup {
|
|
15
|
+
constructor(versionGroup, name, instances) {
|
|
11
16
|
this.instances = instances;
|
|
12
17
|
this.name = name;
|
|
13
18
|
this.versionGroup = versionGroup;
|
|
14
19
|
}
|
|
15
|
-
|
|
16
|
-
return this.instances.some(
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return Array.from(new Set(this.instances.map(
|
|
20
|
-
}
|
|
21
|
-
|
|
20
|
+
hasUnsupportedVersion() {
|
|
21
|
+
return this.instances.some((obj) => !(0, is_semver_1.isSemver)(obj.version));
|
|
22
|
+
}
|
|
23
|
+
getUniqueVersions() {
|
|
24
|
+
return Array.from(new Set(this.instances.map((obj) => obj.version))).sort();
|
|
25
|
+
}
|
|
26
|
+
hasMismatchingVersions() {
|
|
22
27
|
return this.getUniqueVersions().length > 1;
|
|
23
|
-
}
|
|
24
|
-
|
|
28
|
+
}
|
|
29
|
+
isInvalid() {
|
|
25
30
|
return this.versionGroup.isIgnored()
|
|
26
31
|
? false
|
|
27
32
|
: this.versionGroup.isBanned() ||
|
|
28
33
|
this.versionGroup.isUnpinned() ||
|
|
29
34
|
this.hasMismatchingVersions();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
var REMOVE_DEPENDENCY = undefined;
|
|
35
|
+
}
|
|
36
|
+
getExpectedVersion() {
|
|
37
|
+
const versionGroup = this.versionGroup;
|
|
34
38
|
if (versionGroup.isBanned())
|
|
35
|
-
return
|
|
39
|
+
return ts_belt_1.R.Ok(exports.DELETE);
|
|
36
40
|
if (versionGroup.isUnpinned())
|
|
37
|
-
return versionGroup.getPinnedVersion();
|
|
41
|
+
return (0, ts_belt_1.pipe)(versionGroup.getPinnedVersion(), ts_belt_1.O.toResult(new error_1.BaseError(`${this.name} is in a versionGroup with pinVersion configuration, but the pinVersion value is not valid`)));
|
|
42
|
+
if (versionGroup.hasSnappedToPackages() && ts_belt_1.R.getExn(this.isUnsnapped()))
|
|
43
|
+
return this.getSnappedVersion();
|
|
38
44
|
if (this.hasWorkspaceInstance())
|
|
39
45
|
return this.getWorkspaceVersion();
|
|
40
46
|
if (this.hasUnsupportedVersion()) {
|
|
41
|
-
|
|
47
|
+
return ts_belt_1.R.Error(new error_1.BaseError(`${this.name} contains unsupported versions: ${(0, print_strings_1.printStrings)(this.getUniqueVersions())}`));
|
|
42
48
|
}
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
return versionGroup.groupConfig.preferVersion ===
|
|
50
|
+
'lowestSemver'
|
|
51
|
+
? this.getLowestVersion()
|
|
52
|
+
: this.getHighestVersion();
|
|
53
|
+
}
|
|
54
|
+
/** If all versions are valid semver, return the newest one */
|
|
55
|
+
getHighestVersion() {
|
|
46
56
|
return (0, get_highest_version_1.getHighestVersion)(this.getUniqueVersions());
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
return (this.
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
}
|
|
58
|
+
/** If all versions are valid semver, return the lowest one */
|
|
59
|
+
getLowestVersion() {
|
|
60
|
+
return (0, get_lowest_version_1.getLowestVersion)(this.getUniqueVersions());
|
|
61
|
+
}
|
|
62
|
+
/** Get the first version matched by the `snapTo` packages */
|
|
63
|
+
getSnappedVersion() {
|
|
64
|
+
return (0, ts_belt_1.pipe)(this.versionGroup.getSnappedToPackages(), ts_belt_1.O.flatMap((pkgNames) => ts_belt_1.O.fromFalsy(this.instances
|
|
65
|
+
.filter(({ pkgName }) => pkgNames.includes(pkgName))
|
|
66
|
+
.map(({ version }) => version)
|
|
67
|
+
.find(Boolean))), ts_belt_1.O.filter(expect_more_1.isNonEmptyString), ts_belt_1.O.toResult(new error_1.BaseError(`${this.name} is in a versionGroup with snapTo configuration, but ${this.name} was not found in those packages`)));
|
|
68
|
+
}
|
|
69
|
+
/** Is `snapTo` defined and this group does not match that version? */
|
|
70
|
+
isUnsnapped() {
|
|
71
|
+
return this.versionGroup.hasSnappedToPackages()
|
|
72
|
+
? (0, ts_belt_1.pipe)(this.getSnappedVersion(), ts_belt_1.R.map((nextVersion) => this.instances.some(({ version }) => version !== nextVersion)))
|
|
73
|
+
: ts_belt_1.R.Ok(false);
|
|
74
|
+
}
|
|
56
75
|
/** Get version of dependency which is developed in this monorepo */
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
return (_a = this.getWorkspaceInstance()) === null || _a === void 0 ? void 0 : _a.packageJsonFile.contents.version;
|
|
61
|
-
}
|
|
62
|
-
throw new error_1.BaseError('getWorkspaceVersion invoked when there is none');
|
|
63
|
-
};
|
|
76
|
+
getWorkspaceVersion() {
|
|
77
|
+
return (0, ts_belt_1.pipe)(this.getWorkspaceInstance(), (0, props_1.props)('packageJsonFile.contents.version', expect_more_1.isNonEmptyString), ts_belt_1.O.toResult(new error_1.BaseError(`Expected to find a package.json file developed in this monorepo with a "name" property of "${this.name}" and a valid "version" property`)));
|
|
78
|
+
}
|
|
64
79
|
/** Find instance of this dependency which is developed in this monorepo */
|
|
65
|
-
|
|
66
|
-
return this.instances.find(
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
return InstanceGroup;
|
|
75
|
-
}());
|
|
80
|
+
getWorkspaceInstance() {
|
|
81
|
+
return ts_belt_1.O.fromFalsy(this.instances.find(({ pathDef }) => pathDef.name === 'workspace'));
|
|
82
|
+
}
|
|
83
|
+
/** Is an instance of this dependency developed in this monorepo? */
|
|
84
|
+
hasWorkspaceInstance() {
|
|
85
|
+
return (0, ts_belt_1.pipe)(this.getWorkspaceInstance(), ts_belt_1.O.toUndefined) !== undefined;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
76
88
|
exports.InstanceGroup = InstanceGroup;
|
|
@@ -0,0 +1,13 @@
|
|
|
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.clean = void 0;
|
|
7
|
+
const coerce_1 = __importDefault(require("semver/functions/coerce"));
|
|
8
|
+
const valid_1 = __importDefault(require("semver/functions/valid"));
|
|
9
|
+
/** Convert eg "1" to "1.0.0" which the semver lib does not understand */
|
|
10
|
+
function clean(v) {
|
|
11
|
+
return (0, valid_1.default)((0, coerce_1.default)(v)) || '';
|
|
12
|
+
}
|
|
13
|
+
exports.clean = clean;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Is this next version to be inspected higher than the current highest? */
|
|
2
|
+
export declare function compareGt(next: string, highest: string | undefined): '*' | 'invalid' | 'gt' | 'lt' | 'eq';
|
|
3
|
+
/** Is this next version to be inspected lower than the current lowest? */
|
|
4
|
+
export declare function compareLt(next: string, lowest: string | undefined): '*' | 'invalid' | 'gt' | 'lt' | 'eq';
|
|
@@ -0,0 +1,38 @@
|
|
|
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.compareLt = exports.compareGt = void 0;
|
|
7
|
+
const gt_1 = __importDefault(require("semver/functions/gt"));
|
|
8
|
+
const lt_1 = __importDefault(require("semver/functions/lt"));
|
|
9
|
+
const is_semver_1 = require("../../../../../lib/is-semver");
|
|
10
|
+
const clean_1 = require("./clean");
|
|
11
|
+
/** Is this next version to be inspected higher than the current highest? */
|
|
12
|
+
function compareGt(next, highest) {
|
|
13
|
+
if (next === '*')
|
|
14
|
+
return '*';
|
|
15
|
+
if (!(0, is_semver_1.isSemver)(next))
|
|
16
|
+
return 'invalid';
|
|
17
|
+
if (!highest || (0, gt_1.default)((0, clean_1.clean)(next), highest))
|
|
18
|
+
return 'gt';
|
|
19
|
+
if ((0, lt_1.default)((0, clean_1.clean)(next), highest))
|
|
20
|
+
return 'lt';
|
|
21
|
+
return 'eq';
|
|
22
|
+
}
|
|
23
|
+
exports.compareGt = compareGt;
|
|
24
|
+
/** Is this next version to be inspected lower than the current lowest? */
|
|
25
|
+
function compareLt(next, lowest) {
|
|
26
|
+
if (next === '*')
|
|
27
|
+
return '*';
|
|
28
|
+
if (!(0, is_semver_1.isSemver)(next))
|
|
29
|
+
return 'invalid';
|
|
30
|
+
if (lowest === '*')
|
|
31
|
+
return 'lt';
|
|
32
|
+
if (!lowest || (0, lt_1.default)((0, clean_1.clean)(next), lowest))
|
|
33
|
+
return 'lt';
|
|
34
|
+
if ((0, gt_1.default)((0, clean_1.clean)(next), lowest))
|
|
35
|
+
return 'gt';
|
|
36
|
+
return 'eq';
|
|
37
|
+
}
|
|
38
|
+
exports.compareLt = compareLt;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getRangeScore = void 0;
|
|
4
|
+
const constants_1 = require("../../../../../constants");
|
|
5
|
+
const scoresByRange = {
|
|
6
|
+
[constants_1.RANGE.ANY]: 8,
|
|
7
|
+
[constants_1.RANGE.GT]: 7,
|
|
8
|
+
[constants_1.RANGE.GTE]: 6,
|
|
9
|
+
[constants_1.RANGE.MINOR]: 5,
|
|
10
|
+
[constants_1.RANGE.LOOSE]: 4,
|
|
11
|
+
[constants_1.RANGE.PATCH]: 3,
|
|
12
|
+
[constants_1.RANGE.EXACT]: 2,
|
|
13
|
+
[constants_1.RANGE.LTE]: 1,
|
|
14
|
+
[constants_1.RANGE.LT]: 0,
|
|
15
|
+
};
|
|
16
|
+
/** Rank a Semver Range according to its greediness */
|
|
17
|
+
function getRangeScore(version) {
|
|
18
|
+
const range = version.indexOf('.x') !== -1
|
|
19
|
+
? constants_1.RANGE.LOOSE
|
|
20
|
+
: version.slice(0, version.search(/[0-9]/));
|
|
21
|
+
return scoresByRange[range] || 0;
|
|
22
|
+
}
|
|
23
|
+
exports.getRangeScore = getRangeScore;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getFilePaths = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const is_array_of_strings_1 = require("expect-more/dist/is-array-of-strings");
|
|
6
|
+
const is_empty_array_1 = require("expect-more/dist/is-empty-array");
|
|
7
|
+
const _R_1 = require("../$R");
|
|
8
|
+
const error_1 = require("../../lib/error");
|
|
9
|
+
const print_strings_1 = require("../../lib/print-strings");
|
|
10
|
+
const get_patterns_1 = require("./get-patterns");
|
|
10
11
|
/**
|
|
11
12
|
* Using --source options and/or config files on disk from npm/pnpm/yarn/lerna,
|
|
12
13
|
* return an array of absolute paths to every package.json file the user is
|
|
@@ -17,21 +18,19 @@ var get_patterns_1 = require("./get-patterns");
|
|
|
17
18
|
function getFilePaths(disk, program) {
|
|
18
19
|
return (0, ts_belt_1.pipe)(program, (0, get_patterns_1.getPatterns)(disk), ts_belt_1.R.flatMap(resolvePatterns));
|
|
19
20
|
function resolvePatterns(patterns) {
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
const quoted = (0, print_strings_1.printStrings)(patterns);
|
|
22
|
+
const ERR_NO_MATCH = `No package.json files matched the patterns: ${quoted}`;
|
|
22
23
|
return (0, ts_belt_1.pipe)(patterns, _R_1.$R.onlyOk(resolvePattern), ts_belt_1.R.mapError(error_1.BaseError.map(ERR_NO_MATCH)), ts_belt_1.R.map((0, ts_belt_1.flow)(ts_belt_1.A.flat, ts_belt_1.A.uniq, removeReadonlyType)));
|
|
23
24
|
}
|
|
24
25
|
function resolvePattern(pattern) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
: ts_belt_1.R.Error(new error_1.BaseError(ERR_INVALID));
|
|
34
|
-
}));
|
|
26
|
+
const ERR_GLOB_MISS = `No package.json files match pattern "${pattern}"`;
|
|
27
|
+
const ERR_INVALID = `"glob" returned unexpected data on pattern "${pattern}"`;
|
|
28
|
+
const ERR_GLOB_THROW = `"glob" threw on pattern "${pattern}"`;
|
|
29
|
+
return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => disk.globSync(pattern)), ts_belt_1.R.mapError(error_1.BaseError.map(ERR_GLOB_THROW)), ts_belt_1.R.flatMap((filePaths) => (0, is_empty_array_1.isEmptyArray)(filePaths)
|
|
30
|
+
? ts_belt_1.R.Error(new error_1.BaseError(ERR_GLOB_MISS))
|
|
31
|
+
: (0, is_array_of_strings_1.isArrayOfStrings)(filePaths)
|
|
32
|
+
? ts_belt_1.R.Ok((0, ts_belt_1.pipe)(filePaths, ts_belt_1.A.flat, ts_belt_1.A.uniq, removeReadonlyType))
|
|
33
|
+
: ts_belt_1.R.Error(new error_1.BaseError(ERR_INVALID))));
|
|
35
34
|
}
|
|
36
35
|
/** Remove unwanted readonly type */
|
|
37
36
|
function removeReadonlyType(value) {
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getLernaPatterns = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const constants_1 = require("../../../constants");
|
|
7
|
+
const error_1 = require("../../../lib/error");
|
|
8
|
+
const get_array_of_strings_1 = require("./lib/get-array-of-strings");
|
|
9
|
+
const read_json_safe_1 = require("./read-json-safe");
|
|
10
10
|
function getLernaPatterns(disk) {
|
|
11
|
-
|
|
11
|
+
const getPackages = (0, get_array_of_strings_1.getArrayOfStrings)('packages');
|
|
12
12
|
return function getLernaPatterns() {
|
|
13
|
-
return (0, ts_belt_1.pipe)((0, path_1.join)(constants_1.CWD, 'lerna.json'), (0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.flatMap(
|
|
14
|
-
var contents = _a.contents;
|
|
15
|
-
return (0, ts_belt_1.pipe)(getPackages(contents), ts_belt_1.O.toResult(new error_1.BaseError('no lerna patterns found')));
|
|
16
|
-
}));
|
|
13
|
+
return (0, ts_belt_1.pipe)((0, path_1.join)(constants_1.CWD, 'lerna.json'), (0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.flatMap(({ contents }) => (0, ts_belt_1.pipe)(getPackages(contents), ts_belt_1.O.toResult(new error_1.BaseError('no lerna patterns found')))));
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
16
|
exports.getLernaPatterns = getLernaPatterns;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPnpmPatterns = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const constants_1 = require("../../../constants");
|
|
7
|
+
const error_1 = require("../../../lib/error");
|
|
8
|
+
const get_array_of_strings_1 = require("./lib/get-array-of-strings");
|
|
9
|
+
const read_yaml_safe_1 = require("./read-yaml-safe");
|
|
10
|
+
const getPackages = (0, get_array_of_strings_1.getArrayOfStrings)('packages');
|
|
11
11
|
function getPnpmPatterns(disk) {
|
|
12
12
|
return function getPnpmPatterns() {
|
|
13
13
|
return (0, ts_belt_1.pipe)(
|
|
@@ -15,9 +15,7 @@ function getPnpmPatterns(disk) {
|
|
|
15
15
|
// - "packages/**"
|
|
16
16
|
// - "components/**"
|
|
17
17
|
// - "!**/test/**"
|
|
18
|
-
(0, path_1.join)(constants_1.CWD, 'pnpm-workspace.yaml'), (0, read_yaml_safe_1.readYamlSafe)(disk), ts_belt_1.R.flatMap(
|
|
19
|
-
return (0, ts_belt_1.pipe)(getPackages(packageJson), ts_belt_1.O.match(ts_belt_1.F.identity, function () { return getPackages(packageJson); }), ts_belt_1.O.toResult(new error_1.BaseError('no pnpm patterns found')));
|
|
20
|
-
}));
|
|
18
|
+
(0, path_1.join)(constants_1.CWD, 'pnpm-workspace.yaml'), (0, read_yaml_safe_1.readYamlSafe)(disk), ts_belt_1.R.flatMap((packageJson) => (0, ts_belt_1.pipe)(getPackages(packageJson), ts_belt_1.O.match(ts_belt_1.F.identity, () => getPackages(packageJson)), ts_belt_1.O.toResult(new error_1.BaseError('no pnpm patterns found')))));
|
|
21
19
|
};
|
|
22
20
|
}
|
|
23
21
|
exports.getPnpmPatterns = getPnpmPatterns;
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getYarnPatterns = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
const constants_1 = require("../../../constants");
|
|
7
|
+
const error_1 = require("../../../lib/error");
|
|
8
|
+
const get_array_of_strings_1 = require("./lib/get-array-of-strings");
|
|
9
|
+
const read_json_safe_1 = require("./read-json-safe");
|
|
10
10
|
function getYarnPatterns(disk) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const getPackages = (0, get_array_of_strings_1.getArrayOfStrings)('workspaces');
|
|
12
|
+
const getPackagesNested = (0, get_array_of_strings_1.getArrayOfStrings)('workspaces.packages');
|
|
13
13
|
return function getYarnPatterns() {
|
|
14
|
-
return (0, ts_belt_1.pipe)((0, path_1.join)(constants_1.CWD, 'package.json'), (0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.flatMap(
|
|
15
|
-
var contents = _a.contents;
|
|
16
|
-
return (0, ts_belt_1.pipe)(getPackages(contents), ts_belt_1.O.match(ts_belt_1.F.identity, function () { return getPackagesNested(contents); }), ts_belt_1.O.toResult(new error_1.BaseError('no yarn patterns found')));
|
|
17
|
-
}));
|
|
14
|
+
return (0, ts_belt_1.pipe)((0, path_1.join)(constants_1.CWD, 'package.json'), (0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.flatMap(({ contents }) => (0, ts_belt_1.pipe)(getPackages(contents), ts_belt_1.O.match(ts_belt_1.F.identity, () => getPackagesNested(contents)), ts_belt_1.O.toResult(new error_1.BaseError('no yarn patterns found')))));
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
17
|
exports.getYarnPatterns = getYarnPatterns;
|
|
@@ -1,38 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
-
if (!m) return o;
|
|
5
|
-
var i = m.call(o), r, ar = [], e;
|
|
6
|
-
try {
|
|
7
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
-
}
|
|
9
|
-
catch (error) { e = { error: error }; }
|
|
10
|
-
finally {
|
|
11
|
-
try {
|
|
12
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
-
}
|
|
14
|
-
finally { if (e) throw e.error; }
|
|
15
|
-
}
|
|
16
|
-
return ar;
|
|
17
|
-
};
|
|
18
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
-
if (ar || !(i in from)) {
|
|
21
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
-
ar[i] = from[i];
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
-
};
|
|
27
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
3
|
exports.getPatterns = void 0;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const is_array_of_strings_1 = require("expect-more/dist/is-array-of-strings");
|
|
6
|
+
const constants_1 = require("../../../constants");
|
|
7
|
+
const error_1 = require("../../../lib/error");
|
|
8
|
+
const get_lerna_patterns_1 = require("./get-lerna-patterns");
|
|
9
|
+
const get_pnpm_patterns_1 = require("./get-pnpm-patterns");
|
|
10
|
+
const get_yarn_patterns_1 = require("./get-yarn-patterns");
|
|
36
11
|
/**
|
|
37
12
|
* Find every glob pattern which should be used to find package.json files for
|
|
38
13
|
* this monorepo.
|
|
@@ -41,29 +16,27 @@ var get_yarn_patterns_1 = require("./get-yarn-patterns");
|
|
|
41
16
|
*/
|
|
42
17
|
function getPatterns(disk) {
|
|
43
18
|
return function getPatterns(program) {
|
|
44
|
-
|
|
19
|
+
const getters = [
|
|
45
20
|
getCliPatterns,
|
|
46
21
|
(0, get_yarn_patterns_1.getYarnPatterns)(disk),
|
|
47
22
|
(0, get_pnpm_patterns_1.getPnpmPatterns)(disk),
|
|
48
23
|
(0, get_lerna_patterns_1.getLernaPatterns)(disk),
|
|
49
24
|
];
|
|
50
|
-
|
|
51
|
-
|
|
25
|
+
const initialResult = ts_belt_1.R.Error(new error_1.BaseError('getPatterns did not try any sources'));
|
|
26
|
+
const res = ts_belt_1.A.reduce(getters, initialResult, (previousResult, getNextResult) => {
|
|
52
27
|
if (ts_belt_1.R.isOk(previousResult))
|
|
53
28
|
return previousResult;
|
|
54
29
|
return getNextResult();
|
|
55
30
|
});
|
|
56
|
-
return (0, ts_belt_1.pipe)(res, ts_belt_1.R.map(addRootDir), ts_belt_1.R.map(limitToPackageJson), ts_belt_1.R.handleError(
|
|
31
|
+
return (0, ts_belt_1.pipe)(res, ts_belt_1.R.map(addRootDir), ts_belt_1.R.map(limitToPackageJson), ts_belt_1.R.handleError(() => constants_1.DEFAULT_SOURCES), ts_belt_1.R.mapError(ts_belt_1.F.identity));
|
|
57
32
|
function getCliPatterns() {
|
|
58
|
-
return ts_belt_1.R.fromPredicate(program.source,
|
|
33
|
+
return ts_belt_1.R.fromPredicate(program.source, is_array_of_strings_1.isArrayOfStrings, new error_1.BaseError('No --source options provided'));
|
|
59
34
|
}
|
|
60
35
|
function addRootDir(patterns) {
|
|
61
|
-
return
|
|
36
|
+
return ['package.json', ...patterns];
|
|
62
37
|
}
|
|
63
38
|
function limitToPackageJson(patterns) {
|
|
64
|
-
return patterns.map(
|
|
65
|
-
return pattern.includes('package.json') ? pattern : "".concat(pattern, "/package.json");
|
|
66
|
-
});
|
|
39
|
+
return patterns.map((pattern) => pattern.includes('package.json') ? pattern : `${pattern}/package.json`);
|
|
67
40
|
}
|
|
68
41
|
};
|
|
69
42
|
}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getArrayOfStrings = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const is_array_of_strings_1 = require("expect-more/dist/is-array-of-strings");
|
|
5
|
+
const props_1 = require("../props");
|
|
6
6
|
// Yarn's config for this can be in more than one place
|
|
7
|
-
|
|
8
|
-
return (0, props_1.props)(path, expect_more_1.isArrayOfStrings);
|
|
9
|
-
};
|
|
7
|
+
const getArrayOfStrings = (path) => (0, props_1.props)(path, is_array_of_strings_1.isArrayOfStrings);
|
|
10
8
|
exports.getArrayOfStrings = getArrayOfStrings;
|
|
@@ -1,46 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
-
if (m) return m.call(o);
|
|
5
|
-
if (o && typeof o.length === "number") return {
|
|
6
|
-
next: function () {
|
|
7
|
-
if (o && i >= o.length) o = void 0;
|
|
8
|
-
return { value: o && o[i++], done: !o };
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
12
|
-
};
|
|
13
|
-
exports.__esModule = true;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.props = void 0;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return value !== null && typeof value !== 'undefined';
|
|
18
|
-
};
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const isWalkable = (value) => value !== null && typeof value !== 'undefined';
|
|
19
6
|
/**
|
|
20
7
|
* Safely read nested properties of any value.
|
|
21
8
|
* @param keys 'child.grandChild.greatGrandChild'
|
|
22
9
|
*/
|
|
23
10
|
function props(keys, predicate) {
|
|
24
11
|
return function getNestedProp(obj) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var key = _c.value;
|
|
30
|
-
if (isWalkable(next) && key in next) {
|
|
31
|
-
next = next[key];
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
return ts_belt_1.O.None;
|
|
35
|
-
}
|
|
12
|
+
let next = obj;
|
|
13
|
+
for (const key of keys.split('.')) {
|
|
14
|
+
if (isWalkable(next) && key in next) {
|
|
15
|
+
next = next[key];
|
|
36
16
|
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
finally {
|
|
40
|
-
try {
|
|
41
|
-
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
|
|
17
|
+
else {
|
|
18
|
+
return ts_belt_1.O.None;
|
|
42
19
|
}
|
|
43
|
-
finally { if (e_1) throw e_1.error; }
|
|
44
20
|
}
|
|
45
21
|
return ts_belt_1.O.fromPredicate(next, predicate);
|
|
46
22
|
};
|
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
exports
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.readJsonSafe = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
const ts_belt_1 = require("@mobily/ts-belt");
|
|
5
|
+
const error_1 = require("../../../lib/error");
|
|
6
6
|
function readJsonSafe(disk) {
|
|
7
7
|
return function readJsonSafe(filePath) {
|
|
8
|
-
return (0, ts_belt_1.pipe)(readFileSafe(filePath), ts_belt_1.R.flatMap((0, ts_belt_1.flow)((parseJsonSafe), ts_belt_1.R.mapError(error_1.BaseError.map(
|
|
9
|
-
var contents = _a.contents, json = _a.json;
|
|
10
|
-
return ({ contents: contents, filePath: filePath, json: json });
|
|
11
|
-
}))));
|
|
8
|
+
return (0, ts_belt_1.pipe)(readFileSafe(filePath), ts_belt_1.R.flatMap((0, ts_belt_1.flow)((parseJsonSafe), ts_belt_1.R.mapError(error_1.BaseError.map(`Failed to parse JSON file at ${filePath}`)), ts_belt_1.R.map(({ contents, json }) => ({ contents, filePath, json })))));
|
|
12
9
|
};
|
|
13
10
|
function readFileSafe(filePath) {
|
|
14
|
-
return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(
|
|
11
|
+
return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => disk.readFileSync(filePath)), ts_belt_1.R.mapError(error_1.BaseError.map(`Failed to read JSON file at ${filePath}`)));
|
|
15
12
|
}
|
|
16
13
|
}
|
|
17
14
|
exports.readJsonSafe = readJsonSafe;
|
|
18
15
|
function parseJsonSafe(json) {
|
|
19
|
-
return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(
|
|
16
|
+
return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => JSON.parse(json)), ts_belt_1.R.mapError(error_1.BaseError.map('Failed to parse JSON')), ts_belt_1.R.map((contents) => ({ contents, json })));
|
|
20
17
|
}
|