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

Add globby #178

Merged
merged 3 commits into from
Aug 4, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ The [fs-extra](https://www.npmjs.com/package/fs-extra) package.
let content = await fs.readFile('./package.json')
```

#### `globby` package

The [globby](https://github.com/sindresorhus/globby) package.

```js
let packages = await globby(['package.json', 'packages/*/package.json'])
antonmedv marked this conversation as resolved.
Show resolved Hide resolved

let pictures = globby.globbySync('content/*.(jpg|png)')
```

#### `os` package

The [os](https://nodejs.org/api/os.html) package.
Expand Down
3 changes: 3 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import {ChildProcess} from 'child_process'
import {Readable, Writable} from 'stream'
import * as _fs from 'fs-extra'
import * as _globby from 'globby'
import * as _os from 'os'
import * as _chalk from 'chalk'
import _fetch from 'node-fetch'
Expand Down Expand Up @@ -61,6 +62,7 @@ export const cd: cd
export const chalk: typeof _chalk
export const fetch: typeof _fetch
export const fs: typeof _fs
export const globby: typeof _globby.globby & typeof _globby
export const nothrow: nothrow
export const os: typeof _os
export const question: question
Expand All @@ -74,6 +76,7 @@ declare global {
// @ts-ignore
var fetch: typeof _fetch
var fs: typeof _fs
var globby: typeof _globby.globby & typeof _globby
zloirock marked this conversation as resolved.
Show resolved Hide resolved
var nothrow: nothrow
var os: typeof _os
var question: question
Expand Down
6 changes: 6 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

import fs from 'fs-extra'
import * as globbyModule from 'globby'
import os from 'os'
import {promisify, inspect} from 'util'
import {spawn} from 'child_process'
Expand Down Expand Up @@ -79,6 +80,10 @@ export function $(pieces, ...args) {

export const argv = minimist(process.argv.slice(2))

export const globby = Object.assign(function globby(...args) {
return globbyModule.globby(...args)
}, globbyModule)

$.verbose = !argv.quiet
if (typeof argv.shell === 'string') {
$.shell = argv.shell
Expand Down Expand Up @@ -261,6 +266,7 @@ Object.assign(global, {
chalk,
fetch,
fs,
globby,
nothrow,
os,
question,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/node-fetch": "^2.5.10",
"chalk": "^4.1.1",
"fs-extra": "^10.0.0",
"globby": "^12.0.0",
"minimist": "^1.2.5",
"node-fetch": "^2.6.1",
"which": "^2.0.2"
Expand Down
14 changes: 13 additions & 1 deletion test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import {strict as assert} from 'assert'
import {strict as assert, deepEqual} from 'assert'

{ // Only stdout is used during command substitution
let hello = await $`echo Error >&2; echo Hello`
Expand Down Expand Up @@ -133,6 +133,18 @@ import {strict as assert} from 'assert'
assert(exitCode === 42)
}

{ // globby available
assert(typeof globby === 'function')
assert(typeof globby.globbySync === 'function')
assert(typeof globby.globbyStream === 'function')
assert(typeof globby.generateGlobTasks === 'function')
assert(typeof globby.isDynamicPattern === 'function')
assert(typeof globby.isGitIgnored === 'function')
assert(typeof globby.isGitIgnoredSync === 'function')
deepEqual(await globby('*.mjs'), ['index.mjs', 'test.mjs', 'zx.mjs'])
console.log(chalk.greenBright('globby available'))
}

{ // require() is working in ESM
const {name, version} = require('./package.json')
assert(typeof name === 'string')
Expand Down