Gathering detailed insights and metrics for glob-module-file
Gathering detailed insights and metrics for glob-module-file
Gathering detailed insights and metrics for glob-module-file
Gathering detailed insights and metrics for glob-module-file
expandglob
Node.js module to expand glob file patterns.
resolve-dep
Return an array of resolved filepaths for require-able local or named npm modules. Wildcard (glob) patterns may be used.
glob-ext
Simple wrapper of glob module with multi file extension support
package-json-exports
A file based package.json exports generator depending on fast-glob
Generate a file of code that imports/requires a bunch of files, and exports them as an array
npm install glob-module-file
Typescript
Module System
Node Version
NPM Version
67.8
Supply Chain
97.6
Quality
73.6
Maintenance
100
Vulnerability
99.6
License
JavaScript (100%)
Total Downloads
65,485
Last Day
1
Last Week
110
Last Month
409
Last Year
3,518
5 Stars
41 Commits
2 Forks
2 Watchers
2 Branches
2 Contributors
Updated on Mar 14, 2023
Minified
Minified + Gzipped
Latest Version
3.2.0
Package Id
glob-module-file@3.2.0
Unpacked Size
14.69 kB
Size
4.65 kB
File Count
12
NPM Version
8.1.4
Node Version
18.2.0
Published on
Mar 14, 2023
Cumulative downloads
Total Downloads
Pass in a file pattern and an output path, and a file will be created that imports all the matching files, and then exports them as a single array.
It's really nice to be able to auto-initialize a whole bunch of parts of your application, without having to maintain a list of modules to require in your index.js:
1// Maintaining this is inconvenient 2const coolService = require('./service/cool/the-coolest.js') 3const niftyService = require('./service/nifty/nearly-as-cool.js') 4const yetAnotherService = require('./service/hope-you-didnt-forget-any-other-files.js') 5 6coolService(initialConfig) 7niftyService(initialConfig) 8yetAnotherService(initialConfig)
To avoid dealing with such ever-growing lists of modules, I've used this pattern in node.js code:
1glob.sync('service/**/*.js', { ignore: 'service/**/*.test.js' }) 2.map(file => require(`./${file}`)) 3.forEach(moduleFunction => { 4 moduleFunction(initialConfig) 5})
It finds all the js files in a part of the application's directory tree, require
s them, and then runs them as a function passing in some initial options.
The above code doesn't work for client-side apps built with a bundler.
Bundlers must be able to tell which files will be loaded by reading the code, without executing it.
So, you're back to maintaining a long list imports/requires somewhere. Unless you use this library.
Given these files:
fixtures/one.js
fixtures/someDirectory/two.js
Calling this library and passing in fixtures/**/*.js
and my-globbed-files.js
will cause it to spit out a file containing:
1const fixtures$47$one$46$js = require('./fixtures/one.js') 2const fixtures$47$someDirectory$47$two$46$js = require('./fixtures/someDirectory/two.js') 3 4module.exports = [ 5 fixtures$47$one$46$js, 6 fixtures$47$someDirectory$47$two$46$js, 7]
or, for es6 module bundlers:
1import fixtures$47$one$46$js from './fixtures/one.js' 2import fixtures$47$someDirectory$47$two$46$js from './fixtures/someDirectory/two.js' 3 4export default [ 5 fixtures$47$one$46$js, 6 fixtures$47$someDirectory$47$two$46$js, 7]
Then, all your index file needs to do is
1require('my-globbed-files.js').forEach(moduleFunction => { 2 moduleFunction(initialConfig) 3})
globModuleFile(options, [globOptions])
Returns a promise that resolves to the JS code with all the requires/imports and exports.
If an outputPath
is provided, the promise will not resolve until after the file is done being written.
options
pattern
: (required): Passed to glob.outputPath
: A file to be created or overwritten with all of the import code.exportWithPath
: If false, exports whatever value was imported from the original file. If true, exports an object { path: thePathStringThatWasImported, export: theObjectExportedFromTheGlobbedFile }
. Defaults to false
.format
: Specify the module output - either the string es
(import/export) or cjs
(require/module.exports). Defaults to cjs
sortFunction
: A comparison function to be passed to Array.sort
to determine the order to import the files in (and determine their order in the output array). Defaults to a function that orders by how deep in the directory structure the file is (shallowest to deepest).pathPrefix
: A string to be prepended to the paths passed to require
. Defaults to ./
importStar
: whether to use import * as whateverExport
instead of import defaultExport
when outputting ES module syntax. Defaults to false
globOptions
Optional. Passed straight through as the options argument to glob
.
1const expected = `const fixtures$47$one$46$js = require('./fixtures/one.js') 2const fixtures$47$someDirectory$47$two$46$js = require('./fixtures/someDirectory/two.js') 3 4module.exports = [ 5\tfixtures$47$one$46$js, 6\tfixtures$47$someDirectory$47$two$46$js, 7] 8` 9 10globModuleFiles({ pattern: 'fixtures/**/*.js', outputPath: '/tmp/globbed.js' }).then(code => { 11 code // => expected 12 13 require('fs').readFileSync('/tmp/globbed.js', { encoding: 'utf8' }) // => code 14}).catch(err => { 15 console.error(err) 16})
1glob-module-file --pattern="fixtures/**/*.js" --format=es --ignore="**/one.js"
Takes any number of named arguments corresponding to the options objects above.
Spits the code to stdout so you can pipe it into a file or what have you.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/25 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
28 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreLast Day
0%
1
Compared to previous day
Last Week
74.6%
110
Compared to previous week
Last Month
49.8%
409
Compared to previous month
Last Year
61.9%
3,518
Compared to previous year