UNPKG

one

Version:

One is a new React Framework that makes Vite serve both native and web.

97 lines (96 loc) 3.05 kB
import * as path from "path"; import colors from "picocolors"; import { setServerGlobals } from "../server/setServerGlobals.native.js"; import { virtualEntryIdNative } from "../vite/plugins/virtualEntryConstants.native.js"; import { checkNodeVersion } from "./checkNodeVersion.native.js"; import { labelProcess } from "./label-process.native.js"; var DEFAULT_PORT = 8081, DAEMON_PORT = 8081; async function dev(args) { labelProcess("dev"), checkNodeVersion(), setServerGlobals(); var root = process.cwd(), daemonServerId, useDaemon = !1, effectivePort = args.port ? +args.port : DEFAULT_PORT, { isDaemonRunning, registerWithDaemon, unregisterFromDaemon, writeServerFile, removeServerFile } = await import("../daemon/ipc.native.js"), { getBundleIdFromConfig, getAvailablePort } = await import("../daemon/utils.native.js"), daemonRunning = await isDaemonRunning(), bundleId = getBundleIdFromConfig(root) || path.basename(root); if (daemonRunning) { var requestedPort = args.port ? +args.port : null; !requestedPort || requestedPort === DAEMON_PORT ? (effectivePort = await getAvailablePort(8082, DAEMON_PORT), console.log(colors.cyan(`[daemon] Detected running daemon on :${DAEMON_PORT}`)), console.log(colors.cyan(`[daemon] Using port :${effectivePort} for this server`)), useDaemon = !0) : effectivePort = requestedPort; } var { dev: dev2 } = await import("vxrn/dev"), { start, stop } = await dev2({ mode: args.mode, clean: args.clean, root, debugBundle: args.debugBundle, debug: args.debug, server: { host: args.host, port: effectivePort }, entries: { native: virtualEntryIdNative } }), { closePromise } = await start(); if (useDaemon && bundleId) try { daemonServerId = await registerWithDaemon({ port: effectivePort, bundleId, root }), console.log(colors.green(`[daemon] Registered as ${bundleId} (${daemonServerId}) \u2192 accessible via :${DAEMON_PORT}`)), writeServerFile({ port: effectivePort, bundleId, root, pid: process.pid }); } catch (err) { console.log(colors.yellow(`[daemon] Failed to register: ${err}`)); } var cleanup = async function () { if (daemonServerId) try { await unregisterFromDaemon(daemonServerId), removeServerFile(root); } catch {} await stop(); }; process.on("beforeExit", function () { cleanup(); }), process.on("SIGINT", async function () { try { await cleanup(); } finally { process.exit(2); } }), process.on("SIGTERM", async function () { try { await cleanup(); } finally { process.exit(0); } }), process.on("uncaughtException", function (err) { console.error(err?.message || err); }), process.on("unhandledRejection", function (err) { console.error(err); }), await closePromise; } export { dev }; //# sourceMappingURL=dev.native.js.map