Commit 0109e06

henrycunh <henrycunh@gmail.com>
2022-01-24 20:11:51
feat: add yaml dependency (#274)
* feat: add yaml dependency * docs: add yaml package entry to readme * ref: rename YAML package and add declaration Co-authored-by: Anton Medvedev <antonmedv@google.com>
1 parent 1ad81de
index.d.ts
@@ -19,6 +19,7 @@ import * as _globby from 'globby'
 import * as _os from 'os'
 import * as _path from 'path'
 import * as _chalk from 'chalk'
+import * as _yaml from 'yaml'
 import _fetch from 'node-fetch'
 import {ParsedArgs} from 'minimist'
 
@@ -63,6 +64,7 @@ export const argv: ParsedArgs
 export const cd: cd
 export const chalk: typeof _chalk
 export const fetch: typeof _fetch
+export const YAML: typeof _yaml
 export const fs: typeof _fs
 export const glob: typeof _globby.globby & typeof _globby
 export const globby: typeof _globby.globby & typeof _globby
index.mjs
@@ -22,10 +22,11 @@ import {createInterface} from 'readline'
 import {default as nodeFetch} from 'node-fetch'
 import which from 'which'
 import chalk from 'chalk'
+import YAML from 'yaml'
 import minimist from 'minimist'
 import psTreeModule from 'ps-tree'
 
-export {chalk, fs, os, path}
+export {chalk, fs, os, path, YAML}
 export const sleep = promisify(setTimeout)
 export const argv = minimist(process.argv.slice(2))
 export const globby = Object.assign(function globby(...args) {
@@ -49,6 +50,7 @@ export function registerGlobals() {
     path,
     question,
     sleep,
+    YAML,
   })
 }
 
package-lock.json
@@ -19,7 +19,8 @@
         "minimist": "^1.2.5",
         "node-fetch": "^2.6.1",
         "ps-tree": "^1.2.0",
-        "which": "^2.0.2"
+        "which": "^2.0.2",
+        "yaml": "^1.10.2"
       },
       "bin": {
         "zx": "zx.mjs"
@@ -918,6 +919,14 @@
       "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
       "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
       "dev": true
+    },
+    "node_modules/yaml": {
+      "version": "1.10.2",
+      "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
+      "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg==",
+      "engines": {
+        "node": ">= 6"
+      }
     }
   },
   "dependencies": {
@@ -1581,6 +1590,11 @@
       "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
       "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=",
       "dev": true
+    },
+    "yaml": {
+      "version": "1.10.2",
+      "resolved": "https://registry.npmjs.org/yaml/-/yaml-1.10.2.tgz",
+      "integrity": "sha512-r3vXyErRCYJ7wg28yvBY5VSoAF8ZvlcW9/BwUzEtUsjvX/DKs24dIkuwjtuprwJJHsbyUbLApepYTR1BN4uHrg=="
     }
   }
 }
package.json
@@ -36,7 +36,8 @@
     "minimist": "^1.2.5",
     "node-fetch": "^2.6.1",
     "ps-tree": "^1.2.0",
-    "which": "^2.0.2"
+    "which": "^2.0.2",
+    "yaml": "^1.10.2"
   },
   "devDependencies": {
     "@rollup/plugin-commonjs": "^20.0.0",
README.md
@@ -233,6 +233,14 @@ The [chalk](https://www.npmjs.com/package/chalk) package.
 console.log(chalk.blue('Hello world!'))
 ```
 
+#### `yaml` package
+
+The [yaml](https://www.npmjs.com/package/yaml) package.
+
+```js
+console.log(YAML.parse('foo: bar').foo)
+```
+
 #### `fs` package
 
 The [fs-extra](https://www.npmjs.com/package/fs-extra) package.
test.mjs
@@ -227,4 +227,16 @@ import {strict as assert} from 'assert'
   console.log(chalk.black.bgYellowBright(` ${name} version is ${version} `))
 }
 
+{ // yaml parsing and stringifying is available
+  assert(typeof YAML === 'object')
+  assert(typeof YAML.parse === 'function')
+  assert(typeof YAML.stringify === 'function')
+  console.log(chalk.greenBright('yaml parsing and stringifying is available'))
+}
+
+{ // yaml parsing and stringifying works
+  assert.deepEqual(YAML.parse(YAML.stringify({foo: 'bar'})), {foo: 'bar'})
+  console.log(chalk.greenBright('yaml parsing and stringifying works'))
+}
+
 console.log(chalk.greenBright(' 🍺 Success!'))