@uni-helper/vite-plugin-uni-pages 0.3.19 → 0.3.21

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/index.cjs CHANGED
@@ -319,18 +319,18 @@ async function writeFileWithLock(path, content, retry = 3) {
319
319
  debug.error(`${path} \u83B7\u53D6\u6587\u4EF6\u9501\u5931\u8D25\uFF0C\u5199\u5165\u5931\u8D25`);
320
320
  return;
321
321
  }
322
- let relase;
322
+ let release;
323
323
  try {
324
324
  try {
325
- relase = await lockfile__default.lock(path, { realpath: false });
325
+ release = await lockfile__default.lock(path, { realpath: false });
326
326
  } catch {
327
327
  await sleep(500);
328
328
  return writeFileWithLock(path, content, retry - 1);
329
329
  }
330
330
  await fs__default.promises.writeFile(path, content, { encoding: "utf-8" });
331
331
  } finally {
332
- if (relase) {
333
- await relase();
332
+ if (release) {
333
+ await release();
334
334
  }
335
335
  }
336
336
  }
@@ -809,6 +809,9 @@ class PageContext {
809
809
  return result;
810
810
  }
811
811
  async mergePageMetaData() {
812
+ const subPageAbsolutePaths = Array.from(this.subPages.values()).flatMap((v) => Array.from(v.keys()));
813
+ for (const subPageAbsolutePath of subPageAbsolutePaths)
814
+ this.pages.delete(subPageAbsolutePath);
812
815
  const pageMetaData = await this.parsePages(this.pages, "main", this.pagesGlobConfig?.pages);
813
816
  this.pageMetaData = pageMetaData;
814
817
  debug.pages(this.pageMetaData);
@@ -938,8 +941,7 @@ class PageContext {
938
941
  async genratePagesJSON() {
939
942
  const content = await fs__default.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "");
940
943
  const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = commentJson.parse(content || "{}");
941
- const { pages: _, subPackages: __, tabBar: ___, ...others } = this.pagesGlobConfig || {};
942
- const pageJson = { ...others };
944
+ const { pages: _, subPackages: __, tabBar: ___, ...pageJson } = this.pagesGlobConfig || {};
943
945
  const currentPlatform = uniEnv.platform.toUpperCase();
944
946
  pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
945
947
  pageJson.subPackages = oldSubPackages || new commentJson.CommentArray();
@@ -1040,7 +1042,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
1040
1042
  continue;
1041
1043
  }
1042
1044
  const existing = tmpMap.get(uniqueKey) || [];
1043
- existing.push({ item, platforms, platformStr: platforms.join(" || ") });
1045
+ existing.push({ item, itemStr: JSON.stringify(item), platforms, platformStr: platforms.join(" || ") });
1044
1046
  tmpMap.set(uniqueKey, existing);
1045
1047
  }
1046
1048
  for (const item of items) {
@@ -1052,6 +1054,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
1052
1054
  if (!tmpMap.has(uniqueKey)) {
1053
1055
  tmpMap.set(uniqueKey, [{
1054
1056
  item: newItem,
1057
+ itemStr: JSON.stringify(newItem),
1055
1058
  platforms: [currentPlatform],
1056
1059
  platformStr: currentPlatform
1057
1060
  }]);
@@ -1059,13 +1062,15 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
1059
1062
  }
1060
1063
  const existing = tmpMap.get(uniqueKey);
1061
1064
  const newItemStr = JSON.stringify(newItem);
1062
- const equalObj = existing.find((val) => JSON.stringify(val.item) === newItemStr);
1065
+ const equalObj = existing.find((val) => val.itemStr === newItemStr);
1063
1066
  if (equalObj) {
1064
1067
  equalObj.platforms.push(currentPlatform);
1068
+ equalObj.platforms.sort();
1065
1069
  equalObj.platformStr = equalObj.platforms.join(" || ");
1066
1070
  } else {
1067
1071
  existing.push({
1068
1072
  item: newItem,
1073
+ itemStr: newItemStr,
1069
1074
  platforms: [currentPlatform],
1070
1075
  platformStr: currentPlatform
1071
1076
  });
package/dist/index.d.cts CHANGED
@@ -3152,6 +3152,9 @@ interface PageMetaDatum {
3152
3152
  needLogin?: boolean;
3153
3153
  [x: string]: any;
3154
3154
  }
3155
+ type ExcludeIndexSignature<T> = {
3156
+ [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
3157
+ };
3155
3158
  interface SubPageMetaDatum {
3156
3159
  root: string;
3157
3160
  pages: PageMetaDatum[];
@@ -3214,4 +3217,4 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
3214
3217
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3215
3218
 
3216
3219
  export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileWithLock };
3217
- export type { Condition, ConditionItem, ConfigSource, CustomBlock, DefinePage, EasyCom, GlobalStyle, MaybeCallable, MaybePromise, MaybePromiseCallable, Options, PageMetaDatum, PagePath, PagesConfig, ResolvedOptions, RouteBlockLang, SubPackage, SubPackages, SubPageMetaDatum, TabBar, TabBarIconFont, TabBarItem, TabBarMidButton, TheWindow, UniIdRouter, UserOptions, UserPageMeta, UserPagesConfig, UserTabBarItem, debugType };
3220
+ export type { Condition, ConditionItem, ConfigSource, CustomBlock, DefinePage, EasyCom, ExcludeIndexSignature, GlobalStyle, MaybeCallable, MaybePromise, MaybePromiseCallable, Options, PageMetaDatum, PagePath, PagesConfig, ResolvedOptions, RouteBlockLang, SubPackage, SubPackages, SubPageMetaDatum, TabBar, TabBarIconFont, TabBarItem, TabBarMidButton, TheWindow, UniIdRouter, UserOptions, UserPageMeta, UserPagesConfig, UserTabBarItem, debugType };
package/dist/index.d.mts CHANGED
@@ -3152,6 +3152,9 @@ interface PageMetaDatum {
3152
3152
  needLogin?: boolean;
3153
3153
  [x: string]: any;
3154
3154
  }
3155
+ type ExcludeIndexSignature<T> = {
3156
+ [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
3157
+ };
3155
3158
  interface SubPageMetaDatum {
3156
3159
  root: string;
3157
3160
  pages: PageMetaDatum[];
@@ -3214,4 +3217,4 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
3214
3217
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3215
3218
 
3216
3219
  export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileWithLock };
3217
- export type { Condition, ConditionItem, ConfigSource, CustomBlock, DefinePage, EasyCom, GlobalStyle, MaybeCallable, MaybePromise, MaybePromiseCallable, Options, PageMetaDatum, PagePath, PagesConfig, ResolvedOptions, RouteBlockLang, SubPackage, SubPackages, SubPageMetaDatum, TabBar, TabBarIconFont, TabBarItem, TabBarMidButton, TheWindow, UniIdRouter, UserOptions, UserPageMeta, UserPagesConfig, UserTabBarItem, debugType };
3220
+ export type { Condition, ConditionItem, ConfigSource, CustomBlock, DefinePage, EasyCom, ExcludeIndexSignature, GlobalStyle, MaybeCallable, MaybePromise, MaybePromiseCallable, Options, PageMetaDatum, PagePath, PagesConfig, ResolvedOptions, RouteBlockLang, SubPackage, SubPackages, SubPageMetaDatum, TabBar, TabBarIconFont, TabBarItem, TabBarMidButton, TheWindow, UniIdRouter, UserOptions, UserPageMeta, UserPagesConfig, UserTabBarItem, debugType };
package/dist/index.d.ts CHANGED
@@ -3152,6 +3152,9 @@ interface PageMetaDatum {
3152
3152
  needLogin?: boolean;
3153
3153
  [x: string]: any;
3154
3154
  }
3155
+ type ExcludeIndexSignature<T> = {
3156
+ [K in keyof T as string extends K ? never : number extends K ? never : K]: T[K];
3157
+ };
3155
3158
  interface SubPageMetaDatum {
3156
3159
  root: string;
3157
3160
  pages: PageMetaDatum[];
@@ -3214,4 +3217,4 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
3214
3217
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3215
3218
 
3216
3219
  export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileWithLock };
3217
- export type { Condition, ConditionItem, ConfigSource, CustomBlock, DefinePage, EasyCom, GlobalStyle, MaybeCallable, MaybePromise, MaybePromiseCallable, Options, PageMetaDatum, PagePath, PagesConfig, ResolvedOptions, RouteBlockLang, SubPackage, SubPackages, SubPageMetaDatum, TabBar, TabBarIconFont, TabBarItem, TabBarMidButton, TheWindow, UniIdRouter, UserOptions, UserPageMeta, UserPagesConfig, UserTabBarItem, debugType };
3220
+ export type { Condition, ConditionItem, ConfigSource, CustomBlock, DefinePage, EasyCom, ExcludeIndexSignature, GlobalStyle, MaybeCallable, MaybePromise, MaybePromiseCallable, Options, PageMetaDatum, PagePath, PagesConfig, ResolvedOptions, RouteBlockLang, SubPackage, SubPackages, SubPageMetaDatum, TabBar, TabBarIconFont, TabBarItem, TabBarMidButton, TheWindow, UniIdRouter, UserOptions, UserPageMeta, UserPagesConfig, UserTabBarItem, debugType };
package/dist/index.mjs CHANGED
@@ -284,18 +284,18 @@ async function writeFileWithLock(path, content, retry = 3) {
284
284
  debug.error(`${path} \u83B7\u53D6\u6587\u4EF6\u9501\u5931\u8D25\uFF0C\u5199\u5165\u5931\u8D25`);
285
285
  return;
286
286
  }
287
- let relase;
287
+ let release;
288
288
  try {
289
289
  try {
290
- relase = await lockfile.lock(path, { realpath: false });
290
+ release = await lockfile.lock(path, { realpath: false });
291
291
  } catch {
292
292
  await sleep(500);
293
293
  return writeFileWithLock(path, content, retry - 1);
294
294
  }
295
295
  await fs.promises.writeFile(path, content, { encoding: "utf-8" });
296
296
  } finally {
297
- if (relase) {
298
- await relase();
297
+ if (release) {
298
+ await release();
299
299
  }
300
300
  }
301
301
  }
@@ -774,6 +774,9 @@ class PageContext {
774
774
  return result;
775
775
  }
776
776
  async mergePageMetaData() {
777
+ const subPageAbsolutePaths = Array.from(this.subPages.values()).flatMap((v) => Array.from(v.keys()));
778
+ for (const subPageAbsolutePath of subPageAbsolutePaths)
779
+ this.pages.delete(subPageAbsolutePath);
777
780
  const pageMetaData = await this.parsePages(this.pages, "main", this.pagesGlobConfig?.pages);
778
781
  this.pageMetaData = pageMetaData;
779
782
  debug.pages(this.pageMetaData);
@@ -903,8 +906,7 @@ class PageContext {
903
906
  async genratePagesJSON() {
904
907
  const content = await fs.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "");
905
908
  const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = parse(content || "{}");
906
- const { pages: _, subPackages: __, tabBar: ___, ...others } = this.pagesGlobConfig || {};
907
- const pageJson = { ...others };
909
+ const { pages: _, subPackages: __, tabBar: ___, ...pageJson } = this.pagesGlobConfig || {};
908
910
  const currentPlatform = platform.toUpperCase();
909
911
  pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
910
912
  pageJson.subPackages = oldSubPackages || new CommentArray();
@@ -1005,7 +1007,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
1005
1007
  continue;
1006
1008
  }
1007
1009
  const existing = tmpMap.get(uniqueKey) || [];
1008
- existing.push({ item, platforms, platformStr: platforms.join(" || ") });
1010
+ existing.push({ item, itemStr: JSON.stringify(item), platforms, platformStr: platforms.join(" || ") });
1009
1011
  tmpMap.set(uniqueKey, existing);
1010
1012
  }
1011
1013
  for (const item of items) {
@@ -1017,6 +1019,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
1017
1019
  if (!tmpMap.has(uniqueKey)) {
1018
1020
  tmpMap.set(uniqueKey, [{
1019
1021
  item: newItem,
1022
+ itemStr: JSON.stringify(newItem),
1020
1023
  platforms: [currentPlatform],
1021
1024
  platformStr: currentPlatform
1022
1025
  }]);
@@ -1024,13 +1027,15 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
1024
1027
  }
1025
1028
  const existing = tmpMap.get(uniqueKey);
1026
1029
  const newItemStr = JSON.stringify(newItem);
1027
- const equalObj = existing.find((val) => JSON.stringify(val.item) === newItemStr);
1030
+ const equalObj = existing.find((val) => val.itemStr === newItemStr);
1028
1031
  if (equalObj) {
1029
1032
  equalObj.platforms.push(currentPlatform);
1033
+ equalObj.platforms.sort();
1030
1034
  equalObj.platformStr = equalObj.platforms.join(" || ");
1031
1035
  } else {
1032
1036
  existing.push({
1033
1037
  item: newItem,
1038
+ itemStr: newItemStr,
1034
1039
  platforms: [currentPlatform],
1035
1040
  platformStr: currentPlatform
1036
1041
  });
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.3.19",
4
+ "version": "0.3.21",
5
5
  "description": "File system based routing for uni-app applications using Vite",
6
6
  "author": "KeJun",
7
7
  "maintainers": [