Skip to content

Commit

Permalink
feat: let $ presets be composable (#883)
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub authored Sep 5, 2024
1 parent 09d0d04 commit 5d2ad78
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
24 changes: 12 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@
"prettier": "^3.3.3",
"size-limit": "^11.1.4",
"ts-node": "^10.9.2",
"tsd": "^0.31.1",
"tsd": "^0.31.2",
"tsx": "^4.19.0",
"typescript": "^5.5.4",
"which": "^4.0.0",
"yaml": "^2.5.0",
"zurk": "^0.3.0"
"yaml": "^2.5.1",
"zurk": "^0.3.1"
},
"publishConfig": {
"registry": "https://wombat-dressing-room.appspot.com"
Expand Down
4 changes: 2 additions & 2 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ function getStore() {

export const $: Shell & Options = new Proxy<Shell & Options>(
function (pieces, ...args) {
const snapshot = getStore()
if (!Array.isArray(pieces)) {
return function (this: any, ...args: any) {
const self = this
return within(() => {
return Object.assign($, pieces).apply(self, args)
return Object.assign($, snapshot, pieces).apply(self, args)
})
}
}
Expand All @@ -186,7 +187,6 @@ export const $: Shell & Options = new Proxy<Shell & Options>(
pieces as TemplateStringsArray,
args
) as string
const snapshot = getStore()
const sync = snapshot[syncExec]
const callback = () => promise.isHalted() || promise.run()

Expand Down
5 changes: 5 additions & 0 deletions test/core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,19 @@ describe('core', () => {
test('`$.sync()` provides synchronous API', () => {
const o1 = $.sync`echo foo`
const o2 = $({ sync: true })`echo foo`
const o3 = $.sync({})`echo foo`
assert.equal(o1.stdout, 'foo\n')
assert.equal(o2.stdout, 'foo\n')
assert.equal(o3.stdout, 'foo\n')
})

describe('$({opts}) API', () => {
test('provides presets', async () => {
const $$ = $({ nothrow: true })
assert.equal((await $$`exit 1`).exitCode, 1)

const $$$ = $$({ sync: true })
assert.equal($$$`exit 2`.exitCode, 2)
})

test('handles `input` option', async () => {
Expand Down

0 comments on commit 5d2ad78

Please sign in to comment.