Commit 9f195ee

Anton Golub <antongolub@antongolub.com>
2025-07-31 22:45:38
refactor: enhance `ProcessPromise` modifier types (#1301)
1 parent 38da212
build/cli.js
build/core.d.ts
@@ -99,7 +99,7 @@ export declare class ProcessPromise extends Promise<ProcessOutput> {
     private _reject;
     constructor(executor: PromiseCallback);
     private build;
-    run(): ProcessPromise;
+    run(): this;
     private _breakData?;
     private break;
     private finalize;
@@ -130,11 +130,11 @@ export declare class ProcessPromise extends Promise<ProcessOutput> {
     get sync(): boolean;
     get [Symbol.toStringTag](): string;
     [Symbol.toPrimitive](): string;
-    stdio(stdin: IOType, stdout?: IOType, stderr?: IOType): ProcessPromise;
-    nothrow(v?: boolean): ProcessPromise;
-    quiet(v?: boolean): ProcessPromise;
-    verbose(v?: boolean): ProcessPromise;
-    timeout(d?: Duration, signal?: NodeJS.Signals | undefined): ProcessPromise;
+    stdio(stdin: IOType, stdout?: IOType, stderr?: IOType): this;
+    nothrow(v?: boolean): this;
+    quiet(v?: boolean): this;
+    verbose(v?: boolean): this;
+    timeout(d?: Duration, signal?: NodeJS.Signals | undefined): this;
     json<T = any>(): Promise<T>;
     text(encoding?: Encoding): Promise<string>;
     lines(delimiter?: Options['delimiter']): Promise<string[]>;
src/core.ts
@@ -292,7 +292,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
       $.args
     ) as string
   }
-  run(): ProcessPromise {
+  run(): this {
     ProcessPromise.bus.runBack(this)
     if (this.isRunning() || this.isSettled()) return this // The _run() can be called from a few places.
     this._stage = 'running'
@@ -627,31 +627,27 @@ export class ProcessPromise extends Promise<ProcessOutput> {
   }
 
   // Configurators
-  stdio(
-    stdin: IOType,
-    stdout: IOType = 'pipe',
-    stderr: IOType = 'pipe'
-  ): ProcessPromise {
+  stdio(stdin: IOType, stdout: IOType = 'pipe', stderr: IOType = 'pipe'): this {
     this._snapshot.stdio = [stdin, stdout, stderr]
     return this
   }
 
-  nothrow(v = true): ProcessPromise {
+  nothrow(v = true): this {
     this._snapshot.nothrow = v
     return this
   }
 
-  quiet(v = true): ProcessPromise {
+  quiet(v = true): this {
     this._snapshot.quiet = v
     return this
   }
 
-  verbose(v = true): ProcessPromise {
+  verbose(v = true): this {
     this._snapshot.verbose = v
     return this
   }
 
-  timeout(d: Duration = 0, signal = $.timeoutSignal): ProcessPromise {
+  timeout(d: Duration = 0, signal = $.timeoutSignal): this {
     if (this.isSettled()) return this
 
     const $ = this._snapshot
.size-limit.json
@@ -15,7 +15,7 @@
       "README.md",
       "LICENSE"
     ],
-    "limit": "124.302 kB",
+    "limit": "124.25 kB",
     "brotli": false,
     "gzip": false
   },
@@ -36,7 +36,7 @@
   {
     "name": "libdefs",
     "path": "build/*.d.ts",
-    "limit": "40.35 kB",
+    "limit": "40.30 kB",
     "brotli": false,
     "gzip": false
   },
@@ -62,7 +62,7 @@
       "README.md",
       "LICENSE"
     ],
-    "limit": "871.805 kB",
+    "limit": "871.75 kB",
     "brotli": false,
     "gzip": false
   }