one
Version:
One is a React framework for web, iOS, and Android apps.
112 lines (109 loc) • 3.42 kB
JavaScript
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 { formatErrorSafely, installPrepareStackTraceGuard } from "./install-error-handlers.native.js";
import { labelProcess } from "./label-process.native.js";
installPrepareStackTraceGuard();
var DAEMON_PORT = 8081;
async function dev(args) {
var _ref;
labelProcess("dev");
checkNodeVersion();
setServerGlobals();
var root = process.cwd();
var daemonServerId;
var useDaemon = false;
var forcePort = process.env.ONE_FORCE_PORT ? +process.env.ONE_FORCE_PORT : void 0;
var envPort = process.env.ONE_PORT ? +process.env.ONE_PORT : void 0;
var effectivePort = (_ref = forcePort !== null && forcePort !== void 0 ? forcePort : args.port ? +args.port : void 0) !== null && _ref !== void 0 ? _ref : envPort;
var { isDaemonRunning, registerWithDaemon, unregisterFromDaemon, writeServerFile, removeServerFile } = await import("../daemon/ipc.native.js");
var { getBundleIdFromConfig, getAvailablePort } = await import("../daemon/utils.native.js");
var daemonRunning = await isDaemonRunning();
var bundleId = getBundleIdFromConfig(root) || path.basename(root);
if (daemonRunning) {
if (!effectivePort || effectivePort === 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 = true;
}
}
var { dev: dev2 } = await import("vxrn/dev");
var { start, stop } = await dev2({
mode: args.mode,
clean: args.clean,
root,
debugBundle: args.debugBundle,
debug: args.debug,
extraConfig: args.extraConfig,
server: {
host: args.host,
port: effectivePort
},
entries: { native: virtualEntryIdNative }
});
var { 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 cleanup2() {
if (daemonServerId) {
try {
await unregisterFromDaemon(daemonServerId);
removeServerFile(root);
} catch (unused) {}
}
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) {
try {
process.stderr.write(`[one dev] uncaught exception
${formatErrorSafely(err)}
`);
} catch (unused) {}
});
process.on("unhandledRejection", function(err) {
try {
process.stderr.write(`[one dev] unhandled rejection
${formatErrorSafely(err)}
`);
} catch (unused) {}
});
await closePromise;
}
export { dev };
//# sourceMappingURL=dev.native.js.map