Skip to content

Commit

Permalink
fix(mini-runner): 修复 windows 下编译后 taro 引用错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Dec 3, 2019
1 parent 8ce0d6a commit 094b6ac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
19 changes: 10 additions & 9 deletions packages/taro-mini-runner/src/loaders/fileParseLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import {
taroJsRedux,
QUICKAPP_SPECIAL_COMPONENTS,
PARSE_AST_TYPE,
NODE_MODULES_REG
NODE_MODULES_REG,
excludeReplaceTaroFrameworkPkgs
} from '../utils/constants'
import {
isNpmPkg,
Expand Down Expand Up @@ -192,9 +193,6 @@ function processAst (
)
return
}
if (NODE_MODULES_REG.test(sourceFilePath) && sourceFilePath.indexOf(taroMiniAppFramework) >= 0) {
return
}
if (isNpmPkg(value)) {
if (value === taroJsComponents) {
if (isQuickApp) {
Expand All @@ -219,7 +217,10 @@ function processAst (
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 @@ -250,9 +251,6 @@ function processAst (
callee.name = NON_WEBPACK_REQUIRE
return
}
if (NODE_MODULES_REG.test(sourceFilePath) && sourceFilePath.indexOf(taroMiniAppFramework) >= 0) {
return
}
if (isNpmPkg(value)) {
if (value === taroJsComponents) {
if (isQuickApp) {
Expand All @@ -275,7 +273,10 @@ function processAst (
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
4 changes: 4 additions & 0 deletions packages/taro-mini-runner/src/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ export const taroJsComponents = '@tarojs/components'
export const taroJsQuickAppComponents = '@tarojs/components-qa'
export const taroJsFramework = '@tarojs/taro'
export const taroJsRedux = '@tarojs/redux'
export const taroJsMobx = '@tarojs/mobx'
export const taroJsMobxCommon = '@tarojs/mobx-common'

export const DEVICE_RATIO_NAME = 'deviceRatio'
export const isWindows = os.platform() === 'win32'
Expand Down Expand Up @@ -301,3 +303,5 @@ export const processTypeMap: IProcessTypeMap = {
color: 'blue'
}
}

export const excludeReplaceTaroFrameworkPkgs = new Set([taroJsRedux, taroJsMobx, taroJsMobxCommon])

0 comments on commit 094b6ac

Please sign in to comment.