@uni-helper/vite-plugin-uni-pages 0.4.6 → 0.4.8
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/README.md +2 -1
- package/dist/index.cjs +16 -35
- package/dist/index.d.cts +2 -17
- package/dist/index.d.mts +2 -17
- package/dist/index.mjs +17 -34
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -253,7 +253,8 @@ export default defineConfig({
|
|
|
253
253
|
本插件默认会:
|
|
254
254
|
|
|
255
255
|
- 通过文件锁串行化对 `pages.json` 的「读取已有内容 → 合并当前平台配置 → 写回」整个流程,避免并发写入互相覆盖;
|
|
256
|
-
- 保留其他平台已经写入的条件编译块(`#ifdef H5` / `#ifndef MP-WEIXIN`
|
|
256
|
+
- 保留其他平台已经写入的条件编译块(`#ifdef H5` / `#ifndef MP-WEIXIN` 等),只更新当前平台对应的条目;
|
|
257
|
+
- 对同一 `path`(或 tabBar 的 `pagePath`)的条目按内容去重:内容相同的条目会合并为一条并叠加平台标识(如 `H5 || MP-WEIXIN`),不会因为先后跑过多个平台而产生重复路由。
|
|
257
258
|
|
|
258
259
|
这样每个终端都能保留各自的平台配置。条件编译注释基于 `comment-json` 写入,最终 `pages.json` 同时包含所有平台的分支。
|
|
259
260
|
|
package/dist/index.cjs
CHANGED
|
@@ -312,27 +312,6 @@ function getDefaultExport(expr) {
|
|
|
312
312
|
}
|
|
313
313
|
/** Babel code generator for converting AST back to code */
|
|
314
314
|
const babelGenerate = getDefaultExport(_babel_generator.default);
|
|
315
|
-
function stripType(item) {
|
|
316
|
-
const { type, ...rest } = item;
|
|
317
|
-
return rest;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* Remove the internal `type` marker (`'home'` / `'page'`) from every element of
|
|
321
|
-
* a `CommentArray` *in place* and return the same array.
|
|
322
|
-
*
|
|
323
|
-
* Unlike `items.map(stripType)`, this preserves the `Symbol.for('before:N')` /
|
|
324
|
-
* `Symbol.for('after:N')` comment slots that `comment-json` attaches to the
|
|
325
|
-
* array, so multi-platform `#ifdef` / `#endif` conditional-compilation blocks
|
|
326
|
-
* survive serialization into pages.json. `.map()` rebuilds the array and drops
|
|
327
|
-
* those symbol-keyed comments.
|
|
328
|
-
*
|
|
329
|
-
* @param items - CommentArray (or plain array) of page/tabBar metadata
|
|
330
|
-
* @returns The same array reference, with `type` removed from each element
|
|
331
|
-
*/
|
|
332
|
-
function stripTypeInPlace(items) {
|
|
333
|
-
for (const item of items) if (item && "type" in item) delete item.type;
|
|
334
|
-
return items;
|
|
335
|
-
}
|
|
336
315
|
//#endregion
|
|
337
316
|
//#region src/files.ts
|
|
338
317
|
/**
|
|
@@ -1043,17 +1022,14 @@ var PageContext = class {
|
|
|
1043
1022
|
* @returns JSON string of main package page metadata
|
|
1044
1023
|
*/
|
|
1045
1024
|
resolveRoutes() {
|
|
1046
|
-
return (0, comment_json.stringify)(this.pageMetaData
|
|
1025
|
+
return (0, comment_json.stringify)(this.pageMetaData, null, 2);
|
|
1047
1026
|
}
|
|
1048
1027
|
/**
|
|
1049
1028
|
* Resolve sub-package route data to JSON string
|
|
1050
1029
|
* @returns JSON string of sub-package page metadata
|
|
1051
1030
|
*/
|
|
1052
1031
|
resolveSubRoutes() {
|
|
1053
|
-
return (0, comment_json.stringify)(this.subPageMetaData
|
|
1054
|
-
...rest,
|
|
1055
|
-
pages: pages.map(stripType)
|
|
1056
|
-
})), null, 2);
|
|
1032
|
+
return (0, comment_json.stringify)(this.subPageMetaData, null, 2);
|
|
1057
1033
|
}
|
|
1058
1034
|
/**
|
|
1059
1035
|
* Resolve tabBar configuration
|
|
@@ -1093,7 +1069,7 @@ var PageContext = class {
|
|
|
1093
1069
|
const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = (0, comment_json.parse)(await node_fs.default.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "") || "{}");
|
|
1094
1070
|
const { pages: _pages, subPackages: _subPackages, tabBar: _tabBar, ...pageJson } = this.pagesGlobConfig || {};
|
|
1095
1071
|
const currentPlatform = _uni_helper_uni_env.platform.toUpperCase();
|
|
1096
|
-
pageJson.pages =
|
|
1072
|
+
pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
|
|
1097
1073
|
if (pageJson.pages && pageJson.pages.length > 0) {
|
|
1098
1074
|
const pagesArray = pageJson.pages;
|
|
1099
1075
|
const homeIndex = pagesArray.findIndex((page) => page.type === "home");
|
|
@@ -1108,7 +1084,7 @@ var PageContext = class {
|
|
|
1108
1084
|
for (const existing of pageJson.subPackages) {
|
|
1109
1085
|
const sub = newSubPackages.get(existing.root);
|
|
1110
1086
|
if (sub) {
|
|
1111
|
-
existing.pages =
|
|
1087
|
+
existing.pages = mergePlatformItems(existing.pages, currentPlatform, sub.pages, "path");
|
|
1112
1088
|
if (sub.plugins) existing.plugins = sub.plugins;
|
|
1113
1089
|
newSubPackages.delete(existing.root);
|
|
1114
1090
|
}
|
|
@@ -1116,7 +1092,7 @@ var PageContext = class {
|
|
|
1116
1092
|
for (const [_, newSub] of newSubPackages) {
|
|
1117
1093
|
const subPackage = {
|
|
1118
1094
|
root: newSub.root,
|
|
1119
|
-
pages:
|
|
1095
|
+
pages: mergePlatformItems(void 0, currentPlatform, newSub.pages, "path")
|
|
1120
1096
|
};
|
|
1121
1097
|
if (newSub.plugins) subPackage.plugins = newSub.plugins;
|
|
1122
1098
|
pageJson.subPackages.push(subPackage);
|
|
@@ -1186,6 +1162,13 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1186
1162
|
const trimed = comment.value.trim();
|
|
1187
1163
|
if (trimed.startsWith("GENERATED BY UNI-PAGES, PLATFORM:")) lastPlatforms = trimed.split(":")[1].split("||").map((s) => s.trim()).filter((s) => s !== currentPlatform).sort();
|
|
1188
1164
|
}
|
|
1165
|
+
const stringifyForCompare = (val) => {
|
|
1166
|
+
if (val && typeof val === "object" && "type" in val) {
|
|
1167
|
+
const { type: _type, ...rest } = val;
|
|
1168
|
+
return JSON.stringify(rest);
|
|
1169
|
+
}
|
|
1170
|
+
return JSON.stringify(val);
|
|
1171
|
+
};
|
|
1189
1172
|
const tmpMap = /* @__PURE__ */ new Map();
|
|
1190
1173
|
for (let i = 0; i < src.length; i++) {
|
|
1191
1174
|
const item = src[i];
|
|
@@ -1201,7 +1184,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1201
1184
|
const existing = tmpMap.get(uniqueKey) || [];
|
|
1202
1185
|
existing.push({
|
|
1203
1186
|
item,
|
|
1204
|
-
itemStr:
|
|
1187
|
+
itemStr: stringifyForCompare(item),
|
|
1205
1188
|
platforms,
|
|
1206
1189
|
platformStr: platforms.join(" || ")
|
|
1207
1190
|
});
|
|
@@ -1214,14 +1197,14 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1214
1197
|
if (!tmpMap.has(uniqueKey)) {
|
|
1215
1198
|
tmpMap.set(uniqueKey, [{
|
|
1216
1199
|
item: newItem,
|
|
1217
|
-
itemStr:
|
|
1200
|
+
itemStr: stringifyForCompare(newItem),
|
|
1218
1201
|
platforms: [currentPlatform],
|
|
1219
1202
|
platformStr: currentPlatform
|
|
1220
1203
|
}]);
|
|
1221
1204
|
continue;
|
|
1222
1205
|
}
|
|
1223
1206
|
const existing = tmpMap.get(uniqueKey);
|
|
1224
|
-
const newItemStr =
|
|
1207
|
+
const newItemStr = stringifyForCompare(newItem);
|
|
1225
1208
|
const equalObj = existing.find((val) => val.itemStr === newItemStr);
|
|
1226
1209
|
if (equalObj) {
|
|
1227
1210
|
equalObj.platforms.push(currentPlatform);
|
|
@@ -1229,7 +1212,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1229
1212
|
equalObj.platformStr = equalObj.platforms.join(" || ");
|
|
1230
1213
|
} else existing.push({
|
|
1231
1214
|
item: newItem,
|
|
1232
|
-
itemStr:
|
|
1215
|
+
itemStr: stringifyForCompare(newItem),
|
|
1233
1216
|
platforms: [currentPlatform],
|
|
1234
1217
|
platformStr: currentPlatform
|
|
1235
1218
|
});
|
|
@@ -1411,8 +1394,6 @@ exports.parseSFC = parseSFC;
|
|
|
1411
1394
|
exports.resolveOptions = resolveOptions;
|
|
1412
1395
|
exports.resolvePageDirs = resolvePageDirs;
|
|
1413
1396
|
exports.sleep = sleep;
|
|
1414
|
-
exports.stripType = stripType;
|
|
1415
|
-
exports.stripTypeInPlace = stripTypeInPlace;
|
|
1416
1397
|
exports.tryPageMetaFromMacro = tryPageMetaFromMacro;
|
|
1417
1398
|
exports.withFileLock = withFileLock;
|
|
1418
1399
|
exports.writeFileWithLock = writeFileWithLock;
|
package/dist/index.d.cts
CHANGED
|
@@ -336,21 +336,6 @@ declare function parseCode(options: {
|
|
|
336
336
|
declare function sleep(ms: number): Promise<unknown>;
|
|
337
337
|
/** Babel code generator for converting AST back to code */
|
|
338
338
|
declare const babelGenerate: typeof babelGenerator;
|
|
339
|
-
declare function stripType<T extends Record<string, unknown>>(item: T): Omit<T, 'type'>;
|
|
340
|
-
/**
|
|
341
|
-
* Remove the internal `type` marker (`'home'` / `'page'`) from every element of
|
|
342
|
-
* a `CommentArray` *in place* and return the same array.
|
|
343
|
-
*
|
|
344
|
-
* Unlike `items.map(stripType)`, this preserves the `Symbol.for('before:N')` /
|
|
345
|
-
* `Symbol.for('after:N')` comment slots that `comment-json` attaches to the
|
|
346
|
-
* array, so multi-platform `#ifdef` / `#endif` conditional-compilation blocks
|
|
347
|
-
* survive serialization into pages.json. `.map()` rebuilds the array and drops
|
|
348
|
-
* those symbol-keyed comments.
|
|
349
|
-
*
|
|
350
|
-
* @param items - CommentArray (or plain array) of page/tabBar metadata
|
|
351
|
-
* @returns The same array reference, with `type` removed from each element
|
|
352
|
-
*/
|
|
353
|
-
declare function stripTypeInPlace<T extends Record<string, unknown>>(items: T[]): T[];
|
|
354
339
|
//#endregion
|
|
355
340
|
//#region src/types.d.ts
|
|
356
341
|
/** Debug log type, corresponding to methods in the debug object */
|
|
@@ -565,7 +550,7 @@ declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): Re
|
|
|
565
550
|
*/
|
|
566
551
|
declare function resolvePageDirs(dir: string, root: string, exclude: string[]): string[];
|
|
567
552
|
declare namespace index_d_exports {
|
|
568
|
-
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep,
|
|
553
|
+
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromMacro, withFileLock, writeFileWithLock };
|
|
569
554
|
}
|
|
570
555
|
/**
|
|
571
556
|
* vite-plugin-uni-pages plugin main entry
|
|
@@ -581,4 +566,4 @@ declare namespace index_d_exports {
|
|
|
581
566
|
*/
|
|
582
567
|
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
583
568
|
//#endregion
|
|
584
|
-
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, type definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep,
|
|
569
|
+
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, type definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromMacro, withFileLock, writeFileWithLock };
|
package/dist/index.d.mts
CHANGED
|
@@ -337,21 +337,6 @@ declare function parseCode(options: {
|
|
|
337
337
|
declare function sleep(ms: number): Promise<unknown>;
|
|
338
338
|
/** Babel code generator for converting AST back to code */
|
|
339
339
|
declare const babelGenerate: typeof babelGenerator;
|
|
340
|
-
declare function stripType<T extends Record<string, unknown>>(item: T): Omit<T, 'type'>;
|
|
341
|
-
/**
|
|
342
|
-
* Remove the internal `type` marker (`'home'` / `'page'`) from every element of
|
|
343
|
-
* a `CommentArray` *in place* and return the same array.
|
|
344
|
-
*
|
|
345
|
-
* Unlike `items.map(stripType)`, this preserves the `Symbol.for('before:N')` /
|
|
346
|
-
* `Symbol.for('after:N')` comment slots that `comment-json` attaches to the
|
|
347
|
-
* array, so multi-platform `#ifdef` / `#endif` conditional-compilation blocks
|
|
348
|
-
* survive serialization into pages.json. `.map()` rebuilds the array and drops
|
|
349
|
-
* those symbol-keyed comments.
|
|
350
|
-
*
|
|
351
|
-
* @param items - CommentArray (or plain array) of page/tabBar metadata
|
|
352
|
-
* @returns The same array reference, with `type` removed from each element
|
|
353
|
-
*/
|
|
354
|
-
declare function stripTypeInPlace<T extends Record<string, unknown>>(items: T[]): T[];
|
|
355
340
|
//#endregion
|
|
356
341
|
//#region src/types.d.ts
|
|
357
342
|
/** Debug log type, corresponding to methods in the debug object */
|
|
@@ -566,7 +551,7 @@ declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): Re
|
|
|
566
551
|
*/
|
|
567
552
|
declare function resolvePageDirs(dir: string, root: string, exclude: string[]): string[];
|
|
568
553
|
declare namespace index_d_exports {
|
|
569
|
-
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep,
|
|
554
|
+
export { ConfigSource, DefinePage, ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, MaybeCallable, MaybePromise, MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, SubPageMetaDatum, UserOptions, UserPageMeta, UserTabBarItem, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, debugType, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromMacro, withFileLock, writeFileWithLock };
|
|
570
555
|
}
|
|
571
556
|
/**
|
|
572
557
|
* vite-plugin-uni-pages plugin main entry
|
|
@@ -582,4 +567,4 @@ declare namespace index_d_exports {
|
|
|
582
567
|
*/
|
|
583
568
|
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
584
569
|
//#endregion
|
|
585
|
-
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, type definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep,
|
|
570
|
+
export { ConfigSource, type DefinePage, type ExcludeIndexSignature, FILE_EXTENSIONS, MODULE_ID_VIRTUAL, type MaybeCallable, type MaybePromise, type MaybePromiseCallable, OUTPUT_NAME, Options, Page, PageContext, type PageMetaDatum, PagePath, RESOLVED_MODULE_ID_VIRTUAL, ResolvedOptions, SubPackageConfig, type SubPageMetaDatum, UserOptions, type UserPageMeta, type UserTabBarItem, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, debugType, type definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromMacro, withFileLock, writeFileWithLock };
|
package/dist/index.mjs
CHANGED
|
@@ -271,27 +271,6 @@ function getDefaultExport(expr) {
|
|
|
271
271
|
}
|
|
272
272
|
/** Babel code generator for converting AST back to code */
|
|
273
273
|
const babelGenerate = getDefaultExport(babelGenerator);
|
|
274
|
-
function stripType(item) {
|
|
275
|
-
const { type, ...rest } = item;
|
|
276
|
-
return rest;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Remove the internal `type` marker (`'home'` / `'page'`) from every element of
|
|
280
|
-
* a `CommentArray` *in place* and return the same array.
|
|
281
|
-
*
|
|
282
|
-
* Unlike `items.map(stripType)`, this preserves the `Symbol.for('before:N')` /
|
|
283
|
-
* `Symbol.for('after:N')` comment slots that `comment-json` attaches to the
|
|
284
|
-
* array, so multi-platform `#ifdef` / `#endif` conditional-compilation blocks
|
|
285
|
-
* survive serialization into pages.json. `.map()` rebuilds the array and drops
|
|
286
|
-
* those symbol-keyed comments.
|
|
287
|
-
*
|
|
288
|
-
* @param items - CommentArray (or plain array) of page/tabBar metadata
|
|
289
|
-
* @returns The same array reference, with `type` removed from each element
|
|
290
|
-
*/
|
|
291
|
-
function stripTypeInPlace(items) {
|
|
292
|
-
for (const item of items) if (item && "type" in item) delete item.type;
|
|
293
|
-
return items;
|
|
294
|
-
}
|
|
295
274
|
//#endregion
|
|
296
275
|
//#region src/files.ts
|
|
297
276
|
/**
|
|
@@ -1002,17 +981,14 @@ var PageContext = class {
|
|
|
1002
981
|
* @returns JSON string of main package page metadata
|
|
1003
982
|
*/
|
|
1004
983
|
resolveRoutes() {
|
|
1005
|
-
return stringify(this.pageMetaData
|
|
984
|
+
return stringify(this.pageMetaData, null, 2);
|
|
1006
985
|
}
|
|
1007
986
|
/**
|
|
1008
987
|
* Resolve sub-package route data to JSON string
|
|
1009
988
|
* @returns JSON string of sub-package page metadata
|
|
1010
989
|
*/
|
|
1011
990
|
resolveSubRoutes() {
|
|
1012
|
-
return stringify(this.subPageMetaData
|
|
1013
|
-
...rest,
|
|
1014
|
-
pages: pages.map(stripType)
|
|
1015
|
-
})), null, 2);
|
|
991
|
+
return stringify(this.subPageMetaData, null, 2);
|
|
1016
992
|
}
|
|
1017
993
|
/**
|
|
1018
994
|
* Resolve tabBar configuration
|
|
@@ -1052,7 +1028,7 @@ var PageContext = class {
|
|
|
1052
1028
|
const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = parse(await fs.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "") || "{}");
|
|
1053
1029
|
const { pages: _pages, subPackages: _subPackages, tabBar: _tabBar, ...pageJson } = this.pagesGlobConfig || {};
|
|
1054
1030
|
const currentPlatform = platform.toUpperCase();
|
|
1055
|
-
pageJson.pages =
|
|
1031
|
+
pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
|
|
1056
1032
|
if (pageJson.pages && pageJson.pages.length > 0) {
|
|
1057
1033
|
const pagesArray = pageJson.pages;
|
|
1058
1034
|
const homeIndex = pagesArray.findIndex((page) => page.type === "home");
|
|
@@ -1067,7 +1043,7 @@ var PageContext = class {
|
|
|
1067
1043
|
for (const existing of pageJson.subPackages) {
|
|
1068
1044
|
const sub = newSubPackages.get(existing.root);
|
|
1069
1045
|
if (sub) {
|
|
1070
|
-
existing.pages =
|
|
1046
|
+
existing.pages = mergePlatformItems(existing.pages, currentPlatform, sub.pages, "path");
|
|
1071
1047
|
if (sub.plugins) existing.plugins = sub.plugins;
|
|
1072
1048
|
newSubPackages.delete(existing.root);
|
|
1073
1049
|
}
|
|
@@ -1075,7 +1051,7 @@ var PageContext = class {
|
|
|
1075
1051
|
for (const [_, newSub] of newSubPackages) {
|
|
1076
1052
|
const subPackage = {
|
|
1077
1053
|
root: newSub.root,
|
|
1078
|
-
pages:
|
|
1054
|
+
pages: mergePlatformItems(void 0, currentPlatform, newSub.pages, "path")
|
|
1079
1055
|
};
|
|
1080
1056
|
if (newSub.plugins) subPackage.plugins = newSub.plugins;
|
|
1081
1057
|
pageJson.subPackages.push(subPackage);
|
|
@@ -1145,6 +1121,13 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1145
1121
|
const trimed = comment.value.trim();
|
|
1146
1122
|
if (trimed.startsWith("GENERATED BY UNI-PAGES, PLATFORM:")) lastPlatforms = trimed.split(":")[1].split("||").map((s) => s.trim()).filter((s) => s !== currentPlatform).sort();
|
|
1147
1123
|
}
|
|
1124
|
+
const stringifyForCompare = (val) => {
|
|
1125
|
+
if (val && typeof val === "object" && "type" in val) {
|
|
1126
|
+
const { type: _type, ...rest } = val;
|
|
1127
|
+
return JSON.stringify(rest);
|
|
1128
|
+
}
|
|
1129
|
+
return JSON.stringify(val);
|
|
1130
|
+
};
|
|
1148
1131
|
const tmpMap = /* @__PURE__ */ new Map();
|
|
1149
1132
|
for (let i = 0; i < src.length; i++) {
|
|
1150
1133
|
const item = src[i];
|
|
@@ -1160,7 +1143,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1160
1143
|
const existing = tmpMap.get(uniqueKey) || [];
|
|
1161
1144
|
existing.push({
|
|
1162
1145
|
item,
|
|
1163
|
-
itemStr:
|
|
1146
|
+
itemStr: stringifyForCompare(item),
|
|
1164
1147
|
platforms,
|
|
1165
1148
|
platformStr: platforms.join(" || ")
|
|
1166
1149
|
});
|
|
@@ -1173,14 +1156,14 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1173
1156
|
if (!tmpMap.has(uniqueKey)) {
|
|
1174
1157
|
tmpMap.set(uniqueKey, [{
|
|
1175
1158
|
item: newItem,
|
|
1176
|
-
itemStr:
|
|
1159
|
+
itemStr: stringifyForCompare(newItem),
|
|
1177
1160
|
platforms: [currentPlatform],
|
|
1178
1161
|
platformStr: currentPlatform
|
|
1179
1162
|
}]);
|
|
1180
1163
|
continue;
|
|
1181
1164
|
}
|
|
1182
1165
|
const existing = tmpMap.get(uniqueKey);
|
|
1183
|
-
const newItemStr =
|
|
1166
|
+
const newItemStr = stringifyForCompare(newItem);
|
|
1184
1167
|
const equalObj = existing.find((val) => val.itemStr === newItemStr);
|
|
1185
1168
|
if (equalObj) {
|
|
1186
1169
|
equalObj.platforms.push(currentPlatform);
|
|
@@ -1188,7 +1171,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1188
1171
|
equalObj.platformStr = equalObj.platforms.join(" || ");
|
|
1189
1172
|
} else existing.push({
|
|
1190
1173
|
item: newItem,
|
|
1191
|
-
itemStr:
|
|
1174
|
+
itemStr: stringifyForCompare(newItem),
|
|
1192
1175
|
platforms: [currentPlatform],
|
|
1193
1176
|
platformStr: currentPlatform
|
|
1194
1177
|
});
|
|
@@ -1346,4 +1329,4 @@ function VitePluginUniPages(userOptions = {}) {
|
|
|
1346
1329
|
};
|
|
1347
1330
|
}
|
|
1348
1331
|
//#endregion
|
|
1349
|
-
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep,
|
|
1332
|
+
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, VitePluginUniPages as default, babelGenerate, checkPagesJsonFileSync, debug, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromMacro, withFileLock, writeFileWithLock };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uni-helper/vite-plugin-uni-pages",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.8",
|
|
5
5
|
"description": "File system based routing for uni-app applications using Vite",
|
|
6
6
|
"author": "KeJun",
|
|
7
7
|
"maintainers": [
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"unconfig": "^7.5.0",
|
|
73
73
|
"write-file-atomic": "^7.0.1",
|
|
74
74
|
"yaml": "^2.9.0",
|
|
75
|
-
"@uni-helper/uni-pages-types": "0.4.
|
|
75
|
+
"@uni-helper/uni-pages-types": "0.4.8"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@antfu/utils": "^9.3.0",
|