@bemoje/cli 4.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.cjs CHANGED
@@ -118,9 +118,7 @@ __name(valuesOf, "valuesOf");
118
118
 
119
119
  // src/lib/helpers/findCommand.ts
120
120
  function findCommand(cmd, nameOrAlias) {
121
- return cmd.commands[nameOrAlias] ?? valuesOf(cmd.commands).find((c) => {
122
- return c.aliases.includes(nameOrAlias);
123
- });
121
+ return cmd.commands[nameOrAlias] ?? valuesOf(cmd.commands).find((c) => c.aliases.includes(nameOrAlias));
124
122
  }
125
123
  __name(findCommand, "findCommand");
126
124
 
@@ -1189,23 +1187,17 @@ var Command = class _Command {
1189
1187
  }
1190
1188
  /** adds aliases to existing ones */
1191
1189
  addAliases(...aliases) {
1192
- const taken = this.parent ? valuesOf(this.parent.commands).flatMap((c) => {
1193
- return [
1194
- c.name,
1195
- ...c.aliases
1196
- ];
1197
- }) : [];
1198
- array.uniq(aliases.flat()).filter((a) => {
1199
- return !this.aliases.includes(a) && a !== this.name;
1200
- }).forEach((a) => {
1190
+ const taken = this.parent ? valuesOf(this.parent.commands).flatMap((c) => [
1191
+ c.name,
1192
+ ...c.aliases
1193
+ ]) : [];
1194
+ array.uniq(aliases.flat()).filter((a) => !this.aliases.includes(a) && a !== this.name).forEach((a) => {
1201
1195
  if (taken.includes(a)) {
1202
1196
  throw new Error(`Alias "${a}" is already used by a sibling command: ${findCommand(this.parent, a)?.name}`);
1203
1197
  }
1204
1198
  this.aliases.push(a);
1205
1199
  });
1206
- this.aliases.sort((a, b) => {
1207
- return a.length - b.length;
1208
- });
1200
+ this.aliases.sort((a, b) => a.length - b.length);
1209
1201
  return this;
1210
1202
  }
1211
1203
  /** sets the command version */
@@ -1217,9 +1209,7 @@ var Command = class _Command {
1217
1209
  return this.addOption("-V, --version", {
1218
1210
  description: "Display semver version"
1219
1211
  }).addOptionHook("version", ({ cmd }) => {
1220
- console.log(getCommandAndAncestors(cmd).find((c) => {
1221
- return c.version;
1222
- })?.version);
1212
+ console.log(getCommandAndAncestors(cmd).find((c) => c.version)?.version);
1223
1213
  process.exitCode = 0;
1224
1214
  });
1225
1215
  }
@@ -1252,32 +1242,20 @@ var Command = class _Command {
1252
1242
  const sub = this.createSubcommand(name);
1253
1243
  const inherit = this.options;
1254
1244
  sub.options.push(...inherit);
1255
- const inheritHooks = this.hooks.filter((t) => {
1256
- return inherit.some((i) => {
1257
- return i.name === t.name;
1258
- });
1259
- });
1245
+ const inheritHooks = this.hooks.filter((t) => inherit.some((i) => i.name === t.name));
1260
1246
  sub.hooks.push(...inheritHooks);
1261
- const taken = valuesOf(this.commands).flatMap((c) => {
1262
- return [
1263
- c.name,
1264
- ...c.aliases
1265
- ];
1266
- });
1247
+ const taken = valuesOf(this.commands).flatMap((c) => [
1248
+ c.name,
1249
+ ...c.aliases
1250
+ ]);
1267
1251
  if (taken.includes(name)) {
1268
- throw new Error(`Command name "${getCommandAndAncestors(sub).map((c) => {
1269
- return c.name;
1270
- })}" is already used by this command or its aliases: ${taken.join(", ")}`);
1252
+ throw new Error(`Command name "${getCommandAndAncestors(sub).map((c) => c.name)}" is already used by this command or its aliases: ${taken.join(", ")}`);
1271
1253
  }
1272
1254
  const kebab = string.kebabCase(name);
1273
1255
  const words = kebab.split("-");
1274
- const initials = words.map((s) => {
1275
- return s[0];
1276
- }).join("");
1256
+ const initials = words.map((s) => s[0]).join("");
1277
1257
  if (taken.includes(initials)) {
1278
- const initials2 = words.map((s) => {
1279
- return s[0] + s[1];
1280
- }).join("");
1258
+ const initials2 = words.map((s) => s[0] + s[1]).join("");
1281
1259
  if (!taken.includes(initials2)) {
1282
1260
  sub.addAliases(initials2);
1283
1261
  }
@@ -1371,9 +1349,7 @@ var Command = class _Command {
1371
1349
  if (ins.type === "boolean") {
1372
1350
  ins.defaultValue = /^(t(rue)?|y(es)?|1)$/i.test(process.env[ins.env]);
1373
1351
  } else if (ins.variadic) {
1374
- ins.defaultValue = process.env[ins.env].replace(/\[]/, "").split(",").map((v) => {
1375
- return v.trim();
1376
- });
1352
+ ins.defaultValue = process.env[ins.env].replace(/\[]/, "").split(",").map((v) => v.trim());
1377
1353
  } else {
1378
1354
  ins.defaultValue = process.env[ins.env];
1379
1355
  }
@@ -1395,9 +1371,7 @@ var Command = class _Command {
1395
1371
  }
1396
1372
  this.hooks.push({
1397
1373
  name: optionName,
1398
- predicate: setName(`has${string.upperFirst(optionName)}`, ({ opts }) => {
1399
- return opts[optionName] !== void 0 && opts[optionName] !== false && !(Array.isArray(opts[optionName]) && opts[optionName].length === 0);
1400
- }),
1374
+ predicate: setName(`has${string.upperFirst(optionName)}`, ({ opts }) => opts[optionName] !== void 0 && opts[optionName] !== false && !(Array.isArray(opts[optionName]) && opts[optionName].length === 0)),
1401
1375
  action: setName(optionName, action)
1402
1376
  });
1403
1377
  return this;
@@ -1411,17 +1385,15 @@ var Command = class _Command {
1411
1385
  argv = normalizeArgv(argv, this.options);
1412
1386
  const parsed = util.parseArgs({
1413
1387
  args: argv,
1414
- options: Object.fromEntries(this.options.map((o) => {
1415
- return [
1416
- o.name,
1417
- {
1418
- type: o.type,
1419
- short: o.short,
1420
- default: o.defaultValue,
1421
- multiple: !!o.variadic
1422
- }
1423
- ];
1424
- })),
1388
+ options: Object.fromEntries(this.options.map((o) => [
1389
+ o.name,
1390
+ {
1391
+ type: o.type,
1392
+ short: o.short,
1393
+ default: o.defaultValue,
1394
+ multiple: !!o.variadic
1395
+ }
1396
+ ])),
1425
1397
  allowPositionals: true,
1426
1398
  tokens: true,
1427
1399
  strict: false,
@@ -1429,17 +1401,11 @@ var Command = class _Command {
1429
1401
  });
1430
1402
  collectVariadicOptionValues(parsed, this.options);
1431
1403
  mergeOptionDefaults(parsed.values, this.options);
1432
- parsed.values = objSortKeys(parsed.values, (a, b) => {
1433
- return a[1] === false ? 1 : b[1] === false ? -1 : a[1] === true ? 1 : b[1] === true ? -1 : 0;
1434
- });
1404
+ parsed.values = objSortKeys(parsed.values, (a, b) => a[1] === false ? 1 : b[1] === false ? -1 : a[1] === true ? 1 : b[1] === true ? -1 : 0);
1435
1405
  const args = resolveArguments(parsed.positionals, this.arguments);
1436
- const opts = filterObject(parsed.values, (value) => {
1437
- return value !== void 0;
1438
- });
1406
+ const opts = filterObject(parsed.values, (value) => value !== void 0);
1439
1407
  const errors = validateParsed(args, parsed.values, this.arguments, this.options);
1440
- const path = getCommandAncestors(this).map((c) => {
1441
- return c.name;
1442
- });
1408
+ const path = getCommandAncestors(this).map((c) => c.name);
1443
1409
  const data = {
1444
1410
  path,
1445
1411
  name: this.name,
@@ -1449,9 +1415,7 @@ var Command = class _Command {
1449
1415
  errors,
1450
1416
  cmd: this
1451
1417
  };
1452
- const hooks = this.hooks.filter((t) => {
1453
- return t.predicate(data);
1454
- });
1418
+ const hooks = this.hooks.filter((t) => t.predicate(data));
1455
1419
  const execute = /* @__PURE__ */ __name(async () => {
1456
1420
  for (const hook of hooks) {
1457
1421
  await hook.action(data);
@@ -1467,9 +1431,7 @@ var Command = class _Command {
1467
1431
  this.description
1468
1432
  ], async (logger) => {
1469
1433
  if (errors) {
1470
- errors.forEach((msg) => {
1471
- return logger.error(C__default.default.red(msg));
1472
- });
1434
+ errors.forEach((msg) => logger.error(C__default.default.red(msg)));
1473
1435
  process.exitCode = 1;
1474
1436
  return;
1475
1437
  }
package/lib/index.d.cts CHANGED
@@ -894,6 +894,31 @@ type SimpleMerge<Destination, Source> = Simplify<{
894
894
  /**
895
895
  Merge two types into a new type. Keys of the second type overrides keys of the first type.
896
896
 
897
+ This is different from the TypeScript `&` (intersection) operator. With `&`, conflicting property types are intersected, which often results in `never`. For example, `{a: string} & {a: number}` makes `a` become `string & number`, which resolves to `never`. With `Merge`, the second type's keys cleanly override the first, so `Merge<{a: string}, {a: number}>` gives `{a: number}` as expected. `Merge` also produces a flattened type (via `Simplify`), making it more readable in IDE tooltips compared to `A & B`.
898
+
899
+ @example
900
+ ```
901
+ import type {Merge} from 'type-fest';
902
+
903
+ type Foo = {
904
+ a: string;
905
+ b: number;
906
+ };
907
+
908
+ type Bar = {
909
+ a: number; // Conflicts with Foo['a']
910
+ c: boolean;
911
+ };
912
+
913
+ // With `&`, `a` becomes `string & number` which is `never`. Not what you want.
914
+ type WithIntersection = (Foo & Bar)['a'];
915
+ //=> never
916
+
917
+ // With `Merge`, `a` is cleanly overridden to `number`.
918
+ type WithMerge = Merge<Foo, Bar>['a'];
919
+ //=> number
920
+ ```
921
+
897
922
  @example
898
923
  ```
899
924
  import type {Merge} from 'type-fest';
@@ -1083,6 +1108,180 @@ type ApplyDefaultOptions<
1083
1108
  ]: SpecifiedOptions[Key]
1084
1109
  }> & Required<Options>>>>;
1085
1110
 
1111
+ /**
1112
+ @see {@link SomeExtend}
1113
+ */
1114
+ type SomeExtendOptions = {
1115
+ /**
1116
+ Consider `never` elements to match the target type only if the target type itself is `never` (or `any`).
1117
+
1118
+ - When set to `true` (default), `never` is _not_ treated as a bottom type, instead, it is treated as a type that matches only itself (or `any`).
1119
+ - When set to `false`, `never` is treated as a bottom type, and behaves as it normally would.
1120
+
1121
+ @default true
1122
+
1123
+ @example
1124
+ ```
1125
+ import type {SomeExtend} from 'type-fest';
1126
+
1127
+ type A = SomeExtend<[1, 2, never], string, {strictNever: true}>;
1128
+ //=> false
1129
+
1130
+ type B = SomeExtend<[1, 2, never], string, {strictNever: false}>;
1131
+ //=> true
1132
+
1133
+ type C = SomeExtend<[1, never], never, {strictNever: true}>;
1134
+ //=> true
1135
+
1136
+ type D = SomeExtend<[1, never], never, {strictNever: false}>;
1137
+ //=> true
1138
+
1139
+ type E = SomeExtend<[never], any, {strictNever: true}>;
1140
+ //=> true
1141
+
1142
+ type F = SomeExtend<[never], any, {strictNever: false}>;
1143
+ //=> true
1144
+ ```
1145
+ */
1146
+ strictNever?: boolean;
1147
+ };
1148
+
1149
+ type DefaultSomeExtendOptions = {
1150
+ strictNever: true;
1151
+ };
1152
+
1153
+ /**
1154
+ Returns a boolean for whether some element in an array type extends another type.
1155
+
1156
+ @example
1157
+ ```
1158
+ import type {SomeExtend} from 'type-fest';
1159
+
1160
+ type A = SomeExtend<['1', '2', 3], number>;
1161
+ //=> true
1162
+
1163
+ type B = SomeExtend<[1, 2, 3], string>;
1164
+ //=> false
1165
+
1166
+ type C = SomeExtend<[string, number | string], number>;
1167
+ //=> boolean
1168
+
1169
+ type D = SomeExtend<[true, boolean, true], false>;
1170
+ //=> boolean
1171
+ ```
1172
+
1173
+ Note: Behaviour of optional elements depend on the `exactOptionalPropertyTypes` compiler option. When the option is disabled, the target type must include `undefined` for a successful match.
1174
+
1175
+ ```
1176
+ // @exactOptionalPropertyTypes: true
1177
+ import type {SomeExtend} from 'type-fest';
1178
+
1179
+ type A = SomeExtend<[1?, 2?, '3'?], string>;
1180
+ //=> true
1181
+ ```
1182
+
1183
+ ```
1184
+ // @exactOptionalPropertyTypes: false
1185
+ import type {SomeExtend} from 'type-fest';
1186
+
1187
+ type A = SomeExtend<[1?, 2?, '3'?], string>;
1188
+ //=> boolean
1189
+
1190
+ type B = SomeExtend<[1?, 2?, '3'?], string | undefined>;
1191
+ //=> true
1192
+ ```
1193
+
1194
+ @see {@link SomeExtendOptions}
1195
+
1196
+ @category Utilities
1197
+ @category Array
1198
+ */
1199
+ type SomeExtend<TArray extends UnknownArray, Type, Options extends SomeExtendOptions = {}> =
1200
+ _SomeExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<SomeExtendOptions, DefaultSomeExtendOptions, Options>>;
1201
+
1202
+ type _SomeExtend<TArray extends UnknownArray, Type, Options extends Required<SomeExtendOptions>> = IfNotAnyOrNever<TArray,
1203
+ TArray extends readonly [infer First, ...infer Rest]
1204
+ ? IsNever<First> extends true
1205
+ ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true
1206
+ // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, return `true`.
1207
+ ? true
1208
+ : _SomeExtend<Rest, Type, Options>
1209
+ : First extends Type
1210
+ ? true
1211
+ : _SomeExtend<Rest, Type, Options>
1212
+ : false,
1213
+ false, false>;
1214
+
1215
+ /**
1216
+ Returns a boolean for whether any of the given elements is `true`.
1217
+
1218
+ Use-cases:
1219
+ - Check if at least one condition in a list of booleans is met.
1220
+
1221
+ @example
1222
+ ```
1223
+ import type {OrAll} from 'type-fest';
1224
+
1225
+ type FFT = OrAll<[false, false, true]>;
1226
+ //=> true
1227
+
1228
+ type FFF = OrAll<[false, false, false]>;
1229
+ //=> false
1230
+ ```
1231
+
1232
+ Note: When `boolean` is passed as an element, it is distributed into separate cases, and the final result is a union of those cases.
1233
+ For example, `OrAll<[false, boolean]>` expands to `OrAll<[false, true]> | OrAll<[false, false]>`, which simplifies to `true | false` (i.e., `boolean`).
1234
+
1235
+ @example
1236
+ ```
1237
+ import type {OrAll} from 'type-fest';
1238
+
1239
+ type A = OrAll<[false, boolean]>;
1240
+ //=> boolean
1241
+
1242
+ type B = OrAll<[true, boolean]>;
1243
+ //=> true
1244
+ ```
1245
+
1246
+ Note: If `never` is passed as an element, it is treated as `false` and the result is computed accordingly.
1247
+
1248
+ @example
1249
+ ```
1250
+ import type {OrAll} from 'type-fest';
1251
+
1252
+ type A = OrAll<[never, never, true]>;
1253
+ //=> true
1254
+
1255
+ type B = OrAll<[never, never, false]>;
1256
+ //=> false
1257
+
1258
+ type C = OrAll<[never, never, never]>;
1259
+ //=> false
1260
+
1261
+ type D = OrAll<[never, never, boolean]>;
1262
+ //=> boolean
1263
+ ```
1264
+
1265
+ Note: If `any` is passed as an element, it is treated as `boolean` and the result is computed accordingly.
1266
+
1267
+ @example
1268
+ ```
1269
+ import type {OrAll} from 'type-fest';
1270
+
1271
+ type A = OrAll<[false, any]>;
1272
+ //=> boolean
1273
+
1274
+ type B = OrAll<[true, any]>;
1275
+ //=> true
1276
+ ```
1277
+
1278
+ Note: `OrAll<[]>` evaluates to `false` because there are no `true` elements in an empty tuple. See [Wikipedia: Clause (logic) > Empty clauses](https://en.wikipedia.org/wiki/Clause_(logic)#Empty_clauses:~:text=The%20truth%20evaluation%20of%20an%20empty%20disjunctive%20clause%20is%20always%20false.).
1279
+
1280
+ @see {@link Or}
1281
+ @see {@link AndAll}
1282
+ */
1283
+ type OrAll<T extends readonly boolean[]> = SomeExtend<T, true>;
1284
+
1086
1285
  /**
1087
1286
  Returns a boolean for whether either of two given types is true.
1088
1287
 
@@ -1156,17 +1355,11 @@ type G = Or<never, never>;
1156
1355
  //=> false
1157
1356
  ```
1158
1357
 
1358
+ @see {@link OrAll}
1159
1359
  @see {@link And}
1160
1360
  @see {@link Xor}
1161
1361
  */
1162
- type Or<A extends boolean, B extends boolean> =
1163
- _Or<If<IsNever<A>, false, A>, If<IsNever<B>, false, B>>; // `never` is treated as `false`
1164
-
1165
- type _Or<A extends boolean, B extends boolean> = A extends true
1166
- ? true
1167
- : B extends true
1168
- ? true
1169
- : false;
1362
+ type Or<A extends boolean, B extends boolean> = OrAll<[A, B]>;
1170
1363
 
1171
1364
  /**
1172
1365
  @see {@link AllExtend}
@@ -1265,18 +1458,18 @@ type B = AllExtend<[1?, 2?, 3?], number | undefined>;
1265
1458
  type AllExtend<TArray extends UnknownArray, Type, Options extends AllExtendOptions = {}> =
1266
1459
  _AllExtend<CollapseRestElement<TArray>, Type, ApplyDefaultOptions<AllExtendOptions, DefaultAllExtendOptions, Options>>;
1267
1460
 
1268
- type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray, If<IsAny<Type>, true,
1461
+ type _AllExtend<TArray extends UnknownArray, Type, Options extends Required<AllExtendOptions>> = IfNotAnyOrNever<TArray,
1269
1462
  TArray extends readonly [infer First, ...infer Rest]
1270
1463
  ? IsNever<First> extends true
1271
- ? Or<IsNever<Type>, Not<Options['strictNever']>> extends true
1272
- // If target `Type` is also `never` OR `strictNever` is disabled, recurse further.
1464
+ ? Or<Or<IsNever<Type>, IsAny<Type>>, Not<Options['strictNever']>> extends true
1465
+ // If target `Type` is also `never`, or is `any`, or `strictNever` is disabled, recurse further.
1273
1466
  ? _AllExtend<Rest, Type, Options>
1274
1467
  : false
1275
1468
  : First extends Type
1276
1469
  ? _AllExtend<Rest, Type, Options>
1277
1470
  : false
1278
- : true
1279
- >, false, false>;
1471
+ : true,
1472
+ false, false>;
1280
1473
 
1281
1474
  /**
1282
1475
  Filter out keys from an object.
@@ -1402,11 +1595,7 @@ type Foo = {
1402
1595
  };
1403
1596
 
1404
1597
  type SomeRequired = SetRequired<Foo, 'b' | 'c'>;
1405
- // type SomeRequired = {
1406
- // a?: number;
1407
- // b: string; // Was already required and still is.
1408
- // c: boolean; // Is now required.
1409
- // }
1598
+ //=> {a?: number; b: string; c: boolean}
1410
1599
 
1411
1600
  // Set specific indices in an array to be required.
1412
1601
  type ArrayExample = SetRequired<[number?, number?, number?], 0 | 1>;