From c541cef7b353eb558f35ca1c10995cb3eb7112f2 Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Wed, 25 Sep 2024 14:27:10 +0800 Subject: [PATCH] fix: relative deps context inject (#2203) * fix: relative deps context inject * fix: let --- src/loaders/markdown/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/loaders/markdown/index.ts b/src/loaders/markdown/index.ts index ee1b7fd42..349810dc5 100644 --- a/src/loaders/markdown/index.ts +++ b/src/loaders/markdown/index.ts @@ -144,15 +144,18 @@ function emitDemo( const { demos } = ret.meta; const shareDepsMap: Record = {}; const demoDepsMap: Record> = {}; + const relativeDepsMap: Record> = {}; demos?.forEach((demo) => { if ('resolveMap' in demo && 'asset' in demo) { const entryFileName = Object.keys(demo.asset.dependencies)[0]; demoDepsMap[demo.id] ??= {}; + relativeDepsMap[demo.id] ??= {}; Object.keys(demo.resolveMap).forEach((key, index) => { const specifier = `${demo.id.replace(/[^\w\d]/g, '_')}_deps_${index}`; if (key !== entryFileName) { - const normalizedKey = isRelativePath(key) + const isRelative = isRelativePath(key); + const normalizedKey = isRelative ? winPath(demo.resolveMap[key]) : key; @@ -162,6 +165,12 @@ function emitDemo( } else { demoDepsMap[demo.id][normalizedKey] = shareDepsMap[normalizedKey]; } + + if (isRelative) { + relativeDepsMap[demo.id][key] = `{{{${ + shareDepsMap[normalizedKey] || specifier + }}}}`; + } } }); } @@ -244,7 +253,7 @@ export const demos = { ...acc, ...{ [key]: `{{{${specifier}}}}` }, }), - {}, + relativeDepsMap[this.id], ); return JSON.stringify(context, null, 2).replace(/"{{{|}}}"/g, ''); },