Commit 6726292

Anton Golub <antongolub@antongolub.com>
2022-04-25 20:50:58
feat: add zx.mjs to pkg exports (#402)
* feat: add zx.mjs to pkg exports * docs: add basic customization guides
1 parent 88ab61e
package.json
@@ -8,6 +8,7 @@
     ".": "./src/index.mjs",
     "./globals": "./src/globals.mjs",
     "./experimental": "./src/experimental.mjs",
+    "./cli": "./zx.mjs",
     "./package.json": "./package.json"
   },
   "bin": {
README.md
@@ -566,6 +566,31 @@ jobs:
         EOF
 ```
 
+### Customizing
+
+You can build your very own custom zx version that best suits your needs.
+```ts
+// index.js
+import {$} from 'zx'
+
+$.quote = () => {}
+$.extraFn = async () => {
+    await $`ping example.com`
+    await $`npm whoami`
+}
+
+// cli.js
+#!/usr/bin/env node
+
+import './index.js'
+import 'zx/cli'
+
+// script.mjs
+await $.extraFn()
+
+// zx-custom script.mjs
+```
+
 ## License
 
 [Apache-2.0](LICENSE)
zx.mjs
@@ -15,10 +15,10 @@
 // limitations under the License.
 
 import fs from 'fs-extra'
-import {createRequire} from 'module'
-import {tmpdir} from 'os'
-import {basename, dirname, extname, join, resolve} from 'path'
-import url from 'url'
+import {createRequire} from 'node:module'
+import {tmpdir} from 'node:os'
+import {basename, dirname, extname, join, resolve} from 'node:path'
+import url from 'node:url'
 
 import {$, argv, fetch, ProcessOutput, registerGlobals} from './src/index.mjs'