source: trip-planner-front/node_modules/loader-runner/lib/loadLoader.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.6 KB
Line 
1var LoaderLoadingError = require("./LoaderLoadingError");
2var url;
3
4module.exports = function loadLoader(loader, callback) {
5 if(loader.type === "module") {
6 try {
7 if(url === undefined) url = require("url");
8 var loaderUrl = url.pathToFileURL(loader.path);
9 var modulePromise = eval("import(" + JSON.stringify(loaderUrl.toString()) + ")");
10 modulePromise.then(function(module) {
11 handleResult(loader, module, callback);
12 }, callback);
13 return;
14 } catch(e) {
15 callback(e);
16 }
17 } else {
18 try {
19 var module = require(loader.path);
20 } catch(e) {
21 // it is possible for node to choke on a require if the FD descriptor
22 // limit has been reached. give it a chance to recover.
23 if(e instanceof Error && e.code === "EMFILE") {
24 var retry = loadLoader.bind(null, loader, callback);
25 if(typeof setImmediate === "function") {
26 // node >= 0.9.0
27 return setImmediate(retry);
28 } else {
29 // node < 0.9.0
30 return process.nextTick(retry);
31 }
32 }
33 return callback(e);
34 }
35 return handleResult(loader, module, callback);
36 }
37};
38
39function handleResult(loader, module, callback) {
40 if(typeof module !== "function" && typeof module !== "object") {
41 return callback(new LoaderLoadingError(
42 "Module '" + loader.path + "' is not a loader (export function or es6 module)"
43 ));
44 }
45 loader.normal = typeof module === "function" ? module : module.default;
46 loader.pitch = module.pitch;
47 loader.raw = module.raw;
48 if(typeof loader.normal !== "function" && typeof loader.pitch !== "function") {
49 return callback(new LoaderLoadingError(
50 "Module '" + loader.path + "' is not a loader (must have normal or pitch function)"
51 ));
52 }
53 callback();
54}
Note: See TracBrowser for help on using the repository browser.