effective-progress 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -212,7 +212,7 @@ Supported modifiers:
212
212
 
213
213
  ## Dependencies & package size
214
214
 
215
- This library is designed for CLI workflows, where package size is typically a lower-priority concern. Alongside `effect`, it relies on two mature runtime dependencies: `chalk` and `es-toolkit`.
215
+ This library is designed for CLI workflows, where package size is typically a lower-priority concern. Alongside `effect` though, I will strive to only rely on other high quality packages.
216
216
 
217
217
  ## Notes
218
218
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "effective-progress",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Effect-first terminal progress bars with nested multibar support",
5
5
  "homepage": "https://github.com/stromseng/effective-progress#readme",
6
6
  "bugs": {
package/src/api.ts CHANGED
@@ -19,11 +19,15 @@ export interface EffectAllExecutionOptions extends EffectExecutionOptions {
19
19
 
20
20
  export type AllOptions = Omit<TrackOptions, "total"> & EffectAllExecutionOptions;
21
21
  export type AllReturn<
22
- Arg extends ReadonlyArray<Effect.Effect<any, any, any>>,
22
+ Arg extends ReadonlyArray<Effect.Effect<any, any, any>> | Record<string, Effect.Effect<any, any, any>>,
23
23
  O extends EffectAllExecutionOptions,
24
- > = [Effect.All.ReturnTuple<Arg, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>] extends [
25
- Effect.Effect<infer A, infer E, infer R>,
26
- ]
24
+ > = [
25
+ [Arg] extends [ReadonlyArray<Effect.Effect<any, any, any>>]
26
+ ? Effect.All.ReturnTuple<Arg, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
27
+ : [Arg] extends [Record<string, Effect.Effect<any, any, any>>]
28
+ ? Effect.All.ReturnObject<Arg, Effect.All.IsDiscard<O>, Effect.All.ExtractMode<O>>
29
+ : never,
30
+ ] extends [Effect.Effect<infer A, infer E, infer R>]
27
31
  ? Effect.Effect<A, E, Exclude<R, Progress | Task>>
28
32
  : never;
29
33
 
@@ -52,25 +56,30 @@ export const task: {
52
56
  ) as Effect.Effect<A, E, Exclude<R, Progress | Task>>,
53
57
  );
54
58
 
59
+ type AllArg = ReadonlyArray<Effect.Effect<any, any, any>> | Record<string, Effect.Effect<any, any, any>>;
60
+
61
+ const wrapEffects = (
62
+ effects: AllArg,
63
+ tap: (effect: Effect.Effect<any, any, any>) => Effect.Effect<any, any, any>,
64
+ ): AllArg =>
65
+ Array.isArray(effects)
66
+ ? effects.map(tap)
67
+ : Object.fromEntries(Object.entries(effects).map(([k, effect]) => [k, tap(effect)]));
68
+
69
+ const countEffects = (effects: AllArg): number =>
70
+ Array.isArray(effects) ? effects.length : Object.keys(effects).length;
71
+
55
72
  export const all: {
56
- <
57
- const Arg extends ReadonlyArray<Effect.Effect<any, any, any>>,
58
- O extends EffectAllExecutionOptions,
59
- >(
73
+ <const Arg extends AllArg, O extends EffectAllExecutionOptions>(
60
74
  effects: Arg,
61
75
  options: Omit<TrackOptions, "total"> & O,
62
76
  ): AllReturn<Arg, O>;
63
77
  <O extends EffectAllExecutionOptions>(
64
78
  options: Omit<TrackOptions, "total"> & O,
65
- ): <const Arg extends ReadonlyArray<Effect.Effect<any, any, any>>>(
66
- effects: Arg,
67
- ) => AllReturn<Arg, O>;
79
+ ): <const Arg extends AllArg>(effects: Arg) => AllReturn<Arg, O>;
68
80
  } = dual(
69
81
  2,
70
- <
71
- const Arg extends ReadonlyArray<Effect.Effect<any, any, any>>,
72
- O extends EffectAllExecutionOptions,
73
- >(
82
+ <const Arg extends AllArg, O extends EffectAllExecutionOptions>(
74
83
  effects: Arg,
75
84
  options: Omit<TrackOptions, "total"> & O,
76
85
  ) =>
@@ -82,7 +91,9 @@ export const all: {
82
91
  const taskId = yield* Task;
83
92
  const exit = yield* Effect.exit(
84
93
  Effect.all(
85
- effects.map((effect) => Effect.tap(effect, () => progress.advanceTask(taskId, 1))),
94
+ wrapEffects(effects, (effect) =>
95
+ Effect.tap(effect, () => progress.advanceTask(taskId, 1)),
96
+ ),
86
97
  {
87
98
  concurrency: options.concurrency,
88
99
  batching: options.batching,
@@ -106,7 +117,7 @@ export const all: {
106
117
  }),
107
118
  {
108
119
  description: options.description,
109
- total: effects.length,
120
+ total: countEffects(effects),
110
121
  transient: options.transient,
111
122
  progressbar: options.progressbar,
112
123
  },
package/src/colors.ts CHANGED
@@ -104,10 +104,10 @@ export const defaultProgressBarColors: ProgressBarColors = {
104
104
  };
105
105
 
106
106
  const applyModifier = (instance: ChalkInstance, modifier: StyleModifier): ChalkInstance =>
107
- instance[modifier] as ChalkInstance;
107
+ instance[modifier];
108
108
 
109
109
  const applyNamedColor = (instance: ChalkInstance, color: NamedColor): ChalkInstance =>
110
- instance[color] as ChalkInstance;
110
+ instance[color];
111
111
 
112
112
  const resolveBaseStyle = (style: ColorStyle): ChalkInstance => {
113
113
  switch (style.kind) {