Commit be5bae0

Anton Golub <mailbox@antongolub.ru>
2022-03-14 13:21:01
feat: print zx version in std semver format (#338)
1 parent 15d500d
package.json
@@ -6,7 +6,8 @@
   "exports": {
     ".": "./index.mjs",
     "./globals": "./globals.mjs",
-    "./experimental": "./experimental.mjs"
+    "./experimental": "./experimental.mjs",
+    "./package.json": "./package.json"
   },
   "types": "index.d.ts",
   "bin": {
test.mjs
@@ -256,6 +256,7 @@ if (test('require() is working in ESM')) {
   let data = require('./package.json')
   version = data.version
   assert.equal(data.name, 'zx')
+  assert.equal(data, require('zx/package.json'))
 }
 
 console.log('\n' +
zx.mjs
@@ -25,8 +25,8 @@ import {fetch, ProcessOutput} from './index.mjs'
 
 await async function main() {
   try {
-    if (['--version', '-v', '-V'].includes(process.argv[2] || '')) {
-      console.log(`zx version ${createRequire(import.meta.url)('./package.json').version}`)
+    if (['--version', '-v', '-V'].includes(process.argv[2])) {
+      console.log(createRequire(import.meta.url)('./package.json').version)
       return process.exitCode = 0
     }
     let firstArg = process.argv.slice(2).find(a => !a.startsWith('--'))
@@ -202,5 +202,6 @@ function printUsage() {
    --quiet            : don't echo commands
    --shell=<path>     : custom shell binary
    --prefix=<command> : prefix all commands
+   --version, -v      : print current zx version
 `)
 }