Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(taro-cli): 符号链接+Alias导致源代码文件被意外修改 #2176

Merged
merged 1 commit into from
Feb 14, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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