@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.d.ts CHANGED
@@ -1,8 +1,6 @@
1
- import { Dirent, Stats, closeSync, constants, existsSync, mkdirSync, openSync, promises, readFileSync, unlinkSync, utimesSync, watch, writeFileSync } from "node:fs";
2
- import { FileHandle, OpenMode, PathLike } from "node:fs/promises";
3
1
  import set from "set-value";
4
2
 
5
- //#region ../../node_modules/.pnpm/defu@6.1.6/node_modules/defu/dist/defu.d.mts
3
+ //#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.d.mts
6
4
  type Input = Record<string | number | symbol, any>;
7
5
  type IgnoredInput = boolean | number | null | any[] | Record<never, any> | undefined;
8
6
  type Merger = <T extends Input, K extends keyof T>(object: T, key: keyof T, value: T[K], namespace: string) => any;
@@ -20,94 +18,314 @@ type MergeArrays<Destination, Source> = Destination extends Array<infer Destinat
20
18
  type Merge<Destination extends Input, Defaults extends Input> = Destination extends nullish ? Defaults extends nullish ? nullish : Defaults : Defaults extends nullish ? Destination : Destination extends Array<any> ? Defaults extends Array<any> ? MergeArrays<Destination, Defaults> : Destination | Defaults : Destination extends Function ? Destination | Defaults : Destination extends RegExp ? Destination | Defaults : Destination extends Promise<any> ? Destination | Defaults : Defaults extends Function ? Destination | Defaults : Defaults extends RegExp ? Destination | Defaults : Defaults extends Promise<any> ? Destination | Defaults : Destination extends Input ? Defaults extends Input ? MergeObjects<Destination, Defaults> : Destination | Defaults : Destination | Defaults;
21
19
  declare const defu: DefuInstance;
22
20
  //#endregion
23
- //#region src/fs/index.d.ts
24
- interface JsonReadOptions {
25
- encoding?: BufferEncoding;
26
- throws?: boolean;
21
+ //#region src/platforms/types.d.ts
22
+ type MpPlatform = 'weapp' | 'alipay' | 'tt' | 'swan' | 'jd' | 'xhs';
23
+ type MiniProgramTemplatePreset = 'wechat' | 'alipay' | 'tt' | 'swan';
24
+ type MiniProgramPlatformFamily = 'wechat' | 'alipay' | 'tt' | 'swan';
25
+ interface OutputExtensions {
26
+ js: string;
27
+ json: string;
28
+ wxml: string;
29
+ wxss: string;
30
+ wxs?: string;
27
31
  }
28
- interface JsonWriteOptions {
29
- encoding?: BufferEncoding;
30
- replacer?: ((this: any, key: string, value: any) => any) | Array<number | string> | null;
31
- spaces?: number | string;
32
+ interface MiniProgramPageIdentityRule {
33
+ /**
34
+ * @description 注册 layout bridge 等页面级能力时使用的 key 前缀。
35
+ */
36
+ prefix: string;
37
+ /**
38
+ * @description 页面 key 的来源类型:字段或 route。
39
+ */
40
+ source: 'field' | 'route';
41
+ /**
42
+ * @description 当来源类型为字段时使用的字段名。
43
+ */
44
+ field?: string;
32
45
  }
33
- interface CopyOptions {
34
- dereference?: boolean;
35
- errorOnExist?: boolean;
36
- filter?: (src: string, dest: string) => boolean | Promise<boolean>;
37
- overwrite?: boolean;
38
- preserveTimestamps?: boolean;
39
- verbatimSymlinks?: boolean;
46
+ interface MiniProgramRuntimeCapabilities {
47
+ /**
48
+ * @description 宿主是否支持全局 `getCurrentPages()` 页面栈读取。
49
+ */
50
+ globalPageStack: boolean;
51
+ /**
52
+ * @description 宿主是否支持从全局对象创建 `SelectorQuery`。
53
+ */
54
+ globalCreateSelectorQuery: boolean;
55
+ /**
56
+ * @description 全局 `createSelectorQuery()` 是否需要通过 `.in(instance)` 绑定作用域。
57
+ */
58
+ selectorQueryScopeByIn: boolean;
59
+ /**
60
+ * @description 宿主是否支持从全局对象创建 `IntersectionObserver`。
61
+ */
62
+ globalCreateIntersectionObserver: boolean;
63
+ /**
64
+ * @description 全局 `createIntersectionObserver()` 是否要求将实例作为首个参数传入。
65
+ */
66
+ intersectionObserverScopeByParameter: boolean;
67
+ /**
68
+ * @description 宿主是否支持页面分享菜单能力。
69
+ */
70
+ pageShareMenu: boolean;
71
+ /**
72
+ * @description 时间线分享是否要求同时展示 `shareAppMessage`。
73
+ */
74
+ shareTimelineRequiresShareAppMessage: boolean;
75
+ /**
76
+ * @description 宿主是否支持通过全局 `pageScrollTo` 做页面滚动桥接。
77
+ */
78
+ pageScrollApi: boolean;
79
+ /**
80
+ * @description 宿主是否支持通过全局 `startPullDownRefresh` 做下拉刷新桥接。
81
+ */
82
+ pullDownRefreshApi: boolean;
83
+ /**
84
+ * @description 宿主是否支持通过全局对象调用 `navigateTo` / `redirectTo` 等路由 API。
85
+ */
86
+ globalRouterApi: boolean;
87
+ /**
88
+ * @description 宿主是否支持 App 级 `onError/offError` 监听。
89
+ */
90
+ appErrorListener: boolean;
91
+ /**
92
+ * @description 宿主是否支持 App 级 `onPageNotFound/offPageNotFound` 监听。
93
+ */
94
+ appPageNotFoundListener: boolean;
95
+ /**
96
+ * @description 宿主是否支持 App 级 `onUnhandledRejection/offUnhandledRejection` 监听。
97
+ */
98
+ appUnhandledRejectionListener: boolean;
99
+ /**
100
+ * @description 宿主是否支持 App 级 `onThemeChange/offThemeChange` 监听。
101
+ */
102
+ appThemeChangeListener: boolean;
103
+ /**
104
+ * @description 宿主是否支持 App 级 `onMemoryWarning/offMemoryWarning` 监听。
105
+ */
106
+ appMemoryWarningListener: boolean;
40
107
  }
41
- interface MoveOptions {
42
- overwrite?: boolean;
108
+ type MiniProgramRuntimeCapabilityName = keyof MiniProgramRuntimeCapabilities;
109
+ interface MiniProgramPlatformDescriptor {
110
+ /**
111
+ * @description 构建流程中使用的标准平台标识。
112
+ */
113
+ id: MpPlatform;
114
+ /**
115
+ * @description 用于日志/诊断/工具展示的可读名称。
116
+ */
117
+ displayName: string;
118
+ /**
119
+ * @description 平台所属语义族群,用于模板与 runtime 默认策略复用。
120
+ */
121
+ family: MiniProgramPlatformFamily;
122
+ /**
123
+ * @description 需要映射到该平台的别名列表。
124
+ */
125
+ aliases: readonly string[];
126
+ /**
127
+ * @description 编译产物应输出的文件扩展名。
128
+ */
129
+ outputExtensions: OutputExtensions;
130
+ /**
131
+ * @description IDE 项目配置文件名。
132
+ */
133
+ projectConfigFileName: string;
134
+ /**
135
+ * @description 项目根目录候选字段,按优先级排序。
136
+ */
137
+ projectConfigRootKeys: readonly string[];
138
+ /**
139
+ * @description 不同脚本模块扩展名对应的模板标签名。
140
+ */
141
+ scriptModuleTagByExtension?: Readonly<Partial<Record<string, string>>>;
142
+ /**
143
+ * @description 是否使用项目根目录作为 npm 产物目录基准。
144
+ */
145
+ usesProjectRootNpmDir?: boolean;
146
+ /**
147
+ * @description IDE 打开项目时的平台级默认行为。
148
+ */
149
+ ide?: {
150
+ requiresOpenPlatformArg?: boolean;
151
+ defaultProjectRoot?: string;
152
+ };
153
+ /**
154
+ * @description 构建流程相关的平台静态能力。
155
+ */
156
+ build?: {
157
+ /**
158
+ * @description 是否允许在自动模式下补齐 app 样式入口,以支持样式 HMR 等行为。
159
+ */
160
+ autoTouchAppStyle?: boolean;
161
+ /**
162
+ * @description 平台默认使用的构建目标。
163
+ */
164
+ defaultBuildTarget?: string;
165
+ };
166
+ /**
167
+ * @description 构建清理时需要保留的 npm 产物目录名。
168
+ */
169
+ resolvePreservedNpmDirNames: (options?: {
170
+ alipayNpmMode?: string;
171
+ }) => readonly string[];
172
+ /**
173
+ * @description JSON 归一化相关的平台能力。
174
+ */
175
+ json?: {
176
+ normalizeUsingComponents?: boolean;
177
+ fillComponentGenericsDefault?: boolean;
178
+ rewriteBundleNpmImports?: boolean;
179
+ };
180
+ /**
181
+ * @description npm 构建相关的平台能力。
182
+ */
183
+ npm?: {
184
+ distDirName?: (options?: {
185
+ alipayNpmMode?: string;
186
+ }) => string;
187
+ normalizeImportPath?: boolean;
188
+ normalizeMiniprogramPackage?: boolean;
189
+ copyEsModuleDirectory?: boolean;
190
+ hoistNestedDependencies?: boolean;
191
+ shouldRebuildCachedPackage?: boolean;
192
+ };
193
+ /**
194
+ * @description WXML / 模板转换相关的平台能力。
195
+ */
196
+ wxml?: {
197
+ eventBindingStyle?: 'default' | 'alipay';
198
+ directivePrefix?: string;
199
+ normalizeComponentTagName?: boolean;
200
+ normalizeVueTemplate?: boolean;
201
+ emitGenericPlaceholder?: boolean;
202
+ };
203
+ /**
204
+ * @description 模板编译器使用的策略预设。
205
+ */
206
+ compiler?: {
207
+ templatePreset?: MiniProgramTemplatePreset;
208
+ };
209
+ /**
210
+ * @description TypeScript 支持相关的平台能力。
211
+ */
212
+ typescript?: {
213
+ appTypesPackage?: string;
214
+ };
215
+ /**
216
+ * @description 小程序宿主 runtime 相关的静态能力描述。
217
+ */
218
+ runtime: {
219
+ globalObjectKey: string;
220
+ hostConfigKey: string;
221
+ /**
222
+ * @description 通用全局对象解析优先级,值越小越先尝试。
223
+ */
224
+ globalResolvePriority?: number;
225
+ /**
226
+ * @description 路由全局对象解析优先级,值越小越先尝试。
227
+ */
228
+ routeGlobalResolvePriority?: number;
229
+ pageIdentityRules: readonly MiniProgramPageIdentityRule[];
230
+ capabilities: MiniProgramRuntimeCapabilities;
231
+ };
43
232
  }
44
- declare function pathExists(target: string): Promise<boolean>;
45
- declare function pathExistsSync(target: string): boolean;
46
- declare function exists(target: string): Promise<boolean>;
47
- declare function ensureDir(dir: string): Promise<void>;
48
- declare function ensureFile(file: string): Promise<void>;
49
- declare function remove(target: string): Promise<void>;
50
- declare function ensureSymlink(target: string, file: string): Promise<void>;
51
- declare function emptyDir(dir: string): Promise<void>;
52
- declare function outputFile(file: string, data: string | NodeJS.ArrayBufferView, options?: BufferEncoding): Promise<void>;
53
- declare function appendFile(file: string, data: string | NodeJS.ArrayBufferView, options?: BufferEncoding): Promise<void>;
54
- declare function writeJson(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
55
- declare function writeJSON(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
56
- declare function outputJson(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
57
- declare function outputJSON(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
58
- declare function readJson<T = unknown>(file: string, options?: JsonReadOptions): Promise<T | null>;
59
- declare function readJSON<T = unknown>(file: string, options?: JsonReadOptions): Promise<T | null>;
60
- declare function readJsonSync<T = unknown>(file: string, options?: JsonReadOptions): T | null;
61
- declare function copy(src: string, dest: string, options?: CopyOptions): Promise<void>;
62
- declare function move(src: string, dest: string, options?: MoveOptions): Promise<void>;
63
- declare function close$1(handle: number | FileHandle): Promise<void>;
64
- declare const fs: {
65
- Dirent: typeof Dirent;
66
- Stats: typeof Stats;
67
- access: typeof promises.access;
68
- appendFile: typeof appendFile;
69
- close: typeof close$1;
70
- closeSync: typeof closeSync;
71
- constants: typeof constants;
72
- copy: typeof copy;
73
- emptyDir: typeof emptyDir;
74
- ensureDir: typeof ensureDir;
75
- ensureFile: typeof ensureFile;
76
- ensureSymlink: typeof ensureSymlink;
77
- exists: typeof exists;
78
- existsSync: typeof existsSync;
79
- mkdir: typeof promises.mkdir;
80
- mkdirSync: typeof mkdirSync;
81
- mkdtemp: typeof promises.mkdtemp;
82
- move: typeof move;
83
- open: (file: PathLike, flags: OpenMode) => Promise<FileHandle>;
84
- openSync: typeof openSync;
85
- outputFile: typeof outputFile;
86
- outputJSON: typeof outputJSON;
87
- outputJson: typeof outputJson;
88
- pathExists: typeof pathExists;
89
- pathExistsSync: typeof pathExistsSync;
90
- readFile: typeof promises.readFile;
91
- readFileSync: typeof readFileSync;
92
- readJSON: typeof readJSON;
93
- readJson: typeof readJson;
94
- readJsonSync: typeof readJsonSync;
95
- readdir: typeof promises.readdir;
96
- rm: typeof promises.rm;
97
- remove: typeof remove;
98
- stat: typeof promises.stat;
99
- symlink: typeof promises.symlink;
100
- unlinkSync: typeof unlinkSync;
101
- utimes: typeof promises.utimes;
102
- utimesSync: typeof utimesSync;
103
- watch: typeof watch;
104
- writeFile: typeof promises.writeFile;
105
- writeFileSync: typeof writeFileSync;
106
- writeJSON: typeof writeJSON;
107
- writeJson: typeof writeJson;
108
- };
109
- type FsDirent = Dirent;
110
- type FsStats = Stats;
233
+ //#endregion
234
+ //#region src/platforms/descriptors.d.ts
235
+ /**
236
+ * @description 全仓库统一的小程序平台描述表。
237
+ */
238
+ declare const MINI_PROGRAM_PLATFORM_DESCRIPTORS: readonly MiniProgramPlatformDescriptor[];
239
+ //#endregion
240
+ //#region src/platforms/helpers.d.ts
241
+ /**
242
+ * @description 小程序平台别名映射表。
243
+ */
244
+ declare const MINI_PROGRAM_PLATFORM_ALIASES: Readonly<Record<string, MpPlatform>>;
245
+ /**
246
+ * @description 标准化平台输入。
247
+ */
248
+ declare function normalizeMiniProgramPlatform(input?: string | null): string | undefined;
249
+ /**
250
+ * @description 解析平台输入到标准平台标识。
251
+ */
252
+ declare function resolveMiniProgramPlatform(input?: string | null): MpPlatform | undefined;
253
+ /**
254
+ * @description 返回所有受支持的小程序平台。
255
+ */
256
+ declare function getSupportedMiniProgramPlatforms(): readonly MpPlatform[];
257
+ /**
258
+ * @description 返回所有受支持的小程序模板指令前缀。
259
+ */
260
+ declare function getSupportedMiniProgramDirectivePrefixes(): readonly string[];
261
+ /**
262
+ * @description 返回默认小程序平台。
263
+ */
264
+ declare function getDefaultMiniProgramPlatform(): MpPlatform;
265
+ /**
266
+ * @description 获取平台描述。
267
+ */
268
+ declare function getMiniProgramPlatformDescriptor(platform: MpPlatform): MiniProgramPlatformDescriptor;
269
+ /**
270
+ * @description 获取模板编译预设。
271
+ */
272
+ declare function getMiniProgramTemplatePreset(platform?: MpPlatform): MiniProgramTemplatePreset;
273
+ /**
274
+ * @description 判断平台是否允许自动补齐 app 样式入口。
275
+ */
276
+ declare function supportsMiniProgramAutoTouchAppStyle(platform?: MpPlatform): boolean;
277
+ /**
278
+ * @description 获取平台默认构建目标。
279
+ */
280
+ declare function getMiniProgramDefaultBuildTarget(platform?: MpPlatform): string | undefined;
281
+ /**
282
+ * @description 获取平台默认使用的类型包。
283
+ */
284
+ declare function getMiniProgramAppTypesPackage(platform?: MpPlatform): string;
285
+ /**
286
+ * @description 获取平台模板指令前缀。
287
+ */
288
+ declare function getMiniProgramDirectivePrefix(platform?: MpPlatform): string;
289
+ /**
290
+ * @description 获取宿主全局对象 key。
291
+ */
292
+ declare function getMiniProgramRuntimeGlobalKey(platform: MpPlatform): string;
293
+ /**
294
+ * @description 获取默认宿主全局对象 key。
295
+ */
296
+ declare function getDefaultMiniProgramRuntimeGlobalKey(): string;
297
+ /**
298
+ * @description 解析宿主全局对象 key 对应的平台。
299
+ */
300
+ declare function getMiniProgramPlatformByRuntimeGlobalKey(globalObjectKey?: string | null): MpPlatform | undefined;
301
+ /**
302
+ * @description 返回 runtime 全局对象 key 的扫描优先级。
303
+ */
304
+ declare function getMiniProgramRuntimeGlobalKeys(platform?: MpPlatform): readonly string[];
305
+ /**
306
+ * @description 返回按通用解析优先级排序的 runtime 全局对象 key。
307
+ */
308
+ declare function getMiniProgramRuntimeGlobalKeysByResolvePriority(platform?: MpPlatform): readonly string[];
309
+ /**
310
+ * @description 返回按路由解析优先级排序的 runtime 全局对象 key。
311
+ */
312
+ declare function getMiniProgramRouteRuntimeGlobalKeys(platform?: MpPlatform): readonly string[];
313
+ /**
314
+ * @description 获取平台 runtime 宿主配置 key。
315
+ */
316
+ declare function getMiniProgramRuntimeHostConfigKey(platform?: MpPlatform): string;
317
+ /**
318
+ * @description 获取平台 runtime 能力描述。
319
+ */
320
+ declare function getMiniProgramRuntimeCapabilities(platform?: MpPlatform): MiniProgramRuntimeCapabilities;
321
+ /**
322
+ * @description 判断平台是否支持指定 runtime 能力。
323
+ */
324
+ declare function supportsMiniProgramRuntimeCapability(platform: MpPlatform | undefined, capabilityName: MiniProgramRuntimeCapabilityName): boolean;
325
+ /**
326
+ * @description 根据平台描述解析页面身份 key。
327
+ */
328
+ declare function resolveMiniProgramPageKeys(page?: Record<string, any>, platform?: MpPlatform): string[];
111
329
  //#endregion
112
330
  //#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/index.d.ts
113
331
  declare function get<T>(obj: T): T;
@@ -188,9 +406,5 @@ declare function isObject(x: unknown): x is Record<string | symbol | number, unk
188
406
  * @description 判断对象是否为空对象
189
407
  */
190
408
  declare function isEmptyObject(obj: unknown): boolean;
191
- /**
192
- * @description 生成稳定对象哈希,避免依赖已被禁用的 object-hash 包
193
- */
194
- declare function objectHash(value: unknown): string;
195
409
  //#endregion
196
- export { CopyOptions, FsDirent, FsStats, JsonReadOptions, JsonWriteOptions, MoveOptions, addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, fs, get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set };
410
+ export { MINI_PROGRAM_PLATFORM_ALIASES, MINI_PROGRAM_PLATFORM_DESCRIPTORS, MiniProgramPageIdentityRule, MiniProgramPlatformDescriptor, MiniProgramPlatformFamily, MiniProgramRuntimeCapabilities, MiniProgramRuntimeCapabilityName, MiniProgramTemplatePreset, MpPlatform, OutputExtensions, addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, 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 };