@leafage/toolkit
Version:
The React Server Side Render Framework
91 lines (87 loc) • 3.76 kB
JavaScript
/**
* @leafage/toolkit v1.3.2
*
* Copyright (c) Leafage.
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/
;
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
var path = require('node:path');
var node_url = require('node:url');
var exsolve = require('exsolve');
var importFresh = require('import-fresh');
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
var directoryToURL = function directoryToURL(dir) {
return node_url.pathToFileURL("".concat(dir, "/"));
};
var resolveModule = function resolveModule(id) {
var _ref, _options$url;
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
return exsolve.resolveModulePath(id, {
from: (_ref = (_options$url = options.url) !== null && _options$url !== void 0 ? _options$url : options.paths) !== null && _ref !== void 0 ? _ref : [(typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('imports.js', document.baseURI).href))],
extensions: ['.js', '.mjs', '.jsx', '.cjs', '.ts', '.mts', '.cts', '.tsx']
});
};
var importModule = /*#__PURE__*/function () {
var _ref2 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee(id) {
var _module$default;
var options,
resolvedPath,
module,
_args = arguments;
return _rollupPluginBabelHelpers.regenerator().w(function (_context) {
while (1) switch (_context.n) {
case 0:
options = _args.length > 1 && _args[1] !== undefined ? _args[1] : {};
resolvedPath = resolveModule(id, options);
if (!options.isDev) {
_context.n = 1;
break;
}
return _context.a(2, importFresh(resolvedPath));
case 1:
_context.n = 2;
return import(node_url.pathToFileURL(resolvedPath).href);
case 2:
module = _context.v;
return _context.a(2, (_module$default = module === null || module === void 0 ? void 0 : module["default"]) !== null && _module$default !== void 0 ? _module$default : module);
}
}, _callee);
}));
return function importModule(_x) {
return _ref2.apply(this, arguments);
};
}();
var importServerModule = /*#__PURE__*/function () {
var _ref3 = _rollupPluginBabelHelpers.asyncToGenerator(/*#__PURE__*/_rollupPluginBabelHelpers.regenerator().m(function _callee2(name, options) {
var _module$default2;
var module;
return _rollupPluginBabelHelpers.regenerator().w(function (_context2) {
while (1) switch (_context2.n) {
case 0:
_context2.n = 1;
return importModule("./".concat(name), {
isDev: options.dev,
url: path.join(options.dir.root, options.dir.dist, options.dir.server)
});
case 1:
module = _context2.v;
return _context2.a(2, {
loader: module === null || module === void 0 ? void 0 : module.loader,
Component: (_module$default2 = module === null || module === void 0 ? void 0 : module["default"]) !== null && _module$default2 !== void 0 ? _module$default2 : module
});
}
}, _callee2);
}));
return function importServerModule(_x2, _x3) {
return _ref3.apply(this, arguments);
};
}();
exports.directoryToURL = directoryToURL;
exports.importModule = importModule;
exports.importServerModule = importServerModule;
exports.resolveModule = resolveModule;