Skip to content

Commit

Permalink
fix: 修复 componet 多引入场景下导致的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
murongg committed Dec 18, 2020
1 parent 96cb64e commit d978ccc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 14 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ exports.findJson = findJson;
* @returns {(string | null)}
*/
function getStr(str, start, end) {
let res = str.match(new RegExp(`${start}(.*?)${end}`));
const reg = new RegExp(`${start}(.*?)${end}`);
let res = str.match(reg);
return res ? res[1] : null;
}
exports.getStr = getStr;
Expand Down Expand Up @@ -75,10 +76,21 @@ function getComponentsName(pagesJson, isNodeModules = false, linUiDir, miniProgr
}
}
componentsPath.forEach((item) => {
const component = getStr(item, path, '/index');
// 当为 /miniprogram_npm/lin-ui/button/index 时
const componentWithIndex = getStr(item, path, '/index');
if (componentWithIndex) {
names.add(componentWithIndex);
return;
}
// 当为 /miniprogram_npm/lin-ui/button/ 时
const component = getStr(item, path, '/');
if (component) {
names.add(component);
return;
}
// 当为 /miniprogram_npm/lin-ui/button 时
let arr = item.split(path);
names.add(arr[arr.length - 1]);
});
return names;
}
Expand Down
16 changes: 14 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export function findJson(pathArr: Set<string>): Set<string> {
* @returns {(string | null)}
*/
export function getStr(str: string, start: string, end: string): string | null {
let res = str.match(new RegExp(`${start}(.*?)${end}`))
const reg = new RegExp(`${start}(.*?)${end}`)
let res = str.match(reg)
return res ? res[1] : null
}

Expand Down Expand Up @@ -75,10 +76,21 @@ export function getComponentsName(pagesJson: Array<PageJson> | PageJson, isNodeM
}
}
componentsPath.forEach((item: string) => {
const component = getStr(item, path, '/index')
// 当为 /miniprogram_npm/lin-ui/button/index 时
const componentWithIndex = getStr(item, path, '/index')
if (componentWithIndex) {
names.add(componentWithIndex)
return
}
// 当为 /miniprogram_npm/lin-ui/button/ 时
const component = getStr(item, path, '/')
if (component) {
names.add(component)
return
}
// 当为 /miniprogram_npm/lin-ui/button 时
let arr = item.split(path)
names.add(arr[arr.length - 1])
})
return names
}
Expand Down

0 comments on commit d978ccc

Please sign in to comment.