Skip to content

Commit 6bd951f

Browse files
authored
Merge pull request #2 from sdinteractive/sandbox-inject
Allow injecting variables into requirejs-config sandbox
2 parents 6e2c0d9 + 69bc18d commit 6bd951f

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const vm = require('vm');
44

55
function RequireJsResolverPlugin(options) {
66
this.configPath = options.configPath;
7+
this.sandbox = options.sandbox || {};
78
}
89

910
RequireJsResolverPlugin.prototype.getConfig = function(fs) {
@@ -24,11 +25,11 @@ RequireJsResolverPlugin.prototype.getConfig = function(fs) {
2425
return this.configData;
2526
}
2627

27-
var sandbox = {
28+
let sandbox = Object.assign({
2829
paths: {},
2930
require: function() {
3031
},
31-
};
32+
}, this.sandbox);
3233
sandbox.require.addPaths = function(paths) {
3334
for (var path in paths) {
3435
sandbox.paths[path] = paths[path];
@@ -65,7 +66,9 @@ RequireJsResolverPlugin.prototype.apply = function(resolver) {
6566
} else {
6667
callback();
6768
}
68-
})
69+
}, err => {
70+
callback(err);
71+
});
6972
});
7073
};
7174

0 commit comments

Comments
 (0)