fix admn controller

This commit is contained in:
Mateusz Gruszczyński
2026-04-06 16:29:58 +02:00
parent 78a0b21e48
commit 723e3441df
10 changed files with 43 additions and 46 deletions

View File

@@ -1,5 +1,4 @@
import type { Response } from 'express';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
import process from 'node:process';
@@ -41,14 +40,11 @@ const userUpdateSchema = z.object({
type PackageJson = { version?: string };
const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const readPackageJsonSafe = (filePath: string | null): PackageJson | null => {
if (!filePath || !fs.existsSync(filePath)) {
return null;
}
if (!filePath || !fs.existsSync(filePath)) return null;
try {
return JSON.parse(fs.readFileSync(filePath, 'utf8')) as PackageJson;
@@ -62,15 +58,10 @@ const findNearestPackageJson = (startDir: string): string | null => {
while (true) {
const candidate = path.join(currentDir, 'package.json');
if (fs.existsSync(candidate)) {
return candidate;
}
if (fs.existsSync(candidate)) return candidate;
const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
return null;
}
if (parentDir == currentDir) return null;
currentDir = parentDir;
}
};