@addfox/common 0.1.1-beta.2
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/README.md +102 -0
- package/dist/cjs/errors/index.d.ts +86 -0
- package/dist/cjs/errors/index.d.ts.map +1 -0
- package/dist/cjs/hooks/HookManager.d.ts +67 -0
- package/dist/cjs/hooks/HookManager.d.ts.map +1 -0
- package/dist/cjs/hooks/index.d.ts +7 -0
- package/dist/cjs/hooks/index.d.ts.map +1 -0
- package/dist/cjs/hooks/types.d.ts +26 -0
- package/dist/cjs/hooks/types.d.ts.map +1 -0
- package/dist/cjs/index.cjs +756 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/interfaces/index.d.ts +56 -0
- package/dist/cjs/interfaces/index.d.ts.map +1 -0
- package/dist/cjs/logger/index.d.ts +171 -0
- package/dist/cjs/logger/index.d.ts.map +1 -0
- package/dist/cjs/utils/cache.d.ts +28 -0
- package/dist/cjs/utils/cache.d.ts.map +1 -0
- package/dist/cjs/utils/index.d.ts +7 -0
- package/dist/cjs/utils/index.d.ts.map +1 -0
- package/dist/cjs/utils/object.d.ts +52 -0
- package/dist/cjs/utils/object.d.ts.map +1 -0
- package/dist/cjs/utils/pipeline.d.ts +45 -0
- package/dist/cjs/utils/pipeline.d.ts.map +1 -0
- package/dist/cjs/webExtStdoutOrigin.d.ts +4 -0
- package/dist/cjs/webExtStdoutOrigin.d.ts.map +1 -0
- package/dist/esm/errors/index.d.ts +86 -0
- package/dist/esm/errors/index.d.ts.map +1 -0
- package/dist/esm/hooks/HookManager.d.ts +67 -0
- package/dist/esm/hooks/HookManager.d.ts.map +1 -0
- package/dist/esm/hooks/index.d.ts +7 -0
- package/dist/esm/hooks/index.d.ts.map +1 -0
- package/dist/esm/hooks/types.d.ts +26 -0
- package/dist/esm/hooks/types.d.ts.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +567 -0
- package/dist/esm/interfaces/index.d.ts +56 -0
- package/dist/esm/interfaces/index.d.ts.map +1 -0
- package/dist/esm/logger/index.d.ts +171 -0
- package/dist/esm/logger/index.d.ts.map +1 -0
- package/dist/esm/utils/cache.d.ts +28 -0
- package/dist/esm/utils/cache.d.ts.map +1 -0
- package/dist/esm/utils/index.d.ts +7 -0
- package/dist/esm/utils/index.d.ts.map +1 -0
- package/dist/esm/utils/object.d.ts +52 -0
- package/dist/esm/utils/object.d.ts.map +1 -0
- package/dist/esm/utils/pipeline.d.ts +45 -0
- package/dist/esm/utils/pipeline.d.ts.map +1 -0
- package/dist/esm/webExtStdoutOrigin.d.ts +4 -0
- package/dist/esm/webExtStdoutOrigin.d.ts.map +1 -0
- package/package.json +37 -0
|
@@ -0,0 +1,756 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.n = (module)=>{
|
|
5
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
+
__webpack_require__.d(getter, {
|
|
7
|
+
a: getter
|
|
8
|
+
});
|
|
9
|
+
return getter;
|
|
10
|
+
};
|
|
11
|
+
})();
|
|
12
|
+
(()=>{
|
|
13
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
14
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: definition[key]
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
})();
|
|
20
|
+
(()=>{
|
|
21
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
22
|
+
})();
|
|
23
|
+
(()=>{
|
|
24
|
+
__webpack_require__.r = (exports1)=>{
|
|
25
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
26
|
+
value: 'Module'
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
29
|
+
value: true
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
})();
|
|
33
|
+
var __webpack_exports__ = {};
|
|
34
|
+
__webpack_require__.r(__webpack_exports__);
|
|
35
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
36
|
+
memoize: ()=>memoize,
|
|
37
|
+
writeExtensionErrorBlock: ()=>writeExtensionErrorBlock,
|
|
38
|
+
setAddfoxLoggerRawWrites: ()=>setAddfoxLoggerRawWrites,
|
|
39
|
+
unflatten: ()=>unflatten,
|
|
40
|
+
StageHookManager: ()=>StageHookManager,
|
|
41
|
+
compose: ()=>compose,
|
|
42
|
+
get: ()=>get,
|
|
43
|
+
log: ()=>log,
|
|
44
|
+
deepMerge: ()=>deepMerge,
|
|
45
|
+
logDoneWithValue: ()=>logDoneWithValue,
|
|
46
|
+
partial: ()=>partial,
|
|
47
|
+
popWebExtStdoutOrigin: ()=>popWebExtStdoutOrigin,
|
|
48
|
+
tap: ()=>tap,
|
|
49
|
+
AddfoxError: ()=>AddfoxError,
|
|
50
|
+
pipeAsync: ()=>pipeAsync,
|
|
51
|
+
ANSI_COLORS: ()=>ANSI_COLORS,
|
|
52
|
+
logger: ()=>logger,
|
|
53
|
+
omit: ()=>omit,
|
|
54
|
+
flatten: ()=>flatten,
|
|
55
|
+
isEmpty: ()=>isEmpty,
|
|
56
|
+
pipe: ()=>pipe,
|
|
57
|
+
error: ()=>logger_error,
|
|
58
|
+
warn: ()=>warn,
|
|
59
|
+
logEntriesTable: ()=>logEntriesTable,
|
|
60
|
+
mapValues: ()=>mapValues,
|
|
61
|
+
createError: ()=>createError,
|
|
62
|
+
logDoneTimed: ()=>logDoneTimed,
|
|
63
|
+
isPlainObject: ()=>isPlainObject,
|
|
64
|
+
exitWithError: ()=>exitWithError,
|
|
65
|
+
pushWebExtStdoutOrigin: ()=>pushWebExtStdoutOrigin,
|
|
66
|
+
createPipeline: ()=>createPipeline,
|
|
67
|
+
tryCatchAsync: ()=>tryCatchAsync,
|
|
68
|
+
tryCatch: ()=>tryCatch,
|
|
69
|
+
set: ()=>set,
|
|
70
|
+
applyMiddleware: ()=>applyMiddleware,
|
|
71
|
+
getWebExtStdoutOriginDepth: ()=>getWebExtStdoutOriginDepth,
|
|
72
|
+
isAddfoxError: ()=>isAddfoxError,
|
|
73
|
+
ADDFOX_ERROR_CODES: ()=>ADDFOX_ERROR_CODES,
|
|
74
|
+
HookManager: ()=>HookManager,
|
|
75
|
+
createCache: ()=>createCache,
|
|
76
|
+
curry: ()=>curry,
|
|
77
|
+
filter: ()=>filter,
|
|
78
|
+
memoizeAsync: ()=>memoizeAsync,
|
|
79
|
+
pick: ()=>pick,
|
|
80
|
+
Logger: ()=>Logger,
|
|
81
|
+
formatDuration: ()=>formatDuration,
|
|
82
|
+
logDone: ()=>logDone,
|
|
83
|
+
formatError: ()=>formatError,
|
|
84
|
+
has: ()=>has
|
|
85
|
+
});
|
|
86
|
+
const external_node_util_namespaceObject = require("node:util");
|
|
87
|
+
const external_node_path_namespaceObject = require("node:path");
|
|
88
|
+
var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
|
|
89
|
+
const external_node_url_namespaceObject = require("node:url");
|
|
90
|
+
const external_cli_table3_namespaceObject = require("cli-table3");
|
|
91
|
+
var external_cli_table3_default = /*#__PURE__*/ __webpack_require__.n(external_cli_table3_namespaceObject);
|
|
92
|
+
const ANSI_COLORS = {
|
|
93
|
+
ORANGE: "\x1b[38;5;208m",
|
|
94
|
+
DONE: "\x1b[1m\x1b[32m",
|
|
95
|
+
TIME: "\x1b[38;5;245m",
|
|
96
|
+
VALUE: "\x1b[38;5;75m",
|
|
97
|
+
PURPLE: "\x1b[38;5;141m",
|
|
98
|
+
ERROR_BADGE: "\x1b[41m\x1b[93m",
|
|
99
|
+
RED: "\x1b[31m",
|
|
100
|
+
RESET: "\x1b[0m"
|
|
101
|
+
};
|
|
102
|
+
class Logger {
|
|
103
|
+
prefix;
|
|
104
|
+
showTimestamp;
|
|
105
|
+
useColors;
|
|
106
|
+
rawWrites = null;
|
|
107
|
+
constructor(options = {}){
|
|
108
|
+
this.prefix = options.prefix ?? "[Addfox]";
|
|
109
|
+
this.showTimestamp = options.showTimestamp ?? false;
|
|
110
|
+
this.useColors = options.useColors ?? true;
|
|
111
|
+
this.rawWrites = options.rawWrites ?? null;
|
|
112
|
+
}
|
|
113
|
+
setRawWrites(writes) {
|
|
114
|
+
this.rawWrites = writes;
|
|
115
|
+
}
|
|
116
|
+
getWrites() {
|
|
117
|
+
if (this.rawWrites) return this.rawWrites;
|
|
118
|
+
return {
|
|
119
|
+
stdout: process.stdout.write.bind(process.stdout),
|
|
120
|
+
stderr: process.stderr.write.bind(process.stderr)
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
formatPrefix() {
|
|
124
|
+
if (!this.useColors) return `${this.prefix} `;
|
|
125
|
+
return `${ANSI_COLORS.ORANGE}${this.prefix}${ANSI_COLORS.RESET} `;
|
|
126
|
+
}
|
|
127
|
+
formatTimestamp() {
|
|
128
|
+
if (!this.showTimestamp) return "";
|
|
129
|
+
const now = new Date();
|
|
130
|
+
const timeStr = now.toLocaleTimeString();
|
|
131
|
+
return this.useColors ? `${ANSI_COLORS.TIME}${timeStr}${ANSI_COLORS.RESET} ` : `${timeStr} `;
|
|
132
|
+
}
|
|
133
|
+
writeLines(stream, text) {
|
|
134
|
+
const w = this.getWrites()[stream];
|
|
135
|
+
const prefix = this.formatPrefix() + this.formatTimestamp();
|
|
136
|
+
for (const line of text.split("\n"))w(prefix + line + "\n", "utf8");
|
|
137
|
+
}
|
|
138
|
+
info(...args) {
|
|
139
|
+
this.writeLines("stdout", (0, external_node_util_namespaceObject.format)(...args));
|
|
140
|
+
}
|
|
141
|
+
log(...args) {
|
|
142
|
+
this.info(...args);
|
|
143
|
+
}
|
|
144
|
+
success(...args) {
|
|
145
|
+
const text = (0, external_node_util_namespaceObject.format)(...args);
|
|
146
|
+
const w = this.getWrites().stdout;
|
|
147
|
+
const prefix = this.formatPrefix() + this.formatTimestamp();
|
|
148
|
+
const donePrefix = this.useColors ? `${ANSI_COLORS.DONE}●${ANSI_COLORS.RESET} ` : "● ";
|
|
149
|
+
for (const line of text.split("\n"))w(prefix + donePrefix + line + "\n", "utf8");
|
|
150
|
+
}
|
|
151
|
+
successWithValue(label, value) {
|
|
152
|
+
const w = this.getWrites().stdout;
|
|
153
|
+
const prefix = this.formatPrefix() + this.formatTimestamp();
|
|
154
|
+
const donePrefix = this.useColors ? `${ANSI_COLORS.DONE}●${ANSI_COLORS.RESET} ` : "● ";
|
|
155
|
+
const valueColored = this.useColors ? `${ANSI_COLORS.VALUE}${value}${ANSI_COLORS.RESET}` : value;
|
|
156
|
+
const line = donePrefix + label + " " + valueColored;
|
|
157
|
+
w(prefix + line + "\n", "utf8");
|
|
158
|
+
}
|
|
159
|
+
successWithDuration(message, ms) {
|
|
160
|
+
const timeStr = this.formatDuration(ms);
|
|
161
|
+
const w = this.getWrites().stdout;
|
|
162
|
+
const prefix = this.formatPrefix() + this.formatTimestamp();
|
|
163
|
+
const donePrefix = this.useColors ? `${ANSI_COLORS.DONE}●${ANSI_COLORS.RESET} ` : "● ";
|
|
164
|
+
const timeColored = this.useColors ? `${ANSI_COLORS.TIME}${timeStr}${ANSI_COLORS.RESET}` : timeStr;
|
|
165
|
+
const line = donePrefix + message + " " + timeColored;
|
|
166
|
+
w(prefix + line + "\n", "utf8");
|
|
167
|
+
}
|
|
168
|
+
warn(...args) {
|
|
169
|
+
this.writeLines("stderr", (0, external_node_util_namespaceObject.format)(...args));
|
|
170
|
+
}
|
|
171
|
+
error(...args) {
|
|
172
|
+
const text = (0, external_node_util_namespaceObject.format)(...args);
|
|
173
|
+
const w = this.getWrites().stderr;
|
|
174
|
+
const lines = text.split("\n");
|
|
175
|
+
const errorBadge = this.useColors ? `${ANSI_COLORS.ERROR_BADGE} error ${ANSI_COLORS.RESET} ` : " error ";
|
|
176
|
+
const redPrefix = this.useColors ? ANSI_COLORS.RED : "";
|
|
177
|
+
const resetSuffix = this.useColors ? ANSI_COLORS.RESET : "";
|
|
178
|
+
w("\n", "utf8");
|
|
179
|
+
if (lines.length > 0) {
|
|
180
|
+
w(errorBadge + redPrefix + lines[0] + resetSuffix + "\n", "utf8");
|
|
181
|
+
for(let i = 1; i < lines.length; i++)w(redPrefix + lines[i] + resetSuffix + "\n", "utf8");
|
|
182
|
+
}
|
|
183
|
+
w("\n", "utf8");
|
|
184
|
+
}
|
|
185
|
+
writeErrorBlock(lines) {
|
|
186
|
+
const w = this.getWrites().stderr;
|
|
187
|
+
const errorBadge = this.useColors ? `${ANSI_COLORS.ERROR_BADGE} error ${ANSI_COLORS.RESET} ` : " error ";
|
|
188
|
+
const redPrefix = this.useColors ? ANSI_COLORS.RED : "";
|
|
189
|
+
const resetSuffix = this.useColors ? ANSI_COLORS.RESET : "";
|
|
190
|
+
w("\n", "utf8");
|
|
191
|
+
for(let i = 0; i < lines.length; i++){
|
|
192
|
+
const line = lines[i];
|
|
193
|
+
w(0 === i ? errorBadge + redPrefix + line + resetSuffix + "\n" : redPrefix + line + resetSuffix + "\n", "utf8");
|
|
194
|
+
}
|
|
195
|
+
w("\n", "utf8");
|
|
196
|
+
}
|
|
197
|
+
formatDuration(ms) {
|
|
198
|
+
if (ms >= 1000) return (ms / 1000).toFixed(2) + "s";
|
|
199
|
+
return ms + "ms";
|
|
200
|
+
}
|
|
201
|
+
logEntriesTable(entries, options) {
|
|
202
|
+
if (0 === entries.length) return;
|
|
203
|
+
const root = options?.root;
|
|
204
|
+
const headColor = this.useColors ? ANSI_COLORS.PURPLE : "";
|
|
205
|
+
const resetColor = this.useColors ? ANSI_COLORS.RESET : "";
|
|
206
|
+
const table = new (external_cli_table3_default())({
|
|
207
|
+
head: [
|
|
208
|
+
headColor + "Entry" + resetColor,
|
|
209
|
+
headColor + "File" + resetColor
|
|
210
|
+
],
|
|
211
|
+
style: {
|
|
212
|
+
head: [],
|
|
213
|
+
border: []
|
|
214
|
+
},
|
|
215
|
+
chars: {
|
|
216
|
+
top: "╌",
|
|
217
|
+
"top-mid": "┬",
|
|
218
|
+
"top-left": "┌",
|
|
219
|
+
"top-right": "┐",
|
|
220
|
+
bottom: "╌",
|
|
221
|
+
"bottom-mid": "┴",
|
|
222
|
+
"bottom-left": "└",
|
|
223
|
+
"bottom-right": "┘",
|
|
224
|
+
left: "│",
|
|
225
|
+
"left-mid": "├",
|
|
226
|
+
mid: "╌",
|
|
227
|
+
"mid-mid": "┼",
|
|
228
|
+
right: "│",
|
|
229
|
+
"right-mid": "┤",
|
|
230
|
+
middle: "│"
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
for (const e of entries){
|
|
234
|
+
const fileDisplay = void 0 !== root ? this.fileLink(e.scriptPath, external_node_path_default().relative(root, e.scriptPath).replace(/\\/g, "/")) : e.scriptPath;
|
|
235
|
+
table.push([
|
|
236
|
+
e.name,
|
|
237
|
+
fileDisplay
|
|
238
|
+
]);
|
|
239
|
+
}
|
|
240
|
+
const w = this.getWrites().stdout;
|
|
241
|
+
w(table.toString() + "\n", "utf8");
|
|
242
|
+
}
|
|
243
|
+
fileLink(absolutePath, displayText) {
|
|
244
|
+
const url = (0, external_node_url_namespaceObject.pathToFileURL)(absolutePath).href;
|
|
245
|
+
if (!this.useColors) return displayText;
|
|
246
|
+
return "\x1b]8;;" + url + "\x07" + displayText + "\x1b]8;;\x07";
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const logger = new Logger();
|
|
250
|
+
function log(...args) {
|
|
251
|
+
logger.log(...args);
|
|
252
|
+
}
|
|
253
|
+
function logDone(...args) {
|
|
254
|
+
logger.success(...args);
|
|
255
|
+
}
|
|
256
|
+
function logDoneTimed(message, ms) {
|
|
257
|
+
logger.successWithDuration(message, ms);
|
|
258
|
+
}
|
|
259
|
+
function logDoneWithValue(label, value) {
|
|
260
|
+
logger.successWithValue(label, value);
|
|
261
|
+
}
|
|
262
|
+
function formatDuration(ms) {
|
|
263
|
+
return logger.formatDuration(ms);
|
|
264
|
+
}
|
|
265
|
+
function warn(...args) {
|
|
266
|
+
logger.warn(...args);
|
|
267
|
+
}
|
|
268
|
+
function logger_error(...args) {
|
|
269
|
+
logger.error(...args);
|
|
270
|
+
}
|
|
271
|
+
function writeExtensionErrorBlock(lines) {
|
|
272
|
+
logger.writeErrorBlock(lines);
|
|
273
|
+
}
|
|
274
|
+
function logEntriesTable(entries, options) {
|
|
275
|
+
logger.logEntriesTable(entries, options);
|
|
276
|
+
}
|
|
277
|
+
function setAddfoxLoggerRawWrites(writes) {
|
|
278
|
+
logger.setRawWrites(writes);
|
|
279
|
+
}
|
|
280
|
+
const ADDFOX_ERROR_CODES = {
|
|
281
|
+
CONFIG_NOT_FOUND: "ADDFOX_CONFIG_NOT_FOUND",
|
|
282
|
+
CONFIG_LOAD_FAILED: "ADDFOX_CONFIG_LOAD_FAILED",
|
|
283
|
+
MANIFEST_MISSING: "ADDFOX_MANIFEST_MISSING",
|
|
284
|
+
APP_DIR_MISSING: "ADDFOX_APP_DIR_MISSING",
|
|
285
|
+
NO_ENTRIES: "ADDFOX_NO_ENTRIES",
|
|
286
|
+
ENTRY_SCRIPT_FROM_HTML: "ADDFOX_ENTRY_SCRIPT_FROM_HTML",
|
|
287
|
+
INVALID_BROWSER: "ADDFOX_INVALID_BROWSER",
|
|
288
|
+
UNKNOWN_COMMAND: "ADDFOX_UNKNOWN_COMMAND",
|
|
289
|
+
RSTEST_CONFIG_NOT_FOUND: "ADDFOX_RSTEST_CONFIG_NOT_FOUND",
|
|
290
|
+
RSDOCTOR_NOT_INSTALLED: "ADDFOX_RSDOCTOR_NOT_INSTALLED",
|
|
291
|
+
RSBUILD_CONFIG_ERROR: "ADDFOX_RSBUILD_CONFIG_ERROR",
|
|
292
|
+
BUILD_ERROR: "ADDFOX_BUILD_ERROR",
|
|
293
|
+
ZIP_OUTPUT: "ADDFOX_ZIP_OUTPUT",
|
|
294
|
+
ZIP_ARCHIVE: "ADDFOX_ZIP_ARCHIVE"
|
|
295
|
+
};
|
|
296
|
+
class AddfoxError extends Error {
|
|
297
|
+
code;
|
|
298
|
+
details;
|
|
299
|
+
hint;
|
|
300
|
+
cause;
|
|
301
|
+
constructor(options){
|
|
302
|
+
super(options.message);
|
|
303
|
+
this.name = "AddfoxError";
|
|
304
|
+
this.code = options.code;
|
|
305
|
+
this.details = options.details;
|
|
306
|
+
this.hint = options.hint;
|
|
307
|
+
this.cause = options.cause;
|
|
308
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
309
|
+
}
|
|
310
|
+
toJSON() {
|
|
311
|
+
return {
|
|
312
|
+
name: this.name,
|
|
313
|
+
code: this.code,
|
|
314
|
+
message: this.message,
|
|
315
|
+
details: this.details,
|
|
316
|
+
hint: this.hint,
|
|
317
|
+
stack: this.stack,
|
|
318
|
+
cause: this.cause
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
format() {
|
|
322
|
+
const parts = [
|
|
323
|
+
`[${this.code}] ${this.message}`
|
|
324
|
+
];
|
|
325
|
+
if (this.details) parts.push(` Details: ${this.details}`);
|
|
326
|
+
if (this.hint) parts.push(` Hint: ${this.hint}`);
|
|
327
|
+
return parts.join("\n");
|
|
328
|
+
}
|
|
329
|
+
toString() {
|
|
330
|
+
return this.format();
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function createError(code, message, options) {
|
|
334
|
+
return new AddfoxError({
|
|
335
|
+
code,
|
|
336
|
+
message,
|
|
337
|
+
...options
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
function isAddfoxError(error) {
|
|
341
|
+
return error instanceof AddfoxError;
|
|
342
|
+
}
|
|
343
|
+
function formatError(error) {
|
|
344
|
+
if (isAddfoxError(error)) return error.format();
|
|
345
|
+
if (error instanceof Error) return error.stack ?? error.message;
|
|
346
|
+
return String(error);
|
|
347
|
+
}
|
|
348
|
+
function exitWithError(_err, exitCode = 1) {
|
|
349
|
+
process.exit(exitCode);
|
|
350
|
+
}
|
|
351
|
+
function createCache() {
|
|
352
|
+
const store = new Map();
|
|
353
|
+
return {
|
|
354
|
+
get (key) {
|
|
355
|
+
const entry = store.get(key);
|
|
356
|
+
if (!entry) return;
|
|
357
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) return void store.delete(key);
|
|
358
|
+
return entry.value;
|
|
359
|
+
},
|
|
360
|
+
set (key, value, ttlMs) {
|
|
361
|
+
const entry = {
|
|
362
|
+
value,
|
|
363
|
+
expiresAt: ttlMs ? Date.now() + ttlMs : void 0
|
|
364
|
+
};
|
|
365
|
+
store.set(key, entry);
|
|
366
|
+
},
|
|
367
|
+
has (key) {
|
|
368
|
+
const entry = store.get(key);
|
|
369
|
+
if (!entry) return false;
|
|
370
|
+
if (entry.expiresAt && Date.now() > entry.expiresAt) {
|
|
371
|
+
store.delete(key);
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
return true;
|
|
375
|
+
},
|
|
376
|
+
delete (key) {
|
|
377
|
+
return store.delete(key);
|
|
378
|
+
},
|
|
379
|
+
clear () {
|
|
380
|
+
store.clear();
|
|
381
|
+
},
|
|
382
|
+
keys () {
|
|
383
|
+
const now = Date.now();
|
|
384
|
+
const keys = [];
|
|
385
|
+
for (const [key, entry] of store)if (!entry.expiresAt || now <= entry.expiresAt) keys.push(key);
|
|
386
|
+
return keys;
|
|
387
|
+
},
|
|
388
|
+
size () {
|
|
389
|
+
return this.keys().length;
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
function memoize(fn, keyFn) {
|
|
394
|
+
const cache = createCache();
|
|
395
|
+
return (...args)=>{
|
|
396
|
+
const key = keyFn ? keyFn(...args) : JSON.stringify(args);
|
|
397
|
+
if (cache.has(key)) return cache.get(key);
|
|
398
|
+
const result = fn(...args);
|
|
399
|
+
cache.set(key, result);
|
|
400
|
+
return result;
|
|
401
|
+
};
|
|
402
|
+
}
|
|
403
|
+
function memoizeAsync(fn, keyFn) {
|
|
404
|
+
const cache = createCache();
|
|
405
|
+
const pending = new Map();
|
|
406
|
+
return async (...args)=>{
|
|
407
|
+
const key = keyFn ? keyFn(...args) : JSON.stringify(args);
|
|
408
|
+
if (cache.has(key)) return cache.get(key);
|
|
409
|
+
if (pending.has(key)) return pending.get(key);
|
|
410
|
+
const promise = fn(...args).finally(()=>{
|
|
411
|
+
pending.delete(key);
|
|
412
|
+
});
|
|
413
|
+
pending.set(key, promise);
|
|
414
|
+
const result = await promise;
|
|
415
|
+
cache.set(key, result);
|
|
416
|
+
return result;
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
function pipe(...fns) {
|
|
420
|
+
return (x)=>fns.reduce((v, f)=>f(v), x);
|
|
421
|
+
}
|
|
422
|
+
function pipeAsync(...fns) {
|
|
423
|
+
return async (x)=>{
|
|
424
|
+
let result = x;
|
|
425
|
+
for (const fn of fns)result = await fn(result);
|
|
426
|
+
return result;
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
function compose(...fns) {
|
|
430
|
+
return (x)=>fns.reduceRight((v, f)=>f(v), x);
|
|
431
|
+
}
|
|
432
|
+
function createPipeline(...steps) {
|
|
433
|
+
return async (input)=>{
|
|
434
|
+
let result = input;
|
|
435
|
+
for (const step of steps)result = await step(result);
|
|
436
|
+
return result;
|
|
437
|
+
};
|
|
438
|
+
}
|
|
439
|
+
function applyMiddleware(value, middlewares) {
|
|
440
|
+
let index = 0;
|
|
441
|
+
function next() {
|
|
442
|
+
if (index >= middlewares.length) return value;
|
|
443
|
+
const middleware = middlewares[index++];
|
|
444
|
+
return middleware(value, next);
|
|
445
|
+
}
|
|
446
|
+
return next();
|
|
447
|
+
}
|
|
448
|
+
function curry(fn) {
|
|
449
|
+
return (a)=>(b)=>fn(a, b);
|
|
450
|
+
}
|
|
451
|
+
function partial(fn, a) {
|
|
452
|
+
return (...rest)=>fn(a, ...rest);
|
|
453
|
+
}
|
|
454
|
+
function tap(fn) {
|
|
455
|
+
return (x)=>{
|
|
456
|
+
fn(x);
|
|
457
|
+
return x;
|
|
458
|
+
};
|
|
459
|
+
}
|
|
460
|
+
function tryCatch(fn, onError) {
|
|
461
|
+
try {
|
|
462
|
+
return fn();
|
|
463
|
+
} catch (error) {
|
|
464
|
+
return onError?.(error);
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
async function tryCatchAsync(fn, onError) {
|
|
468
|
+
try {
|
|
469
|
+
return await fn();
|
|
470
|
+
} catch (error) {
|
|
471
|
+
return onError?.(error);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
function deepMerge(target, source) {
|
|
475
|
+
const result = {
|
|
476
|
+
...target
|
|
477
|
+
};
|
|
478
|
+
for (const key of Object.keys(source)){
|
|
479
|
+
const sourceValue = source[key];
|
|
480
|
+
const targetValue = result[key];
|
|
481
|
+
if (null === sourceValue || 'object' != typeof sourceValue || Array.isArray(sourceValue) || null === targetValue || 'object' != typeof targetValue || Array.isArray(targetValue)) result[key] = sourceValue;
|
|
482
|
+
else result[key] = deepMerge(targetValue, sourceValue);
|
|
483
|
+
}
|
|
484
|
+
return result;
|
|
485
|
+
}
|
|
486
|
+
function pick(obj, keys) {
|
|
487
|
+
const result = {};
|
|
488
|
+
for (const key of keys)if (key in obj) result[key] = obj[key];
|
|
489
|
+
return result;
|
|
490
|
+
}
|
|
491
|
+
function omit(obj, keys) {
|
|
492
|
+
const result = {
|
|
493
|
+
...obj
|
|
494
|
+
};
|
|
495
|
+
for (const key of keys)delete result[key];
|
|
496
|
+
return result;
|
|
497
|
+
}
|
|
498
|
+
function get(obj, path, defaultValue) {
|
|
499
|
+
const keys = path.split('.');
|
|
500
|
+
let current = obj;
|
|
501
|
+
for (const key of keys){
|
|
502
|
+
if (null == current) return defaultValue;
|
|
503
|
+
current = current[key];
|
|
504
|
+
}
|
|
505
|
+
return current ?? defaultValue;
|
|
506
|
+
}
|
|
507
|
+
function set(obj, path, value) {
|
|
508
|
+
const keys = path.split('.');
|
|
509
|
+
const result = {
|
|
510
|
+
...obj
|
|
511
|
+
};
|
|
512
|
+
let current = result;
|
|
513
|
+
for(let i = 0; i < keys.length - 1; i++){
|
|
514
|
+
const key = keys[i];
|
|
515
|
+
if (!(key in current) || 'object' != typeof current[key]) current[key] = {};
|
|
516
|
+
current = current[key];
|
|
517
|
+
}
|
|
518
|
+
current[keys[keys.length - 1]] = value;
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
521
|
+
function has(obj, path) {
|
|
522
|
+
const keys = path.split('.');
|
|
523
|
+
let current = obj;
|
|
524
|
+
for (const key of keys){
|
|
525
|
+
if (null == current || 'object' != typeof current || !(key in current)) return false;
|
|
526
|
+
current = current[key];
|
|
527
|
+
}
|
|
528
|
+
return true;
|
|
529
|
+
}
|
|
530
|
+
function flatten(obj, prefix = '') {
|
|
531
|
+
const result = {};
|
|
532
|
+
for (const [key, value] of Object.entries(obj)){
|
|
533
|
+
const newKey = prefix ? `${prefix}.${key}` : key;
|
|
534
|
+
if (null === value || 'object' != typeof value || Array.isArray(value)) result[newKey] = value;
|
|
535
|
+
else Object.assign(result, flatten(value, newKey));
|
|
536
|
+
}
|
|
537
|
+
return result;
|
|
538
|
+
}
|
|
539
|
+
function unflatten(obj) {
|
|
540
|
+
let result = {};
|
|
541
|
+
for (const [key, value] of Object.entries(obj))result = set(result, key, value);
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
544
|
+
function filter(obj, predicate) {
|
|
545
|
+
const result = {};
|
|
546
|
+
for (const [key, value] of Object.entries(obj))if (predicate(key, value)) result[key] = value;
|
|
547
|
+
return result;
|
|
548
|
+
}
|
|
549
|
+
function mapValues(obj, fn) {
|
|
550
|
+
const result = {};
|
|
551
|
+
for (const [key, value] of Object.entries(obj))result[key] = fn(value, key);
|
|
552
|
+
return result;
|
|
553
|
+
}
|
|
554
|
+
function isPlainObject(value) {
|
|
555
|
+
if (null === value || 'object' != typeof value) return false;
|
|
556
|
+
const proto = Object.getPrototypeOf(value);
|
|
557
|
+
return null === proto || proto === Object.prototype;
|
|
558
|
+
}
|
|
559
|
+
function isEmpty(value) {
|
|
560
|
+
if (null == value) return true;
|
|
561
|
+
if ('string' == typeof value || Array.isArray(value)) return 0 === value.length;
|
|
562
|
+
if (isPlainObject(value)) return 0 === Object.keys(value).length;
|
|
563
|
+
return false;
|
|
564
|
+
}
|
|
565
|
+
class HookManager {
|
|
566
|
+
registry = new Map();
|
|
567
|
+
options;
|
|
568
|
+
constructor(options = {}){
|
|
569
|
+
this.options = {
|
|
570
|
+
parallel: false,
|
|
571
|
+
bail: false,
|
|
572
|
+
...options
|
|
573
|
+
};
|
|
574
|
+
}
|
|
575
|
+
register(stage, phase, handler) {
|
|
576
|
+
const key = this.getKey(stage, phase);
|
|
577
|
+
if (!this.registry.has(key)) this.registry.set(key, []);
|
|
578
|
+
const hooks = this.registry.get(key);
|
|
579
|
+
hooks.push(handler);
|
|
580
|
+
return ()=>{
|
|
581
|
+
const index = hooks.indexOf(handler);
|
|
582
|
+
if (index > -1) hooks.splice(index, 1);
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
async execute(stage, phase, payload) {
|
|
586
|
+
const key = this.getKey(stage, phase);
|
|
587
|
+
const hooks = this.registry.get(key) || [];
|
|
588
|
+
if (0 === hooks.length) return;
|
|
589
|
+
if (this.options.parallel) if (this.options.bail) await Promise.all(hooks.map((hook)=>hook(payload)));
|
|
590
|
+
else {
|
|
591
|
+
const results = await Promise.allSettled(hooks.map((hook)=>hook(payload)));
|
|
592
|
+
const errors = results.filter((r)=>'rejected' === r.status).map((r)=>r.reason);
|
|
593
|
+
if (errors.length > 0) throw new AggregateError(errors, `Hook execution failed for ${String(stage)}:${phase}`);
|
|
594
|
+
}
|
|
595
|
+
else for (const hook of hooks)try {
|
|
596
|
+
await hook(payload);
|
|
597
|
+
} catch (error) {
|
|
598
|
+
if (this.options.bail) throw error;
|
|
599
|
+
console.error(`Hook error in ${String(stage)}:${phase}:`, error);
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
has(stage, phase) {
|
|
603
|
+
const key = this.getKey(stage, phase);
|
|
604
|
+
return (this.registry.get(key)?.length || 0) > 0;
|
|
605
|
+
}
|
|
606
|
+
count(stage, phase) {
|
|
607
|
+
const key = this.getKey(stage, phase);
|
|
608
|
+
return this.registry.get(key)?.length || 0;
|
|
609
|
+
}
|
|
610
|
+
clear(stage, phase) {
|
|
611
|
+
if (void 0 === stage) this.registry.clear();
|
|
612
|
+
else if (void 0 === phase) {
|
|
613
|
+
this.registry.delete(this.getKey(stage, 'before'));
|
|
614
|
+
this.registry.delete(this.getKey(stage, 'after'));
|
|
615
|
+
} else this.registry.delete(this.getKey(stage, phase));
|
|
616
|
+
}
|
|
617
|
+
getKey(stage, phase) {
|
|
618
|
+
return `${String(stage)}:${phase}`;
|
|
619
|
+
}
|
|
620
|
+
for(stage) {
|
|
621
|
+
return new StageHookManager(this, stage);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
class StageHookManager {
|
|
625
|
+
manager;
|
|
626
|
+
stage;
|
|
627
|
+
constructor(manager, stage){
|
|
628
|
+
this.manager = manager;
|
|
629
|
+
this.stage = stage;
|
|
630
|
+
}
|
|
631
|
+
before(handler) {
|
|
632
|
+
return this.manager.register(this.stage, 'before', handler);
|
|
633
|
+
}
|
|
634
|
+
after(handler) {
|
|
635
|
+
return this.manager.register(this.stage, 'after', handler);
|
|
636
|
+
}
|
|
637
|
+
async runBefore(payload) {
|
|
638
|
+
return this.manager.execute(this.stage, 'before', payload);
|
|
639
|
+
}
|
|
640
|
+
async runAfter(payload) {
|
|
641
|
+
return this.manager.execute(this.stage, 'after', payload);
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
let webExtStdoutOriginDepth = 0;
|
|
645
|
+
function pushWebExtStdoutOrigin() {
|
|
646
|
+
webExtStdoutOriginDepth += 1;
|
|
647
|
+
}
|
|
648
|
+
function popWebExtStdoutOrigin() {
|
|
649
|
+
webExtStdoutOriginDepth = Math.max(0, webExtStdoutOriginDepth - 1);
|
|
650
|
+
}
|
|
651
|
+
function getWebExtStdoutOriginDepth() {
|
|
652
|
+
return webExtStdoutOriginDepth;
|
|
653
|
+
}
|
|
654
|
+
exports.ADDFOX_ERROR_CODES = __webpack_exports__.ADDFOX_ERROR_CODES;
|
|
655
|
+
exports.ANSI_COLORS = __webpack_exports__.ANSI_COLORS;
|
|
656
|
+
exports.AddfoxError = __webpack_exports__.AddfoxError;
|
|
657
|
+
exports.HookManager = __webpack_exports__.HookManager;
|
|
658
|
+
exports.Logger = __webpack_exports__.Logger;
|
|
659
|
+
exports.StageHookManager = __webpack_exports__.StageHookManager;
|
|
660
|
+
exports.applyMiddleware = __webpack_exports__.applyMiddleware;
|
|
661
|
+
exports.compose = __webpack_exports__.compose;
|
|
662
|
+
exports.createCache = __webpack_exports__.createCache;
|
|
663
|
+
exports.createError = __webpack_exports__.createError;
|
|
664
|
+
exports.createPipeline = __webpack_exports__.createPipeline;
|
|
665
|
+
exports.curry = __webpack_exports__.curry;
|
|
666
|
+
exports.deepMerge = __webpack_exports__.deepMerge;
|
|
667
|
+
exports.error = __webpack_exports__.error;
|
|
668
|
+
exports.exitWithError = __webpack_exports__.exitWithError;
|
|
669
|
+
exports.filter = __webpack_exports__.filter;
|
|
670
|
+
exports.flatten = __webpack_exports__.flatten;
|
|
671
|
+
exports.formatDuration = __webpack_exports__.formatDuration;
|
|
672
|
+
exports.formatError = __webpack_exports__.formatError;
|
|
673
|
+
exports.get = __webpack_exports__.get;
|
|
674
|
+
exports.getWebExtStdoutOriginDepth = __webpack_exports__.getWebExtStdoutOriginDepth;
|
|
675
|
+
exports.has = __webpack_exports__.has;
|
|
676
|
+
exports.isAddfoxError = __webpack_exports__.isAddfoxError;
|
|
677
|
+
exports.isEmpty = __webpack_exports__.isEmpty;
|
|
678
|
+
exports.isPlainObject = __webpack_exports__.isPlainObject;
|
|
679
|
+
exports.log = __webpack_exports__.log;
|
|
680
|
+
exports.logDone = __webpack_exports__.logDone;
|
|
681
|
+
exports.logDoneTimed = __webpack_exports__.logDoneTimed;
|
|
682
|
+
exports.logDoneWithValue = __webpack_exports__.logDoneWithValue;
|
|
683
|
+
exports.logEntriesTable = __webpack_exports__.logEntriesTable;
|
|
684
|
+
exports.logger = __webpack_exports__.logger;
|
|
685
|
+
exports.mapValues = __webpack_exports__.mapValues;
|
|
686
|
+
exports.memoize = __webpack_exports__.memoize;
|
|
687
|
+
exports.memoizeAsync = __webpack_exports__.memoizeAsync;
|
|
688
|
+
exports.omit = __webpack_exports__.omit;
|
|
689
|
+
exports.partial = __webpack_exports__.partial;
|
|
690
|
+
exports.pick = __webpack_exports__.pick;
|
|
691
|
+
exports.pipe = __webpack_exports__.pipe;
|
|
692
|
+
exports.pipeAsync = __webpack_exports__.pipeAsync;
|
|
693
|
+
exports.popWebExtStdoutOrigin = __webpack_exports__.popWebExtStdoutOrigin;
|
|
694
|
+
exports.pushWebExtStdoutOrigin = __webpack_exports__.pushWebExtStdoutOrigin;
|
|
695
|
+
exports.set = __webpack_exports__.set;
|
|
696
|
+
exports.setAddfoxLoggerRawWrites = __webpack_exports__.setAddfoxLoggerRawWrites;
|
|
697
|
+
exports.tap = __webpack_exports__.tap;
|
|
698
|
+
exports.tryCatch = __webpack_exports__.tryCatch;
|
|
699
|
+
exports.tryCatchAsync = __webpack_exports__.tryCatchAsync;
|
|
700
|
+
exports.unflatten = __webpack_exports__.unflatten;
|
|
701
|
+
exports.warn = __webpack_exports__.warn;
|
|
702
|
+
exports.writeExtensionErrorBlock = __webpack_exports__.writeExtensionErrorBlock;
|
|
703
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
704
|
+
"ADDFOX_ERROR_CODES",
|
|
705
|
+
"ANSI_COLORS",
|
|
706
|
+
"AddfoxError",
|
|
707
|
+
"HookManager",
|
|
708
|
+
"Logger",
|
|
709
|
+
"StageHookManager",
|
|
710
|
+
"applyMiddleware",
|
|
711
|
+
"compose",
|
|
712
|
+
"createCache",
|
|
713
|
+
"createError",
|
|
714
|
+
"createPipeline",
|
|
715
|
+
"curry",
|
|
716
|
+
"deepMerge",
|
|
717
|
+
"error",
|
|
718
|
+
"exitWithError",
|
|
719
|
+
"filter",
|
|
720
|
+
"flatten",
|
|
721
|
+
"formatDuration",
|
|
722
|
+
"formatError",
|
|
723
|
+
"get",
|
|
724
|
+
"getWebExtStdoutOriginDepth",
|
|
725
|
+
"has",
|
|
726
|
+
"isAddfoxError",
|
|
727
|
+
"isEmpty",
|
|
728
|
+
"isPlainObject",
|
|
729
|
+
"log",
|
|
730
|
+
"logDone",
|
|
731
|
+
"logDoneTimed",
|
|
732
|
+
"logDoneWithValue",
|
|
733
|
+
"logEntriesTable",
|
|
734
|
+
"logger",
|
|
735
|
+
"mapValues",
|
|
736
|
+
"memoize",
|
|
737
|
+
"memoizeAsync",
|
|
738
|
+
"omit",
|
|
739
|
+
"partial",
|
|
740
|
+
"pick",
|
|
741
|
+
"pipe",
|
|
742
|
+
"pipeAsync",
|
|
743
|
+
"popWebExtStdoutOrigin",
|
|
744
|
+
"pushWebExtStdoutOrigin",
|
|
745
|
+
"set",
|
|
746
|
+
"setAddfoxLoggerRawWrites",
|
|
747
|
+
"tap",
|
|
748
|
+
"tryCatch",
|
|
749
|
+
"tryCatchAsync",
|
|
750
|
+
"unflatten",
|
|
751
|
+
"warn",
|
|
752
|
+
"writeExtensionErrorBlock"
|
|
753
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
754
|
+
Object.defineProperty(exports, '__esModule', {
|
|
755
|
+
value: true
|
|
756
|
+
});
|