summaryrefslogtreecommitdiff
path: root/node_modules/loader-runner/lib/loadLoader.js
diff options
context:
space:
mode:
authorlittleblack111 <littleblack11111@gmail.com>2023-11-05 17:16:09 +0800
committerlittleblack111 <littleblack11111@gmail.com>2023-11-05 17:16:09 +0800
commitd1d9f00b1bd660842addf5e6b1d1b64c852a9eea (patch)
tree60fb37ae73a1109d95301de5ec9b61b5726a4b61 /node_modules/loader-runner/lib/loadLoader.js
parent7c85166c4cbdd862fc4252007d2df5befcbc2a58 (diff)
added hover prefixer
Diffstat (limited to 'node_modules/loader-runner/lib/loadLoader.js')
-rw-r--r--node_modules/loader-runner/lib/loadLoader.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/loader-runner/lib/loadLoader.js b/node_modules/loader-runner/lib/loadLoader.js
new file mode 100644
index 00000000..12103534
--- /dev/null
+++ b/node_modules/loader-runner/lib/loadLoader.js
@@ -0,0 +1,54 @@
+var LoaderLoadingError = require("./LoaderLoadingError");
+var url;
+
+module.exports = function loadLoader(loader, callback) {
+ if(loader.type === "module") {
+ try {
+ if(url === undefined) url = require("url");
+ var loaderUrl = url.pathToFileURL(loader.path);
+ var modulePromise = eval("import(" + JSON.stringify(loaderUrl.toString()) + ")");
+ modulePromise.then(function(module) {
+ handleResult(loader, module, callback);
+ }, callback);
+ return;
+ } catch(e) {
+ callback(e);
+ }
+ } else {
+ try {
+ var module = require(loader.path);
+ } catch(e) {
+ // it is possible for node to choke on a require if the FD descriptor
+ // limit has been reached. give it a chance to recover.
+ if(e instanceof Error && e.code === "EMFILE") {
+ var retry = loadLoader.bind(null, loader, callback);
+ if(typeof setImmediate === "function") {
+ // node >= 0.9.0
+ return setImmediate(retry);
+ } else {
+ // node < 0.9.0
+ return process.nextTick(retry);
+ }
+ }
+ return callback(e);
+ }
+ return handleResult(loader, module, callback);
+ }
+};
+
+function handleResult(loader, module, callback) {
+ if(typeof module !== "function" && typeof module !== "object") {
+ return callback(new LoaderLoadingError(
+ "Module '" + loader.path + "' is not a loader (export function or es6 module)"
+ ));
+ }
+ loader.normal = typeof module === "function" ? module : module.default;
+ loader.pitch = module.pitch;
+ loader.raw = module.raw;
+ if(typeof loader.normal !== "function" && typeof loader.pitch !== "function") {
+ return callback(new LoaderLoadingError(
+ "Module '" + loader.path + "' is not a loader (must have normal or pitch function)"
+ ));
+ }
+ callback();
+}