-
Notifications
You must be signed in to change notification settings - Fork 1
/
injectorTemplate.js
41 lines (33 loc) · 1.11 KB
/
injectorTemplate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module.exports = "ORIGINAL_DEFINE{ \
var originalDeps = arguments; \
return " + function (mocks) {
// Create a custom define method which the original module will
// use to resolve dependencies. If a mock is passed for a given path
// the mock will be used, otherwise the original dependency will be
// loaded.
var __defined_module__;
var __define__ = function (paths, definition) {
var deps = [];
function relsoveDependency (path, index) {
index = index || 0;
if(mocks && mocks[path]) {
deps.push(mocks[path])
} else {
deps.push(originalDeps[index]);
}
}
if (paths) {
if(typeof paths === 'string') {
relsoveDependency(paths);
} else {
paths.forEach(relsoveDependency);
}
}
__defined_module__ = definition.apply(this, deps);
}
return (function () {
SOURCE
return __defined_module__;
})();
}.toString() + "; \
});";