diff --git a/README.md b/README.md index 5c41823..e3e1fb9 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 731b366..568b45d 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -9,15 +9,15 @@ "version": "1.6.5", "license": "MIT", "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" }, "bin": { "zx-extra": "src/main/js/cli.mjs" @@ -56,9 +56,9 @@ } }, "node_modules/@qiwi/deep-proxy": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@qiwi/deep-proxy/-/deep-proxy-1.9.0.tgz", - "integrity": "sha512-/lEv75Dck3UmXuGKdCE3aGk4KLRoEsT4yjPacmUDcKOChsMwamvXk9hlKn4uRzJuGG5XScOVM2FzNT6dYL9Ttw==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@qiwi/deep-proxy/-/deep-proxy-2.0.1.tgz", + "integrity": "sha512-uMRpUEv+jJ4ggWYWCSw0/ha5G7Ml/Uv/P4tlGuSPIVA9aB/e05wjnCC0YwJ6Vw+IHTSY9eyZS9pqNXNe/gXa/w==", "dependencies": { "tslib": "^2.4.0" } @@ -136,9 +136,9 @@ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==" }, "node_modules/@types/node": { - "version": "17.0.38", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.38.tgz", - "integrity": "sha512-5jY9RhV7c0Z4Jy09G+NIDTsCZ5G0L5n+Z+p+Y7t5VJHM30bgwzSjVtlcBxqAj+6L/swIlvtOSzr8rBk/aNyV2g==" + "version": "17.0.40", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.40.tgz", + "integrity": "sha512-UXdBxNGqTMtm7hCwh9HtncFVLrXoqA3oJW30j6XWp5BH/wu3mVeaxo7cq5benFdBw34HB3XDT2TRPI7rXZ+mDg==" }, "node_modules/@types/ps-tree": { "version": "1.1.2", @@ -1140,9 +1140,9 @@ } }, "node_modules/zx": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/zx/-/zx-6.2.0.tgz", - "integrity": "sha512-g7M/j+Jgw0XVpuX0VyW5vHctU/G7Q2/xb0yysyaTS37Iv39s9Fxn1QvLePVt/QnQSkfNPqeYzsqST1+sRG5Jaw==", + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/zx/-/zx-6.2.3.tgz", + "integrity": "sha512-KROw4oYCPBXDQn5N1XAaf9UmM5g6UBTjSOGv1JDvU+T0bxcKDlRR4KzLykyjnfRqy4VPX4wRYBO3A7TenDczsA==", "dependencies": { "@types/fs-extra": "^9.0.13", "@types/minimist": "^1.2.2", @@ -1154,7 +1154,7 @@ "globby": "^13.1.1", "ignore": "^5.2.0", "minimist": "^1.2.6", - "node-fetch": "^3.2.4", + "node-fetch": "^3.2.5", "ps-tree": "^1.2.0", "which": "^2.0.2", "yaml": "^2.1.1" @@ -1192,9 +1192,9 @@ } }, "@qiwi/deep-proxy": { - "version": "1.9.0", - "resolved": "https://registry.npmjs.org/@qiwi/deep-proxy/-/deep-proxy-1.9.0.tgz", - "integrity": "sha512-/lEv75Dck3UmXuGKdCE3aGk4KLRoEsT4yjPacmUDcKOChsMwamvXk9hlKn4uRzJuGG5XScOVM2FzNT6dYL9Ttw==", + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/@qiwi/deep-proxy/-/deep-proxy-2.0.1.tgz", + "integrity": "sha512-uMRpUEv+jJ4ggWYWCSw0/ha5G7Ml/Uv/P4tlGuSPIVA9aB/e05wjnCC0YwJ6Vw+IHTSY9eyZS9pqNXNe/gXa/w==", "requires": { "tslib": "^2.4.0" } @@ -1263,9 +1263,9 @@ "integrity": "sha512-jhuKLIRrhvCPLqwPcx6INqmKeiA5EWrsCOPhrlFSrbrmU4ZMPjj5Ul/oLCMDO98XRUIwVm78xICz4EPCektzeQ==" }, "@types/node": { - "version": "17.0.38", - "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.38.tgz", - "integrity": "sha512-5jY9RhV7c0Z4Jy09G+NIDTsCZ5G0L5n+Z+p+Y7t5VJHM30bgwzSjVtlcBxqAj+6L/swIlvtOSzr8rBk/aNyV2g==" + "version": "17.0.40", + "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.40.tgz", + "integrity": "sha512-UXdBxNGqTMtm7hCwh9HtncFVLrXoqA3oJW30j6XWp5BH/wu3mVeaxo7cq5benFdBw34HB3XDT2TRPI7rXZ+mDg==" }, "@types/ps-tree": { "version": "1.1.2", @@ -1952,9 +1952,9 @@ "integrity": "sha512-o96x3OPo8GjWeSLF+wOAbrPfhFOGY0W00GNaxCDv+9hkcDJEnev1yh8S7pgHF0ik6zc8sQLuL8hjHjJULZp8bw==" }, "zx": { - "version": "6.2.0", - "resolved": "https://registry.npmjs.org/zx/-/zx-6.2.0.tgz", - "integrity": "sha512-g7M/j+Jgw0XVpuX0VyW5vHctU/G7Q2/xb0yysyaTS37Iv39s9Fxn1QvLePVt/QnQSkfNPqeYzsqST1+sRG5Jaw==", + "version": "6.2.3", + "resolved": "https://registry.npmjs.org/zx/-/zx-6.2.3.tgz", + "integrity": "sha512-KROw4oYCPBXDQn5N1XAaf9UmM5g6UBTjSOGv1JDvU+T0bxcKDlRR4KzLykyjnfRqy4VPX4wRYBO3A7TenDczsA==", "requires": { "@types/fs-extra": "^9.0.13", "@types/minimist": "^1.2.2", @@ -1966,7 +1966,7 @@ "globby": "^13.1.1", "ignore": "^5.2.0", "minimist": "^1.2.6", - "node-fetch": "^3.2.4", + "node-fetch": "^3.2.5", "ps-tree": "^1.2.0", "which": "^2.0.2", "yaml": "^2.1.1" diff --git a/package.json b/package.json index c5ee273..76096ff 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/main/js/index.mjs b/src/main/js/index.mjs index db352d3..98ec979 100644 --- a/src/main/js/index.mjs +++ b/src/main/js/index.mjs @@ -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 diff --git a/src/test/js/test.mjs b/src/test/js/test.mjs index ae51aa7..f0e1ea9 100644 --- a/src/test/js/test.mjs +++ b/src/test/js/test.mjs @@ -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, @@ -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 ) @@ -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') }