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

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
@@ -15,10 +15,10 @@ const commentJson = require('comment-json');
15
15
  const Debug = require('debug');
16
16
  const detectIndent = require('detect-indent');
17
17
  const detectNewline = require('detect-newline');
18
- const lockfile = require('proper-lockfile');
19
18
  const unconfig = require('unconfig');
20
19
  const promises = require('node:fs/promises');
21
20
  const fg = require('fast-glob');
21
+ const lockfile = require('proper-lockfile');
22
22
  const node_module = require('node:module');
23
23
  const vm = require('node:vm');
24
24
  const babelGenerator = require('@babel/generator');
@@ -51,8 +51,8 @@ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
51
51
  const Debug__default = /*#__PURE__*/_interopDefaultCompat(Debug);
52
52
  const detectIndent__default = /*#__PURE__*/_interopDefaultCompat(detectIndent);
53
53
  const detectNewline__default = /*#__PURE__*/_interopDefaultCompat(detectNewline);
54
- const lockfile__default = /*#__PURE__*/_interopDefaultCompat(lockfile);
55
54
  const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
55
+ const lockfile__default = /*#__PURE__*/_interopDefaultCompat(lockfile);
56
56
  const vm__default = /*#__PURE__*/_interopDefaultCompat(vm);
57
57
  const babelGenerator__default = /*#__PURE__*/_interopDefaultCompat(babelGenerator);
58
58
  const groupBy__default = /*#__PURE__*/_interopDefaultCompat(groupBy);
@@ -777,8 +777,11 @@ class PageContext {
777
777
  const generatedPageMetaData = await Promise.all(jobs);
778
778
  const customPageMetaData = overrides || [];
779
779
  const result = customPageMetaData.length ? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData)) : generatedPageMetaData;
780
- const parseMeta = result.filter(
781
- (page, index, self) => self.findLastIndex((item) => page.path === item.path) === index
780
+ const parseMeta = Array.from(
781
+ result.reduce((map, page) => {
782
+ map.set(page.path, page);
783
+ return map;
784
+ }, /* @__PURE__ */ new Map()).values()
782
785
  );
783
786
  return type === "main" ? this.setHomePage(parseMeta) : parseMeta;
784
787
  }
@@ -932,35 +935,14 @@ class PageContext {
932
935
  debug.declaration("generating");
933
936
  return writeDeclaration(this, this.options.dts);
934
937
  }
935
- async writePagesJSONFile(pagesJson, retry = 3) {
936
- if (retry <= 0) {
937
- debug.error(`${this.resolvedPagesJSONPath} \u83B7\u53D6\u6587\u4EF6\u9501\u5931\u8D25\uFF0C\u5199\u5165\u5931\u8D25`);
938
- return;
939
- }
940
- let relase;
941
- try {
942
- try {
943
- relase = await lockfile__default.lock(this.resolvedPagesJSONPath, { realpath: false });
944
- } catch {
945
- return this.writePagesJSONFile(pagesJson, retry - 1);
946
- }
947
- await fs__default.promises.writeFile(this.resolvedPagesJSONPath, pagesJson, { encoding: "utf-8" });
948
- } finally {
949
- if (relase) {
950
- await relase();
951
- }
952
- }
953
- }
954
938
  async genratePagesJSON() {
955
939
  const content = await fs__default.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "");
956
- let pageJson = commentJson.parse(content || "{}");
940
+ const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = commentJson.parse(content || "{}");
957
941
  const { pages: _, subPackages: __, tabBar: ___, ...others } = this.pagesGlobConfig || {};
958
- pageJson = Object.assign(pageJson, {
959
- ...others
960
- });
942
+ const pageJson = { ...others };
961
943
  const currentPlatform = uniEnv.platform.toUpperCase();
962
- pageJson.pages = mergePlatformItems(pageJson?.pages, currentPlatform, this.pageMetaData, "path");
963
- pageJson.subPackages = pageJson?.subPackages || new commentJson.CommentArray();
944
+ pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
945
+ pageJson.subPackages = oldSubPackages || new commentJson.CommentArray();
964
946
  const newSubPackages = /* @__PURE__ */ new Map();
965
947
  for (const item of this.subPageMetaData) {
966
948
  newSubPackages.set(item.root, item);
@@ -978,15 +960,17 @@ class PageContext {
978
960
  pages: mergePlatformItems(void 0, currentPlatform, newSub.pages, "path")
979
961
  });
980
962
  }
981
- const tabBar = await this.getTabBarMerged();
982
- if (tabBar) {
983
- const list = mergePlatformItems(pageJson?.tabBar?.list, currentPlatform, tabBar.list, "pagePath");
984
- if (pageJson?.tabBar?.list) {
985
- pageJson.tabBar.list = list;
986
- } else {
987
- pageJson.tabBar = pageJson.tabBar || {};
988
- pageJson.tabBar.list = list;
989
- }
963
+ const { list, ...tabBarOthers } = await this.getTabBarMerged() || {};
964
+ if (list) {
965
+ const { list: oldList } = oldTabBar || {};
966
+ const newList = mergePlatformItems(oldList, currentPlatform, list, "pagePath");
967
+ pageJson.tabBar = {
968
+ ...tabBarOthers,
969
+ // 每次都直接更新除 list 外的其他属性
970
+ list: newList
971
+ };
972
+ } else {
973
+ pageJson.tabBar = void 0;
990
974
  }
991
975
  return pageJson;
992
976
  }
package/dist/index.d.cts CHANGED
@@ -2995,7 +2995,6 @@ declare class PageContext {
2995
2995
  resolveRoutes(): string;
2996
2996
  resolveSubRoutes(): string;
2997
2997
  generateDeclaration(): Promise<void> | undefined;
2998
- private writePagesJSONFile;
2999
2998
  private genratePagesJSON;
3000
2999
  private readInfoFromPagesJSON;
3001
3000
  private getIndent;
package/dist/index.d.mts CHANGED
@@ -2995,7 +2995,6 @@ declare class PageContext {
2995
2995
  resolveRoutes(): string;
2996
2996
  resolveSubRoutes(): string;
2997
2997
  generateDeclaration(): Promise<void> | undefined;
2998
- private writePagesJSONFile;
2999
2998
  private genratePagesJSON;
3000
2999
  private readInfoFromPagesJSON;
3001
3000
  private getIndent;
package/dist/index.d.ts CHANGED
@@ -2995,7 +2995,6 @@ declare class PageContext {
2995
2995
  resolveRoutes(): string;
2996
2996
  resolveSubRoutes(): string;
2997
2997
  generateDeclaration(): Promise<void> | undefined;
2998
- private writePagesJSONFile;
2999
2998
  private genratePagesJSON;
3000
2999
  private readInfoFromPagesJSON;
3001
3000
  private getIndent;
package/dist/index.mjs CHANGED
@@ -11,10 +11,10 @@ import { parse, assign, stringify, CommentArray } from 'comment-json';
11
11
  import Debug from 'debug';
12
12
  import detectIndent from 'detect-indent';
13
13
  import detectNewline from 'detect-newline';
14
- import lockfile from 'proper-lockfile';
15
14
  import { loadConfig } from 'unconfig';
16
15
  import { readFile, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
17
16
  import fg from 'fast-glob';
17
+ import lockfile from 'proper-lockfile';
18
18
  import { createRequire } from 'node:module';
19
19
  import vm from 'node:vm';
20
20
  import babelGenerator from '@babel/generator';
@@ -742,8 +742,11 @@ class PageContext {
742
742
  const generatedPageMetaData = await Promise.all(jobs);
743
743
  const customPageMetaData = overrides || [];
744
744
  const result = customPageMetaData.length ? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData)) : generatedPageMetaData;
745
- const parseMeta = result.filter(
746
- (page, index, self) => self.findLastIndex((item) => page.path === item.path) === index
745
+ const parseMeta = Array.from(
746
+ result.reduce((map, page) => {
747
+ map.set(page.path, page);
748
+ return map;
749
+ }, /* @__PURE__ */ new Map()).values()
747
750
  );
748
751
  return type === "main" ? this.setHomePage(parseMeta) : parseMeta;
749
752
  }
@@ -897,35 +900,14 @@ class PageContext {
897
900
  debug.declaration("generating");
898
901
  return writeDeclaration(this, this.options.dts);
899
902
  }
900
- async writePagesJSONFile(pagesJson, retry = 3) {
901
- if (retry <= 0) {
902
- debug.error(`${this.resolvedPagesJSONPath} \u83B7\u53D6\u6587\u4EF6\u9501\u5931\u8D25\uFF0C\u5199\u5165\u5931\u8D25`);
903
- return;
904
- }
905
- let relase;
906
- try {
907
- try {
908
- relase = await lockfile.lock(this.resolvedPagesJSONPath, { realpath: false });
909
- } catch {
910
- return this.writePagesJSONFile(pagesJson, retry - 1);
911
- }
912
- await fs.promises.writeFile(this.resolvedPagesJSONPath, pagesJson, { encoding: "utf-8" });
913
- } finally {
914
- if (relase) {
915
- await relase();
916
- }
917
- }
918
- }
919
903
  async genratePagesJSON() {
920
904
  const content = await fs.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "");
921
- let pageJson = parse(content || "{}");
905
+ const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = parse(content || "{}");
922
906
  const { pages: _, subPackages: __, tabBar: ___, ...others } = this.pagesGlobConfig || {};
923
- pageJson = Object.assign(pageJson, {
924
- ...others
925
- });
907
+ const pageJson = { ...others };
926
908
  const currentPlatform = platform.toUpperCase();
927
- pageJson.pages = mergePlatformItems(pageJson?.pages, currentPlatform, this.pageMetaData, "path");
928
- pageJson.subPackages = pageJson?.subPackages || new CommentArray();
909
+ pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
910
+ pageJson.subPackages = oldSubPackages || new CommentArray();
929
911
  const newSubPackages = /* @__PURE__ */ new Map();
930
912
  for (const item of this.subPageMetaData) {
931
913
  newSubPackages.set(item.root, item);
@@ -943,15 +925,17 @@ class PageContext {
943
925
  pages: mergePlatformItems(void 0, currentPlatform, newSub.pages, "path")
944
926
  });
945
927
  }
946
- const tabBar = await this.getTabBarMerged();
947
- if (tabBar) {
948
- const list = mergePlatformItems(pageJson?.tabBar?.list, currentPlatform, tabBar.list, "pagePath");
949
- if (pageJson?.tabBar?.list) {
950
- pageJson.tabBar.list = list;
951
- } else {
952
- pageJson.tabBar = pageJson.tabBar || {};
953
- pageJson.tabBar.list = list;
954
- }
928
+ const { list, ...tabBarOthers } = await this.getTabBarMerged() || {};
929
+ if (list) {
930
+ const { list: oldList } = oldTabBar || {};
931
+ const newList = mergePlatformItems(oldList, currentPlatform, list, "pagePath");
932
+ pageJson.tabBar = {
933
+ ...tabBarOthers,
934
+ // 每次都直接更新除 list 外的其他属性
935
+ list: newList
936
+ };
937
+ } else {
938
+ pageJson.tabBar = void 0;
955
939
  }
956
940
  return pageJson;
957
941
  }
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.18",
4
+ "version": "0.3.19",
5
5
  "description": "File system based routing for uni-app applications using Vite",
6
6
  "author": "KeJun",
7
7
  "maintainers": [