-
Notifications
You must be signed in to change notification settings - Fork 18
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: 更改/开头路径导入报错问题 #165
fix: 更改/开头路径导入报错问题 #165
Conversation
@@ -23,31 +23,38 @@ export function getPkgVersion (): string { | |||
return require(path.join(getRootPath(), 'package.json')).version | |||
} | |||
|
|||
function getRelativePath (rootPath: string, sourceFilePath: string, oriPath: string) { | |||
function revertScriptPath (p: string, extArrs = SCRIPT_EXT): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
变量名不要用单个字符
if (relativePath.indexOf('.') !== 0) { | ||
return './' + relativePath | ||
const absSearchPath = revertScriptPath(path.resolve(sourceFilePath, '..' + oriPath)) | ||
let absolutePath = path.relative(path.dirname(sourceFilePath), absSearchPath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里是相对路径,absSearchPath变量名是否不合适
relativePath = promoteRelativePath(relativePath) | ||
if (relativePath.indexOf('.') !== 0) { | ||
return './' + relativePath | ||
const absSearchPath = revertScriptPath(path.resolve(sourceFilePath, '..' + oriPath)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
返回为空字符串的情况有没有考虑
// 微信小程序中js文件的引用可不加后缀,需考虑 | ||
return `./${oriPath}.js` | ||
const vpath = revertScriptPath(path.resolve(sourceFilePath, '..', oriPath)) | ||
const absolutePath = path.relative(path.dirname(sourceFilePath), vpath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
相对路径为啥叫absolutePath
return `./${oriPath}.js` | ||
const vpath = revertScriptPath(path.resolve(sourceFilePath, '..', oriPath)) | ||
const absolutePath = path.relative(path.dirname(sourceFilePath), vpath) | ||
if (vpath) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果vpath是空字符串呢
@@ -23,31 +23,38 @@ export function getPkgVersion (): string { | |||
return require(path.join(getRootPath(), 'package.json')).version | |||
} | |||
|
|||
function getRelativePath (rootPath: string, sourceFilePath: string, oriPath: string) { | |||
function revertScriptPath (p: string, extArrs = SCRIPT_EXT): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把SCRIPT_EXT的内容提取出来加个注释吧
} else if (fs.existsSync(`${p}${item}`)){ | ||
return `${p}${item}` | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
遍历如果可以的话,尽量用对象或数组自身的方法,这里可以用foreach,for循环中的索引命名也尽量有意义。
let absolutePath = path.relative(path.dirname(sourceFilePath), absSearchPath) | ||
absolutePath = promoteRelativePath(absolutePath) | ||
if (absolutePath.indexOf('.') !== 0) { | ||
return './' + absolutePath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多处的字符串拼接,尽量采取同一种形式,建议采用模板字符串继续字符串拼接,并且统一
这个 PR 做了什么? (简要描述所做更改)
更改/开头路径导入报错问题
这个 PR 是什么类型? (至少选择一个)
这个 PR 涉及以下平台: