refactor(env): refactor env module
test / test (push) Failing after 31m39s

This commit is contained in:
2026-10-27 01:18:23 +03:00
parent cf3a707a47
commit fc7f97b520
6 changed files with 33 additions and 27 deletions
+15 -9
View File
@@ -1,19 +1,25 @@
import path from "path";
export class Env {
static set(key: string, value: string) {
process.env[key] = value;
constructor(private target: Record<string, string | undefined>) {}
set(key: string, value: string) {
this.target[key] = value;
}
static get(key: string) {
return process.env[key];
get(key: string) {
return this.target[key];
}
static addPath(value: string, key = "PATH") {
if (!process.env[key]) {
process.env[key] = value;
} else if (process.env[key].split(path.delimiter).indexOf(value) === -1) {
process.env[key] = [process.env[key], value].join(path.delimiter);
addPath(value: string, key: string = "PATH") {
if (!this.target[key]) {
this.target[key] = value;
} else if (this.target[key].split(path.delimiter).indexOf(value) === -1) {
this.target[key] = [this.target[key], value].join(path.delimiter);
}
}
}
export const env = new Env(process.env);
export default env;
+4 -4
View File
@@ -3,7 +3,7 @@ import os from "os";
import path from "path";
import through from "through2";
import download from "../common/download";
import { Env } from "../common/env";
import env from "../common/env";
import exec from "../common/exec";
import { System } from "../common/system";
import { HandlerWriter } from "../common/tail";
@@ -101,9 +101,9 @@ export class Android extends Sdk {
}
activate() {
Env.set("ANDROID_HOME", this.android_home);
Env.set("ANDROID_NDK_HOME", this.ndk_home);
Env.set("NDK_HOME", this.ndk_home);
env.set("ANDROID_HOME", this.android_home);
env.set("ANDROID_NDK_HOME", this.ndk_home);
env.set("NDK_HOME", this.ndk_home);
}
get adbBin(): string {
+2 -2
View File
@@ -2,7 +2,7 @@ import fs from "fs";
import fse from "fs-extra";
import os from "os";
import path from "path";
import { Env } from "../common/env";
import env from "../common/env";
import { System } from "../common/system";
import { watch } from "../common/watch";
import { Sdk } from "../core/sdk";
@@ -31,7 +31,7 @@ export class FlashPlayer extends Sdk {
constructor(debug: boolean = false, version?: string, playerId = FlashPlayer.ID) {
super(playerId, version || FlashPlayer.VERSION);
this.debug = debug;
this.baseUrl = Env.get("FLASHPLAYER_URL") || this.BASE_URL;
this.baseUrl = env.get("FLASHPLAYER_URL") || this.BASE_URL;
}
prepare() {
+6 -6
View File
@@ -4,7 +4,7 @@ import rename from "gulp-rename";
import os from "os";
import path from "path";
import vfs from "vinyl-fs";
import { Env } from "../common/env";
import env from "../common/env";
import exec from "../common/exec";
import { System } from "../common/system";
import template from "../common/template";
@@ -68,11 +68,11 @@ export class Haxe extends Sdk {
activate() {
this.neko.activate();
Env.set("HAXE_VERSION", this.version);
Env.set("HAXE_STD_PATH", path.join(this.path, "std"));
Env.set("HAXE_HOME", this.path);
Env.addPath(this.path);
Env.addPath(this.path, "LD_LIBRARY_PATH");
env.set("HAXE_VERSION", this.version);
env.set("HAXE_STD_PATH", path.join(this.path, "std"));
env.set("HAXE_HOME", this.path);
env.addPath(this.path);
env.addPath(this.path, "LD_LIBRARY_PATH");
}
prepare() {
+4 -4
View File
@@ -1,7 +1,7 @@
import fs from "fs";
import os from "os";
import path from "path";
import { Env } from "../common/env";
import env from "../common/env";
import { Sdk } from "../core/sdk";
import run from "../run/index";
@@ -63,9 +63,9 @@ export class Neko extends Sdk {
}
activate() {
Env.set("NEKO_INSTPATH", this.path);
Env.addPath(this.path);
Env.addPath(this.path, "LD_LIBRARY_PATH");
env.set("NEKO_INSTPATH", this.path);
env.addPath(this.path);
env.addPath(this.path, "LD_LIBRARY_PATH");
}
prepare() {
+2 -2
View File
@@ -1,6 +1,6 @@
import os from "os";
import path from "path";
import { Env } from "../common/env";
import env from "../common/env";
import { System } from "../common/system";
import { watch } from "../common/watch";
import run from "../run";
@@ -20,7 +20,7 @@ export class RufflePlayer extends FlashPlayer {
constructor(debug: boolean, version: string) {
super(debug, version || RufflePlayer.VERSION, RufflePlayer.ID);
this.baseUrl = Env.get("RUFFLE_URL") || this.BASE_URL;
this.baseUrl = env.get("RUFFLE_URL") || this.BASE_URL;
}
get link(): string {