Skip to content

Commit 8036b68

Browse files
committed
fix(alita): 修复导入目录,小程序json文件路径错误的bug
1 parent 520b0cf commit 8036b68

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/tran/handleImportExpre.ts

+15-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
*
77
*/
88

9+
import * as npath from 'path'
10+
import * as fse from 'fs-extra'
911
import traverse from "@babel/traverse"
1012
import * as t from "@babel/types"
1113
import {RNNOTSUPPORTCOMP} from '../constants'
@@ -65,15 +67,27 @@ export default function (ast, info){
6567

6668

6769
function geneUsedComps(idens, relativePath, JSXElements, usedComponent, filepath) {
70+
const isCompModule = idens.some(iden => JSXElements.has(iden))
71+
if (!isCompModule) {
72+
return
73+
}
74+
6875
const relativeFilePath = filepath.replace(configure.inputFullpath, '')
6976
const isLibPath = judgeLibPath(relativePath)
7077

7178
if (!isLibPath) {
79+
const absoluteRP = npath.resolve(npath.dirname(filepath), relativePath)
80+
81+
let compPath = relativePath
82+
if (fse.existsSync(absoluteRP)) {
83+
compPath = `${relativePath}/index`
84+
}
85+
7286
for (let i = 0; i < idens.length; i ++ ) {
7387
const importElement = idens[i]
7488

7589
if(JSXElements.has(importElement)){
76-
usedComponent[importElement] = relativePath
90+
usedComponent[importElement] = compPath
7791
}
7892
}
7993
} else {

0 commit comments

Comments
 (0)