Commit 3f5d50a

Denis Pushkarev <zloirock@zloirock.ru>
2021-08-04 11:28:29
Add `globby` (#178)
* add `globby` * add `globby` to `.d.ts` * prevent `globbyModule.globby` mutation
1 parent b6a52f9
index.d.ts
@@ -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'
@@ -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
@@ -74,6 +76,7 @@ declare global {
   // @ts-ignore
   var fetch: typeof _fetch
   var fs: typeof _fs
+  var globby: typeof _globby.globby & typeof _globby
   var nothrow: nothrow
   var os: typeof _os
   var question: question
index.mjs
@@ -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'
@@ -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
@@ -261,6 +266,7 @@ Object.assign(global, {
   chalk,
   fetch,
   fs,
+  globby,
   nothrow,
   os,
   question,
package.json
@@ -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"
README.md
@@ -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'])
+
+let pictures = globby.globbySync('content/*.(jpg|png)')
+```
+
 #### `os` package
 
 The [os](https://nodejs.org/api/os.html) package.
test.mjs
@@ -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`
@@ -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')