@weapp-core/shared 3.0.3 → 3.0.4

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.js CHANGED
@@ -1,7 +1,3 @@
1
- import { Buffer as Buffer$1 } from "node:buffer";
2
- import { createHash } from "node:crypto";
3
- import path, { extname } from "node:path";
4
- import { Dirent, Stats, close, closeSync, constants, existsSync, mkdirSync, openSync, promises, readFileSync, unlinkSync, utimesSync, watch, writeFileSync } from "node:fs";
5
1
  //#region \0rolldown/runtime.js
6
2
  var __create = Object.create;
7
3
  var __defProp$1 = Object.defineProperty;
@@ -25,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
25
21
  enumerable: true
26
22
  }) : target, mod));
27
23
  //#endregion
28
- //#region ../../node_modules/.pnpm/defu@6.1.6/node_modules/defu/dist/defu.mjs
24
+ //#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs
29
25
  function isPlainObject(value) {
30
26
  if (value === null || typeof value !== "object") return false;
31
27
  const prototype = Object.getPrototypeOf(value);
@@ -65,197 +61,504 @@ createDefu((object, key, currentValue) => {
65
61
  }
66
62
  });
67
63
  //#endregion
68
- //#region src/fs/index.ts
69
- function normalizeJsonEncoding(encoding) {
70
- return encoding ?? "utf8";
64
+ //#region src/platforms/descriptors.ts
65
+ const DEFAULT_PROJECT_CONFIG_ROOT_KEYS = ["miniprogramRoot", "srcMiniprogramRoot"];
66
+ const DEFAULT_RUNTIME_CAPABILITIES = Object.freeze({
67
+ globalPageStack: true,
68
+ globalCreateSelectorQuery: true,
69
+ selectorQueryScopeByIn: true,
70
+ globalCreateIntersectionObserver: true,
71
+ intersectionObserverScopeByParameter: true,
72
+ pageShareMenu: true,
73
+ shareTimelineRequiresShareAppMessage: true,
74
+ pageScrollApi: true,
75
+ pullDownRefreshApi: true,
76
+ globalRouterApi: true,
77
+ appErrorListener: true,
78
+ appPageNotFoundListener: true,
79
+ appUnhandledRejectionListener: true,
80
+ appThemeChangeListener: true,
81
+ appMemoryWarningListener: true
82
+ });
83
+ const DEFAULT_PAGE_IDENTITY_RULES = [{
84
+ prefix: "route",
85
+ source: "route"
86
+ }];
87
+ /**
88
+ * @description 全仓库统一的小程序平台描述表。
89
+ */
90
+ const MINI_PROGRAM_PLATFORM_DESCRIPTORS = [
91
+ {
92
+ id: "weapp",
93
+ displayName: "WeChat Mini Program",
94
+ family: "wechat",
95
+ aliases: [
96
+ "weapp",
97
+ "wechat",
98
+ "weixin",
99
+ "wx"
100
+ ],
101
+ outputExtensions: {
102
+ js: "js",
103
+ json: "json",
104
+ wxml: "wxml",
105
+ wxss: "wxss",
106
+ wxs: "wxs"
107
+ },
108
+ projectConfigFileName: "project.config.json",
109
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
110
+ ide: {},
111
+ build: {
112
+ autoTouchAppStyle: true,
113
+ defaultBuildTarget: "es2020"
114
+ },
115
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
116
+ json: {},
117
+ npm: { distDirName: () => "miniprogram_npm" },
118
+ wxml: {
119
+ eventBindingStyle: "default",
120
+ directivePrefix: "wx"
121
+ },
122
+ compiler: { templatePreset: "wechat" },
123
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
124
+ runtime: {
125
+ globalObjectKey: "wx",
126
+ hostConfigKey: "__wxConfig",
127
+ globalResolvePriority: 1,
128
+ routeGlobalResolvePriority: 0,
129
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
130
+ pageIdentityRules: [
131
+ {
132
+ prefix: "webview",
133
+ source: "field",
134
+ field: "__wxWebviewId__"
135
+ },
136
+ {
137
+ prefix: "exparser",
138
+ source: "field",
139
+ field: "__wxExparserNodeId__"
140
+ },
141
+ ...DEFAULT_PAGE_IDENTITY_RULES
142
+ ]
143
+ }
144
+ },
145
+ {
146
+ id: "alipay",
147
+ displayName: "Alipay Mini Program",
148
+ family: "alipay",
149
+ aliases: [
150
+ "alipay",
151
+ "ali",
152
+ "my"
153
+ ],
154
+ outputExtensions: {
155
+ js: "js",
156
+ json: "json",
157
+ wxml: "axml",
158
+ wxss: "acss",
159
+ wxs: "sjs"
160
+ },
161
+ projectConfigFileName: "mini.project.json",
162
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
163
+ scriptModuleTagByExtension: { sjs: "import-sjs" },
164
+ usesProjectRootNpmDir: true,
165
+ ide: {
166
+ requiresOpenPlatformArg: true,
167
+ defaultProjectRoot: "dist/alipay/dist"
168
+ },
169
+ build: {
170
+ autoTouchAppStyle: false,
171
+ defaultBuildTarget: "es2015"
172
+ },
173
+ resolvePreservedNpmDirNames: (options) => [options?.alipayNpmMode === "miniprogram_npm" ? "miniprogram_npm" : "node_modules"],
174
+ json: {
175
+ normalizeUsingComponents: true,
176
+ fillComponentGenericsDefault: true,
177
+ rewriteBundleNpmImports: true
178
+ },
179
+ npm: {
180
+ distDirName: (options) => options?.alipayNpmMode === "miniprogram_npm" ? "miniprogram_npm" : "node_modules",
181
+ normalizeImportPath: true,
182
+ normalizeMiniprogramPackage: true,
183
+ copyEsModuleDirectory: true,
184
+ hoistNestedDependencies: true,
185
+ shouldRebuildCachedPackage: true
186
+ },
187
+ wxml: {
188
+ eventBindingStyle: "alipay",
189
+ directivePrefix: "a",
190
+ normalizeComponentTagName: true,
191
+ normalizeVueTemplate: true,
192
+ emitGenericPlaceholder: true
193
+ },
194
+ compiler: { templatePreset: "alipay" },
195
+ typescript: { appTypesPackage: "@mini-types/alipay" },
196
+ runtime: {
197
+ globalObjectKey: "my",
198
+ hostConfigKey: "__wxConfig",
199
+ globalResolvePriority: 0,
200
+ routeGlobalResolvePriority: 2,
201
+ capabilities: {
202
+ ...DEFAULT_RUNTIME_CAPABILITIES,
203
+ pageShareMenu: false,
204
+ appThemeChangeListener: false
205
+ },
206
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
207
+ }
208
+ },
209
+ {
210
+ id: "swan",
211
+ displayName: "Baidu Smart Program",
212
+ family: "swan",
213
+ aliases: [
214
+ "swan",
215
+ "baidu",
216
+ "bd"
217
+ ],
218
+ outputExtensions: {
219
+ js: "js",
220
+ json: "json",
221
+ wxml: "swan",
222
+ wxss: "css",
223
+ wxs: "sjs"
224
+ },
225
+ projectConfigFileName: "project.swan.json",
226
+ projectConfigRootKeys: ["smartProgramRoot", ...DEFAULT_PROJECT_CONFIG_ROOT_KEYS],
227
+ ide: {},
228
+ build: { autoTouchAppStyle: false },
229
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
230
+ json: {},
231
+ npm: { distDirName: () => "miniprogram_npm" },
232
+ wxml: {
233
+ eventBindingStyle: "default",
234
+ directivePrefix: "s"
235
+ },
236
+ compiler: { templatePreset: "swan" },
237
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
238
+ runtime: {
239
+ globalObjectKey: "swan",
240
+ hostConfigKey: "__wxConfig",
241
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
242
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
243
+ }
244
+ },
245
+ {
246
+ id: "tt",
247
+ displayName: "ByteDance / Douyin Mini Program",
248
+ family: "tt",
249
+ aliases: [
250
+ "tt",
251
+ "toutiao",
252
+ "bytedance",
253
+ "douyin"
254
+ ],
255
+ outputExtensions: {
256
+ js: "js",
257
+ json: "json",
258
+ wxml: "ttml",
259
+ wxss: "ttss"
260
+ },
261
+ projectConfigFileName: "project.config.json",
262
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
263
+ ide: {},
264
+ build: { autoTouchAppStyle: false },
265
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
266
+ json: {},
267
+ npm: { distDirName: () => "miniprogram_npm" },
268
+ wxml: {
269
+ eventBindingStyle: "default",
270
+ directivePrefix: "tt"
271
+ },
272
+ compiler: { templatePreset: "tt" },
273
+ typescript: { appTypesPackage: "@douyin-microapp/typings" },
274
+ runtime: {
275
+ globalObjectKey: "tt",
276
+ hostConfigKey: "__wxConfig",
277
+ globalResolvePriority: 2,
278
+ routeGlobalResolvePriority: 1,
279
+ capabilities: {
280
+ ...DEFAULT_RUNTIME_CAPABILITIES,
281
+ appThemeChangeListener: false
282
+ },
283
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
284
+ }
285
+ },
286
+ {
287
+ id: "jd",
288
+ displayName: "JD Mini Program",
289
+ family: "wechat",
290
+ aliases: ["jd", "jingdong"],
291
+ outputExtensions: {
292
+ js: "js",
293
+ json: "json",
294
+ wxml: "jxml",
295
+ wxss: "jxss",
296
+ wxs: "wxs"
297
+ },
298
+ projectConfigFileName: "project.config.json",
299
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
300
+ ide: {},
301
+ build: { autoTouchAppStyle: false },
302
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
303
+ json: {},
304
+ npm: { distDirName: () => "miniprogram_npm" },
305
+ wxml: {
306
+ eventBindingStyle: "default",
307
+ directivePrefix: "wx"
308
+ },
309
+ compiler: { templatePreset: "wechat" },
310
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
311
+ runtime: {
312
+ globalObjectKey: "jd",
313
+ hostConfigKey: "__wxConfig",
314
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
315
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
316
+ }
317
+ },
318
+ {
319
+ id: "xhs",
320
+ displayName: "Xiaohongshu Mini Program",
321
+ family: "wechat",
322
+ aliases: [
323
+ "xhs",
324
+ "xiaohongshu",
325
+ "little-red-book",
326
+ "red"
327
+ ],
328
+ outputExtensions: {
329
+ js: "js",
330
+ json: "json",
331
+ wxml: "xhsml",
332
+ wxss: "css",
333
+ wxs: "wxs"
334
+ },
335
+ projectConfigFileName: "project.config.json",
336
+ projectConfigRootKeys: DEFAULT_PROJECT_CONFIG_ROOT_KEYS,
337
+ ide: {},
338
+ build: { autoTouchAppStyle: false },
339
+ resolvePreservedNpmDirNames: () => ["miniprogram_npm"],
340
+ json: {},
341
+ npm: { distDirName: () => "miniprogram_npm" },
342
+ wxml: {
343
+ eventBindingStyle: "default",
344
+ directivePrefix: "wx"
345
+ },
346
+ compiler: { templatePreset: "wechat" },
347
+ typescript: { appTypesPackage: "miniprogram-api-typings" },
348
+ runtime: {
349
+ globalObjectKey: "xhs",
350
+ hostConfigKey: "__wxConfig",
351
+ capabilities: DEFAULT_RUNTIME_CAPABILITIES,
352
+ pageIdentityRules: DEFAULT_PAGE_IDENTITY_RULES
353
+ }
354
+ }
355
+ ];
356
+ //#endregion
357
+ //#region src/platforms/helpers.ts
358
+ const LEADING_SLASH_RE = /^\/+/;
359
+ function createMiniProgramPlatformRegistry(descriptors) {
360
+ const descriptorById = /* @__PURE__ */ new Map();
361
+ const aliasToId = /* @__PURE__ */ new Map();
362
+ const runtimeGlobalKeyToId = /* @__PURE__ */ new Map();
363
+ for (const descriptor of descriptors) {
364
+ descriptorById.set(descriptor.id, descriptor);
365
+ runtimeGlobalKeyToId.set(descriptor.runtime.globalObjectKey, descriptor.id);
366
+ aliasToId.set(descriptor.id, descriptor.id);
367
+ for (const alias of descriptor.aliases) {
368
+ const normalized = alias.trim().toLowerCase();
369
+ if (!normalized) continue;
370
+ aliasToId.set(normalized, descriptor.id);
371
+ }
372
+ }
373
+ return {
374
+ aliasToId,
375
+ descriptorById,
376
+ runtimeGlobalKeyToId
377
+ };
71
378
  }
72
- function normalizeJsonText(source) {
73
- return source.charCodeAt(0) === 65279 ? source.slice(1) : source;
379
+ const { aliasToId: MINI_PROGRAM_PLATFORM_ALIAS_TO_ID, descriptorById: MINI_PROGRAM_PLATFORM_DESCRIPTOR_BY_ID, runtimeGlobalKeyToId: MINI_PROGRAM_RUNTIME_GLOBAL_KEY_TO_ID } = createMiniProgramPlatformRegistry(MINI_PROGRAM_PLATFORM_DESCRIPTORS);
380
+ const SUPPORTED_MINI_PROGRAM_PLATFORMS = Object.freeze(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.id));
381
+ const SUPPORTED_MINI_PROGRAM_DIRECTIVE_PREFIXES = Object.freeze(Array.from(new Set(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.wxml?.directivePrefix).filter((prefix) => Boolean(prefix)))));
382
+ const ORDERED_RUNTIME_GLOBAL_KEYS = Object.freeze(Array.from(new Set(MINI_PROGRAM_PLATFORM_DESCRIPTORS.map((descriptor) => descriptor.runtime.globalObjectKey))));
383
+ const MAX_RUNTIME_RESOLVE_PRIORITY = Number.MAX_SAFE_INTEGER;
384
+ function getOrderedRuntimeGlobalKeysByPriority(priorityKey) {
385
+ const ordered = [...MINI_PROGRAM_PLATFORM_DESCRIPTORS].sort((left, right) => {
386
+ const leftPriority = left.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
387
+ const rightPriority = right.runtime[priorityKey] ?? MAX_RUNTIME_RESOLVE_PRIORITY;
388
+ if (leftPriority !== rightPriority) return leftPriority - rightPriority;
389
+ return MINI_PROGRAM_PLATFORM_DESCRIPTORS.indexOf(left) - MINI_PROGRAM_PLATFORM_DESCRIPTORS.indexOf(right);
390
+ });
391
+ return Object.freeze(Array.from(new Set(ordered.map((descriptor) => descriptor.runtime.globalObjectKey))));
74
392
  }
75
- function serializeJson(data, options) {
76
- return JSON.stringify(data, options?.replacer ?? null, options?.spaces);
393
+ const ORDERED_RUNTIME_GLOBAL_KEYS_BY_RESOLVE_PRIORITY = getOrderedRuntimeGlobalKeysByPriority("globalResolvePriority");
394
+ const ORDERED_RUNTIME_GLOBAL_KEYS_BY_ROUTE_PRIORITY = getOrderedRuntimeGlobalKeysByPriority("routeGlobalResolvePriority");
395
+ /**
396
+ * @description 小程序平台别名映射表。
397
+ */
398
+ const MINI_PROGRAM_PLATFORM_ALIASES = Object.freeze(Object.fromEntries(MINI_PROGRAM_PLATFORM_ALIAS_TO_ID.entries()));
399
+ /**
400
+ * @description 标准化平台输入。
401
+ */
402
+ function normalizeMiniProgramPlatform(input) {
403
+ return input?.trim().toLowerCase() || void 0;
77
404
  }
78
- async function pathExists(target) {
79
- try {
80
- await promises.access(target);
81
- return true;
82
- } catch {
83
- return false;
84
- }
405
+ /**
406
+ * @description 解析平台输入到标准平台标识。
407
+ */
408
+ function resolveMiniProgramPlatform(input) {
409
+ const normalized = normalizeMiniProgramPlatform(input);
410
+ if (!normalized) return;
411
+ return MINI_PROGRAM_PLATFORM_ALIAS_TO_ID.get(normalized);
85
412
  }
86
- function pathExistsSync(target) {
87
- try {
88
- return existsSync(target);
89
- } catch {
90
- return false;
91
- }
413
+ /**
414
+ * @description 返回所有受支持的小程序平台。
415
+ */
416
+ function getSupportedMiniProgramPlatforms() {
417
+ return SUPPORTED_MINI_PROGRAM_PLATFORMS;
92
418
  }
93
- async function exists(target) {
94
- return pathExists(target);
419
+ /**
420
+ * @description 返回所有受支持的小程序模板指令前缀。
421
+ */
422
+ function getSupportedMiniProgramDirectivePrefixes() {
423
+ return SUPPORTED_MINI_PROGRAM_DIRECTIVE_PREFIXES;
95
424
  }
96
- async function ensureDir(dir) {
97
- await promises.mkdir(dir, { recursive: true });
425
+ /**
426
+ * @description 返回默认小程序平台。
427
+ */
428
+ function getDefaultMiniProgramPlatform() {
429
+ return SUPPORTED_MINI_PROGRAM_PLATFORMS[0] ?? "weapp";
98
430
  }
99
- async function ensureFile(file) {
100
- await ensureDir(path.dirname(file));
101
- await (await promises.open(file, "a")).close();
431
+ /**
432
+ * @description 获取平台描述。
433
+ */
434
+ function getMiniProgramPlatformDescriptor(platform) {
435
+ const descriptor = MINI_PROGRAM_PLATFORM_DESCRIPTOR_BY_ID.get(platform);
436
+ if (!descriptor) throw new Error(`不支持的小程序平台 "${platform}"。`);
437
+ return descriptor;
102
438
  }
103
- async function remove(target) {
104
- await promises.rm(target, {
105
- force: true,
106
- recursive: true
107
- });
439
+ /**
440
+ * @description 获取模板编译预设。
441
+ */
442
+ function getMiniProgramTemplatePreset(platform) {
443
+ if (!platform) return "wechat";
444
+ return getMiniProgramPlatformDescriptor(platform).compiler?.templatePreset ?? "wechat";
108
445
  }
109
- async function ensureSymlink(target, file) {
110
- await ensureDir(path.dirname(file));
111
- try {
112
- if (await promises.readlink(file) === target) return;
113
- await remove(file);
114
- } catch (error) {
115
- if (error?.code !== "ENOENT") throw error;
116
- }
117
- await promises.symlink(target, file);
118
- }
119
- async function emptyDir(dir) {
120
- await ensureDir(dir);
121
- const entries = await promises.readdir(dir, { withFileTypes: true });
122
- await Promise.all(entries.map((entry) => {
123
- return remove(path.join(dir, entry.name));
124
- }));
125
- }
126
- async function outputFile(file, data, options) {
127
- await ensureDir(path.dirname(file));
128
- await promises.writeFile(file, data, options);
129
- }
130
- async function appendFile(file, data, options) {
131
- await ensureDir(path.dirname(file));
132
- await promises.appendFile(file, data, options);
133
- }
134
- async function writeJson(file, data, options) {
135
- const source = serializeJson(data, options);
136
- await promises.writeFile(file, source, normalizeJsonEncoding(options?.encoding));
137
- }
138
- async function writeJSON(file, data, options) {
139
- await writeJson(file, data, options);
140
- }
141
- async function outputJson(file, data, options) {
142
- await ensureDir(path.dirname(file));
143
- await writeJson(file, data, options);
144
- }
145
- async function outputJSON(file, data, options) {
146
- await outputJson(file, data, options);
147
- }
148
- async function readJson(file, options) {
149
- try {
150
- const source = await promises.readFile(file, normalizeJsonEncoding(options?.encoding));
151
- return JSON.parse(normalizeJsonText(source));
152
- } catch (error) {
153
- if (options?.throws === false && error instanceof SyntaxError) return null;
154
- throw error;
155
- }
446
+ /**
447
+ * @description 判断平台是否允许自动补齐 app 样式入口。
448
+ */
449
+ function supportsMiniProgramAutoTouchAppStyle(platform) {
450
+ if (!platform) return false;
451
+ return getMiniProgramPlatformDescriptor(platform).build?.autoTouchAppStyle === true;
156
452
  }
157
- async function readJSON(file, options) {
158
- return readJson(file, options);
453
+ /**
454
+ * @description 获取平台默认构建目标。
455
+ */
456
+ function getMiniProgramDefaultBuildTarget(platform) {
457
+ if (!platform) return;
458
+ return getMiniProgramPlatformDescriptor(platform).build?.defaultBuildTarget;
159
459
  }
160
- function readJsonSync(file, options) {
161
- try {
162
- const source = readFileSync(file, normalizeJsonEncoding(options?.encoding));
163
- return JSON.parse(normalizeJsonText(source));
164
- } catch (error) {
165
- if (options?.throws === false && error instanceof SyntaxError) return null;
166
- throw error;
167
- }
460
+ /**
461
+ * @description 获取平台默认使用的类型包。
462
+ */
463
+ function getMiniProgramAppTypesPackage(platform) {
464
+ return getMiniProgramPlatformDescriptor(platform ?? getDefaultMiniProgramPlatform()).typescript?.appTypesPackage ?? "miniprogram-api-typings";
168
465
  }
169
- async function copy(src, dest, options) {
170
- await promises.cp(src, dest, {
171
- ...typeof options?.dereference === "boolean" ? { dereference: options.dereference } : {},
172
- ...typeof options?.errorOnExist === "boolean" ? { errorOnExist: options.errorOnExist } : {},
173
- ...typeof options?.filter === "function" ? { filter: options.filter } : {},
174
- ...typeof options?.preserveTimestamps === "boolean" ? { preserveTimestamps: options.preserveTimestamps } : {},
175
- ...typeof options?.verbatimSymlinks === "boolean" ? { verbatimSymlinks: options.verbatimSymlinks } : {},
176
- force: options?.overwrite ?? true,
177
- recursive: true
178
- });
466
+ /**
467
+ * @description 获取平台模板指令前缀。
468
+ */
469
+ function getMiniProgramDirectivePrefix(platform) {
470
+ if (!platform) return "wx";
471
+ return getMiniProgramPlatformDescriptor(platform).wxml?.directivePrefix ?? "wx";
472
+ }
473
+ /**
474
+ * @description 获取宿主全局对象 key。
475
+ */
476
+ function getMiniProgramRuntimeGlobalKey(platform) {
477
+ return getMiniProgramPlatformDescriptor(platform).runtime.globalObjectKey;
478
+ }
479
+ /**
480
+ * @description 获取默认宿主全局对象 key。
481
+ */
482
+ function getDefaultMiniProgramRuntimeGlobalKey() {
483
+ return ORDERED_RUNTIME_GLOBAL_KEYS[0] ?? "wx";
484
+ }
485
+ /**
486
+ * @description 解析宿主全局对象 key 对应的平台。
487
+ */
488
+ function getMiniProgramPlatformByRuntimeGlobalKey(globalObjectKey) {
489
+ const normalized = globalObjectKey?.trim();
490
+ if (!normalized) return;
491
+ return MINI_PROGRAM_RUNTIME_GLOBAL_KEY_TO_ID.get(normalized);
492
+ }
493
+ /**
494
+ * @description 返回 runtime 全局对象 key 的扫描优先级。
495
+ */
496
+ function getMiniProgramRuntimeGlobalKeys(platform) {
497
+ if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
498
+ return ORDERED_RUNTIME_GLOBAL_KEYS;
179
499
  }
180
- async function move(src, dest, options) {
181
- if (src === dest) return;
182
- if (await pathExists(dest)) {
183
- if (!options?.overwrite) {
184
- const error = /* @__PURE__ */ new Error(`dest already exists: ${dest}`);
185
- error.code = "EEXIST";
186
- throw error;
500
+ /**
501
+ * @description 返回按通用解析优先级排序的 runtime 全局对象 key。
502
+ */
503
+ function getMiniProgramRuntimeGlobalKeysByResolvePriority(platform) {
504
+ if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
505
+ return ORDERED_RUNTIME_GLOBAL_KEYS_BY_RESOLVE_PRIORITY;
506
+ }
507
+ /**
508
+ * @description 返回按路由解析优先级排序的 runtime 全局对象 key。
509
+ */
510
+ function getMiniProgramRouteRuntimeGlobalKeys(platform) {
511
+ if (platform) return [getMiniProgramRuntimeGlobalKey(platform)];
512
+ return ORDERED_RUNTIME_GLOBAL_KEYS_BY_ROUTE_PRIORITY;
513
+ }
514
+ /**
515
+ * @description 获取平台 runtime 宿主配置 key。
516
+ */
517
+ function getMiniProgramRuntimeHostConfigKey(platform) {
518
+ if (!platform) return "__wxConfig";
519
+ return getMiniProgramPlatformDescriptor(platform).runtime.hostConfigKey;
520
+ }
521
+ /**
522
+ * @description 获取平台 runtime 能力描述。
523
+ */
524
+ function getMiniProgramRuntimeCapabilities(platform) {
525
+ if (!platform) return DEFAULT_RUNTIME_CAPABILITIES;
526
+ return getMiniProgramPlatformDescriptor(platform).runtime.capabilities;
527
+ }
528
+ /**
529
+ * @description 判断平台是否支持指定 runtime 能力。
530
+ */
531
+ function supportsMiniProgramRuntimeCapability(platform, capabilityName) {
532
+ return getMiniProgramRuntimeCapabilities(platform)[capabilityName] === true;
533
+ }
534
+ function serializeMiniProgramPageIdentityRule(rule) {
535
+ return rule.source === "field" ? `${rule.prefix}:${rule.field ?? ""}` : `${rule.prefix}:route`;
536
+ }
537
+ function getMiniProgramPageIdentityRules(platform) {
538
+ if (platform) return getMiniProgramPlatformDescriptor(platform).runtime.pageIdentityRules;
539
+ const merged = /* @__PURE__ */ new Map();
540
+ for (const descriptor of MINI_PROGRAM_PLATFORM_DESCRIPTORS) for (const rule of descriptor.runtime.pageIdentityRules) merged.set(serializeMiniProgramPageIdentityRule(rule), rule);
541
+ return [...merged.values()];
542
+ }
543
+ /**
544
+ * @description 根据平台描述解析页面身份 key。
545
+ */
546
+ function resolveMiniProgramPageKeys(page, platform) {
547
+ if (!page || typeof page !== "object") return [];
548
+ const keys = [];
549
+ for (const rule of getMiniProgramPageIdentityRules(platform)) {
550
+ if (rule.source === "route") {
551
+ const route = typeof page.route === "string" ? page.route.replace(LEADING_SLASH_RE, "") : "";
552
+ if (route) keys.push(`${rule.prefix}:${route}`);
553
+ continue;
187
554
  }
188
- await remove(dest);
189
- }
190
- await ensureDir(path.dirname(dest));
191
- try {
192
- await promises.rename(src, dest);
193
- } catch (error) {
194
- if (error?.code !== "EXDEV") throw error;
195
- await copy(src, dest, { overwrite: options?.overwrite ?? true });
196
- await remove(src);
555
+ const field = rule.field;
556
+ if (!field) continue;
557
+ const value = page[field];
558
+ if (typeof value === "number" || typeof value === "string") keys.push(`${rule.prefix}:${String(value)}`);
197
559
  }
560
+ return Array.from(new Set(keys));
198
561
  }
199
- async function close$1(handle) {
200
- if (typeof handle === "number") {
201
- await new Promise((resolve, reject) => {
202
- close(handle, (error) => {
203
- if (error) {
204
- reject(error);
205
- return;
206
- }
207
- resolve();
208
- });
209
- });
210
- return;
211
- }
212
- await handle.close();
213
- }
214
- const fs = {
215
- Dirent,
216
- Stats,
217
- access: promises.access,
218
- appendFile,
219
- close: close$1,
220
- closeSync,
221
- constants,
222
- copy,
223
- emptyDir,
224
- ensureDir,
225
- ensureFile,
226
- ensureSymlink,
227
- exists,
228
- existsSync,
229
- mkdir: promises.mkdir,
230
- mkdirSync,
231
- mkdtemp: promises.mkdtemp,
232
- move,
233
- open: (file, flags) => promises.open(file, flags),
234
- openSync,
235
- outputFile,
236
- outputJSON,
237
- outputJson,
238
- pathExists,
239
- pathExistsSync,
240
- readFile: promises.readFile,
241
- readFileSync,
242
- readJSON,
243
- readJson,
244
- readJsonSync,
245
- readdir: promises.readdir,
246
- rm: promises.rm,
247
- remove,
248
- stat: promises.stat,
249
- symlink: promises.symlink,
250
- unlinkSync,
251
- utimes: promises.utimes,
252
- utimesSync,
253
- watch,
254
- writeFile: promises.writeFile,
255
- writeFileSync,
256
- writeJSON,
257
- writeJson
258
- };
259
562
  //#endregion
260
563
  //#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
261
564
  var __defProp = Object.defineProperty;
@@ -485,33 +788,9 @@ const SPECIAL_CHARS_RE = /[|\\{}()[\]^$+*?.]/g;
485
788
  const HYPHEN_RE = /-/g;
486
789
  const LAST_EXT_RE = /\.[^/.]+$/;
487
790
  const ALL_EXT_RE = /(\.[^/.]+)+$/;
488
- function stableSerialize(value, seen = /* @__PURE__ */ new Map()) {
489
- if (value === null) return "null";
490
- switch (typeof value) {
491
- case "undefined": return "undefined";
492
- case "string": return JSON.stringify(value);
493
- case "number":
494
- if (Number.isNaN(value)) return "number:NaN";
495
- if (!Number.isFinite(value)) return `number:${value > 0 ? "Infinity" : "-Infinity"}`;
496
- if (Object.is(value, -0)) return "number:-0";
497
- return `number:${value}`;
498
- case "bigint": return `bigint:${value.toString()}`;
499
- case "boolean": return `boolean:${value}`;
500
- case "symbol": return `symbol:${String(value)}`;
501
- case "function": return `function:${value.toString()}`;
502
- }
503
- if (value instanceof Date) return `date:${value.toISOString()}`;
504
- if (value instanceof RegExp) return `regexp:${value.toString()}`;
505
- if (ArrayBuffer.isView(value)) return `${value.constructor.name}:${Buffer$1.from(value.buffer, value.byteOffset, value.byteLength).toString("hex")}`;
506
- if (value instanceof ArrayBuffer) return `ArrayBuffer:${Buffer$1.from(value).toString("hex")}`;
507
- if (seen.has(value)) return `circular:${seen.get(value)}`;
508
- seen.set(value, seen.size);
509
- if (Array.isArray(value)) return `[${value.map((item) => stableSerialize(item, seen)).join(",")}]`;
510
- if (value instanceof Set) return `Set(${Array.from(value, (item) => stableSerialize(item, seen)).join(",")})`;
511
- if (value instanceof Map) return `Map(${Array.from(value.entries(), ([key, item]) => [stableSerialize(key, seen), stableSerialize(item, seen)]).sort(([left], [right]) => left.localeCompare(right)).map(([key, item]) => `${key}=>${item}`).join(",")})`;
512
- return `{${Reflect.ownKeys(value).sort((left, right) => String(left).localeCompare(String(right))).map((key) => {
513
- return `${stableSerialize(key, seen)}:${stableSerialize(value[key], seen)}`;
514
- }).join(",")}}`;
791
+ function hasExtension(filename) {
792
+ const lastSlashIndex = Math.max(filename.lastIndexOf("/"), filename.lastIndexOf("\\"));
793
+ return (lastSlashIndex >= 0 ? filename.slice(lastSlashIndex + 1) : filename).lastIndexOf(".") > 0;
515
794
  }
516
795
  /**
517
796
  * @description 转义字符串中的正则特殊字符
@@ -536,7 +815,7 @@ function removeExtensionDeep(file) {
536
815
  */
537
816
  function addExtension(filename, ext = ".js") {
538
817
  let result = `${filename}`;
539
- if (!extname(filename)) result += ext;
818
+ if (!hasExtension(filename)) result += ext;
540
819
  return result;
541
820
  }
542
821
  /**
@@ -572,12 +851,6 @@ function isEmptyObject(obj) {
572
851
  }
573
852
  return false;
574
853
  }
575
- /**
576
- * @description 生成稳定对象哈希,避免依赖已被禁用的 object-hash 包
577
- */
578
- function objectHash(value) {
579
- return createHash("sha256").update(stableSerialize(value)).digest("hex");
580
- }
581
854
  //#endregion
582
855
  var set = import_set_value.default;
583
- export { addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, fs, index_default as get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set };
856
+ export { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, index_default as get, getDefaultMiniProgramPlatform, getDefaultMiniProgramRuntimeGlobalKey, getMiniProgramAppTypesPackage, getMiniProgramDefaultBuildTarget, getMiniProgramDirectivePrefix, getMiniProgramPlatformByRuntimeGlobalKey, getMiniProgramPlatformDescriptor, getMiniProgramRouteRuntimeGlobalKeys, getMiniProgramRuntimeCapabilities, getMiniProgramRuntimeGlobalKey, getMiniProgramRuntimeGlobalKeys, getMiniProgramRuntimeGlobalKeysByResolvePriority, getMiniProgramRuntimeHostConfigKey, getMiniProgramTemplatePreset, getSupportedMiniProgramDirectivePrefixes, getSupportedMiniProgramPlatforms, isEmptyObject, isObject, normalizeMiniProgramPlatform, removeExtension, removeExtensionDeep, resolveMiniProgramPageKeys, resolveMiniProgramPlatform, set, supportsMiniProgramAutoTouchAppStyle, supportsMiniProgramRuntimeCapability };