diff --git a/package.json b/package.json index 46cceabec4..58afba8d80 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,6 @@ "@types/flush-write-stream": "1.0.0", "@types/from2": "2.3.0", "@types/fs-extra": "9.0.6", - "@types/fs-readdir-recursive": "1.0.0", "@types/gulp-if": "0.0.33", "@types/htmlescape": "^1.1.1", "@types/ink-spinner": "3.0.0", diff --git a/packages/generator/package.json b/packages/generator/package.json index 5deeb1005f..7277788951 100644 --- a/packages/generator/package.json +++ b/packages/generator/package.json @@ -40,7 +40,6 @@ "diff": "5.0.0", "enquirer": "2.3.6", "fs-extra": "^9.1.0", - "fs-readdir-recursive": "1.1.0", "got": "^11.8.1", "jscodeshift": "0.11.0", "mem-fs": "1.2.0", diff --git a/packages/generator/src/generator.ts b/packages/generator/src/generator.ts index 4cf3e46c72..9c49317767 100644 --- a/packages/generator/src/generator.ts +++ b/packages/generator/src/generator.ts @@ -5,7 +5,6 @@ import {log} from "@blitzjs/display" import Enquirer from "enquirer" import {EventEmitter} from "events" import * as fs from "fs-extra" -import readDirRecursive from "fs-readdir-recursive" import j from "jscodeshift" import {Collection} from "jscodeshift/src/Collection" import {create as createStore, Store} from "mem-fs" @@ -15,6 +14,7 @@ import getBabelOptions, {Overrides} from "recast/parsers/_babel_options" import * as babelParser from "recast/parsers/babel" import {ConflictChecker} from "./conflict-checker" import {pipe} from "./utils/pipe" +import {readdirRecursive} from "./utils/readdir-recursive" const debug = require("debug")("blitz:generator") export const customTsParser = { @@ -229,7 +229,7 @@ export abstract class Generator< async write(): Promise { debug("Generator.write...") - const paths = readDirRecursive(this.sourcePath(), (name) => { + const paths = await readdirRecursive(this.sourcePath(), (name) => { const additionalFilesToIgnore = this.filesToIgnore() return ![...alwaysIgnoreFiles, ...additionalFilesToIgnore].includes(name) }) diff --git a/packages/generator/src/utils/readdir-recursive.ts b/packages/generator/src/utils/readdir-recursive.ts new file mode 100644 index 0000000000..485e310519 --- /dev/null +++ b/packages/generator/src/utils/readdir-recursive.ts @@ -0,0 +1,24 @@ +import fs from "fs/promises" +import path from "path" + +type Filter = (name: string, dir: string) => boolean + +export async function readdirRecursive(root: string, filter?: Filter, dir = ""): Promise { + const absoluteDir = path.resolve(root, dir) + const dirStats = await fs.stat(absoluteDir) + + if (dirStats.isDirectory()) { + let entries = await fs.readdir(absoluteDir) + + if (filter) { + entries = entries.filter((name) => filter(name, dir)) + } + + const recursiveList = await Promise.all( + entries.map((name) => readdirRecursive(root, filter, path.join(dir, name))), + ) + return recursiveList.flat(Infinity) as string[] + } else { + return [dir] + } +} diff --git a/yarn.lock b/yarn.lock index 0edb985be5..ac14e9aa21 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3908,11 +3908,6 @@ dependencies: "@types/node" "*" -"@types/fs-readdir-recursive@1.0.0": - version "1.0.0" - resolved "https://registry.yarnpkg.com/@types/fs-readdir-recursive/-/fs-readdir-recursive-1.0.0.tgz#404f77bdadc6b90cccd3f04d15f6dd85cdde38ef" - integrity sha512-1w3aDEWvddRoBCPm3hdGehNovSvqwe30dxplDH5bjZXoMCDVbntkbNENxfyScS4kYsovJYcwLPxJ9gjN/hh2Xg== - "@types/glob-stream@*": version "6.1.0" resolved "https://registry.yarnpkg.com/@types/glob-stream/-/glob-stream-6.1.0.tgz#7ede8a33e59140534f8d8adfb8ac9edfb31897bc" @@ -9548,11 +9543,6 @@ fs-mkdirp-stream@^1.0.0: graceful-fs "^4.1.11" through2 "^2.0.3" -fs-readdir-recursive@1.1.0: - version "1.1.0" - resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27" - integrity sha512-GNanXlVr2pf02+sPN40XN8HG+ePaNcvM0q5mZBd668Obwb0yD5GiUbZOFgwn8kGMY6I3mdyDJzieUy3PTYyTRA== - fs-write-stream-atomic@^1.0.8: version "1.0.10" resolved "https://registry.yarnpkg.com/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz#b47df53493ef911df75731e70a9ded0189db40c9"