Skip to content

Commit

Permalink
fix(mini-runner): 修复包未安装不报错的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 7, 2020
1 parent ab3279a commit 5552fa2
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions packages/taro-mini-runner/src/plugins/MiniPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,23 +341,31 @@ export default class MiniPlugin {
transformComponentsPath (filePath, components: IComponentObj[]) {
const { buildAdapter, alias } = this.options
components.forEach(component => {
let componentPath = component.path
let realComponentPath
if (componentPath) {
if (isNpmPkg(componentPath)) {
if (isAliasPath(componentPath, alias)) {
componentPath = replaceAliasPath(filePath, componentPath, alias)
realComponentPath = resolveScriptPath(path.resolve(filePath, '..', componentPath as string))
try {
let componentPath = component.path
let realComponentPath
if (componentPath) {
if (isNpmPkg(componentPath)) {
if (isAliasPath(componentPath, alias)) {
componentPath = replaceAliasPath(filePath, componentPath, alias)
realComponentPath = resolveScriptPath(path.resolve(filePath, '..', componentPath as string))
} else {
realComponentPath = resolveNpmSync(componentPath, this.context)
}
} else {
realComponentPath = resolveNpmSync(componentPath, this.context)
realComponentPath = resolveScriptPath(path.resolve(filePath, '..', componentPath as string))
}
const code = fs.readFileSync(realComponentPath).toString()
const newComponent = Object.assign({}, component, { path: realComponentPath })
realComponentPath = this.getNpmComponentRealPath(code, newComponent, buildAdapter)
component.path = realComponentPath
}
} catch (error) {
if (error.codeFrame) {
this.errors.push(new Error(error.message + '\n' + error.codeFrame))
} else {
realComponentPath = resolveScriptPath(path.resolve(filePath, '..', componentPath as string))
this.errors.push(error)
}
const code = fs.readFileSync(realComponentPath).toString()
const newComponent = Object.assign({}, component, { path: realComponentPath })
realComponentPath = this.getNpmComponentRealPath(code, newComponent, buildAdapter)
component.path = realComponentPath
}
})
}
Expand Down

0 comments on commit 5552fa2

Please sign in to comment.