@modern-js/utils
Version:
A Progressive React Framework for modern web development.
116 lines (115 loc) • 5.63 kB
JavaScript
;
var __webpack_require__ = {};
(()=>{
__webpack_require__.n = (module)=>{
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
__webpack_require__.d(getter, {
a: getter
});
return getter;
};
})();
(()=>{
__webpack_require__.d = (exports1, definition)=>{
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
enumerable: true,
get: definition[key]
});
};
})();
(()=>{
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
})();
(()=>{
__webpack_require__.r = (exports1)=>{
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
value: 'Module'
});
Object.defineProperty(exports1, '__esModule', {
value: true
});
};
})();
var __webpack_exports__ = {};
__webpack_require__.r(__webpack_exports__);
__webpack_require__.d(__webpack_exports__, {
getAddressUrls: ()=>getAddressUrls,
prettyInstructions: ()=>prettyInstructions
});
const external_net_namespaceObject = require("net");
const external_os_namespaceObject = require("os");
var external_os_default = /*#__PURE__*/ __webpack_require__.n(external_os_namespaceObject);
const external_compiled_js_namespaceObject = require("../compiled.js");
const external_constants_js_namespaceObject = require("./constants.js");
const index_js_namespaceObject = require("./is/index.js");
const normalizeUrl = (url)=>url.replace(/([^:]\/)\/+/g, '$1');
const getIpv4Interfaces = ()=>{
const interfaces = external_os_default().networkInterfaces();
const ipv4Interfaces = [];
Object.keys(interfaces).forEach((key)=>{
interfaces[key].forEach((detail)=>{
const familyV4Value = 'string' == typeof detail.family ? 'IPv4' : 4;
if (detail.family === familyV4Value) ipv4Interfaces.push(detail);
});
});
return ipv4Interfaces;
};
const getHostInUrl = (host)=>{
if ((0, external_net_namespaceObject.isIPv6)(host)) return '::' === host ? '[::1]' : `[${host}]`;
return host;
};
const getAddressUrls = (protocol = 'http', port, host)=>{
const LOCAL_LABEL = 'Local: ';
const NETWORK_LABEL = 'Network: ';
const isLocalhost = (url)=>url?.includes('localhost');
if (host && host !== external_constants_js_namespaceObject.DEFAULT_DEV_HOST) return [
{
label: isLocalhost(host) ? LOCAL_LABEL : NETWORK_LABEL,
url: `${protocol}://${getHostInUrl(host)}:${port}`
}
];
const ipv4Interfaces = getIpv4Interfaces();
return ipv4Interfaces.reduce((memo, detail)=>{
if (isLocalhost(detail.address) || detail.internal) memo.push({
label: LOCAL_LABEL,
url: `${protocol}://localhost:${port}`
});
else memo.push({
label: NETWORK_LABEL,
url: `${protocol}://${detail.address}:${port}`
});
return memo;
}, []);
};
const prettyInstructions = (appContext, config)=>{
const { entrypoints, serverRoutes, port, apiOnly, checkedEntries } = appContext;
const isHttps = (0, index_js_namespaceObject.isDev)() && (config?.dev?.https || config?.tools?.devServer?.https);
const urls = getAddressUrls(isHttps ? 'https' : 'http', port, config.dev?.host);
const routes = apiOnly ? serverRoutes : serverRoutes.filter((route)=>route.entryName);
let message = '\n';
if ((0, index_js_namespaceObject.isSingleEntry)(entrypoints, config.source?.mainEntryName) || apiOnly) message += urls.map(({ label, url })=>` ${external_compiled_js_namespaceObject.chalk.bold(`> ${label.padEnd(10)}`)}${external_compiled_js_namespaceObject.chalk.cyanBright(normalizeUrl(`${url}/${routes[0].urlPath}`))}\n`).join('');
else {
const maxNameLength = Math.max(...routes.map((r)=>r.entryName.length));
urls.forEach(({ label, url })=>{
message += ` ${external_compiled_js_namespaceObject.chalk.bold(`> ${label}`)}${0 === routes.length ? external_compiled_js_namespaceObject.chalk.cyanBright(url) : ''}\n`;
routes.forEach(({ entryName, urlPath, isSSR })=>{
if (!checkedEntries.includes(entryName)) return;
message += ` ${external_compiled_js_namespaceObject.chalk.yellowBright(isSSR ? 'λ' : '○')} ${external_compiled_js_namespaceObject.chalk.yellowBright(entryName.padEnd(maxNameLength + 8))}${external_compiled_js_namespaceObject.chalk.cyanBright(normalizeUrl(`${url}/${urlPath}`))}\n`;
});
});
message += '\n';
message += external_compiled_js_namespaceObject.chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
message += external_compiled_js_namespaceObject.chalk.cyanBright(' ○ (Static) client-side renders as static HTML\n');
}
if (config.dev?.cliShortcuts) message += ` ${external_compiled_js_namespaceObject.chalk.dim('> press')} ${external_compiled_js_namespaceObject.chalk.bold('h + enter')} ${external_compiled_js_namespaceObject.chalk.dim('to show shortcuts')}\n`;
return message;
};
exports.getAddressUrls = __webpack_exports__.getAddressUrls;
exports.prettyInstructions = __webpack_exports__.prettyInstructions;
for(var __rspack_i in __webpack_exports__)if (-1 === [
"getAddressUrls",
"prettyInstructions"
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
Object.defineProperty(exports, '__esModule', {
value: true
});