diff --git a/packages/mcp/tutorial-step-slicer.js b/packages/mcp/tutorial-step-slicer.js index 706ade7a4..64a32c08b 100644 --- a/packages/mcp/tutorial-step-slicer.js +++ b/packages/mcp/tutorial-step-slicer.js @@ -19,19 +19,14 @@ import { parseMarkdownSteps } from '@tutorials/core/tutorial-markdown-steps.js'; import { absolutizeImagePaths } from '@tutorials/core/tutorial-markdown.js'; import { filterVariants } from './option-filter.js'; import { collectTroubleshootEntries } from '../../scripts/parsers/blockquote-troubleshoot-collect.js'; - -// Lazy import: scripts/parsers/directives.js is a TypeScript source file that is NOT -// bundled into gen/srv at cds build time. At CF runtime the workspace path is absent; -// the pre-built _shared/parsers.bundle.mjs (created by scripts/bundle-shared.cjs, same -// pattern as freshness-detector.js after #3029) is used instead. -// Memoised so the async resolution only happens once per process lifetime. -let _directivesMod; -async function getDirectivesMod() { - if (_directivesMod) return _directivesMod; - try { _directivesMod = await import('../../scripts/parsers/directives.js'); } - catch { _directivesMod = await import('./_shared/parsers.bundle.mjs'); } - return _directivesMod; -} +// `renderDirectivesAsText` lives in scripts/parsers/directives.ts. Imported +// statically (same as collectTroubleshootEntries above): esbuild inlines it into +// srv/lib/_shared/mcp.bundle.mjs at bundle time, so CF runtime never needs the +// scripts/parsers/ source on disk. A dynamic import('./_shared/parsers.bundle.mjs') +// was tried (#3029 pattern) but that path is relative to packages/mcp/ — where no +// _shared/ dir is ever emitted — so esbuild could not resolve it and the bundle build +// failed. Static import avoids the runtime-path problem entirely. +import { renderDirectivesAsText } from '../../scripts/parsers/directives.js'; const NS = 'com.sap.developers.ims'; const LOG = cds.log('mcp-slicer'); @@ -268,7 +263,6 @@ async function loadAndParseMarkdown(slug) { } const { repo, branch } = await getRepoProvenance(slug); - const { renderDirectivesAsText } = await getDirectivesMod(); const steps = new Map(); for (const s of parsedSteps) { const md = renderDirectivesAsText(absolutizeImagePaths(s.markdown, { slug, repo, branch }));