Sv443 7 месяцев назад
Родитель
Сommit
c18c0c1f7c
2 измененных файлов с 12 добавлено и 10 удалено
  1. 5 5
      src/tools/post-build.ts
  2. 7 5
      src/tools/serve.ts

+ 5 - 5
src/tools/post-build.ts

@@ -9,6 +9,8 @@ import locales from "../../assets/locales.json" with { type: "json" };
 import pkg from "../../package.json" with { type: "json" };
 import type { RollupArgs } from "../types.js";
 
+const { argv, env, stdout } = process;
+
 /** Any type that is either a string or can be implicitly converted to one by having a .toString() method */
 type Stringifiable = string | { toString(): string; };
 
@@ -33,8 +35,6 @@ const buildTs = Date.now();
 /** Used to force the browser and userscript extension to refresh resources */
 const buildUuid = randomUUID();
 
-const { env } = process;
-
 type CliArg<TName extends keyof Required<RollupArgs>> = Required<RollupArgs>[TName];
 
 const mode = getCliArg<CliArg<"config-mode">>("mode", "development");
@@ -176,7 +176,7 @@ I welcome every contribution on GitHub!
     console.info(`Userscript URL: \x1b[34m\x1b[4m${devServerUserscriptUrl}\x1b[0m`);
     console.info();
 
-    ringBell && process.stdout.write("\u0007");
+    ringBell && stdout.write("\u0007");
 
     const buildStatsNew: BuildStats = {
       sizeKiB,
@@ -337,7 +337,7 @@ function getCliArg<TReturn extends string = string>(name: string, defaultVal: TR
 function getCliArg<TReturn extends string = string>(name: string, defaultVal?: TReturn | (string & {})): TReturn | undefined
 /** Returns the value of a CLI argument (in the format `--arg=<value>`) or the value of `defaultVal` if it doesn't exist */
 function getCliArg<TReturn extends string = string>(name: string, defaultVal?: TReturn | (string & {})): TReturn | undefined {
-  const arg = process.argv.find((v) => v.trim().match(new RegExp(`^(--)?${name}=.+$`, "i")));
+  const arg = argv.find((v) => v.trim().match(new RegExp(`^(--)?${name}=.+$`, "i")));
   const val = arg?.split("=")?.[1];
   return (val && val.length > 0 ? val : defaultVal)?.trim() as TReturn | undefined;
 }
@@ -369,5 +369,5 @@ async function getLinkedPkgs() {
 
 /** Schedules an exit after I/O events finish */
 function exit(code: number) {
-  setImmediate(() => process.exit(code));
+  setImmediate(() => exit(code));
 }

+ 7 - 5
src/tools/serve.ts

@@ -4,14 +4,16 @@ import express, { NextFunction, Request, Response } from "express";
 import "dotenv/config";
 import { outputDir } from "../../rollup.config.mjs";
 
-const envPort = Number(process.env.DEV_SERVER_PORT);
+const { argv, env, exit, stdout } = process;
+
+const envPort = Number(env.DEV_SERVER_PORT);
 
 /** HTTP port of the dev server */
 const devServerPort = isNaN(envPort) || envPort === 0 ? 8710 : envPort;
 /** Whether to log requests to the console */
 const enableLogging = false;
 
-const autoExitRaw = process.argv.find(arg => arg.startsWith("--auto-exit-time="))?.split("=")[1];
+const autoExitRaw = argv.find(arg => arg.startsWith("--auto-exit-time="))?.split("=")[1];
 /** Time in milliseconds after which the process should automatically exit */
 const autoExitTime: number | undefined = !isNaN(Number(autoExitRaw)) ? Number(autoExitRaw) * 1000 : undefined;
 
@@ -19,7 +21,7 @@ const app = express();
 
 enableLogging &&
   app.use((_req, _res, next) => {
-    process.stdout.write("*");
+    stdout.write("*");
     next();
   });
 
@@ -43,7 +45,7 @@ app.use("/assets", express.static(
 const server = app.listen(devServerPort, "0.0.0.0", () => {
   console.log(`Dev server is running on port ${devServerPort}`);
   if(enableLogging)
-    process.stdout.write("\nRequests: ");
+    stdout.write("\nRequests: ");
   else
     console.log("\x1b[2m(request logging is disabled)\x1b[0m");
   console.log();
@@ -51,7 +53,7 @@ const server = app.listen(devServerPort, "0.0.0.0", () => {
   if(autoExitTime) {
     console.log(`Exiting in ${autoExitTime / 1000}s...`);
     setTimeout(() => {
-      server.close(() => setImmediate(() => process.exit(0)));
+      server.close(() => setImmediate(() => exit(0)));
     }, autoExitTime);
   }
 });