From fc57a7b06751e9bb1f6d6ac6e5e1a903ea8a9c8d Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Wed, 4 Aug 2021 02:46:49 +0700 Subject: [PATCH 1/3] add `globby` --- README.md | 10 ++++++++++ index.mjs | 4 ++++ package.json | 1 + test.mjs | 14 +++++++++++++- 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 53d3aedc15..de0e7db7d1 100644 --- a/README.md +++ b/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. diff --git a/index.mjs b/index.mjs index 06454da80f..309765c498 100644 --- a/index.mjs +++ b/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,8 @@ export function $(pieces, ...args) { export const argv = minimist(process.argv.slice(2)) +export const globby = Object.assign(globbyModule.globby, globbyModule) + $.verbose = !argv.quiet if (typeof argv.shell === 'string') { $.shell = argv.shell @@ -261,6 +264,7 @@ Object.assign(global, { chalk, fetch, fs, + globby, nothrow, os, question, diff --git a/package.json b/package.json index 258a88312f..298b4cf545 100644 --- a/package.json +++ b/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" diff --git a/test.mjs b/test.mjs index edafd4a15c..e1ba50acea 100755 --- a/test.mjs +++ b/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') From 79e3e27bec63a135f0a21d9b31c3e38b119fbb05 Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Wed, 4 Aug 2021 03:59:10 +0700 Subject: [PATCH 2/3] add `globby` to `.d.ts` --- index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.d.ts b/index.d.ts index 7e76fe906a..94a40f8f20 100644 --- a/index.d.ts +++ b/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 From 0cb1f0283f41e69b22748d8a097a47894be7f8eb Mon Sep 17 00:00:00 2001 From: Denis Pushkarev Date: Wed, 4 Aug 2021 15:05:41 +0700 Subject: [PATCH 3/3] prevent `globbyModule.globby` mutation --- index.mjs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/index.mjs b/index.mjs index 309765c498..4630302603 100644 --- a/index.mjs +++ b/index.mjs @@ -80,7 +80,9 @@ export function $(pieces, ...args) { export const argv = minimist(process.argv.slice(2)) -export const globby = Object.assign(globbyModule.globby, globbyModule) +export const globby = Object.assign(function globby(...args) { + return globbyModule.globby(...args) +}, globbyModule) $.verbose = !argv.quiet if (typeof argv.shell === 'string') {