Skip to content

Commit

Permalink
feat(alita): 添加收集模块的jsonRelativeFiles信息
Browse files Browse the repository at this point in the history
  • Loading branch information
ykforerlang committed Jan 2, 2020
1 parent 44b77ab commit 8b23d81
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
26 changes: 21 additions & 5 deletions src/extractWxCompFiles/extractJSONFile.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from "path";

import {getModuleInfo} from '../util/cacheModuleInfos'
import {getModuleInfo, setJsonRelativeFiles} from '../util/cacheModuleInfos'
import {getLibPath, judgeLibPath} from "../util/util"
import configure from "../configure";

Expand All @@ -15,10 +15,12 @@ export const handleChanged = (resouce, info, finalJSPath) => {

const chunks = info.chunks

const jsonRelativeFiles = new Set()

for(let i = 0; i < chunks.length; i ++ ) {
const chunk = chunks[i]

const renderUsingComponents = getUsedCompPaths(resouce, chunk)
const renderUsingComponents = getUsedCompPaths(resouce, chunk, jsonRelativeFiles)

for(let i = 0; i < outComp.length; i ++) {
const name = outComp[i]
Expand Down Expand Up @@ -53,12 +55,15 @@ export const handleChanged = (resouce, info, finalJSPath) => {
newWxOutFiles[filepathWithChunk] = renderJSONStr
}
}


setJsonRelativeFiles(resouce, jsonRelativeFiles)
return newWxOutFiles
}



function getUsedCompPaths(resouce, chunk) {
function getUsedCompPaths(resouce, chunk, jsonRelativeFiles) {

const info = getModuleInfo(resouce)

Expand All @@ -81,7 +86,7 @@ function getUsedCompPaths(resouce, chunk) {

try {
//TODO getFinalPath参数耦合太紧,切分为各独立函数模块。
usedComps[elementKey] = getFinalPath(element, source, resouce, info, defaultSpecifier, chunk)
usedComps[elementKey] = getFinalPath(element, source, resouce, info, defaultSpecifier, chunk, jsonRelativeFiles)
} catch (e) {
console.log(`${resouce.replace(configure.inputFullpath, '')} 组件${element} 搜索路径失败!`.error)
console.log(e)
Expand Down Expand Up @@ -117,18 +122,26 @@ function isRnBaseSkipEle(element, source) {
}


function getFinalPath(element, source, module, info, defaultSpecifier, chunk) {
function getFinalPath(element, source, module, info, defaultSpecifier, chunk, jsonRelativeFiles) {

let requireAbsolutePath = null
let requireDefault = true
if (source === 'react-native') {
requireAbsolutePath = getCompPath(chunk, source, `WX${element}`)
jsonRelativeFiles.add(source)
} else if (judgeLibPath(source) && source === getLibPath(source) && getCompPath(chunk, source, element)) {
requireAbsolutePath = getCompPath(chunk, source, element)
jsonRelativeFiles.add(source)
} else {
const deepSeekResult = deepSeekPath(element, info.deps[source], defaultSpecifier, chunk)
requireAbsolutePath = deepSeekResult.absolutePath
requireDefault = deepSeekResult.defaultSpecifier

if (judgeLibPath(source)) {
jsonRelativeFiles.add(getLibPath(source))
} else {
jsonRelativeFiles.add(deepSeekResult.rawAbsolutePath)
}
}

if (chunk !== '_rn_') {
Expand Down Expand Up @@ -161,6 +174,8 @@ function deepSeekPath(element, absolutePath, defaultSpecifier, chunk) {
}


const rawAbsolutePath = absolutePath

if (!(info.chunks.length === 1 && info.chunks[0] === '_rn_')) {
const subpageDir = chunk === '_rn_' ? '': chunk.replace('/_rn_', '')
absolutePath = absolutePath
Expand All @@ -170,6 +185,7 @@ function deepSeekPath(element, absolutePath, defaultSpecifier, chunk) {
return {
absolutePath,
defaultSpecifier,
rawAbsolutePath,
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/util/cacheModuleInfos.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ interface IModuleInfo {

chunks?: any,

jsonRelativeFiles?: any,

}

interface IModuleInfos {
Expand Down Expand Up @@ -77,6 +79,11 @@ export function updateModuleOutFiles(filepath, outFiles) {
moduleInfos[filepath].outFiles = outFiles
}


export function setJsonRelativeFiles(filepath, jsonRelativeFiles) {
moduleInfos[filepath].jsonRelativeFiles = jsonRelativeFiles
}

export function getModuleInfos() {
return moduleInfos
}
Expand Down

0 comments on commit 8b23d81

Please sign in to comment.