Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions packages/mcp/tutorial-step-slicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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 }));
Expand Down
Loading