Skip to content

Commit

Permalink
fix(cli): 组件库未npm包时其中的组件无法识别
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen authored and jia000 committed Dec 9, 2024
1 parent a569d51 commit e6909dc
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/cli/src/utils/resolveAppPackages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execSync } from 'child_process';
import path from 'path';
import { exit } from 'process';
import { execSync } from 'node:child_process';
import path from 'node:path';
import { exit } from 'node:process';

import fs, { existsSync } from 'fs-extra';
import * as recast from 'recast';
Expand Down Expand Up @@ -290,7 +290,7 @@ const getComponentPackageImports = function ({
};

const getIndexPath = function (entry: string) {
for (const affix of ['', '.js', '.ts']) {
for (const affix of ['', '.js', '.cjs', 'mjs', '.ts']) {
const filePath = `${entry}${affix}`;
if (isFile(filePath)) {
return filePath;
Expand Down Expand Up @@ -469,7 +469,7 @@ const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string

if (isDirectory(moduleName)) {
if (!fs.existsSync(path.join(moduleName, './package.json'))) {
['index.js', 'index.ts'].forEach((index) => {
['index.js', 'index.ts', 'index.cjs', 'index.mjs', 'index.json'].forEach((index) => {
const indexFile = path.join(moduleName!, `./${index}`);
if (fs.existsSync(indexFile)) {
moduleName = indexFile;
Expand All @@ -493,7 +493,17 @@ const setPackages = (packages: ModuleMainFilePath, app: App, packagePath: string
// 组件&插件&数据源包
if (result.type === PackageType.COMPONENT_PACKAGE) {
result.imports.forEach((i) => {
setPackages(packages, app, i.indexPath, moduleName!, i.type);
if (!moduleName) {
return;
}

let componentCwd = moduleName;

if (!isDirectory(moduleName)) {
componentCwd = path.join(cwd, `node_modules/${moduleName}`);
}

setPackages(packages, app, i.indexPath, componentCwd, i.type);
});

return;
Expand Down

0 comments on commit e6909dc

Please sign in to comment.