Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add yaml dependency #274

Merged
merged 4 commits into from
Jan 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {createInterface} from 'readline'
import {default as nodeFetch} from 'node-fetch'
import which from 'which'
import chalk from 'chalk'
import yamljs from 'yaml'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget to upgrade .d.ts as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import minimist from 'minimist'
import psTreeModule from 'ps-tree'

Expand All @@ -32,6 +33,7 @@ export const globby = Object.assign(function globby(...args) {
return globbyModule.globby(...args)
}, globbyModule)
export const glob = globby
export const yaml = { parse: yamljs.parse, stringify: yamljs.stringify }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's export everything. And let's use YAML same as JSON.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const psTree = promisify(psTreeModule)

export function registerGlobals() {
Expand All @@ -49,6 +51,7 @@ export function registerGlobals() {
path,
question,
sleep,
yaml,
})
}

Expand Down
20 changes: 17 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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",
Expand Down
12 changes: 12 additions & 0 deletions test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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!'))