mirror of
https://github.com/AutoMaker-Org/automaker.git
synced 2026-02-02 20:43:36 +00:00
refactor: Simplify tsx path lookup and remove redundant try-catch
Address review feedback: - Simplify tsx CLI path lookup by extracting path variables and reducing nested try-catch blocks - Remove redundant try-catch around electronAppExists check in production server path validation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,22 +63,23 @@ export async function startServer(): Promise<void> {
|
|||||||
const rootNodeModules = path.join(__dirname, '../../../node_modules/tsx');
|
const rootNodeModules = path.join(__dirname, '../../../node_modules/tsx');
|
||||||
|
|
||||||
let tsxCliPath: string;
|
let tsxCliPath: string;
|
||||||
// Check for tsx in app bundle paths
|
// Check for tsx in app bundle paths, fallback to require.resolve
|
||||||
|
const serverTsxPath = path.join(serverNodeModules, 'dist/cli.mjs');
|
||||||
|
const rootTsxPath = path.join(rootNodeModules, 'dist/cli.mjs');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (electronAppExists(path.join(serverNodeModules, 'dist/cli.mjs'))) {
|
if (electronAppExists(serverTsxPath)) {
|
||||||
tsxCliPath = path.join(serverNodeModules, 'dist/cli.mjs');
|
tsxCliPath = serverTsxPath;
|
||||||
} else if (electronAppExists(path.join(rootNodeModules, 'dist/cli.mjs'))) {
|
} else if (electronAppExists(rootTsxPath)) {
|
||||||
tsxCliPath = path.join(rootNodeModules, 'dist/cli.mjs');
|
tsxCliPath = rootTsxPath;
|
||||||
} else {
|
} else {
|
||||||
try {
|
// Fallback to require.resolve
|
||||||
tsxCliPath = require.resolve('tsx/cli.mjs', {
|
tsxCliPath = require.resolve('tsx/cli.mjs', {
|
||||||
paths: [path.join(__dirname, '../../server')],
|
paths: [path.join(__dirname, '../../server')],
|
||||||
});
|
});
|
||||||
} catch {
|
|
||||||
throw new Error("Could not find tsx. Please run 'npm install' in the server directory.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
|
// electronAppExists threw or require.resolve failed
|
||||||
try {
|
try {
|
||||||
tsxCliPath = require.resolve('tsx/cli.mjs', {
|
tsxCliPath = require.resolve('tsx/cli.mjs', {
|
||||||
paths: [path.join(__dirname, '../../server')],
|
paths: [path.join(__dirname, '../../server')],
|
||||||
@@ -93,11 +94,7 @@ export async function startServer(): Promise<void> {
|
|||||||
serverPath = path.join(process.resourcesPath, 'server', 'index.js');
|
serverPath = path.join(process.resourcesPath, 'server', 'index.js');
|
||||||
args = [serverPath];
|
args = [serverPath];
|
||||||
|
|
||||||
try {
|
if (!electronAppExists(serverPath)) {
|
||||||
if (!electronAppExists(serverPath)) {
|
|
||||||
throw new Error(`Server not found at: ${serverPath}`);
|
|
||||||
}
|
|
||||||
} catch {
|
|
||||||
throw new Error(`Server not found at: ${serverPath}`);
|
throw new Error(`Server not found at: ${serverPath}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user