From 013a1c39a5c60acc50f6b70494e138ed44c42936 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Mon, 4 Nov 2019 22:13:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(cli):=20=E4=BF=AE=E5=A4=8D=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=20node=5Fmodules=20=E4=B8=AD=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-cli/src/mini/astProcess.ts | 11 +++++++++-- packages/taro-cli/src/util/resolve_npm_files.ts | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/taro-cli/src/mini/astProcess.ts b/packages/taro-cli/src/mini/astProcess.ts index c6d1946fc917..8fab73b19c64 100644 --- a/packages/taro-cli/src/mini/astProcess.ts +++ b/packages/taro-cli/src/mini/astProcess.ts @@ -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 { @@ -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') { @@ -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 => { diff --git a/packages/taro-cli/src/util/resolve_npm_files.ts b/packages/taro-cli/src/util/resolve_npm_files.ts index febaee160710..f44619867f05 100644 --- a/packages/taro-cli/src/util/resolve_npm_files.ts +++ b/packages/taro-cli/src/util/resolve_npm_files.ts @@ -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,