fix: respect compose project name

This commit is contained in:
2026-08-30 19:11:50 +07:00 Unverified
parent 7f1d445981
commit e7efa9b44a
8 changed files with 58 additions and 7 deletions
+22 -1
View File
@@ -15,6 +15,14 @@ type AppContext = {
const appContext = new AsyncLocalStorage<AppContext>();
export function resolveProjectName(
config: Pick<ResolvedKuberConfig, "project" | "projectConfigured">,
compose: ComposeSpecification,
): string {
if (config.projectConfigured) return config.project;
return compose.name?.trim() || config.project;
}
export async function provideContext<T>(
fn: () => T,
configPath?: string,
@@ -26,6 +34,19 @@ export async function provideContext<T>(
? Promise.resolve(config.composeFile)
: resolveComposeFile(cwd),
);
const parsedCompose = createCachedGetter("parsedCompose", async () => {
const composeFile = await path();
if (!composeFile) throw new Error("Compose file cannot be found");
return readCompose(composeFile);
});
if (!config.projectConfigured) {
const composeFile = await path();
if (composeFile) {
config.project = resolveProjectName(config, await parsedCompose());
}
}
const getHookContext = createCachedGetter("hookContext", async () => {
const composeFile = await path();
if (!composeFile) throw new Error("Compose file cannot be found");
@@ -33,7 +54,7 @@ export async function provideContext<T>(
});
const compose = createCachedGetter("compose", async () => {
const context = await getHookContext();
const value = await readCompose(context.composeFile);
const value = await parsedCompose();
await config.compose?.(value, context);
return value;
});