Skip to content

Commit

Permalink
fix: update zx to v6.2.3, migrate to @qiwi/deep-proxy v2
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Jun 5, 2022
1 parent b102888 commit fa11e40
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 40 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ In npm run scripts you can execute locally installed binaries by name. This enab
```js
$`terser input.js --compress ecma=2015,computed_props=false`
```
Note, that yarn and npm modify `env.$PATH` value, so some `*/node_modules/.bin` binaries are available for invocation.
To disable this side-effect, append smth like [`PATH=$(env -i bash -c 'echo $PATH')` to the command](https://askubuntu.com/questions/386629/what-are-the-default-path-values).

### `$.raw`
Evaluates target cmd as is without `shq`.
Expand Down
46 changes: 23 additions & 23 deletions npm-shrinkwrap.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 @@ -35,14 +35,14 @@
},
"homepage": "https://github.com/qiwi/zx-extra#readme",
"dependencies": {
"@qiwi/deep-proxy": "^1.9.0",
"@qiwi/deep-proxy": "^2.0.1",
"@types/ip": "^1.1.0",
"@types/node": "^17.0.38",
"@types/node": "^17.0.40",
"@types/semver": "^7.3.9",
"ip": "^1.1.8",
"is-reachable": "^5.2.0",
"npm-run-path": "^5.1.0",
"tempy": "^3.0.0",
"zx": "^6.2.0"
"zx": "^6.2.3"
}
}
12 changes: 6 additions & 6 deletions src/main/js/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ import {DeepProxy} from '@qiwi/deep-proxy'
export * from 'zx'
export * from './goods.mjs'

export const $ = new DeepProxy(_$, ({DEFAULT, trapName, args}) => {
export const $ = new DeepProxy(_$, ({DEFAULT, target: t, trapName, args}) => {
if (trapName === 'apply') {
const [t,, receiver] = args
if (!t.preferLocal) {
return DEFAULT
}
const env = t.env
t.env = {...t.env, PATH: npmRunPath({cwd: t.cwd})}
const res = t(...receiver)
t.env = env

return res
try {
return t(...args)
} finally {
t.env = env
}
}

return DEFAULT
Expand Down
16 changes: 8 additions & 8 deletions src/test/js/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ import {$, semver, createHook, ip, tempy, tcping, sleep} from '../../main/js/ind

// hooks
{
const quiet = createHook({ verbose: false }, 'quiet')
const nothrow = createHook({nothrow: true}, 'nothrow')
const quiet = createHook({ verbose: 0 }, 'quiet')
const debug = createHook({ verbose: 2 }, 'debug')
const timeout = createHook(
null,
Expand All @@ -51,10 +52,9 @@ import {$, semver, createHook, ip, tempy, tcping, sleep} from '../../main/js/ind
if (!t) return p
let timer = setTimeout(() => p.kill(signal), t)

return Object.assign(
p.finally(() => clearTimeout(timer)),
p
)
p.finally(() => clearTimeout(timer))

return p
},
true
)
Expand All @@ -64,20 +64,20 @@ import {$, semver, createHook, ip, tempy, tcping, sleep} from '../../main/js/ind
await $`echo 'chained'`.quiet()

try {
await quiet(timeout(100, 'SIGKILL')`sleep 9999`)
await nothrow(quiet(timeout(100, 'SIGKILL')`sleep 9999`))
} catch {
console.log('killed1')
}

try {
const p = $`sleep 9999`
await quiet(timeout(100, 'SIGKILL')(p))
await nothrow(quiet(timeout(100, 'SIGKILL')(p)))
} catch {
console.log('killed2')
}

try {
await $`sleep 9999`.quiet().timeout(100, 'SIGKILL')
await $`sleep 9999`.timeout(100, 'SIGKILL').quiet().nothrow()
} catch {
console.log('killed3')
}
Expand Down

0 comments on commit fa11e40

Please sign in to comment.