zeed 0.8.3 → 0.8.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-AM7QCF4I.js +29 -1
- package/dist/chunk-AM7QCF4I.js.map +1 -1
- package/dist/chunk-OJCXV4BY.js +15 -2
- package/dist/chunk-OJCXV4BY.js.map +1 -1
- package/dist/chunk-QCWYJ7FQ.js +23 -4
- package/dist/chunk-QCWYJ7FQ.js.map +1 -1
- package/dist/chunk-RIAAIUAZ.js +255 -6
- package/dist/chunk-RIAAIUAZ.js.map +1 -1
- package/dist/chunk-S5JPRTZ4.js +83 -18
- package/dist/chunk-S5JPRTZ4.js.map +1 -1
- package/dist/index.all.cjs +5354 -1134
- package/dist/index.all.cjs.map +1 -1
- package/dist/index.all.js +576 -5
- package/dist/index.all.js.map +1 -1
- package/dist/index.browser.cjs +4659 -1045
- package/dist/index.browser.cjs.map +1 -1
- package/dist/index.browser.js +530 -4
- package/dist/index.browser.js.map +1 -1
- package/dist/index.log.cjs +655 -19
- package/dist/index.log.cjs.map +1 -1
- package/dist/index.log.js +14 -2
- package/dist/index.log.js.map +1 -1
- package/dist/index.node.cjs +4787 -1096
- package/dist/index.node.cjs.map +1 -1
- package/dist/index.node.js +554 -3
- package/dist/index.node.js.map +1 -1
- package/package.json +4 -3
- package/dist/chunk-AITOWUS2.cjs +0 -3305
- package/dist/chunk-AITOWUS2.cjs.map +0 -1
- package/dist/chunk-C66X5FP6.cjs +0 -516
- package/dist/chunk-C66X5FP6.cjs.map +0 -1
- package/dist/chunk-CCZIVE22.cjs +0 -657
- package/dist/chunk-CCZIVE22.cjs.map +0 -1
- package/dist/chunk-KG3OKVAH.cjs +0 -254
- package/dist/chunk-KG3OKVAH.cjs.map +0 -1
- package/dist/chunk-RHL3RQGE.cjs +0 -320
- package/dist/chunk-RHL3RQGE.cjs.map +0 -1
package/dist/chunk-CCZIVE22.cjs
DELETED
|
@@ -1,657 +0,0 @@
|
|
|
1
|
-
"use strict"; function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var chunkAITOWUS2_cjs = require('./chunk-AITOWUS2.cjs');
|
|
6
|
-
var chunkC66X5FP6_cjs = require('./chunk-C66X5FP6.cjs');
|
|
7
|
-
var child_process = require('child_process');
|
|
8
|
-
var fs = require('fs');
|
|
9
|
-
var path = require('path');
|
|
10
|
-
var promises = require('fs/promises');
|
|
11
|
-
var tty = require('tty');
|
|
12
|
-
var nodeCrypto = require('crypto');
|
|
13
|
-
|
|
14
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
-
|
|
16
|
-
var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
17
|
-
var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty);
|
|
18
|
-
var nodeCrypto__default = /*#__PURE__*/_interopDefaultLegacy(nodeCrypto);
|
|
19
|
-
|
|
20
|
-
// src/node/args.ts
|
|
21
|
-
function parseArgs(config = {}) {
|
|
22
|
-
const {
|
|
23
|
-
args = process.argv.slice(1),
|
|
24
|
-
alias = {},
|
|
25
|
-
normalize: normalize2 = chunkAITOWUS2_cjs.toCamelCase,
|
|
26
|
-
booleanArgs = [],
|
|
27
|
-
listArgs = [],
|
|
28
|
-
numberArgs = []
|
|
29
|
-
} = config;
|
|
30
|
-
let nameToAlias = Object.entries(alias).reduce((map, curr) => {
|
|
31
|
-
let [name, values] = curr;
|
|
32
|
-
if (typeof values === "string")
|
|
33
|
-
values = [values];
|
|
34
|
-
for (let value of values) {
|
|
35
|
-
map[normalize2(value)] = normalize2(name);
|
|
36
|
-
}
|
|
37
|
-
return map;
|
|
38
|
-
}, {});
|
|
39
|
-
let opts = {
|
|
40
|
-
_: []
|
|
41
|
-
};
|
|
42
|
-
function setOpt(name, value) {
|
|
43
|
-
if (opts[name] == null) {
|
|
44
|
-
opts[name] = value;
|
|
45
|
-
} else if (typeof opts[name] === "boolean") {
|
|
46
|
-
opts[name] = value;
|
|
47
|
-
} else if (Array.isArray(opts[name])) {
|
|
48
|
-
opts[name].push(value);
|
|
49
|
-
} else {
|
|
50
|
-
opts[name] = [opts[name], value];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
chunkC66X5FP6_cjs.__name(setOpt, "setOpt");
|
|
54
|
-
let argList = [...args];
|
|
55
|
-
let arg;
|
|
56
|
-
while (arg = argList.shift()) {
|
|
57
|
-
let value;
|
|
58
|
-
if (/^--?/.test(arg)) {
|
|
59
|
-
let key = arg.replace(/^--?/, "");
|
|
60
|
-
if (arg.includes("=")) {
|
|
61
|
-
let [name, valuePart] = key.split("=", 2);
|
|
62
|
-
key = name.trim();
|
|
63
|
-
value = valuePart.trim();
|
|
64
|
-
}
|
|
65
|
-
key = normalize2(key);
|
|
66
|
-
key = _nullishCoalesce(nameToAlias[key], () => ( key));
|
|
67
|
-
if (booleanArgs.includes(key)) {
|
|
68
|
-
setOpt(key, true);
|
|
69
|
-
} else {
|
|
70
|
-
value = _nullishCoalesce(_nullishCoalesce(value, () => ( argList.shift())), () => ( ""));
|
|
71
|
-
if (numberArgs.includes(key)) {
|
|
72
|
-
value = Number(_nullishCoalesce(value, () => ( 0)));
|
|
73
|
-
}
|
|
74
|
-
if (listArgs.includes(key)) {
|
|
75
|
-
if (Array.isArray(opts[key])) {
|
|
76
|
-
opts[key].push(value);
|
|
77
|
-
} else {
|
|
78
|
-
opts[key] = [value];
|
|
79
|
-
}
|
|
80
|
-
} else {
|
|
81
|
-
setOpt(key, value);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
opts._.push(arg);
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return opts;
|
|
89
|
-
}
|
|
90
|
-
chunkC66X5FP6_cjs.__name(parseArgs, "parseArgs");
|
|
91
|
-
function pbcopy(data) {
|
|
92
|
-
return new Promise(async (resolve6, reject) => {
|
|
93
|
-
const proc = child_process.spawn("pbcopy");
|
|
94
|
-
proc.on("error", (err) => reject(err));
|
|
95
|
-
proc.on("close", () => resolve6(data));
|
|
96
|
-
proc.stdin.write(data);
|
|
97
|
-
proc.stdin.end();
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
chunkC66X5FP6_cjs.__name(pbcopy, "pbcopy");
|
|
101
|
-
var log = chunkC66X5FP6_cjs.Logger("zeed:env");
|
|
102
|
-
var NEWLINE = "\n";
|
|
103
|
-
var RE_INI_KEY_VAL = /^\s*([\w_.-]+)\s*=\s*(.*)?\s*$/;
|
|
104
|
-
var RE_NEWLINES = /\\n/g;
|
|
105
|
-
var NEWLINES_MATCH = /\n|\r|\r\n/;
|
|
106
|
-
function parse(src, options = {}) {
|
|
107
|
-
let obj = {};
|
|
108
|
-
String(src).split(NEWLINES_MATCH).forEach(function(line, idx) {
|
|
109
|
-
const keyValueArr = line.match(RE_INI_KEY_VAL);
|
|
110
|
-
if (keyValueArr != null) {
|
|
111
|
-
const key = keyValueArr[1];
|
|
112
|
-
let val = keyValueArr[2] || "";
|
|
113
|
-
const end = val.length - 1;
|
|
114
|
-
const isDoubleQuoted = val[0] === '"' && val[end] === '"';
|
|
115
|
-
const isSingleQuoted = val[0] === "'" && val[end] === "'";
|
|
116
|
-
if (isSingleQuoted || isDoubleQuoted) {
|
|
117
|
-
val = val.substring(1, end);
|
|
118
|
-
if (isDoubleQuoted) {
|
|
119
|
-
val = val.replace(RE_NEWLINES, NEWLINE);
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
val = val.trim();
|
|
123
|
-
}
|
|
124
|
-
obj[key] = val;
|
|
125
|
-
} else {
|
|
126
|
-
log.debug(
|
|
127
|
-
`did not match key and value when parsing line ${idx + 1}: ${line}`
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
return obj;
|
|
132
|
-
}
|
|
133
|
-
chunkC66X5FP6_cjs.__name(parse, "parse");
|
|
134
|
-
function stringToPath(value, defaultValue = ".") {
|
|
135
|
-
return path.resolve(process.cwd(), _nullishCoalesce(value, () => ( defaultValue)));
|
|
136
|
-
}
|
|
137
|
-
chunkC66X5FP6_cjs.__name(stringToPath, "stringToPath");
|
|
138
|
-
function valueToPath(value, defaultValue = "") {
|
|
139
|
-
if (value == null)
|
|
140
|
-
value = defaultValue;
|
|
141
|
-
return stringToPath(String(value).trim(), defaultValue);
|
|
142
|
-
}
|
|
143
|
-
chunkC66X5FP6_cjs.__name(valueToPath, "valueToPath");
|
|
144
|
-
var toPath = valueToPath;
|
|
145
|
-
function setupEnv(options = {}) {
|
|
146
|
-
const dotenvPath = _nullishCoalesce((options == null ? void 0 : options.path), () => ( toPath(_nullishCoalesce((options == null ? void 0 : options.filename), () => ( ".env")))));
|
|
147
|
-
const encoding = _nullishCoalesce((options == null ? void 0 : options.encoding), () => ( "utf8"));
|
|
148
|
-
const debug = (options == null ? void 0 : options.debug) || false;
|
|
149
|
-
if (debug !== true)
|
|
150
|
-
log.level = Infinity /* off */;
|
|
151
|
-
try {
|
|
152
|
-
const parsedEnv = fs__default["default"].existsSync(dotenvPath) ? parse(fs__default["default"].readFileSync(dotenvPath, { encoding }), { debug }) : {};
|
|
153
|
-
const parsedEnvLocal = fs__default["default"].existsSync(dotenvPath + ".local") ? parse(fs__default["default"].readFileSync(dotenvPath + ".local", { encoding }), { debug }) : {};
|
|
154
|
-
const parsed = Object.assign(
|
|
155
|
-
{},
|
|
156
|
-
parsedEnv,
|
|
157
|
-
parsedEnvLocal
|
|
158
|
-
);
|
|
159
|
-
let env = _nullishCoalesce((options == null ? void 0 : options.env), () => ( process.env));
|
|
160
|
-
Object.entries(parsed).forEach(([key, value]) => {
|
|
161
|
-
if (typeof (options == null ? void 0 : options.prefix) === "string") {
|
|
162
|
-
key = (options == null ? void 0 : options.prefix) + key;
|
|
163
|
-
}
|
|
164
|
-
if (!Object.prototype.hasOwnProperty.call(env, key)) {
|
|
165
|
-
if (value != null) {
|
|
166
|
-
log.info(`set env.${key} = ${value}`);
|
|
167
|
-
env[key] = value;
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
log.debug(`"${key}" is already defined and will not be overwritten`);
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
return { parsed };
|
|
174
|
-
} catch (e) {
|
|
175
|
-
log.error(e);
|
|
176
|
-
return { error: e };
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
chunkC66X5FP6_cjs.__name(setupEnv, "setupEnv");
|
|
180
|
-
var log2 = chunkC66X5FP6_cjs.Logger("zeed:filestorage");
|
|
181
|
-
var FileStorage = class {
|
|
182
|
-
constructor(opt = {}) {
|
|
183
|
-
this.store = {};
|
|
184
|
-
this.fileKeys = void 0;
|
|
185
|
-
this.pretty = false;
|
|
186
|
-
this.dirname = path.resolve(process.cwd(), opt.path || ".fileStorage");
|
|
187
|
-
this.pretty = !!opt.pretty;
|
|
188
|
-
this.extension = _nullishCoalesce(opt.extension, () => ( ".json"));
|
|
189
|
-
if (opt.extension && !this.extension.startsWith(".")) {
|
|
190
|
-
this.extension = "." + this.extension;
|
|
191
|
-
}
|
|
192
|
-
this.extensionLength = this.extension.length;
|
|
193
|
-
this.objectToString = _nullishCoalesce(opt.objectToString, () => ( ((data) => {
|
|
194
|
-
return this.pretty ? JSON.stringify(data, null, 2) : JSON.stringify(data);
|
|
195
|
-
})));
|
|
196
|
-
this.objectFromString = _nullishCoalesce(opt.objectFromString, () => ( ((data) => {
|
|
197
|
-
try {
|
|
198
|
-
return JSON.parse(data);
|
|
199
|
-
} catch (err) {
|
|
200
|
-
log2.warn(`fileStorage parse error '${err}' in`, data);
|
|
201
|
-
}
|
|
202
|
-
})));
|
|
203
|
-
this.keyToFilename = _nullishCoalesce(opt.keyToFilename, () => ( chunkAITOWUS2_cjs.toValidFilename));
|
|
204
|
-
}
|
|
205
|
-
setItem(key, value) {
|
|
206
|
-
this.store[key] = chunkAITOWUS2_cjs.cloneObject(value);
|
|
207
|
-
try {
|
|
208
|
-
const data = this.objectToString(value);
|
|
209
|
-
const path$1 = this.getPath(key);
|
|
210
|
-
fs.mkdirSync(path.dirname(path$1), { recursive: true });
|
|
211
|
-
fs.writeFileSync(path$1, data, "utf8");
|
|
212
|
-
} catch (err) {
|
|
213
|
-
log2.error("setItem error", err);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
getPath(key) {
|
|
217
|
-
return path.resolve(this.dirname, this.keyToFilename(key) + this.extension);
|
|
218
|
-
}
|
|
219
|
-
getBuffer(key) {
|
|
220
|
-
const path = this.getPath(key);
|
|
221
|
-
return Buffer.from(fs.readFileSync(path));
|
|
222
|
-
}
|
|
223
|
-
getItem(key) {
|
|
224
|
-
let value = this.store[key];
|
|
225
|
-
if (value === null)
|
|
226
|
-
return;
|
|
227
|
-
if (value != null) {
|
|
228
|
-
return chunkAITOWUS2_cjs.cloneObject(value);
|
|
229
|
-
}
|
|
230
|
-
try {
|
|
231
|
-
const path = this.getPath(key);
|
|
232
|
-
const data = fs.readFileSync(path, "utf8");
|
|
233
|
-
if (data != null) {
|
|
234
|
-
const value2 = this.objectFromString(data);
|
|
235
|
-
this.store[key] = value2;
|
|
236
|
-
return value2;
|
|
237
|
-
}
|
|
238
|
-
} catch (err) {
|
|
239
|
-
log2.warn("getItem error", err);
|
|
240
|
-
this.store[key] = null;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
removeItem(key) {
|
|
244
|
-
delete this.store[key];
|
|
245
|
-
if (this.fileKeys != null) {
|
|
246
|
-
const index = this.fileKeys.indexOf(key);
|
|
247
|
-
if (index !== -1) {
|
|
248
|
-
this.fileKeys.splice(index, 1);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
try {
|
|
252
|
-
const path = this.getPath(key);
|
|
253
|
-
fs.unlinkSync(path);
|
|
254
|
-
} catch (err) {
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
clear() {
|
|
258
|
-
this.fileKeys = [];
|
|
259
|
-
this.store = {};
|
|
260
|
-
fs.rmSync(this.dirname, { recursive: true, force: true });
|
|
261
|
-
}
|
|
262
|
-
allKeys() {
|
|
263
|
-
if (this.fileKeys == null) {
|
|
264
|
-
try {
|
|
265
|
-
this.fileKeys = fs.readdirSync(this.dirname, { withFileTypes: true }).filter(
|
|
266
|
-
(item) => !item.isDirectory() && item.name.endsWith(this.extension)
|
|
267
|
-
).map((item) => item.name.slice(0, -this.extensionLength)) || [];
|
|
268
|
-
} catch (err) {
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
let keys = [...this.fileKeys || []];
|
|
272
|
-
for (let key of Object.keys(this.store)) {
|
|
273
|
-
if (!keys.includes(key)) {
|
|
274
|
-
keys.push(key);
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
keys.sort();
|
|
278
|
-
return keys;
|
|
279
|
-
}
|
|
280
|
-
};
|
|
281
|
-
chunkC66X5FP6_cjs.__name(FileStorage, "FileStorage");
|
|
282
|
-
function toHumanReadableFilePath(path$1) {
|
|
283
|
-
const p = path.normalize(path$1);
|
|
284
|
-
const h = process.env.HOME;
|
|
285
|
-
if (h && p.startsWith(h)) {
|
|
286
|
-
return "~" + p.slice(h.length);
|
|
287
|
-
}
|
|
288
|
-
return p;
|
|
289
|
-
}
|
|
290
|
-
chunkC66X5FP6_cjs.__name(toHumanReadableFilePath, "toHumanReadableFilePath");
|
|
291
|
-
async function exists(path) {
|
|
292
|
-
try {
|
|
293
|
-
await promises.stat(path);
|
|
294
|
-
} catch (err) {
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
297
|
-
return true;
|
|
298
|
-
}
|
|
299
|
-
chunkC66X5FP6_cjs.__name(exists, "exists");
|
|
300
|
-
async function ensureFolder(...parts) {
|
|
301
|
-
const path$1 = path.join(...parts);
|
|
302
|
-
if (!await exists(path$1)) {
|
|
303
|
-
await promises.mkdir(path$1, { recursive: true });
|
|
304
|
-
}
|
|
305
|
-
return path$1;
|
|
306
|
-
}
|
|
307
|
-
chunkC66X5FP6_cjs.__name(ensureFolder, "ensureFolder");
|
|
308
|
-
async function removeFolder(...parts) {
|
|
309
|
-
const path$1 = path.join(...parts);
|
|
310
|
-
if (await exists(path$1)) {
|
|
311
|
-
await promises.rm(path$1, { recursive: true });
|
|
312
|
-
}
|
|
313
|
-
return path$1;
|
|
314
|
-
}
|
|
315
|
-
chunkC66X5FP6_cjs.__name(removeFolder, "removeFolder");
|
|
316
|
-
async function readText(...parts) {
|
|
317
|
-
const path$1 = path.join(...parts);
|
|
318
|
-
if (await exists(path$1)) {
|
|
319
|
-
return await promises.readFile(path$1, "utf-8");
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
chunkC66X5FP6_cjs.__name(readText, "readText");
|
|
323
|
-
async function writeText(path, content) {
|
|
324
|
-
await promises.writeFile(path, content, "utf-8");
|
|
325
|
-
}
|
|
326
|
-
chunkC66X5FP6_cjs.__name(writeText, "writeText");
|
|
327
|
-
var namespaces = {};
|
|
328
|
-
function LoggerFileHandler(path$1, opt = {}) {
|
|
329
|
-
const { level = -1 /* all */, filter = "*" } = opt;
|
|
330
|
-
path$1 = path.resolve(process.cwd(), path$1);
|
|
331
|
-
fs.mkdirSync(path.dirname(path$1), { recursive: true });
|
|
332
|
-
var stream = fs.createWriteStream(path$1, { flags: "a" });
|
|
333
|
-
const matchesNamespace = chunkC66X5FP6_cjs.useNamespaceFilter(filter);
|
|
334
|
-
const matchesLevel = chunkC66X5FP6_cjs.useLevelFilter(level);
|
|
335
|
-
return (msg) => {
|
|
336
|
-
if (!matchesLevel(msg.level))
|
|
337
|
-
return;
|
|
338
|
-
if (!matchesNamespace(msg.name))
|
|
339
|
-
return;
|
|
340
|
-
const time2 = new Date().toISOString();
|
|
341
|
-
let name = msg.name || "";
|
|
342
|
-
let ninfo = namespaces[name || ""];
|
|
343
|
-
if (ninfo == null) {
|
|
344
|
-
namespaces[name] = ninfo;
|
|
345
|
-
}
|
|
346
|
-
let args = [
|
|
347
|
-
`[${name || "*"}]`,
|
|
348
|
-
chunkAITOWUS2_cjs.renderMessages(msg.messages, { pretty: false })
|
|
349
|
-
];
|
|
350
|
-
function write(...args2) {
|
|
351
|
-
stream.write(args2.join(" ") + "\n");
|
|
352
|
-
}
|
|
353
|
-
chunkC66X5FP6_cjs.__name(write, "write");
|
|
354
|
-
switch (msg.level) {
|
|
355
|
-
case 1 /* info */:
|
|
356
|
-
write(time2, `I|* `, ...args);
|
|
357
|
-
break;
|
|
358
|
-
case 2 /* warn */:
|
|
359
|
-
write(time2, `W|** `, ...args);
|
|
360
|
-
break;
|
|
361
|
-
case 3 /* error */:
|
|
362
|
-
write(time2, `E|***`, ...args);
|
|
363
|
-
break;
|
|
364
|
-
default:
|
|
365
|
-
write(time2, `D| `, ...args);
|
|
366
|
-
break;
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
chunkC66X5FP6_cjs.__name(LoggerFileHandler, "LoggerFileHandler");
|
|
371
|
-
function getStackLlocationList(stack) {
|
|
372
|
-
var _a2, _b2;
|
|
373
|
-
if (typeof stack !== "string")
|
|
374
|
-
return [];
|
|
375
|
-
return ((_b2 = (_a2 = stack == null ? void 0 : stack.split("\n")) == null ? void 0 : _a2.map((rawLine) => {
|
|
376
|
-
let m = rawLine.match(
|
|
377
|
-
/^\s+at.*(\((.*)\)|file:\/\/(.*)$)|\s*at\s(\/.*)$/
|
|
378
|
-
);
|
|
379
|
-
if (m) {
|
|
380
|
-
let line = m[3] || m[2] || m[4];
|
|
381
|
-
if (line.endsWith(")"))
|
|
382
|
-
line = line.slice(0, -1);
|
|
383
|
-
return line;
|
|
384
|
-
}
|
|
385
|
-
})) == null ? void 0 : _b2.filter((v) => v != null)) || [];
|
|
386
|
-
}
|
|
387
|
-
chunkC66X5FP6_cjs.__name(getStackLlocationList, "getStackLlocationList");
|
|
388
|
-
var cwd = path.resolve(process.cwd());
|
|
389
|
-
var _a, _b;
|
|
390
|
-
var home = ((_a = process.env) == null ? void 0 : _a.HOME) ? path.resolve((_b = process.env) == null ? void 0 : _b.HOME) : "";
|
|
391
|
-
function pathStripCwd(path) {
|
|
392
|
-
if (path.includes("/node_modules/")) {
|
|
393
|
-
return "";
|
|
394
|
-
}
|
|
395
|
-
const fileURL = "file://";
|
|
396
|
-
if (path.startsWith(fileURL)) {
|
|
397
|
-
return path.substr(fileURL.length);
|
|
398
|
-
}
|
|
399
|
-
if (cwd && path.startsWith(cwd)) {
|
|
400
|
-
return path.substr(cwd.length + 1);
|
|
401
|
-
}
|
|
402
|
-
if (home && path.startsWith(home)) {
|
|
403
|
-
path = "~/" + path.substr(home.length + 1);
|
|
404
|
-
}
|
|
405
|
-
return path;
|
|
406
|
-
}
|
|
407
|
-
chunkC66X5FP6_cjs.__name(pathStripCwd, "pathStripCwd");
|
|
408
|
-
function extractFileInfo(stackLine) {
|
|
409
|
-
let m = stackLine.match(/^\s*at.*(\((.*)\)|file:\/\/(.*)$)|\s*at\s(\/.*)$/);
|
|
410
|
-
if (m) {
|
|
411
|
-
let line = m[3] || m[2] || m[4];
|
|
412
|
-
if (line.endsWith(")"))
|
|
413
|
-
line = line.slice(0, -1);
|
|
414
|
-
return line;
|
|
415
|
-
}
|
|
416
|
-
return "";
|
|
417
|
-
}
|
|
418
|
-
chunkC66X5FP6_cjs.__name(extractFileInfo, "extractFileInfo");
|
|
419
|
-
function getSourceLocation(level = 2, stripCwd = true) {
|
|
420
|
-
var _a2;
|
|
421
|
-
let stack = new Error().stack || "";
|
|
422
|
-
let line = (_a2 = getStackLlocationList(stack)) == null ? void 0 : _a2[level];
|
|
423
|
-
if (line && stripCwd) {
|
|
424
|
-
line = pathStripCwd(line);
|
|
425
|
-
}
|
|
426
|
-
return line || "";
|
|
427
|
-
}
|
|
428
|
-
chunkC66X5FP6_cjs.__name(getSourceLocation, "getSourceLocation");
|
|
429
|
-
function getStack() {
|
|
430
|
-
return new Error().stack || "";
|
|
431
|
-
}
|
|
432
|
-
chunkC66X5FP6_cjs.__name(getStack, "getStack");
|
|
433
|
-
function getSourceLocationByPrecedingPattern(patterns, stripCwd = true) {
|
|
434
|
-
let line = "";
|
|
435
|
-
let stack = new Error().stack || "";
|
|
436
|
-
if (typeof stack === "string") {
|
|
437
|
-
const lines = stack.split("\n").map((l) => l.trim());
|
|
438
|
-
const index = lines.findIndex((l) => patterns.some((p) => l.startsWith(p)));
|
|
439
|
-
line = lines[index + 1];
|
|
440
|
-
if (line) {
|
|
441
|
-
line = extractFileInfo(line);
|
|
442
|
-
}
|
|
443
|
-
if (line && stripCwd) {
|
|
444
|
-
line = pathStripCwd(line);
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
return line;
|
|
448
|
-
}
|
|
449
|
-
chunkC66X5FP6_cjs.__name(getSourceLocationByPrecedingPattern, "getSourceLocationByPrecedingPattern");
|
|
450
|
-
function shouldUseColor() {
|
|
451
|
-
try {
|
|
452
|
-
return chunkAITOWUS2_cjs.valueToBoolean(process.env.ZEED_COLOR, tty__default["default"].isatty(process.stdout.fd));
|
|
453
|
-
} catch (err) {
|
|
454
|
-
}
|
|
455
|
-
return false;
|
|
456
|
-
}
|
|
457
|
-
chunkC66X5FP6_cjs.__name(shouldUseColor, "shouldUseColor");
|
|
458
|
-
var defaultUseColor = shouldUseColor();
|
|
459
|
-
var colors = [6, 2, 3, 4, 5, 1];
|
|
460
|
-
function selectColor(namespace) {
|
|
461
|
-
let hash = 0;
|
|
462
|
-
for (let i = 0; i < namespace.length; i++) {
|
|
463
|
-
hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
|
464
|
-
hash |= 0;
|
|
465
|
-
}
|
|
466
|
-
return colors[Math.abs(hash) % colors.length];
|
|
467
|
-
}
|
|
468
|
-
chunkC66X5FP6_cjs.__name(selectColor, "selectColor");
|
|
469
|
-
var namespaces2 = {};
|
|
470
|
-
var time = chunkC66X5FP6_cjs.getTimestamp();
|
|
471
|
-
function log3(...args) {
|
|
472
|
-
process.stdout.write(chunkAITOWUS2_cjs.renderMessages(args) + "\n");
|
|
473
|
-
}
|
|
474
|
-
chunkC66X5FP6_cjs.__name(log3, "log");
|
|
475
|
-
var TTY_STYLE = {
|
|
476
|
-
BOLD: "\x1B[1m",
|
|
477
|
-
UNBOLD: "\x1B[2m",
|
|
478
|
-
RED: "\x1B[31m",
|
|
479
|
-
GREEN: "\x1B[32m",
|
|
480
|
-
BLUE: "\x1B[34m",
|
|
481
|
-
PURPLE: "\x1B[35m",
|
|
482
|
-
GRAY: "\x1B[37m",
|
|
483
|
-
ORANGE: "\x1B[38;5;208m",
|
|
484
|
-
UNCOLOR: "\x1B[0m"
|
|
485
|
-
};
|
|
486
|
-
var colorEnd = "\x1B[0m";
|
|
487
|
-
function colorString(value, colorCode) {
|
|
488
|
-
const colorStart = colorCode === 8 /* ORANGE */ ? TTY_STYLE.ORANGE : "\x1B[3" + (colorCode < 8 ? colorCode : "8;5;" + colorCode) + "m";
|
|
489
|
-
return `${colorStart}${value}${colorEnd}`;
|
|
490
|
-
}
|
|
491
|
-
chunkC66X5FP6_cjs.__name(colorString, "colorString");
|
|
492
|
-
function colorStringList(list, style, bold = true) {
|
|
493
|
-
return list.map((value) => {
|
|
494
|
-
if (typeof value !== "string")
|
|
495
|
-
return value;
|
|
496
|
-
let start = style;
|
|
497
|
-
let end = colorEnd;
|
|
498
|
-
if (bold) {
|
|
499
|
-
start = `${TTY_STYLE.BOLD}${start}`;
|
|
500
|
-
end = `${end}${TTY_STYLE.BOLD}`;
|
|
501
|
-
}
|
|
502
|
-
return `${start}${value}${end}`;
|
|
503
|
-
});
|
|
504
|
-
}
|
|
505
|
-
chunkC66X5FP6_cjs.__name(colorStringList, "colorStringList");
|
|
506
|
-
var loggerStackTraceDebug = "loggerStackTraceDebug-7d38e5a9214b58d29734374cdb9521fd964d7485";
|
|
507
|
-
function LoggerNodeHandler(opt = {}) {
|
|
508
|
-
const {
|
|
509
|
-
level = void 0,
|
|
510
|
-
filter = void 0,
|
|
511
|
-
colors: colors2 = defaultUseColor,
|
|
512
|
-
levelHelper = true,
|
|
513
|
-
nameBrackets = true,
|
|
514
|
-
padding = 0,
|
|
515
|
-
fill = 0,
|
|
516
|
-
stack = true
|
|
517
|
-
} = opt;
|
|
518
|
-
const matchesNamespace = chunkC66X5FP6_cjs.useNamespaceFilter(filter);
|
|
519
|
-
const matchesLevel = chunkC66X5FP6_cjs.useLevelFilter(level);
|
|
520
|
-
return (msg) => {
|
|
521
|
-
var _a2;
|
|
522
|
-
if (!matchesLevel(msg.level))
|
|
523
|
-
return;
|
|
524
|
-
if (!matchesNamespace(msg.name))
|
|
525
|
-
return;
|
|
526
|
-
const timeNow = chunkC66X5FP6_cjs.getTimestamp();
|
|
527
|
-
let name = msg.name || "";
|
|
528
|
-
let ninfo = namespaces2[name || ""];
|
|
529
|
-
if (ninfo == null) {
|
|
530
|
-
ninfo = {
|
|
531
|
-
color: selectColor(name)
|
|
532
|
-
};
|
|
533
|
-
namespaces2[name] = ninfo;
|
|
534
|
-
}
|
|
535
|
-
const diff = chunkC66X5FP6_cjs.formatMilliseconds(timeNow - time);
|
|
536
|
-
let args;
|
|
537
|
-
let displayName = nameBrackets ? `[${name}]` : name;
|
|
538
|
-
if (padding > 0) {
|
|
539
|
-
displayName = displayName.padStart(padding, " ");
|
|
540
|
-
}
|
|
541
|
-
if (fill > 0) {
|
|
542
|
-
displayName = displayName.padEnd(fill, " ");
|
|
543
|
-
}
|
|
544
|
-
if (colors2) {
|
|
545
|
-
const c = ninfo.color;
|
|
546
|
-
args = [colorString(displayName, c) + ` | `];
|
|
547
|
-
if (msg.level === 2 /* warn */) {
|
|
548
|
-
args.push(...colorStringList(msg.messages, TTY_STYLE.ORANGE));
|
|
549
|
-
} else if (msg.level === 3 /* error */) {
|
|
550
|
-
args.push(...colorStringList(msg.messages, TTY_STYLE.RED));
|
|
551
|
-
} else {
|
|
552
|
-
args.push(...msg.messages);
|
|
553
|
-
}
|
|
554
|
-
args.push(colorString(`+${diff}`, c));
|
|
555
|
-
} else {
|
|
556
|
-
args = [displayName, ...msg.messages];
|
|
557
|
-
args.push(`+${diff}`);
|
|
558
|
-
}
|
|
559
|
-
if (((_a2 = msg.messages) == null ? void 0 : _a2[0]) === loggerStackTraceDebug) {
|
|
560
|
-
console.log(getStack());
|
|
561
|
-
}
|
|
562
|
-
if (stack) {
|
|
563
|
-
let line = "";
|
|
564
|
-
if (typeof stack === "boolean") {
|
|
565
|
-
line = getSourceLocationByPrecedingPattern(
|
|
566
|
-
["at Function.", "at null.log (", "at log ("],
|
|
567
|
-
true
|
|
568
|
-
);
|
|
569
|
-
if (!line) {
|
|
570
|
-
line = getSourceLocation(0, true);
|
|
571
|
-
}
|
|
572
|
-
} else {
|
|
573
|
-
const depth = typeof stack === "number" ? stack : 3;
|
|
574
|
-
line = getSourceLocation(depth, true);
|
|
575
|
-
}
|
|
576
|
-
if (line) {
|
|
577
|
-
args.push(colorString(`(${line})`, 7 /* GRAY */));
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
const sep = "|";
|
|
581
|
-
const charLevel = ".";
|
|
582
|
-
switch (msg.level) {
|
|
583
|
-
case 1 /* info */:
|
|
584
|
-
if (levelHelper)
|
|
585
|
-
args[0] = `I${sep}${charLevel} ` + args[0];
|
|
586
|
-
log3(...args);
|
|
587
|
-
break;
|
|
588
|
-
case 2 /* warn */:
|
|
589
|
-
if (levelHelper)
|
|
590
|
-
args[0] = (colors2 ? colorString(`W${sep}${charLevel}${charLevel} `, 8 /* ORANGE */) : `W${sep}${charLevel}${charLevel} `) + args[0];
|
|
591
|
-
log3(...args);
|
|
592
|
-
break;
|
|
593
|
-
case 3 /* error */:
|
|
594
|
-
if (levelHelper)
|
|
595
|
-
args[0] = (colors2 ? colorString(
|
|
596
|
-
`E${sep}${charLevel}${charLevel}${charLevel} `,
|
|
597
|
-
1 /* RED */
|
|
598
|
-
) : `E${sep}${charLevel}${charLevel}${charLevel} `) + args[0];
|
|
599
|
-
log3(...args);
|
|
600
|
-
break;
|
|
601
|
-
default:
|
|
602
|
-
if (levelHelper)
|
|
603
|
-
args[0] = `D${sep} ` + args[0];
|
|
604
|
-
log3(...args);
|
|
605
|
-
break;
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
}
|
|
609
|
-
chunkC66X5FP6_cjs.__name(LoggerNodeHandler, "LoggerNodeHandler");
|
|
610
|
-
try {
|
|
611
|
-
if (nodeCrypto__default["default"] && nodeCrypto__default["default"].webcrypto && typeof globalThis !== "undefined" && typeof globalThis.crypto === "undefined") {
|
|
612
|
-
globalThis.crypto = nodeCrypto__default["default"].webcrypto;
|
|
613
|
-
}
|
|
614
|
-
} catch (err) {
|
|
615
|
-
console.warn("Failed to polyfill webcrypto", err);
|
|
616
|
-
}
|
|
617
|
-
|
|
618
|
-
// src/node/log-context-node.ts
|
|
619
|
-
function setupLogContextNode() {
|
|
620
|
-
let handlers = [
|
|
621
|
-
LoggerNodeHandler({
|
|
622
|
-
padding: 32,
|
|
623
|
-
nameBrackets: false
|
|
624
|
-
})
|
|
625
|
-
];
|
|
626
|
-
let logFilePath = _nullishCoalesce(process.env.ZEED_LOG, () => ( process.env.LOG));
|
|
627
|
-
if (logFilePath) {
|
|
628
|
-
handlers.unshift(LoggerFileHandler(toPath(logFilePath)));
|
|
629
|
-
}
|
|
630
|
-
chunkC66X5FP6_cjs.Logger.setHandlers(handlers);
|
|
631
|
-
}
|
|
632
|
-
chunkC66X5FP6_cjs.__name(setupLogContextNode, "setupLogContextNode");
|
|
633
|
-
setupLogContextNode();
|
|
634
|
-
|
|
635
|
-
exports.FileStorage = FileStorage;
|
|
636
|
-
exports.LoggerFileHandler = LoggerFileHandler;
|
|
637
|
-
exports.LoggerNodeHandler = LoggerNodeHandler;
|
|
638
|
-
exports.colorString = colorString;
|
|
639
|
-
exports.colorStringList = colorStringList;
|
|
640
|
-
exports.ensureFolder = ensureFolder;
|
|
641
|
-
exports.exists = exists;
|
|
642
|
-
exports.getSourceLocation = getSourceLocation;
|
|
643
|
-
exports.getSourceLocationByPrecedingPattern = getSourceLocationByPrecedingPattern;
|
|
644
|
-
exports.getStack = getStack;
|
|
645
|
-
exports.getStackLlocationList = getStackLlocationList;
|
|
646
|
-
exports.loggerStackTraceDebug = loggerStackTraceDebug;
|
|
647
|
-
exports.parseArgs = parseArgs;
|
|
648
|
-
exports.pbcopy = pbcopy;
|
|
649
|
-
exports.readText = readText;
|
|
650
|
-
exports.removeFolder = removeFolder;
|
|
651
|
-
exports.setupEnv = setupEnv;
|
|
652
|
-
exports.stringToPath = stringToPath;
|
|
653
|
-
exports.toHumanReadableFilePath = toHumanReadableFilePath;
|
|
654
|
-
exports.toPath = toPath;
|
|
655
|
-
exports.valueToPath = valueToPath;
|
|
656
|
-
exports.writeText = writeText;
|
|
657
|
-
//# sourceMappingURL=chunk-CCZIVE22.cjs.map
|