@uni-helper/vite-plugin-uni-pages 0.3.0 → 0.3.2
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/README.md +1 -1
- package/dist/index.cjs +22 -9
- package/dist/index.d.cts +3 -2
- package/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.mjs +24 -11
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ export interface Options {
|
|
|
112
112
|
* Set the default route block parser, or use `<route lang="xxx">` in SFC route block
|
|
113
113
|
* @default 'json5'
|
|
114
114
|
*/
|
|
115
|
-
routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml'
|
|
115
|
+
routeBlockLang: 'json5' | 'jsonc' | 'json' | 'yaml' | 'yml'
|
|
116
116
|
|
|
117
117
|
onBeforeLoadUserConfig: (ctx: PageContext) => void
|
|
118
118
|
onAfterLoadUserConfig: (ctx: PageContext) => void
|
package/dist/index.cjs
CHANGED
|
@@ -13,6 +13,7 @@ const Debug = require('debug');
|
|
|
13
13
|
const uniEnv = require('@uni-helper/uni-env');
|
|
14
14
|
const detectIndent = require('detect-indent');
|
|
15
15
|
const detectNewline = require('detect-newline');
|
|
16
|
+
const commentJson = require('comment-json');
|
|
16
17
|
const fs = require('node:fs');
|
|
17
18
|
const promises = require('node:fs/promises');
|
|
18
19
|
const groupBy = require('lodash.groupby');
|
|
@@ -111,12 +112,21 @@ function parseCustomBlock(block, filePath, options) {
|
|
|
111
112
|
};
|
|
112
113
|
let content;
|
|
113
114
|
debug.routeBlock(`use ${lang} parser`);
|
|
114
|
-
if (lang === "json5"
|
|
115
|
+
if (lang === "json5") {
|
|
115
116
|
try {
|
|
116
117
|
content = JSON5__default.parse(block.content);
|
|
117
118
|
} catch (err) {
|
|
118
119
|
throw new Error(
|
|
119
120
|
`Invalid JSON5 format of <${block.type}> content in ${filePath}
|
|
121
|
+
${err.message}`
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
} else if (lang === "jsonc") {
|
|
125
|
+
try {
|
|
126
|
+
content = commentJson.parse(block.content);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
`Invalid JSONC format of <${block.type}> content in ${filePath}
|
|
120
130
|
${err.message}`
|
|
121
131
|
);
|
|
122
132
|
}
|
|
@@ -206,12 +216,12 @@ function useCachedPages() {
|
|
|
206
216
|
};
|
|
207
217
|
}
|
|
208
218
|
function setCache(filePath, routeBlock) {
|
|
209
|
-
pages.set(filePath,
|
|
219
|
+
pages.set(filePath, commentJson.stringify(parseData(routeBlock)));
|
|
210
220
|
}
|
|
211
221
|
async function hasChanged(filePath, routeBlock) {
|
|
212
222
|
if (!routeBlock)
|
|
213
223
|
routeBlock = await getRouteSfcBlock(vite.normalizePath(filePath));
|
|
214
|
-
return !pages.has(filePath) ||
|
|
224
|
+
return !pages.has(filePath) || commentJson.stringify(parseData(routeBlock)) !== pages.get(filePath);
|
|
215
225
|
}
|
|
216
226
|
return {
|
|
217
227
|
setCache,
|
|
@@ -302,7 +312,7 @@ function getPageFiles(path, options) {
|
|
|
302
312
|
}
|
|
303
313
|
function checkPagesJsonFile(path) {
|
|
304
314
|
if (!fs__default.existsSync(path)) {
|
|
305
|
-
writeFileSync(path,
|
|
315
|
+
writeFileSync(path, commentJson.stringify({ pages: [{ path: "" }] }, null, 2));
|
|
306
316
|
return false;
|
|
307
317
|
}
|
|
308
318
|
return true;
|
|
@@ -457,7 +467,7 @@ class PageContext {
|
|
|
457
467
|
type: routeBlock?.attr.type ?? "page"
|
|
458
468
|
};
|
|
459
469
|
if (routeBlock)
|
|
460
|
-
|
|
470
|
+
commentJson.assign(pageMetaDatum, routeBlock.content);
|
|
461
471
|
return pageMetaDatum;
|
|
462
472
|
}
|
|
463
473
|
/**
|
|
@@ -544,7 +554,10 @@ class PageContext {
|
|
|
544
554
|
await this.mergeSubPageMetaData();
|
|
545
555
|
this.options.onAfterMergePageMetaData(this);
|
|
546
556
|
const pagesMap = /* @__PURE__ */ new Map();
|
|
547
|
-
const pages = this.withUniPlatform ? this.pageMetaData.filter((v) => !/\..*$/.test(v.path) || v.path.includes(uniEnv.platform)).map((v) =>
|
|
557
|
+
const pages = this.withUniPlatform ? this.pageMetaData.filter((v) => !/\..*$/.test(v.path) || v.path.includes(uniEnv.platform)).map((v) => {
|
|
558
|
+
v.path = v.path.replace(/\..*$/, "");
|
|
559
|
+
return v;
|
|
560
|
+
}) : this.pageMetaData;
|
|
548
561
|
pages.forEach((v) => pagesMap.set(v.path, v));
|
|
549
562
|
this.pageMetaData = [...pagesMap.values()];
|
|
550
563
|
this.options.onBeforeWriteFile(this);
|
|
@@ -553,7 +566,7 @@ class PageContext {
|
|
|
553
566
|
pages: this.pageMetaData,
|
|
554
567
|
subPackages: this.subPageMetaData
|
|
555
568
|
};
|
|
556
|
-
const pagesJson =
|
|
569
|
+
const pagesJson = commentJson.stringify(
|
|
557
570
|
data,
|
|
558
571
|
null,
|
|
559
572
|
this.options.minify ? void 0 : this.resolvedPagesJSONIndent
|
|
@@ -574,10 +587,10 @@ class PageContext {
|
|
|
574
587
|
return [pages, subPackages].join("\n");
|
|
575
588
|
}
|
|
576
589
|
resolveRoutes() {
|
|
577
|
-
return
|
|
590
|
+
return commentJson.stringify(this.pageMetaData, null, 2);
|
|
578
591
|
}
|
|
579
592
|
resolveSubRoutes() {
|
|
580
|
-
return
|
|
593
|
+
return commentJson.stringify(this.subPageMetaData, null, 2);
|
|
581
594
|
}
|
|
582
595
|
generateDeclaration() {
|
|
583
596
|
if (!this.options.dts)
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger, ViteDevServer, Plugin } from 'vite';
|
|
2
2
|
import { LoadConfigSource } from 'unconfig';
|
|
3
|
+
import { CommentJSONValue } from 'comment-json';
|
|
3
4
|
import { FSWatcher } from 'chokidar';
|
|
4
5
|
import Debug from 'debug';
|
|
5
6
|
import { SFCBlock, SFCDescriptor } from '@vue/compiler-sfc';
|
|
@@ -2995,7 +2996,7 @@ declare function useCachedPages(): {
|
|
|
2995
2996
|
|
|
2996
2997
|
interface CustomBlock {
|
|
2997
2998
|
attr: Record<string, any>;
|
|
2998
|
-
content: Record<string, any
|
|
2999
|
+
content: Record<string, any> | CommentJSONValue;
|
|
2999
3000
|
}
|
|
3000
3001
|
type debugType = keyof typeof debug;
|
|
3001
3002
|
type ConfigSource = string | LoadConfigSource<PagesConfig> | LoadConfigSource<PagesConfig>[];
|
|
@@ -3048,7 +3049,7 @@ interface Options {
|
|
|
3048
3049
|
* Set the default route block parser, or use `<route lang="xxx">` in SFC route block
|
|
3049
3050
|
* @default 'json5'
|
|
3050
3051
|
*/
|
|
3051
|
-
routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml';
|
|
3052
|
+
routeBlockLang: 'json5' | 'jsonc' | 'json' | 'yaml' | 'yml';
|
|
3052
3053
|
/**
|
|
3053
3054
|
* minify the `pages.json`
|
|
3054
3055
|
* @default false
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger, ViteDevServer, Plugin } from 'vite';
|
|
2
2
|
import { LoadConfigSource } from 'unconfig';
|
|
3
|
+
import { CommentJSONValue } from 'comment-json';
|
|
3
4
|
import { FSWatcher } from 'chokidar';
|
|
4
5
|
import Debug from 'debug';
|
|
5
6
|
import { SFCBlock, SFCDescriptor } from '@vue/compiler-sfc';
|
|
@@ -2995,7 +2996,7 @@ declare function useCachedPages(): {
|
|
|
2995
2996
|
|
|
2996
2997
|
interface CustomBlock {
|
|
2997
2998
|
attr: Record<string, any>;
|
|
2998
|
-
content: Record<string, any
|
|
2999
|
+
content: Record<string, any> | CommentJSONValue;
|
|
2999
3000
|
}
|
|
3000
3001
|
type debugType = keyof typeof debug;
|
|
3001
3002
|
type ConfigSource = string | LoadConfigSource<PagesConfig> | LoadConfigSource<PagesConfig>[];
|
|
@@ -3048,7 +3049,7 @@ interface Options {
|
|
|
3048
3049
|
* Set the default route block parser, or use `<route lang="xxx">` in SFC route block
|
|
3049
3050
|
* @default 'json5'
|
|
3050
3051
|
*/
|
|
3051
|
-
routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml';
|
|
3052
|
+
routeBlockLang: 'json5' | 'jsonc' | 'json' | 'yaml' | 'yml';
|
|
3052
3053
|
/**
|
|
3053
3054
|
* minify the `pages.json`
|
|
3054
3055
|
* @default false
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Logger, ViteDevServer, Plugin } from 'vite';
|
|
2
2
|
import { LoadConfigSource } from 'unconfig';
|
|
3
|
+
import { CommentJSONValue } from 'comment-json';
|
|
3
4
|
import { FSWatcher } from 'chokidar';
|
|
4
5
|
import Debug from 'debug';
|
|
5
6
|
import { SFCBlock, SFCDescriptor } from '@vue/compiler-sfc';
|
|
@@ -2995,7 +2996,7 @@ declare function useCachedPages(): {
|
|
|
2995
2996
|
|
|
2996
2997
|
interface CustomBlock {
|
|
2997
2998
|
attr: Record<string, any>;
|
|
2998
|
-
content: Record<string, any
|
|
2999
|
+
content: Record<string, any> | CommentJSONValue;
|
|
2999
3000
|
}
|
|
3000
3001
|
type debugType = keyof typeof debug;
|
|
3001
3002
|
type ConfigSource = string | LoadConfigSource<PagesConfig> | LoadConfigSource<PagesConfig>[];
|
|
@@ -3048,7 +3049,7 @@ interface Options {
|
|
|
3048
3049
|
* Set the default route block parser, or use `<route lang="xxx">` in SFC route block
|
|
3049
3050
|
* @default 'json5'
|
|
3050
3051
|
*/
|
|
3051
|
-
routeBlockLang: 'json5' | 'json' | 'yaml' | 'yml';
|
|
3052
|
+
routeBlockLang: 'json5' | 'jsonc' | 'json' | 'yaml' | 'yml';
|
|
3052
3053
|
/**
|
|
3053
3054
|
* minify the `pages.json`
|
|
3054
3055
|
* @default false
|
package/dist/index.mjs
CHANGED
|
@@ -9,11 +9,12 @@ import Debug from 'debug';
|
|
|
9
9
|
import { platform } from '@uni-helper/uni-env';
|
|
10
10
|
import detectIndent from 'detect-indent';
|
|
11
11
|
import detectNewline from 'detect-newline';
|
|
12
|
+
import { parse as parse$1, stringify, assign } from 'comment-json';
|
|
12
13
|
import fs, { existsSync } from 'node:fs';
|
|
13
14
|
import { readFile, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
|
|
14
15
|
import groupBy from 'lodash.groupby';
|
|
15
16
|
import JSON5 from 'json5';
|
|
16
|
-
import { parse as parse$
|
|
17
|
+
import { parse as parse$2 } from 'yaml';
|
|
17
18
|
import { parse } from '@vue/compiler-sfc';
|
|
18
19
|
import fg from 'fast-glob';
|
|
19
20
|
|
|
@@ -93,12 +94,21 @@ function parseCustomBlock(block, filePath, options) {
|
|
|
93
94
|
};
|
|
94
95
|
let content;
|
|
95
96
|
debug.routeBlock(`use ${lang} parser`);
|
|
96
|
-
if (lang === "json5"
|
|
97
|
+
if (lang === "json5") {
|
|
97
98
|
try {
|
|
98
99
|
content = JSON5.parse(block.content);
|
|
99
100
|
} catch (err) {
|
|
100
101
|
throw new Error(
|
|
101
102
|
`Invalid JSON5 format of <${block.type}> content in ${filePath}
|
|
103
|
+
${err.message}`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
} else if (lang === "jsonc") {
|
|
107
|
+
try {
|
|
108
|
+
content = parse$1(block.content);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`Invalid JSONC format of <${block.type}> content in ${filePath}
|
|
102
112
|
${err.message}`
|
|
103
113
|
);
|
|
104
114
|
}
|
|
@@ -113,7 +123,7 @@ ${err.message}`
|
|
|
113
123
|
}
|
|
114
124
|
} else if (lang === "yaml" || lang === "yml") {
|
|
115
125
|
try {
|
|
116
|
-
content = parse$
|
|
126
|
+
content = parse$2(block.content);
|
|
117
127
|
} catch (err) {
|
|
118
128
|
throw new Error(
|
|
119
129
|
`Invalid YAML format of <${block.type}> content in ${filePath}
|
|
@@ -188,12 +198,12 @@ function useCachedPages() {
|
|
|
188
198
|
};
|
|
189
199
|
}
|
|
190
200
|
function setCache(filePath, routeBlock) {
|
|
191
|
-
pages.set(filePath,
|
|
201
|
+
pages.set(filePath, stringify(parseData(routeBlock)));
|
|
192
202
|
}
|
|
193
203
|
async function hasChanged(filePath, routeBlock) {
|
|
194
204
|
if (!routeBlock)
|
|
195
205
|
routeBlock = await getRouteSfcBlock(normalizePath(filePath));
|
|
196
|
-
return !pages.has(filePath) ||
|
|
206
|
+
return !pages.has(filePath) || stringify(parseData(routeBlock)) !== pages.get(filePath);
|
|
197
207
|
}
|
|
198
208
|
return {
|
|
199
209
|
setCache,
|
|
@@ -284,7 +294,7 @@ function getPageFiles(path, options) {
|
|
|
284
294
|
}
|
|
285
295
|
function checkPagesJsonFile(path) {
|
|
286
296
|
if (!fs.existsSync(path)) {
|
|
287
|
-
writeFileSync(path,
|
|
297
|
+
writeFileSync(path, stringify({ pages: [{ path: "" }] }, null, 2));
|
|
288
298
|
return false;
|
|
289
299
|
}
|
|
290
300
|
return true;
|
|
@@ -439,7 +449,7 @@ class PageContext {
|
|
|
439
449
|
type: routeBlock?.attr.type ?? "page"
|
|
440
450
|
};
|
|
441
451
|
if (routeBlock)
|
|
442
|
-
|
|
452
|
+
assign(pageMetaDatum, routeBlock.content);
|
|
443
453
|
return pageMetaDatum;
|
|
444
454
|
}
|
|
445
455
|
/**
|
|
@@ -526,7 +536,10 @@ class PageContext {
|
|
|
526
536
|
await this.mergeSubPageMetaData();
|
|
527
537
|
this.options.onAfterMergePageMetaData(this);
|
|
528
538
|
const pagesMap = /* @__PURE__ */ new Map();
|
|
529
|
-
const pages = this.withUniPlatform ? this.pageMetaData.filter((v) => !/\..*$/.test(v.path) || v.path.includes(platform)).map((v) =>
|
|
539
|
+
const pages = this.withUniPlatform ? this.pageMetaData.filter((v) => !/\..*$/.test(v.path) || v.path.includes(platform)).map((v) => {
|
|
540
|
+
v.path = v.path.replace(/\..*$/, "");
|
|
541
|
+
return v;
|
|
542
|
+
}) : this.pageMetaData;
|
|
530
543
|
pages.forEach((v) => pagesMap.set(v.path, v));
|
|
531
544
|
this.pageMetaData = [...pagesMap.values()];
|
|
532
545
|
this.options.onBeforeWriteFile(this);
|
|
@@ -535,7 +548,7 @@ class PageContext {
|
|
|
535
548
|
pages: this.pageMetaData,
|
|
536
549
|
subPackages: this.subPageMetaData
|
|
537
550
|
};
|
|
538
|
-
const pagesJson =
|
|
551
|
+
const pagesJson = stringify(
|
|
539
552
|
data,
|
|
540
553
|
null,
|
|
541
554
|
this.options.minify ? void 0 : this.resolvedPagesJSONIndent
|
|
@@ -556,10 +569,10 @@ class PageContext {
|
|
|
556
569
|
return [pages, subPackages].join("\n");
|
|
557
570
|
}
|
|
558
571
|
resolveRoutes() {
|
|
559
|
-
return
|
|
572
|
+
return stringify(this.pageMetaData, null, 2);
|
|
560
573
|
}
|
|
561
574
|
resolveSubRoutes() {
|
|
562
|
-
return
|
|
575
|
+
return stringify(this.subPageMetaData, null, 2);
|
|
563
576
|
}
|
|
564
577
|
generateDeclaration() {
|
|
565
578
|
if (!this.options.dts)
|
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.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"description": "File system based routing for uni-app applications using Vite",
|
|
6
6
|
"author": "KeJun",
|
|
7
7
|
"maintainers": [
|
|
@@ -61,7 +61,8 @@
|
|
|
61
61
|
"lodash.groupby": "^4.6.0",
|
|
62
62
|
"magic-string": "^0.30.11",
|
|
63
63
|
"unconfig": "^7.3.2",
|
|
64
|
-
"yaml": "^2.5.0"
|
|
64
|
+
"yaml": "^2.5.0",
|
|
65
|
+
"comment-json": "^4.2.5"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
68
|
"@antfu/utils": "^0.7.10",
|