fix: respect compose project name
This commit is contained in:
+22
-1
@@ -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;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user