@uni-helper/vite-plugin-uni-pages 0.4.4 → 0.4.7
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 +2 -1
- package/dist/index.cjs +10 -3
- package/dist/index.d.mts +9 -9
- package/dist/index.mjs +20 -13
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -253,7 +253,8 @@ export default defineConfig({
|
|
|
253
253
|
本插件默认会:
|
|
254
254
|
|
|
255
255
|
- 通过文件锁串行化对 `pages.json` 的「读取已有内容 → 合并当前平台配置 → 写回」整个流程,避免并发写入互相覆盖;
|
|
256
|
-
- 保留其他平台已经写入的条件编译块(`#ifdef H5` / `#ifndef MP-WEIXIN`
|
|
256
|
+
- 保留其他平台已经写入的条件编译块(`#ifdef H5` / `#ifndef MP-WEIXIN` 等),只更新当前平台对应的条目;
|
|
257
|
+
- 对同一 `path`(或 tabBar 的 `pagePath`)的条目按内容去重:内容相同的条目会合并为一条并叠加平台标识(如 `H5 || MP-WEIXIN`),不会因为先后跑过多个平台而产生重复路由。
|
|
257
258
|
|
|
258
259
|
这样每个终端都能保留各自的平台配置。条件编译注释基于 `comment-json` 写入,最终 `pages.json` 同时包含所有平台的分支。
|
|
259
260
|
|
package/dist/index.cjs
CHANGED
|
@@ -1207,6 +1207,13 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1207
1207
|
});
|
|
1208
1208
|
tmpMap.set(uniqueKey, existing);
|
|
1209
1209
|
}
|
|
1210
|
+
const stringifyForCompare = (val) => {
|
|
1211
|
+
if (val && typeof val === "object" && "type" in val) {
|
|
1212
|
+
const { type: _type, ...rest } = val;
|
|
1213
|
+
return JSON.stringify(rest);
|
|
1214
|
+
}
|
|
1215
|
+
return JSON.stringify(val);
|
|
1216
|
+
};
|
|
1210
1217
|
for (const item of items) {
|
|
1211
1218
|
const newItem = item;
|
|
1212
1219
|
const uniqueKey = item[uniqueKeyName];
|
|
@@ -1214,14 +1221,14 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1214
1221
|
if (!tmpMap.has(uniqueKey)) {
|
|
1215
1222
|
tmpMap.set(uniqueKey, [{
|
|
1216
1223
|
item: newItem,
|
|
1217
|
-
itemStr:
|
|
1224
|
+
itemStr: stringifyForCompare(newItem),
|
|
1218
1225
|
platforms: [currentPlatform],
|
|
1219
1226
|
platformStr: currentPlatform
|
|
1220
1227
|
}]);
|
|
1221
1228
|
continue;
|
|
1222
1229
|
}
|
|
1223
1230
|
const existing = tmpMap.get(uniqueKey);
|
|
1224
|
-
const newItemStr =
|
|
1231
|
+
const newItemStr = stringifyForCompare(newItem);
|
|
1225
1232
|
const equalObj = existing.find((val) => val.itemStr === newItemStr);
|
|
1226
1233
|
if (equalObj) {
|
|
1227
1234
|
equalObj.platforms.push(currentPlatform);
|
|
@@ -1229,7 +1236,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1229
1236
|
equalObj.platformStr = equalObj.platforms.join(" || ");
|
|
1230
1237
|
} else existing.push({
|
|
1231
1238
|
item: newItem,
|
|
1232
|
-
itemStr:
|
|
1239
|
+
itemStr: stringifyForCompare(newItem),
|
|
1233
1240
|
platforms: [currentPlatform],
|
|
1234
1241
|
platformStr: currentPlatform
|
|
1235
1242
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ import { createRequire } from "node:module";
|
|
|
2
2
|
import { FSWatcher } from "chokidar";
|
|
3
3
|
import { Logger, Plugin, ViteDevServer } from "vite";
|
|
4
4
|
import fs from "node:fs";
|
|
5
|
-
import
|
|
5
|
+
import Debug from "debug";
|
|
6
6
|
import { LoadConfigSource } from "unconfig";
|
|
7
7
|
import babelGenerator from "@babel/generator";
|
|
8
8
|
import * as t from "@babel/types";
|
|
@@ -286,14 +286,14 @@ declare function invalidatePagesModule(server: ViteDevServer): void;
|
|
|
286
286
|
* Enable via environment variable DEBUG=vite-plugin-uni-pages:*
|
|
287
287
|
*/
|
|
288
288
|
declare const debug: {
|
|
289
|
-
/** HMR related logs */hmr:
|
|
290
|
-
options:
|
|
291
|
-
pages:
|
|
292
|
-
subPages:
|
|
293
|
-
error:
|
|
294
|
-
cache:
|
|
295
|
-
declaration:
|
|
296
|
-
definePage:
|
|
289
|
+
/** HMR related logs */hmr: Debug.Debugger; /** Configuration options related logs */
|
|
290
|
+
options: Debug.Debugger; /** Main package page scanning logs */
|
|
291
|
+
pages: Debug.Debugger; /** Sub-package page scanning logs */
|
|
292
|
+
subPages: Debug.Debugger; /** Error logs */
|
|
293
|
+
error: Debug.Debugger; /** Cache related logs */
|
|
294
|
+
cache: Debug.Debugger; /** Declaration file generation logs */
|
|
295
|
+
declaration: Debug.Debugger; /** definePage macro parsing logs */
|
|
296
|
+
definePage: Debug.Debugger;
|
|
297
297
|
};
|
|
298
298
|
/**
|
|
299
299
|
* Convert file extensions array to glob pattern
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { createLogger, normalizePath } from "vite";
|
|
|
8
8
|
import fs, { existsSync } from "node:fs";
|
|
9
9
|
import { platform } from "@uni-helper/uni-env";
|
|
10
10
|
import { CommentArray, parse, stringify } from "comment-json";
|
|
11
|
-
import
|
|
11
|
+
import Debug from "debug";
|
|
12
12
|
import detectIndent from "detect-indent";
|
|
13
13
|
import detectNewline from "detect-newline";
|
|
14
14
|
import { loadConfig } from "unconfig";
|
|
@@ -135,21 +135,21 @@ function invalidatePagesModule(server) {
|
|
|
135
135
|
*/
|
|
136
136
|
const debug = {
|
|
137
137
|
/** HMR related logs */
|
|
138
|
-
hmr:
|
|
138
|
+
hmr: Debug("vite-plugin-uni-pages:hmr"),
|
|
139
139
|
/** Configuration options related logs */
|
|
140
|
-
options:
|
|
140
|
+
options: Debug("vite-plugin-uni-pages:options"),
|
|
141
141
|
/** Main package page scanning logs */
|
|
142
|
-
pages:
|
|
142
|
+
pages: Debug("vite-plugin-uni-pages:pages"),
|
|
143
143
|
/** Sub-package page scanning logs */
|
|
144
|
-
subPages:
|
|
144
|
+
subPages: Debug("vite-plugin-uni-pages:subPages"),
|
|
145
145
|
/** Error logs */
|
|
146
|
-
error:
|
|
146
|
+
error: Debug("vite-plugin-uni-pages:error"),
|
|
147
147
|
/** Cache related logs */
|
|
148
|
-
cache:
|
|
148
|
+
cache: Debug("vite-plugin-uni-pages:cache"),
|
|
149
149
|
/** Declaration file generation logs */
|
|
150
|
-
declaration:
|
|
150
|
+
declaration: Debug("vite-plugin-uni-pages:declaration"),
|
|
151
151
|
/** definePage macro parsing logs */
|
|
152
|
-
definePage:
|
|
152
|
+
definePage: Debug("vite-plugin-uni-pages:definePage")
|
|
153
153
|
};
|
|
154
154
|
/**
|
|
155
155
|
* Convert file extensions array to glob pattern
|
|
@@ -712,7 +712,7 @@ var PageContext = class {
|
|
|
712
712
|
if (debugOption) {
|
|
713
713
|
const prefix = "vite-plugin-uni-pages:";
|
|
714
714
|
const suffix = typeof debugOption === "boolean" ? "*" : debugOption;
|
|
715
|
-
|
|
715
|
+
Debug.enable(`${prefix}${suffix}`);
|
|
716
716
|
}
|
|
717
717
|
this.resolvedPagesJSONPath = path.join(this.root, this.options.outDir, OUTPUT_NAME);
|
|
718
718
|
debug.options(this.options);
|
|
@@ -1166,6 +1166,13 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1166
1166
|
});
|
|
1167
1167
|
tmpMap.set(uniqueKey, existing);
|
|
1168
1168
|
}
|
|
1169
|
+
const stringifyForCompare = (val) => {
|
|
1170
|
+
if (val && typeof val === "object" && "type" in val) {
|
|
1171
|
+
const { type: _type, ...rest } = val;
|
|
1172
|
+
return JSON.stringify(rest);
|
|
1173
|
+
}
|
|
1174
|
+
return JSON.stringify(val);
|
|
1175
|
+
};
|
|
1169
1176
|
for (const item of items) {
|
|
1170
1177
|
const newItem = item;
|
|
1171
1178
|
const uniqueKey = item[uniqueKeyName];
|
|
@@ -1173,14 +1180,14 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1173
1180
|
if (!tmpMap.has(uniqueKey)) {
|
|
1174
1181
|
tmpMap.set(uniqueKey, [{
|
|
1175
1182
|
item: newItem,
|
|
1176
|
-
itemStr:
|
|
1183
|
+
itemStr: stringifyForCompare(newItem),
|
|
1177
1184
|
platforms: [currentPlatform],
|
|
1178
1185
|
platformStr: currentPlatform
|
|
1179
1186
|
}]);
|
|
1180
1187
|
continue;
|
|
1181
1188
|
}
|
|
1182
1189
|
const existing = tmpMap.get(uniqueKey);
|
|
1183
|
-
const newItemStr =
|
|
1190
|
+
const newItemStr = stringifyForCompare(newItem);
|
|
1184
1191
|
const equalObj = existing.find((val) => val.itemStr === newItemStr);
|
|
1185
1192
|
if (equalObj) {
|
|
1186
1193
|
equalObj.platforms.push(currentPlatform);
|
|
@@ -1188,7 +1195,7 @@ function mergePlatformItems(source, currentPlatform, items, uniqueKeyName) {
|
|
|
1188
1195
|
equalObj.platformStr = equalObj.platforms.join(" || ");
|
|
1189
1196
|
} else existing.push({
|
|
1190
1197
|
item: newItem,
|
|
1191
|
-
itemStr:
|
|
1198
|
+
itemStr: stringifyForCompare(newItem),
|
|
1192
1199
|
platforms: [currentPlatform],
|
|
1193
1200
|
platformStr: currentPlatform
|
|
1194
1201
|
});
|
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.4.
|
|
4
|
+
"version": "0.4.7",
|
|
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/generator": "^7.29.7",
|
|
56
56
|
"@babel/types": "^7.29.7",
|
|
57
57
|
"@types/proper-lockfile": "^4.1.4",
|
|
58
|
-
"@uni-helper/uni-env": "^0.
|
|
58
|
+
"@uni-helper/uni-env": "^0.3.1",
|
|
59
59
|
"@vue/compiler-sfc": "~3.4.38",
|
|
60
60
|
"ast-kit": "^1.4.3",
|
|
61
61
|
"chokidar": "^3.6.0",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"unconfig": "^7.5.0",
|
|
73
73
|
"write-file-atomic": "^7.0.1",
|
|
74
74
|
"yaml": "^2.9.0",
|
|
75
|
-
"@uni-helper/uni-pages-types": "0.4.
|
|
75
|
+
"@uni-helper/uni-pages-types": "0.4.7"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"@antfu/utils": "^9.3.0",
|