-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
node-integration-iframe.mustache.js
61 lines (55 loc) · 2.38 KB
/
node-integration-iframe.mustache.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
(function () {
// Based off of https://github.com/atom/electron/blob/v0.36.9/atom/common/lib/init.js#L34-L47
// Bind parent window's node integration to this closure
// DEV: Due to using an `iframe`, we lose the node integration inheritance =/
// DEV: We use a closure since `__filename`/`__dirname` and relative requires change based on file
// DEV: We skip error handlers so Karma can catch them
var __parentWindow = window.parent || {};
var module = __parentWindow.module ? __parentWindow.module : undefined;
// DEV: Ignore JSHint errors about unused variables
// jshint ignore:start
var process = __parentWindow.process ? __parentWindow.process : undefined;
var setImmediate = __parentWindow.setImmediate ? __parentWindow.setImmediate : undefined;
var clearImmediate = __parentWindow.clearImmediate ? __parentWindow.clearImmediate : undefined;
var global = __parentWindow.module ? window : undefined;
// jshint ignore:end
var __filename = __parentWindow.module ? '{{!filename}}' : undefined;
var __dirname = __parentWindow.module ? '{{!dirname}}' : undefined;
// Set up local requires
var require;
if (__filename) {
// Save original require/require.resolve
var __require = __parentWindow.require;
var __requireResolve = __require.resolve;
// Add our base directory as the path to find node modules from
if (!window.__karmaBasePathAddedToModule) {
module.paths = module.paths.concat(__require('module')._nodeModulePaths('{{!karmaBasePath}}'));
window.__karmaBasePathAddedToModule = true;
}
// Define our patched require/require.resolve
var __requireFilepath = function (filepath) {
// If the filepath is relative, prepend the filename
// e.g. `./submodule` -> `/home/todd/.../integration-test/./submodule`
if (filepath && filepath[0] === '.') {
filepath = __dirname + '{{!sep}}' + filepath;
}
// Return our filepath
return filepath;
};
// Define our require/resolve.resolve
require = function (filepath) {
return __require(__requireFilepath(filepath));
};
require.resolve = function (filepath) {
return __requireResolve(__requireFilepath(filepath));
};
}
// Unset our `__parentWindow` to prevent leaks
// jscs:disable
__parentWindow = undefined;
// Inject our content
// jshint ignore:start
{{!content}}
// jshint ignore:end
// jscs:enable
}());