forked from kmagiera/babel-watch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.js
54 lines (46 loc) · 1.12 KB
/
runner.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
'use strict';
let path = require('path');
let sourceMapSupport = require('source-map-support');
let sources = {};
let maps = {};
function loader(module_, filename, defaultHandler) {
let source = sources[filename];
if (source) {
module_._compile(source, filename);
} else {
defaultHandler(module_, filename);
}
}
function replaceExtensionHooks() {
for (let ext in require.extensions) {
let defaultHandler = require.extensions[ext]
require.extensions[ext] = (module_, filename) => {
loader(module_, filename, defaultHandler);
};
}
}
replaceExtensionHooks();
process.on('message', function(data) {
sources = data.sources;
maps = data.maps;
let filename = data.args[0];
if (filename.charAt(0) !== '/') {
data.args[0] = path.join(process.cwd(), filename);
}
process.argv = ["node"].concat(data.args);
require('module').runMain();
});
sourceMapSupport.install({
handleUncaughtExceptions: false,
retrieveSourceMap(filename) {
let map = maps && maps[filename];
if (map) {
return {
url: null,
map: map
};
} else {
return null;
}
}
});