Commit be21ecc

Anton Medvedev <anton@medv.io>
2022-06-02 18:14:04
Deprecate nothrow() and quiet()
1 parent f3a729e
Changed files (3)
src/core.ts
@@ -104,8 +104,8 @@ export class ProcessPromise extends Promise<ProcessOutput> {
   private _resolve: Resolve = noop
   private _reject: Resolve = noop
   private _inherit = false
-  _nothrow = false
-  _quiet = false
+  private _nothrow = false
+  private _quiet = false
   private _resolved = false
   _piped = false
   _prerun = noop
@@ -261,6 +261,16 @@ export class ProcessPromise extends Promise<ProcessOutput> {
     this._inherit = true
     return this
   }
+
+  nothrow() {
+    this._nothrow = true
+    return this
+  }
+
+  quiet() {
+    this._quiet = true
+    return this
+  }
 }
 
 export class ProcessOutput extends Error {
@@ -322,16 +332,20 @@ export class ProcessOutput extends Error {
   }
 }
 
-export function nothrow(promise: ProcessPromise) {
-  promise._nothrow = true
-  return promise
+export function within<R>(callback: (...args: any) => R): R {
+  return storage.run({ ...getStore() }, callback)
 }
 
-export function quiet(promise: ProcessPromise) {
-  promise._quiet = true
-  return promise
+/**
+ *  @deprecated Use $.nothrow() instead.
+ */
+export function nothrow(promise: ProcessPromise) {
+  return promise.nothrow()
 }
 
-export function within<R>(callback: (...args: any) => R): R {
-  return storage.run({ ...getStore() }, callback)
+/**
+ * @deprecated Use $.quiet() instead.
+ */
+export function quiet(promise: ProcessPromise) {
+  return promise.quiet()
 }
test/cli.test.js
@@ -73,15 +73,15 @@ test('supports `--prefix` flag ', async () => {
 
 test('scripts from https', async () => {
   let script = path.resolve('test/fixtures/echo.http')
-  let server = quiet($`while true; do cat ${script} | nc -l 8080; done`)
-  let p = await quiet($`node build/cli.js http://127.0.0.1:8080/echo.mjs`)
+  let server = $`while true; do cat ${script} | nc -l 8080; done`.quiet()
+  let p = await $`node build/cli.js http://127.0.0.1:8080/echo.mjs`.quiet()
 
   assert.ok(p.stdout.includes('test'))
   server.kill()
 
   let err
   try {
-    await quiet($`node build/cli.js http://127.0.0.1:8081/echo.mjs`)
+    await $`node build/cli.js http://127.0.0.1:8081/echo.mjs`.quiet()
   } catch (e) {
     err = e
   }
test/index.test.js
@@ -87,7 +87,7 @@ test('quiet mode is working', async () => {
   console.log = (...args) => {
     stdout += args.join(' ')
   }
-  await quiet($`echo 'test'`)
+  await $`echo 'test'`.quiet()
   console.log = log
   assert.is(stdout, '')
 })
@@ -198,7 +198,7 @@ test('await $`cmd`.exitCode does not throw', async () => {
 })
 
 test('nothrow() do not throw', async () => {
-  let { exitCode } = await nothrow($`exit 42`)
+  let { exitCode } = await $`exit 42`.nothrow()
   assert.is(exitCode, 42)
 })
 
@@ -309,7 +309,7 @@ test('cd() does affect parallel contexts', async () => {
 })
 
 test('kill() method works', async () => {
-  let p = nothrow($`sleep 9999`)
+  let p = $`sleep 9999`.nothrow()
   setTimeout(() => {
     p.kill()
   }, 100)