Skip to content

Commit

Permalink
feat(mp-toutiao): pages.json support ext:// path (dcloudio#3917)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxy060608 committed Oct 11, 2022
1 parent ac176ea commit 7acb012
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
9 changes: 7 additions & 2 deletions packages/uni-cli-shared/lib/cache.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fs = require('fs')
const path = require('path')
const crypto = require('crypto')
const {
isNormalPage
} = require('./util')
/**
* 1.page-loader 缓存基础的 app.json page.json project.config.json
* 2.main-loader 缓存 app.json 中的 usingComponents 节点
Expand Down Expand Up @@ -49,7 +52,9 @@ function getJsonFile (name) {
function getChangedJsonFileMap (clear = true) {
const changedJsonFileMap = new Map()
for (const name of changedJsonFileSet.values()) {
changedJsonFileMap.set(name + '.json', jsonFileMap.get(name))
if (isNormalPage(name)) {
changedJsonFileMap.set(name + '.json', jsonFileMap.get(name))
}
}
clear && changedJsonFileSet.clear()
return changedJsonFileMap
Expand Down Expand Up @@ -361,4 +366,4 @@ module.exports = {
getChangedJsonFileMap,
getSpecialMethods,
supportGlobalUsingComponents
}
}
28 changes: 21 additions & 7 deletions packages/uni-cli-shared/lib/pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const {
removeExt,
normalizePath,
camelize,
capitalize
capitalize,
isNormalPage
} = require('./util')

const {
Expand Down Expand Up @@ -113,7 +114,9 @@ function isNVuePage (page, root = '') {

function isValidPage (page, root = '') {
if (typeof page === 'string' || !page.path) { // 不合法的配置
console.warn(uniI18n.__('cliShared.pagesJsonError', { 0: 'https://uniapp.dcloud.io/collocation/pages?id=pages' }))
console.warn(uniI18n.__('cliShared.pagesJsonError', {
0: 'https://uniapp.dcloud.io/collocation/pages?id=pages'
}))
return false
}
let pagePath = page.path
Expand Down Expand Up @@ -213,7 +216,10 @@ function parseEntry (pagesJson) {
const weixinConfig = manifestConfig['mp-weixin'] || {}
const independentSwitch = !!weixinConfig.independent
if (independentSwitch) {
Object.values(process.UNI_SUBPACKAGES).forEach(({ root, independent = false }) => {
Object.values(process.UNI_SUBPACKAGES).forEach(({
root,
independent = false
}) => {
if (root && independent) {
const pkgRootMainJsKey = `${root}/common/main`
// const pkgRootMainJsPath = `${process.env.UNI_INPUT_DIR}/${root}/main.js`;
Expand All @@ -239,7 +245,9 @@ function parseEntry (pagesJson) {

// pages
pagesJson.pages.forEach(page => {
process.UNI_ENTRY[page.path] = getMainJsPath(page.path)
if (isNormalPage(page.path)) {
process.UNI_ENTRY[page.path] = getMainJsPath(page.path)
}
})
// subPackages
if (Array.isArray(pagesJson.subPackages) && pagesJson.subPackages.length) {
Expand Down Expand Up @@ -404,7 +412,11 @@ function initAutoComponents () {
})
if (conflictFiles.length > 0) {
conflictFiles.forEach(files => {
console.warn(uniI18n.__('cliShared.easycomConflict', { 0: '[' + files.map((file, index) => { return file }).join(',') + ']' }))
console.warn(uniI18n.__('cliShared.easycomConflict', {
0: '[' + files.map((file, index) => {
return file
}).join(',') + ']'
}))
console.log('\n')
})
}
Expand Down Expand Up @@ -519,7 +531,9 @@ function parseUsingAutoImportComponents (usingAutoImportComponents) {

const BUILT_IN_COMPONENTS = ['page-meta', 'navigation-bar', 'uni-match-media']

const BUILT_IN_EASYCOMS = ['unicloud-db', 'uniad', 'ad-rewarded-video', 'ad-fullscreen-video', 'ad-interstitial', 'ad-interactive']
const BUILT_IN_EASYCOMS = ['unicloud-db', 'uniad', 'ad-rewarded-video', 'ad-fullscreen-video', 'ad-interstitial',
'ad-interactive'
]

function isBuiltInComponent (name) { // uni-template-compiler/lib/util.js 识别微信内置组件
return BUILT_IN_COMPONENTS.includes(name)
Expand Down Expand Up @@ -551,4 +565,4 @@ module.exports = {
getGlobalUsingComponentsCode,
parseUsingAutoImportComponents,
generateGlobalUsingComponentsCode
}
}
9 changes: 9 additions & 0 deletions packages/uni-cli-shared/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,17 @@ function pathToGlob (pathString, glob, options = {}) {
}
return path.posix.join(safeStr, glob)
}
/**
* 字节跳动小程序可以配置 ext:// 开头的插件页面模板,如 ext://microapp-trade-plugin/order-confirm
* @param pagePath
* @returns
*/
function isNormalPage (pagePath) {
return !pagePath.startsWith('ext://')
}

module.exports = {
isNormalPage,
isInHBuilderX,
isInHBuilderXAlpha,
getCLIContext,
Expand Down

0 comments on commit 7acb012

Please sign in to comment.