1 |
3a515b92
|
cagy
|
var LoaderLoadingError = require("./LoaderLoadingError");
|
2 |
|
|
|
3 |
|
|
module.exports = function loadLoader(loader, callback) {
|
4 |
|
|
if(typeof System === "object" && typeof System.import === "function") {
|
5 |
|
|
System.import(loader.path).catch(callback).then(function(module) {
|
6 |
|
|
loader.normal = typeof module === "function" ? module : module.default;
|
7 |
|
|
loader.pitch = module.pitch;
|
8 |
|
|
loader.raw = module.raw;
|
9 |
|
|
if(typeof loader.normal !== "function" && typeof loader.pitch !== "function") {
|
10 |
|
|
return callback(new LoaderLoadingError(
|
11 |
|
|
"Module '" + loader.path + "' is not a loader (must have normal or pitch function)"
|
12 |
|
|
));
|
13 |
|
|
}
|
14 |
|
|
callback();
|
15 |
|
|
});
|
16 |
|
|
} else {
|
17 |
|
|
try {
|
18 |
|
|
var module = require(loader.path);
|
19 |
|
|
} catch(e) {
|
20 |
|
|
// it is possible for node to choke on a require if the FD descriptor
|
21 |
|
|
// limit has been reached. give it a chance to recover.
|
22 |
|
|
if(e instanceof Error && e.code === "EMFILE") {
|
23 |
|
|
var retry = loadLoader.bind(null, loader, callback);
|
24 |
|
|
if(typeof setImmediate === "function") {
|
25 |
|
|
// node >= 0.9.0
|
26 |
|
|
return setImmediate(retry);
|
27 |
|
|
} else {
|
28 |
|
|
// node < 0.9.0
|
29 |
|
|
return process.nextTick(retry);
|
30 |
|
|
}
|
31 |
|
|
}
|
32 |
|
|
return callback(e);
|
33 |
|
|
}
|
34 |
|
|
if(typeof module !== "function" && typeof module !== "object") {
|
35 |
|
|
return callback(new LoaderLoadingError(
|
36 |
|
|
"Module '" + loader.path + "' is not a loader (export function or es6 module)"
|
37 |
|
|
));
|
38 |
|
|
}
|
39 |
|
|
loader.normal = typeof module === "function" ? module : module.default;
|
40 |
|
|
loader.pitch = module.pitch;
|
41 |
|
|
loader.raw = module.raw;
|
42 |
|
|
if(typeof loader.normal !== "function" && typeof loader.pitch !== "function") {
|
43 |
|
|
return callback(new LoaderLoadingError(
|
44 |
|
|
"Module '" + loader.path + "' is not a loader (must have normal or pitch function)"
|
45 |
|
|
));
|
46 |
|
|
}
|
47 |
|
|
callback();
|
48 |
|
|
}
|
49 |
|
|
};
|