chore: improve demo dependency logic (#45142)

This commit is contained in:
2023-10-07 09:45:27 +08:00 committed by GitHub
parent a2192281be
commit 131a17d099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -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;
}, },

View File

@ -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) {