Skip to content

Commit adde780

Browse files
committed
refactor: simplify setup checks
1 parent 3931b9d commit adde780

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/core.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import {
4040
parseDuration,
4141
quote,
4242
quotePowerShell,
43-
noquote,
4443
preferNmBin,
4544
} from './util.js'
4645

@@ -74,7 +73,7 @@ export interface Options {
7473
nothrow: boolean
7574
prefix: string
7675
postfix: string
77-
quote: typeof quote
76+
quote?: typeof quote
7877
quiet: boolean
7978
detached: boolean
8079
preferLocal: boolean
@@ -114,7 +113,6 @@ export const defaults: Options = {
114113
quiet: false,
115114
prefix: '',
116115
postfix: '',
117-
quote: noquote,
118116
detached: false,
119117
preferLocal: false,
120118
spawn,
@@ -145,9 +143,15 @@ export function useBash() {
145143
}
146144

147145
function checkShell() {
148-
if (!$.shell) {
149-
throw new Error(`shell is not available: setup guide goes here`)
150-
}
146+
if (!$.shell)
147+
throw new Error(
148+
`No shell is available: https://google.github.io/zx/setup#bash`
149+
)
150+
}
151+
152+
function checkQuote() {
153+
if (!$.quote)
154+
throw new Error('No quote function is defined: https://ï.at/no-quote-func')
151155
}
152156

153157
function getStore() {
@@ -156,8 +160,6 @@ function getStore() {
156160

157161
export const $: Shell & Options = new Proxy<Shell & Options>(
158162
function (pieces, ...args) {
159-
checkShell()
160-
161163
if (!Array.isArray(pieces)) {
162164
return function (this: any, ...args: any) {
163165
const self = this
@@ -170,10 +172,13 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
170172
if (pieces.some((p) => p == undefined)) {
171173
throw new Error(`Malformed command at ${from}`)
172174
}
175+
checkShell()
176+
checkQuote()
177+
173178
let resolve: Resolve, reject: Resolve
174179
const promise = new ProcessPromise((...args) => ([resolve, reject] = args))
175180
const cmd = buildCmd(
176-
$.quote,
181+
$.quote as typeof quote,
177182
pieces as TemplateStringsArray,
178183
args
179184
) as string

src/util.ts

-4
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ export function normalizeMultilinePieces(
8585
)
8686
}
8787

88-
export function noquote(): string {
89-
throw new Error('No quote function is defined: https://ï.at/no-quote-func')
90-
}
91-
9288
export function quote(arg: string) {
9389
if (/^[a-z0-9/_.\-@:=]+$/i.test(arg) || arg === '') {
9490
return arg

0 commit comments

Comments
 (0)