For CommonJS modules, you can make a parent module that collects all the exports from a set of sub-modules and then exports them all as part of one main object. Here's some code I used in one of my projects that does that:
// this just re-exports everything that the sub-modules export
module.exports = [
'./mapConcurrent.js',
'./deferred.js',
'./utils.js',
'./rateMap.js',
'./concurrency.js',
'./retry.js',
].reduce((obj, file) => {
const m = require(file);
Object.assign(obj, m);
return obj;
}, {});
I put this in an index.js
file that then allowed a user of this module to just require()
the directory name and they would get an imported object with all the entry points on it for the whole module.
Note: This assumes that none of the exported symbols in any of the sub-modules have conflicting names. That is under your own control to manage so that's a requirement to do this.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…