chore(db): harden workspace env wrappers

This commit is contained in:
2026-03-31 22:47:07 +02:00
parent 5097ceab7e
commit 3e8b1702bc
6 changed files with 72 additions and 14 deletions
+6 -2
View File
@@ -1,11 +1,15 @@
import { existsSync, readFileSync } from "node:fs";
import { existsSync, readFileSync, realpathSync } from "node:fs";
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
function resolveWorkspaceRoot() {
export function resolveWorkspaceRoot() {
return resolve(dirname(fileURLToPath(import.meta.url)), "..");
}
export function resolveRealWorkspaceRoot() {
return realpathSync(resolveWorkspaceRoot());
}
export function resolveWorkspaceEnvPath(options = {}) {
const { workspaceRoot = resolveWorkspaceRoot() } = options;
return resolve(workspaceRoot, ".env");
+4 -2
View File
@@ -1,9 +1,11 @@
#!/usr/bin/env node
import { spawnSync } from "node:child_process";
import { loadWorkspaceEnv } from "./load-env.mjs";
import { loadWorkspaceEnv, resolveRealWorkspaceRoot } from "./load-env.mjs";
loadWorkspaceEnv();
const workspaceRoot = resolveRealWorkspaceRoot();
process.chdir(workspaceRoot);
const args = process.argv.slice(2);
@@ -15,6 +17,7 @@ if (args.length === 0) {
const result = spawnSync(args[0], args.slice(1), {
stdio: "inherit",
env: process.env,
cwd: workspaceRoot,
});
if (result.error) {
@@ -23,4 +26,3 @@ if (result.error) {
}
process.exit(result.status ?? 1);