@hot-updater/repack 0.17.0 → 0.18.0
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/LICENSE +21 -0
- package/dist/index.cjs +491 -346
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +485 -311
- package/package.json +4 -3
- package/dist/index.cjs.LICENSE.txt +0 -8
- package/dist/index.js.LICENSE.txt +0 -8
package/dist/index.cjs
CHANGED
|
@@ -1,348 +1,493 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let replaceClose = (string, close, replace, index)=>{
|
|
11
|
-
let result = "", cursor = 0;
|
|
12
|
-
do {
|
|
13
|
-
result += string.substring(cursor, index) + replace;
|
|
14
|
-
cursor = index + close.length;
|
|
15
|
-
index = string.indexOf(close, cursor);
|
|
16
|
-
}while (~index);
|
|
17
|
-
return result + string.substring(cursor);
|
|
18
|
-
};
|
|
19
|
-
let createColors = (enabled = isColorSupported)=>{
|
|
20
|
-
let f = enabled ? formatter : ()=>String;
|
|
21
|
-
return {
|
|
22
|
-
isColorSupported: enabled,
|
|
23
|
-
reset: f("\x1b[0m", "\x1b[0m"),
|
|
24
|
-
bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
|
|
25
|
-
dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
|
|
26
|
-
italic: f("\x1b[3m", "\x1b[23m"),
|
|
27
|
-
underline: f("\x1b[4m", "\x1b[24m"),
|
|
28
|
-
inverse: f("\x1b[7m", "\x1b[27m"),
|
|
29
|
-
hidden: f("\x1b[8m", "\x1b[28m"),
|
|
30
|
-
strikethrough: f("\x1b[9m", "\x1b[29m"),
|
|
31
|
-
black: f("\x1b[30m", "\x1b[39m"),
|
|
32
|
-
red: f("\x1b[31m", "\x1b[39m"),
|
|
33
|
-
green: f("\x1b[32m", "\x1b[39m"),
|
|
34
|
-
yellow: f("\x1b[33m", "\x1b[39m"),
|
|
35
|
-
blue: f("\x1b[34m", "\x1b[39m"),
|
|
36
|
-
magenta: f("\x1b[35m", "\x1b[39m"),
|
|
37
|
-
cyan: f("\x1b[36m", "\x1b[39m"),
|
|
38
|
-
white: f("\x1b[37m", "\x1b[39m"),
|
|
39
|
-
gray: f("\x1b[90m", "\x1b[39m"),
|
|
40
|
-
bgBlack: f("\x1b[40m", "\x1b[49m"),
|
|
41
|
-
bgRed: f("\x1b[41m", "\x1b[49m"),
|
|
42
|
-
bgGreen: f("\x1b[42m", "\x1b[49m"),
|
|
43
|
-
bgYellow: f("\x1b[43m", "\x1b[49m"),
|
|
44
|
-
bgBlue: f("\x1b[44m", "\x1b[49m"),
|
|
45
|
-
bgMagenta: f("\x1b[45m", "\x1b[49m"),
|
|
46
|
-
bgCyan: f("\x1b[46m", "\x1b[49m"),
|
|
47
|
-
bgWhite: f("\x1b[47m", "\x1b[49m"),
|
|
48
|
-
blackBright: f("\x1b[90m", "\x1b[39m"),
|
|
49
|
-
redBright: f("\x1b[91m", "\x1b[39m"),
|
|
50
|
-
greenBright: f("\x1b[92m", "\x1b[39m"),
|
|
51
|
-
yellowBright: f("\x1b[93m", "\x1b[39m"),
|
|
52
|
-
blueBright: f("\x1b[94m", "\x1b[39m"),
|
|
53
|
-
magentaBright: f("\x1b[95m", "\x1b[39m"),
|
|
54
|
-
cyanBright: f("\x1b[96m", "\x1b[39m"),
|
|
55
|
-
whiteBright: f("\x1b[97m", "\x1b[39m"),
|
|
56
|
-
bgBlackBright: f("\x1b[100m", "\x1b[49m"),
|
|
57
|
-
bgRedBright: f("\x1b[101m", "\x1b[49m"),
|
|
58
|
-
bgGreenBright: f("\x1b[102m", "\x1b[49m"),
|
|
59
|
-
bgYellowBright: f("\x1b[103m", "\x1b[49m"),
|
|
60
|
-
bgBlueBright: f("\x1b[104m", "\x1b[49m"),
|
|
61
|
-
bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
|
|
62
|
-
bgCyanBright: f("\x1b[106m", "\x1b[49m"),
|
|
63
|
-
bgWhiteBright: f("\x1b[107m", "\x1b[49m")
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
module.exports = createColors();
|
|
67
|
-
module.exports.createColors = createColors;
|
|
68
|
-
}
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
69
10
|
};
|
|
70
|
-
var
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
13
|
+
key = keys[i];
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
15
|
+
get: ((k) => from[k]).bind(null, key),
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
value: mod,
|
|
23
|
+
enumerable: true
|
|
24
|
+
}) : target, mod));
|
|
25
|
+
|
|
26
|
+
//#endregion
|
|
27
|
+
const fs = __toESM(require("fs"));
|
|
28
|
+
const path = __toESM(require("path"));
|
|
29
|
+
const __hot_updater_plugin_core = __toESM(require("@hot-updater/plugin-core"));
|
|
30
|
+
|
|
31
|
+
//#region ../../node_modules/.pnpm/es-toolkit@1.32.0/node_modules/es-toolkit/dist/function/memoize.mjs
|
|
32
|
+
function memoize(fn, options = {}) {
|
|
33
|
+
const { cache = new Map(), getCacheKey } = options;
|
|
34
|
+
const memoizedFn = function(arg) {
|
|
35
|
+
const key = getCacheKey ? getCacheKey(arg) : arg;
|
|
36
|
+
if (cache.has(key)) return cache.get(key);
|
|
37
|
+
const result = fn.call(this, arg);
|
|
38
|
+
cache.set(key, result);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
memoizedFn.cache = cache;
|
|
42
|
+
return memoizedFn;
|
|
79
43
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
(
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
47
|
+
var require_picocolors = __commonJS({ "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js"(exports, module) {
|
|
48
|
+
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
49
|
+
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
50
|
+
let formatter = (open, close, replace = open) => (input) => {
|
|
51
|
+
let string = "" + input, index = string.indexOf(close, open.length);
|
|
52
|
+
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
53
|
+
};
|
|
54
|
+
let replaceClose = (string, close, replace, index) => {
|
|
55
|
+
let result = "", cursor = 0;
|
|
56
|
+
do {
|
|
57
|
+
result += string.substring(cursor, index) + replace;
|
|
58
|
+
cursor = index + close.length;
|
|
59
|
+
index = string.indexOf(close, cursor);
|
|
60
|
+
} while (~index);
|
|
61
|
+
return result + string.substring(cursor);
|
|
62
|
+
};
|
|
63
|
+
let createColors = (enabled = isColorSupported) => {
|
|
64
|
+
let f = enabled ? formatter : () => String;
|
|
65
|
+
return {
|
|
66
|
+
isColorSupported: enabled,
|
|
67
|
+
reset: f("\x1B[0m", "\x1B[0m"),
|
|
68
|
+
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
69
|
+
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
70
|
+
italic: f("\x1B[3m", "\x1B[23m"),
|
|
71
|
+
underline: f("\x1B[4m", "\x1B[24m"),
|
|
72
|
+
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
73
|
+
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
74
|
+
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
75
|
+
black: f("\x1B[30m", "\x1B[39m"),
|
|
76
|
+
red: f("\x1B[31m", "\x1B[39m"),
|
|
77
|
+
green: f("\x1B[32m", "\x1B[39m"),
|
|
78
|
+
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
79
|
+
blue: f("\x1B[34m", "\x1B[39m"),
|
|
80
|
+
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
81
|
+
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
82
|
+
white: f("\x1B[37m", "\x1B[39m"),
|
|
83
|
+
gray: f("\x1B[90m", "\x1B[39m"),
|
|
84
|
+
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
85
|
+
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
86
|
+
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
87
|
+
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
88
|
+
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
89
|
+
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
90
|
+
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
91
|
+
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
92
|
+
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
93
|
+
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
94
|
+
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
95
|
+
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
96
|
+
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
97
|
+
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
98
|
+
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
99
|
+
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
100
|
+
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
101
|
+
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
102
|
+
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
103
|
+
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
104
|
+
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
105
|
+
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
106
|
+
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
107
|
+
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
module.exports = createColors();
|
|
111
|
+
module.exports.createColors = createColors;
|
|
112
|
+
} });
|
|
113
|
+
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region ../../node_modules/.pnpm/uuidv7@1.0.2/node_modules/uuidv7/dist/index.js
|
|
116
|
+
/**
|
|
117
|
+
* uuidv7: A JavaScript implementation of UUID version 7
|
|
118
|
+
*
|
|
119
|
+
* Copyright 2021-2024 LiosK
|
|
120
|
+
*
|
|
121
|
+
* @license Apache-2.0
|
|
122
|
+
* @packageDocumentation
|
|
123
|
+
*/
|
|
124
|
+
const DIGITS = "0123456789abcdef";
|
|
125
|
+
/** Represents a UUID as a 16-byte byte array. */
|
|
126
|
+
var UUID = class UUID {
|
|
127
|
+
/** @param bytes - The 16-byte byte array representation. */
|
|
128
|
+
constructor(bytes) {
|
|
129
|
+
this.bytes = bytes;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Creates an object from the internal representation, a 16-byte byte array
|
|
133
|
+
* containing the binary UUID representation in the big-endian byte order.
|
|
134
|
+
*
|
|
135
|
+
* This method does NOT shallow-copy the argument, and thus the created object
|
|
136
|
+
* holds the reference to the underlying buffer.
|
|
137
|
+
*
|
|
138
|
+
* @throws TypeError if the length of the argument is not 16.
|
|
139
|
+
*/
|
|
140
|
+
static ofInner(bytes) {
|
|
141
|
+
if (bytes.length !== 16) throw new TypeError("not 128-bit length");
|
|
142
|
+
else return new UUID(bytes);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Builds a byte array from UUIDv7 field values.
|
|
146
|
+
*
|
|
147
|
+
* @param unixTsMs - A 48-bit `unix_ts_ms` field value.
|
|
148
|
+
* @param randA - A 12-bit `rand_a` field value.
|
|
149
|
+
* @param randBHi - The higher 30 bits of 62-bit `rand_b` field value.
|
|
150
|
+
* @param randBLo - The lower 32 bits of 62-bit `rand_b` field value.
|
|
151
|
+
* @throws RangeError if any field value is out of the specified range.
|
|
152
|
+
*/
|
|
153
|
+
static fromFieldsV7(unixTsMs, randA, randBHi, randBLo) {
|
|
154
|
+
if (!Number.isInteger(unixTsMs) || !Number.isInteger(randA) || !Number.isInteger(randBHi) || !Number.isInteger(randBLo) || unixTsMs < 0 || randA < 0 || randBHi < 0 || randBLo < 0 || unixTsMs > 0xffffffffffff || randA > 4095 || randBHi > 1073741823 || randBLo > 4294967295) throw new RangeError("invalid field value");
|
|
155
|
+
const bytes = new Uint8Array(16);
|
|
156
|
+
bytes[0] = unixTsMs / 2 ** 40;
|
|
157
|
+
bytes[1] = unixTsMs / 2 ** 32;
|
|
158
|
+
bytes[2] = unixTsMs / 2 ** 24;
|
|
159
|
+
bytes[3] = unixTsMs / 2 ** 16;
|
|
160
|
+
bytes[4] = unixTsMs / 2 ** 8;
|
|
161
|
+
bytes[5] = unixTsMs;
|
|
162
|
+
bytes[6] = 112 | randA >>> 8;
|
|
163
|
+
bytes[7] = randA;
|
|
164
|
+
bytes[8] = 128 | randBHi >>> 24;
|
|
165
|
+
bytes[9] = randBHi >>> 16;
|
|
166
|
+
bytes[10] = randBHi >>> 8;
|
|
167
|
+
bytes[11] = randBHi;
|
|
168
|
+
bytes[12] = randBLo >>> 24;
|
|
169
|
+
bytes[13] = randBLo >>> 16;
|
|
170
|
+
bytes[14] = randBLo >>> 8;
|
|
171
|
+
bytes[15] = randBLo;
|
|
172
|
+
return new UUID(bytes);
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Builds a byte array from a string representation.
|
|
176
|
+
*
|
|
177
|
+
* This method accepts the following formats:
|
|
178
|
+
*
|
|
179
|
+
* - 32-digit hexadecimal format without hyphens: `0189dcd553117d408db09496a2eef37b`
|
|
180
|
+
* - 8-4-4-4-12 hyphenated format: `0189dcd5-5311-7d40-8db0-9496a2eef37b`
|
|
181
|
+
* - Hyphenated format with surrounding braces: `{0189dcd5-5311-7d40-8db0-9496a2eef37b}`
|
|
182
|
+
* - RFC 9562 URN format: `urn:uuid:0189dcd5-5311-7d40-8db0-9496a2eef37b`
|
|
183
|
+
*
|
|
184
|
+
* Leading and trailing whitespaces represents an error.
|
|
185
|
+
*
|
|
186
|
+
* @throws SyntaxError if the argument could not parse as a valid UUID string.
|
|
187
|
+
*/
|
|
188
|
+
static parse(uuid) {
|
|
189
|
+
var _a, _b, _c, _d;
|
|
190
|
+
let hex = void 0;
|
|
191
|
+
switch (uuid.length) {
|
|
192
|
+
case 32:
|
|
193
|
+
hex = (_a = /^[0-9a-f]{32}$/i.exec(uuid)) === null || _a === void 0 ? void 0 : _a[0];
|
|
194
|
+
break;
|
|
195
|
+
case 36:
|
|
196
|
+
hex = (_b = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(uuid)) === null || _b === void 0 ? void 0 : _b.slice(1, 6).join("");
|
|
197
|
+
break;
|
|
198
|
+
case 38:
|
|
199
|
+
hex = (_c = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i.exec(uuid)) === null || _c === void 0 ? void 0 : _c.slice(1, 6).join("");
|
|
200
|
+
break;
|
|
201
|
+
case 45:
|
|
202
|
+
hex = (_d = /^urn:uuid:([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(uuid)) === null || _d === void 0 ? void 0 : _d.slice(1, 6).join("");
|
|
203
|
+
break;
|
|
204
|
+
default: break;
|
|
205
|
+
}
|
|
206
|
+
if (hex) {
|
|
207
|
+
const inner = new Uint8Array(16);
|
|
208
|
+
for (let i = 0; i < 16; i += 4) {
|
|
209
|
+
const n = parseInt(hex.substring(2 * i, 2 * i + 8), 16);
|
|
210
|
+
inner[i + 0] = n >>> 24;
|
|
211
|
+
inner[i + 1] = n >>> 16;
|
|
212
|
+
inner[i + 2] = n >>> 8;
|
|
213
|
+
inner[i + 3] = n;
|
|
214
|
+
}
|
|
215
|
+
return new UUID(inner);
|
|
216
|
+
} else throw new SyntaxError("could not parse UUID string");
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @returns The 8-4-4-4-12 canonical hexadecimal string representation
|
|
220
|
+
* (`0189dcd5-5311-7d40-8db0-9496a2eef37b`).
|
|
221
|
+
*/
|
|
222
|
+
toString() {
|
|
223
|
+
let text = "";
|
|
224
|
+
for (let i = 0; i < this.bytes.length; i++) {
|
|
225
|
+
text += DIGITS.charAt(this.bytes[i] >>> 4);
|
|
226
|
+
text += DIGITS.charAt(this.bytes[i] & 15);
|
|
227
|
+
if (i === 3 || i === 5 || i === 7 || i === 9) text += "-";
|
|
228
|
+
}
|
|
229
|
+
return text;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* @returns The 32-digit hexadecimal representation without hyphens
|
|
233
|
+
* (`0189dcd553117d408db09496a2eef37b`).
|
|
234
|
+
*/
|
|
235
|
+
toHex() {
|
|
236
|
+
let text = "";
|
|
237
|
+
for (let i = 0; i < this.bytes.length; i++) {
|
|
238
|
+
text += DIGITS.charAt(this.bytes[i] >>> 4);
|
|
239
|
+
text += DIGITS.charAt(this.bytes[i] & 15);
|
|
240
|
+
}
|
|
241
|
+
return text;
|
|
242
|
+
}
|
|
243
|
+
/** @returns The 8-4-4-4-12 canonical hexadecimal string representation. */
|
|
244
|
+
toJSON() {
|
|
245
|
+
return this.toString();
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Reports the variant field value of the UUID or, if appropriate, "NIL" or
|
|
249
|
+
* "MAX".
|
|
250
|
+
*
|
|
251
|
+
* For convenience, this method reports "NIL" or "MAX" if `this` represents
|
|
252
|
+
* the Nil or Max UUID, although the Nil and Max UUIDs are technically
|
|
253
|
+
* subsumed under the variants `0b0` and `0b111`, respectively.
|
|
254
|
+
*/
|
|
255
|
+
getVariant() {
|
|
256
|
+
const n = this.bytes[8] >>> 4;
|
|
257
|
+
if (n < 0) throw new Error("unreachable");
|
|
258
|
+
else if (n <= 7) return this.bytes.every((e) => e === 0) ? "NIL" : "VAR_0";
|
|
259
|
+
else if (n <= 11) return "VAR_10";
|
|
260
|
+
else if (n <= 13) return "VAR_110";
|
|
261
|
+
else if (n <= 15) return this.bytes.every((e) => e === 255) ? "MAX" : "VAR_RESERVED";
|
|
262
|
+
else throw new Error("unreachable");
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Returns the version field value of the UUID or `undefined` if the UUID does
|
|
266
|
+
* not have the variant field value of `0b10`.
|
|
267
|
+
*/
|
|
268
|
+
getVersion() {
|
|
269
|
+
return this.getVariant() === "VAR_10" ? this.bytes[6] >>> 4 : void 0;
|
|
270
|
+
}
|
|
271
|
+
/** Creates an object from `this`. */
|
|
272
|
+
clone() {
|
|
273
|
+
return new UUID(this.bytes.slice(0));
|
|
274
|
+
}
|
|
275
|
+
/** Returns true if `this` is equivalent to `other`. */
|
|
276
|
+
equals(other) {
|
|
277
|
+
return this.compareTo(other) === 0;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Returns a negative integer, zero, or positive integer if `this` is less
|
|
281
|
+
* than, equal to, or greater than `other`, respectively.
|
|
282
|
+
*/
|
|
283
|
+
compareTo(other) {
|
|
284
|
+
for (let i = 0; i < 16; i++) {
|
|
285
|
+
const diff = this.bytes[i] - other.bytes[i];
|
|
286
|
+
if (diff !== 0) return Math.sign(diff);
|
|
287
|
+
}
|
|
288
|
+
return 0;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
/**
|
|
292
|
+
* Encapsulates the monotonic counter state.
|
|
293
|
+
*
|
|
294
|
+
* This class provides APIs to utilize a separate counter state from that of the
|
|
295
|
+
* global generator used by {@link uuidv7} and {@link uuidv7obj}. In addition to
|
|
296
|
+
* the default {@link generate} method, this class has {@link generateOrAbort}
|
|
297
|
+
* that is useful to absolutely guarantee the monotonically increasing order of
|
|
298
|
+
* generated UUIDs. See their respective documentation for details.
|
|
299
|
+
*/
|
|
300
|
+
var V7Generator = class {
|
|
301
|
+
/**
|
|
302
|
+
* Creates a generator object with the default random number generator, or
|
|
303
|
+
* with the specified one if passed as an argument. The specified random
|
|
304
|
+
* number generator should be cryptographically strong and securely seeded.
|
|
305
|
+
*/
|
|
306
|
+
constructor(randomNumberGenerator) {
|
|
307
|
+
this.timestamp = 0;
|
|
308
|
+
this.counter = 0;
|
|
309
|
+
this.random = randomNumberGenerator !== null && randomNumberGenerator !== void 0 ? randomNumberGenerator : getDefaultRandom();
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Generates a new UUIDv7 object from the current timestamp, or resets the
|
|
313
|
+
* generator upon significant timestamp rollback.
|
|
314
|
+
*
|
|
315
|
+
* This method returns a monotonically increasing UUID by reusing the previous
|
|
316
|
+
* timestamp even if the up-to-date timestamp is smaller than the immediately
|
|
317
|
+
* preceding UUID's. However, when such a clock rollback is considered
|
|
318
|
+
* significant (i.e., by more than ten seconds), this method resets the
|
|
319
|
+
* generator and returns a new UUID based on the given timestamp, breaking the
|
|
320
|
+
* increasing order of UUIDs.
|
|
321
|
+
*
|
|
322
|
+
* See {@link generateOrAbort} for the other mode of generation and
|
|
323
|
+
* {@link generateOrResetCore} for the low-level primitive.
|
|
324
|
+
*/
|
|
325
|
+
generate() {
|
|
326
|
+
return this.generateOrResetCore(Date.now(), 1e4);
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Generates a new UUIDv7 object from the current timestamp, or returns
|
|
330
|
+
* `undefined` upon significant timestamp rollback.
|
|
331
|
+
*
|
|
332
|
+
* This method returns a monotonically increasing UUID by reusing the previous
|
|
333
|
+
* timestamp even if the up-to-date timestamp is smaller than the immediately
|
|
334
|
+
* preceding UUID's. However, when such a clock rollback is considered
|
|
335
|
+
* significant (i.e., by more than ten seconds), this method aborts and
|
|
336
|
+
* returns `undefined` immediately.
|
|
337
|
+
*
|
|
338
|
+
* See {@link generate} for the other mode of generation and
|
|
339
|
+
* {@link generateOrAbortCore} for the low-level primitive.
|
|
340
|
+
*/
|
|
341
|
+
generateOrAbort() {
|
|
342
|
+
return this.generateOrAbortCore(Date.now(), 1e4);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Generates a new UUIDv7 object from the `unixTsMs` passed, or resets the
|
|
346
|
+
* generator upon significant timestamp rollback.
|
|
347
|
+
*
|
|
348
|
+
* This method is equivalent to {@link generate} except that it takes a custom
|
|
349
|
+
* timestamp and clock rollback allowance.
|
|
350
|
+
*
|
|
351
|
+
* @param rollbackAllowance - The amount of `unixTsMs` rollback that is
|
|
352
|
+
* considered significant. A suggested value is `10_000` (milliseconds).
|
|
353
|
+
* @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
|
|
354
|
+
*/
|
|
355
|
+
generateOrResetCore(unixTsMs, rollbackAllowance) {
|
|
356
|
+
let value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
|
|
357
|
+
if (value === void 0) {
|
|
358
|
+
this.timestamp = 0;
|
|
359
|
+
value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
|
|
360
|
+
}
|
|
361
|
+
return value;
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Generates a new UUIDv7 object from the `unixTsMs` passed, or returns
|
|
365
|
+
* `undefined` upon significant timestamp rollback.
|
|
366
|
+
*
|
|
367
|
+
* This method is equivalent to {@link generateOrAbort} except that it takes a
|
|
368
|
+
* custom timestamp and clock rollback allowance.
|
|
369
|
+
*
|
|
370
|
+
* @param rollbackAllowance - The amount of `unixTsMs` rollback that is
|
|
371
|
+
* considered significant. A suggested value is `10_000` (milliseconds).
|
|
372
|
+
* @throws RangeError if `unixTsMs` is not a 48-bit positive integer.
|
|
373
|
+
*/
|
|
374
|
+
generateOrAbortCore(unixTsMs, rollbackAllowance) {
|
|
375
|
+
const MAX_COUNTER = 4398046511103;
|
|
376
|
+
if (!Number.isInteger(unixTsMs) || unixTsMs < 1 || unixTsMs > 0xffffffffffff) throw new RangeError("`unixTsMs` must be a 48-bit positive integer");
|
|
377
|
+
else if (rollbackAllowance < 0 || rollbackAllowance > 0xffffffffffff) throw new RangeError("`rollbackAllowance` out of reasonable range");
|
|
378
|
+
if (unixTsMs > this.timestamp) {
|
|
379
|
+
this.timestamp = unixTsMs;
|
|
380
|
+
this.resetCounter();
|
|
381
|
+
} else if (unixTsMs + rollbackAllowance >= this.timestamp) {
|
|
382
|
+
this.counter++;
|
|
383
|
+
if (this.counter > MAX_COUNTER) {
|
|
384
|
+
this.timestamp++;
|
|
385
|
+
this.resetCounter();
|
|
386
|
+
}
|
|
387
|
+
} else return void 0;
|
|
388
|
+
return UUID.fromFieldsV7(this.timestamp, Math.trunc(this.counter / 2 ** 30), this.counter & 2 ** 30 - 1, this.random.nextUint32());
|
|
389
|
+
}
|
|
390
|
+
/** Initializes the counter at a 42-bit random integer. */
|
|
391
|
+
resetCounter() {
|
|
392
|
+
this.counter = this.random.nextUint32() * 1024 + (this.random.nextUint32() & 1023);
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Generates a new UUIDv4 object utilizing the random number generator inside.
|
|
396
|
+
*
|
|
397
|
+
* @internal
|
|
398
|
+
*/
|
|
399
|
+
generateV4() {
|
|
400
|
+
const bytes = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
|
|
401
|
+
bytes[6] = 64 | bytes[6] >>> 4;
|
|
402
|
+
bytes[8] = 128 | bytes[8] >>> 2;
|
|
403
|
+
return UUID.ofInner(bytes);
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
/** Returns the default random number generator available in the environment. */
|
|
407
|
+
const getDefaultRandom = () => {
|
|
408
|
+
if (typeof crypto !== "undefined" && typeof crypto.getRandomValues !== "undefined") return new BufferedCryptoRandom();
|
|
409
|
+
else {
|
|
410
|
+
if (typeof UUIDV7_DENY_WEAK_RNG !== "undefined" && UUIDV7_DENY_WEAK_RNG) throw new Error("no cryptographically strong RNG available");
|
|
411
|
+
return { nextUint32: () => Math.trunc(Math.random() * 65536) * 65536 + Math.trunc(Math.random() * 65536) };
|
|
412
|
+
}
|
|
413
|
+
};
|
|
414
|
+
/**
|
|
415
|
+
* Wraps `crypto.getRandomValues()` to enable buffering; this uses a small
|
|
416
|
+
* buffer by default to avoid both unbearable throughput decline in some
|
|
417
|
+
* environments and the waste of time and space for unused values.
|
|
418
|
+
*/
|
|
419
|
+
var BufferedCryptoRandom = class {
|
|
420
|
+
constructor() {
|
|
421
|
+
this.buffer = new Uint32Array(8);
|
|
422
|
+
this.cursor = 65535;
|
|
423
|
+
}
|
|
424
|
+
nextUint32() {
|
|
425
|
+
if (this.cursor >= this.buffer.length) {
|
|
426
|
+
crypto.getRandomValues(this.buffer);
|
|
427
|
+
this.cursor = 0;
|
|
428
|
+
}
|
|
429
|
+
return this.buffer[this.cursor++];
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
let defaultGenerator;
|
|
433
|
+
/**
|
|
434
|
+
* Generates a UUIDv7 string.
|
|
435
|
+
*
|
|
436
|
+
* @returns The 8-4-4-4-12 canonical hexadecimal string representation
|
|
437
|
+
* ("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx").
|
|
438
|
+
*/
|
|
439
|
+
const uuidv7 = () => uuidv7obj().toString();
|
|
440
|
+
/** Generates a UUIDv7 object. */
|
|
441
|
+
const uuidv7obj = () => (defaultGenerator || (defaultGenerator = new V7Generator())).generate();
|
|
442
|
+
|
|
443
|
+
//#endregion
|
|
444
|
+
//#region src/index.ts
|
|
445
|
+
var import_picocolors = __toESM(require_picocolors(), 1);
|
|
446
|
+
const NIL_UUID = "00000000-0000-0000-0000-000000000000";
|
|
447
|
+
const memoizeLoadConfig = memoize(__hot_updater_plugin_core.loadConfigSync);
|
|
448
|
+
const getBundleId = () => {
|
|
449
|
+
const buildOutDir = process.env["BUILD_OUT_DIR"];
|
|
450
|
+
if (!buildOutDir) return NIL_UUID;
|
|
451
|
+
const bundleIdPath = path.default.join(buildOutDir, "BUNDLE_ID");
|
|
452
|
+
let bundleId = uuidv7();
|
|
453
|
+
if (fs.default.existsSync(bundleIdPath)) bundleId = fs.default.readFileSync(bundleIdPath, "utf-8");
|
|
454
|
+
else {
|
|
455
|
+
fs.default.writeFileSync(bundleIdPath, bundleId);
|
|
456
|
+
console.log(import_picocolors.default.green(`[HotUpdater] Generated bundle ID: ${bundleId}`));
|
|
457
|
+
}
|
|
458
|
+
return bundleId;
|
|
459
|
+
};
|
|
460
|
+
const getFingerprintJson = () => {
|
|
461
|
+
const { updateStrategy } = memoizeLoadConfig(null);
|
|
462
|
+
if (updateStrategy === "appVersion") return null;
|
|
463
|
+
const fingerprintPath = path.default.join((0, __hot_updater_plugin_core.getCwd)(), "fingerprint.json");
|
|
464
|
+
if (!fs.default.existsSync(fingerprintPath)) throw new Error("Missing fingerprint.json. Since updateStrategy is set to 'fingerprint' in hot-updater.config, please run `hot-updater fingerprint create`.");
|
|
465
|
+
try {
|
|
466
|
+
const fingerprint = JSON.parse(fs.default.readFileSync(fingerprintPath, "utf-8"));
|
|
467
|
+
return {
|
|
468
|
+
iosHash: fingerprint.ios.hash,
|
|
469
|
+
androidHash: fingerprint.android.hash
|
|
470
|
+
};
|
|
471
|
+
} catch {
|
|
472
|
+
throw new Error("Invalid fingerprint.json. Since updateStrategy is set to 'fingerprint' in hot-updater.config, please run `hot-updater fingerprint create`.");
|
|
473
|
+
}
|
|
474
|
+
};
|
|
475
|
+
const getOverTheAirChannel = () => {
|
|
476
|
+
return process.env?.["HOT_UPDATER_CHANNEL"] ?? null;
|
|
477
|
+
};
|
|
478
|
+
var HotUpdaterPlugin = class {
|
|
479
|
+
apply(compiler) {
|
|
480
|
+
const fingerprint = getFingerprintJson();
|
|
481
|
+
const { updateStrategy } = memoizeLoadConfig(null);
|
|
482
|
+
new compiler.webpack.DefinePlugin({
|
|
483
|
+
__HOT_UPDATER_BUNDLE_ID: JSON.stringify(getBundleId()),
|
|
484
|
+
__HOT_UPDATER_CHANNEL: JSON.stringify(getOverTheAirChannel()),
|
|
485
|
+
__HOT_UPDATER_FINGERPRINT_HASH_IOS: JSON.stringify(fingerprint?.iosHash ?? null),
|
|
486
|
+
__HOT_UPDATER_FINGERPRINT_HASH_ANDROID: JSON.stringify(fingerprint?.androidHash ?? null),
|
|
487
|
+
__HOT_UPDATER_UPDATE_STRATEGY: JSON.stringify(updateStrategy)
|
|
488
|
+
}).apply(compiler);
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
//#endregion
|
|
493
|
+
exports.HotUpdaterPlugin = HotUpdaterPlugin;
|