@weapp-core/shared 3.0.1 → 3.0.3

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.
Files changed (3) hide show
  1. package/dist/index.d.ts +164 -17
  2. package/dist/index.js +548 -446
  3. package/package.json +5 -6
package/dist/index.d.ts CHANGED
@@ -1,9 +1,161 @@
1
- import * as defu from 'defu';
2
- export { default as defu } from 'defu';
3
- export { default as objectHash } from 'object-hash';
4
- export { default as get } from 'get-value';
5
- export { default as set } from 'set-value';
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
+ import set from "set-value";
6
4
 
5
+ //#region ../../node_modules/.pnpm/defu@6.1.6/node_modules/defu/dist/defu.d.mts
6
+ type Input = Record<string | number | symbol, any>;
7
+ type IgnoredInput = boolean | number | null | any[] | Record<never, any> | undefined;
8
+ type Merger = <T extends Input, K extends keyof T>(object: T, key: keyof T, value: T[K], namespace: string) => any;
9
+ type nullish = null | undefined | void;
10
+ type MergeObjects<Destination extends Input, Defaults extends Input> = Destination extends Defaults ? Destination : Omit<Destination, keyof Destination & keyof Defaults> & Omit<Defaults, keyof Destination & keyof Defaults> & { -readonly [Key in keyof Destination & keyof Defaults]: Destination[Key] extends nullish ? Defaults[Key] extends nullish ? nullish : Defaults[Key] : Defaults[Key] extends nullish ? Destination[Key] : Merge<Destination[Key], Defaults[Key]> };
11
+ type Defu<S extends Input, D extends Array<Input | IgnoredInput>> = D extends [infer F, ...infer Rest] ? F extends Input ? Rest extends Array<Input | IgnoredInput> ? Defu<MergeObjects<S, F>, Rest> : MergeObjects<S, F> : F extends IgnoredInput ? Rest extends Array<Input | IgnoredInput> ? Defu<S, Rest> : S : S : S;
12
+ type DefuFn = <Source extends Input, Defaults extends Array<Input | IgnoredInput>>(source: Source, ...defaults: Defaults) => Defu<Source, Defaults>;
13
+ interface DefuInstance {
14
+ <Source extends Input, Defaults extends Array<Input | IgnoredInput>>(source: Source | IgnoredInput, ...defaults: Defaults): Defu<Source, Defaults>;
15
+ fn: DefuFn;
16
+ arrayFn: DefuFn;
17
+ extend(merger?: Merger): DefuFn;
18
+ }
19
+ type MergeArrays<Destination, Source> = Destination extends Array<infer DestinationType> ? Source extends Array<infer SourceType> ? Array<DestinationType | SourceType> : Source | Array<DestinationType> : Source | Destination;
20
+ 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
+ declare const defu: DefuInstance;
22
+ //#endregion
23
+ //#region src/fs/index.d.ts
24
+ interface JsonReadOptions {
25
+ encoding?: BufferEncoding;
26
+ throws?: boolean;
27
+ }
28
+ interface JsonWriteOptions {
29
+ encoding?: BufferEncoding;
30
+ replacer?: ((this: any, key: string, value: any) => any) | Array<number | string> | null;
31
+ spaces?: number | string;
32
+ }
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;
40
+ }
41
+ interface MoveOptions {
42
+ overwrite?: boolean;
43
+ }
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;
111
+ //#endregion
112
+ //#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/index.d.ts
113
+ declare function get<T>(obj: T): T;
114
+ declare function get(obj: object, key: string | string[], options?: get.Options): any;
115
+ declare namespace get {
116
+ interface Options {
117
+ /**
118
+ * The default value to return when get-value cannot result a value from the given object.
119
+ *
120
+ * default: `undefined`
121
+ */
122
+ default?: any;
123
+ /**
124
+ * If defined, this function is called on each resolved value.
125
+ * Useful if you want to do `.hasOwnProperty` or `Object.prototype.propertyIsEnumerable`.
126
+ */
127
+ isValid?: (<K extends string>(key: K, object: Record<K, any>) => boolean) | undefined;
128
+ /**
129
+ * Custom function to use for splitting the string into object path segments.
130
+ *
131
+ * default: `String.split`
132
+ */
133
+ split?: ((s: string) => string[]) | undefined;
134
+ /**
135
+ * The separator to use for spliting the string.
136
+ * (this is probably not needed when `options.split` is used).
137
+ *
138
+ * default: `"."`
139
+ */
140
+ separator?: string | RegExp | undefined;
141
+ /**
142
+ * Customize how the object path is created when iterating over path segments.
143
+ *
144
+ * default: `Array.join`
145
+ */
146
+ join?: ((segs: string[]) => string) | undefined;
147
+ /**
148
+ * The character to use when re-joining the string to check for keys
149
+ * with dots in them (this is probably not needed when `options.join` is used).
150
+ * This can be a different value than the separator, since the separator can be a string or regex.
151
+ *
152
+ * default: `"."`
153
+ */
154
+ joinChar?: string | undefined;
155
+ }
156
+ }
157
+ //#endregion
158
+ //#region src/index.d.ts
7
159
  /**
8
160
  * @description 转义字符串中的正则特殊字符
9
161
  */
@@ -24,19 +176,10 @@ declare function addExtension(filename: string, ext?: string): string;
24
176
  * @description 将单个值转换为数组
25
177
  */
26
178
  declare function arrify<T>(val: T | readonly T[]): T[];
27
-
28
179
  /**
29
180
  * @description defu 合并策略:当目标/来源为数组时直接覆盖
30
181
  */
31
- declare const defuOverrideArray: <Source extends {
32
- [x: string]: any;
33
- [x: number]: any;
34
- [x: symbol]: any;
35
- }, Defaults extends Array<{
36
- [x: string]: any;
37
- [x: number]: any;
38
- [x: symbol]: any;
39
- } | (number | boolean | any[] | Record<never, any> | null | undefined)>>(source: Source, ...defaults: Defaults) => defu.Defu<Source, Defaults>;
182
+ declare const defuOverrideArray: DefuFn;
40
183
  /**
41
184
  * @description 判断是否为非 null 的对象
42
185
  */
@@ -45,5 +188,9 @@ declare function isObject(x: unknown): x is Record<string | symbol | number, unk
45
188
  * @description 判断对象是否为空对象
46
189
  */
47
190
  declare function isEmptyObject(obj: unknown): boolean;
48
-
49
- export { addExtension, arrify, defuOverrideArray, escapeStringRegexp, isEmptyObject, isObject, removeExtension, removeExtensionDeep };
191
+ /**
192
+ * @description 生成稳定对象哈希,避免依赖已被禁用的 object-hash 包
193
+ */
194
+ declare function objectHash(value: unknown): string;
195
+ //#endregion
196
+ export { CopyOptions, FsDirent, FsStats, JsonReadOptions, JsonWriteOptions, MoveOptions, addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, fs, get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set };
package/dist/index.js CHANGED
@@ -1,481 +1,583 @@
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
+ //#region \0rolldown/runtime.js
1
6
  var __create = Object.create;
2
- var __defProp = Object.defineProperty;
7
+ var __defProp$1 = Object.defineProperty;
3
8
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
9
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
10
  var __getProtoOf = Object.getPrototypeOf;
6
11
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __esm = (fn, res) => function __init() {
8
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
9
- };
10
- var __commonJS = (cb, mod) => function __require() {
11
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
12
- };
12
+ var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
13
13
  var __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from === "object" || typeof from === "function") {
15
- for (let key of __getOwnPropNames(from))
16
- if (!__hasOwnProp.call(to, key) && key !== except)
17
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
- }
19
- return to;
14
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
15
+ key = keys[i];
16
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp$1(to, key, {
17
+ get: ((k) => from[k]).bind(null, key),
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
20
22
  };
21
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
- // If the importer is in node compatibility mode or this is not an ESM
23
- // file that has been converted to a CommonJS file using a Babel-
24
- // compatible transform (i.e. "__esModule" has not been set), then set
25
- // "default" to the CommonJS "module.exports" for node compatibility.
26
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
- mod
28
- ));
29
-
30
- // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.56.0_@types+node@25.2.0__@swc+core@1.15.11_jiti@2_1af55e4e1e3a88da689103a99e6896b3/node_modules/tsup/assets/esm_shims.js
31
- import path from "path";
32
- import { fileURLToPath } from "url";
33
- var init_esm_shims = __esm({
34
- "../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.56.0_@types+node@25.2.0__@swc+core@1.15.11_jiti@2_1af55e4e1e3a88da689103a99e6896b3/node_modules/tsup/assets/esm_shims.js"() {
35
- "use strict";
36
- }
37
- });
38
-
39
- // ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
40
- var require_is_primitive = __commonJS({
41
- "../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js"(exports, module) {
42
- "use strict";
43
- init_esm_shims();
44
- module.exports = function isPrimitive(val) {
45
- if (typeof val === "object") {
46
- return val === null;
47
- }
48
- return typeof val !== "function";
49
- };
50
- }
51
- });
52
-
53
- // ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
54
- var require_isobject = __commonJS({
55
- "../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
56
- "use strict";
57
- init_esm_shims();
58
- module.exports = function isObject3(val) {
59
- return val != null && typeof val === "object" && Array.isArray(val) === false;
60
- };
61
- }
62
- });
63
-
64
- // ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
65
- var require_is_plain_object = __commonJS({
66
- "../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js"(exports, module) {
67
- "use strict";
68
- init_esm_shims();
69
- var isObject3 = require_isobject();
70
- function isObjectObject(o) {
71
- return isObject3(o) === true && Object.prototype.toString.call(o) === "[object Object]";
72
- }
73
- module.exports = function isPlainObject2(o) {
74
- var ctor, prot;
75
- if (isObjectObject(o) === false) return false;
76
- ctor = o.constructor;
77
- if (typeof ctor !== "function") return false;
78
- prot = ctor.prototype;
79
- if (isObjectObject(prot) === false) return false;
80
- if (prot.hasOwnProperty("isPrototypeOf") === false) {
81
- return false;
82
- }
83
- return true;
84
- };
85
- }
86
- });
87
-
88
- // ../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js
89
- var require_set_value = __commonJS({
90
- "../../node_modules/.pnpm/set-value@4.1.0/node_modules/set-value/index.js"(exports, module) {
91
- "use strict";
92
- init_esm_shims();
93
- var { deleteProperty } = Reflect;
94
- var isPrimitive = require_is_primitive();
95
- var isPlainObject2 = require_is_plain_object();
96
- var isObject3 = (value) => {
97
- return typeof value === "object" && value !== null || typeof value === "function";
98
- };
99
- var isUnsafeKey = (key) => {
100
- return key === "__proto__" || key === "constructor" || key === "prototype";
101
- };
102
- var validateKey = (key) => {
103
- if (!isPrimitive(key)) {
104
- throw new TypeError("Object keys must be strings or symbols");
105
- }
106
- if (isUnsafeKey(key)) {
107
- throw new Error(`Cannot set unsafe key: "${key}"`);
108
- }
109
- };
110
- var toStringKey = (input) => {
111
- return Array.isArray(input) ? input.flat().map(String).join(",") : input;
112
- };
113
- var createMemoKey = (input, options) => {
114
- if (typeof input !== "string" || !options) return input;
115
- let key = input + ";";
116
- if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
117
- if (options.separator !== void 0) key += `separator=${options.separator};`;
118
- if (options.split !== void 0) key += `split=${options.split};`;
119
- if (options.merge !== void 0) key += `merge=${options.merge};`;
120
- if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
121
- return key;
122
- };
123
- var memoize = (input, options, fn) => {
124
- const key = toStringKey(options ? createMemoKey(input, options) : input);
125
- validateKey(key);
126
- const value = setValue.cache.get(key) || fn();
127
- setValue.cache.set(key, value);
128
- return value;
129
- };
130
- var splitString = (input, options = {}) => {
131
- const sep = options.separator || ".";
132
- const preserve = sep === "/" ? false : options.preservePaths;
133
- if (typeof input === "string" && preserve !== false && /\//.test(input)) {
134
- return [input];
135
- }
136
- const parts = [];
137
- let part = "";
138
- const push = (part2) => {
139
- let number;
140
- if (part2.trim() !== "" && Number.isInteger(number = Number(part2))) {
141
- parts.push(number);
142
- } else {
143
- parts.push(part2);
144
- }
145
- };
146
- for (let i = 0; i < input.length; i++) {
147
- const value = input[i];
148
- if (value === "\\") {
149
- part += input[++i];
150
- continue;
151
- }
152
- if (value === sep) {
153
- push(part);
154
- part = "";
155
- continue;
156
- }
157
- part += value;
158
- }
159
- if (part) {
160
- push(part);
161
- }
162
- return parts;
163
- };
164
- var split2 = (input, options) => {
165
- if (options && typeof options.split === "function") return options.split(input);
166
- if (typeof input === "symbol") return [input];
167
- if (Array.isArray(input)) return input;
168
- return memoize(input, options, () => splitString(input, options));
169
- };
170
- var assignProp = (obj, prop, value, options) => {
171
- validateKey(prop);
172
- if (value === void 0) {
173
- deleteProperty(obj, prop);
174
- } else if (options && options.merge) {
175
- const merge = options.merge === "function" ? options.merge : Object.assign;
176
- if (merge && isPlainObject2(obj[prop]) && isPlainObject2(value)) {
177
- obj[prop] = merge(obj[prop], value);
178
- } else {
179
- obj[prop] = value;
180
- }
181
- } else {
182
- obj[prop] = value;
183
- }
184
- return obj;
185
- };
186
- var setValue = (target, path2, value, options) => {
187
- if (!path2 || !isObject3(target)) return target;
188
- const keys = split2(path2, options);
189
- let obj = target;
190
- for (let i = 0; i < keys.length; i++) {
191
- const key = keys[i];
192
- const next = keys[i + 1];
193
- validateKey(key);
194
- if (next === void 0) {
195
- assignProp(obj, key, value, options);
196
- break;
197
- }
198
- if (typeof next === "number" && !Array.isArray(obj[key])) {
199
- obj = obj[key] = [];
200
- continue;
201
- }
202
- if (!isObject3(obj[key])) {
203
- obj[key] = {};
204
- }
205
- obj = obj[key];
206
- }
207
- return target;
208
- };
209
- setValue.split = split2;
210
- setValue.cache = /* @__PURE__ */ new Map();
211
- setValue.clear = () => {
212
- setValue.cache = /* @__PURE__ */ new Map();
213
- };
214
- module.exports = setValue;
215
- }
216
- });
217
-
218
- // src/index.ts
219
- init_esm_shims();
220
- import { extname } from "path";
221
-
222
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
223
- init_esm_shims();
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp$1(target, "default", {
24
+ value: mod,
25
+ enumerable: true
26
+ }) : target, mod));
27
+ //#endregion
28
+ //#region ../../node_modules/.pnpm/defu@6.1.6/node_modules/defu/dist/defu.mjs
224
29
  function isPlainObject(value) {
225
- if (value === null || typeof value !== "object") {
226
- return false;
227
- }
228
- const prototype = Object.getPrototypeOf(value);
229
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
230
- return false;
231
- }
232
- if (Symbol.iterator in value) {
233
- return false;
234
- }
235
- if (Symbol.toStringTag in value) {
236
- return Object.prototype.toString.call(value) === "[object Module]";
237
- }
238
- return true;
30
+ if (value === null || typeof value !== "object") return false;
31
+ const prototype = Object.getPrototypeOf(value);
32
+ if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) return false;
33
+ if (Symbol.iterator in value) return false;
34
+ if (Symbol.toStringTag in value) return Object.prototype.toString.call(value) === "[object Module]";
35
+ return true;
239
36
  }
240
37
  function _defu(baseObject, defaults, namespace = ".", merger) {
241
- if (!isPlainObject(defaults)) {
242
- return _defu(baseObject, {}, namespace, merger);
243
- }
244
- const object = Object.assign({}, defaults);
245
- for (const key in baseObject) {
246
- if (key === "__proto__" || key === "constructor") {
247
- continue;
248
- }
249
- const value = baseObject[key];
250
- if (value === null || value === void 0) {
251
- continue;
252
- }
253
- if (merger && merger(object, key, value, namespace)) {
254
- continue;
255
- }
256
- if (Array.isArray(value) && Array.isArray(object[key])) {
257
- object[key] = [...value, ...object[key]];
258
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
259
- object[key] = _defu(
260
- value,
261
- object[key],
262
- (namespace ? `${namespace}.` : "") + key.toString(),
263
- merger
264
- );
265
- } else {
266
- object[key] = value;
267
- }
268
- }
269
- return object;
38
+ if (!isPlainObject(defaults)) return _defu(baseObject, {}, namespace, merger);
39
+ const object = { ...defaults };
40
+ for (const key of Object.keys(baseObject)) {
41
+ if (key === "__proto__" || key === "constructor") continue;
42
+ const value = baseObject[key];
43
+ if (value === null || value === void 0) continue;
44
+ if (merger && merger(object, key, value, namespace)) continue;
45
+ if (Array.isArray(value) && Array.isArray(object[key])) object[key] = [...value, ...object[key]];
46
+ else if (isPlainObject(value) && isPlainObject(object[key])) object[key] = _defu(value, object[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
47
+ else object[key] = value;
48
+ }
49
+ return object;
270
50
  }
271
51
  function createDefu(merger) {
272
- return (...arguments_) => (
273
- // eslint-disable-next-line unicorn/no-array-reduce
274
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
275
- );
276
- }
277
- var defu = createDefu();
278
- var defuFn = createDefu((object, key, currentValue) => {
279
- if (object[key] !== void 0 && typeof currentValue === "function") {
280
- object[key] = currentValue(object[key]);
281
- return true;
282
- }
52
+ return (...arguments_) => arguments_.reduce((p, c) => _defu(p, c, "", merger), {});
53
+ }
54
+ const defu = createDefu();
55
+ createDefu((object, key, currentValue) => {
56
+ if (object[key] !== void 0 && typeof currentValue === "function") {
57
+ object[key] = currentValue(object[key]);
58
+ return true;
59
+ }
60
+ });
61
+ createDefu((object, key, currentValue) => {
62
+ if (Array.isArray(object[key]) && typeof currentValue === "function") {
63
+ object[key] = currentValue(object[key]);
64
+ return true;
65
+ }
283
66
  });
284
- var defuArrayFn = createDefu((object, key, currentValue) => {
285
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
286
- object[key] = currentValue(object[key]);
287
- return true;
288
- }
67
+ //#endregion
68
+ //#region src/fs/index.ts
69
+ function normalizeJsonEncoding(encoding) {
70
+ return encoding ?? "utf8";
71
+ }
72
+ function normalizeJsonText(source) {
73
+ return source.charCodeAt(0) === 65279 ? source.slice(1) : source;
74
+ }
75
+ function serializeJson(data, options) {
76
+ return JSON.stringify(data, options?.replacer ?? null, options?.spaces);
77
+ }
78
+ async function pathExists(target) {
79
+ try {
80
+ await promises.access(target);
81
+ return true;
82
+ } catch {
83
+ return false;
84
+ }
85
+ }
86
+ function pathExistsSync(target) {
87
+ try {
88
+ return existsSync(target);
89
+ } catch {
90
+ return false;
91
+ }
92
+ }
93
+ async function exists(target) {
94
+ return pathExists(target);
95
+ }
96
+ async function ensureDir(dir) {
97
+ await promises.mkdir(dir, { recursive: true });
98
+ }
99
+ async function ensureFile(file) {
100
+ await ensureDir(path.dirname(file));
101
+ await (await promises.open(file, "a")).close();
102
+ }
103
+ async function remove(target) {
104
+ await promises.rm(target, {
105
+ force: true,
106
+ recursive: true
107
+ });
108
+ }
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
+ }
156
+ }
157
+ async function readJSON(file, options) {
158
+ return readJson(file, options);
159
+ }
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
+ }
168
+ }
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
+ });
179
+ }
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;
187
+ }
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);
197
+ }
198
+ }
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
+ //#endregion
260
+ //#region ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
261
+ var __defProp = Object.defineProperty;
262
+ var __name = (target, value) => __defProp(target, "name", {
263
+ value,
264
+ configurable: true
289
265
  });
290
-
291
- // src/index.ts
292
- import objectHash from "object-hash";
293
-
294
- // ../../node_modules/.pnpm/get-value@4.0.1/node_modules/get-value/dist/index.mjs
295
- init_esm_shims();
296
- var __defProp2 = Object.defineProperty;
297
- var __name = (target, value) => __defProp2(target, "name", { value, configurable: true });
298
- var isObject = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
266
+ var isObject$1 = /* @__PURE__ */ __name((v) => v !== null && typeof v === "object", "isObject");
299
267
  var join = /* @__PURE__ */ __name((segs, joinChar, options) => {
300
- if (typeof options.join === "function") {
301
- return options.join(segs);
302
- }
303
- return segs[0] + joinChar + segs[1];
268
+ if (typeof options.join === "function") return options.join(segs);
269
+ return segs[0] + joinChar + segs[1];
304
270
  }, "join");
305
- var split = /* @__PURE__ */ __name((path2, splitChar, options) => {
306
- if (typeof options.split === "function") {
307
- return options.split(path2);
308
- }
309
- return path2.split(splitChar);
271
+ var split = /* @__PURE__ */ __name((path, splitChar, options) => {
272
+ if (typeof options.split === "function") return options.split(path);
273
+ return path.split(splitChar);
310
274
  }, "split");
311
275
  var isValid = /* @__PURE__ */ __name((key, target = {}, options) => {
312
- if (typeof options?.isValid === "function") {
313
- return options.isValid(key, target);
314
- }
315
- return true;
276
+ if (typeof options?.isValid === "function") return options.isValid(key, target);
277
+ return true;
316
278
  }, "isValid");
317
279
  var isValidObject = /* @__PURE__ */ __name((v) => {
318
- return isObject(v) || typeof v === "function";
280
+ return isObject$1(v) || typeof v === "function";
319
281
  }, "isValidObject");
320
- var getValue = /* @__PURE__ */ __name((target, path2, options = {}) => {
321
- if (!isObject(options)) {
322
- options = { default: options };
323
- }
324
- if (!isValidObject(target)) {
325
- return typeof options.default !== "undefined" ? options.default : target;
326
- }
327
- if (typeof path2 === "number") {
328
- path2 = String(path2);
329
- }
330
- const pathIsArray = Array.isArray(path2);
331
- const pathIsString = typeof path2 === "string";
332
- const splitChar = options.separator || ".";
333
- const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
334
- if (!pathIsString && !pathIsArray) {
335
- return target;
336
- }
337
- if (target[path2] !== void 0) {
338
- return isValid(path2, target, options) ? target[path2] : options.default;
339
- }
340
- const segs = pathIsArray ? path2 : split(path2, splitChar, options);
341
- const len = segs.length;
342
- let idx = 0;
343
- do {
344
- let prop = segs[idx];
345
- if (typeof prop !== "string") {
346
- prop = String(prop);
347
- }
348
- while (prop && prop.slice(-1) === "\\") {
349
- prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
350
- }
351
- if (target[prop] !== void 0) {
352
- if (!isValid(prop, target, options)) {
353
- return options.default;
354
- }
355
- target = target[prop];
356
- } else {
357
- let hasProp = false;
358
- let n = idx + 1;
359
- while (n < len) {
360
- prop = join([prop, segs[n++]], joinChar, options);
361
- if (hasProp = target[prop] !== void 0) {
362
- if (!isValid(prop, target, options)) {
363
- return options.default;
364
- }
365
- target = target[prop];
366
- idx = n - 1;
367
- break;
368
- }
369
- }
370
- if (!hasProp) {
371
- return options.default;
372
- }
373
- }
374
- } while (++idx < len && isValidObject(target));
375
- if (idx === len) {
376
- return target;
377
- }
378
- return options.default;
282
+ var index_default = /* @__PURE__ */ __name((target, path, options = {}) => {
283
+ if (!isObject$1(options)) options = { default: options };
284
+ if (!isValidObject(target)) return typeof options.default !== "undefined" ? options.default : target;
285
+ if (typeof path === "number") path = String(path);
286
+ const pathIsArray = Array.isArray(path);
287
+ const pathIsString = typeof path === "string";
288
+ const splitChar = options.separator || ".";
289
+ const joinChar = options.joinChar || (typeof splitChar === "string" ? splitChar : ".");
290
+ if (!pathIsString && !pathIsArray) return target;
291
+ if (target[path] !== void 0) return isValid(path, target, options) ? target[path] : options.default;
292
+ const segs = pathIsArray ? path : split(path, splitChar, options);
293
+ const len = segs.length;
294
+ let idx = 0;
295
+ do {
296
+ let prop = segs[idx];
297
+ if (typeof prop !== "string") prop = String(prop);
298
+ while (prop && prop.slice(-1) === "\\") prop = join([prop.slice(0, -1), segs[++idx] || ""], joinChar, options);
299
+ if (target[prop] !== void 0) {
300
+ if (!isValid(prop, target, options)) return options.default;
301
+ target = target[prop];
302
+ } else {
303
+ let hasProp = false;
304
+ let n = idx + 1;
305
+ while (n < len) {
306
+ prop = join([prop, segs[n++]], joinChar, options);
307
+ if (hasProp = target[prop] !== void 0) {
308
+ if (!isValid(prop, target, options)) return options.default;
309
+ target = target[prop];
310
+ idx = n - 1;
311
+ break;
312
+ }
313
+ }
314
+ if (!hasProp) return options.default;
315
+ }
316
+ } while (++idx < len && isValidObject(target));
317
+ if (idx === len) return target;
318
+ return options.default;
379
319
  }, "getValue");
380
- var index_default = getValue;
381
-
382
- // src/index.ts
383
- var import_set_value = __toESM(require_set_value(), 1);
320
+ /*!
321
+ * get-value <https://github.com/jonschlinkert/get-value>
322
+ *
323
+ * Copyright (c) 2014-present, Jon Schlinkert.
324
+ * Released under the MIT License.
325
+ */
326
+ //#endregion
327
+ //#region ../../node_modules/.pnpm/is-primitive@3.0.1/node_modules/is-primitive/index.js
328
+ /*!
329
+ * is-primitive <https://github.com/jonschlinkert/is-primitive>
330
+ *
331
+ * Copyright (c) 2014-present, Jon Schlinkert.
332
+ * Released under the MIT License.
333
+ */
334
+ var require_is_primitive = /* @__PURE__ */ __commonJSMin(((exports, module) => {
335
+ module.exports = function isPrimitive(val) {
336
+ if (typeof val === "object") return val === null;
337
+ return typeof val !== "function";
338
+ };
339
+ }));
340
+ //#endregion
341
+ //#region ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
342
+ /*!
343
+ * isobject <https://github.com/jonschlinkert/isobject>
344
+ *
345
+ * Copyright (c) 2014-2017, Jon Schlinkert.
346
+ * Released under the MIT License.
347
+ */
348
+ var require_isobject = /* @__PURE__ */ __commonJSMin(((exports, module) => {
349
+ module.exports = function isObject(val) {
350
+ return val != null && typeof val === "object" && Array.isArray(val) === false;
351
+ };
352
+ }));
353
+ //#endregion
354
+ //#region ../../node_modules/.pnpm/is-plain-object@2.0.4/node_modules/is-plain-object/index.js
355
+ /*!
356
+ * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
357
+ *
358
+ * Copyright (c) 2014-2017, Jon Schlinkert.
359
+ * Released under the MIT License.
360
+ */
361
+ var require_is_plain_object = /* @__PURE__ */ __commonJSMin(((exports, module) => {
362
+ var isObject = require_isobject();
363
+ function isObjectObject(o) {
364
+ return isObject(o) === true && Object.prototype.toString.call(o) === "[object Object]";
365
+ }
366
+ module.exports = function isPlainObject(o) {
367
+ var ctor, prot;
368
+ if (isObjectObject(o) === false) return false;
369
+ ctor = o.constructor;
370
+ if (typeof ctor !== "function") return false;
371
+ prot = ctor.prototype;
372
+ if (isObjectObject(prot) === false) return false;
373
+ if (prot.hasOwnProperty("isPrototypeOf") === false) return false;
374
+ return true;
375
+ };
376
+ }));
377
+ //#endregion
378
+ //#region src/index.ts
379
+ var import_set_value = /* @__PURE__ */ __toESM((/* @__PURE__ */ __commonJSMin(((exports, module) => {
380
+ const { deleteProperty } = Reflect;
381
+ const isPrimitive = require_is_primitive();
382
+ const isPlainObject = require_is_plain_object();
383
+ const isObject = (value) => {
384
+ return typeof value === "object" && value !== null || typeof value === "function";
385
+ };
386
+ const isUnsafeKey = (key) => {
387
+ return key === "__proto__" || key === "constructor" || key === "prototype";
388
+ };
389
+ const validateKey = (key) => {
390
+ if (!isPrimitive(key)) throw new TypeError("Object keys must be strings or symbols");
391
+ if (isUnsafeKey(key)) throw new Error(`Cannot set unsafe key: "${key}"`);
392
+ };
393
+ const toStringKey = (input) => {
394
+ return Array.isArray(input) ? input.flat().map(String).join(",") : input;
395
+ };
396
+ const createMemoKey = (input, options) => {
397
+ if (typeof input !== "string" || !options) return input;
398
+ let key = input + ";";
399
+ if (options.arrays !== void 0) key += `arrays=${options.arrays};`;
400
+ if (options.separator !== void 0) key += `separator=${options.separator};`;
401
+ if (options.split !== void 0) key += `split=${options.split};`;
402
+ if (options.merge !== void 0) key += `merge=${options.merge};`;
403
+ if (options.preservePaths !== void 0) key += `preservePaths=${options.preservePaths};`;
404
+ return key;
405
+ };
406
+ const memoize = (input, options, fn) => {
407
+ const key = toStringKey(options ? createMemoKey(input, options) : input);
408
+ validateKey(key);
409
+ const value = setValue.cache.get(key) || fn();
410
+ setValue.cache.set(key, value);
411
+ return value;
412
+ };
413
+ const splitString = (input, options = {}) => {
414
+ const sep = options.separator || ".";
415
+ const preserve = sep === "/" ? false : options.preservePaths;
416
+ if (typeof input === "string" && preserve !== false && /\//.test(input)) return [input];
417
+ const parts = [];
418
+ let part = "";
419
+ const push = (part) => {
420
+ let number;
421
+ if (part.trim() !== "" && Number.isInteger(number = Number(part))) parts.push(number);
422
+ else parts.push(part);
423
+ };
424
+ for (let i = 0; i < input.length; i++) {
425
+ const value = input[i];
426
+ if (value === "\\") {
427
+ part += input[++i];
428
+ continue;
429
+ }
430
+ if (value === sep) {
431
+ push(part);
432
+ part = "";
433
+ continue;
434
+ }
435
+ part += value;
436
+ }
437
+ if (part) push(part);
438
+ return parts;
439
+ };
440
+ const split = (input, options) => {
441
+ if (options && typeof options.split === "function") return options.split(input);
442
+ if (typeof input === "symbol") return [input];
443
+ if (Array.isArray(input)) return input;
444
+ return memoize(input, options, () => splitString(input, options));
445
+ };
446
+ const assignProp = (obj, prop, value, options) => {
447
+ validateKey(prop);
448
+ if (value === void 0) deleteProperty(obj, prop);
449
+ else if (options && options.merge) {
450
+ const merge = options.merge === "function" ? options.merge : Object.assign;
451
+ if (merge && isPlainObject(obj[prop]) && isPlainObject(value)) obj[prop] = merge(obj[prop], value);
452
+ else obj[prop] = value;
453
+ } else obj[prop] = value;
454
+ return obj;
455
+ };
456
+ const setValue = (target, path, value, options) => {
457
+ if (!path || !isObject(target)) return target;
458
+ const keys = split(path, options);
459
+ let obj = target;
460
+ for (let i = 0; i < keys.length; i++) {
461
+ const key = keys[i];
462
+ const next = keys[i + 1];
463
+ validateKey(key);
464
+ if (next === void 0) {
465
+ assignProp(obj, key, value, options);
466
+ break;
467
+ }
468
+ if (typeof next === "number" && !Array.isArray(obj[key])) {
469
+ obj = obj[key] = [];
470
+ continue;
471
+ }
472
+ if (!isObject(obj[key])) obj[key] = {};
473
+ obj = obj[key];
474
+ }
475
+ return target;
476
+ };
477
+ setValue.split = split;
478
+ setValue.cache = /* @__PURE__ */ new Map();
479
+ setValue.clear = () => {
480
+ setValue.cache = /* @__PURE__ */ new Map();
481
+ };
482
+ module.exports = setValue;
483
+ })))(), 1);
484
+ const SPECIAL_CHARS_RE = /[|\\{}()[\]^$+*?.]/g;
485
+ const HYPHEN_RE = /-/g;
486
+ const LAST_EXT_RE = /\.[^/.]+$/;
487
+ 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(",")}}`;
515
+ }
516
+ /**
517
+ * @description 转义字符串中的正则特殊字符
518
+ */
384
519
  function escapeStringRegexp(str) {
385
- return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
520
+ return str.replace(SPECIAL_CHARS_RE, "\\$&").replace(HYPHEN_RE, "\\x2d");
386
521
  }
522
+ /**
523
+ * @description 移除文件名的最后一个扩展名
524
+ */
387
525
  function removeExtension(file) {
388
- return file.replace(/\.[^/.]+$/, "");
526
+ return file.replace(LAST_EXT_RE, "");
389
527
  }
528
+ /**
529
+ * @description 移除文件名的所有扩展名(多重后缀)
530
+ */
390
531
  function removeExtensionDeep(file) {
391
- return file.replace(/(\.[^/.]+)+$/, "");
532
+ return file.replace(ALL_EXT_RE, "");
392
533
  }
534
+ /**
535
+ * @description 若缺少扩展名则追加(默认 .js)
536
+ */
393
537
  function addExtension(filename, ext = ".js") {
394
- let result = `${filename}`;
395
- if (!extname(filename)) {
396
- result += ext;
397
- }
398
- return result;
538
+ let result = `${filename}`;
539
+ if (!extname(filename)) result += ext;
540
+ return result;
399
541
  }
542
+ /**
543
+ * @description 将单个值转换为数组
544
+ */
400
545
  function arrify(val) {
401
- if (Array.isArray(val)) {
402
- return [...val];
403
- }
404
- return [val];
405
- }
406
- var defuOverrideArray = createDefu((obj, key, value) => {
407
- if (Array.isArray(obj[key]) && Array.isArray(value)) {
408
- obj[key] = value;
409
- return true;
410
- }
546
+ if (Array.isArray(val)) return [...val];
547
+ return [val];
548
+ }
549
+ /**
550
+ * @description defu 合并策略:当目标/来源为数组时直接覆盖
551
+ */
552
+ const defuOverrideArray = createDefu((obj, key, value) => {
553
+ if (Array.isArray(obj[key]) && Array.isArray(value)) {
554
+ obj[key] = value;
555
+ return true;
556
+ }
411
557
  });
412
- function isObject2(x) {
413
- return typeof x === "object" && x !== null;
558
+ /**
559
+ * @description 判断是否为非 null 的对象
560
+ */
561
+ function isObject(x) {
562
+ return typeof x === "object" && x !== null;
414
563
  }
564
+ /**
565
+ * @description 判断对象是否为空对象
566
+ */
415
567
  function isEmptyObject(obj) {
416
- if (isObject2(obj)) {
417
- let name;
418
- for (name in obj) {
419
- return false;
420
- }
421
- return true;
422
- }
423
- return false;
424
- }
425
- var export_set = import_set_value.default;
426
- export {
427
- addExtension,
428
- arrify,
429
- defu,
430
- defuOverrideArray,
431
- escapeStringRegexp,
432
- index_default as get,
433
- isEmptyObject,
434
- isObject2 as isObject,
435
- objectHash,
436
- removeExtension,
437
- removeExtensionDeep,
438
- export_set as set
439
- };
440
- /*! Bundled license information:
441
-
442
- is-primitive/index.js:
443
- (*!
444
- * is-primitive <https://github.com/jonschlinkert/is-primitive>
445
- *
446
- * Copyright (c) 2014-present, Jon Schlinkert.
447
- * Released under the MIT License.
448
- *)
449
-
450
- isobject/index.js:
451
- (*!
452
- * isobject <https://github.com/jonschlinkert/isobject>
453
- *
454
- * Copyright (c) 2014-2017, Jon Schlinkert.
455
- * Released under the MIT License.
456
- *)
457
-
458
- is-plain-object/index.js:
459
- (*!
460
- * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
461
- *
462
- * Copyright (c) 2014-2017, Jon Schlinkert.
463
- * Released under the MIT License.
464
- *)
465
-
466
- set-value/index.js:
467
- (*!
468
- * set-value <https://github.com/jonschlinkert/set-value>
469
- *
470
- * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
471
- * Released under the MIT License.
472
- *)
473
-
474
- get-value/dist/index.mjs:
475
- (*!
476
- * get-value <https://github.com/jonschlinkert/get-value>
477
- *
478
- * Copyright (c) 2014-present, Jon Schlinkert.
479
- * Released under the MIT License.
480
- *)
568
+ if (isObject(obj)) {
569
+ let name;
570
+ for (name in obj) return false;
571
+ return true;
572
+ }
573
+ return false;
574
+ }
575
+ /**
576
+ * @description 生成稳定对象哈希,避免依赖已被禁用的 object-hash 包
481
577
  */
578
+ function objectHash(value) {
579
+ return createHash("sha256").update(stableSerialize(value)).digest("hex");
580
+ }
581
+ //#endregion
582
+ var set = import_set_value.default;
583
+ export { addExtension, arrify, defu, defuOverrideArray, escapeStringRegexp, fs, index_default as get, isEmptyObject, isObject, objectHash, removeExtension, removeExtensionDeep, set };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@weapp-core/shared",
3
3
  "type": "module",
4
- "version": "3.0.1",
4
+ "version": "3.0.3",
5
5
  "description": "@weapp-core/shared",
6
6
  "author": "ice breaker <1324318532@qq.com>",
7
7
  "license": "MIT",
@@ -41,15 +41,14 @@
41
41
  "engines": {
42
42
  "node": "^20.19.0 || >=22.12.0"
43
43
  },
44
- "dependencies": {
45
- "object-hash": "^3.0.0"
46
- },
44
+ "dependencies": {},
47
45
  "devDependencies": {},
48
46
  "scripts": {
49
- "dev": "tsup --watch --sourcemap",
50
- "build": "tsup",
47
+ "dev": "tsdown -w --sourcemap",
48
+ "build": "tsdown",
51
49
  "test": "vitest run",
52
50
  "test:dev": "vitest",
51
+ "typecheck": "tsc --noEmit",
53
52
  "release": "pnpm publish",
54
53
  "lint": "eslint .",
55
54
  "lint:fix": "eslint . --fix",