UNPKG

@leafage/toolkit

Version:

The React Server Side Render Framework

85 lines (82 loc) 3.2 kB
/** * @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 */ import { asyncToGenerator as _asyncToGenerator, regenerator as _regenerator } from './_virtual/_rollupPluginBabelHelpers.js'; import path from 'node:path'; import { pathToFileURL } from 'node:url'; import { resolveModulePath } from 'exsolve'; import importFresh from 'import-fresh'; var directoryToURL = function directoryToURL(dir) { return pathToFileURL("".concat(dir, "/")); }; var resolveModule = function resolveModule(id) { var _ref, _options$url; var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; return resolveModulePath(id, { from: (_ref = (_options$url = options.url) !== null && _options$url !== void 0 ? _options$url : options.paths) !== null && _ref !== void 0 ? _ref : [import.meta.url], extensions: ['.js', '.mjs', '.jsx', '.cjs', '.ts', '.mts', '.cts', '.tsx'] }); }; var importModule = /*#__PURE__*/function () { var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(id) { var _module$default; var options, resolvedPath, module, _args = arguments; return _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(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 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(name, options) { var _module$default2; var module; return _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); }; }(); export { directoryToURL, importModule, importServerModule, resolveModule };