@dcloudio/uni-cli-shared 3.0.0-5010520260709002 → 3.0.0-5020320260806002
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dom2/vue.d.ts +0 -1
- package/dist/dom2/vue.js +1 -14
- package/dist/hbx/alias.js +16 -18
- package/dist/json/app/pages/definePage.js +3 -1
- package/dist/json/mp/index.d.ts +2 -0
- package/dist/json/mp/index.js +23 -1
- package/dist/json/mp/jsonFile.d.ts +3 -2
- package/dist/json/mp/jsonFile.js +83 -13
- package/dist/json/mp/pages.d.ts +1 -0
- package/dist/json/mp/pages.js +6 -2
- package/dist/json/mp/subpackage.d.ts +26 -0
- package/dist/json/mp/subpackage.js +236 -0
- package/dist/logs/console.js +4 -1
- package/dist/messages/en.d.ts +2 -0
- package/dist/messages/en.js +2 -0
- package/dist/messages/index.d.ts +4 -0
- package/dist/messages/zh_CN.d.ts +2 -0
- package/dist/messages/zh_CN.js +2 -0
- package/dist/mp/usingComponents.d.ts +7 -5
- package/dist/mp/usingComponents.js +63 -34
- package/dist/resolve.d.ts +1 -0
- package/dist/resolve.js +9 -2
- package/dist/uts.d.ts +0 -1
- package/dist/uts.js +1 -31
- package/dist/vite/plugins/cssScoped.js +11 -2
- package/dist/vite/plugins/easycom.js +3 -1
- package/dist/vite/plugins/inject.js +7 -2
- package/dist/vite/plugins/jsonJs.js +41 -3
- package/dist/vite/plugins/sfc.js +4 -1
- package/dist/vite/plugins/vitejs/plugins/asset.js +14 -1
- package/dist/vite/plugins/vitejs/plugins/css.js +35 -1
- package/dist/vue/transforms/index.js +1 -1
- package/dist/x.d.ts +1 -0
- package/dist/x.js +5 -1
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.js +11 -9
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.cjs.prod.js +11 -9
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.d.ts +13 -1
- package/lib/dom2/app/@vue/compiler-core/dist/compiler-core.esm-bundler.js +8 -7
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.js +1 -1
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +1 -1
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.js +8 -7
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-browser.prod.js +5 -5
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.esm-bundler.js +1 -1
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.js +8 -7
- package/lib/dom2/app/@vue/compiler-dom/dist/compiler-dom.global.prod.js +5 -5
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.cjs.js +4772 -1513
- package/lib/dom2/app/@vue/compiler-sfc/dist/compiler-sfc.esm-browser.js +3209 -1754
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.cjs.js +1471 -395
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.d.ts +143 -119
- package/lib/dom2/app/@vue/compiler-vapor/dist/compiler-vapor.esm-browser.js +1576 -470
- package/lib/dom2/app/@vue/compiler-vapor-dom2/dist/compiler-vapor-dom2.cjs.js +1 -1
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.js +77 -2
- package/lib/dom2/app/@vue/shared/dist/shared.cjs.prod.js +77 -2
- package/lib/dom2/app/@vue/shared/dist/shared.d.ts +89 -2
- package/lib/dom2/app/@vue/shared/dist/shared.esm-bundler.js +74 -3
- package/package.json +5 -5
package/dist/dom2/vue.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export declare function initVueTemplateCompilerExtraOptions(descriptor: SFCDescr
|
|
|
9
9
|
enableRootScrollViewTransform: boolean;
|
|
10
10
|
rootScrollView: import("src/json/uni-x").UniXPageOptions | undefined;
|
|
11
11
|
scriptCppBlocks: any;
|
|
12
|
-
disableStaticStyle: boolean;
|
|
13
12
|
onVueTemplateCompileLog(type: 'warn' | 'error', error: CompilerError): void;
|
|
14
13
|
r: any;
|
|
15
14
|
className: any;
|
package/dist/dom2/vue.js
CHANGED
|
@@ -13,32 +13,19 @@ function initVueTemplateCompilerExtraOptions(descriptor) {
|
|
|
13
13
|
const relativeFilename = (0, utils_1.normalizePath)(path_1.default.relative(process.env.UNI_INPUT_DIR, filename));
|
|
14
14
|
const rootScrollView = (0, json_1.parseUniXPageOptions)(filename);
|
|
15
15
|
const componentType = rootScrollView || (0, json_1.isUniPageFile)(filename) ? 'page' : 'component';
|
|
16
|
-
const isDevX = process.env.UNI_HX_VERSION_DEV === 'true' &&
|
|
17
|
-
process.env.UNI_APP_X === 'true';
|
|
18
16
|
const isDynamic = process.env.UNI_APP_X_DOM2_DYNAMIC === 'true';
|
|
19
|
-
let disableStaticStyle = false;
|
|
20
|
-
if (isDevX &&
|
|
21
|
-
// 动态渲染时,仍旧使用静态样式,避免性能问题。
|
|
22
|
-
!isDynamic &&
|
|
23
|
-
process.env.NODE_ENV === 'development') {
|
|
24
|
-
if (process.env.UNI_UTS_PLATFORM === 'app-harmony') {
|
|
25
|
-
// 开发版本、开发模式下,非鸿蒙release模式打包
|
|
26
|
-
disableStaticStyle = process.env.UNI_APP_HARMONY_RUN_MODE !== 'release';
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
17
|
const helper = (0, utils_1.requireUniHelpers)();
|
|
30
18
|
return {
|
|
31
19
|
root: (0, utils_1.normalizePath)(process.env.UNI_INPUT_DIR),
|
|
32
20
|
platform: process.env.UNI_UTS_PLATFORM,
|
|
33
21
|
componentType,
|
|
34
|
-
filename
|
|
22
|
+
filename,
|
|
35
23
|
relativeFilename,
|
|
36
24
|
helper,
|
|
37
25
|
enableRootScrollViewTransform: true,
|
|
38
26
|
// 仅页面透传 rootScrollView,避免非页面组件误触发 ROOT 自动包裹逻辑。
|
|
39
27
|
rootScrollView: componentType === 'page' ? rootScrollView : undefined,
|
|
40
28
|
scriptCppBlocks: descriptor.scriptCppBlocks,
|
|
41
|
-
disableStaticStyle,
|
|
42
29
|
onVueTemplateCompileLog(type, error) {
|
|
43
30
|
return (0, vue_1.onVueTemplateCompileLog)(type, error, descriptor.source, relativeFilename);
|
|
44
31
|
},
|
package/dist/hbx/alias.js
CHANGED
|
@@ -5,11 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.formatInstallHBuilderXPluginTips = exports.moduleAliasFormatter = exports.installHBuilderXPlugin = exports.initModuleAlias = void 0;
|
|
7
7
|
// 注意:该文件尽可能少依赖其他文件,否则可能会导致还没有alias的时候,就加载了目标模块
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
8
|
const path_1 = __importDefault(require("path"));
|
|
10
9
|
const module_alias_1 = __importDefault(require("module-alias"));
|
|
11
10
|
const utils_1 = require("./utils");
|
|
12
|
-
const jsonc_parser_1 = require("jsonc-parser");
|
|
13
11
|
const hbxPlugins = {
|
|
14
12
|
typescript: 'compile-typescript/node_modules/typescript',
|
|
15
13
|
less: 'compile-less/node_modules/less',
|
|
@@ -17,32 +15,32 @@ const hbxPlugins = {
|
|
|
17
15
|
stylus: 'compile-stylus/node_modules/stylus',
|
|
18
16
|
pug: 'compile-pug-cli/node_modules/pug',
|
|
19
17
|
};
|
|
18
|
+
function isWebOrMpPlatform(platform) {
|
|
19
|
+
return platform === 'h5' || platform === 'web' || platform?.startsWith('mp-');
|
|
20
|
+
}
|
|
20
21
|
function initModuleAlias() {
|
|
21
22
|
const libDir = path_1.default.resolve(__dirname, '../../lib');
|
|
22
23
|
const compilerSfcPath = path_1.default.resolve(libDir, '@vue/compiler-sfc');
|
|
23
24
|
const serverRendererPath = require.resolve('@vue/server-renderer');
|
|
25
|
+
if (process.env.UNI_OUTPUT_DIR) {
|
|
26
|
+
const baseOutDir = path_1.default.basename(process.env.UNI_OUTPUT_DIR);
|
|
27
|
+
process.env.UNI_APP_X_CACHE_DIR =
|
|
28
|
+
process.env.UNI_APP_X_CACHE_DIR ||
|
|
29
|
+
path_1.default.resolve(process.env.UNI_OUTPUT_DIR, '../cache/.' + baseOutDir);
|
|
30
|
+
}
|
|
24
31
|
// 对路径进行兼容
|
|
25
32
|
if (!process.env.UNI_APP_X_DOM2_CPP_DIR &&
|
|
26
33
|
process.env.UNI_APP_HARMONY_DOM2_CPP_DIR) {
|
|
27
34
|
process.env.UNI_APP_X_DOM2_CPP_DIR =
|
|
28
35
|
process.env.UNI_APP_HARMONY_DOM2_CPP_DIR;
|
|
29
36
|
}
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const manifestJson = (0, jsonc_parser_1.parse)(manifestJsonStr);
|
|
38
|
-
if (manifestJson?.['uni-app-x']?.vapor === true) {
|
|
39
|
-
const vaporFilename = path_1.default.resolve(process.env.UNI_INPUT_DIR, '.vapor');
|
|
40
|
-
if (fs_1.default.existsSync(vaporFilename)) {
|
|
41
|
-
process.env.UNI_APP_X_DOM2 = 'true';
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
37
|
+
// alias 初始化可能早于 CLI 环境初始化,这里仅依据外部预置的平台环境变量判断。
|
|
38
|
+
// 如果是 web 和小程序,目前强制非蒸汽。
|
|
39
|
+
const utsPlatform = process.env.UNI_UTS_PLATFORM;
|
|
40
|
+
const uniPlatform = process.env.UNI_PLATFORM;
|
|
41
|
+
if (isWebOrMpPlatform(utsPlatform) || isWebOrMpPlatform(uniPlatform)) {
|
|
42
|
+
delete process.env.UNI_APP_X_DOM2;
|
|
43
|
+
delete process.env.UNI_APP_X_DOM2_DYNAMIC;
|
|
46
44
|
}
|
|
47
45
|
if (process.env.UNI_APP_X_DOM2 === 'true') {
|
|
48
46
|
if (process.env.UNI_OUTPUT_DIR &&
|
|
@@ -46,7 +46,9 @@ function defineNVuePageCode(pagesJson) {
|
|
|
46
46
|
}
|
|
47
47
|
const pagePathWithExtname = (0, utils_1.normalizePagePath)(page.path, 'app');
|
|
48
48
|
if (pagePathWithExtname) {
|
|
49
|
-
importNVuePagesCode.push(
|
|
49
|
+
importNVuePagesCode.push(
|
|
50
|
+
// 使用 res.default 确保 rollup 不会摇树
|
|
51
|
+
`import('./${pagePathWithExtname}').then((res)=>{res.default})`);
|
|
50
52
|
}
|
|
51
53
|
});
|
|
52
54
|
return importNVuePagesCode.join('\n');
|
package/dist/json/mp/index.d.ts
CHANGED
|
@@ -2,3 +2,5 @@ export * from './jsonFile';
|
|
|
2
2
|
export { AppJson, ComponentJson, MiniProgramComponentsType } from './types';
|
|
3
3
|
export { mergeMiniProgramAppJson, parseMiniProgramPagesJson } from './pages';
|
|
4
4
|
export { parseMiniProgramProjectJson } from './project';
|
|
5
|
+
export { MP_INDEPENDENT_ROOT_QUERY, MP_INDEPENDENT_MAIN_PREFIX, MP_INDEPENDENT_VIRTUAL_ROOT_QUERY, formatIndependentVirtualId, getIndependentRootByFilename, getIndependentRoots, getIndependentSubPackages, hasIndependentRoot, isAppPagesJson, isInIndependentRoot, normalizeIndependentRoot, parseIndependentMainRoot, parseIndependentRoot, parseIndependentSubPackages, parseIndependentVirtualRoot, resolveIndependentRoot, setIndependentSubPackages, stringifyIndependentRoots, withIndependentRoot, withIndependentRootIfNeeded, withoutIndependentRoot, } from './subpackage';
|
|
6
|
+
export type { IndependentSubPackage } from './subpackage';
|
package/dist/json/mp/index.js
CHANGED
|
@@ -14,10 +14,32 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.parseMiniProgramProjectJson = exports.parseMiniProgramPagesJson = exports.mergeMiniProgramAppJson = void 0;
|
|
17
|
+
exports.withoutIndependentRoot = exports.withIndependentRootIfNeeded = exports.withIndependentRoot = exports.stringifyIndependentRoots = exports.setIndependentSubPackages = exports.resolveIndependentRoot = exports.parseIndependentVirtualRoot = exports.parseIndependentSubPackages = exports.parseIndependentRoot = exports.parseIndependentMainRoot = exports.normalizeIndependentRoot = exports.isInIndependentRoot = exports.isAppPagesJson = exports.hasIndependentRoot = exports.getIndependentSubPackages = exports.getIndependentRoots = exports.getIndependentRootByFilename = exports.formatIndependentVirtualId = exports.MP_INDEPENDENT_VIRTUAL_ROOT_QUERY = exports.MP_INDEPENDENT_MAIN_PREFIX = exports.MP_INDEPENDENT_ROOT_QUERY = exports.parseMiniProgramProjectJson = exports.parseMiniProgramPagesJson = exports.mergeMiniProgramAppJson = void 0;
|
|
18
18
|
__exportStar(require("./jsonFile"), exports);
|
|
19
19
|
var pages_1 = require("./pages");
|
|
20
20
|
Object.defineProperty(exports, "mergeMiniProgramAppJson", { enumerable: true, get: function () { return pages_1.mergeMiniProgramAppJson; } });
|
|
21
21
|
Object.defineProperty(exports, "parseMiniProgramPagesJson", { enumerable: true, get: function () { return pages_1.parseMiniProgramPagesJson; } });
|
|
22
22
|
var project_1 = require("./project");
|
|
23
23
|
Object.defineProperty(exports, "parseMiniProgramProjectJson", { enumerable: true, get: function () { return project_1.parseMiniProgramProjectJson; } });
|
|
24
|
+
var subpackage_1 = require("./subpackage");
|
|
25
|
+
Object.defineProperty(exports, "MP_INDEPENDENT_ROOT_QUERY", { enumerable: true, get: function () { return subpackage_1.MP_INDEPENDENT_ROOT_QUERY; } });
|
|
26
|
+
Object.defineProperty(exports, "MP_INDEPENDENT_MAIN_PREFIX", { enumerable: true, get: function () { return subpackage_1.MP_INDEPENDENT_MAIN_PREFIX; } });
|
|
27
|
+
Object.defineProperty(exports, "MP_INDEPENDENT_VIRTUAL_ROOT_QUERY", { enumerable: true, get: function () { return subpackage_1.MP_INDEPENDENT_VIRTUAL_ROOT_QUERY; } });
|
|
28
|
+
Object.defineProperty(exports, "formatIndependentVirtualId", { enumerable: true, get: function () { return subpackage_1.formatIndependentVirtualId; } });
|
|
29
|
+
Object.defineProperty(exports, "getIndependentRootByFilename", { enumerable: true, get: function () { return subpackage_1.getIndependentRootByFilename; } });
|
|
30
|
+
Object.defineProperty(exports, "getIndependentRoots", { enumerable: true, get: function () { return subpackage_1.getIndependentRoots; } });
|
|
31
|
+
Object.defineProperty(exports, "getIndependentSubPackages", { enumerable: true, get: function () { return subpackage_1.getIndependentSubPackages; } });
|
|
32
|
+
Object.defineProperty(exports, "hasIndependentRoot", { enumerable: true, get: function () { return subpackage_1.hasIndependentRoot; } });
|
|
33
|
+
Object.defineProperty(exports, "isAppPagesJson", { enumerable: true, get: function () { return subpackage_1.isAppPagesJson; } });
|
|
34
|
+
Object.defineProperty(exports, "isInIndependentRoot", { enumerable: true, get: function () { return subpackage_1.isInIndependentRoot; } });
|
|
35
|
+
Object.defineProperty(exports, "normalizeIndependentRoot", { enumerable: true, get: function () { return subpackage_1.normalizeIndependentRoot; } });
|
|
36
|
+
Object.defineProperty(exports, "parseIndependentMainRoot", { enumerable: true, get: function () { return subpackage_1.parseIndependentMainRoot; } });
|
|
37
|
+
Object.defineProperty(exports, "parseIndependentRoot", { enumerable: true, get: function () { return subpackage_1.parseIndependentRoot; } });
|
|
38
|
+
Object.defineProperty(exports, "parseIndependentSubPackages", { enumerable: true, get: function () { return subpackage_1.parseIndependentSubPackages; } });
|
|
39
|
+
Object.defineProperty(exports, "parseIndependentVirtualRoot", { enumerable: true, get: function () { return subpackage_1.parseIndependentVirtualRoot; } });
|
|
40
|
+
Object.defineProperty(exports, "resolveIndependentRoot", { enumerable: true, get: function () { return subpackage_1.resolveIndependentRoot; } });
|
|
41
|
+
Object.defineProperty(exports, "setIndependentSubPackages", { enumerable: true, get: function () { return subpackage_1.setIndependentSubPackages; } });
|
|
42
|
+
Object.defineProperty(exports, "stringifyIndependentRoots", { enumerable: true, get: function () { return subpackage_1.stringifyIndependentRoots; } });
|
|
43
|
+
Object.defineProperty(exports, "withIndependentRoot", { enumerable: true, get: function () { return subpackage_1.withIndependentRoot; } });
|
|
44
|
+
Object.defineProperty(exports, "withIndependentRootIfNeeded", { enumerable: true, get: function () { return subpackage_1.withIndependentRootIfNeeded; } });
|
|
45
|
+
Object.defineProperty(exports, "withoutIndependentRoot", { enumerable: true, get: function () { return subpackage_1.withoutIndependentRoot; } });
|
|
@@ -6,11 +6,12 @@ export declare function getComponentJsonFilenames(): string[];
|
|
|
6
6
|
export declare function findJsonFile(filename: string): Record<string, any> | ComponentJson | PageWindowOptions | undefined;
|
|
7
7
|
export declare function findUsingComponents(filename: string): UsingComponents | undefined;
|
|
8
8
|
export declare function normalizeJsonFilename(filename: string): string;
|
|
9
|
-
export declare function findChangedJsonFiles(supportGlobalUsingComponents?: boolean): Map<string, string>;
|
|
9
|
+
export declare function findChangedJsonFiles(supportGlobalUsingComponents?: boolean | ((filename: string) => boolean)): Map<string, string>;
|
|
10
10
|
export declare function addMiniProgramAppJson(appJson: Record<string, any>): void;
|
|
11
11
|
export declare function addMiniProgramPageJson(filename: string, json: PageWindowOptions): void;
|
|
12
12
|
export declare function addMiniProgramComponentJson(filename: string, json: ComponentJson): void;
|
|
13
13
|
export declare function addMiniProgramUsingComponents(filename: string, json: UsingComponents): void;
|
|
14
|
+
export declare function resetMiniProgramJsonFiles(): void;
|
|
14
15
|
export declare function isMiniProgramUsingComponent(name: string, options: {
|
|
15
16
|
filename: string;
|
|
16
17
|
inputDir: string;
|
|
@@ -39,5 +40,5 @@ export declare function findMiniProgramUsingComponents({ filename, inputDir, com
|
|
|
39
40
|
* - "demo": "wxcomponents/demo"
|
|
40
41
|
* - [TODO 待确认] "demo": "../wxcomponents/demo"
|
|
41
42
|
*/
|
|
42
|
-
export declare function findUsingComponentsJson(pathInpages: string, componentsDir: string): Record<any, any>;
|
|
43
|
+
export declare function findUsingComponentsJson(pathInpages: string, componentsDir: string, ownerFilename?: string): Record<any, any>;
|
|
43
44
|
export {};
|
package/dist/json/mp/jsonFile.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.findUsingComponentsJson = exports.findMiniProgramUsingComponents = exports.isMiniProgramUsingComponent = exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.findUsingComponents = exports.findJsonFile = exports.getComponentJsonFilenames = exports.hasJsonFile = exports.isMiniProgramPageSfcFile = exports.isMiniProgramPageFile = void 0;
|
|
6
|
+
exports.findUsingComponentsJson = exports.findMiniProgramUsingComponents = exports.isMiniProgramUsingComponent = exports.resetMiniProgramJsonFiles = exports.addMiniProgramUsingComponents = exports.addMiniProgramComponentJson = exports.addMiniProgramPageJson = exports.addMiniProgramAppJson = exports.findChangedJsonFiles = exports.normalizeJsonFilename = exports.findUsingComponents = exports.findJsonFile = exports.getComponentJsonFilenames = exports.hasJsonFile = exports.isMiniProgramPageSfcFile = exports.isMiniProgramPageFile = void 0;
|
|
7
7
|
const path_1 = __importDefault(require("path"));
|
|
8
8
|
const fs_1 = __importDefault(require("fs"));
|
|
9
9
|
const shared_1 = require("@vue/shared");
|
|
@@ -11,7 +11,9 @@ const utils_1 = require("../../utils");
|
|
|
11
11
|
const resolve_1 = require("../../resolve");
|
|
12
12
|
const utils_2 = require("../../vue/utils");
|
|
13
13
|
const uni_shared_1 = require("@dcloudio/uni-shared");
|
|
14
|
+
const subpackage_1 = require("./subpackage");
|
|
14
15
|
let appJsonCache = {};
|
|
16
|
+
let independentRootsCache = [];
|
|
15
17
|
const jsonFilesCache = new Map();
|
|
16
18
|
const jsonPagesCache = new Map();
|
|
17
19
|
const jsonComponentsCache = new Map();
|
|
@@ -64,8 +66,12 @@ function findChangedJsonFiles(supportGlobalUsingComponents = true) {
|
|
|
64
66
|
// app.json mp-baidu 在 win 不支持相对路径。所有平台改用绝对路径
|
|
65
67
|
if (filename !== 'app') {
|
|
66
68
|
let usingComponents = newJson.usingComponents;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
const independentRoot = findIndependentRoot(filename, independentRootsCache);
|
|
70
|
+
const supportGlobalUsingComponentsForFile = typeof supportGlobalUsingComponents === 'function'
|
|
71
|
+
? supportGlobalUsingComponents(filename)
|
|
72
|
+
: supportGlobalUsingComponents;
|
|
73
|
+
// 如果小程序不支持 global 的 usingComponents,或独立分包冷启动不能依赖 app.json
|
|
74
|
+
if (!supportGlobalUsingComponentsForFile || independentRoot) {
|
|
69
75
|
// 从取全局的 usingComponents 并补充到子组件 usingComponents 中
|
|
70
76
|
const globalUsingComponents = appJsonCache?.usingComponents || {};
|
|
71
77
|
const globalComponents = findUsingComponents('app') || {};
|
|
@@ -75,6 +81,9 @@ function findChangedJsonFiles(supportGlobalUsingComponents = true) {
|
|
|
75
81
|
...newJson.usingComponents,
|
|
76
82
|
};
|
|
77
83
|
}
|
|
84
|
+
if (independentRoot) {
|
|
85
|
+
validateIndependentUsingComponents(filename, independentRoot, usingComponents);
|
|
86
|
+
}
|
|
78
87
|
Object.keys(usingComponents).forEach((name) => {
|
|
79
88
|
const componentFilename = usingComponents[name];
|
|
80
89
|
if (componentFilename.startsWith('/')) {
|
|
@@ -102,8 +111,40 @@ function findChangedJsonFiles(supportGlobalUsingComponents = true) {
|
|
|
102
111
|
return changedJsonFiles;
|
|
103
112
|
}
|
|
104
113
|
exports.findChangedJsonFiles = findChangedJsonFiles;
|
|
114
|
+
function findIndependentRoot(filename, independentRoots) {
|
|
115
|
+
return independentRoots.find((root) => {
|
|
116
|
+
return filename === root || filename.startsWith(root + '/');
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function validateIndependentUsingComponents(filename, root, usingComponents) {
|
|
120
|
+
Object.keys(usingComponents).forEach((name) => {
|
|
121
|
+
const componentFilename = usingComponents[name];
|
|
122
|
+
if (isLocalUsingComponent(componentFilename) &&
|
|
123
|
+
!isUsingComponentInRoot(componentFilename, root, filename)) {
|
|
124
|
+
throw new Error(`独立分包 "${root}" 不能在 "${filename}" 中使用 root 外组件 "${name}"(${componentFilename}),请移动到 "${root}" 内或改为页面局部组件。`);
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function isUsingComponentInRoot(componentFilename, root, ownerFilename) {
|
|
129
|
+
const filename = normalizeUsingComponentFilename(componentFilename, ownerFilename);
|
|
130
|
+
return filename === root || filename.startsWith(root + '/');
|
|
131
|
+
}
|
|
132
|
+
function normalizeUsingComponentFilename(componentFilename, ownerFilename) {
|
|
133
|
+
if (componentFilename.startsWith('/')) {
|
|
134
|
+
return (0, utils_1.normalizePath)(componentFilename).replace(/^\/+/, '');
|
|
135
|
+
}
|
|
136
|
+
if (componentFilename.startsWith('.')) {
|
|
137
|
+
return (0, utils_1.normalizePath)(path_1.default.join(path_1.default.dirname(ownerFilename), componentFilename));
|
|
138
|
+
}
|
|
139
|
+
return (0, utils_1.normalizePath)(componentFilename);
|
|
140
|
+
}
|
|
141
|
+
function isLocalUsingComponent(componentFilename) {
|
|
142
|
+
return (!/^(?:plugin|dynamicLib|ext):\/\//.test(componentFilename) &&
|
|
143
|
+
!componentFilename.startsWith('weui-miniprogram'));
|
|
144
|
+
}
|
|
105
145
|
function addMiniProgramAppJson(appJson) {
|
|
106
146
|
appJsonCache = appJson;
|
|
147
|
+
independentRootsCache = (0, subpackage_1.parseIndependentSubPackages)(appJson).map(({ root }) => root);
|
|
107
148
|
}
|
|
108
149
|
exports.addMiniProgramAppJson = addMiniProgramAppJson;
|
|
109
150
|
function addMiniProgramPageJson(filename, json) {
|
|
@@ -118,6 +159,16 @@ function addMiniProgramUsingComponents(filename, json) {
|
|
|
118
159
|
jsonUsingComponentsCache.set(filename, json);
|
|
119
160
|
}
|
|
120
161
|
exports.addMiniProgramUsingComponents = addMiniProgramUsingComponents;
|
|
162
|
+
function resetMiniProgramJsonFiles() {
|
|
163
|
+
appJsonCache = {};
|
|
164
|
+
independentRootsCache = [];
|
|
165
|
+
(0, subpackage_1.setIndependentSubPackages)([]);
|
|
166
|
+
jsonFilesCache.clear();
|
|
167
|
+
jsonPagesCache.clear();
|
|
168
|
+
jsonComponentsCache.clear();
|
|
169
|
+
jsonUsingComponentsCache.clear();
|
|
170
|
+
}
|
|
171
|
+
exports.resetMiniProgramJsonFiles = resetMiniProgramJsonFiles;
|
|
121
172
|
function isMiniProgramUsingComponent(name, options) {
|
|
122
173
|
return !!findMiniProgramUsingComponents(options)[name];
|
|
123
174
|
}
|
|
@@ -135,20 +186,21 @@ function findMiniProgramUsingComponents({ filename, inputDir, componentsDir, })
|
|
|
135
186
|
if (globalUsingComponents) {
|
|
136
187
|
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(globalUsingComponents, componentsDir));
|
|
137
188
|
}
|
|
138
|
-
const
|
|
189
|
+
const ownerFilename = (0, utils_1.removeExt)((0, utils_1.normalizeMiniProgramFilename)(filename, inputDir));
|
|
190
|
+
const jsonFile = findJsonFile(ownerFilename);
|
|
139
191
|
if (jsonFile) {
|
|
140
192
|
if (jsonFile.usingComponents) {
|
|
141
|
-
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingComponents, componentsDir));
|
|
193
|
+
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingComponents, componentsDir, ownerFilename));
|
|
142
194
|
}
|
|
143
195
|
// mp-baidu 特有
|
|
144
196
|
if (jsonFile.usingSwanComponents) {
|
|
145
|
-
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingSwanComponents, componentsDir));
|
|
197
|
+
(0, shared_1.extend)(miniProgramComponents, findMiniProgramUsingComponent(jsonFile.usingSwanComponents, componentsDir, ownerFilename));
|
|
146
198
|
}
|
|
147
199
|
}
|
|
148
200
|
return miniProgramComponents;
|
|
149
201
|
}
|
|
150
202
|
exports.findMiniProgramUsingComponents = findMiniProgramUsingComponents;
|
|
151
|
-
function findMiniProgramUsingComponent(usingComponents, componentsDir) {
|
|
203
|
+
function findMiniProgramUsingComponent(usingComponents, componentsDir, ownerFilename) {
|
|
152
204
|
return Object.keys(usingComponents).reduce((res, name) => {
|
|
153
205
|
const path = usingComponents[name];
|
|
154
206
|
if (path.includes('plugin://')) {
|
|
@@ -165,7 +217,8 @@ function findMiniProgramUsingComponent(usingComponents, componentsDir) {
|
|
|
165
217
|
}
|
|
166
218
|
else if (componentsDir &&
|
|
167
219
|
path.includes(componentsDir + '/') &&
|
|
168
|
-
findUsingComponentsJson(path, componentsDir).renderer ===
|
|
220
|
+
findUsingComponentsJson(path, componentsDir, ownerFilename).renderer ===
|
|
221
|
+
'xr-frame') {
|
|
169
222
|
// mp-weixin & x-frame
|
|
170
223
|
res[name] = 'xr-frame';
|
|
171
224
|
}
|
|
@@ -193,17 +246,15 @@ function findMiniProgramUsingComponent(usingComponents, componentsDir) {
|
|
|
193
246
|
* - "demo": "wxcomponents/demo"
|
|
194
247
|
* - [TODO 待确认] "demo": "../wxcomponents/demo"
|
|
195
248
|
*/
|
|
196
|
-
function findUsingComponentsJson(pathInpages, componentsDir) {
|
|
249
|
+
function findUsingComponentsJson(pathInpages, componentsDir, ownerFilename) {
|
|
197
250
|
// 兼容test case
|
|
198
251
|
if (!process.env.UNI_INPUT_DIR)
|
|
199
252
|
return {};
|
|
200
|
-
|
|
201
|
-
if (
|
|
253
|
+
const fulldir = resolveUsingComponentsDir(pathInpages, componentsDir, ownerFilename);
|
|
254
|
+
if (!fulldir) {
|
|
202
255
|
console.warn(`${pathInpages} 路径里没有找到对应的 ${componentsDir} 目录`);
|
|
203
256
|
return {};
|
|
204
257
|
}
|
|
205
|
-
dir = '.' + dir;
|
|
206
|
-
const fulldir = path_1.default.resolve(process.env.UNI_INPUT_DIR, componentsDir, dir);
|
|
207
258
|
let jsonPath = fulldir + '.json';
|
|
208
259
|
if (fs_1.default.existsSync(jsonPath)) {
|
|
209
260
|
return require(jsonPath);
|
|
@@ -216,3 +267,22 @@ function findUsingComponentsJson(pathInpages, componentsDir) {
|
|
|
216
267
|
return {};
|
|
217
268
|
}
|
|
218
269
|
exports.findUsingComponentsJson = findUsingComponentsJson;
|
|
270
|
+
function resolveUsingComponentsDir(pathInpages, componentsDir, ownerFilename) {
|
|
271
|
+
const normalizedPath = (0, utils_1.normalizePath)(pathInpages);
|
|
272
|
+
if (normalizedPath.startsWith('/')) {
|
|
273
|
+
return path_1.default.resolve(process.env.UNI_INPUT_DIR, '.' + normalizedPath);
|
|
274
|
+
}
|
|
275
|
+
if (ownerFilename && normalizedPath.startsWith('.')) {
|
|
276
|
+
return path_1.default.resolve(process.env.UNI_INPUT_DIR, path_1.default.dirname(ownerFilename), normalizedPath);
|
|
277
|
+
}
|
|
278
|
+
const marker = componentsDir + '/';
|
|
279
|
+
const index = normalizedPath.indexOf(marker);
|
|
280
|
+
if (index === -1) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const dir = normalizedPath.slice(index + componentsDir.length);
|
|
284
|
+
if (!dir) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
return path_1.default.resolve(process.env.UNI_INPUT_DIR, componentsDir, '.' + dir);
|
|
288
|
+
}
|
package/dist/json/mp/pages.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ interface ParsePagesJsonOptions {
|
|
|
3
3
|
debug?: boolean;
|
|
4
4
|
darkmode?: boolean;
|
|
5
5
|
subpackages: boolean;
|
|
6
|
+
independentSubpackages?: boolean;
|
|
6
7
|
windowOptionsMap?: Record<string, string>;
|
|
7
8
|
tabBarOptionsMap?: Record<string, string>;
|
|
8
9
|
tabBarItemOptionsMap?: Record<string, string>;
|
package/dist/json/mp/pages.js
CHANGED
|
@@ -44,7 +44,7 @@ function mergeMiniProgramAppJson(appJson, platformJson = {}, source = {}) {
|
|
|
44
44
|
});
|
|
45
45
|
}
|
|
46
46
|
exports.mergeMiniProgramAppJson = mergeMiniProgramAppJson;
|
|
47
|
-
function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, subpackages, windowOptionsMap, tabBarOptionsMap, tabBarItemOptionsMap, } = {
|
|
47
|
+
function parsePagesJson(jsonStr, platform, { debug, darkmode, independentSubpackages, networkTimeout, subpackages, windowOptionsMap, tabBarOptionsMap, tabBarItemOptionsMap, } = {
|
|
48
48
|
subpackages: false,
|
|
49
49
|
}) {
|
|
50
50
|
let appJson = {
|
|
@@ -81,7 +81,11 @@ function parsePagesJson(jsonStr, platform, { debug, darkmode, networkTimeout, su
|
|
|
81
81
|
pagesJson.subPackages = pagesJson.subPackages || pagesJson.subpackages;
|
|
82
82
|
if (pagesJson.subPackages) {
|
|
83
83
|
if (subpackages) {
|
|
84
|
-
appJson.subPackages = pagesJson.subPackages.map((
|
|
84
|
+
appJson.subPackages = pagesJson.subPackages.map((subPackage) => {
|
|
85
|
+
const { root, pages, ...rest } = subPackage;
|
|
86
|
+
if (!independentSubpackages) {
|
|
87
|
+
delete rest.independent;
|
|
88
|
+
}
|
|
85
89
|
return (0, shared_1.extend)({
|
|
86
90
|
root,
|
|
87
91
|
pages: pages.map((page) => {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export declare const MP_INDEPENDENT_ROOT_QUERY = "uni_mp_independent_root";
|
|
2
|
+
export declare const MP_INDEPENDENT_MAIN_PREFIX = "\0uni:mp-independent-main";
|
|
3
|
+
export declare const MP_INDEPENDENT_VIRTUAL_ROOT_QUERY = "root";
|
|
4
|
+
export interface IndependentSubPackage {
|
|
5
|
+
root: string;
|
|
6
|
+
pages: string[];
|
|
7
|
+
independent: true;
|
|
8
|
+
}
|
|
9
|
+
export declare function parseIndependentSubPackages(pagesJson: UniApp.PagesJson | undefined): IndependentSubPackage[];
|
|
10
|
+
export declare function setIndependentSubPackages(packages: IndependentSubPackage[]): void;
|
|
11
|
+
export declare function getIndependentSubPackages(): IndependentSubPackage[];
|
|
12
|
+
export declare function getIndependentRoots(): Set<string>;
|
|
13
|
+
export declare function getIndependentRootByFilename(filename: string, inputDir: string | undefined): string | undefined;
|
|
14
|
+
export declare function resolveIndependentRoot(id: string, importer: string | undefined, inputDir: string | undefined, platform: string | undefined): string | undefined;
|
|
15
|
+
export declare function withIndependentRootIfNeeded(id: string, root: string | undefined, inputDir: string | undefined): string;
|
|
16
|
+
export declare function isInIndependentRoot(filename: string, inputDir: string, root: string): boolean;
|
|
17
|
+
export declare function isAppPagesJson(filename: string, inputDir: string): boolean;
|
|
18
|
+
export declare function stringifyIndependentRoots(packages: IndependentSubPackage[]): string;
|
|
19
|
+
export declare function normalizeIndependentRoot(root: string): string;
|
|
20
|
+
export declare function parseIndependentRoot(id: string): string | undefined;
|
|
21
|
+
export declare function withIndependentRoot(id: string, root: string): string;
|
|
22
|
+
export declare function withoutIndependentRoot(id: string): string;
|
|
23
|
+
export declare function hasIndependentRoot(id: string): boolean;
|
|
24
|
+
export declare function formatIndependentVirtualId(prefix: string, root: string): string;
|
|
25
|
+
export declare function parseIndependentMainRoot(id: string): string | undefined;
|
|
26
|
+
export declare function parseIndependentVirtualRoot(id: string, prefix: string): string | undefined;
|