Skip to content

Commit f824c72

Browse files
committed
CLJS-3147: Allow Node require from foreign lib
Export require to global.
1 parent 885238e commit f824c72

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/main/cljs/cljs/bootstrap_nodejs.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,26 @@ global.CLOSURE_LOAD_FILE_SYNC = function(src) {
108108

109109
// Declared here so it can be used to require base.js
110110
function nodeGlobalRequire(file) {
111-
var _module = global.module, _exports = global.exports;
111+
var _module = global.module,
112+
_exports = global.exports,
113+
exportedRequire = false;
114+
112115
global.module = undefined;
113116
global.exports = undefined;
117+
118+
if(global.require == undefined) {
119+
exportedRequire = true;
120+
global.require = require;
121+
}
122+
114123
vm.runInThisContext.call(global, fs.readFileSync(file), file);
124+
115125
global.exports = _exports;
116126
global.module = _module;
127+
128+
if(exportedRequire) {
129+
global.require = undefined;
130+
}
117131
}
118132

119133

0 commit comments

Comments
 (0)