Skip to content

Commit ccb9af4

Browse files
committed
[INTERNAL] index.js: Implement lazy require
Exported modules are required on access
1 parent b9856e8 commit ccb9af4

File tree

1 file changed

+24
-5
lines changed

1 file changed

+24
-5
lines changed

index.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
* @module module:@ui5/project
33
* @public
44
*/
5-
module.exports = {
6-
normalizer: require("./lib/normalizer"),
7-
projectPreprocessor: require("./lib/projectPreprocessor"),
5+
const modules = {
6+
normalizer: "./lib/normalizer",
7+
projectPreprocessor: "./lib/projectPreprocessor",
88
/**
99
* @public
1010
* @see module:@ui5/project.ui5Framework
@@ -29,7 +29,26 @@ module.exports = {
2929
* @namespace
3030
*/
3131
translators: {
32-
"npm": require("./lib/translators/npm"),
33-
"static": require("./lib/translators/static")
32+
"npm": "./lib/translators/npm",
33+
"static": "./lib/translators/static"
3434
}
3535
};
36+
37+
function exportModules(exportRoot, modulePaths) {
38+
for (const moduleName in modulePaths) {
39+
if (modulePaths.hasOwnProperty(moduleName)) {
40+
if (typeof modulePaths[moduleName] === "object") {
41+
exportRoot[moduleName] = {};
42+
exportModules(exportRoot[moduleName], modulePaths[moduleName]);
43+
} else {
44+
Object.defineProperty(exportRoot, moduleName, {
45+
get() {
46+
return require(modulePaths[moduleName]);
47+
}
48+
});
49+
}
50+
}
51+
}
52+
}
53+
54+
exportModules(module.exports, modules);

0 commit comments

Comments
 (0)