From 7acb0125317f3e9e3c70171ccba27caec1fca5bd Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Tue, 11 Oct 2022 19:34:50 +0800 Subject: [PATCH] feat(mp-toutiao): pages.json support ext:// path (#3917) --- packages/uni-cli-shared/lib/cache.js | 9 +++++++-- packages/uni-cli-shared/lib/pages.js | 28 +++++++++++++++++++++------- packages/uni-cli-shared/lib/util.js | 9 +++++++++ 3 files changed, 37 insertions(+), 9 deletions(-) diff --git a/packages/uni-cli-shared/lib/cache.js b/packages/uni-cli-shared/lib/cache.js index 23c2adcfc..0e3cbc786 100644 --- a/packages/uni-cli-shared/lib/cache.js +++ b/packages/uni-cli-shared/lib/cache.js @@ -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 节点 @@ -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 @@ -361,4 +366,4 @@ module.exports = { getChangedJsonFileMap, getSpecialMethods, supportGlobalUsingComponents -} +} diff --git a/packages/uni-cli-shared/lib/pages.js b/packages/uni-cli-shared/lib/pages.js index acf03c89e..0f70942ea 100644 --- a/packages/uni-cli-shared/lib/pages.js +++ b/packages/uni-cli-shared/lib/pages.js @@ -6,7 +6,8 @@ const { removeExt, normalizePath, camelize, - capitalize + capitalize, + isNormalPage } = require('./util') const { @@ -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 @@ -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`; @@ -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) { @@ -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') }) } @@ -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) @@ -551,4 +565,4 @@ module.exports = { getGlobalUsingComponentsCode, parseUsingAutoImportComponents, generateGlobalUsingComponentsCode -} +} diff --git a/packages/uni-cli-shared/lib/util.js b/packages/uni-cli-shared/lib/util.js index 19dc3e804..ef07d861d 100644 --- a/packages/uni-cli-shared/lib/util.js +++ b/packages/uni-cli-shared/lib/util.js @@ -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, -- GitLab