@hot-updater/repack 0.16.7-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/dist/index.js CHANGED
@@ -1,319 +1,493 @@
1
- /*! For license information please see index.js.LICENSE.txt */
2
- import * as __WEBPACK_EXTERNAL_MODULE_fs__ from "fs";
3
- import * as __WEBPACK_EXTERNAL_MODULE_path__ from "path";
4
- import * as __WEBPACK_EXTERNAL_MODULE__hot_updater_plugin_core_40c1c502__ from "@hot-updater/plugin-core";
5
- var __webpack_modules__ = {
6
- "../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js": function(module) {
7
- let p = process || {}, argv = p.argv || [], env = p.env || {};
8
- let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || "win32" === p.platform || (p.stdout || {}).isTTY && "dumb" !== env.TERM || !!env.CI);
9
- let formatter = (open, close, replace = open)=>(input)=>{
10
- let string = "" + input, index = string.indexOf(close, open.length);
11
- return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
12
- };
13
- let replaceClose = (string, close, replace, index)=>{
14
- let result = "", cursor = 0;
15
- do {
16
- result += string.substring(cursor, index) + replace;
17
- cursor = index + close.length;
18
- index = string.indexOf(close, cursor);
19
- }while (~index);
20
- return result + string.substring(cursor);
21
- };
22
- let createColors = (enabled = isColorSupported)=>{
23
- let f = enabled ? formatter : ()=>String;
24
- return {
25
- isColorSupported: enabled,
26
- reset: f("\x1b[0m", "\x1b[0m"),
27
- bold: f("\x1b[1m", "\x1b[22m", "\x1b[22m\x1b[1m"),
28
- dim: f("\x1b[2m", "\x1b[22m", "\x1b[22m\x1b[2m"),
29
- italic: f("\x1b[3m", "\x1b[23m"),
30
- underline: f("\x1b[4m", "\x1b[24m"),
31
- inverse: f("\x1b[7m", "\x1b[27m"),
32
- hidden: f("\x1b[8m", "\x1b[28m"),
33
- strikethrough: f("\x1b[9m", "\x1b[29m"),
34
- black: f("\x1b[30m", "\x1b[39m"),
35
- red: f("\x1b[31m", "\x1b[39m"),
36
- green: f("\x1b[32m", "\x1b[39m"),
37
- yellow: f("\x1b[33m", "\x1b[39m"),
38
- blue: f("\x1b[34m", "\x1b[39m"),
39
- magenta: f("\x1b[35m", "\x1b[39m"),
40
- cyan: f("\x1b[36m", "\x1b[39m"),
41
- white: f("\x1b[37m", "\x1b[39m"),
42
- gray: f("\x1b[90m", "\x1b[39m"),
43
- bgBlack: f("\x1b[40m", "\x1b[49m"),
44
- bgRed: f("\x1b[41m", "\x1b[49m"),
45
- bgGreen: f("\x1b[42m", "\x1b[49m"),
46
- bgYellow: f("\x1b[43m", "\x1b[49m"),
47
- bgBlue: f("\x1b[44m", "\x1b[49m"),
48
- bgMagenta: f("\x1b[45m", "\x1b[49m"),
49
- bgCyan: f("\x1b[46m", "\x1b[49m"),
50
- bgWhite: f("\x1b[47m", "\x1b[49m"),
51
- blackBright: f("\x1b[90m", "\x1b[39m"),
52
- redBright: f("\x1b[91m", "\x1b[39m"),
53
- greenBright: f("\x1b[92m", "\x1b[39m"),
54
- yellowBright: f("\x1b[93m", "\x1b[39m"),
55
- blueBright: f("\x1b[94m", "\x1b[39m"),
56
- magentaBright: f("\x1b[95m", "\x1b[39m"),
57
- cyanBright: f("\x1b[96m", "\x1b[39m"),
58
- whiteBright: f("\x1b[97m", "\x1b[39m"),
59
- bgBlackBright: f("\x1b[100m", "\x1b[49m"),
60
- bgRedBright: f("\x1b[101m", "\x1b[49m"),
61
- bgGreenBright: f("\x1b[102m", "\x1b[49m"),
62
- bgYellowBright: f("\x1b[103m", "\x1b[49m"),
63
- bgBlueBright: f("\x1b[104m", "\x1b[49m"),
64
- bgMagentaBright: f("\x1b[105m", "\x1b[49m"),
65
- bgCyanBright: f("\x1b[106m", "\x1b[49m"),
66
- bgWhiteBright: f("\x1b[107m", "\x1b[49m")
67
- };
68
- };
69
- module.exports = createColors();
70
- module.exports.createColors = createColors;
71
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { getCwd, loadConfigSync } from "@hot-updater/plugin-core";
4
+
5
+ //#region rolldown:runtime
6
+ var __create = Object.create;
7
+ var __defProp = Object.defineProperty;
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __commonJS = (cb, mod) => function() {
13
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
72
14
  };
73
- var __webpack_module_cache__ = {};
74
- function __webpack_require__(moduleId) {
75
- var cachedModule = __webpack_module_cache__[moduleId];
76
- if (void 0 !== cachedModule) return cachedModule.exports;
77
- var module = __webpack_module_cache__[moduleId] = {
78
- exports: {}
79
- };
80
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
81
- return module.exports;
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
17
+ key = keys[i];
18
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: ((k) => from[k]).bind(null, key),
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+
30
+ //#endregion
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;
82
43
  }
83
- (()=>{
84
- __webpack_require__.n = (module)=>{
85
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
86
- __webpack_require__.d(getter, {
87
- a: getter
88
- });
89
- return getter;
90
- };
91
- })();
92
- (()=>{
93
- __webpack_require__.d = (exports, definition)=>{
94
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) Object.defineProperty(exports, key, {
95
- enumerable: true,
96
- get: definition[key]
97
- });
98
- };
99
- })();
100
- (()=>{
101
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
102
- })();
103
- var picocolors = __webpack_require__("../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js");
104
- var picocolors_default = /*#__PURE__*/ __webpack_require__.n(picocolors);
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
105
116
  /**
106
- * uuidv7: A JavaScript implementation of UUID version 7
107
- *
108
- * Copyright 2021-2024 LiosK
109
- *
110
- * @license Apache-2.0
111
- * @packageDocumentation
112
- */ const DIGITS = "0123456789abcdef";
113
- class UUID {
114
- constructor(bytes){
115
- this.bytes = bytes;
116
- }
117
- static ofInner(bytes) {
118
- if (16 === bytes.length) return new UUID(bytes);
119
- throw new TypeError("not 128-bit length");
120
- }
121
- static fromFieldsV7(unixTsMs, randA, randBHi, randBLo) {
122
- if (!Number.isInteger(unixTsMs) || !Number.isInteger(randA) || !Number.isInteger(randBHi) || !Number.isInteger(randBLo) || unixTsMs < 0 || randA < 0 || randBHi < 0 || randBLo < 0 || unixTsMs > 281474976710655 || randA > 0xfff || randBHi > 1073741823 || randBLo > 4294967295) throw new RangeError("invalid field value");
123
- const bytes = new Uint8Array(16);
124
- bytes[0] = unixTsMs / 2 ** 40;
125
- bytes[1] = unixTsMs / 2 ** 32;
126
- bytes[2] = unixTsMs / 2 ** 24;
127
- bytes[3] = unixTsMs / 2 ** 16;
128
- bytes[4] = unixTsMs / 256;
129
- bytes[5] = unixTsMs;
130
- bytes[6] = 0x70 | randA >>> 8;
131
- bytes[7] = randA;
132
- bytes[8] = 0x80 | randBHi >>> 24;
133
- bytes[9] = randBHi >>> 16;
134
- bytes[10] = randBHi >>> 8;
135
- bytes[11] = randBHi;
136
- bytes[12] = randBLo >>> 24;
137
- bytes[13] = randBLo >>> 16;
138
- bytes[14] = randBLo >>> 8;
139
- bytes[15] = randBLo;
140
- return new UUID(bytes);
141
- }
142
- static parse(uuid) {
143
- var _a, _b, _c, _d;
144
- let hex;
145
- switch(uuid.length){
146
- case 32:
147
- hex = null == (_a = /^[0-9a-f]{32}$/i.exec(uuid)) ? void 0 : _a[0];
148
- break;
149
- case 36:
150
- hex = null == (_b = /^([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})$/i.exec(uuid)) ? void 0 : _b.slice(1, 6).join("");
151
- break;
152
- case 38:
153
- hex = null == (_c = /^\{([0-9a-f]{8})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{4})-([0-9a-f]{12})\}$/i.exec(uuid)) ? void 0 : _c.slice(1, 6).join("");
154
- break;
155
- case 45:
156
- hex = null == (_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)) ? void 0 : _d.slice(1, 6).join("");
157
- break;
158
- default:
159
- break;
160
- }
161
- if (hex) {
162
- const inner = new Uint8Array(16);
163
- for(let i = 0; i < 16; i += 4){
164
- const n = parseInt(hex.substring(2 * i, 2 * i + 8), 16);
165
- inner[i + 0] = n >>> 24;
166
- inner[i + 1] = n >>> 16;
167
- inner[i + 2] = n >>> 8;
168
- inner[i + 3] = n;
169
- }
170
- return new UUID(inner);
171
- }
172
- throw new SyntaxError("could not parse UUID string");
173
- }
174
- toString() {
175
- let text = "";
176
- for(let i = 0; i < this.bytes.length; i++){
177
- text += DIGITS.charAt(this.bytes[i] >>> 4);
178
- text += DIGITS.charAt(0xf & this.bytes[i]);
179
- if (3 === i || 5 === i || 7 === i || 9 === i) text += "-";
180
- }
181
- return text;
182
- }
183
- toHex() {
184
- let text = "";
185
- for(let i = 0; i < this.bytes.length; i++){
186
- text += DIGITS.charAt(this.bytes[i] >>> 4);
187
- text += DIGITS.charAt(0xf & this.bytes[i]);
188
- }
189
- return text;
190
- }
191
- toJSON() {
192
- return this.toString();
193
- }
194
- getVariant() {
195
- const n = this.bytes[8] >>> 4;
196
- if (n < 0) throw new Error("unreachable");
197
- if (n <= 7) return this.bytes.every((e)=>0 === e) ? "NIL" : "VAR_0";
198
- if (n <= 11) return "VAR_10";
199
- if (n <= 13) return "VAR_110";
200
- if (n <= 15) return this.bytes.every((e)=>0xff === e) ? "MAX" : "VAR_RESERVED";
201
- else throw new Error("unreachable");
202
- }
203
- getVersion() {
204
- return "VAR_10" === this.getVariant() ? this.bytes[6] >>> 4 : void 0;
205
- }
206
- clone() {
207
- return new UUID(this.bytes.slice(0));
208
- }
209
- equals(other) {
210
- return 0 === this.compareTo(other);
211
- }
212
- compareTo(other) {
213
- for(let i = 0; i < 16; i++){
214
- const diff = this.bytes[i] - other.bytes[i];
215
- if (0 !== diff) return Math.sign(diff);
216
- }
217
- return 0;
218
- }
219
- }
220
- class V7Generator {
221
- constructor(randomNumberGenerator){
222
- this.timestamp = 0;
223
- this.counter = 0;
224
- this.random = null != randomNumberGenerator ? randomNumberGenerator : getDefaultRandom();
225
- }
226
- generate() {
227
- return this.generateOrResetCore(Date.now(), 10000);
228
- }
229
- generateOrAbort() {
230
- return this.generateOrAbortCore(Date.now(), 10000);
231
- }
232
- generateOrResetCore(unixTsMs, rollbackAllowance) {
233
- let value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
234
- if (void 0 === value) {
235
- this.timestamp = 0;
236
- value = this.generateOrAbortCore(unixTsMs, rollbackAllowance);
237
- }
238
- return value;
239
- }
240
- generateOrAbortCore(unixTsMs, rollbackAllowance) {
241
- const MAX_COUNTER = 4398046511103;
242
- if (!Number.isInteger(unixTsMs) || unixTsMs < 1 || unixTsMs > 281474976710655) throw new RangeError("`unixTsMs` must be a 48-bit positive integer");
243
- if (rollbackAllowance < 0 || rollbackAllowance > 281474976710655) throw new RangeError("`rollbackAllowance` out of reasonable range");
244
- if (unixTsMs > this.timestamp) {
245
- this.timestamp = unixTsMs;
246
- this.resetCounter();
247
- } else {
248
- if (!(unixTsMs + rollbackAllowance >= this.timestamp)) return;
249
- this.counter++;
250
- if (this.counter > MAX_COUNTER) {
251
- this.timestamp++;
252
- this.resetCounter();
253
- }
254
- }
255
- return UUID.fromFieldsV7(this.timestamp, Math.trunc(this.counter / 2 ** 30), this.counter & 2 ** 30 - 1, this.random.nextUint32());
256
- }
257
- resetCounter() {
258
- this.counter = 0x400 * this.random.nextUint32() + (0x3ff & this.random.nextUint32());
259
- }
260
- generateV4() {
261
- const bytes = new Uint8Array(Uint32Array.of(this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32(), this.random.nextUint32()).buffer);
262
- bytes[6] = 0x40 | bytes[6] >>> 4;
263
- bytes[8] = 0x80 | bytes[8] >>> 2;
264
- return UUID.ofInner(bytes);
265
- }
266
- }
267
- const getDefaultRandom = ()=>{
268
- if ("undefined" != typeof crypto && void 0 !== crypto.getRandomValues) return new BufferedCryptoRandom();
269
- if ("undefined" != typeof UUIDV7_DENY_WEAK_RNG && UUIDV7_DENY_WEAK_RNG) throw new Error("no cryptographically strong RNG available");
270
- return {
271
- nextUint32: ()=>65536 * Math.trunc(65536 * Math.random()) + Math.trunc(65536 * Math.random())
272
- };
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
+ }
273
431
  };
274
- class BufferedCryptoRandom {
275
- constructor(){
276
- this.buffer = new Uint32Array(8);
277
- this.cursor = 0xffff;
278
- }
279
- nextUint32() {
280
- if (this.cursor >= this.buffer.length) {
281
- crypto.getRandomValues(this.buffer);
282
- this.cursor = 0;
283
- }
284
- return this.buffer[this.cursor++];
285
- }
286
- }
287
432
  let defaultGenerator;
288
- const uuidv7 = ()=>uuidv7obj().toString();
289
- const uuidv7obj = ()=>(defaultGenerator || (defaultGenerator = new V7Generator())).generate();
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);
290
446
  const NIL_UUID = "00000000-0000-0000-0000-000000000000";
291
- const getBundleId = ()=>{
292
- const buildOutDir = process.env["BUILD_OUT_DIR"];
293
- if (!buildOutDir) return NIL_UUID;
294
- const bundleIdPath = __WEBPACK_EXTERNAL_MODULE_path__["default"].join(buildOutDir, "BUNDLE_ID");
295
- let bundleId = uuidv7();
296
- if (__WEBPACK_EXTERNAL_MODULE_fs__["default"].existsSync(bundleIdPath)) bundleId = __WEBPACK_EXTERNAL_MODULE_fs__["default"].readFileSync(bundleIdPath, "utf-8");
297
- else {
298
- __WEBPACK_EXTERNAL_MODULE_fs__["default"].writeFileSync(bundleIdPath, bundleId);
299
- console.log(picocolors_default().green(`[HotUpdater] Generated bundle ID: ${bundleId}`));
300
- }
301
- return bundleId;
447
+ const memoizeLoadConfig = memoize(loadConfigSync);
448
+ const getBundleId = () => {
449
+ const buildOutDir = process.env["BUILD_OUT_DIR"];
450
+ if (!buildOutDir) return NIL_UUID;
451
+ const bundleIdPath = path.join(buildOutDir, "BUNDLE_ID");
452
+ let bundleId = uuidv7();
453
+ if (fs.existsSync(bundleIdPath)) bundleId = fs.readFileSync(bundleIdPath, "utf-8");
454
+ else {
455
+ fs.writeFileSync(bundleIdPath, bundleId);
456
+ console.log(import_picocolors.default.green(`[HotUpdater] Generated bundle ID: ${bundleId}`));
457
+ }
458
+ return bundleId;
302
459
  };
303
- const getChannel = ()=>{
304
- const currentEnv = process.env["BABEL_ENV"] || process.env["NODE_ENV"];
305
- if ("development" === currentEnv) return null;
306
- const envChannel = process.env["HOT_UPDATER_CHANNEL"];
307
- if (envChannel) return envChannel;
308
- const { releaseChannel } = (0, __WEBPACK_EXTERNAL_MODULE__hot_updater_plugin_core_40c1c502__.loadConfigSync)(null);
309
- return releaseChannel;
460
+ const getFingerprintJson = () => {
461
+ const { updateStrategy } = memoizeLoadConfig(null);
462
+ if (updateStrategy === "appVersion") return null;
463
+ const fingerprintPath = path.join(getCwd(), "fingerprint.json");
464
+ if (!fs.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.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
+ }
310
474
  };
311
- class HotUpdaterPlugin {
312
- apply(compiler) {
313
- new compiler.webpack.DefinePlugin({
314
- __HOT_UPDATER_BUNDLE_ID: JSON.stringify(getBundleId()),
315
- __HOT_UPDATER_CHANNEL: JSON.stringify(getChannel())
316
- }).apply(compiler);
317
- }
318
- }
319
- export { HotUpdaterPlugin, getChannel };
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
+ export { HotUpdaterPlugin };