Commit cafb90d
Changed files (17)
test
fixtures
js-project
ts-project
src/cli.ts
@@ -53,7 +53,15 @@ function printUsage() {
const argv = minimist(process.argv.slice(2), {
string: ['shell', 'prefix', 'eval'],
- boolean: ['version', 'help', 'quiet', 'install', 'repl', 'experimental'],
+ boolean: [
+ 'version',
+ 'help',
+ 'quiet',
+ 'verbose',
+ 'install',
+ 'repl',
+ 'experimental',
+ ],
alias: { e: 'eval', i: 'install', v: 'version', h: 'help' },
stopEarly: true,
})
@@ -61,6 +69,7 @@ const argv = minimist(process.argv.slice(2), {
await (async function main() {
const globals = './globals.js'
await import(globals)
+ if (argv.verbose) $.verbose = true
if (argv.quiet) $.verbose = false
if (argv.shell) $.shell = argv.shell
if (argv.prefix) $.prefix = argv.prefix
src/core.ts
@@ -83,7 +83,7 @@ hook.enable()
export const defaults: Options = {
[processCwd]: process.cwd(),
[syncExec]: false,
- verbose: true,
+ verbose: false,
env: process.env,
sync: false,
shell: true,
@@ -257,7 +257,7 @@ export class ProcessPromise extends Promise<ProcessOutput> {
},
stderr: (data) => {
// Stderr should be printed regardless of piping.
- $.log({ kind: 'stderr', data, verbose: self.isVerbose() })
+ $.log({ kind: 'stderr', data, verbose: !self.isQuiet() })
},
end: ({ error, stdout, stderr, stdall, status, signal }) => {
self._resolved = true
@@ -425,9 +425,12 @@ export class ProcessPromise extends Promise<ProcessOutput> {
return this
}
+ isQuiet(): boolean {
+ return this._quiet ?? this._snapshot.quiet
+ }
+
isVerbose(): boolean {
- const { verbose, quiet } = this._snapshot
- return verbose && !(this._quiet ?? quiet)
+ return this._snapshot.verbose && !this.isQuiet()
}
timeout(d: Duration, signal = 'SIGTERM'): ProcessPromise {
test/fixtures/js-project/package-lock.json
@@ -0,0 +1,57 @@
+{
+ "name": "js-project",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "dependencies": {
+ "zx": "file:../../.."
+ }
+ },
+ "../../..": {
+ "version": "7.2.3",
+ "license": "Apache-2.0",
+ "bin": {
+ "zx": "build/cli.js"
+ },
+ "devDependencies": {
+ "@stryker-mutator/core": "^6.4.2",
+ "@types/fs-extra": "^11.0.4",
+ "@types/minimist": "^1.2.5",
+ "@types/node": ">=20.11.30",
+ "@types/which": "^3.0.3",
+ "@webpod/ps": "^0.0.0-beta.2",
+ "c8": "^9.1.0",
+ "chalk": "^5.3.0",
+ "dts-bundle-generator": "^9.3.1",
+ "esbuild": "^0.20.2",
+ "esbuild-node-externals": "^1.13.0",
+ "esbuild-plugin-entry-chunks": "^0.1.11",
+ "fs-extra": "^11.2.0",
+ "fx": "*",
+ "globby": "^14.0.1",
+ "madge": "^6.1.0",
+ "minimist": "^1.2.8",
+ "node-fetch-native": "^1.6.4",
+ "prettier": "^3.2.5",
+ "tsd": "^0.30.7",
+ "typescript": "^5.4.3",
+ "webpod": "^1",
+ "which": "^4.0.0",
+ "yaml": "^2.4.1",
+ "zurk": "^0.0.32"
+ },
+ "engines": {
+ "node": ">= 16.0.0"
+ },
+ "optionalDependencies": {
+ "@types/fs-extra": "^11.0.4",
+ "@types/node": ">=20.11.30"
+ }
+ },
+ "node_modules/zx": {
+ "resolved": "../../..",
+ "link": true
+ }
+ }
+}
test/fixtures/js-project/package.json
@@ -2,6 +2,6 @@
"private": true,
"type": "module",
"dependencies": {
- "zx": "*"
+ "zx": "file:../../.."
}
}
test/fixtures/ts-project/package.json
@@ -3,6 +3,6 @@
"type": "module",
"dependencies": {
"typescript": "^5.0.0",
- "zx": "*"
+ "zx": "file:../../.."
}
}
test/fixtures/ts-project/script.ts
@@ -14,5 +14,5 @@
import { $, ProcessPromise } from 'zx'
-let p: ProcessPromise = $`echo ts-script`
+let p: ProcessPromise = $({ verbose: true })`echo ts-script`
await p
test/cli.test.js
@@ -21,7 +21,6 @@ describe('cli', () => {
let promiseResolved = false
beforeEach(() => {
- $.verbose = false
process.on('exit', () => {
if (!promiseResolved) {
console.error('Error: ProcessPromise never resolved.')
@@ -77,29 +76,30 @@ describe('cli', () => {
})
test('supports `--quiet` flag', async () => {
- let p = await $`node build/cli.js test/fixtures/markdown.md`
+ let p = await $`node build/cli.js --quiet test/fixtures/markdown.md`
assert.ok(!p.stderr.includes('ignore'), 'ignore was printed')
- assert.ok(p.stderr.includes('hello'), 'no hello')
+ assert.ok(!p.stderr.includes('hello'), 'no hello')
assert.ok(p.stdout.includes('world'), 'no world')
})
test('supports `--shell` flag ', async () => {
let shell = $.shell
let p =
- await $`node build/cli.js --shell=${shell} <<< '$\`echo \${$.shell}\`'`
+ await $`node build/cli.js --verbose --shell=${shell} <<< '$\`echo \${$.shell}\`'`
assert.ok(p.stderr.includes(shell))
})
test('supports `--prefix` flag ', async () => {
let prefix = 'set -e;'
let p =
- await $`node build/cli.js --prefix=${prefix} <<< '$\`echo \${$.prefix}\`'`
+ await $`node build/cli.js --verbose --prefix=${prefix} <<< '$\`echo \${$.prefix}\`'`
assert.ok(p.stderr.includes(prefix))
})
test('scripts from https', async () => {
$`cat ${path.resolve('test/fixtures/echo.http')} | nc -l 8080`
- let out = await $`node build/cli.js http://127.0.0.1:8080/echo.mjs`
+ let out =
+ await $`node build/cli.js --verbose http://127.0.0.1:8080/echo.mjs`
assert.match(out.stderr, /test/)
})
test/core.test.js
@@ -21,10 +21,6 @@ import { ProcessPromise, ProcessOutput } from '../build/index.js'
import '../build/globals.js'
describe('core', () => {
- beforeEach(() => {
- $.verbose = false
- })
-
test('only stdout is used during command substitution', async () => {
let hello = await $`echo Error >&2; echo Hello`
let len = +(await $`echo ${hello} | wc -c`)
@@ -340,7 +336,6 @@ describe('core', () => {
resolve()
}
- $.verbose = false
assert.equal($.verbose, false)
within(() => {
@@ -364,7 +359,6 @@ describe('core', () => {
let pwd = await $`pwd`
within(async () => {
- $.verbose = false
cd('/tmp')
setTimeout(async () => {
assert.ok((await $`pwd`).stdout.trim().endsWith('/tmp'))
test/deps.test.js
@@ -18,10 +18,6 @@ import { $ } from '../build/index.js'
import { installDeps, parseDeps } from '../build/deps.js'
describe('deps', () => {
- beforeEach(() => {
- $.verbose = false
- })
-
test('installDeps() loader works via JS API', async () => {
await installDeps({
cpy: '9.0.1',
test/experimental.test.js
@@ -15,8 +15,4 @@
import { describe, before } from 'node:test'
import '../build/globals.js'
-describe('experimental', () => {
- before(() => {
- $.verbose = false
- })
-})
+describe('experimental', () => {})
test/extra.test.js
@@ -13,15 +13,20 @@
// limitations under the License.
import assert from 'node:assert'
-import fs from 'node:fs'
+import fs from 'node:fs/promises'
import { test, describe } from 'node:test'
import { globby } from 'globby'
describe('extra', () => {
test('every file should have a license', async () => {
- const files = await globby(['**/*.{ts,js,mjs}'], { gitignore: true })
+ const files = await globby(['**/*.{js,mjs,ts}'], {
+ gitignore: true,
+ onlyFiles: true,
+ cwd: process.cwd(),
+ followSymbolicLinks: false,
+ })
for (const file of files) {
- const content = fs.readFileSync(file).toString()
+ const content = await fs.readFile(file, 'utf8')
assert(
content
.replace(/\d{4}/g, 'YEAR')
test/goods.test.js
@@ -18,10 +18,6 @@ import { test, describe, beforeEach } from 'node:test'
import '../build/globals.js'
describe('goods', () => {
- beforeEach(() => {
- $.verbose = false
- })
-
function zx(script) {
return $`node build/cli.js --eval ${script}`.nothrow().timeout('5s')
}
test/package.test.js
@@ -18,7 +18,6 @@ import '../build/globals.js'
describe('package', () => {
beforeEach(async () => {
- $.verbose = false
const pack = await $`npm pack`
await $`tar xf ${pack}`
await $`rm ${pack}`.nothrow()
@@ -29,8 +28,6 @@ describe('package', () => {
const out = await within(async () => {
cd('test/fixtures/ts-project')
await $`npm i`
- await $`rm -rf node_modules/zx`
- await $`mv ${pack} node_modules/zx`
try {
await $`npx tsc`
} catch (err) {
@@ -45,10 +42,8 @@ describe('package', () => {
const pack = path.resolve('package')
const out = await within(async () => {
cd('test/fixtures/js-project')
- await $`rm -rf node_modules`
- await $`mkdir node_modules`
- await $`mv ${pack} node_modules/zx`
- return $`node node_modules/zx/build/cli.js script.js`
+ await $`npm i`
+ return $`node node_modules/zx/build/cli.js --verbose script.js`
})
assert.match(out.stderr, /js-script/)
})
test/win32.test.js
@@ -19,10 +19,6 @@ import '../build/globals.js'
const _describe = process.platform === 'win32' ? describe : describe.skip
_describe('win32', () => {
- beforeEach(() => {
- $.verbose = false
- })
-
test('should work with windows-specific commands', async () => {
const p = await $`echo $0` // Bash is first by default.
assert.match(p.stdout, /bash/)
.gitignore
@@ -6,3 +6,4 @@ reports/
.stryker-tmp/
yarn.lock
test/fixtures/ts-project/package-lock.json
+test/fixtures/js-project/package-lock.json
package-lock.json
@@ -15,7 +15,7 @@
"@stryker-mutator/core": "^6.4.2",
"@types/fs-extra": "^11.0.4",
"@types/minimist": "^1.2.5",
- "@types/node": ">=20.11.19",
+ "@types/node": ">=20.11.30",
"@types/which": "^3.0.3",
"@webpod/ps": "^0.0.0-beta.2",
"c8": "^9.1.0",
@@ -1140,9 +1140,9 @@
"dev": true
},
"node_modules/@types/node": {
- "version": "20.11.19",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.19.tgz",
- "integrity": "sha512-7xMnVEcZFu0DikYjWOlRq7NTPETrm7teqUT2WkQjrTIkEgUyyGdWsj/Zg8bEJt5TNklzbPD1X3fqfsHw3SpapQ==",
+ "version": "20.11.30",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-20.11.30.tgz",
+ "integrity": "sha512-dHM6ZxwlmuZaRmUPfv1p+KrdD1Dci04FbdEm/9wEMouFqxYoFl5aMkt0VMAUtYRQDyYvD41WJLukhq/ha3YuTw==",
"dev": true,
"dependencies": {
"undici-types": "~5.26.4"
package.json
@@ -46,7 +46,8 @@
"build:js": "node scripts/build-js.mjs --format=esm --entry=src/*.ts && npm run build:vendor",
"build:vendor": "node scripts/build-js.mjs --format=esm --entry=src/vendor.ts --bundle=all --banner",
"build:dts": "tsc --project tsconfig.prod.json && node scripts/build-dts.mjs",
- "test": "npm run build && node ./test/all.test.js",
+ "test": "npm run build && npm run test:unit && npm run test:types",
+ "test:unit": "node ./test/all.test.js",
"test:types": "tsd",
"coverage": "c8 -x build/vendor.js -x 'test/**' -x scripts --check-coverage npm test",
"mutation": "stryker run",
@@ -61,7 +62,7 @@
"@stryker-mutator/core": "^6.4.2",
"@types/fs-extra": "^11.0.4",
"@types/minimist": "^1.2.5",
- "@types/node": ">=20.11.19",
+ "@types/node": ">=20.11.30",
"@types/which": "^3.0.3",
"@webpod/ps": "^0.0.0-beta.2",
"c8": "^9.1.0",