Skip to content

Commit

Permalink
fix: relative deps context inject (#2203)
Browse files Browse the repository at this point in the history
* fix: relative deps context inject

* fix: let
  • Loading branch information
Jinbao1001 authored Sep 25, 2024
1 parent 74be4d0 commit c541cef
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/loaders/markdown/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,18 @@ function emitDemo(
const { demos } = ret.meta;
const shareDepsMap: Record<string, string> = {};
const demoDepsMap: Record<string, Record<string, string>> = {};
const relativeDepsMap: Record<string, Record<string, string>> = {};

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;

Expand All @@ -162,6 +165,12 @@ function emitDemo(
} else {
demoDepsMap[demo.id][normalizedKey] = shareDepsMap[normalizedKey];
}

if (isRelative) {
relativeDepsMap[demo.id][key] = `{{{${
shareDepsMap[normalizedKey] || specifier
}}}}`;
}
}
});
}
Expand Down Expand Up @@ -244,7 +253,7 @@ export const demos = {
...acc,
...{ [key]: `{{{${specifier}}}}` },
}),
{},
relativeDepsMap[this.id],
);
return JSON.stringify(context, null, 2).replace(/"{{{|}}}"/g, '');
},
Expand Down

0 comments on commit c541cef

Please sign in to comment.