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.
Files changed (100) hide show
  1. package/dist/bin-fix-mismatches/fix-mismatches-cli.js +4 -4
  2. package/dist/bin-fix-mismatches/fix-mismatches.js +17 -15
  3. package/dist/bin-fix-mismatches/index.js +50 -48
  4. package/dist/bin-format/format-cli.js +4 -4
  5. package/dist/bin-format/format.js +20 -18
  6. package/dist/bin-format/index.js +43 -46
  7. package/dist/bin-lint-semver-ranges/index.js +59 -48
  8. package/dist/bin-lint-semver-ranges/lint-semver-ranges-cli.js +4 -4
  9. package/dist/bin-lint-semver-ranges/lint-semver-ranges.js +13 -35
  10. package/dist/bin-list/index.js +43 -46
  11. package/dist/bin-list/list-cli.js +4 -4
  12. package/dist/bin-list/list.js +26 -29
  13. package/dist/bin-list-mismatches/index.js +46 -47
  14. package/dist/bin-list-mismatches/list-mismatches-cli.js +4 -4
  15. package/dist/bin-list-mismatches/list-mismatches.js +55 -40
  16. package/dist/bin-set-semver-ranges/index.js +62 -49
  17. package/dist/bin-set-semver-ranges/set-semver-ranges-cli.js +4 -4
  18. package/dist/bin-set-semver-ranges/set-semver-ranges.js +4 -4
  19. package/dist/bin.js +8 -8
  20. package/dist/constants.d.ts +2 -1
  21. package/dist/constants.js +6 -5
  22. package/dist/get-context/$R.js +14 -36
  23. package/dist/get-context/get-config/get-core-types.js +11 -41
  24. package/dist/get-context/get-config/get-custom-types.js +7 -19
  25. package/dist/get-context/get-config/get-enabled-types.js +9 -11
  26. package/dist/get-context/get-config/index.d.ts +3 -1
  27. package/dist/get-context/get-config/index.js +37 -61
  28. package/dist/get-context/get-config/path-strategy/index.js +8 -8
  29. package/dist/get-context/get-config/path-strategy/lib/get-non-empty-string-prop.js +6 -6
  30. package/dist/get-context/get-config/path-strategy/name-and-version-props.js +23 -49
  31. package/dist/get-context/get-config/path-strategy/name-and-version-string.js +26 -42
  32. package/dist/get-context/get-config/path-strategy/types.js +1 -1
  33. package/dist/get-context/get-config/path-strategy/version-string.js +25 -41
  34. package/dist/get-context/get-config/path-strategy/versions-by-name.js +14 -30
  35. package/dist/get-context/get-config/schema/base-group.d.ts +2 -2
  36. package/dist/get-context/get-config/schema/base-group.js +5 -5
  37. package/dist/get-context/get-config/schema/index.d.ts +292 -164
  38. package/dist/get-context/get-config/schema/index.js +40 -63
  39. package/dist/get-context/get-config/schema/lib/non-empty-string.d.ts +2 -0
  40. package/dist/get-context/get-config/schema/lib/non-empty-string.js +5 -0
  41. package/dist/get-context/get-config/schema/paths.js +12 -12
  42. package/dist/get-context/get-config/schema/semver-group.d.ts +24 -24
  43. package/dist/get-context/get-config/schema/semver-group.js +11 -18
  44. package/dist/get-context/get-config/schema/semver-range.js +4 -4
  45. package/dist/get-context/get-config/schema/version-group.d.ts +90 -41
  46. package/dist/get-context/get-config/schema/version-group.js +28 -23
  47. package/dist/get-context/get-groups/base-group.d.ts +4 -1
  48. package/dist/get-context/get-groups/base-group.js +18 -19
  49. package/dist/get-context/get-groups/index.d.ts +7 -3
  50. package/dist/get-context/get-groups/index.js +42 -38
  51. package/dist/get-context/get-groups/semver-group.d.ts +0 -1
  52. package/dist/get-context/get-groups/semver-group.js +23 -66
  53. package/dist/get-context/get-groups/version-group/index.d.ts +7 -4
  54. package/dist/get-context/get-groups/version-group/index.js +31 -70
  55. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.d.ts +3 -1
  56. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +36 -45
  57. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.d.ts +3 -0
  58. package/dist/get-context/get-groups/version-group/instance-group/get-lowest-version.js +44 -0
  59. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +16 -5
  60. package/dist/get-context/get-groups/version-group/instance-group/index.js +66 -54
  61. package/dist/get-context/get-groups/version-group/instance-group/lib/clean.d.ts +2 -0
  62. package/dist/get-context/get-groups/version-group/instance-group/lib/clean.js +13 -0
  63. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +4 -0
  64. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +38 -0
  65. package/dist/get-context/get-groups/version-group/instance-group/lib/get-range-score.d.ts +2 -0
  66. package/dist/get-context/get-groups/version-group/instance-group/lib/get-range-score.js +23 -0
  67. package/dist/get-context/get-package-json-files/get-file-paths.js +18 -19
  68. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.js +9 -12
  69. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.js +9 -11
  70. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.js +10 -13
  71. package/dist/get-context/get-package-json-files/get-patterns/index.js +15 -42
  72. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.js +4 -6
  73. package/dist/get-context/get-package-json-files/get-patterns/props.js +9 -33
  74. package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.js +6 -9
  75. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.js +4 -4
  76. package/dist/get-context/get-package-json-files/index.d.ts +3 -1
  77. package/dist/get-context/get-package-json-files/index.js +8 -8
  78. package/dist/get-context/get-package-json-files/package-json-file/index.js +32 -55
  79. package/dist/get-context/get-package-json-files/package-json-file/instance.d.ts +2 -1
  80. package/dist/get-context/get-package-json-files/package-json-file/instance.js +15 -15
  81. package/dist/get-context/index.d.ts +3 -2
  82. package/dist/get-context/index.js +28 -24
  83. package/dist/lib/disk.js +28 -29
  84. package/dist/lib/error.js +13 -31
  85. package/dist/lib/exit-if-invalid.js +1 -1
  86. package/dist/lib/is-semver.d.ts +1 -1
  87. package/dist/lib/is-semver.js +15 -7
  88. package/dist/lib/log.js +38 -58
  89. package/dist/lib/newlines.js +11 -11
  90. package/dist/lib/print-strings.js +2 -2
  91. package/dist/lib/set-semver-range.js +8 -8
  92. package/dist/lib/show-help-on-error.js +31 -8
  93. package/dist/lib/sort-by-name.js +1 -1
  94. package/dist/lib/write-if-changed.js +3 -3
  95. package/dist/option.js +8 -13
  96. package/dist/types.d.ts +3 -1
  97. package/dist/types.js +1 -1
  98. package/package.json +20 -16
  99. package/dist/get-context/get-all-instances.d.ts +0 -3
  100. package/dist/get-context/get-all-instances.js +0 -8
@@ -1,11 +1,11 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.readYamlSafe = void 0;
4
- var ts_belt_1 = require("@mobily/ts-belt");
5
- var error_1 = require("../../../lib/error");
4
+ const ts_belt_1 = require("@mobily/ts-belt");
5
+ const error_1 = require("../../../lib/error");
6
6
  function readYamlSafe(disk) {
7
7
  return function readYamlSafe(filePath) {
8
- return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(function () { return disk.readYamlFileSync(filePath); }), ts_belt_1.R.mapError(error_1.BaseError.map("Failed to read YAML file at ".concat(filePath))));
8
+ return (0, ts_belt_1.pipe)(ts_belt_1.R.fromExecution(() => disk.readYamlFileSync(filePath)), ts_belt_1.R.mapError(error_1.BaseError.map(`Failed to read YAML file at ${filePath}`)));
9
9
  };
10
10
  }
11
11
  exports.readYamlSafe = readYamlSafe;
@@ -1,5 +1,7 @@
1
+ import { R } from '@mobily/ts-belt';
1
2
  import type { Disk } from '../../lib/disk';
3
+ import type { BaseError } from '../../lib/error';
2
4
  import type { Syncpack } from '../../types';
3
5
  import { PackageJsonFile } from './package-json-file';
4
6
  /** Create an API for every package.json file needed. */
5
- export declare function getPackageJsonFiles(disk: Disk, config: Syncpack.Config.Private): PackageJsonFile[];
7
+ export declare function getPackageJsonFiles(disk: Disk, config: Syncpack.Config.Private): R.Result<PackageJsonFile[], BaseError>;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getPackageJsonFiles = void 0;
4
- var ts_belt_1 = require("@mobily/ts-belt");
5
- var _R_1 = require("../$R");
6
- var get_file_paths_1 = require("./get-file-paths");
7
- var read_json_safe_1 = require("./get-patterns/read-json-safe");
8
- var package_json_file_1 = require("./package-json-file");
4
+ const ts_belt_1 = require("@mobily/ts-belt");
5
+ const _R_1 = require("../$R");
6
+ const get_file_paths_1 = require("./get-file-paths");
7
+ const read_json_safe_1 = require("./get-patterns/read-json-safe");
8
+ const package_json_file_1 = require("./package-json-file");
9
9
  /** Create an API for every package.json file needed. */
10
10
  function getPackageJsonFiles(disk, config) {
11
- return (0, ts_belt_1.pipe)((0, get_file_paths_1.getFilePaths)(disk, config), ts_belt_1.R.flatMap(_R_1.$R.onlyOk(resolvePackageJson(disk))), ts_belt_1.R.getWithDefault([]));
11
+ return (0, ts_belt_1.pipe)((0, get_file_paths_1.getFilePaths)(disk, config), ts_belt_1.R.flatMap(_R_1.$R.onlyOk(resolvePackageJson(disk))), ts_belt_1.R.recover([]));
12
12
  function resolvePackageJson(disk) {
13
- return (0, ts_belt_1.flow)((0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.map(function (jsonFile) { return new package_json_file_1.PackageJsonFile(jsonFile, config, disk); }));
13
+ return (0, ts_belt_1.flow)((0, read_json_safe_1.readJsonSafe)(disk), ts_belt_1.R.map((jsonFile) => new package_json_file_1.PackageJsonFile(jsonFile, config, disk)), _R_1.$R.tapErrVerbose);
14
14
  }
15
15
  }
16
16
  exports.getPackageJsonFiles = getPackageJsonFiles;
@@ -1,31 +1,15 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
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
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
19
3
  exports.PackageJsonFile = void 0;
20
- var ts_belt_1 = require("@mobily/ts-belt");
21
- var path_1 = require("path");
22
- var constants_1 = require("../../../constants");
23
- var log_1 = require("../../../lib/log");
24
- var newlines_1 = require("../../../lib/newlines");
25
- var path_strategy_1 = require("../../get-config/path-strategy");
26
- var instance_1 = require("./instance");
27
- var PackageJsonFile = /** @class */ (function () {
28
- function PackageJsonFile(jsonFile, config, disk) {
4
+ const ts_belt_1 = require("@mobily/ts-belt");
5
+ const path_1 = require("path");
6
+ const constants_1 = require("../../../constants");
7
+ const log_1 = require("../../../lib/log");
8
+ const newlines_1 = require("../../../lib/newlines");
9
+ const path_strategy_1 = require("../../get-config/path-strategy");
10
+ const instance_1 = require("./instance");
11
+ class PackageJsonFile {
12
+ constructor(jsonFile, config, disk) {
29
13
  this.contents = jsonFile.contents;
30
14
  this.disk = disk;
31
15
  this.filePath = jsonFile.filePath;
@@ -33,41 +17,35 @@ var PackageJsonFile = /** @class */ (function () {
33
17
  this.config = config;
34
18
  this.shortPath = (0, path_1.relative)(constants_1.CWD, jsonFile.filePath);
35
19
  }
36
- PackageJsonFile.prototype.hasChanged = function () {
20
+ hasChanged() {
37
21
  return this.json !== this.getSource();
38
- };
39
- PackageJsonFile.prototype.write = function () {
22
+ }
23
+ write() {
40
24
  this.disk.writeFileSync(this.filePath, this.getSource());
41
- };
42
- PackageJsonFile.prototype.getSource = function () {
43
- var contents = this.contents;
44
- var indent = this.config.indent;
45
- var EOL = newlines_1.newlines.detect(this.json);
46
- var source = "".concat(JSON.stringify(contents, null, indent)).concat(EOL);
25
+ }
26
+ getSource() {
27
+ const contents = this.contents;
28
+ const indent = this.config.indent;
29
+ const EOL = newlines_1.newlines.detect(this.json);
30
+ const source = `${JSON.stringify(contents, null, indent)}${EOL}`;
47
31
  return newlines_1.newlines.fix(source, EOL);
48
- };
49
- PackageJsonFile.prototype.getInstances = function () {
50
- var _this = this;
32
+ }
33
+ getInstances() {
51
34
  return this.config.enabledTypes
52
- .flatMap(function (pathDef) {
53
- return _this.getPathEntries(pathDef, _this).map(function (_a) {
54
- var _b = __read(_a, 2), name = _b[0], version = _b[1];
55
- return new instance_1.Instance(pathDef, name, _this, version);
56
- });
57
- })
58
- .filter(function (instance) {
59
- var pathDef = instance.pathDef, name = instance.name, version = instance.version;
60
- var filter = _this.config.filter;
35
+ .flatMap((pathDef) => this.getPathEntries(pathDef, this).map(([name, version]) => new instance_1.Instance(pathDef, name, this, version)))
36
+ .filter((instance) => {
37
+ const { pathDef, name, version } = instance;
38
+ const filter = this.config.filter;
61
39
  if (name.search(new RegExp(filter)) === -1) {
62
- (0, log_1.verbose)("skip, name \"".concat(name, "\" does not match filter \"").concat(filter, "\""));
40
+ (0, log_1.verbose)(`skip, name "${name}" does not match filter "${filter}"`);
63
41
  return false;
64
42
  }
65
- (0, log_1.verbose)("add ".concat(name, "@").concat(version, " to ").concat(pathDef.name, ":").concat(pathDef.strategy, " ").concat(_this.shortPath));
43
+ (0, log_1.verbose)(`add ${name}@${version} to ${pathDef.name}:${pathDef.strategy} ${this.shortPath}`);
66
44
  return true;
67
45
  });
68
- };
69
- PackageJsonFile.prototype.getPathEntries = function (pathDef, file) {
70
- var strategyName = pathDef.strategy;
46
+ }
47
+ getPathEntries(pathDef, file) {
48
+ const strategyName = pathDef.strategy;
71
49
  switch (strategyName) {
72
50
  case 'name@version':
73
51
  return (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].read(file, pathDef), ts_belt_1.R.getWithDefault([]));
@@ -80,7 +58,6 @@ var PackageJsonFile = /** @class */ (function () {
80
58
  default:
81
59
  return (0, path_strategy_1.exhaustiveCheck)(strategyName);
82
60
  }
83
- };
84
- return PackageJsonFile;
85
- }());
61
+ }
62
+ }
86
63
  exports.PackageJsonFile = PackageJsonFile;
@@ -1,5 +1,6 @@
1
1
  import type { PackageJsonFile } from '.';
2
2
  import type { Syncpack } from '../../../types';
3
+ import type { Delete } from '../../get-groups/version-group/instance-group';
3
4
  export declare class Instance {
4
5
  /** the name of this dependency */
5
6
  name: string;
@@ -18,5 +19,5 @@ export declare class Instance {
18
19
  * In the case of banned dependencies, their version is set to `undefined`,
19
20
  * which causes them to be removed by `JSON.stringify`.
20
21
  */
21
- setVersion(version: string | undefined): void;
22
+ setVersion(version: string | Delete): void;
22
23
  }
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Instance = void 0;
4
- var ts_belt_1 = require("@mobily/ts-belt");
5
- var _R_1 = require("../../$R");
6
- var path_strategy_1 = require("../../get-config/path-strategy");
7
- var Instance = /** @class */ (function () {
8
- function Instance(pathDef, name, packageJsonFile, version) {
4
+ const ts_belt_1 = require("@mobily/ts-belt");
5
+ const _R_1 = require("../../$R");
6
+ const path_strategy_1 = require("../../get-config/path-strategy");
7
+ const instance_group_1 = require("../../get-groups/version-group/instance-group");
8
+ class Instance {
9
+ constructor(pathDef, name, packageJsonFile, version) {
9
10
  this.pathDef = pathDef;
10
11
  this.name = name;
11
12
  this.packageJsonFile = packageJsonFile;
@@ -13,17 +14,17 @@ var Instance = /** @class */ (function () {
13
14
  this.version = version;
14
15
  }
15
16
  /** Is this instance the package.json file of this package developed in this repo? */
16
- Instance.prototype.isWorkspace = function () {
17
+ isWorkspace() {
17
18
  return this.pathDef.name === 'workspace';
18
- };
19
+ }
19
20
  /**
20
21
  * In the case of banned dependencies, their version is set to `undefined`,
21
22
  * which causes them to be removed by `JSON.stringify`.
22
23
  */
23
- Instance.prototype.setVersion = function (version) {
24
- var strategyName = this.pathDef.strategy;
25
- var entry = [this.name, version];
26
- var file = this.packageJsonFile;
24
+ setVersion(version) {
25
+ const strategyName = this.pathDef.strategy;
26
+ const entry = [this.name, version === instance_group_1.DELETE ? undefined : version];
27
+ const file = this.packageJsonFile;
27
28
  switch (strategyName) {
28
29
  case 'name@version':
29
30
  (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
@@ -40,7 +41,6 @@ var Instance = /** @class */ (function () {
40
41
  default:
41
42
  return (0, path_strategy_1.exhaustiveCheck)(strategyName);
42
43
  }
43
- };
44
- return Instance;
45
- }());
44
+ }
45
+ }
46
46
  exports.Instance = Instance;
@@ -3,13 +3,14 @@ import type { Syncpack } from '../types';
3
3
  import type { SemverGroup } from './get-groups/semver-group';
4
4
  import type { VersionGroup } from './get-groups/version-group';
5
5
  import type { PackageJsonFile } from './get-package-json-files/package-json-file';
6
- export type Context = Omit<Syncpack.Config.Private, 'semverGroups' | 'versionGroups'> & {
6
+ export interface Context {
7
+ config: Syncpack.Config.Private;
7
8
  disk: Disk;
8
9
  isInvalid: boolean;
9
10
  packageJsonFiles: PackageJsonFile[];
10
11
  semverGroups: SemverGroup[];
11
12
  versionGroups: VersionGroup[];
12
- };
13
+ }
13
14
  /**
14
15
  * Every command in syncpack should accept the return value of this function as
15
16
  * its input.
@@ -1,22 +1,12 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.getContext = void 0;
15
- var disk_1 = require("../lib/disk");
16
- var get_all_instances_1 = require("./get-all-instances");
17
- var get_config_1 = require("./get-config");
18
- var get_groups_1 = require("./get-groups");
19
- var get_package_json_files_1 = require("./get-package-json-files");
4
+ const ts_belt_1 = require("@mobily/ts-belt");
5
+ const disk_1 = require("../lib/disk");
6
+ const _R_1 = require("./$R");
7
+ const get_config_1 = require("./get-config");
8
+ const get_groups_1 = require("./get-groups");
9
+ const get_package_json_files_1 = require("./get-package-json-files");
20
10
  /**
21
11
  * Every command in syncpack should accept the return value of this function as
22
12
  * its input.
@@ -25,12 +15,26 @@ var get_package_json_files_1 = require("./get-package-json-files");
25
15
  * that the majority of syncpack and its tests don't have to deal with the file
26
16
  * system and can focus solely on transformation logic.
27
17
  */
28
- function getContext(program, disk) {
29
- if (disk === void 0) { disk = disk_1.disk; }
30
- var config = (0, get_config_1.getConfig)(disk, program);
31
- var packageJsonFiles = (0, get_package_json_files_1.getPackageJsonFiles)(disk, config);
32
- var instances = (0, get_all_instances_1.getAllInstances)(packageJsonFiles);
33
- var _a = (0, get_groups_1.getGroups)(config, instances), semverGroups = _a.semverGroups, versionGroups = _a.versionGroups;
34
- return __assign(__assign({}, config), { disk: disk, isInvalid: false, packageJsonFiles: packageJsonFiles, semverGroups: semverGroups, versionGroups: versionGroups });
18
+ function getContext(program, disk = disk_1.disk) {
19
+ return (0, ts_belt_1.pipe)(
20
+ // merge CLI options, .syncpackrc contents, and default config
21
+ (0, get_config_1.getConfig)(disk, program), ts_belt_1.R.flatMap((config) => (0, ts_belt_1.pipe)(
22
+ // get the package.json file which match the globs in config
23
+ (0, get_package_json_files_1.getPackageJsonFiles)(disk, config), ts_belt_1.R.flatMap((packageJsonFiles) => (0, ts_belt_1.pipe)(
24
+ // allocate dependencies into semver and version groups
25
+ (0, get_groups_1.getGroups)(config, packageJsonFiles),
26
+ // combine everything into the final config
27
+ ts_belt_1.R.map(({ semverGroups, versionGroups }) => ({
28
+ config,
29
+ disk,
30
+ isInvalid: false,
31
+ packageJsonFiles,
32
+ semverGroups,
33
+ versionGroups,
34
+ })))))),
35
+ // if anything errored at any stage, log it when in verbose mode
36
+ _R_1.$R.tapErrVerbose,
37
+ // throw if anything errored, can't do anything without this data
38
+ ts_belt_1.R.getExn);
35
39
  }
36
40
  exports.getContext = getContext;
package/dist/lib/disk.js CHANGED
@@ -1,46 +1,45 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.disk = void 0;
4
- var cosmiconfig_1 = require("cosmiconfig");
5
- var expect_more_1 = require("expect-more");
6
- var fs_extra_1 = require("fs-extra");
7
- var glob_1 = require("glob");
8
- var path_1 = require("path");
9
- var read_yaml_file_1 = require("read-yaml-file");
10
- var constants_1 = require("../constants");
11
- var log_1 = require("./log");
12
- var client = (0, cosmiconfig_1.cosmiconfigSync)('syncpack');
4
+ const cosmiconfig_1 = require("cosmiconfig");
5
+ const is_non_empty_object_1 = require("expect-more/dist/is-non-empty-object");
6
+ const fs_extra_1 = require("fs-extra");
7
+ const glob_1 = require("glob");
8
+ const path_1 = require("path");
9
+ const read_yaml_file_1 = require("read-yaml-file");
10
+ const constants_1 = require("../constants");
11
+ const log_1 = require("./log");
12
+ const client = (0, cosmiconfig_1.cosmiconfigSync)('syncpack');
13
13
  exports.disk = {
14
14
  process: {
15
- exit: function (code) {
15
+ exit(code) {
16
16
  (0, log_1.verbose)('exit(', code, ')');
17
17
  process.exit(code);
18
- }
18
+ },
19
19
  },
20
- globSync: function (pattern) {
20
+ globSync(pattern) {
21
21
  (0, log_1.verbose)('globSync(', pattern, ')');
22
22
  return (0, glob_1.sync)(pattern, {
23
23
  ignore: '**/node_modules/**',
24
24
  absolute: true,
25
- cwd: constants_1.CWD
25
+ cwd: constants_1.CWD,
26
26
  });
27
27
  },
28
- readConfigFileSync: function (configPath) {
29
- var _a;
28
+ readConfigFileSync(configPath) {
30
29
  (0, log_1.verbose)('readConfigFileSync(', configPath, ')');
31
30
  try {
32
- var result = configPath ? client.load(configPath) : client.search();
31
+ const result = configPath ? client.load(configPath) : client.search();
33
32
  if (result === null) {
34
- var rcPath_1 = (0, path_1.join)(constants_1.CWD, 'package.json');
35
- var pjson = (0, fs_extra_1.readJsonSync)(rcPath_1, { throws: false });
36
- var rcConfig_1 = (_a = pjson === null || pjson === void 0 ? void 0 : pjson.config) === null || _a === void 0 ? void 0 : _a.syncpack;
37
- if ((0, expect_more_1.isNonEmptyObject)(rcConfig_1))
38
- return rcConfig_1;
33
+ const rcPath = (0, path_1.join)(constants_1.CWD, 'package.json');
34
+ const pjson = (0, fs_extra_1.readJsonSync)(rcPath, { throws: false });
35
+ const rcConfig = pjson?.config?.syncpack;
36
+ if ((0, is_non_empty_object_1.isNonEmptyObject)(rcConfig))
37
+ return rcConfig;
39
38
  (0, log_1.verbose)('no config file found');
40
39
  return {};
41
40
  }
42
- var rcPath = result.filepath;
43
- var rcConfig = result.config;
41
+ const rcPath = result.filepath;
42
+ const rcConfig = result.config;
44
43
  (0, log_1.verbose)('.syncpackrc path:', rcPath);
45
44
  (0, log_1.verbose)('.syncpackrc contents:', rcConfig);
46
45
  return rcConfig;
@@ -50,20 +49,20 @@ exports.disk = {
50
49
  return {};
51
50
  }
52
51
  },
53
- readFileSync: function (filePath) {
52
+ readFileSync(filePath) {
54
53
  (0, log_1.verbose)('readFileSync(', filePath, ')');
55
54
  return (0, fs_extra_1.readFileSync)(filePath, { encoding: 'utf8' });
56
55
  },
57
- readYamlFileSync: function (filePath) {
56
+ readYamlFileSync(filePath) {
58
57
  (0, log_1.verbose)('readYamlFileSync(', filePath, ')');
59
58
  return (0, read_yaml_file_1.sync)(filePath);
60
59
  },
61
- removeSync: function (filePath) {
60
+ removeSync(filePath) {
62
61
  (0, log_1.verbose)('removeSync(', filePath, ')');
63
62
  (0, fs_extra_1.removeSync)(filePath);
64
63
  },
65
- writeFileSync: function (filePath, contents) {
64
+ writeFileSync(filePath, contents) {
66
65
  (0, log_1.verbose)('writeFileSync(', filePath, contents, ')');
67
66
  (0, fs_extra_1.writeFileSync)(filePath, contents);
68
- }
67
+ },
69
68
  };
package/dist/lib/error.js CHANGED
@@ -1,30 +1,13 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.BaseError = void 0;
19
- var BaseError = /** @class */ (function (_super) {
20
- __extends(BaseError, _super);
21
- function BaseError(message, options) {
22
- var _this = _super.call(this, message) || this;
23
- _this.name = 'SyncpackError';
24
- _this.cause = BaseError.normalize(options === null || options === void 0 ? void 0 : options.cause);
25
- return _this;
4
+ class BaseError extends Error {
5
+ constructor(message, options) {
6
+ super(message);
7
+ this.name = 'SyncpackError';
8
+ this.cause = BaseError.normalize(options?.cause);
26
9
  }
27
- BaseError.normalize = function (value) {
10
+ static normalize(value) {
28
11
  if (value instanceof BaseError)
29
12
  return value;
30
13
  if (value instanceof Error)
@@ -32,12 +15,11 @@ var BaseError = /** @class */ (function (_super) {
32
15
  if (typeof value === 'string')
33
16
  return new Error(value);
34
17
  return null;
35
- };
36
- BaseError.map = function (message) {
37
- return function (cause) {
38
- return new BaseError(message, { cause: cause });
18
+ }
19
+ static map(message) {
20
+ return (cause) => {
21
+ return new BaseError(message, { cause });
39
22
  };
40
- };
41
- return BaseError;
42
- }(Error));
23
+ }
24
+ }
43
25
  exports.BaseError = BaseError;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.exitIfInvalid = void 0;
4
4
  function exitIfInvalid(ctx) {
5
5
  if (ctx.isInvalid) {
@@ -1,4 +1,4 @@
1
1
  import type { Syncpack } from '../types';
2
2
  export declare function isValidSemverRange(value: unknown): value is Syncpack.Config.SemverRange.Value;
3
- export declare function isSemver(version: unknown): boolean;
3
+ export declare function isSemver(version: unknown): version is string;
4
4
  export declare function isLooseSemver(version: unknown): boolean;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isLooseSemver = exports.isSemver = exports.isValidSemverRange = void 0;
4
- var expect_more_1 = require("expect-more");
5
- var constants_1 = require("../constants");
4
+ const is_string_1 = require("expect-more/dist/is-string");
5
+ const constants_1 = require("../constants");
6
6
  function isValidSemverRange(value) {
7
7
  return (value === constants_1.RANGE.ANY ||
8
8
  value === constants_1.RANGE.EXACT ||
@@ -16,12 +16,20 @@ function isValidSemverRange(value) {
16
16
  }
17
17
  exports.isValidSemverRange = isValidSemverRange;
18
18
  function isSemver(version) {
19
- return ((0, expect_more_1.isString)(version) &&
20
- version.search(/^(~|\^|>=|>|<=|<|)?[0-9]+\.[0-9x]+\.[0-9x]+/) !== -1 &&
21
- version.indexOf(' ') === -1);
19
+ const range = '(~|\\^|>=|>|<=|<)?';
20
+ const ints = '[0-9]+';
21
+ const intsOrX = '([0-9]+|x)';
22
+ const dot = '\\.';
23
+ const major = new RegExp(`^${range}${ints}$`);
24
+ const minor = new RegExp(`^${range}${ints}${dot}${intsOrX}$`);
25
+ const patch = new RegExp(`^${range}${ints}${dot}${intsOrX}${dot}${intsOrX}$`);
26
+ return ((0, is_string_1.isString)(version) &&
27
+ (version.search(major) !== -1 ||
28
+ version.search(minor) !== -1 ||
29
+ version.search(patch) !== -1));
22
30
  }
23
31
  exports.isSemver = isSemver;
24
32
  function isLooseSemver(version) {
25
- return ((0, expect_more_1.isString)(version) && isSemver(version) && version.search(/\.x(\.|$)/) !== -1);
33
+ return isSemver(version) && version.search(/\.x(\.|$)/) !== -1;
26
34
  }
27
35
  exports.isLooseSemver = isLooseSemver;