Skip to content

Commit

Permalink
fix(cli): 修复解析 node_modules 中组件路径的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Nov 4, 2019
1 parent a442efd commit 013a1c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions packages/taro-cli/src/mini/astProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
} from '../util/astConvert'
import babylonConfig from '../config/babylon'
import { getExactedNpmFilePath, getNotExistNpmList } from '../util/npmExact'
import { excludeReplaceTaroFrameworkPkgs } from '../util/resolve_npm_files'

import { IComponentObj } from './interface'
import {
Expand Down Expand Up @@ -490,7 +491,10 @@ export function parseAst (
if (defaultSpecifier) {
taroImportDefaultName = defaultSpecifier
}
value = taroMiniAppFramework
excludeReplaceTaroFrameworkPkgs.add(taroMiniAppFramework)
if (!Array.from(excludeReplaceTaroFrameworkPkgs).some(item => sourceFilePath.replace(/\\/g, '/').indexOf(item) >= 0)) {
value = taroMiniAppFramework
}
} else if (value === taroJsRedux) {
specifiers.forEach(item => {
if (item.type === 'ImportSpecifier') {
Expand Down Expand Up @@ -592,7 +596,10 @@ export function parseAst (
const id = parentNode.declarations[0].id
if (value === taroJsFramework && id.type === 'Identifier') {
taroImportDefaultName = id.name
value = taroMiniAppFramework
excludeReplaceTaroFrameworkPkgs.add(taroMiniAppFramework)
if (!Array.from(excludeReplaceTaroFrameworkPkgs).some(item => sourceFilePath.replace(/\\/g, '/').indexOf(item) >= 0)) {
value = taroMiniAppFramework
}
} else if (value === taroJsRedux) {
const declarations = parentNode.declarations
declarations.forEach(item => {
Expand Down
2 changes: 1 addition & 1 deletion packages/taro-cli/src/util/resolve_npm_files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const excludeNpmPkgs = ['ReactPropTypes']

const resolvedCache: IResolvedCache = {}
const copyedFiles = {}
const excludeReplaceTaroFrameworkPkgs = new Set([taroJsRedux, taroJsMobx, taroJsMobxCommon])
export const excludeReplaceTaroFrameworkPkgs = new Set([taroJsRedux, taroJsMobx, taroJsMobxCommon])

export function resolveNpmPkgMainPath (
pkgName: string,
Expand Down

0 comments on commit 013a1c3

Please sign in to comment.