@uni-helper/vite-plugin-uni-pages 0.3.10 → 0.3.12

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
@@ -404,53 +404,64 @@ var __publicField$1 = (obj, key, value) => {
404
404
  return value;
405
405
  };
406
406
  class Page {
407
- constructor(ctx, path) {
407
+ constructor(ctx, path$1) {
408
408
  __publicField$1(this, "ctx");
409
409
  __publicField$1(this, "path");
410
- __publicField$1(this, "rawOptions", "");
411
- __publicField$1(this, "options");
410
+ __publicField$1(this, "uri");
411
+ __publicField$1(this, "changed", true);
412
+ __publicField$1(this, "raw", "");
413
+ __publicField$1(this, "meta");
412
414
  this.ctx = ctx;
413
- this.path = path;
415
+ this.path = path$1;
416
+ this.uri = vite.normalizePath(path$1.relativePath.replace(path.extname(path$1.relativePath), ""));
414
417
  }
415
418
  async getPageMeta(forceUpdate = false) {
416
- if (forceUpdate || !this.options) {
417
- await this.readPageMeta();
419
+ if (forceUpdate || !this.meta) {
420
+ await this.read();
418
421
  }
419
- return this.options;
422
+ const { path, tabBar: _, ...others } = this.meta;
423
+ return {
424
+ path: path ?? this.uri,
425
+ ...others
426
+ };
427
+ }
428
+ async getTabBar(forceUpdate = false) {
429
+ if (forceUpdate || !this.meta) {
430
+ await this.read();
431
+ }
432
+ const { tabBar } = this.meta;
433
+ if (tabBar === void 0) {
434
+ return void 0;
435
+ }
436
+ return {
437
+ ...tabBar,
438
+ pagePath: tabBar.pagePath || this.uri,
439
+ index: tabBar.index || 0
440
+ };
441
+ }
442
+ hasChanged() {
443
+ return this.changed;
420
444
  }
421
- async hasChanged() {
422
- const { hasChanged } = await this.readPageMeta();
423
- return hasChanged;
445
+ async read() {
446
+ this.meta = await this.readPageMetaFromFile();
447
+ const raw = this.meta ? JSON.stringify(this.meta) : "";
448
+ this.changed = this.raw !== raw;
449
+ this.raw = raw;
424
450
  }
425
- async readPageMeta() {
451
+ async readPageMetaFromFile() {
426
452
  try {
427
- const { relativePath } = this.path;
428
- const { path: path$1, ...others } = await this.readPageMetaFromFile();
429
- this.options = {
430
- path: path$1 ?? vite.normalizePath(relativePath.replace(path.extname(relativePath), "")),
431
- ...others
432
- };
433
- const raw = this.options ? JSON.stringify(this.options) : "";
434
- const hasChanged = this.rawOptions !== raw;
435
- this.rawOptions = raw;
436
- return {
437
- options: this.options,
438
- hasChanged
439
- };
453
+ const content = fs.readFileSync(this.path.absolutePath, "utf-8");
454
+ const sfc = parseSFC(content, { filename: this.path.absolutePath });
455
+ const meta = await tryPageMetaFromMacro(sfc);
456
+ if (meta) {
457
+ return meta;
458
+ }
459
+ return tryPageMetaFromCustomBlock(sfc, this.ctx.options.routeBlockLang);
440
460
  } catch (err) {
441
- throw new Error(`Read page options fail in ${this.path.relativePath}
461
+ throw new Error(`Read page meta fail in ${this.path.relativePath}
442
462
  ${err.message}`);
443
463
  }
444
464
  }
445
- async readPageMetaFromFile() {
446
- const content = fs.readFileSync(this.path.absolutePath, "utf-8");
447
- const sfc = parseSFC(content, { filename: this.path.absolutePath });
448
- const meta = await tryPageMetaFromMacro(sfc);
449
- if (meta) {
450
- return meta;
451
- }
452
- return tryPageMetaFromCustomBlock(sfc, this.ctx.options.routeBlockLang);
453
- }
454
465
  }
455
466
  function parseSFC(code, options) {
456
467
  try {
@@ -477,7 +488,7 @@ async function tryPageMetaFromMacro(sfc) {
477
488
  });
478
489
  const macro = findMacro(ast.body, sfc.filename);
479
490
  if (macro) {
480
- const imports = findImports(ast.body).map((imp) => babelGenerate(imp).code);
491
+ const imports = findImports(ast.body).filter((imp) => !!imp.specifiers.length).map((imp) => babelGenerate(imp).code);
481
492
  const [macroOption] = macro.arguments;
482
493
  const code = babelGenerate(macroOption).code;
483
494
  const result = await execScript({
@@ -524,7 +535,13 @@ function findMacro(stmts, filename) {
524
535
  return macro;
525
536
  }
526
537
  function findImports(stmts) {
527
- return stmts.map((node) => node.type === "ImportDeclaration" ? node : void 0).filter((node) => !!node);
538
+ const imports = [];
539
+ for (const stmt of stmts) {
540
+ if (t__namespace.isImportDeclaration(stmt)) {
541
+ imports.push(stmt);
542
+ }
543
+ }
544
+ return imports;
528
545
  }
529
546
 
530
547
  var __defProp = Object.defineProperty;
@@ -735,6 +752,31 @@ class PageContext {
735
752
  this.subPageMetaData = subPageMetaData;
736
753
  debug.subPages(this.subPageMetaData);
737
754
  }
755
+ async getTabBarMerged() {
756
+ const tabBar = {
757
+ ...this.pagesGlobConfig?.tabBar,
758
+ list: this.pagesGlobConfig?.tabBar?.list || []
759
+ };
760
+ const pagePaths = /* @__PURE__ */ new Map();
761
+ for (const item of tabBar.list) {
762
+ pagePaths.set(item.pagePath, true);
763
+ }
764
+ const tabBarItems = [];
765
+ for (const [_, page] of this.pages) {
766
+ const tabbar = await page.getTabBar();
767
+ if (tabbar) {
768
+ tabBarItems.push(tabbar);
769
+ }
770
+ }
771
+ tabBarItems.sort((a, b) => a.index - b.index);
772
+ for (const item of tabBarItems) {
773
+ if (!pagePaths.has(item.pagePath)) {
774
+ const { index: _, ...tabbar } = item;
775
+ tabBar.list.push(tabbar);
776
+ }
777
+ }
778
+ return tabBar;
779
+ }
738
780
  async updatePagesJSON(filepath) {
739
781
  if (filepath) {
740
782
  let page = this.pages.get(filepath);
@@ -748,9 +790,12 @@ class PageContext {
748
790
  }
749
791
  page = subPage;
750
792
  }
751
- if (page && !await page.hasChanged()) {
752
- debug.cache(`The route block on page ${filepath} did not send any changes, skipping`);
753
- return false;
793
+ if (page) {
794
+ await page.read();
795
+ if (!page.hasChanged()) {
796
+ debug.cache(`The route block on page ${filepath} did not send any changes, skipping`);
797
+ return false;
798
+ }
754
799
  }
755
800
  }
756
801
  checkPagesJsonFile(this.resolvedPagesJSONPath);
@@ -778,7 +823,8 @@ class PageContext {
778
823
  const data = {
779
824
  ...this.pagesGlobConfig,
780
825
  pages: this.pageMetaData,
781
- subPackages: this.subPageMetaData
826
+ subPackages: this.subPageMetaData,
827
+ tabBar: await this.getTabBarMerged()
782
828
  };
783
829
  const pagesJson = commentJson.stringify(
784
830
  data,
package/dist/index.d.cts CHANGED
@@ -2533,6 +2533,7 @@ interface SubPackage {
2533
2533
  [pluginName: string]: {
2534
2534
  version: string;
2535
2535
  provider: string;
2536
+ export?: string;
2536
2537
  [key: string]: any;
2537
2538
  };
2538
2539
  };
@@ -2926,15 +2927,17 @@ declare function defineUniPages(config: UserPagesConfig): UserPagesConfig;
2926
2927
  declare class Page {
2927
2928
  ctx: PageContext;
2928
2929
  path: PagePath;
2929
- private rawOptions;
2930
- private options;
2930
+ uri: string;
2931
+ changed: boolean;
2932
+ private raw;
2933
+ private meta;
2931
2934
  constructor(ctx: PageContext, path: PagePath);
2932
2935
  getPageMeta(forceUpdate?: boolean): Promise<PageMetaDatum>;
2933
- hasChanged(): Promise<boolean>;
2934
- readPageMeta(): Promise<{
2935
- options: PageMetaDatum;
2936
- hasChanged: boolean;
2937
- }>;
2936
+ getTabBar(forceUpdate?: boolean): Promise<TabBarItem & {
2937
+ index: number;
2938
+ } | undefined>;
2939
+ hasChanged(): boolean;
2940
+ read(): Promise<void>;
2938
2941
  private readPageMetaFromFile;
2939
2942
  }
2940
2943
  declare function parseSFC(code: string, options?: SFCParseOptions): SFCDescriptor;
@@ -2984,6 +2987,7 @@ declare class PageContext {
2984
2987
  setHomePage(result: PageMetaDatum[]): PageMetaDatum[];
2985
2988
  mergePageMetaData(): Promise<void>;
2986
2989
  mergeSubPageMetaData(): Promise<void>;
2990
+ private getTabBarMerged;
2987
2991
  updatePagesJSON(filepath?: string): Promise<boolean>;
2988
2992
  virtualModule(): string;
2989
2993
  resolveRoutes(): string;
@@ -3144,12 +3148,27 @@ interface SubPageMetaDatum {
3144
3148
  root: string;
3145
3149
  pages: PageMetaDatum[];
3146
3150
  }
3151
+ interface UserTabBarItem extends Partial<TabBarItem> {
3152
+ /**
3153
+ * 配置页面路径
3154
+ * @deprecated 可选,将会根据文件路径自动生成
3155
+ */
3156
+ pagePath?: string;
3157
+ /**
3158
+ * 排序,数字越小越靠前
3159
+ */
3160
+ index?: number;
3161
+ }
3147
3162
  interface UserPageMeta extends Partial<PageMetaDatum> {
3148
3163
  /**
3149
3164
  * 配置页面路径
3150
3165
  * @deprecated 可选,将会根据文件路径自动生成
3151
3166
  */
3152
3167
  path?: string;
3168
+ /**
3169
+ * 底部 tabBar 的子项 [tabBar](https://uniapp.dcloud.net.cn/collocation/pages#tabBar)
3170
+ */
3171
+ tabBar?: UserTabBarItem;
3153
3172
  }
3154
3173
  type MaybePromise<T> = T | Promise<T>;
3155
3174
  type MaybeCallable<T> = T | (() => T);
@@ -3183,4 +3202,4 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
3183
3202
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3184
3203
 
3185
3204
  export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFile, debug, VitePluginUniPages as default, definePage, defineUniPages, execScript, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, readFileSync, resolveOptions, resolvePageDirs, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileSync };
3186
- 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, debugType };
3205
+ 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 };
package/dist/index.d.mts CHANGED
@@ -2533,6 +2533,7 @@ interface SubPackage {
2533
2533
  [pluginName: string]: {
2534
2534
  version: string;
2535
2535
  provider: string;
2536
+ export?: string;
2536
2537
  [key: string]: any;
2537
2538
  };
2538
2539
  };
@@ -2926,15 +2927,17 @@ declare function defineUniPages(config: UserPagesConfig): UserPagesConfig;
2926
2927
  declare class Page {
2927
2928
  ctx: PageContext;
2928
2929
  path: PagePath;
2929
- private rawOptions;
2930
- private options;
2930
+ uri: string;
2931
+ changed: boolean;
2932
+ private raw;
2933
+ private meta;
2931
2934
  constructor(ctx: PageContext, path: PagePath);
2932
2935
  getPageMeta(forceUpdate?: boolean): Promise<PageMetaDatum>;
2933
- hasChanged(): Promise<boolean>;
2934
- readPageMeta(): Promise<{
2935
- options: PageMetaDatum;
2936
- hasChanged: boolean;
2937
- }>;
2936
+ getTabBar(forceUpdate?: boolean): Promise<TabBarItem & {
2937
+ index: number;
2938
+ } | undefined>;
2939
+ hasChanged(): boolean;
2940
+ read(): Promise<void>;
2938
2941
  private readPageMetaFromFile;
2939
2942
  }
2940
2943
  declare function parseSFC(code: string, options?: SFCParseOptions): SFCDescriptor;
@@ -2984,6 +2987,7 @@ declare class PageContext {
2984
2987
  setHomePage(result: PageMetaDatum[]): PageMetaDatum[];
2985
2988
  mergePageMetaData(): Promise<void>;
2986
2989
  mergeSubPageMetaData(): Promise<void>;
2990
+ private getTabBarMerged;
2987
2991
  updatePagesJSON(filepath?: string): Promise<boolean>;
2988
2992
  virtualModule(): string;
2989
2993
  resolveRoutes(): string;
@@ -3144,12 +3148,27 @@ interface SubPageMetaDatum {
3144
3148
  root: string;
3145
3149
  pages: PageMetaDatum[];
3146
3150
  }
3151
+ interface UserTabBarItem extends Partial<TabBarItem> {
3152
+ /**
3153
+ * 配置页面路径
3154
+ * @deprecated 可选,将会根据文件路径自动生成
3155
+ */
3156
+ pagePath?: string;
3157
+ /**
3158
+ * 排序,数字越小越靠前
3159
+ */
3160
+ index?: number;
3161
+ }
3147
3162
  interface UserPageMeta extends Partial<PageMetaDatum> {
3148
3163
  /**
3149
3164
  * 配置页面路径
3150
3165
  * @deprecated 可选,将会根据文件路径自动生成
3151
3166
  */
3152
3167
  path?: string;
3168
+ /**
3169
+ * 底部 tabBar 的子项 [tabBar](https://uniapp.dcloud.net.cn/collocation/pages#tabBar)
3170
+ */
3171
+ tabBar?: UserTabBarItem;
3153
3172
  }
3154
3173
  type MaybePromise<T> = T | Promise<T>;
3155
3174
  type MaybeCallable<T> = T | (() => T);
@@ -3183,4 +3202,4 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
3183
3202
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3184
3203
 
3185
3204
  export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFile, debug, VitePluginUniPages as default, definePage, defineUniPages, execScript, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, readFileSync, resolveOptions, resolvePageDirs, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileSync };
3186
- 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, debugType };
3205
+ 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 };
package/dist/index.d.ts CHANGED
@@ -2533,6 +2533,7 @@ interface SubPackage {
2533
2533
  [pluginName: string]: {
2534
2534
  version: string;
2535
2535
  provider: string;
2536
+ export?: string;
2536
2537
  [key: string]: any;
2537
2538
  };
2538
2539
  };
@@ -2926,15 +2927,17 @@ declare function defineUniPages(config: UserPagesConfig): UserPagesConfig;
2926
2927
  declare class Page {
2927
2928
  ctx: PageContext;
2928
2929
  path: PagePath;
2929
- private rawOptions;
2930
- private options;
2930
+ uri: string;
2931
+ changed: boolean;
2932
+ private raw;
2933
+ private meta;
2931
2934
  constructor(ctx: PageContext, path: PagePath);
2932
2935
  getPageMeta(forceUpdate?: boolean): Promise<PageMetaDatum>;
2933
- hasChanged(): Promise<boolean>;
2934
- readPageMeta(): Promise<{
2935
- options: PageMetaDatum;
2936
- hasChanged: boolean;
2937
- }>;
2936
+ getTabBar(forceUpdate?: boolean): Promise<TabBarItem & {
2937
+ index: number;
2938
+ } | undefined>;
2939
+ hasChanged(): boolean;
2940
+ read(): Promise<void>;
2938
2941
  private readPageMetaFromFile;
2939
2942
  }
2940
2943
  declare function parseSFC(code: string, options?: SFCParseOptions): SFCDescriptor;
@@ -2984,6 +2987,7 @@ declare class PageContext {
2984
2987
  setHomePage(result: PageMetaDatum[]): PageMetaDatum[];
2985
2988
  mergePageMetaData(): Promise<void>;
2986
2989
  mergeSubPageMetaData(): Promise<void>;
2990
+ private getTabBarMerged;
2987
2991
  updatePagesJSON(filepath?: string): Promise<boolean>;
2988
2992
  virtualModule(): string;
2989
2993
  resolveRoutes(): string;
@@ -3144,12 +3148,27 @@ interface SubPageMetaDatum {
3144
3148
  root: string;
3145
3149
  pages: PageMetaDatum[];
3146
3150
  }
3151
+ interface UserTabBarItem extends Partial<TabBarItem> {
3152
+ /**
3153
+ * 配置页面路径
3154
+ * @deprecated 可选,将会根据文件路径自动生成
3155
+ */
3156
+ pagePath?: string;
3157
+ /**
3158
+ * 排序,数字越小越靠前
3159
+ */
3160
+ index?: number;
3161
+ }
3147
3162
  interface UserPageMeta extends Partial<PageMetaDatum> {
3148
3163
  /**
3149
3164
  * 配置页面路径
3150
3165
  * @deprecated 可选,将会根据文件路径自动生成
3151
3166
  */
3152
3167
  path?: string;
3168
+ /**
3169
+ * 底部 tabBar 的子项 [tabBar](https://uniapp.dcloud.net.cn/collocation/pages#tabBar)
3170
+ */
3171
+ tabBar?: UserTabBarItem;
3153
3172
  }
3154
3173
  type MaybePromise<T> = T | Promise<T>;
3155
3174
  type MaybeCallable<T> = T | (() => T);
@@ -3183,4 +3202,4 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
3183
3202
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3184
3203
 
3185
3204
  export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFile, debug, VitePluginUniPages as default, definePage, defineUniPages, execScript, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, readFileSync, resolveOptions, resolvePageDirs, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileSync };
3186
- 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, debugType };
3205
+ 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 };
package/dist/index.mjs CHANGED
@@ -373,50 +373,61 @@ class Page {
373
373
  constructor(ctx, path) {
374
374
  __publicField$1(this, "ctx");
375
375
  __publicField$1(this, "path");
376
- __publicField$1(this, "rawOptions", "");
377
- __publicField$1(this, "options");
376
+ __publicField$1(this, "uri");
377
+ __publicField$1(this, "changed", true);
378
+ __publicField$1(this, "raw", "");
379
+ __publicField$1(this, "meta");
378
380
  this.ctx = ctx;
379
381
  this.path = path;
382
+ this.uri = normalizePath(path.relativePath.replace(extname(path.relativePath), ""));
380
383
  }
381
384
  async getPageMeta(forceUpdate = false) {
382
- if (forceUpdate || !this.options) {
383
- await this.readPageMeta();
385
+ if (forceUpdate || !this.meta) {
386
+ await this.read();
384
387
  }
385
- return this.options;
388
+ const { path, tabBar: _, ...others } = this.meta;
389
+ return {
390
+ path: path ?? this.uri,
391
+ ...others
392
+ };
393
+ }
394
+ async getTabBar(forceUpdate = false) {
395
+ if (forceUpdate || !this.meta) {
396
+ await this.read();
397
+ }
398
+ const { tabBar } = this.meta;
399
+ if (tabBar === void 0) {
400
+ return void 0;
401
+ }
402
+ return {
403
+ ...tabBar,
404
+ pagePath: tabBar.pagePath || this.uri,
405
+ index: tabBar.index || 0
406
+ };
407
+ }
408
+ hasChanged() {
409
+ return this.changed;
386
410
  }
387
- async hasChanged() {
388
- const { hasChanged } = await this.readPageMeta();
389
- return hasChanged;
411
+ async read() {
412
+ this.meta = await this.readPageMetaFromFile();
413
+ const raw = this.meta ? JSON.stringify(this.meta) : "";
414
+ this.changed = this.raw !== raw;
415
+ this.raw = raw;
390
416
  }
391
- async readPageMeta() {
417
+ async readPageMetaFromFile() {
392
418
  try {
393
- const { relativePath } = this.path;
394
- const { path, ...others } = await this.readPageMetaFromFile();
395
- this.options = {
396
- path: path ?? normalizePath(relativePath.replace(extname(relativePath), "")),
397
- ...others
398
- };
399
- const raw = this.options ? JSON.stringify(this.options) : "";
400
- const hasChanged = this.rawOptions !== raw;
401
- this.rawOptions = raw;
402
- return {
403
- options: this.options,
404
- hasChanged
405
- };
419
+ const content = readFileSync$1(this.path.absolutePath, "utf-8");
420
+ const sfc = parseSFC(content, { filename: this.path.absolutePath });
421
+ const meta = await tryPageMetaFromMacro(sfc);
422
+ if (meta) {
423
+ return meta;
424
+ }
425
+ return tryPageMetaFromCustomBlock(sfc, this.ctx.options.routeBlockLang);
406
426
  } catch (err) {
407
- throw new Error(`Read page options fail in ${this.path.relativePath}
427
+ throw new Error(`Read page meta fail in ${this.path.relativePath}
408
428
  ${err.message}`);
409
429
  }
410
430
  }
411
- async readPageMetaFromFile() {
412
- const content = readFileSync$1(this.path.absolutePath, "utf-8");
413
- const sfc = parseSFC(content, { filename: this.path.absolutePath });
414
- const meta = await tryPageMetaFromMacro(sfc);
415
- if (meta) {
416
- return meta;
417
- }
418
- return tryPageMetaFromCustomBlock(sfc, this.ctx.options.routeBlockLang);
419
- }
420
431
  }
421
432
  function parseSFC(code, options) {
422
433
  try {
@@ -443,7 +454,7 @@ async function tryPageMetaFromMacro(sfc) {
443
454
  });
444
455
  const macro = findMacro(ast.body, sfc.filename);
445
456
  if (macro) {
446
- const imports = findImports(ast.body).map((imp) => babelGenerate(imp).code);
457
+ const imports = findImports(ast.body).filter((imp) => !!imp.specifiers.length).map((imp) => babelGenerate(imp).code);
447
458
  const [macroOption] = macro.arguments;
448
459
  const code = babelGenerate(macroOption).code;
449
460
  const result = await execScript({
@@ -490,7 +501,13 @@ function findMacro(stmts, filename) {
490
501
  return macro;
491
502
  }
492
503
  function findImports(stmts) {
493
- return stmts.map((node) => node.type === "ImportDeclaration" ? node : void 0).filter((node) => !!node);
504
+ const imports = [];
505
+ for (const stmt of stmts) {
506
+ if (t.isImportDeclaration(stmt)) {
507
+ imports.push(stmt);
508
+ }
509
+ }
510
+ return imports;
494
511
  }
495
512
 
496
513
  var __defProp = Object.defineProperty;
@@ -701,6 +718,31 @@ class PageContext {
701
718
  this.subPageMetaData = subPageMetaData;
702
719
  debug.subPages(this.subPageMetaData);
703
720
  }
721
+ async getTabBarMerged() {
722
+ const tabBar = {
723
+ ...this.pagesGlobConfig?.tabBar,
724
+ list: this.pagesGlobConfig?.tabBar?.list || []
725
+ };
726
+ const pagePaths = /* @__PURE__ */ new Map();
727
+ for (const item of tabBar.list) {
728
+ pagePaths.set(item.pagePath, true);
729
+ }
730
+ const tabBarItems = [];
731
+ for (const [_, page] of this.pages) {
732
+ const tabbar = await page.getTabBar();
733
+ if (tabbar) {
734
+ tabBarItems.push(tabbar);
735
+ }
736
+ }
737
+ tabBarItems.sort((a, b) => a.index - b.index);
738
+ for (const item of tabBarItems) {
739
+ if (!pagePaths.has(item.pagePath)) {
740
+ const { index: _, ...tabbar } = item;
741
+ tabBar.list.push(tabbar);
742
+ }
743
+ }
744
+ return tabBar;
745
+ }
704
746
  async updatePagesJSON(filepath) {
705
747
  if (filepath) {
706
748
  let page = this.pages.get(filepath);
@@ -714,9 +756,12 @@ class PageContext {
714
756
  }
715
757
  page = subPage;
716
758
  }
717
- if (page && !await page.hasChanged()) {
718
- debug.cache(`The route block on page ${filepath} did not send any changes, skipping`);
719
- return false;
759
+ if (page) {
760
+ await page.read();
761
+ if (!page.hasChanged()) {
762
+ debug.cache(`The route block on page ${filepath} did not send any changes, skipping`);
763
+ return false;
764
+ }
720
765
  }
721
766
  }
722
767
  checkPagesJsonFile(this.resolvedPagesJSONPath);
@@ -744,7 +789,8 @@ class PageContext {
744
789
  const data = {
745
790
  ...this.pagesGlobConfig,
746
791
  pages: this.pageMetaData,
747
- subPackages: this.subPageMetaData
792
+ subPackages: this.subPageMetaData,
793
+ tabBar: await this.getTabBarMerged()
748
794
  };
749
795
  const pagesJson = stringify(
750
796
  data,
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.10",
4
+ "version": "0.3.12",
5
5
  "description": "File system based routing for uni-app applications using Vite",
6
6
  "author": "KeJun",
7
7
  "maintainers": [
@@ -55,7 +55,7 @@
55
55
  "@babel/types": "^7.28.2",
56
56
  "@uni-helper/uni-env": "^0.1.4",
57
57
  "@vue/compiler-sfc": "3.4.21",
58
- "ast-kit": "^2.1.2",
58
+ "ast-kit": "1.4.3",
59
59
  "chokidar": "^3.6.0",
60
60
  "comment-json": "^4.2.5",
61
61
  "debug": "^4.3.6",