提交 2363cbc0 编写于 作者: fxy060608's avatar fxy060608

feat(easycom): add conflict warning

上级 3aa1dffa
...@@ -7,6 +7,7 @@ import { createFilter } from '@rollup/pluginutils' ...@@ -7,6 +7,7 @@ import { createFilter } from '@rollup/pluginutils'
import { once } from '@dcloudio/uni-shared' import { once } from '@dcloudio/uni-shared'
import { normalizePath } from './utils' import { normalizePath } from './utils'
import { parsePagesJson, parsePagesJsonOnce } from './json/pages' import { parsePagesJson, parsePagesJsonOnce } from './json/pages'
import { M } from './messages'
interface EasycomOption { interface EasycomOption {
dirs?: string[] dirs?: string[]
...@@ -196,17 +197,35 @@ function initAutoScanEasycoms( ...@@ -196,17 +197,35 @@ function initAutoScanEasycoms(
rootDir: string, rootDir: string,
extensions: string[] extensions: string[]
) { ) {
return dirs.reduce<Record<string, string>>( const conflict: Record<string, string[]> = {}
const res = dirs.reduce<Record<string, string>>(
(easycoms: Record<string, string>, dir: string) => { (easycoms: Record<string, string>, dir: string) => {
const curEasycoms = initAutoScanEasycom(dir, rootDir, extensions) const curEasycoms = initAutoScanEasycom(dir, rootDir, extensions)
Object.keys(curEasycoms).forEach((name) => { Object.keys(curEasycoms).forEach((name) => {
// Use the first component when name conflict // Use the first component when name conflict
if (!easycoms[name]) { const compath = easycoms[name]
if (!compath) {
easycoms[name] = curEasycoms[name] easycoms[name] = curEasycoms[name]
} else {
;(conflict[compath] || (conflict[compath] = [])).push(
normalizeCompath(curEasycoms[name], rootDir)
)
} }
}) })
return easycoms return easycoms
}, },
Object.create(null) Object.create(null)
) )
const conflictComs = Object.keys(conflict)
if (conflictComs.length) {
console.warn(M['easycom.conflict'])
conflictComs.forEach((com) => {
console.warn([normalizeCompath(com, rootDir), conflict[com]].join(','))
})
}
return res
}
function normalizeCompath(compath: string, rootDir: string) {
return normalizePath(path.relative(rootDir, compath))
} }
...@@ -17,4 +17,5 @@ export const M = { ...@@ -17,4 +17,5 @@ export const M = {
'当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{locale}', '当前应用未在 manifest.json 配置 fallbackLocale,默认使用:{locale}',
'i18n.fallbackLocale.missing': 'i18n.fallbackLocale.missing':
'当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件', '当前应用配置的 fallbackLocale 或 locale 为:{locale},但 locale 目录缺少该语言文件',
'easycom.conflict': 'easycom组件冲突:',
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册