@uni-helper/vite-plugin-uni-pages 0.3.17 → 0.3.19
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 +47 -48
- package/dist/index.d.cts +3 -4
- package/dist/index.d.mts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.mjs +46 -47
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -15,10 +15,10 @@ const commentJson = require('comment-json');
|
|
|
15
15
|
const Debug = require('debug');
|
|
16
16
|
const detectIndent = require('detect-indent');
|
|
17
17
|
const detectNewline = require('detect-newline');
|
|
18
|
-
const lockfile = require('proper-lockfile');
|
|
19
18
|
const unconfig = require('unconfig');
|
|
20
19
|
const promises = require('node:fs/promises');
|
|
21
20
|
const fg = require('fast-glob');
|
|
21
|
+
const lockfile = require('proper-lockfile');
|
|
22
22
|
const node_module = require('node:module');
|
|
23
23
|
const vm = require('node:vm');
|
|
24
24
|
const babelGenerator = require('@babel/generator');
|
|
@@ -51,8 +51,8 @@ const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
|
51
51
|
const Debug__default = /*#__PURE__*/_interopDefaultCompat(Debug);
|
|
52
52
|
const detectIndent__default = /*#__PURE__*/_interopDefaultCompat(detectIndent);
|
|
53
53
|
const detectNewline__default = /*#__PURE__*/_interopDefaultCompat(detectNewline);
|
|
54
|
-
const lockfile__default = /*#__PURE__*/_interopDefaultCompat(lockfile);
|
|
55
54
|
const fg__default = /*#__PURE__*/_interopDefaultCompat(fg);
|
|
55
|
+
const lockfile__default = /*#__PURE__*/_interopDefaultCompat(lockfile);
|
|
56
56
|
const vm__default = /*#__PURE__*/_interopDefaultCompat(vm);
|
|
57
57
|
const babelGenerator__default = /*#__PURE__*/_interopDefaultCompat(babelGenerator);
|
|
58
58
|
const groupBy__default = /*#__PURE__*/_interopDefaultCompat(groupBy);
|
|
@@ -164,7 +164,7 @@ function mergePageMetaDataArray(pageMetaData) {
|
|
|
164
164
|
}
|
|
165
165
|
return result;
|
|
166
166
|
}
|
|
167
|
-
async function
|
|
167
|
+
async function parseCode(options) {
|
|
168
168
|
const { imports = [], code, filename } = options;
|
|
169
169
|
let jsCode = "";
|
|
170
170
|
try {
|
|
@@ -215,7 +215,24 @@ async function execScript(options) {
|
|
|
215
215
|
__filename: filename,
|
|
216
216
|
__dirname: dir,
|
|
217
217
|
require: node_module.createRequire(dir),
|
|
218
|
-
import: (id) => import(id)
|
|
218
|
+
import: (id) => import(id),
|
|
219
|
+
// 定时器相关
|
|
220
|
+
setTimeout,
|
|
221
|
+
clearTimeout,
|
|
222
|
+
setInterval,
|
|
223
|
+
clearInterval,
|
|
224
|
+
setImmediate,
|
|
225
|
+
clearImmediate,
|
|
226
|
+
// 控制台相关
|
|
227
|
+
console,
|
|
228
|
+
// URL 处理
|
|
229
|
+
URL,
|
|
230
|
+
URLSearchParams,
|
|
231
|
+
// 进程和性能相关
|
|
232
|
+
performance,
|
|
233
|
+
// 全局对象引用
|
|
234
|
+
global: globalThis,
|
|
235
|
+
globalThis
|
|
219
236
|
};
|
|
220
237
|
const script = new vm__default.Script(jsCode, { filename });
|
|
221
238
|
await script.runInNewContext(vmContext, {
|
|
@@ -223,10 +240,7 @@ async function execScript(options) {
|
|
|
223
240
|
// 设置超时避免长时间运行
|
|
224
241
|
});
|
|
225
242
|
const result = vmContext.exports.default || vmContext.exports;
|
|
226
|
-
|
|
227
|
-
return Promise.resolve(result());
|
|
228
|
-
}
|
|
229
|
-
return Promise.resolve(result);
|
|
243
|
+
return result;
|
|
230
244
|
} catch (error) {
|
|
231
245
|
throw new Error(`EXEC SCRIPT FAIL IN ${filename}: ${error.message}
|
|
232
246
|
|
|
@@ -473,7 +487,7 @@ class Page {
|
|
|
473
487
|
if (forceUpdate || !this.meta) {
|
|
474
488
|
await this.read();
|
|
475
489
|
}
|
|
476
|
-
const { path, tabBar: _, ...others } = this.meta;
|
|
490
|
+
const { path, tabBar: _, ...others } = this.meta || {};
|
|
477
491
|
return {
|
|
478
492
|
path: path ?? this.uri,
|
|
479
493
|
...others
|
|
@@ -550,14 +564,15 @@ async function tryPageMetaFromMacro(sfc) {
|
|
|
550
564
|
const imports = findImports(ast.body).filter((imp) => !!imp.specifiers.length).map((imp) => babelGenerate(imp).code);
|
|
551
565
|
const [macroOption] = macro.arguments;
|
|
552
566
|
const code = babelGenerate(macroOption).code;
|
|
553
|
-
const
|
|
567
|
+
const parsed = await parseCode({
|
|
554
568
|
imports,
|
|
555
569
|
code,
|
|
556
570
|
filename: sfc.filename
|
|
557
571
|
});
|
|
572
|
+
const res = typeof parsed === "function" ? await Promise.resolve(parsed()) : await Promise.resolve(parsed);
|
|
558
573
|
return {
|
|
559
574
|
type: "page",
|
|
560
|
-
...
|
|
575
|
+
...res
|
|
561
576
|
};
|
|
562
577
|
}
|
|
563
578
|
return void 0;
|
|
@@ -762,8 +777,11 @@ class PageContext {
|
|
|
762
777
|
const generatedPageMetaData = await Promise.all(jobs);
|
|
763
778
|
const customPageMetaData = overrides || [];
|
|
764
779
|
const result = customPageMetaData.length ? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData)) : generatedPageMetaData;
|
|
765
|
-
const parseMeta =
|
|
766
|
-
|
|
780
|
+
const parseMeta = Array.from(
|
|
781
|
+
result.reduce((map, page) => {
|
|
782
|
+
map.set(page.path, page);
|
|
783
|
+
return map;
|
|
784
|
+
}, /* @__PURE__ */ new Map()).values()
|
|
767
785
|
);
|
|
768
786
|
return type === "main" ? this.setHomePage(parseMeta) : parseMeta;
|
|
769
787
|
}
|
|
@@ -917,35 +935,14 @@ class PageContext {
|
|
|
917
935
|
debug.declaration("generating");
|
|
918
936
|
return writeDeclaration(this, this.options.dts);
|
|
919
937
|
}
|
|
920
|
-
async writePagesJSONFile(pagesJson, retry = 3) {
|
|
921
|
-
if (retry <= 0) {
|
|
922
|
-
debug.error(`${this.resolvedPagesJSONPath} \u83B7\u53D6\u6587\u4EF6\u9501\u5931\u8D25\uFF0C\u5199\u5165\u5931\u8D25`);
|
|
923
|
-
return;
|
|
924
|
-
}
|
|
925
|
-
let relase;
|
|
926
|
-
try {
|
|
927
|
-
try {
|
|
928
|
-
relase = await lockfile__default.lock(this.resolvedPagesJSONPath, { realpath: false });
|
|
929
|
-
} catch {
|
|
930
|
-
return this.writePagesJSONFile(pagesJson, retry - 1);
|
|
931
|
-
}
|
|
932
|
-
await fs__default.promises.writeFile(this.resolvedPagesJSONPath, pagesJson, { encoding: "utf-8" });
|
|
933
|
-
} finally {
|
|
934
|
-
if (relase) {
|
|
935
|
-
await relase();
|
|
936
|
-
}
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
938
|
async genratePagesJSON() {
|
|
940
939
|
const content = await fs__default.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "");
|
|
941
|
-
|
|
940
|
+
const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = commentJson.parse(content || "{}");
|
|
942
941
|
const { pages: _, subPackages: __, tabBar: ___, ...others } = this.pagesGlobConfig || {};
|
|
943
|
-
pageJson =
|
|
944
|
-
...others
|
|
945
|
-
});
|
|
942
|
+
const pageJson = { ...others };
|
|
946
943
|
const currentPlatform = uniEnv.platform.toUpperCase();
|
|
947
|
-
pageJson.pages = mergePlatformItems(
|
|
948
|
-
pageJson.subPackages =
|
|
944
|
+
pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
|
|
945
|
+
pageJson.subPackages = oldSubPackages || new commentJson.CommentArray();
|
|
949
946
|
const newSubPackages = /* @__PURE__ */ new Map();
|
|
950
947
|
for (const item of this.subPageMetaData) {
|
|
951
948
|
newSubPackages.set(item.root, item);
|
|
@@ -963,15 +960,17 @@ class PageContext {
|
|
|
963
960
|
pages: mergePlatformItems(void 0, currentPlatform, newSub.pages, "path")
|
|
964
961
|
});
|
|
965
962
|
}
|
|
966
|
-
const
|
|
967
|
-
if (
|
|
968
|
-
const list =
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
}
|
|
963
|
+
const { list, ...tabBarOthers } = await this.getTabBarMerged() || {};
|
|
964
|
+
if (list) {
|
|
965
|
+
const { list: oldList } = oldTabBar || {};
|
|
966
|
+
const newList = mergePlatformItems(oldList, currentPlatform, list, "pagePath");
|
|
967
|
+
pageJson.tabBar = {
|
|
968
|
+
...tabBarOthers,
|
|
969
|
+
// 每次都直接更新除 list 外的其他属性
|
|
970
|
+
list: newList
|
|
971
|
+
};
|
|
972
|
+
} else {
|
|
973
|
+
pageJson.tabBar = void 0;
|
|
975
974
|
}
|
|
976
975
|
return pageJson;
|
|
977
976
|
}
|
|
@@ -1220,7 +1219,6 @@ exports.checkPagesJsonFileSync = checkPagesJsonFileSync;
|
|
|
1220
1219
|
exports.debug = debug;
|
|
1221
1220
|
exports.default = VitePluginUniPages;
|
|
1222
1221
|
exports.defineUniPages = defineUniPages;
|
|
1223
|
-
exports.execScript = execScript;
|
|
1224
1222
|
exports.extsToGlob = extsToGlob;
|
|
1225
1223
|
exports.findImports = findImports;
|
|
1226
1224
|
exports.findMacro = findMacro;
|
|
@@ -1230,6 +1228,7 @@ exports.getRouteSfcBlock = getRouteSfcBlock;
|
|
|
1230
1228
|
exports.invalidatePagesModule = invalidatePagesModule;
|
|
1231
1229
|
exports.isTargetFile = isTargetFile;
|
|
1232
1230
|
exports.mergePageMetaDataArray = mergePageMetaDataArray;
|
|
1231
|
+
exports.parseCode = parseCode;
|
|
1233
1232
|
exports.parseCustomBlock = parseCustomBlock;
|
|
1234
1233
|
exports.parseSFC = parseSFC;
|
|
1235
1234
|
exports.resolveOptions = resolveOptions;
|
package/dist/index.d.cts
CHANGED
|
@@ -2995,7 +2995,6 @@ declare class PageContext {
|
|
|
2995
2995
|
resolveRoutes(): string;
|
|
2996
2996
|
resolveSubRoutes(): string;
|
|
2997
2997
|
generateDeclaration(): Promise<void> | undefined;
|
|
2998
|
-
private writePagesJSONFile;
|
|
2999
2998
|
private genratePagesJSON;
|
|
3000
2999
|
private readInfoFromPagesJSON;
|
|
3001
3000
|
private getIndent;
|
|
@@ -3024,7 +3023,7 @@ declare function isTargetFile(path: string): boolean;
|
|
|
3024
3023
|
*/
|
|
3025
3024
|
declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
|
|
3026
3025
|
/**
|
|
3027
|
-
*
|
|
3026
|
+
* 将 TypeScript / JavaScript 脚本代码,转换为对象/函数
|
|
3028
3027
|
*
|
|
3029
3028
|
* @param options - 执行脚本所需的配置项
|
|
3030
3029
|
* @param options.imports - 需要引入的模块导入语句列表
|
|
@@ -3032,7 +3031,7 @@ declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMeta
|
|
|
3032
3031
|
* @param options.filename - 脚本文件名,用于错误定位和上下文环境
|
|
3033
3032
|
* @returns 返回脚本执行后的结果,若导出的是函数则执行后返回其返回值
|
|
3034
3033
|
*/
|
|
3035
|
-
declare function
|
|
3034
|
+
declare function parseCode(options: {
|
|
3036
3035
|
imports: string[];
|
|
3037
3036
|
code: string;
|
|
3038
3037
|
filename: string;
|
|
@@ -3214,5 +3213,5 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
|
|
|
3214
3213
|
|
|
3215
3214
|
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
3216
3215
|
|
|
3217
|
-
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages,
|
|
3216
|
+
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileWithLock };
|
|
3218
3217
|
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
|
@@ -2995,7 +2995,6 @@ declare class PageContext {
|
|
|
2995
2995
|
resolveRoutes(): string;
|
|
2996
2996
|
resolveSubRoutes(): string;
|
|
2997
2997
|
generateDeclaration(): Promise<void> | undefined;
|
|
2998
|
-
private writePagesJSONFile;
|
|
2999
2998
|
private genratePagesJSON;
|
|
3000
2999
|
private readInfoFromPagesJSON;
|
|
3001
3000
|
private getIndent;
|
|
@@ -3024,7 +3023,7 @@ declare function isTargetFile(path: string): boolean;
|
|
|
3024
3023
|
*/
|
|
3025
3024
|
declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
|
|
3026
3025
|
/**
|
|
3027
|
-
*
|
|
3026
|
+
* 将 TypeScript / JavaScript 脚本代码,转换为对象/函数
|
|
3028
3027
|
*
|
|
3029
3028
|
* @param options - 执行脚本所需的配置项
|
|
3030
3029
|
* @param options.imports - 需要引入的模块导入语句列表
|
|
@@ -3032,7 +3031,7 @@ declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMeta
|
|
|
3032
3031
|
* @param options.filename - 脚本文件名,用于错误定位和上下文环境
|
|
3033
3032
|
* @returns 返回脚本执行后的结果,若导出的是函数则执行后返回其返回值
|
|
3034
3033
|
*/
|
|
3035
|
-
declare function
|
|
3034
|
+
declare function parseCode(options: {
|
|
3036
3035
|
imports: string[];
|
|
3037
3036
|
code: string;
|
|
3038
3037
|
filename: string;
|
|
@@ -3214,5 +3213,5 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
|
|
|
3214
3213
|
|
|
3215
3214
|
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
3216
3215
|
|
|
3217
|
-
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages,
|
|
3216
|
+
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileWithLock };
|
|
3218
3217
|
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
|
@@ -2995,7 +2995,6 @@ declare class PageContext {
|
|
|
2995
2995
|
resolveRoutes(): string;
|
|
2996
2996
|
resolveSubRoutes(): string;
|
|
2997
2997
|
generateDeclaration(): Promise<void> | undefined;
|
|
2998
|
-
private writePagesJSONFile;
|
|
2999
2998
|
private genratePagesJSON;
|
|
3000
2999
|
private readInfoFromPagesJSON;
|
|
3001
3000
|
private getIndent;
|
|
@@ -3024,7 +3023,7 @@ declare function isTargetFile(path: string): boolean;
|
|
|
3024
3023
|
*/
|
|
3025
3024
|
declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMetaDatum[];
|
|
3026
3025
|
/**
|
|
3027
|
-
*
|
|
3026
|
+
* 将 TypeScript / JavaScript 脚本代码,转换为对象/函数
|
|
3028
3027
|
*
|
|
3029
3028
|
* @param options - 执行脚本所需的配置项
|
|
3030
3029
|
* @param options.imports - 需要引入的模块导入语句列表
|
|
@@ -3032,7 +3031,7 @@ declare function mergePageMetaDataArray(pageMetaData: PageMetaDatum[]): PageMeta
|
|
|
3032
3031
|
* @param options.filename - 脚本文件名,用于错误定位和上下文环境
|
|
3033
3032
|
* @returns 返回脚本执行后的结果,若导出的是函数则执行后返回其返回值
|
|
3034
3033
|
*/
|
|
3035
|
-
declare function
|
|
3034
|
+
declare function parseCode(options: {
|
|
3036
3035
|
imports: string[];
|
|
3037
3036
|
code: string;
|
|
3038
3037
|
filename: string;
|
|
@@ -3214,5 +3213,5 @@ declare function resolvePageDirs(dir: string, root: string, exclude: string[]):
|
|
|
3214
3213
|
|
|
3215
3214
|
declare function VitePluginUniPages(userOptions?: UserOptions): Plugin;
|
|
3216
3215
|
|
|
3217
|
-
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages,
|
|
3216
|
+
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, definePage, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileWithLock };
|
|
3218
3217
|
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
|
@@ -11,10 +11,10 @@ import { parse, assign, stringify, CommentArray } from 'comment-json';
|
|
|
11
11
|
import Debug from 'debug';
|
|
12
12
|
import detectIndent from 'detect-indent';
|
|
13
13
|
import detectNewline from 'detect-newline';
|
|
14
|
-
import lockfile from 'proper-lockfile';
|
|
15
14
|
import { loadConfig } from 'unconfig';
|
|
16
15
|
import { readFile, mkdir, writeFile as writeFile$1 } from 'node:fs/promises';
|
|
17
16
|
import fg from 'fast-glob';
|
|
17
|
+
import lockfile from 'proper-lockfile';
|
|
18
18
|
import { createRequire } from 'node:module';
|
|
19
19
|
import vm from 'node:vm';
|
|
20
20
|
import babelGenerator from '@babel/generator';
|
|
@@ -129,7 +129,7 @@ function mergePageMetaDataArray(pageMetaData) {
|
|
|
129
129
|
}
|
|
130
130
|
return result;
|
|
131
131
|
}
|
|
132
|
-
async function
|
|
132
|
+
async function parseCode(options) {
|
|
133
133
|
const { imports = [], code, filename } = options;
|
|
134
134
|
let jsCode = "";
|
|
135
135
|
try {
|
|
@@ -180,7 +180,24 @@ async function execScript(options) {
|
|
|
180
180
|
__filename: filename,
|
|
181
181
|
__dirname: dir,
|
|
182
182
|
require: createRequire(dir),
|
|
183
|
-
import: (id) => import(id)
|
|
183
|
+
import: (id) => import(id),
|
|
184
|
+
// 定时器相关
|
|
185
|
+
setTimeout,
|
|
186
|
+
clearTimeout,
|
|
187
|
+
setInterval,
|
|
188
|
+
clearInterval,
|
|
189
|
+
setImmediate,
|
|
190
|
+
clearImmediate,
|
|
191
|
+
// 控制台相关
|
|
192
|
+
console,
|
|
193
|
+
// URL 处理
|
|
194
|
+
URL,
|
|
195
|
+
URLSearchParams,
|
|
196
|
+
// 进程和性能相关
|
|
197
|
+
performance,
|
|
198
|
+
// 全局对象引用
|
|
199
|
+
global: globalThis,
|
|
200
|
+
globalThis
|
|
184
201
|
};
|
|
185
202
|
const script = new vm.Script(jsCode, { filename });
|
|
186
203
|
await script.runInNewContext(vmContext, {
|
|
@@ -188,10 +205,7 @@ async function execScript(options) {
|
|
|
188
205
|
// 设置超时避免长时间运行
|
|
189
206
|
});
|
|
190
207
|
const result = vmContext.exports.default || vmContext.exports;
|
|
191
|
-
|
|
192
|
-
return Promise.resolve(result());
|
|
193
|
-
}
|
|
194
|
-
return Promise.resolve(result);
|
|
208
|
+
return result;
|
|
195
209
|
} catch (error) {
|
|
196
210
|
throw new Error(`EXEC SCRIPT FAIL IN ${filename}: ${error.message}
|
|
197
211
|
|
|
@@ -438,7 +452,7 @@ class Page {
|
|
|
438
452
|
if (forceUpdate || !this.meta) {
|
|
439
453
|
await this.read();
|
|
440
454
|
}
|
|
441
|
-
const { path, tabBar: _, ...others } = this.meta;
|
|
455
|
+
const { path, tabBar: _, ...others } = this.meta || {};
|
|
442
456
|
return {
|
|
443
457
|
path: path ?? this.uri,
|
|
444
458
|
...others
|
|
@@ -515,14 +529,15 @@ async function tryPageMetaFromMacro(sfc) {
|
|
|
515
529
|
const imports = findImports(ast.body).filter((imp) => !!imp.specifiers.length).map((imp) => babelGenerate(imp).code);
|
|
516
530
|
const [macroOption] = macro.arguments;
|
|
517
531
|
const code = babelGenerate(macroOption).code;
|
|
518
|
-
const
|
|
532
|
+
const parsed = await parseCode({
|
|
519
533
|
imports,
|
|
520
534
|
code,
|
|
521
535
|
filename: sfc.filename
|
|
522
536
|
});
|
|
537
|
+
const res = typeof parsed === "function" ? await Promise.resolve(parsed()) : await Promise.resolve(parsed);
|
|
523
538
|
return {
|
|
524
539
|
type: "page",
|
|
525
|
-
...
|
|
540
|
+
...res
|
|
526
541
|
};
|
|
527
542
|
}
|
|
528
543
|
return void 0;
|
|
@@ -727,8 +742,11 @@ class PageContext {
|
|
|
727
742
|
const generatedPageMetaData = await Promise.all(jobs);
|
|
728
743
|
const customPageMetaData = overrides || [];
|
|
729
744
|
const result = customPageMetaData.length ? mergePageMetaDataArray(generatedPageMetaData.concat(customPageMetaData)) : generatedPageMetaData;
|
|
730
|
-
const parseMeta =
|
|
731
|
-
|
|
745
|
+
const parseMeta = Array.from(
|
|
746
|
+
result.reduce((map, page) => {
|
|
747
|
+
map.set(page.path, page);
|
|
748
|
+
return map;
|
|
749
|
+
}, /* @__PURE__ */ new Map()).values()
|
|
732
750
|
);
|
|
733
751
|
return type === "main" ? this.setHomePage(parseMeta) : parseMeta;
|
|
734
752
|
}
|
|
@@ -882,35 +900,14 @@ class PageContext {
|
|
|
882
900
|
debug.declaration("generating");
|
|
883
901
|
return writeDeclaration(this, this.options.dts);
|
|
884
902
|
}
|
|
885
|
-
async writePagesJSONFile(pagesJson, retry = 3) {
|
|
886
|
-
if (retry <= 0) {
|
|
887
|
-
debug.error(`${this.resolvedPagesJSONPath} \u83B7\u53D6\u6587\u4EF6\u9501\u5931\u8D25\uFF0C\u5199\u5165\u5931\u8D25`);
|
|
888
|
-
return;
|
|
889
|
-
}
|
|
890
|
-
let relase;
|
|
891
|
-
try {
|
|
892
|
-
try {
|
|
893
|
-
relase = await lockfile.lock(this.resolvedPagesJSONPath, { realpath: false });
|
|
894
|
-
} catch {
|
|
895
|
-
return this.writePagesJSONFile(pagesJson, retry - 1);
|
|
896
|
-
}
|
|
897
|
-
await fs.promises.writeFile(this.resolvedPagesJSONPath, pagesJson, { encoding: "utf-8" });
|
|
898
|
-
} finally {
|
|
899
|
-
if (relase) {
|
|
900
|
-
await relase();
|
|
901
|
-
}
|
|
902
|
-
}
|
|
903
|
-
}
|
|
904
903
|
async genratePagesJSON() {
|
|
905
904
|
const content = await fs.promises.readFile(this.resolvedPagesJSONPath, { encoding: "utf-8" }).catch(() => "");
|
|
906
|
-
|
|
905
|
+
const { pages: oldPages, subPackages: oldSubPackages, tabBar: oldTabBar } = parse(content || "{}");
|
|
907
906
|
const { pages: _, subPackages: __, tabBar: ___, ...others } = this.pagesGlobConfig || {};
|
|
908
|
-
pageJson =
|
|
909
|
-
...others
|
|
910
|
-
});
|
|
907
|
+
const pageJson = { ...others };
|
|
911
908
|
const currentPlatform = platform.toUpperCase();
|
|
912
|
-
pageJson.pages = mergePlatformItems(
|
|
913
|
-
pageJson.subPackages =
|
|
909
|
+
pageJson.pages = mergePlatformItems(oldPages, currentPlatform, this.pageMetaData, "path");
|
|
910
|
+
pageJson.subPackages = oldSubPackages || new CommentArray();
|
|
914
911
|
const newSubPackages = /* @__PURE__ */ new Map();
|
|
915
912
|
for (const item of this.subPageMetaData) {
|
|
916
913
|
newSubPackages.set(item.root, item);
|
|
@@ -928,15 +925,17 @@ class PageContext {
|
|
|
928
925
|
pages: mergePlatformItems(void 0, currentPlatform, newSub.pages, "path")
|
|
929
926
|
});
|
|
930
927
|
}
|
|
931
|
-
const
|
|
932
|
-
if (
|
|
933
|
-
const list =
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
}
|
|
928
|
+
const { list, ...tabBarOthers } = await this.getTabBarMerged() || {};
|
|
929
|
+
if (list) {
|
|
930
|
+
const { list: oldList } = oldTabBar || {};
|
|
931
|
+
const newList = mergePlatformItems(oldList, currentPlatform, list, "pagePath");
|
|
932
|
+
pageJson.tabBar = {
|
|
933
|
+
...tabBarOthers,
|
|
934
|
+
// 每次都直接更新除 list 外的其他属性
|
|
935
|
+
list: newList
|
|
936
|
+
};
|
|
937
|
+
} else {
|
|
938
|
+
pageJson.tabBar = void 0;
|
|
940
939
|
}
|
|
941
940
|
return pageJson;
|
|
942
941
|
}
|
|
@@ -1173,4 +1172,4 @@ function VitePluginUniPages(userOptions = {}) {
|
|
|
1173
1172
|
};
|
|
1174
1173
|
}
|
|
1175
1174
|
|
|
1176
|
-
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, defineUniPages,
|
|
1175
|
+
export { FILE_EXTENSIONS, MODULE_ID_VIRTUAL, OUTPUT_NAME, Page, PageContext, RESOLVED_MODULE_ID_VIRTUAL, VitePluginUniPages, babelGenerate, checkPagesJsonFileSync, debug, VitePluginUniPages as default, defineUniPages, extsToGlob, findImports, findMacro, getPageFiles, getRouteBlock, getRouteSfcBlock, invalidatePagesModule, isTargetFile, mergePageMetaDataArray, parseCode, parseCustomBlock, parseSFC, resolveOptions, resolvePageDirs, sleep, tryPageMetaFromCustomBlock, tryPageMetaFromMacro, writeFileWithLock };
|