syncpack 9.1.2 → 9.7.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 (92) hide show
  1. package/dist/bin-fix-mismatches/fix-mismatches-cli.js +4 -4
  2. package/dist/bin-fix-mismatches/fix-mismatches.js +14 -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 +19 -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 +15 -37
  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 +51 -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-all-instances.js +3 -3
  24. package/dist/get-context/get-config/get-core-types.js +11 -41
  25. package/dist/get-context/get-config/get-custom-types.js +7 -19
  26. package/dist/get-context/get-config/get-enabled-types.js +9 -11
  27. package/dist/get-context/get-config/index.js +29 -59
  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 -1
  36. package/dist/get-context/get-config/schema/base-group.js +5 -4
  37. package/dist/get-context/get-config/schema/index.d.ts +374 -148
  38. package/dist/get-context/get-config/schema/index.js +40 -63
  39. package/dist/get-context/get-config/schema/paths.js +12 -12
  40. package/dist/get-context/get-config/schema/semver-group.d.ts +42 -24
  41. package/dist/get-context/get-config/schema/semver-group.js +11 -18
  42. package/dist/get-context/get-config/schema/semver-range.js +4 -4
  43. package/dist/get-context/get-config/schema/version-group.d.ts +91 -24
  44. package/dist/get-context/get-config/schema/version-group.js +20 -21
  45. package/dist/get-context/get-groups/base-group.d.ts +4 -1
  46. package/dist/get-context/get-groups/base-group.js +18 -19
  47. package/dist/get-context/get-groups/index.d.ts +2 -1
  48. package/dist/get-context/get-groups/index.js +31 -37
  49. package/dist/get-context/get-groups/semver-group.d.ts +0 -1
  50. package/dist/get-context/get-groups/semver-group.js +23 -66
  51. package/dist/get-context/get-groups/version-group/index.d.ts +2 -1
  52. package/dist/get-context/get-groups/version-group/index.js +29 -68
  53. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.d.ts +3 -1
  54. package/dist/get-context/get-groups/version-group/instance-group/get-highest-version.js +36 -45
  55. package/dist/get-context/get-groups/version-group/instance-group/index.d.ts +2 -1
  56. package/dist/get-context/get-groups/version-group/instance-group/index.js +55 -47
  57. package/dist/get-context/get-groups/version-group/instance-group/lib/clean.d.ts +2 -0
  58. package/dist/get-context/get-groups/version-group/instance-group/lib/clean.js +13 -0
  59. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.d.ts +2 -0
  60. package/dist/get-context/get-groups/version-group/instance-group/lib/compare-semver.js +22 -0
  61. package/dist/get-context/get-groups/version-group/instance-group/lib/get-range-score.d.ts +2 -0
  62. package/dist/get-context/get-groups/version-group/instance-group/lib/get-range-score.js +23 -0
  63. package/dist/get-context/get-package-json-files/get-file-paths.js +18 -19
  64. package/dist/get-context/get-package-json-files/get-patterns/get-lerna-patterns.js +9 -12
  65. package/dist/get-context/get-package-json-files/get-patterns/get-pnpm-patterns.js +9 -11
  66. package/dist/get-context/get-package-json-files/get-patterns/get-yarn-patterns.js +10 -13
  67. package/dist/get-context/get-package-json-files/get-patterns/index.js +15 -42
  68. package/dist/get-context/get-package-json-files/get-patterns/lib/get-array-of-strings.js +4 -6
  69. package/dist/get-context/get-package-json-files/get-patterns/props.js +9 -33
  70. package/dist/get-context/get-package-json-files/get-patterns/read-json-safe.js +6 -9
  71. package/dist/get-context/get-package-json-files/get-patterns/read-yaml-safe.js +4 -4
  72. package/dist/get-context/get-package-json-files/index.js +7 -7
  73. package/dist/get-context/get-package-json-files/package-json-file/index.js +32 -55
  74. package/dist/get-context/get-package-json-files/package-json-file/instance.js +14 -15
  75. package/dist/get-context/index.js +19 -24
  76. package/dist/lib/disk.js +28 -29
  77. package/dist/lib/error.js +13 -31
  78. package/dist/lib/exit-if-invalid.js +1 -1
  79. package/dist/lib/is-semver.d.ts +1 -1
  80. package/dist/lib/is-semver.js +15 -7
  81. package/dist/lib/log.d.ts +4 -2
  82. package/dist/lib/log.js +44 -60
  83. package/dist/lib/newlines.js +11 -11
  84. package/dist/lib/print-strings.js +2 -2
  85. package/dist/lib/set-semver-range.js +8 -8
  86. package/dist/lib/show-help-on-error.js +31 -8
  87. package/dist/lib/sort-by-name.js +1 -1
  88. package/dist/lib/write-if-changed.js +3 -3
  89. package/dist/option.js +8 -13
  90. package/dist/types.d.ts +2 -0
  91. package/dist/types.js +1 -1
  92. package/package.json +20 -16
@@ -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,11 +1,11 @@
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
+ class Instance {
8
+ constructor(pathDef, name, packageJsonFile, version) {
9
9
  this.pathDef = pathDef;
10
10
  this.name = name;
11
11
  this.packageJsonFile = packageJsonFile;
@@ -13,17 +13,17 @@ var Instance = /** @class */ (function () {
13
13
  this.version = version;
14
14
  }
15
15
  /** Is this instance the package.json file of this package developed in this repo? */
16
- Instance.prototype.isWorkspace = function () {
16
+ isWorkspace() {
17
17
  return this.pathDef.name === 'workspace';
18
- };
18
+ }
19
19
  /**
20
20
  * In the case of banned dependencies, their version is set to `undefined`,
21
21
  * which causes them to be removed by `JSON.stringify`.
22
22
  */
23
- Instance.prototype.setVersion = function (version) {
24
- var strategyName = this.pathDef.strategy;
25
- var entry = [this.name, version];
26
- var file = this.packageJsonFile;
23
+ setVersion(version) {
24
+ const strategyName = this.pathDef.strategy;
25
+ const entry = [this.name, version];
26
+ const file = this.packageJsonFile;
27
27
  switch (strategyName) {
28
28
  case 'name@version':
29
29
  (0, ts_belt_1.pipe)(path_strategy_1.strategyByName[strategyName].write(file, this.pathDef, entry), _R_1.$R.tapErrVerbose);
@@ -40,7 +40,6 @@ var Instance = /** @class */ (function () {
40
40
  default:
41
41
  return (0, path_strategy_1.exhaustiveCheck)(strategyName);
42
42
  }
43
- };
44
- return Instance;
45
- }());
43
+ }
44
+ }
46
45
  exports.Instance = Instance;
@@ -1,22 +1,11 @@
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 disk_1 = require("../lib/disk");
5
+ const get_all_instances_1 = require("./get-all-instances");
6
+ const get_config_1 = require("./get-config");
7
+ const get_groups_1 = require("./get-groups");
8
+ const get_package_json_files_1 = require("./get-package-json-files");
20
9
  /**
21
10
  * Every command in syncpack should accept the return value of this function as
22
11
  * its input.
@@ -25,12 +14,18 @@ var get_package_json_files_1 = require("./get-package-json-files");
25
14
  * that the majority of syncpack and its tests don't have to deal with the file
26
15
  * system and can focus solely on transformation logic.
27
16
  */
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 });
17
+ function getContext(program, disk = disk_1.disk) {
18
+ const config = (0, get_config_1.getConfig)(disk, program);
19
+ const packageJsonFiles = (0, get_package_json_files_1.getPackageJsonFiles)(disk, config);
20
+ const instances = (0, get_all_instances_1.getAllInstances)(packageJsonFiles);
21
+ const groups = (0, get_groups_1.getGroups)(config, instances, packageJsonFiles);
22
+ return {
23
+ ...config,
24
+ disk,
25
+ isInvalid: false,
26
+ packageJsonFiles,
27
+ semverGroups: groups.semverGroups,
28
+ versionGroups: groups.versionGroups,
29
+ };
35
30
  }
36
31
  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;
package/dist/lib/log.d.ts CHANGED
@@ -1,7 +1,9 @@
1
+ import type { SemverGroup } from '../get-context/get-groups/semver-group';
2
+ import type { VersionGroup } from '../get-context/get-groups/version-group';
1
3
  export declare function verbose(...values: unknown[]): void;
2
4
  export declare function fixed(message: string): void;
3
5
  export declare function skip(message: string): void;
4
- export declare function semverGroupHeader(order: number): void;
5
- export declare function versionGroupHeader(order: number): void;
6
6
  export declare function valid(message: string, comment?: string): void;
7
7
  export declare function invalid(message: string, comment?: string): void;
8
+ export declare function semverGroupHeader(group: SemverGroup, i: number): void;
9
+ export declare function versionGroupHeader(group: VersionGroup, i: number): void;
package/dist/lib/log.js CHANGED
@@ -1,88 +1,72 @@
1
1
  "use strict";
2
- var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3
- if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4
- return cooked;
5
- };
6
- var __read = (this && this.__read) || function (o, n) {
7
- var m = typeof Symbol === "function" && o[Symbol.iterator];
8
- if (!m) return o;
9
- var i = m.call(o), r, ar = [], e;
10
- try {
11
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
12
- }
13
- catch (error) { e = { error: error }; }
14
- finally {
15
- try {
16
- if (r && !r.done && (m = i["return"])) m.call(i);
17
- }
18
- finally { if (e) throw e.error; }
19
- }
20
- return ar;
21
- };
22
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
23
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
24
- if (ar || !(i in from)) {
25
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
26
- ar[i] = from[i];
27
- }
28
- }
29
- return to.concat(ar || Array.prototype.slice.call(from));
30
- };
31
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
32
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
33
4
  };
34
- exports.__esModule = true;
35
- exports.invalid = exports.valid = exports.versionGroupHeader = exports.semverGroupHeader = exports.skip = exports.fixed = exports.verbose = void 0;
36
- var chalk_1 = __importDefault(require("chalk"));
37
- var expect_more_1 = require("expect-more");
38
- var util_1 = require("util");
39
- var constants_1 = require("../constants");
40
- function verbose() {
41
- var values = [];
42
- for (var _i = 0; _i < arguments.length; _i++) {
43
- values[_i] = arguments[_i];
44
- }
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.versionGroupHeader = exports.semverGroupHeader = exports.invalid = exports.valid = exports.skip = exports.fixed = exports.verbose = void 0;
7
+ const chalk_1 = __importDefault(require("chalk"));
8
+ const is_string_1 = require("expect-more/dist/is-string");
9
+ const util_1 = require("util");
10
+ const constants_1 = require("../constants");
11
+ function verbose(...values) {
12
+ /* istanbul ignore if */
45
13
  if (process.env.SYNCPACK_VERBOSE) {
46
- console.info.apply(console, __spreadArray([chalk_1["default"].yellow(constants_1.ICON.debug)], __read(values.map(function (value) {
47
- return (0, expect_more_1.isString)(value)
48
- ? chalk_1["default"].yellow(value)
49
- : (0, util_1.inspect)(value, false, null, true);
50
- })), false));
14
+ console.info(chalk_1.default.yellow(constants_1.ICON.debug), ...values.map((value) => (0, is_string_1.isString)(value)
15
+ ? chalk_1.default.yellow(value)
16
+ : (0, util_1.inspect)(value, { showHidden: false, colors: true, depth: 20 })));
51
17
  }
52
18
  }
53
19
  exports.verbose = verbose;
54
20
  function fixed(message) {
55
- console.log((0, chalk_1["default"])(templateObject_1 || (templateObject_1 = __makeTemplateObject(["{green ", "}"], ["{green ", "}"])), constants_1.ICON.tick), message);
21
+ console.log((0, chalk_1.default) `{green ${constants_1.ICON.tick}}`, message);
56
22
  }
57
23
  exports.fixed = fixed;
58
24
  function skip(message) {
59
- console.log(chalk_1["default"].dim(constants_1.ICON.skip), chalk_1["default"].dim(message));
25
+ console.log(chalk_1.default.dim(constants_1.ICON.skip), chalk_1.default.dim(message));
60
26
  }
61
27
  exports.skip = skip;
62
- function semverGroupHeader(order) {
63
- console.log((0, chalk_1["default"])(templateObject_2 || (templateObject_2 = __makeTemplateObject(["{dim = Semver Group ", " ", "}"], ["{dim = Semver Group ", " ", "}"])), order, '='.repeat(63)));
64
- }
65
- exports.semverGroupHeader = semverGroupHeader;
66
- function versionGroupHeader(order) {
67
- console.log((0, chalk_1["default"])(templateObject_3 || (templateObject_3 = __makeTemplateObject(["{dim = Version Group ", " ", "}"], ["{dim = Version Group ", " ", "}"])), order, '='.repeat(63)));
68
- }
69
- exports.versionGroupHeader = versionGroupHeader;
70
28
  function valid(message, comment) {
71
29
  if (comment) {
72
- console.log((0, chalk_1["default"])(templateObject_4 || (templateObject_4 = __makeTemplateObject(["{dim ", "} ", " {dim ", "}"], ["{dim ", "} ", " {dim ", "}"])), constants_1.ICON.skip, message, comment));
30
+ console.log((0, chalk_1.default) `{dim ${constants_1.ICON.skip}} ${message} {dim ${comment}}`);
73
31
  }
74
32
  else {
75
- console.log((0, chalk_1["default"])(templateObject_5 || (templateObject_5 = __makeTemplateObject(["{dim ", "} ", ""], ["{dim ", "} ", ""])), constants_1.ICON.skip, message));
33
+ console.log((0, chalk_1.default) `{dim ${constants_1.ICON.skip}} ${message}`);
76
34
  }
77
35
  }
78
36
  exports.valid = valid;
79
37
  function invalid(message, comment) {
80
38
  if (comment) {
81
- console.log((0, chalk_1["default"])(templateObject_6 || (templateObject_6 = __makeTemplateObject(["{red ", "} ", " {dim ", "}"], ["{red ", "} ", " {dim ", "}"])), constants_1.ICON.cross, message, comment));
39
+ console.log((0, chalk_1.default) `{red ${constants_1.ICON.cross}} ${message} {dim ${comment}}`);
82
40
  }
83
41
  else {
84
- console.log((0, chalk_1["default"])(templateObject_7 || (templateObject_7 = __makeTemplateObject(["{red ", "} ", ""], ["{red ", "} ", ""])), constants_1.ICON.cross, message));
42
+ console.log((0, chalk_1.default) `{red ${constants_1.ICON.cross}} ${message}`);
85
43
  }
86
44
  }
87
45
  exports.invalid = invalid;
88
- var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7;
46
+ function semverGroupHeader(group, i) {
47
+ logHeader(group, 'Semver', i);
48
+ }
49
+ exports.semverGroupHeader = semverGroupHeader;
50
+ function versionGroupHeader(group, i) {
51
+ logHeader(group, 'Version', i);
52
+ }
53
+ exports.versionGroupHeader = versionGroupHeader;
54
+ function logHeader(group, type, i) {
55
+ const customLabel = group.groupConfig.label;
56
+ const labelWhenDefault = group.isDefault ? `Default ${type} Group` : '';
57
+ const anonymousLabel = `${type} Group ${i + 1}`;
58
+ const label = (customLabel || labelWhenDefault || anonymousLabel).trim();
59
+ const hasNewLines = label.search(/[\r\n]/) !== -1;
60
+ const header = hasNewLines ? formatMultiLine(label) : formatSingleLine(label);
61
+ console.log(chalk_1.default.blue(header));
62
+ }
63
+ function formatSingleLine(label) {
64
+ const leftSide = `= ${label} `;
65
+ const dividerWidth = 80 - leftSide.length;
66
+ const rightSide = dividerWidth > 0 ? '='.repeat(dividerWidth) : '';
67
+ return `${leftSide}${rightSide}`;
68
+ }
69
+ function formatMultiLine(label) {
70
+ const reindented = label.replace(/^\s+/gm, ' ');
71
+ return `= ${reindented}`;
72
+ }
@@ -1,15 +1,15 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.newlines = void 0;
4
- var os_1 = require("os");
5
- var CR = '\r';
6
- var CRLF = '\r\n';
7
- var LF = '\n';
4
+ const os_1 = require("os");
5
+ const CR = '\r';
6
+ const CRLF = '\r\n';
7
+ const LF = '\n';
8
8
  exports.newlines = {
9
- detect: function (source) {
10
- var cr = source.split(CR).length;
11
- var lf = source.split(LF).length;
12
- var crlf = source.split(CRLF).length;
9
+ detect(source) {
10
+ const cr = source.split(CR).length;
11
+ const lf = source.split(LF).length;
12
+ const crlf = source.split(CRLF).length;
13
13
  if (cr + lf === 0)
14
14
  return os_1.EOL;
15
15
  if (crlf === cr && crlf === lf)
@@ -18,7 +18,7 @@ exports.newlines = {
18
18
  return CR;
19
19
  return LF;
20
20
  },
21
- fix: function (source, lineEnding) {
21
+ fix(source, lineEnding) {
22
22
  return source.replace(/\r\n|\n|\r/g, lineEnding);
23
- }
23
+ },
24
24
  };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.printStrings = void 0;
4
4
  function printStrings(strings) {
5
- return strings.map(function (str) { return "\"".concat(str, "\""); }).join(', ');
5
+ return strings.map((str) => `"${str}"`).join(', ');
6
6
  }
7
7
  exports.printStrings = printStrings;