From 731d48f94343b25e440baa9012652f0772993d30 Mon Sep 17 00:00:00 2001 From: Tom Dracz Date: Fri, 8 Mar 2024 20:22:55 +0000 Subject: [PATCH] Remove dependency on glob --- package.json | 1 - package/environments/base.js | 23 ++++++++++++++++++++--- yarn.lock | 2 +- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 4e78c9ae6..c1248db4a 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$" }, "dependencies": { - "glob": "^7.2.0", "js-yaml": "^4.1.0", "path-complete-extname": "^1.0.0" }, diff --git a/package/environments/base.js b/package/environments/base.js index e047f4e19..ecfeca044 100644 --- a/package/environments/base.js +++ b/package/environments/base.js @@ -1,9 +1,9 @@ /* eslint global-require: 0 */ /* eslint import/no-dynamic-require: 0 */ +const { existsSync, readdirSync } = require('fs') const { basename, dirname, join, relative, resolve } = require('path') const extname = require('path-complete-extname') -const { sync: globSync } = require('glob') const WebpackAssetsManifest = require('webpack-assets-manifest') const webpack = require('webpack') const rules = require('../rules') @@ -11,6 +11,24 @@ const config = require('../config') const { isProduction } = require('../env') const { moduleExists } = require('../utils/helpers') +const getFilesInDirectory = (dir, includeNested) => { + if (!existsSync(dir)) { + return [] + } + + return readdirSync(dir, { withFileTypes: true }).flatMap((dirent) => { + const filePath = join(dir, dirent.name) + + if (dirent.isDirectory() && includeNested) { + return getFilesInDirectory(filePath, includeNested) + } + if (dirent.isFile()) { + return filePath + } + return [] + }) +} + const getEntryObject = () => { const entries = {} const rootPath = join(config.source_path, config.source_entry_path) @@ -20,9 +38,8 @@ const getEntryObject = () => { "'true'. Doing this would result in packs for every one of your source files" ) } - const nesting = config.nested_entries ? '**/' : '' - globSync(`${rootPath}/${nesting}*.*`).forEach((path) => { + getFilesInDirectory(rootPath, config.nested_entries).forEach((path) => { const namespace = relative(join(rootPath), dirname(path)) const name = join(namespace, basename(path, extname(path))) let assetPaths = resolve(path) diff --git a/yarn.lock b/yarn.lock index ce95bb5f5..c12ad7c0f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2263,7 +2263,7 @@ glob-to-regexp@^0.4.1: resolved "https://registry.yarnpkg.com/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz#c75297087c851b9a578bd217dd59a92f59fe546e" integrity sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw== -glob@^7.1.3, glob@^7.1.4, glob@^7.2.0: +glob@^7.1.3, glob@^7.1.4: version "7.2.0" resolved "https://registry.yarnpkg.com/glob/-/glob-7.2.0.tgz#d15535af7732e02e948f4c41628bd910293f6023" integrity sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==