Skip to content

Commit dd1e2c7

Browse files
committed
fix(packages/run): improve runnerFactory intellisense
1 parent 596a4ca commit dd1e2c7

File tree

2 files changed

+59
-31
lines changed

2 files changed

+59
-31
lines changed

packages/run/src/index.ts

+6-31
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@ import { createDebugLogger } from 'rejoinder';
22

33
import { globalDebuggerNamespace } from 'universe+run:constant.ts';
44

5-
import type { Merge } from 'type-fest';
6-
75
import type {
86
DefaultRunOptions,
7+
RunnerFactoryReturnType,
98
RunOptions,
109
RunReturnType
1110
} from 'universe+run:types.ts';
@@ -186,42 +185,18 @@ export function runnerFactory<FactoryOptionsType extends RunOptions = DefaultRun
186185
file: string,
187186
args?: string[],
188187
options?: FactoryOptionsType
189-
) {
188+
): RunnerFactoryReturnType<FactoryOptionsType> {
190189
// ? Hide these names from intellisense
191190
const factoryArgs = args;
192191
const factoryOptions = options;
193192

194-
/**
195-
* Runs (executes) with respect to the factory parameters used to generate
196-
* this function.
197-
*
198-
* Additional arguments specified via `args` will be appended to the
199-
* corresponding factory parameter. On the other hand, additional options
200-
* specified via `options` will _overwrite_ corresponding factory options (via
201-
* `Object.assign`).
202-
*
203-
* Note that, by default (unless modified at the factory level), this
204-
* function:
205-
*
206-
* 1. Rejects on a non-zero exit code. Set `reject: false` to override this.
207-
*
208-
* 2. Coerces output to a string. Set `coerceOutputToString: false` (or
209-
* `lines: true`) to override this.
210-
*/
211-
async function factoryRunner(
212-
args?: string[],
213-
options?: undefined
214-
): Promise<RunReturnType<FactoryOptionsType>>;
215-
async function factoryRunner<LocalOptionsType extends RunOptions>(
193+
return async function factoryRunner(
216194
args?: string[],
217-
options?: LocalOptionsType
218-
): Promise<RunReturnType<Merge<FactoryOptionsType, LocalOptionsType>>>;
219-
async function factoryRunner(args?: string[], options?: RunOptions): Promise<unknown> {
195+
options?: RunOptions
196+
): Promise<RunReturnType<RunOptions>> {
220197
return run(file, [...(factoryArgs || []), ...(args || [])], {
221198
...factoryOptions,
222199
...options
223200
});
224-
}
225-
226-
return factoryRunner;
201+
} as RunnerFactoryReturnType<FactoryOptionsType>;
227202
}

packages/run/src/types.ts

+53
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,56 @@ export type RunReturnType<OptionsType extends RunOptions = DefaultRunOptions> =
158158
: ExecaResult<ReifiedOptionsType>
159159
: never
160160
>;
161+
162+
/**
163+
* @see `runnerFactory`
164+
*/
165+
export type RunnerFactoryReturnType<
166+
FactoryOptionsType extends RunOptions = DefaultRunOptions
167+
> = {
168+
/**
169+
* Runs (executes) with respect to the factory parameters used to generate
170+
* this function.
171+
*
172+
* Additional arguments specified via `args` will be appended to the
173+
* corresponding factory parameter. On the other hand, additional options
174+
* specified via `options` will _overwrite_ corresponding factory options (via
175+
* `Object.assign`).
176+
*
177+
* Note that, by default (unless modified at the factory level), this
178+
* function:
179+
*
180+
* 1. Rejects on a non-zero exit code. Set `reject: false` to override this.
181+
*
182+
* 2. Coerces output to a string. Set `coerceOutputToString: false` (or
183+
* `lines: true`) to override this.
184+
*
185+
* 3. Elides Node.js debugger strings. Set
186+
* `elideNodeDebuggerStringsFromStderr: false` to override this.
187+
*/
188+
(args?: string[], options?: undefined): Promise<RunReturnType<FactoryOptionsType>>;
189+
/**
190+
* Runs (executes) with respect to the factory parameters used to generate
191+
* this function.
192+
*
193+
* Additional arguments specified via `args` will be appended to the
194+
* corresponding factory parameter. On the other hand, additional options
195+
* specified via `options` will _overwrite_ corresponding factory options (via
196+
* `Object.assign`).
197+
*
198+
* Note that, by default (unless modified at the factory level), this
199+
* function:
200+
*
201+
* 1. Rejects on a non-zero exit code. Set `reject: false` to override this.
202+
*
203+
* 2. Coerces output to a string. Set `coerceOutputToString: false` (or
204+
* `lines: true`) to override this.
205+
*
206+
* 3. Elides Node.js debugger strings. Set
207+
* `elideNodeDebuggerStringsFromStderr: false` to override this.
208+
*/
209+
<LocalOptionsType extends RunOptions>(
210+
args?: string[],
211+
options?: LocalOptionsType
212+
): Promise<RunReturnType<Merge<FactoryOptionsType, LocalOptionsType>>>;
213+
};

0 commit comments

Comments
 (0)