Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions packages/uni-cli-shared/__tests__/cache.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,31 @@ describe('shared:cache', () => {
})

it('mp-toutiao generate component.json', () => {
const prevPlatform = process.env.UNI_PLATFORM
process.env.UNI_PLATFORM = 'mp-toutiao'
const name = 'components/component-tag-name'
// 独立 name:覆盖 add 与 update。不得再强制注入 componentPlaceholder(#6057)
const name = 'components/toutiao-no-force-placeholder'
let usingComponents = {
'my-component': '/components/component-tag-name'
}
const componentPlaceholder = {
'my-component': 'view'
}
updateUsingComponents(name, usingComponents, 'Component')
let componentJsonStr = getChangedJsonFileMap().get(name + '.json')
expect(componentJsonStr).toBe(JSON.stringify({
usingComponents,
component: true,
componentPlaceholder
component: true
}, null, 2))
expect(0).toBe(getChangedJsonFileMap().size)

usingComponents = {}
usingComponents = {
'u-icon': '/components/u-icon'
}
updateUsingComponents(name, usingComponents, 'Component')
componentJsonStr = getChangedJsonFileMap().get(name + '.json')
expect(componentJsonStr).toBe(JSON.stringify({
usingComponents,
component: true,
componentPlaceholder
component: true
}, null, 2))
expect(0).toBe(getChangedJsonFileMap().size)
process.env.UNI_PLATFORM = prevPlatform
})
})
12 changes: 0 additions & 12 deletions packages/uni-cli-shared/lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,18 +200,6 @@ function updateUsingComponents (name, usingComponents, type, content = '') {
}
if (oldJsonStr) { // update
jsonObj.usingComponents = usingComponents
// 嵌套组件获取 props 为 null,使用占组件修正父子组件生命周期执行顺序 https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/tutorial/custom-component/placeholder
if (process.env.UNI_PLATFORM === 'mp-toutiao') {
if (type === 'Component') {
const usingComponentnames = Object.keys(jsonObj.usingComponents)
if (usingComponentnames.length) {
jsonObj.componentPlaceholder = {}
usingComponentnames.forEach(componentName => {
jsonObj.componentPlaceholder[componentName] = 'view'
})
}
}
}
const newJsonStr = JSON.stringify(jsonObj, null, 2)
if (newJsonStr !== oldJsonStr) {
updateJsonFile(name, newJsonStr)
Expand Down