Skip to content

Commit 04e00a1

Browse files
claude: Fix bundler async initialization with dynamic imports
Use dynamic imports to break async module initialization chains that caused esbuild bundling errors. The issue was caused by two module-level import paths into render modules with async initialization: 1. check command → command-utils.ts → notebookContext (render modules) 2. quarto-api.ts → checkRender → render-shared.ts (async init) When esbuild bundled these, it generated invalid JavaScript with await in non-async functions, causing "Unexpected reserved word" errors. Solution: Convert static imports to dynamic imports that execute at runtime: - src/command/command-utils.ts: Move projectContext, notebookContext, and reorderEngines imports into function body - src/core/quarto-api.ts: Wrap checkRender export in arrow function with dynamic import This defers module loading until the functions are actually called, avoiding top-level async initialization in the bundle. Fixes prepare-dist workflow and allows test-bundle CI action to pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 5fbbf59 commit 04e00a1

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

src/command/command-utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
*/
66

77
import { initYamlIntelligenceResourcesFromFilesystem } from "../core/schema/utils.ts";
8-
import { projectContext } from "../project/project-context.ts";
9-
import { notebookContext } from "../render/notebook/notebook-context.ts";
10-
import { reorderEngines } from "../execute/engine.ts";
11-
import { ProjectContext } from "../project/types.ts";
8+
import type { ProjectContext } from "../project/types.ts";
129

1310
/**
1411
* Create a minimal "zero-file" project context for loading bundled engine extensions
@@ -59,6 +56,13 @@ async function zeroFileProjectContext(dir?: string): Promise<ProjectContext> {
5956
export async function initializeProjectContextAndEngines(
6057
dir?: string,
6158
): Promise<void> {
59+
// Dynamic imports to avoid async module initialization chain in bundle
60+
const { projectContext } = await import("../project/project-context.ts");
61+
const { notebookContext } = await import(
62+
"../render/notebook/notebook-context.ts"
63+
);
64+
const { reorderEngines } = await import("../execute/engine.ts");
65+
6266
// Initialize YAML intelligence resources (required for project context)
6367
await initYamlIntelligenceResourcesFromFilesystem();
6468

src/core/quarto-api.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import {
5656
executeResultIncludes,
5757
} from "../execute/jupyter/jupyter.ts";
5858
import { completeMessage, withSpinner } from "./console.ts";
59-
import { checkRender } from "../command/check/check-render.ts";
6059
import type { RenderServiceWithLifetime } from "../command/render/types.ts";
6160
import type { LogMessageOptions } from "./log.ts";
6261
import * as log from "../deno_ral/log.ts";
@@ -362,7 +361,11 @@ export const quartoAPI: QuartoAPI = {
362361
runExternalPreviewServer,
363362
onCleanup,
364363
tempContext: globalTempContext,
365-
checkRender,
364+
checkRender: async (options) => {
365+
// Dynamic import to avoid async module initialization chain in bundle
366+
const { checkRender } = await import("../command/check/check-render.ts");
367+
return await checkRender(options);
368+
},
366369
},
367370

368371
text: {

0 commit comments

Comments
 (0)