@weapp-core/shared 3.0.2 → 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/README.md +5 -2
- package/dist/fs/index.d.ts +93 -0
- package/dist/fs/index.js +198 -0
- package/dist/index.d.ts +312 -12
- package/dist/index.js +508 -7
- package/dist/node.d.ts +9 -0
- package/dist/node.js +61 -0
- package/package.json +18 -4
package/README.md
CHANGED
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
## 简介
|
|
4
4
|
|
|
5
5
|
`@weapp-core/shared` 汇总 weapp-vite 生态内的通用工具函数与依赖封装,供多个包复用。
|
|
6
|
+
根入口默认保持小程序运行时安全;Node 专用能力通过独立子入口导出。
|
|
6
7
|
|
|
7
8
|
## 特性
|
|
8
9
|
|
|
9
10
|
- 常用字符串与路径处理工具
|
|
10
11
|
- 对象合并与判定工具
|
|
11
|
-
- 统一导出常用第三方工具(`defu`、`get`、`set
|
|
12
|
+
- 统一导出常用第三方工具(`defu`、`get`、`set`)
|
|
13
|
+
- 通过 `@weapp-core/shared/node` 提供 Node 专用哈希与文件系统能力
|
|
12
14
|
|
|
13
15
|
## 安装
|
|
14
16
|
|
|
@@ -23,13 +25,14 @@ import {
|
|
|
23
25
|
addExtension,
|
|
24
26
|
defu,
|
|
25
27
|
escapeStringRegexp,
|
|
26
|
-
objectHash,
|
|
27
28
|
removeExtension,
|
|
28
29
|
} from '@weapp-core/shared'
|
|
30
|
+
import { fs, objectHash } from '@weapp-core/shared/node'
|
|
29
31
|
|
|
30
32
|
const name = addExtension('pages/index/index')
|
|
31
33
|
const cleaned = removeExtension('app.json')
|
|
32
34
|
const hash = objectHash({ foo: 'bar' })
|
|
35
|
+
const exists = await fs.pathExists('app.json')
|
|
33
36
|
```
|
|
34
37
|
|
|
35
38
|
## 配置
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { Dirent, OpenMode, PathLike, Stats, closeSync, constants, existsSync, mkdirSync, openSync, promises, readFileSync, unlinkSync, utimesSync, watch, writeFileSync } from "node:fs";
|
|
2
|
+
import { FileHandle } from "node:fs/promises";
|
|
3
|
+
|
|
4
|
+
//#region src/fs/index.d.ts
|
|
5
|
+
interface JsonReadOptions {
|
|
6
|
+
encoding?: BufferEncoding;
|
|
7
|
+
throws?: boolean;
|
|
8
|
+
}
|
|
9
|
+
interface JsonWriteOptions {
|
|
10
|
+
encoding?: BufferEncoding;
|
|
11
|
+
replacer?: ((this: any, key: string, value: any) => any) | Array<number | string> | null;
|
|
12
|
+
spaces?: number | string;
|
|
13
|
+
}
|
|
14
|
+
interface CopyOptions {
|
|
15
|
+
dereference?: boolean;
|
|
16
|
+
errorOnExist?: boolean;
|
|
17
|
+
filter?: (src: string, dest: string) => boolean | Promise<boolean>;
|
|
18
|
+
overwrite?: boolean;
|
|
19
|
+
preserveTimestamps?: boolean;
|
|
20
|
+
verbatimSymlinks?: boolean;
|
|
21
|
+
}
|
|
22
|
+
interface MoveOptions {
|
|
23
|
+
overwrite?: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare function pathExists(target: string): Promise<boolean>;
|
|
26
|
+
declare function pathExistsSync(target: string): boolean;
|
|
27
|
+
declare function exists(target: string): Promise<boolean>;
|
|
28
|
+
declare function ensureDir(dir: string): Promise<void>;
|
|
29
|
+
declare function ensureFile(file: string): Promise<void>;
|
|
30
|
+
declare function remove(target: string): Promise<void>;
|
|
31
|
+
declare function ensureSymlink(target: string, file: string): Promise<void>;
|
|
32
|
+
declare function emptyDir(dir: string): Promise<void>;
|
|
33
|
+
declare function outputFile(file: string, data: string | NodeJS.ArrayBufferView, options?: BufferEncoding): Promise<void>;
|
|
34
|
+
declare function appendFile(file: string, data: string | NodeJS.ArrayBufferView, options?: BufferEncoding): Promise<void>;
|
|
35
|
+
declare function writeJson(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
|
|
36
|
+
declare function writeJSON(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
|
|
37
|
+
declare function outputJson(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
|
|
38
|
+
declare function outputJSON(file: string, data: unknown, options?: JsonWriteOptions): Promise<void>;
|
|
39
|
+
declare function readJson<T = unknown>(file: string, options?: JsonReadOptions): Promise<T | null>;
|
|
40
|
+
declare function readJSON<T = unknown>(file: string, options?: JsonReadOptions): Promise<T | null>;
|
|
41
|
+
declare function readJsonSync<T = unknown>(file: string, options?: JsonReadOptions): T | null;
|
|
42
|
+
declare function copy(src: string, dest: string, options?: CopyOptions): Promise<void>;
|
|
43
|
+
declare function move(src: string, dest: string, options?: MoveOptions): Promise<void>;
|
|
44
|
+
declare function close$1(handle: number | FileHandle): Promise<void>;
|
|
45
|
+
declare const fs: {
|
|
46
|
+
Dirent: typeof Dirent;
|
|
47
|
+
Stats: typeof Stats;
|
|
48
|
+
access: typeof promises.access;
|
|
49
|
+
appendFile: typeof appendFile;
|
|
50
|
+
close: typeof close$1;
|
|
51
|
+
closeSync: typeof closeSync;
|
|
52
|
+
constants: typeof constants;
|
|
53
|
+
copy: typeof copy;
|
|
54
|
+
emptyDir: typeof emptyDir;
|
|
55
|
+
ensureDir: typeof ensureDir;
|
|
56
|
+
ensureFile: typeof ensureFile;
|
|
57
|
+
ensureSymlink: typeof ensureSymlink;
|
|
58
|
+
exists: typeof exists;
|
|
59
|
+
existsSync: typeof existsSync;
|
|
60
|
+
mkdir: typeof promises.mkdir;
|
|
61
|
+
mkdirSync: typeof mkdirSync;
|
|
62
|
+
mkdtemp: typeof promises.mkdtemp;
|
|
63
|
+
move: typeof move;
|
|
64
|
+
open: (file: PathLike, flags: OpenMode) => Promise<FileHandle>;
|
|
65
|
+
openSync: typeof openSync;
|
|
66
|
+
outputFile: typeof outputFile;
|
|
67
|
+
outputJSON: typeof outputJSON;
|
|
68
|
+
outputJson: typeof outputJson;
|
|
69
|
+
pathExists: typeof pathExists;
|
|
70
|
+
pathExistsSync: typeof pathExistsSync;
|
|
71
|
+
readFile: typeof promises.readFile;
|
|
72
|
+
readFileSync: typeof readFileSync;
|
|
73
|
+
readJSON: typeof readJSON;
|
|
74
|
+
readJson: typeof readJson;
|
|
75
|
+
readJsonSync: typeof readJsonSync;
|
|
76
|
+
readdir: typeof promises.readdir;
|
|
77
|
+
rm: typeof promises.rm;
|
|
78
|
+
remove: typeof remove;
|
|
79
|
+
stat: typeof promises.stat;
|
|
80
|
+
symlink: typeof promises.symlink;
|
|
81
|
+
unlinkSync: typeof unlinkSync;
|
|
82
|
+
utimes: typeof promises.utimes;
|
|
83
|
+
utimesSync: typeof utimesSync;
|
|
84
|
+
watch: typeof watch;
|
|
85
|
+
writeFile: typeof promises.writeFile;
|
|
86
|
+
writeFileSync: typeof writeFileSync;
|
|
87
|
+
writeJSON: typeof writeJSON;
|
|
88
|
+
writeJson: typeof writeJson;
|
|
89
|
+
};
|
|
90
|
+
type FsDirent = Dirent;
|
|
91
|
+
type FsStats = Stats;
|
|
92
|
+
//#endregion
|
|
93
|
+
export { CopyOptions, FsDirent, FsStats, JsonReadOptions, JsonWriteOptions, MoveOptions, fs };
|
package/dist/fs/index.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { Dirent, Stats, close, closeSync, constants, existsSync, mkdirSync, openSync, promises, readFileSync, unlinkSync, utimesSync, watch, writeFileSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/fs/index.ts
|
|
4
|
+
function normalizeJsonEncoding(encoding) {
|
|
5
|
+
return encoding ?? "utf8";
|
|
6
|
+
}
|
|
7
|
+
function normalizeJsonText(source) {
|
|
8
|
+
return source.charCodeAt(0) === 65279 ? source.slice(1) : source;
|
|
9
|
+
}
|
|
10
|
+
function serializeJson(data, options) {
|
|
11
|
+
const replacer = options?.replacer;
|
|
12
|
+
if (typeof replacer === "function") return JSON.stringify(data, replacer, options?.spaces);
|
|
13
|
+
if (Array.isArray(replacer)) return JSON.stringify(data, replacer, options?.spaces);
|
|
14
|
+
return JSON.stringify(data, null, options?.spaces);
|
|
15
|
+
}
|
|
16
|
+
async function pathExists(target) {
|
|
17
|
+
try {
|
|
18
|
+
await promises.access(target);
|
|
19
|
+
return true;
|
|
20
|
+
} catch {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function pathExistsSync(target) {
|
|
25
|
+
try {
|
|
26
|
+
return existsSync(target);
|
|
27
|
+
} catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function exists(target) {
|
|
32
|
+
return pathExists(target);
|
|
33
|
+
}
|
|
34
|
+
async function ensureDir(dir) {
|
|
35
|
+
await promises.mkdir(dir, { recursive: true });
|
|
36
|
+
}
|
|
37
|
+
async function ensureFile(file) {
|
|
38
|
+
await ensureDir(path.dirname(file));
|
|
39
|
+
await (await promises.open(file, "a")).close();
|
|
40
|
+
}
|
|
41
|
+
async function remove(target) {
|
|
42
|
+
await promises.rm(target, {
|
|
43
|
+
force: true,
|
|
44
|
+
recursive: true
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function ensureSymlink(target, file) {
|
|
48
|
+
await ensureDir(path.dirname(file));
|
|
49
|
+
try {
|
|
50
|
+
if (await promises.readlink(file) === target) return;
|
|
51
|
+
await remove(file);
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (error?.code !== "ENOENT") throw error;
|
|
54
|
+
}
|
|
55
|
+
await promises.symlink(target, file);
|
|
56
|
+
}
|
|
57
|
+
async function emptyDir(dir) {
|
|
58
|
+
await ensureDir(dir);
|
|
59
|
+
const entries = await promises.readdir(dir, { withFileTypes: true });
|
|
60
|
+
await Promise.all(entries.map((entry) => {
|
|
61
|
+
return remove(path.join(dir, entry.name));
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
async function outputFile(file, data, options) {
|
|
65
|
+
await ensureDir(path.dirname(file));
|
|
66
|
+
await promises.writeFile(file, data, options);
|
|
67
|
+
}
|
|
68
|
+
async function appendFile(file, data, options) {
|
|
69
|
+
await ensureDir(path.dirname(file));
|
|
70
|
+
await promises.appendFile(file, data, options);
|
|
71
|
+
}
|
|
72
|
+
async function writeJson(file, data, options) {
|
|
73
|
+
const source = serializeJson(data, options);
|
|
74
|
+
await promises.writeFile(file, source, normalizeJsonEncoding(options?.encoding));
|
|
75
|
+
}
|
|
76
|
+
async function writeJSON(file, data, options) {
|
|
77
|
+
await writeJson(file, data, options);
|
|
78
|
+
}
|
|
79
|
+
async function outputJson(file, data, options) {
|
|
80
|
+
await ensureDir(path.dirname(file));
|
|
81
|
+
await writeJson(file, data, options);
|
|
82
|
+
}
|
|
83
|
+
async function outputJSON(file, data, options) {
|
|
84
|
+
await outputJson(file, data, options);
|
|
85
|
+
}
|
|
86
|
+
async function readJson(file, options) {
|
|
87
|
+
try {
|
|
88
|
+
const source = await promises.readFile(file, normalizeJsonEncoding(options?.encoding));
|
|
89
|
+
return JSON.parse(normalizeJsonText(source));
|
|
90
|
+
} catch (error) {
|
|
91
|
+
if (options?.throws === false && error instanceof SyntaxError) return null;
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async function readJSON(file, options) {
|
|
96
|
+
return readJson(file, options);
|
|
97
|
+
}
|
|
98
|
+
function readJsonSync(file, options) {
|
|
99
|
+
try {
|
|
100
|
+
const source = readFileSync(file, normalizeJsonEncoding(options?.encoding));
|
|
101
|
+
return JSON.parse(normalizeJsonText(source));
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (options?.throws === false && error instanceof SyntaxError) return null;
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
async function copy(src, dest, options) {
|
|
108
|
+
await promises.cp(src, dest, {
|
|
109
|
+
...typeof options?.dereference === "boolean" ? { dereference: options.dereference } : {},
|
|
110
|
+
...typeof options?.errorOnExist === "boolean" ? { errorOnExist: options.errorOnExist } : {},
|
|
111
|
+
...typeof options?.filter === "function" ? { filter: options.filter } : {},
|
|
112
|
+
...typeof options?.preserveTimestamps === "boolean" ? { preserveTimestamps: options.preserveTimestamps } : {},
|
|
113
|
+
...typeof options?.verbatimSymlinks === "boolean" ? { verbatimSymlinks: options.verbatimSymlinks } : {},
|
|
114
|
+
force: options?.overwrite ?? true,
|
|
115
|
+
recursive: true
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
async function move(src, dest, options) {
|
|
119
|
+
if (src === dest) return;
|
|
120
|
+
if (await pathExists(dest)) {
|
|
121
|
+
if (!options?.overwrite) {
|
|
122
|
+
const error = /* @__PURE__ */ new Error(`dest already exists: ${dest}`);
|
|
123
|
+
error.code = "EEXIST";
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
await remove(dest);
|
|
127
|
+
}
|
|
128
|
+
await ensureDir(path.dirname(dest));
|
|
129
|
+
try {
|
|
130
|
+
await promises.rename(src, dest);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
if (error?.code !== "EXDEV") throw error;
|
|
133
|
+
await copy(src, dest, { overwrite: options?.overwrite ?? true });
|
|
134
|
+
await remove(src);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
async function close$1(handle) {
|
|
138
|
+
if (typeof handle === "number") {
|
|
139
|
+
await new Promise((resolve, reject) => {
|
|
140
|
+
close(handle, (error) => {
|
|
141
|
+
if (error) {
|
|
142
|
+
reject(error);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
resolve();
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
await handle.close();
|
|
151
|
+
}
|
|
152
|
+
const fs = {
|
|
153
|
+
Dirent,
|
|
154
|
+
Stats,
|
|
155
|
+
access: promises.access,
|
|
156
|
+
appendFile,
|
|
157
|
+
close: close$1,
|
|
158
|
+
closeSync,
|
|
159
|
+
constants,
|
|
160
|
+
copy,
|
|
161
|
+
emptyDir,
|
|
162
|
+
ensureDir,
|
|
163
|
+
ensureFile,
|
|
164
|
+
ensureSymlink,
|
|
165
|
+
exists,
|
|
166
|
+
existsSync,
|
|
167
|
+
mkdir: promises.mkdir,
|
|
168
|
+
mkdirSync,
|
|
169
|
+
mkdtemp: promises.mkdtemp,
|
|
170
|
+
move,
|
|
171
|
+
open: (file, flags) => promises.open(file, flags),
|
|
172
|
+
openSync,
|
|
173
|
+
outputFile,
|
|
174
|
+
outputJSON,
|
|
175
|
+
outputJson,
|
|
176
|
+
pathExists,
|
|
177
|
+
pathExistsSync,
|
|
178
|
+
readFile: promises.readFile,
|
|
179
|
+
readFileSync,
|
|
180
|
+
readJSON,
|
|
181
|
+
readJson,
|
|
182
|
+
readJsonSync,
|
|
183
|
+
readdir: promises.readdir,
|
|
184
|
+
rm: promises.rm,
|
|
185
|
+
remove,
|
|
186
|
+
stat: promises.stat,
|
|
187
|
+
symlink: promises.symlink,
|
|
188
|
+
unlinkSync,
|
|
189
|
+
utimes: promises.utimes,
|
|
190
|
+
utimesSync,
|
|
191
|
+
watch,
|
|
192
|
+
writeFile: promises.writeFile,
|
|
193
|
+
writeFileSync,
|
|
194
|
+
writeJSON,
|
|
195
|
+
writeJson
|
|
196
|
+
};
|
|
197
|
+
//#endregion
|
|
198
|
+
export { fs };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import objectHash from "object-hash";
|
|
2
1
|
import set from "set-value";
|
|
3
2
|
|
|
4
|
-
//#region ../../node_modules/.pnpm/defu@6.1.
|
|
3
|
+
//#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.d.mts
|
|
5
4
|
type Input = Record<string | number | symbol, any>;
|
|
6
5
|
type IgnoredInput = boolean | number | null | any[] | Record<never, any> | undefined;
|
|
7
6
|
type Merger = <T extends Input, K extends keyof T>(object: T, key: keyof T, value: T[K], namespace: string) => any;
|
|
@@ -19,6 +18,315 @@ type MergeArrays<Destination, Source> = Destination extends Array<infer Destinat
|
|
|
19
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;
|
|
20
19
|
declare const defu: DefuInstance;
|
|
21
20
|
//#endregion
|
|
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;
|
|
31
|
+
}
|
|
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;
|
|
45
|
+
}
|
|
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;
|
|
107
|
+
}
|
|
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
|
+
};
|
|
232
|
+
}
|
|
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[];
|
|
329
|
+
//#endregion
|
|
22
330
|
//#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/index.d.ts
|
|
23
331
|
declare function get<T>(obj: T): T;
|
|
24
332
|
declare function get(obj: object, key: string | string[], options?: get.Options): any;
|
|
@@ -89,15 +397,7 @@ declare function arrify<T>(val: T | readonly T[]): T[];
|
|
|
89
397
|
/**
|
|
90
398
|
* @description defu 合并策略:当目标/来源为数组时直接覆盖
|
|
91
399
|
*/
|
|
92
|
-
declare const defuOverrideArray:
|
|
93
|
-
[x: string]: any;
|
|
94
|
-
[x: number]: any;
|
|
95
|
-
[x: symbol]: any;
|
|
96
|
-
}, Defaults extends Array<{
|
|
97
|
-
[x: string]: any;
|
|
98
|
-
[x: number]: any;
|
|
99
|
-
[x: symbol]: any;
|
|
100
|
-
} | (number | boolean | any[] | Record<never, any> | null | undefined)>>(source: Source, ...defaults: Defaults) => Defu<Source, Defaults>;
|
|
400
|
+
declare const defuOverrideArray: DefuFn;
|
|
101
401
|
/**
|
|
102
402
|
* @description 判断是否为非 null 的对象
|
|
103
403
|
*/
|
|
@@ -107,4 +407,4 @@ declare function isObject(x: unknown): x is Record<string | symbol | number, unk
|
|
|
107
407
|
*/
|
|
108
408
|
declare function isEmptyObject(obj: unknown): boolean;
|
|
109
409
|
//#endregion
|
|
110
|
-
export { addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, get, isEmptyObject, isObject,
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { extname } from "node:path";
|
|
2
|
-
import objectHash from "object-hash";
|
|
3
1
|
//#region \0rolldown/runtime.js
|
|
4
2
|
var __create = Object.create;
|
|
5
3
|
var __defProp$1 = Object.defineProperty;
|
|
@@ -23,7 +21,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
23
21
|
enumerable: true
|
|
24
22
|
}) : target, mod));
|
|
25
23
|
//#endregion
|
|
26
|
-
//#region ../../node_modules/.pnpm/defu@6.1.
|
|
24
|
+
//#region ../../node_modules/.pnpm/defu@6.1.7/node_modules/defu/dist/defu.mjs
|
|
27
25
|
function isPlainObject(value) {
|
|
28
26
|
if (value === null || typeof value !== "object") return false;
|
|
29
27
|
const prototype = Object.getPrototypeOf(value);
|
|
@@ -34,8 +32,8 @@ function isPlainObject(value) {
|
|
|
34
32
|
}
|
|
35
33
|
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
36
34
|
if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
|
|
37
|
-
const object =
|
|
38
|
-
for (const key
|
|
35
|
+
const object = { ...defaults };
|
|
36
|
+
for (const key of Object.keys(baseObject)) {
|
|
39
37
|
if (key === "__proto__" || key === "constructor") continue;
|
|
40
38
|
const value = baseObject[key];
|
|
41
39
|
if (value === null || value === void 0) continue;
|
|
@@ -63,6 +61,505 @@ createDefu((object, key, currentValue) => {
|
|
|
63
61
|
}
|
|
64
62
|
});
|
|
65
63
|
//#endregion
|
|
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
|
+
};
|
|
378
|
+
}
|
|
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))));
|
|
392
|
+
}
|
|
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;
|
|
404
|
+
}
|
|
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);
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* @description 返回所有受支持的小程序平台。
|
|
415
|
+
*/
|
|
416
|
+
function getSupportedMiniProgramPlatforms() {
|
|
417
|
+
return SUPPORTED_MINI_PROGRAM_PLATFORMS;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* @description 返回所有受支持的小程序模板指令前缀。
|
|
421
|
+
*/
|
|
422
|
+
function getSupportedMiniProgramDirectivePrefixes() {
|
|
423
|
+
return SUPPORTED_MINI_PROGRAM_DIRECTIVE_PREFIXES;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* @description 返回默认小程序平台。
|
|
427
|
+
*/
|
|
428
|
+
function getDefaultMiniProgramPlatform() {
|
|
429
|
+
return SUPPORTED_MINI_PROGRAM_PLATFORMS[0] ?? "weapp";
|
|
430
|
+
}
|
|
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;
|
|
438
|
+
}
|
|
439
|
+
/**
|
|
440
|
+
* @description 获取模板编译预设。
|
|
441
|
+
*/
|
|
442
|
+
function getMiniProgramTemplatePreset(platform) {
|
|
443
|
+
if (!platform) return "wechat";
|
|
444
|
+
return getMiniProgramPlatformDescriptor(platform).compiler?.templatePreset ?? "wechat";
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* @description 判断平台是否允许自动补齐 app 样式入口。
|
|
448
|
+
*/
|
|
449
|
+
function supportsMiniProgramAutoTouchAppStyle(platform) {
|
|
450
|
+
if (!platform) return false;
|
|
451
|
+
return getMiniProgramPlatformDescriptor(platform).build?.autoTouchAppStyle === true;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* @description 获取平台默认构建目标。
|
|
455
|
+
*/
|
|
456
|
+
function getMiniProgramDefaultBuildTarget(platform) {
|
|
457
|
+
if (!platform) return;
|
|
458
|
+
return getMiniProgramPlatformDescriptor(platform).build?.defaultBuildTarget;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* @description 获取平台默认使用的类型包。
|
|
462
|
+
*/
|
|
463
|
+
function getMiniProgramAppTypesPackage(platform) {
|
|
464
|
+
return getMiniProgramPlatformDescriptor(platform ?? getDefaultMiniProgramPlatform()).typescript?.appTypesPackage ?? "miniprogram-api-typings";
|
|
465
|
+
}
|
|
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;
|
|
499
|
+
}
|
|
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;
|
|
554
|
+
}
|
|
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)}`);
|
|
559
|
+
}
|
|
560
|
+
return Array.from(new Set(keys));
|
|
561
|
+
}
|
|
562
|
+
//#endregion
|
|
66
563
|
//#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
|
|
67
564
|
var __defProp = Object.defineProperty;
|
|
68
565
|
var __name = (target, value) => __defProp(target, "name", {
|
|
@@ -291,6 +788,10 @@ const SPECIAL_CHARS_RE = /[|\\{}()[\]^$+*?.]/g;
|
|
|
291
788
|
const HYPHEN_RE = /-/g;
|
|
292
789
|
const LAST_EXT_RE = /\.[^/.]+$/;
|
|
293
790
|
const ALL_EXT_RE = /(\.[^/.]+)+$/;
|
|
791
|
+
function hasExtension(filename) {
|
|
792
|
+
const lastSlashIndex = Math.max(filename.lastIndexOf("/"), filename.lastIndexOf("\\"));
|
|
793
|
+
return (lastSlashIndex >= 0 ? filename.slice(lastSlashIndex + 1) : filename).lastIndexOf(".") > 0;
|
|
794
|
+
}
|
|
294
795
|
/**
|
|
295
796
|
* @description 转义字符串中的正则特殊字符
|
|
296
797
|
*/
|
|
@@ -314,7 +815,7 @@ function removeExtensionDeep(file) {
|
|
|
314
815
|
*/
|
|
315
816
|
function addExtension(filename, ext = ".js") {
|
|
316
817
|
let result = `${filename}`;
|
|
317
|
-
if (!
|
|
818
|
+
if (!hasExtension(filename)) result += ext;
|
|
318
819
|
return result;
|
|
319
820
|
}
|
|
320
821
|
/**
|
|
@@ -352,4 +853,4 @@ function isEmptyObject(obj) {
|
|
|
352
853
|
}
|
|
353
854
|
//#endregion
|
|
354
855
|
var set = import_set_value.default;
|
|
355
|
-
export { addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, index_default as get, isEmptyObject, isObject,
|
|
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 };
|
package/dist/node.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CopyOptions, FsDirent, FsStats, JsonReadOptions, JsonWriteOptions, MoveOptions, fs } from "./fs/index.js";
|
|
2
|
+
|
|
3
|
+
//#region src/node.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* @description 生成稳定对象哈希,避免依赖已被禁用的 object-hash 包。
|
|
6
|
+
*/
|
|
7
|
+
declare function objectHash(value: unknown): string;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { type CopyOptions, type FsDirent, type FsStats, type JsonReadOptions, type JsonWriteOptions, type MoveOptions, fs, objectHash };
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { fs } from "./fs/index.js";
|
|
2
|
+
//#region src/node.ts
|
|
3
|
+
const UTF8_ENCODER = new TextEncoder();
|
|
4
|
+
const HASH_SEEDS = [
|
|
5
|
+
0,
|
|
6
|
+
1,
|
|
7
|
+
2,
|
|
8
|
+
3
|
|
9
|
+
];
|
|
10
|
+
function bytesToHex(bytes) {
|
|
11
|
+
let result = "";
|
|
12
|
+
for (const byte of bytes) result += byte.toString(16).padStart(2, "0");
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
function stableSerialize(value, seen = /* @__PURE__ */ new Map()) {
|
|
16
|
+
if (value === null) return "null";
|
|
17
|
+
switch (typeof value) {
|
|
18
|
+
case "undefined": return "undefined";
|
|
19
|
+
case "string": return JSON.stringify(value);
|
|
20
|
+
case "number":
|
|
21
|
+
if (Number.isNaN(value)) return "number:NaN";
|
|
22
|
+
if (!Number.isFinite(value)) return `number:${value > 0 ? "Infinity" : "-Infinity"}`;
|
|
23
|
+
if (Object.is(value, -0)) return "number:-0";
|
|
24
|
+
return `number:${value}`;
|
|
25
|
+
case "bigint": return `bigint:${value.toString()}`;
|
|
26
|
+
case "boolean": return `boolean:${value}`;
|
|
27
|
+
case "symbol": return `symbol:${String(value)}`;
|
|
28
|
+
case "function": return `function:${value.toString()}`;
|
|
29
|
+
}
|
|
30
|
+
if (value instanceof Date) return `date:${value.toISOString()}`;
|
|
31
|
+
if (value instanceof RegExp) return `regexp:${value.toString()}`;
|
|
32
|
+
if (ArrayBuffer.isView(value)) return `${value.constructor.name}:${bytesToHex(new Uint8Array(value.buffer, value.byteOffset, value.byteLength))}`;
|
|
33
|
+
if (value instanceof ArrayBuffer) return `ArrayBuffer:${bytesToHex(new Uint8Array(value))}`;
|
|
34
|
+
if (seen.has(value)) return `circular:${seen.get(value)}`;
|
|
35
|
+
seen.set(value, seen.size);
|
|
36
|
+
if (Array.isArray(value)) return `[${value.map((item) => stableSerialize(item, seen)).join(",")}]`;
|
|
37
|
+
if (value instanceof Set) return `Set(${Array.from(value, (item) => stableSerialize(item, seen)).join(",")})`;
|
|
38
|
+
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(",")})`;
|
|
39
|
+
return `{${Reflect.ownKeys(value).sort((left, right) => String(left).localeCompare(String(right))).map((key) => {
|
|
40
|
+
return `${stableSerialize(key, seen)}:${stableSerialize(value[key], seen)}`;
|
|
41
|
+
}).join(",")}}`;
|
|
42
|
+
}
|
|
43
|
+
function xmur3(bytes, seed) {
|
|
44
|
+
let hash = (1779033703 ^ bytes.length ^ seed) >>> 0;
|
|
45
|
+
for (const byte of bytes) {
|
|
46
|
+
hash = Math.imul(hash ^ byte, 3432918353);
|
|
47
|
+
hash = hash << 13 | hash >>> 19;
|
|
48
|
+
}
|
|
49
|
+
hash = Math.imul(hash ^ hash >>> 16, 2246822507);
|
|
50
|
+
hash = Math.imul(hash ^ hash >>> 13, 3266489909);
|
|
51
|
+
return (hash ^ hash >>> 16) >>> 0;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @description 生成稳定对象哈希,避免依赖已被禁用的 object-hash 包。
|
|
55
|
+
*/
|
|
56
|
+
function objectHash(value) {
|
|
57
|
+
const bytes = UTF8_ENCODER.encode(stableSerialize(value));
|
|
58
|
+
return HASH_SEEDS.map((seed) => xmur3(bytes, seed).toString(16).padStart(8, "0")).join("");
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { fs, objectHash };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.4",
|
|
5
5
|
"description": "@weapp-core/shared",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -20,6 +20,14 @@
|
|
|
20
20
|
".": {
|
|
21
21
|
"types": "./src/index.ts",
|
|
22
22
|
"default": "./src/index.ts"
|
|
23
|
+
},
|
|
24
|
+
"./node": {
|
|
25
|
+
"types": "./src/node.ts",
|
|
26
|
+
"default": "./src/node.ts"
|
|
27
|
+
},
|
|
28
|
+
"./fs": {
|
|
29
|
+
"types": "./src/fs/index.ts",
|
|
30
|
+
"default": "./src/fs/index.ts"
|
|
23
31
|
}
|
|
24
32
|
},
|
|
25
33
|
"main": "./src/index.ts",
|
|
@@ -30,6 +38,14 @@
|
|
|
30
38
|
".": {
|
|
31
39
|
"types": "./dist/index.d.ts",
|
|
32
40
|
"import": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./node": {
|
|
43
|
+
"types": "./dist/node.d.ts",
|
|
44
|
+
"import": "./dist/node.js"
|
|
45
|
+
},
|
|
46
|
+
"./fs": {
|
|
47
|
+
"types": "./dist/fs/index.d.ts",
|
|
48
|
+
"import": "./dist/fs/index.js"
|
|
33
49
|
}
|
|
34
50
|
},
|
|
35
51
|
"main": "./dist/index.js",
|
|
@@ -41,9 +57,7 @@
|
|
|
41
57
|
"engines": {
|
|
42
58
|
"node": "^20.19.0 || >=22.12.0"
|
|
43
59
|
},
|
|
44
|
-
"dependencies": {
|
|
45
|
-
"object-hash": "^3.0.0"
|
|
46
|
-
},
|
|
60
|
+
"dependencies": {},
|
|
47
61
|
"devDependencies": {},
|
|
48
62
|
"scripts": {
|
|
49
63
|
"dev": "tsdown -w --sourcemap",
|