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: export which package as global #347

Merged
merged 4 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Expand Up @@ -3,4 +3,5 @@ Fixes #<issue_number_goes_here>
> It's a good idea to open an issue first for discussion.

- [ ] Tests pass
- [ ] Appropriate changes to README are included in PR
- [ ] Appropriate changes to README are included in PR
- [ ] Types updated
10 changes: 10 additions & 0 deletions README.md
Expand Up @@ -300,6 +300,16 @@ The [minimist](https://www.npmjs.com/package/minimist) package.

Available as global const `argv`.

#### `which`

The [which](https://github.com/npm/node-which) package.

```js
let node = await which('node')

let node = which.sync('node')
```

### Configuration

#### `$.shell`
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -32,6 +32,7 @@
"@types/fs-extra": "^9.0.13",
"@types/minimist": "^1.2.2",
"@types/node": "^17.0",
"@types/which": "^2.0.1",
"chalk": "^5.0.1",
"fs-extra": "^10.0.1",
"globby": "^13.1.1",
Expand Down
2 changes: 2 additions & 0 deletions src/globals.d.ts
Expand Up @@ -11,6 +11,7 @@ import {
path as _path,
question,
sleep,
which as _which,
} from './index'

declare global {
Expand All @@ -28,4 +29,5 @@ declare global {
var path: typeof _path
var question: question
var sleep: sleep
var which: typeof _which
}
2 changes: 2 additions & 0 deletions src/index.d.ts
Expand Up @@ -22,6 +22,7 @@ import {ChalkInstance} from 'chalk'
import * as _yaml from 'yaml'
import _fetch from 'node-fetch'
import {ParsedArgs} from 'minimist'
import * as _which from 'which'

interface $ {
(pieces: TemplateStringsArray, ...args: any[]): ProcessPromise<ProcessOutput>
Expand Down Expand Up @@ -78,3 +79,4 @@ export const path: typeof _path
export const question: question
export const sleep: sleep
export const quiet: quiet
export const which: typeof _which
3 changes: 2 additions & 1 deletion src/index.mjs
Expand Up @@ -26,7 +26,7 @@ import YAML from 'yaml'
import minimist from 'minimist'
import psTreeModule from 'ps-tree'

export {chalk, fs, os, path, YAML}
export {chalk, fs, os, path, YAML, which}
export const sleep = promisify(setTimeout)
export const argv = minimist(process.argv.slice(2))
export const globby = Object.assign(function globby(...args) {
Expand All @@ -52,6 +52,7 @@ export function registerGlobals() {
question,
sleep,
YAML,
which,
})
}

Expand Down
4 changes: 4 additions & 0 deletions test.mjs
Expand Up @@ -257,6 +257,10 @@ if (test('Retry works')) {
assert(Date.now() >= now + 50 * (5 - 1))
}

if (test('which available')) {
assert.equal(which.sync('npm'), await which('npm'))
}

let version
if (test('require() is working in ESM')) {
let data = require('./package.json')
Expand Down