refactor: simplify the resolve entry path logic

Signed-off-by: Camila Belo <camilaibs@gmail.com>
This commit is contained in:
Camila Belo
2025-09-25 10:55:50 +02:00
parent 941613854c
commit d070bda0d4
2 changed files with 10 additions and 12 deletions
@@ -46,12 +46,12 @@ describe('resolveEntryPath', () => {
it('should handle multiple dots in filename', () => {
mockDir.setContent({
'file.backup.old.ts': 'export const data = {};',
'index.alpha.ts': 'export const data = {};',
});
const result = resolveEntryPath('file.backup.old.ts', mockDir.path);
const result = resolveEntryPath('index.alpha.ts', mockDir.path);
expect(result).toBe('file.backup.old');
expect(result).toBe('index.alpha');
});
it('should handle simple directory names', () => {
@@ -17,21 +17,19 @@
import { PackageRole } from '@backstage/cli-node';
import { startBackend, startBackendPlugin } from './startBackend';
import { startFrontend } from './startFrontend';
import { statSync, readdirSync } from 'fs';
import { resolve, join, parse } from 'path';
import { parse, resolve, join } from 'path';
import { glob } from 'glob';
export function resolveEntryPath(
entrypoint: string = 'dev',
targetDir: string,
): string {
const { dir: entryDir, name: entryName } = parse(entrypoint);
const entryPath = join(entryDir, entryName);
const parentPath = resolve(targetDir, entryDir);
const isFile = readdirSync(parentPath).some(base => {
const path = resolve(parentPath, base);
return statSync(path).isFile();
});
return isFile ? entryPath : join(entryPath, 'index');
const [entryFile] = glob.sync(`${resolve(targetDir, entryDir, entryName)}.*`);
if (entryFile) {
return join(entryDir, entryName);
}
return join(entryDir, entryName, 'index');
}
export async function startPackage(options: {