@uni-helper/vite-plugin-uni-pages 0.2.23 → 0.2.25

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
@@ -11,6 +11,8 @@ const chokidar = require('chokidar');
11
11
  const unconfig = require('unconfig');
12
12
  const Debug = require('debug');
13
13
  const uniEnv = require('@uni-helper/uni-env');
14
+ const detectIndent = require('detect-indent');
15
+ const detectNewline = require('detect-newline');
14
16
  const fs = require('node:fs');
15
17
  const promises = require('node:fs/promises');
16
18
  const lodashUnified = require('lodash-unified');
@@ -26,6 +28,8 @@ const process__default = /*#__PURE__*/_interopDefaultCompat(process);
26
28
  const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
27
29
  const chokidar__default = /*#__PURE__*/_interopDefaultCompat(chokidar);
28
30
  const Debug__default = /*#__PURE__*/_interopDefaultCompat(Debug);
31
+ const detectIndent__default = /*#__PURE__*/_interopDefaultCompat(detectIndent);
32
+ const detectNewline__default = /*#__PURE__*/_interopDefaultCompat(detectNewline);
29
33
  const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
30
34
  const JSON5__default = /*#__PURE__*/_interopDefaultCompat(JSON5);
31
35
  const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
@@ -302,6 +306,13 @@ function checkPagesJsonFile(path) {
302
306
  }
303
307
  return true;
304
308
  }
309
+ function readFileSync(path) {
310
+ try {
311
+ return fs__default.readFileSync(path, { encoding: "utf-8" });
312
+ } catch {
313
+ return "";
314
+ }
315
+ }
305
316
  function writeFileSync(path, content) {
306
317
  fs__default.writeFileSync(path, content, { encoding: "utf-8" });
307
318
  }
@@ -324,6 +335,9 @@ class PageContext {
324
335
  __publicField(this, "pageMetaData", []);
325
336
  __publicField(this, "subPageMetaData", []);
326
337
  __publicField(this, "resolvedPagesJSONPath", "");
338
+ __publicField(this, "resolvedPagesJSONIndent", " ");
339
+ __publicField(this, "resolvedPagesJSONNewline", "\n");
340
+ __publicField(this, "resolvedPagesJSONEofNewline", true);
327
341
  __publicField(this, "rawOptions");
328
342
  __publicField(this, "root");
329
343
  __publicField(this, "options");
@@ -340,6 +354,10 @@ class PageContext {
340
354
  Debug__default.enable(`${prefix}${suffix}`);
341
355
  }
342
356
  this.resolvedPagesJSONPath = path__default.join(this.root, this.options.outDir, OUTPUT_NAME);
357
+ const resolvedPagesJSONContent = readFileSync(this.resolvedPagesJSONPath);
358
+ this.resolvedPagesJSONIndent = detectIndent__default(resolvedPagesJSONContent).indent || " ";
359
+ this.resolvedPagesJSONNewline = detectNewline__default(resolvedPagesJSONContent) || "\n";
360
+ this.resolvedPagesJSONEofNewline = (resolvedPagesJSONContent.at(-1) ?? "\n") === this.resolvedPagesJSONNewline;
343
361
  debug.options(this.options);
344
362
  }
345
363
  setLogger(logger) {
@@ -452,7 +470,10 @@ class PageContext {
452
470
  const generatedPageMetaData = await Promise.all(pages.map(async (page) => await this.parsePage(page)));
453
471
  const customPageMetaData = overrides || [];
454
472
  const result = customPageMetaData.length ? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData)) : generatedPageMetaData;
455
- return type === "main" ? this.setHomePage(result) : result;
473
+ const parseMeta = result.filter(
474
+ (page, index, self) => self.findLastIndex((item) => page.path === item.path) === index
475
+ );
476
+ return type === "main" ? this.setHomePage(parseMeta) : parseMeta;
456
477
  }
457
478
  /**
458
479
  * set home page
@@ -531,7 +552,11 @@ class PageContext {
531
552
  pages: this.pageMetaData,
532
553
  subPackages: this.subPageMetaData
533
554
  };
534
- const pagesJson = JSON.stringify(data, null, this.options.minify ? void 0 : 2);
555
+ const pagesJson = JSON.stringify(
556
+ data,
557
+ null,
558
+ this.options.minify ? void 0 : this.resolvedPagesJSONIndent
559
+ ) + (this.resolvedPagesJSONEofNewline ? this.resolvedPagesJSONNewline : "");
535
560
  this.generateDeclaration();
536
561
  if (lsatPagesJson === pagesJson) {
537
562
  debug.pages("PagesJson Not have change");
@@ -678,6 +703,7 @@ exports.isTargetFile = isTargetFile;
678
703
  exports.mergePageMetaDataArray = mergePageMetaDataArray;
679
704
  exports.parseCustomBlock = parseCustomBlock;
680
705
  exports.parseSFC = parseSFC;
706
+ exports.readFileSync = readFileSync;
681
707
  exports.resolveOptions = resolveOptions;
682
708
  exports.resolvePageDirs = resolvePageDirs;
683
709
  exports.useCachedPages = useCachedPages;
package/dist/index.d.cts CHANGED
@@ -2919,6 +2919,9 @@ declare class PageContext {
2919
2919
  pageMetaData: PageMetaDatum[];
2920
2920
  subPageMetaData: SubPageMetaDatum[];
2921
2921
  resolvedPagesJSONPath: string;
2922
+ resolvedPagesJSONIndent: string;
2923
+ resolvedPagesJSONNewline: string;
2924
+ resolvedPagesJSONEofNewline: boolean;
2922
2925
  rawOptions: UserOptions;
2923
2926
  root: string;
2924
2927
  options: ResolvedOptions;
@@ -3107,6 +3110,7 @@ declare const FILE_EXTENSIONS: string[];
3107
3110
  */
3108
3111
  declare function getPageFiles(path: string, options: ResolvedOptions): string[];
3109
3112
  declare function checkPagesJsonFile(path: string): boolean;
3113
+ declare function readFileSync(path: string): string;
3110
3114
  declare function writeFileSync(path: string, content: string): void;
3111
3115
 
3112
3116
  declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): ResolvedOptions;
@@ -3122,4 +3126,4 @@ declare function getRouteBlock(path: string, blockStr: SFCBlock | undefined, opt
3122
3126
 
3123
3127
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3124
3128
 
3125
- export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, MODULE_ID_VIRTUAL, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPackages, type SubPageMetaDatum, type TabBar, type TabBarIconFont, type TabBarItem, type TabBarMidButton, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
3129
+ export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, MODULE_ID_VIRTUAL, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPackages, type SubPageMetaDatum, type TabBar, type TabBarIconFont, type TabBarItem, type TabBarMidButton, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, readFileSync, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
package/dist/index.d.mts CHANGED
@@ -2919,6 +2919,9 @@ declare class PageContext {
2919
2919
  pageMetaData: PageMetaDatum[];
2920
2920
  subPageMetaData: SubPageMetaDatum[];
2921
2921
  resolvedPagesJSONPath: string;
2922
+ resolvedPagesJSONIndent: string;
2923
+ resolvedPagesJSONNewline: string;
2924
+ resolvedPagesJSONEofNewline: boolean;
2922
2925
  rawOptions: UserOptions;
2923
2926
  root: string;
2924
2927
  options: ResolvedOptions;
@@ -3107,6 +3110,7 @@ declare const FILE_EXTENSIONS: string[];
3107
3110
  */
3108
3111
  declare function getPageFiles(path: string, options: ResolvedOptions): string[];
3109
3112
  declare function checkPagesJsonFile(path: string): boolean;
3113
+ declare function readFileSync(path: string): string;
3110
3114
  declare function writeFileSync(path: string, content: string): void;
3111
3115
 
3112
3116
  declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): ResolvedOptions;
@@ -3122,4 +3126,4 @@ declare function getRouteBlock(path: string, blockStr: SFCBlock | undefined, opt
3122
3126
 
3123
3127
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3124
3128
 
3125
- export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, MODULE_ID_VIRTUAL, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPackages, type SubPageMetaDatum, type TabBar, type TabBarIconFont, type TabBarItem, type TabBarMidButton, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
3129
+ export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, MODULE_ID_VIRTUAL, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPackages, type SubPageMetaDatum, type TabBar, type TabBarIconFont, type TabBarItem, type TabBarMidButton, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, readFileSync, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
package/dist/index.d.ts CHANGED
@@ -2919,6 +2919,9 @@ declare class PageContext {
2919
2919
  pageMetaData: PageMetaDatum[];
2920
2920
  subPageMetaData: SubPageMetaDatum[];
2921
2921
  resolvedPagesJSONPath: string;
2922
+ resolvedPagesJSONIndent: string;
2923
+ resolvedPagesJSONNewline: string;
2924
+ resolvedPagesJSONEofNewline: boolean;
2922
2925
  rawOptions: UserOptions;
2923
2926
  root: string;
2924
2927
  options: ResolvedOptions;
@@ -3107,6 +3110,7 @@ declare const FILE_EXTENSIONS: string[];
3107
3110
  */
3108
3111
  declare function getPageFiles(path: string, options: ResolvedOptions): string[];
3109
3112
  declare function checkPagesJsonFile(path: string): boolean;
3113
+ declare function readFileSync(path: string): string;
3110
3114
  declare function writeFileSync(path: string, content: string): void;
3111
3115
 
3112
3116
  declare function resolveOptions(userOptions: UserOptions, viteRoot?: string): ResolvedOptions;
@@ -3122,4 +3126,4 @@ declare function getRouteBlock(path: string, blockStr: SFCBlock | undefined, opt
3122
3126
 
3123
3127
  declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
3124
3128
 
3125
- export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, MODULE_ID_VIRTUAL, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPackages, type SubPageMetaDatum, type TabBar, type TabBarIconFont, type TabBarItem, type TabBarMidButton, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
3129
+ export { type Condition, type ConditionItem, type ConfigSource, type CustomBlock, type EasyCom, FILE_EXTENSIONS, type GlobalStyle, MODULE_ID_VIRTUAL, OUTPUT_NAME, type Options, PageContext, type PageMetaDatum, type PagePath, type PagesConfig, RESOLVED_MODULE_ID_VIRTUAL, type ResolvedOptions, type SubPackage, type SubPackages, type SubPageMetaDatum, type TabBar, type TabBarIconFont, type TabBarItem, type TabBarMidButton, type TheWindow, type UniIdRouter, type UserOptions, type UserPagesConfig, VitePluginUniPages, checkPagesJsonFile, debug, type debugType, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, readFileSync, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
package/dist/index.mjs CHANGED
@@ -7,6 +7,8 @@ import chokidar from 'chokidar';
7
7
  import { loadConfig } from 'unconfig';
8
8
  import Debug from 'debug';
9
9
  import { platform } from '@uni-helper/uni-env';
10
+ import detectIndent from 'detect-indent';
11
+ import detectNewline from 'detect-newline';
10
12
  import fs, { existsSync } from 'node:fs';
11
13
  import { readFile, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
12
14
  import { groupBy } from 'lodash-unified';
@@ -287,6 +289,13 @@ function checkPagesJsonFile(path) {
287
289
  }
288
290
  return true;
289
291
  }
292
+ function readFileSync(path) {
293
+ try {
294
+ return fs.readFileSync(path, { encoding: "utf-8" });
295
+ } catch {
296
+ return "";
297
+ }
298
+ }
290
299
  function writeFileSync(path, content) {
291
300
  fs.writeFileSync(path, content, { encoding: "utf-8" });
292
301
  }
@@ -309,6 +318,9 @@ class PageContext {
309
318
  __publicField(this, "pageMetaData", []);
310
319
  __publicField(this, "subPageMetaData", []);
311
320
  __publicField(this, "resolvedPagesJSONPath", "");
321
+ __publicField(this, "resolvedPagesJSONIndent", " ");
322
+ __publicField(this, "resolvedPagesJSONNewline", "\n");
323
+ __publicField(this, "resolvedPagesJSONEofNewline", true);
312
324
  __publicField(this, "rawOptions");
313
325
  __publicField(this, "root");
314
326
  __publicField(this, "options");
@@ -325,6 +337,10 @@ class PageContext {
325
337
  Debug.enable(`${prefix}${suffix}`);
326
338
  }
327
339
  this.resolvedPagesJSONPath = path.join(this.root, this.options.outDir, OUTPUT_NAME);
340
+ const resolvedPagesJSONContent = readFileSync(this.resolvedPagesJSONPath);
341
+ this.resolvedPagesJSONIndent = detectIndent(resolvedPagesJSONContent).indent || " ";
342
+ this.resolvedPagesJSONNewline = detectNewline(resolvedPagesJSONContent) || "\n";
343
+ this.resolvedPagesJSONEofNewline = (resolvedPagesJSONContent.at(-1) ?? "\n") === this.resolvedPagesJSONNewline;
328
344
  debug.options(this.options);
329
345
  }
330
346
  setLogger(logger) {
@@ -437,7 +453,10 @@ class PageContext {
437
453
  const generatedPageMetaData = await Promise.all(pages.map(async (page) => await this.parsePage(page)));
438
454
  const customPageMetaData = overrides || [];
439
455
  const result = customPageMetaData.length ? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData)) : generatedPageMetaData;
440
- return type === "main" ? this.setHomePage(result) : result;
456
+ const parseMeta = result.filter(
457
+ (page, index, self) => self.findLastIndex((item) => page.path === item.path) === index
458
+ );
459
+ return type === "main" ? this.setHomePage(parseMeta) : parseMeta;
441
460
  }
442
461
  /**
443
462
  * set home page
@@ -516,7 +535,11 @@ class PageContext {
516
535
  pages: this.pageMetaData,
517
536
  subPackages: this.subPageMetaData
518
537
  };
519
- const pagesJson = JSON.stringify(data, null, this.options.minify ? void 0 : 2);
538
+ const pagesJson = JSON.stringify(
539
+ data,
540
+ null,
541
+ this.options.minify ? void 0 : this.resolvedPagesJSONIndent
542
+ ) + (this.resolvedPagesJSONEofNewline ? this.resolvedPagesJSONNewline : "");
520
543
  this.generateDeclaration();
521
544
  if (lsatPagesJson === pagesJson) {
522
545
  debug.pages("PagesJson Not have change");
@@ -644,4 +667,4 @@ function VitePluginUniPages(userOptions = {}) {
644
667
  };
645
668
  }
646
669
 
647
- export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
670
+ export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, checkPagesJsonFile, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCustomBlock, parseSFC, readFileSync, resolveOptions, resolvePageDirs, useCachedPages, writeFileSync };
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.2.23",
4
+ "version": "0.2.25",
5
5
  "description": "File system based routing for uni-app applications using Vite",
6
6
  "author": "KeJun",
7
7
  "license": "MIT",
@@ -36,21 +36,23 @@
36
36
  "dist"
37
37
  ],
38
38
  "dependencies": {
39
- "@uni-helper/uni-env": "^0.1.1",
40
- "@vue/compiler-sfc": "^3.4.27",
39
+ "@uni-helper/uni-env": "^0.1.3",
40
+ "@vue/compiler-sfc": "^3.4.31",
41
41
  "chokidar": "^3.6.0",
42
- "debug": "^4.3.4",
42
+ "debug": "^4.3.5",
43
+ "detect-indent": "^6.1.0",
44
+ "detect-newline": "^3.1.0",
43
45
  "fast-glob": "^3.3.2",
44
46
  "json5": "^2.2.3",
45
47
  "lodash-unified": "^1.0.3",
46
48
  "magic-string": "^0.30.10",
47
- "unconfig": "^0.3.13",
48
- "yaml": "^2.4.2"
49
+ "unconfig": "^0.4.5",
50
+ "yaml": "^2.4.5"
49
51
  },
50
52
  "devDependencies": {
51
- "@antfu/utils": "^0.7.8",
53
+ "@antfu/utils": "^0.7.10",
52
54
  "@types/debug": "^4.1.12",
53
- "@types/node": "^20.12.11"
55
+ "@types/node": "^20.14.10"
54
56
  },
55
57
  "scripts": {
56
58
  "build": "unbuild",