13
13
// limitations under the License.
14
14
15
15
import assert from 'node:assert'
16
- import { spawn , spawnSync , StdioOptions , IOType } from 'node:child_process'
16
+ import {
17
+ type StdioOptions ,
18
+ type IOType ,
19
+ spawn ,
20
+ spawnSync ,
21
+ } from 'node:child_process'
17
22
import { type Encoding } from 'node:crypto'
18
- import { AsyncHook , AsyncLocalStorage , createHook } from 'node:async_hooks'
19
- import { Readable , Writable } from 'node:stream'
23
+ import { type AsyncHook , AsyncLocalStorage , createHook } from 'node:async_hooks'
24
+ import { type Readable , type Writable } from 'node:stream'
20
25
import { inspect } from 'node:util'
21
26
import { EOL } from 'node:os'
22
27
import {
@@ -31,7 +36,7 @@ import {
31
36
type TSpawnStore ,
32
37
} from './vendor.js'
33
38
import {
34
- Duration ,
39
+ type Duration ,
35
40
errnoMessage ,
36
41
exitCodeInfo ,
37
42
formatCmd ,
@@ -40,7 +45,6 @@ import {
40
45
parseDuration ,
41
46
quote ,
42
47
quotePowerShell ,
43
- noquote ,
44
48
preferNmBin ,
45
49
} from './util.js'
46
50
@@ -74,7 +78,7 @@ export interface Options {
74
78
nothrow : boolean
75
79
prefix : string
76
80
postfix : string
77
- quote : typeof quote
81
+ quote ? : typeof quote
78
82
quiet : boolean
79
83
detached : boolean
80
84
preferLocal : boolean
@@ -114,7 +118,6 @@ export const defaults: Options = {
114
118
quiet : false ,
115
119
prefix : '' ,
116
120
postfix : '' ,
117
- quote : noquote ,
118
121
detached : false ,
119
122
preferLocal : false ,
120
123
spawn,
@@ -145,9 +148,13 @@ export function useBash() {
145
148
}
146
149
147
150
function checkShell ( ) {
148
- if ( ! $ . shell ) {
149
- throw new Error ( `shell is not available: setup guide goes here` )
150
- }
151
+ if ( ! $ . shell )
152
+ throw new Error ( `No shell is available: https://ï.at/zx-no-shell` )
153
+ }
154
+
155
+ function checkQuote ( ) {
156
+ if ( ! $ . quote )
157
+ throw new Error ( 'No quote function is defined: https://ï.at/no-quote-func' )
151
158
}
152
159
153
160
function getStore ( ) {
@@ -156,8 +163,6 @@ function getStore() {
156
163
157
164
export const $ : Shell & Options = new Proxy < Shell & Options > (
158
165
function ( pieces , ...args ) {
159
- checkShell ( )
160
-
161
166
if ( ! Array . isArray ( pieces ) ) {
162
167
return function ( this : any , ...args : any ) {
163
168
const self = this
@@ -170,10 +175,13 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
170
175
if ( pieces . some ( ( p ) => p == undefined ) ) {
171
176
throw new Error ( `Malformed command at ${ from } ` )
172
177
}
178
+ checkShell ( )
179
+ checkQuote ( )
180
+
173
181
let resolve : Resolve , reject : Resolve
174
182
const promise = new ProcessPromise ( ( ...args ) => ( [ resolve , reject ] = args ) )
175
183
const cmd = buildCmd (
176
- $ . quote ,
184
+ $ . quote as typeof quote ,
177
185
pieces as TemplateStringsArray ,
178
186
args
179
187
) as string
0 commit comments