Skip to content

Commit

Permalink
fix(taro-cli): 符号链接+Alias导致源代码文件被意外修改 (#2176)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meeeeow authored and luckyadam committed Feb 14, 2019
1 parent b265628 commit d88c7ed
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/taro-cli/src/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,14 @@ exports.isAliasPath = function (name, pathAlias = {}) {
}

exports.replaceAliasPath = function (filePath, name, pathAlias = {}) {
// 后续的 path.join 在遇到符号链接时将会解析为真实路径,如果
// 这里的 filePath 没有做同样的处理,可能会导致 import 指向
// 源代码文件,导致文件被意外修改
filePath = fs.realpathSync(filePath)

const prefixs = Object.keys(pathAlias)
if (prefixs.includes(name)) {
return exports.promoteRelativePath(path.relative(filePath, pathAlias[name]))
return exports.promoteRelativePath(path.relative(filePath, fs.realpathSync(pathAlias[name])))
}
const reg = new RegExp(`^(${prefixs.join('|')})/(.*)`)
name = name.replace(reg, function (m, $1, $2) {
Expand Down

0 comments on commit d88c7ed

Please sign in to comment.