mirror of
https://github.com/ant-design/ant-design.git
synced 2025-01-19 06:43:16 +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(
|
const dependencies: Record<PropertyKey, string> = jsx.split('\n').reduce(
|
||||||
(acc, line) => {
|
(acc, line) => {
|
||||||
const matches = line.match(/import .+? from '(.+)';$/);
|
const matches = line.match(/import .+? from '(.+)';$/);
|
||||||
if (matches && matches[1] && !line.includes('antd')) {
|
if (matches?.[1]) {
|
||||||
const paths = matches[1].split('/');
|
const paths = matches[1].split('/');
|
||||||
if (paths.length) {
|
const dep = paths[0].startsWith('@') ? `${paths[0]}/${paths[1]}` : paths[0];
|
||||||
const dep = paths[0].startsWith('@') ? `${paths[0]}/${paths[1]}` : paths[0];
|
acc[dep] ??= pkgDependencyList[dep] ?? 'latest';
|
||||||
acc[dep] = 'latest';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return acc;
|
return acc;
|
||||||
},
|
},
|
||||||
|
@ -44,9 +44,11 @@ class AntdReactTechStack extends ReactTechStack {
|
|||||||
|
|
||||||
const codePath = opts.fileAbsPath!.replace(/\.\w+$/, '.tsx');
|
const codePath = opts.fileAbsPath!.replace(/\.\w+$/, '.tsx');
|
||||||
const code = fs.existsSync(codePath) ? fs.readFileSync(codePath, 'utf-8') : '';
|
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);
|
props.jsx = sylvanas.parseText(code);
|
||||||
|
|
||||||
if (md) {
|
if (md) {
|
||||||
|
Loading…
Reference in New Issue
Block a user