Skip to content

Commit ff1fedb

Browse files
cscheidgordonwoodhull
authored andcommitted
resolve extension metadata uniformly during object creation
1 parent 7e02521 commit ff1fedb

File tree

2 files changed

+39
-34
lines changed

2 files changed

+39
-34
lines changed

src/command/render/project.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import {
1414
} from "../../deno_ral/fs.ts";
1515
import { dirname, isAbsolute, join, relative } from "../../deno_ral/path.ts";
1616
import { info, warning } from "../../deno_ral/log.ts";
17-
import { mergeProjectMetadata } from "../../config/metadata.ts";
1817

1918
import * as colors from "fmt/colors";
2019

@@ -80,7 +79,6 @@ import { Format } from "../../config/types.ts";
8079
import { fileExecutionEngine } from "../../execute/engine.ts";
8180
import { projectContextForDirectory } from "../../project/project-context.ts";
8281
import { ProjectType } from "../../project/types/types.ts";
83-
import { Zod } from "../../resources/types/zod/schema-types.ts";
8482

8583
const noMutationValidations = (
8684
projType: ProjectType,
@@ -242,37 +240,11 @@ const getProjectRenderScripts = async (
242240
return { preRenderScripts, postRenderScripts };
243241
};
244242

245-
const mergeExtensionMetadata = async (
246-
context: ProjectContext,
247-
pOptions: RenderOptions,
248-
) => {
249-
// this will mutate context.config.project to merge
250-
// in any project metadata from extensions
251-
if (context.config) {
252-
const extensions = await pOptions.services.extension.extensions(
253-
undefined,
254-
context.config,
255-
context.isSingleFile ? undefined : context.dir,
256-
{ builtIn: false },
257-
);
258-
const projectMetadata = extensions.filter((extension) =>
259-
extension.contributes.metadata?.project
260-
).map((extension) => {
261-
return Zod.ProjectConfig.parse(extension.contributes.metadata!.project);
262-
});
263-
context.config.project = mergeProjectMetadata(
264-
context.config.project,
265-
...projectMetadata,
266-
);
267-
}
268-
};
269-
270243
export async function renderProject(
271244
context: ProjectContext,
272245
pOptions: RenderOptions,
273246
pFiles?: string[],
274247
): Promise<RenderResult> {
275-
await mergeExtensionMetadata(context, pOptions);
276248
const { preRenderScripts, postRenderScripts } = await getProjectRenderScripts(
277249
context,
278250
);

src/project/project-context.ts

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,32 @@ import { createTempContext } from "../core/temp.ts";
107107

108108
import { onCleanup } from "../core/cleanup.ts";
109109
import { once } from "../core/once.ts";
110+
import { Zod } from "../resources/types/zod/schema-types.ts";
111+
112+
const mergeExtensionMetadata = async (
113+
context: ProjectContext,
114+
pOptions: RenderOptions,
115+
) => {
116+
// this will mutate context.config.project to merge
117+
// in any project metadata from extensions
118+
if (context.config) {
119+
const extensions = await pOptions.services.extension.extensions(
120+
undefined,
121+
context.config,
122+
context.isSingleFile ? undefined : context.dir,
123+
{ builtIn: false },
124+
);
125+
const projectMetadata = extensions.filter((extension) =>
126+
extension.contributes.metadata?.project
127+
).map((extension) => {
128+
return Zod.ProjectConfig.parse(extension.contributes.metadata!.project);
129+
});
130+
context.config.project = mergeProjectMetadata(
131+
context.config.project,
132+
...projectMetadata,
133+
);
134+
}
135+
};
110136

111137
export async function projectContext(
112138
path: string,
@@ -145,6 +171,16 @@ export async function projectContext(
145171
}
146172
};
147173

174+
const returnResult = async (
175+
context: ProjectContext,
176+
) => {
177+
if (renderOptions) {
178+
await mergeExtensionMetadata(context, renderOptions);
179+
}
180+
onCleanup(context.cleanup);
181+
return context;
182+
};
183+
148184
while (true) {
149185
// use the current resolver
150186
const resolver = configResolvers[0];
@@ -362,8 +398,7 @@ export async function projectContext(
362398
config: configFiles,
363399
configResources: projectConfigResources(dir, projectConfig, type),
364400
};
365-
onCleanup(result.cleanup);
366-
return result;
401+
return await returnResult(result);
367402
} else {
368403
debug(`projectContext: Found Quarto project in ${dir}`);
369404
const temp = createTempContext({
@@ -431,8 +466,7 @@ export async function projectContext(
431466
config: configFiles,
432467
configResources: projectConfigResources(dir, projectConfig),
433468
};
434-
onCleanup(result.cleanup);
435-
return result;
469+
return await returnResult(result);
436470
}
437471
} else {
438472
const nextDir = dirname(dir);
@@ -511,8 +545,7 @@ export async function projectContext(
511545
context.files.input = [input];
512546
}
513547
debug(`projectContext: Found Quarto project in ${originalDir}`);
514-
onCleanup(context.cleanup);
515-
return context;
548+
return await returnResult(context);
516549
} else {
517550
return undefined;
518551
}

0 commit comments

Comments
 (0)