/*1* command-utils.ts2*3* Copyright (C) 2020-2022 Posit Software, PBC4*/56import { initYamlIntelligenceResourcesFromFilesystem } from "../core/schema/utils.ts";7import { projectContext } from "../project/project-context.ts";8import { notebookContext } from "../render/notebook/notebook-context.ts";9import { resolveEngines } from "../execute/engine.ts";10import type { ProjectContext } from "../project/types.ts";1112/**13* Create a minimal "zero-file" project context for loading bundled engine extensions14* when no actual project or file exists.15*16* This is needed for commands like `quarto check julia` that run outside any project17* but still need access to bundled engines. The context provides just enough structure18* to discover and register bundled engine extensions.19*20* @param dir - Directory to use as the base (defaults to current working directory)21* @returns A minimal ProjectContext with bundled engines loaded22*/23async function zeroFileProjectContext(dir?: string): Promise<ProjectContext> {24const { createExtensionContext } = await import(25"../extension/extension.ts"26);27const { resolveEngineExtensions } = await import(28"../project/project-context.ts"29);3031const extensionContext = createExtensionContext();32const config = await resolveEngineExtensions(33extensionContext,34{ project: {} },35dir || Deno.cwd(),36);3738// Return a minimal project context with the resolved engine config39return {40dir: dir || Deno.cwd(),41config,42} as ProjectContext;43}4445/**46* Initialize project context and register external engines from project config.47*48* This consolidates the common pattern of:49* 1. Loading YAML intelligence resources50* 2. Creating project context51* 3. Registering external engines via reorderEngines()52*53* If no project is found, a zero-file context is created to load bundled engine54* extensions (like Julia), ensuring they're available for commands like `quarto check julia`.55*56* @param dir - Optional directory path (defaults to current working directory)57*/58export async function initializeProjectContextAndEngines(59dir?: string,60): Promise<void> {61// Initialize YAML intelligence resources (required for project context)62await initYamlIntelligenceResourcesFromFilesystem();6364// Load project context if we're in a project directory, or create a zero-file65// context to load bundled engines when no project exists66const context = await projectContext(dir || Deno.cwd(), notebookContext()) ||67await zeroFileProjectContext(dir);6869// Register external engines from project config70await resolveEngines(context);71}727374