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

Remove dependency on glob #435

Merged
merged 2 commits into from
Mar 10, 2024
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ Changes since the last non-beta release.
- Emit warnings instead of errors when compilation is success but stderr is not empty. [PR 416](https://github.com/shakacode/shakapacker/pull/416) by [n-rodriguez](https://github.com/n-rodriguez).
- Allow `webpack-dev-server` v5. [PR 418](https://github.com/shakacode/shakapacker/pull/418) by [G-Rath](https://github.com/g-rath)

### Removed
- Removes dependency on `glob` library. [PR 435](https://github.com/shakacode/shakapacker/pull/435) by [tomdracz](https://github.com/tomdracz).

## [v7.2.2] - January 19, 2024

### Added
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$"
},
"dependencies": {
"glob": "^7.2.0",
"js-yaml": "^4.1.0",
"path-complete-extname": "^1.0.0"
},
Expand Down
23 changes: 20 additions & 3 deletions package/environments/base.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
/* 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')
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 []
})
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@G-Rath Is that the kind of thing you had in mind when talking about using readdirSync elsewhere?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup you've got it!

You could also check on Node 18+ to see if you get the same output with using recursive

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified recursive gives expected results when supported on Node 18+

Screenshot 2024-03-09 at 09 44 34

const getEntryObject = () => {
const entries = {}
const rootPath = join(config.source_path, config.source_entry_path)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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==
Expand Down
Loading