From 488f97251e20d45f6c57d5314b2a3840932e5bdd Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Fri, 20 Sep 2024 13:29:50 +0800 Subject: [PATCH 1/2] fix: relative deps context inject --- src/loaders/markdown/index.ts | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/loaders/markdown/index.ts b/src/loaders/markdown/index.ts index ee1b7fd42..cdf790b7e 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 + }}}}`; + } } }); } @@ -239,12 +248,12 @@ export const demos = { opts.disableLiveDemo ) return 'undefined'; - const context = Object.entries(demoDepsMap[this.id]).reduce( + let context = Object.entries(demoDepsMap[this.id]).reduce( (acc, [key, specifier]) => ({ ...acc, ...{ [key]: `{{{${specifier}}}}` }, }), - {}, + relativeDepsMap[this.id], ); return JSON.stringify(context, null, 2).replace(/"{{{|}}}"/g, ''); }, From d1a3329497d85faa533e91951f69f7168c4bd907 Mon Sep 17 00:00:00 2001 From: Jinbao1001 Date: Fri, 20 Sep 2024 13:40:17 +0800 Subject: [PATCH 2/2] fix: let --- src/loaders/markdown/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loaders/markdown/index.ts b/src/loaders/markdown/index.ts index cdf790b7e..349810dc5 100644 --- a/src/loaders/markdown/index.ts +++ b/src/loaders/markdown/index.ts @@ -248,7 +248,7 @@ export const demos = { opts.disableLiveDemo ) return 'undefined'; - let context = Object.entries(demoDepsMap[this.id]).reduce( + const context = Object.entries(demoDepsMap[this.id]).reduce( (acc, [key, specifier]) => ({ ...acc, ...{ [key]: `{{{${specifier}}}}` },