@uni-helper/vite-plugin-uni-pages 0.2.23 → 0.2.24
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 +24 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.mjs +22 -2
- package/package.json +8 -6
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) {
|
|
@@ -531,7 +549,11 @@ class PageContext {
|
|
|
531
549
|
pages: this.pageMetaData,
|
|
532
550
|
subPackages: this.subPageMetaData
|
|
533
551
|
};
|
|
534
|
-
const pagesJson = JSON.stringify(
|
|
552
|
+
const pagesJson = JSON.stringify(
|
|
553
|
+
data,
|
|
554
|
+
null,
|
|
555
|
+
this.options.minify ? void 0 : this.resolvedPagesJSONIndent
|
|
556
|
+
) + (this.resolvedPagesJSONEofNewline ? this.resolvedPagesJSONNewline : "");
|
|
535
557
|
this.generateDeclaration();
|
|
536
558
|
if (lsatPagesJson === pagesJson) {
|
|
537
559
|
debug.pages("PagesJson Not have change");
|
|
@@ -678,6 +700,7 @@ exports.isTargetFile = isTargetFile;
|
|
|
678
700
|
exports.mergePageMetaDataArray = mergePageMetaDataArray;
|
|
679
701
|
exports.parseCustomBlock = parseCustomBlock;
|
|
680
702
|
exports.parseSFC = parseSFC;
|
|
703
|
+
exports.readFileSync = readFileSync;
|
|
681
704
|
exports.resolveOptions = resolveOptions;
|
|
682
705
|
exports.resolvePageDirs = resolvePageDirs;
|
|
683
706
|
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) {
|
|
@@ -516,7 +532,11 @@ class PageContext {
|
|
|
516
532
|
pages: this.pageMetaData,
|
|
517
533
|
subPackages: this.subPageMetaData
|
|
518
534
|
};
|
|
519
|
-
const pagesJson = JSON.stringify(
|
|
535
|
+
const pagesJson = JSON.stringify(
|
|
536
|
+
data,
|
|
537
|
+
null,
|
|
538
|
+
this.options.minify ? void 0 : this.resolvedPagesJSONIndent
|
|
539
|
+
) + (this.resolvedPagesJSONEofNewline ? this.resolvedPagesJSONNewline : "");
|
|
520
540
|
this.generateDeclaration();
|
|
521
541
|
if (lsatPagesJson === pagesJson) {
|
|
522
542
|
debug.pages("PagesJson Not have change");
|
|
@@ -644,4 +664,4 @@ function VitePluginUniPages(userOptions = {}) {
|
|
|
644
664
|
};
|
|
645
665
|
}
|
|
646
666
|
|
|
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 };
|
|
667
|
+
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.
|
|
4
|
+
"version": "0.2.24",
|
|
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.
|
|
40
|
-
"@vue/compiler-sfc": "^3.4.
|
|
39
|
+
"@uni-helper/uni-env": "^0.1.3",
|
|
40
|
+
"@vue/compiler-sfc": "^3.4.30",
|
|
41
41
|
"chokidar": "^3.6.0",
|
|
42
|
-
"debug": "^4.3.
|
|
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
49
|
"unconfig": "^0.3.13",
|
|
48
|
-
"yaml": "^2.4.
|
|
50
|
+
"yaml": "^2.4.5"
|
|
49
51
|
},
|
|
50
52
|
"devDependencies": {
|
|
51
53
|
"@antfu/utils": "^0.7.8",
|
|
52
54
|
"@types/debug": "^4.1.12",
|
|
53
|
-
"@types/node": "^20.
|
|
55
|
+
"@types/node": "^20.14.8"
|
|
54
56
|
},
|
|
55
57
|
"scripts": {
|
|
56
58
|
"build": "unbuild",
|