mirror of
https://gitee.com/ant-design/ant-design.git
synced 2024-12-03 04:30:06 +08:00
chore: improve demo dependency logic (#45142)
This commit is contained in:
parent
a2192281be
commit
131a17d099
@ -208,12 +208,10 @@ const CodePreviewer: React.FC<AntdPreviewerProps> = (props) => {
|
||||
const dependencies: Record<PropertyKey, string> = jsx.split('\n').reduce(
|
||||
(acc, line) => {
|
||||
const matches = line.match(/import .+? from '(.+)';$/);
|
||||
if (matches && matches[1] && !line.includes('antd')) {
|
||||
if (matches?.[1]) {
|
||||
const paths = matches[1].split('/');
|
||||
if (paths.length) {
|
||||
const dep = paths[0].startsWith('@') ? `${paths[0]}/${paths[1]}` : paths[0];
|
||||
acc[dep] = 'latest';
|
||||
}
|
||||
const dep = paths[0].startsWith('@') ? `${paths[0]}/${paths[1]}` : paths[0];
|
||||
acc[dep] ??= pkgDependencyList[dep] ?? 'latest';
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
|
@ -44,9 +44,11 @@ class AntdReactTechStack extends ReactTechStack {
|
||||
|
||||
const codePath = opts.fileAbsPath!.replace(/\.\w+$/, '.tsx');
|
||||
const code = fs.existsSync(codePath) ? fs.readFileSync(codePath, 'utf-8') : '';
|
||||
const pkgDependencyList = localPackage.dependencies;
|
||||
|
||||
props.pkgDependencyList = pkgDependencyList;
|
||||
props.pkgDependencyList = {
|
||||
...localPackage.devDependencies,
|
||||
...localPackage.dependencies,
|
||||
};
|
||||
props.jsx = sylvanas.parseText(code);
|
||||
|
||||
if (md) {
|
||||
|
Loading…
Reference in New Issue
Block a user