@sentenel/node-utils 0.1.1 → 0.1.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/README.md +1 -0
- package/dist/cjs/asset-manifest-cjs.json +15 -0
- package/dist/cjs/dotenv/dotenv.async.d.ts +3 -0
- package/dist/cjs/dotenv/dotenv.async.d.ts.map +1 -0
- package/dist/cjs/dotenv/dotenv.sync.d.ts +3 -0
- package/dist/cjs/dotenv/dotenv.sync.d.ts.map +1 -0
- package/dist/cjs/dotenv/index.d.ts +3 -0
- package/dist/cjs/dotenv/index.d.ts.map +1 -0
- package/dist/cjs/index.cjs +30 -706
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.d.ts.map +1 -0
- package/dist/cjs/paths/index.d.ts +2 -0
- package/dist/cjs/paths/index.d.ts.map +1 -0
- package/dist/cjs/paths/paths.d.ts +4 -0
- package/dist/cjs/paths/paths.d.ts.map +1 -0
- package/dist/cjs/paths/root.path.global.d.ts +12 -0
- package/dist/cjs/paths/root.path.global.d.ts.map +1 -0
- package/dist/esm/asset-manifest-mjs.json +15 -0
- package/dist/esm/dotenv/dotenv.async.d.ts +3 -0
- package/dist/esm/dotenv/dotenv.async.d.ts.map +1 -0
- package/dist/esm/dotenv/dotenv.sync.d.ts +3 -0
- package/dist/esm/dotenv/dotenv.sync.d.ts.map +1 -0
- package/dist/esm/dotenv/index.d.ts +3 -0
- package/dist/esm/dotenv/index.d.ts.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +2 -688
- package/dist/esm/paths/index.d.ts +2 -0
- package/dist/esm/paths/index.d.ts.map +1 -0
- package/dist/esm/paths/paths.d.ts +4 -0
- package/dist/esm/paths/paths.d.ts.map +1 -0
- package/dist/esm/paths/root.path.global.d.ts +12 -0
- package/dist/esm/paths/root.path.global.d.ts.map +1 -0
- package/package.json +2 -1
package/dist/esm/index.js
CHANGED
|
@@ -1,688 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { expand } from "dotenv-expand";
|
|
4
|
-
import { resolve } from "node:path";
|
|
5
|
-
import node_module from "node:module";
|
|
6
|
-
import node_process from "node:process";
|
|
7
|
-
import node_os from "node:os";
|
|
8
|
-
import node_tty from "node:tty";
|
|
9
|
-
const { NODE_ENV: NODE_ENV } = process.env;
|
|
10
|
-
async function asyncExpandDotEnv(path) {
|
|
11
|
-
const dotenvFiles = [
|
|
12
|
-
`${path}.${NODE_ENV}.local`,
|
|
13
|
-
`${path}.${NODE_ENV}`,
|
|
14
|
-
"test" !== NODE_ENV ? `${path}.local` : null,
|
|
15
|
-
path
|
|
16
|
-
].filter(Boolean);
|
|
17
|
-
await Promise.all(dotenvFiles.map(async (dotenvFile)=>{
|
|
18
|
-
if (existsSync(dotenvFile)) import("dotenv-expand").then(async ()=>{
|
|
19
|
-
import("dotenv").then((config)=>{
|
|
20
|
-
config.config({
|
|
21
|
-
path: dotenvFile
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
}));
|
|
26
|
-
}
|
|
27
|
-
const { NODE_ENV: dotenv_sync_NODE_ENV } = process.env;
|
|
28
|
-
async function syncExpandDotEnv(path) {
|
|
29
|
-
const dotenvFiles = [
|
|
30
|
-
`${path}.${dotenv_sync_NODE_ENV}.local`,
|
|
31
|
-
`${path}.${dotenv_sync_NODE_ENV}`,
|
|
32
|
-
"test" !== dotenv_sync_NODE_ENV ? `${path}.local` : null,
|
|
33
|
-
path
|
|
34
|
-
].filter(Boolean);
|
|
35
|
-
dotenvFiles.map(async (dotenvFile)=>{
|
|
36
|
-
if (existsSync(dotenvFile)) expand(external_dotenv_config({
|
|
37
|
-
path: dotenvFile
|
|
38
|
-
}));
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
const ANSI_BACKGROUND_OFFSET = 10;
|
|
42
|
-
const wrapAnsi16 = (offset = 0)=>(code)=>`\u001B[${code + offset}m`;
|
|
43
|
-
const wrapAnsi256 = (offset = 0)=>(code)=>`\u001B[${38 + offset};5;${code}m`;
|
|
44
|
-
const wrapAnsi16m = (offset = 0)=>(red, green, blue)=>`\u001B[${38 + offset};2;${red};${green};${blue}m`;
|
|
45
|
-
const styles = {
|
|
46
|
-
modifier: {
|
|
47
|
-
reset: [
|
|
48
|
-
0,
|
|
49
|
-
0
|
|
50
|
-
],
|
|
51
|
-
bold: [
|
|
52
|
-
1,
|
|
53
|
-
22
|
|
54
|
-
],
|
|
55
|
-
dim: [
|
|
56
|
-
2,
|
|
57
|
-
22
|
|
58
|
-
],
|
|
59
|
-
italic: [
|
|
60
|
-
3,
|
|
61
|
-
23
|
|
62
|
-
],
|
|
63
|
-
underline: [
|
|
64
|
-
4,
|
|
65
|
-
24
|
|
66
|
-
],
|
|
67
|
-
overline: [
|
|
68
|
-
53,
|
|
69
|
-
55
|
|
70
|
-
],
|
|
71
|
-
inverse: [
|
|
72
|
-
7,
|
|
73
|
-
27
|
|
74
|
-
],
|
|
75
|
-
hidden: [
|
|
76
|
-
8,
|
|
77
|
-
28
|
|
78
|
-
],
|
|
79
|
-
strikethrough: [
|
|
80
|
-
9,
|
|
81
|
-
29
|
|
82
|
-
]
|
|
83
|
-
},
|
|
84
|
-
color: {
|
|
85
|
-
black: [
|
|
86
|
-
30,
|
|
87
|
-
39
|
|
88
|
-
],
|
|
89
|
-
red: [
|
|
90
|
-
31,
|
|
91
|
-
39
|
|
92
|
-
],
|
|
93
|
-
green: [
|
|
94
|
-
32,
|
|
95
|
-
39
|
|
96
|
-
],
|
|
97
|
-
yellow: [
|
|
98
|
-
33,
|
|
99
|
-
39
|
|
100
|
-
],
|
|
101
|
-
blue: [
|
|
102
|
-
34,
|
|
103
|
-
39
|
|
104
|
-
],
|
|
105
|
-
magenta: [
|
|
106
|
-
35,
|
|
107
|
-
39
|
|
108
|
-
],
|
|
109
|
-
cyan: [
|
|
110
|
-
36,
|
|
111
|
-
39
|
|
112
|
-
],
|
|
113
|
-
white: [
|
|
114
|
-
37,
|
|
115
|
-
39
|
|
116
|
-
],
|
|
117
|
-
blackBright: [
|
|
118
|
-
90,
|
|
119
|
-
39
|
|
120
|
-
],
|
|
121
|
-
gray: [
|
|
122
|
-
90,
|
|
123
|
-
39
|
|
124
|
-
],
|
|
125
|
-
grey: [
|
|
126
|
-
90,
|
|
127
|
-
39
|
|
128
|
-
],
|
|
129
|
-
redBright: [
|
|
130
|
-
91,
|
|
131
|
-
39
|
|
132
|
-
],
|
|
133
|
-
greenBright: [
|
|
134
|
-
92,
|
|
135
|
-
39
|
|
136
|
-
],
|
|
137
|
-
yellowBright: [
|
|
138
|
-
93,
|
|
139
|
-
39
|
|
140
|
-
],
|
|
141
|
-
blueBright: [
|
|
142
|
-
94,
|
|
143
|
-
39
|
|
144
|
-
],
|
|
145
|
-
magentaBright: [
|
|
146
|
-
95,
|
|
147
|
-
39
|
|
148
|
-
],
|
|
149
|
-
cyanBright: [
|
|
150
|
-
96,
|
|
151
|
-
39
|
|
152
|
-
],
|
|
153
|
-
whiteBright: [
|
|
154
|
-
97,
|
|
155
|
-
39
|
|
156
|
-
]
|
|
157
|
-
},
|
|
158
|
-
bgColor: {
|
|
159
|
-
bgBlack: [
|
|
160
|
-
40,
|
|
161
|
-
49
|
|
162
|
-
],
|
|
163
|
-
bgRed: [
|
|
164
|
-
41,
|
|
165
|
-
49
|
|
166
|
-
],
|
|
167
|
-
bgGreen: [
|
|
168
|
-
42,
|
|
169
|
-
49
|
|
170
|
-
],
|
|
171
|
-
bgYellow: [
|
|
172
|
-
43,
|
|
173
|
-
49
|
|
174
|
-
],
|
|
175
|
-
bgBlue: [
|
|
176
|
-
44,
|
|
177
|
-
49
|
|
178
|
-
],
|
|
179
|
-
bgMagenta: [
|
|
180
|
-
45,
|
|
181
|
-
49
|
|
182
|
-
],
|
|
183
|
-
bgCyan: [
|
|
184
|
-
46,
|
|
185
|
-
49
|
|
186
|
-
],
|
|
187
|
-
bgWhite: [
|
|
188
|
-
47,
|
|
189
|
-
49
|
|
190
|
-
],
|
|
191
|
-
bgBlackBright: [
|
|
192
|
-
100,
|
|
193
|
-
49
|
|
194
|
-
],
|
|
195
|
-
bgGray: [
|
|
196
|
-
100,
|
|
197
|
-
49
|
|
198
|
-
],
|
|
199
|
-
bgGrey: [
|
|
200
|
-
100,
|
|
201
|
-
49
|
|
202
|
-
],
|
|
203
|
-
bgRedBright: [
|
|
204
|
-
101,
|
|
205
|
-
49
|
|
206
|
-
],
|
|
207
|
-
bgGreenBright: [
|
|
208
|
-
102,
|
|
209
|
-
49
|
|
210
|
-
],
|
|
211
|
-
bgYellowBright: [
|
|
212
|
-
103,
|
|
213
|
-
49
|
|
214
|
-
],
|
|
215
|
-
bgBlueBright: [
|
|
216
|
-
104,
|
|
217
|
-
49
|
|
218
|
-
],
|
|
219
|
-
bgMagentaBright: [
|
|
220
|
-
105,
|
|
221
|
-
49
|
|
222
|
-
],
|
|
223
|
-
bgCyanBright: [
|
|
224
|
-
106,
|
|
225
|
-
49
|
|
226
|
-
],
|
|
227
|
-
bgWhiteBright: [
|
|
228
|
-
107,
|
|
229
|
-
49
|
|
230
|
-
]
|
|
231
|
-
}
|
|
232
|
-
};
|
|
233
|
-
Object.keys(styles.modifier);
|
|
234
|
-
const foregroundColorNames = Object.keys(styles.color);
|
|
235
|
-
const backgroundColorNames = Object.keys(styles.bgColor);
|
|
236
|
-
[
|
|
237
|
-
...foregroundColorNames,
|
|
238
|
-
...backgroundColorNames
|
|
239
|
-
];
|
|
240
|
-
function assembleStyles() {
|
|
241
|
-
const codes = new Map();
|
|
242
|
-
for (const [groupName, group] of Object.entries(styles)){
|
|
243
|
-
for (const [styleName, style] of Object.entries(group)){
|
|
244
|
-
styles[styleName] = {
|
|
245
|
-
open: `\u001B[${style[0]}m`,
|
|
246
|
-
close: `\u001B[${style[1]}m`
|
|
247
|
-
};
|
|
248
|
-
group[styleName] = styles[styleName];
|
|
249
|
-
codes.set(style[0], style[1]);
|
|
250
|
-
}
|
|
251
|
-
Object.defineProperty(styles, groupName, {
|
|
252
|
-
value: group,
|
|
253
|
-
enumerable: false
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
Object.defineProperty(styles, 'codes', {
|
|
257
|
-
value: codes,
|
|
258
|
-
enumerable: false
|
|
259
|
-
});
|
|
260
|
-
styles.color.close = '\u001B[39m';
|
|
261
|
-
styles.bgColor.close = '\u001B[49m';
|
|
262
|
-
styles.color.ansi = wrapAnsi16();
|
|
263
|
-
styles.color.ansi256 = wrapAnsi256();
|
|
264
|
-
styles.color.ansi16m = wrapAnsi16m();
|
|
265
|
-
styles.bgColor.ansi = wrapAnsi16(ANSI_BACKGROUND_OFFSET);
|
|
266
|
-
styles.bgColor.ansi256 = wrapAnsi256(ANSI_BACKGROUND_OFFSET);
|
|
267
|
-
styles.bgColor.ansi16m = wrapAnsi16m(ANSI_BACKGROUND_OFFSET);
|
|
268
|
-
Object.defineProperties(styles, {
|
|
269
|
-
rgbToAnsi256: {
|
|
270
|
-
value (red, green, blue) {
|
|
271
|
-
if (red === green && green === blue) {
|
|
272
|
-
if (red < 8) return 16;
|
|
273
|
-
if (red > 248) return 231;
|
|
274
|
-
return Math.round((red - 8) / 247 * 24) + 232;
|
|
275
|
-
}
|
|
276
|
-
return 16 + 36 * Math.round(red / 255 * 5) + 6 * Math.round(green / 255 * 5) + Math.round(blue / 255 * 5);
|
|
277
|
-
},
|
|
278
|
-
enumerable: false
|
|
279
|
-
},
|
|
280
|
-
hexToRgb: {
|
|
281
|
-
value (hex) {
|
|
282
|
-
const matches = /[a-f\d]{6}|[a-f\d]{3}/i.exec(hex.toString(16));
|
|
283
|
-
if (!matches) return [
|
|
284
|
-
0,
|
|
285
|
-
0,
|
|
286
|
-
0
|
|
287
|
-
];
|
|
288
|
-
let [colorString] = matches;
|
|
289
|
-
if (3 === colorString.length) colorString = [
|
|
290
|
-
...colorString
|
|
291
|
-
].map((character)=>character + character).join('');
|
|
292
|
-
const integer = Number.parseInt(colorString, 16);
|
|
293
|
-
return [
|
|
294
|
-
integer >> 16 & 0xFF,
|
|
295
|
-
integer >> 8 & 0xFF,
|
|
296
|
-
0xFF & integer
|
|
297
|
-
];
|
|
298
|
-
},
|
|
299
|
-
enumerable: false
|
|
300
|
-
},
|
|
301
|
-
hexToAnsi256: {
|
|
302
|
-
value: (hex)=>styles.rgbToAnsi256(...styles.hexToRgb(hex)),
|
|
303
|
-
enumerable: false
|
|
304
|
-
},
|
|
305
|
-
ansi256ToAnsi: {
|
|
306
|
-
value (code) {
|
|
307
|
-
if (code < 8) return 30 + code;
|
|
308
|
-
if (code < 16) return 90 + (code - 8);
|
|
309
|
-
let red;
|
|
310
|
-
let green;
|
|
311
|
-
let blue;
|
|
312
|
-
if (code >= 232) {
|
|
313
|
-
red = ((code - 232) * 10 + 8) / 255;
|
|
314
|
-
green = red;
|
|
315
|
-
blue = red;
|
|
316
|
-
} else {
|
|
317
|
-
code -= 16;
|
|
318
|
-
const remainder = code % 36;
|
|
319
|
-
red = Math.floor(code / 36) / 5;
|
|
320
|
-
green = Math.floor(remainder / 6) / 5;
|
|
321
|
-
blue = remainder % 6 / 5;
|
|
322
|
-
}
|
|
323
|
-
const value = 2 * Math.max(red, green, blue);
|
|
324
|
-
if (0 === value) return 30;
|
|
325
|
-
let result = 30 + (Math.round(blue) << 2 | Math.round(green) << 1 | Math.round(red));
|
|
326
|
-
if (2 === value) result += 60;
|
|
327
|
-
return result;
|
|
328
|
-
},
|
|
329
|
-
enumerable: false
|
|
330
|
-
},
|
|
331
|
-
rgbToAnsi: {
|
|
332
|
-
value: (red, green, blue)=>styles.ansi256ToAnsi(styles.rgbToAnsi256(red, green, blue)),
|
|
333
|
-
enumerable: false
|
|
334
|
-
},
|
|
335
|
-
hexToAnsi: {
|
|
336
|
-
value: (hex)=>styles.ansi256ToAnsi(styles.hexToAnsi256(hex)),
|
|
337
|
-
enumerable: false
|
|
338
|
-
}
|
|
339
|
-
});
|
|
340
|
-
return styles;
|
|
341
|
-
}
|
|
342
|
-
const ansiStyles = assembleStyles();
|
|
343
|
-
const ansi_styles = ansiStyles;
|
|
344
|
-
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : node_process.argv) {
|
|
345
|
-
const prefix = flag.startsWith('-') ? '' : 1 === flag.length ? '-' : '--';
|
|
346
|
-
const position = argv.indexOf(prefix + flag);
|
|
347
|
-
const terminatorPosition = argv.indexOf('--');
|
|
348
|
-
return -1 !== position && (-1 === terminatorPosition || position < terminatorPosition);
|
|
349
|
-
}
|
|
350
|
-
const { env: env } = node_process;
|
|
351
|
-
let flagForceColor;
|
|
352
|
-
if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) flagForceColor = 0;
|
|
353
|
-
else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) flagForceColor = 1;
|
|
354
|
-
function envForceColor() {
|
|
355
|
-
if ('FORCE_COLOR' in env) {
|
|
356
|
-
if ('true' === env.FORCE_COLOR) return 1;
|
|
357
|
-
if ('false' === env.FORCE_COLOR) return 0;
|
|
358
|
-
return 0 === env.FORCE_COLOR.length ? 1 : Math.min(Number.parseInt(env.FORCE_COLOR, 10), 3);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
function translateLevel(level) {
|
|
362
|
-
if (0 === level) return false;
|
|
363
|
-
return {
|
|
364
|
-
level,
|
|
365
|
-
hasBasic: true,
|
|
366
|
-
has256: level >= 2,
|
|
367
|
-
has16m: level >= 3
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
|
|
371
|
-
const noFlagForceColor = envForceColor();
|
|
372
|
-
if (void 0 !== noFlagForceColor) flagForceColor = noFlagForceColor;
|
|
373
|
-
const forceColor = sniffFlags ? flagForceColor : noFlagForceColor;
|
|
374
|
-
if (0 === forceColor) return 0;
|
|
375
|
-
if (sniffFlags) {
|
|
376
|
-
if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) return 3;
|
|
377
|
-
if (hasFlag('color=256')) return 2;
|
|
378
|
-
}
|
|
379
|
-
if ('TF_BUILD' in env && 'AGENT_NAME' in env) return 1;
|
|
380
|
-
if (haveStream && !streamIsTTY && void 0 === forceColor) return 0;
|
|
381
|
-
const min = forceColor || 0;
|
|
382
|
-
if ('dumb' === env.TERM) return min;
|
|
383
|
-
if ('win32' === node_process.platform) {
|
|
384
|
-
const osRelease = node_os.release().split('.');
|
|
385
|
-
if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) return Number(osRelease[2]) >= 14931 ? 3 : 2;
|
|
386
|
-
return 1;
|
|
387
|
-
}
|
|
388
|
-
if ('CI' in env) {
|
|
389
|
-
if ([
|
|
390
|
-
'GITHUB_ACTIONS',
|
|
391
|
-
'GITEA_ACTIONS',
|
|
392
|
-
'CIRCLECI'
|
|
393
|
-
].some((key)=>key in env)) return 3;
|
|
394
|
-
if ([
|
|
395
|
-
'TRAVIS',
|
|
396
|
-
'APPVEYOR',
|
|
397
|
-
'GITLAB_CI',
|
|
398
|
-
'BUILDKITE',
|
|
399
|
-
'DRONE'
|
|
400
|
-
].some((sign)=>sign in env) || 'codeship' === env.CI_NAME) return 1;
|
|
401
|
-
return min;
|
|
402
|
-
}
|
|
403
|
-
if ('TEAMCITY_VERSION' in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
|
|
404
|
-
if ('truecolor' === env.COLORTERM) return 3;
|
|
405
|
-
if ('xterm-kitty' === env.TERM) return 3;
|
|
406
|
-
if ('xterm-ghostty' === env.TERM) return 3;
|
|
407
|
-
if ('wezterm' === env.TERM) return 3;
|
|
408
|
-
if ('TERM_PROGRAM' in env) {
|
|
409
|
-
const version = Number.parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
|
|
410
|
-
switch(env.TERM_PROGRAM){
|
|
411
|
-
case 'iTerm.app':
|
|
412
|
-
return version >= 3 ? 3 : 2;
|
|
413
|
-
case 'Apple_Terminal':
|
|
414
|
-
return 2;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
if (/-256(color)?$/i.test(env.TERM)) return 2;
|
|
418
|
-
if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) return 1;
|
|
419
|
-
if ('COLORTERM' in env) return 1;
|
|
420
|
-
return min;
|
|
421
|
-
}
|
|
422
|
-
function createSupportsColor(stream, options = {}) {
|
|
423
|
-
const level = _supportsColor(stream, {
|
|
424
|
-
streamIsTTY: stream && stream.isTTY,
|
|
425
|
-
...options
|
|
426
|
-
});
|
|
427
|
-
return translateLevel(level);
|
|
428
|
-
}
|
|
429
|
-
const supportsColor = {
|
|
430
|
-
stdout: createSupportsColor({
|
|
431
|
-
isTTY: node_tty.isatty(1)
|
|
432
|
-
}),
|
|
433
|
-
stderr: createSupportsColor({
|
|
434
|
-
isTTY: node_tty.isatty(2)
|
|
435
|
-
})
|
|
436
|
-
};
|
|
437
|
-
const supports_color = supportsColor;
|
|
438
|
-
function stringReplaceAll(string, substring, replacer) {
|
|
439
|
-
let index = string.indexOf(substring);
|
|
440
|
-
if (-1 === index) return string;
|
|
441
|
-
const substringLength = substring.length;
|
|
442
|
-
let endIndex = 0;
|
|
443
|
-
let returnValue = '';
|
|
444
|
-
do {
|
|
445
|
-
returnValue += string.slice(endIndex, index) + substring + replacer;
|
|
446
|
-
endIndex = index + substringLength;
|
|
447
|
-
index = string.indexOf(substring, endIndex);
|
|
448
|
-
}while (-1 !== index);
|
|
449
|
-
returnValue += string.slice(endIndex);
|
|
450
|
-
return returnValue;
|
|
451
|
-
}
|
|
452
|
-
function stringEncaseCRLFWithFirstIndex(string, prefix, postfix, index) {
|
|
453
|
-
let endIndex = 0;
|
|
454
|
-
let returnValue = '';
|
|
455
|
-
do {
|
|
456
|
-
const gotCR = '\r' === string[index - 1];
|
|
457
|
-
returnValue += string.slice(endIndex, gotCR ? index - 1 : index) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
|
458
|
-
endIndex = index + 1;
|
|
459
|
-
index = string.indexOf('\n', endIndex);
|
|
460
|
-
}while (-1 !== index);
|
|
461
|
-
returnValue += string.slice(endIndex);
|
|
462
|
-
return returnValue;
|
|
463
|
-
}
|
|
464
|
-
const { stdout: stdoutColor, stderr: stderrColor } = supports_color;
|
|
465
|
-
const GENERATOR = Symbol('GENERATOR');
|
|
466
|
-
const STYLER = Symbol('STYLER');
|
|
467
|
-
const IS_EMPTY = Symbol('IS_EMPTY');
|
|
468
|
-
const levelMapping = [
|
|
469
|
-
'ansi',
|
|
470
|
-
'ansi',
|
|
471
|
-
'ansi256',
|
|
472
|
-
'ansi16m'
|
|
473
|
-
];
|
|
474
|
-
const source_styles = Object.create(null);
|
|
475
|
-
const applyOptions = (object, options = {})=>{
|
|
476
|
-
if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) throw new Error('The `level` option should be an integer from 0 to 3');
|
|
477
|
-
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
|
478
|
-
object.level = void 0 === options.level ? colorLevel : options.level;
|
|
479
|
-
};
|
|
480
|
-
const chalkFactory = (options)=>{
|
|
481
|
-
const chalk = (...strings)=>strings.join(' ');
|
|
482
|
-
applyOptions(chalk, options);
|
|
483
|
-
Object.setPrototypeOf(chalk, createChalk.prototype);
|
|
484
|
-
return chalk;
|
|
485
|
-
};
|
|
486
|
-
function createChalk(options) {
|
|
487
|
-
return chalkFactory(options);
|
|
488
|
-
}
|
|
489
|
-
Object.setPrototypeOf(createChalk.prototype, Function.prototype);
|
|
490
|
-
for (const [styleName, style] of Object.entries(ansi_styles))source_styles[styleName] = {
|
|
491
|
-
get () {
|
|
492
|
-
const builder = createBuilder(this, createStyler(style.open, style.close, this[STYLER]), this[IS_EMPTY]);
|
|
493
|
-
Object.defineProperty(this, styleName, {
|
|
494
|
-
value: builder
|
|
495
|
-
});
|
|
496
|
-
return builder;
|
|
497
|
-
}
|
|
498
|
-
};
|
|
499
|
-
source_styles.visible = {
|
|
500
|
-
get () {
|
|
501
|
-
const builder = createBuilder(this, this[STYLER], true);
|
|
502
|
-
Object.defineProperty(this, 'visible', {
|
|
503
|
-
value: builder
|
|
504
|
-
});
|
|
505
|
-
return builder;
|
|
506
|
-
}
|
|
507
|
-
};
|
|
508
|
-
const getModelAnsi = (model, level, type, ...arguments_)=>{
|
|
509
|
-
if ('rgb' === model) {
|
|
510
|
-
if ('ansi16m' === level) return ansi_styles[type].ansi16m(...arguments_);
|
|
511
|
-
if ('ansi256' === level) return ansi_styles[type].ansi256(ansi_styles.rgbToAnsi256(...arguments_));
|
|
512
|
-
return ansi_styles[type].ansi(ansi_styles.rgbToAnsi(...arguments_));
|
|
513
|
-
}
|
|
514
|
-
if ('hex' === model) return getModelAnsi('rgb', level, type, ...ansi_styles.hexToRgb(...arguments_));
|
|
515
|
-
return ansi_styles[type][model](...arguments_);
|
|
516
|
-
};
|
|
517
|
-
const usedModels = [
|
|
518
|
-
'rgb',
|
|
519
|
-
'hex',
|
|
520
|
-
'ansi256'
|
|
521
|
-
];
|
|
522
|
-
for (const model of usedModels){
|
|
523
|
-
source_styles[model] = {
|
|
524
|
-
get () {
|
|
525
|
-
const { level } = this;
|
|
526
|
-
return function(...arguments_) {
|
|
527
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'color', ...arguments_), ansi_styles.color.close, this[STYLER]);
|
|
528
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
|
-
};
|
|
532
|
-
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
|
533
|
-
source_styles[bgModel] = {
|
|
534
|
-
get () {
|
|
535
|
-
const { level } = this;
|
|
536
|
-
return function(...arguments_) {
|
|
537
|
-
const styler = createStyler(getModelAnsi(model, levelMapping[level], 'bgColor', ...arguments_), ansi_styles.bgColor.close, this[STYLER]);
|
|
538
|
-
return createBuilder(this, styler, this[IS_EMPTY]);
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
};
|
|
542
|
-
}
|
|
543
|
-
const proto = Object.defineProperties(()=>{}, {
|
|
544
|
-
...source_styles,
|
|
545
|
-
level: {
|
|
546
|
-
enumerable: true,
|
|
547
|
-
get () {
|
|
548
|
-
return this[GENERATOR].level;
|
|
549
|
-
},
|
|
550
|
-
set (level) {
|
|
551
|
-
this[GENERATOR].level = level;
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
});
|
|
555
|
-
const createStyler = (open, close, parent)=>{
|
|
556
|
-
let openAll;
|
|
557
|
-
let closeAll;
|
|
558
|
-
if (void 0 === parent) {
|
|
559
|
-
openAll = open;
|
|
560
|
-
closeAll = close;
|
|
561
|
-
} else {
|
|
562
|
-
openAll = parent.openAll + open;
|
|
563
|
-
closeAll = close + parent.closeAll;
|
|
564
|
-
}
|
|
565
|
-
return {
|
|
566
|
-
open,
|
|
567
|
-
close,
|
|
568
|
-
openAll,
|
|
569
|
-
closeAll,
|
|
570
|
-
parent
|
|
571
|
-
};
|
|
572
|
-
};
|
|
573
|
-
const createBuilder = (self, _styler, _isEmpty)=>{
|
|
574
|
-
const builder = (...arguments_)=>applyStyle(builder, 1 === arguments_.length ? '' + arguments_[0] : arguments_.join(' '));
|
|
575
|
-
Object.setPrototypeOf(builder, proto);
|
|
576
|
-
builder[GENERATOR] = self;
|
|
577
|
-
builder[STYLER] = _styler;
|
|
578
|
-
builder[IS_EMPTY] = _isEmpty;
|
|
579
|
-
return builder;
|
|
580
|
-
};
|
|
581
|
-
const applyStyle = (self, string)=>{
|
|
582
|
-
if (self.level <= 0 || !string) return self[IS_EMPTY] ? '' : string;
|
|
583
|
-
let styler = self[STYLER];
|
|
584
|
-
if (void 0 === styler) return string;
|
|
585
|
-
const { openAll, closeAll } = styler;
|
|
586
|
-
if (string.includes('\u001B')) while(void 0 !== styler){
|
|
587
|
-
string = stringReplaceAll(string, styler.close, styler.open);
|
|
588
|
-
styler = styler.parent;
|
|
589
|
-
}
|
|
590
|
-
const lfIndex = string.indexOf('\n');
|
|
591
|
-
if (-1 !== lfIndex) string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
|
592
|
-
return openAll + string + closeAll;
|
|
593
|
-
};
|
|
594
|
-
Object.defineProperties(createChalk.prototype, source_styles);
|
|
595
|
-
const source_chalk = createChalk();
|
|
596
|
-
createChalk({
|
|
597
|
-
level: stderrColor ? stderrColor.level : 0
|
|
598
|
-
});
|
|
599
|
-
const source = source_chalk;
|
|
600
|
-
var root_path_global_ProcessEnvProp = /*#__PURE__*/ function(ProcessEnvProp) {
|
|
601
|
-
ProcessEnvProp["WorkingDirLogsLevel"] = "ENABLE_WORKING_DIR_LOGS_LEVEL";
|
|
602
|
-
ProcessEnvProp["RootWorkingDirectory"] = "ROOT_WORKING_DIRECTORY";
|
|
603
|
-
return ProcessEnvProp;
|
|
604
|
-
}(root_path_global_ProcessEnvProp || {});
|
|
605
|
-
var root_path_global_WorkingDirLogsLevel = /*#__PURE__*/ function(WorkingDirLogsLevel) {
|
|
606
|
-
WorkingDirLogsLevel["None"] = "none";
|
|
607
|
-
WorkingDirLogsLevel["Info"] = "info";
|
|
608
|
-
WorkingDirLogsLevel["Verbose"] = "verbose";
|
|
609
|
-
return WorkingDirLogsLevel;
|
|
610
|
-
}(root_path_global_WorkingDirLogsLevel || {});
|
|
611
|
-
function logInfo(...args) {
|
|
612
|
-
console.info("SENTENEL PATH::", source.blueBright(...args.map((arg)=>String(arg))));
|
|
613
|
-
}
|
|
614
|
-
function getRootWorkingDirectory() {
|
|
615
|
-
const workingDirLogsLevel = process.env["ENABLE_WORKING_DIR_LOGS_LEVEL"] || "none";
|
|
616
|
-
if (!Object.values(root_path_global_WorkingDirLogsLevel).includes(workingDirLogsLevel)) console.error(`Invalid value for environment variable ENABLE_WORKING_DIR_LOGS_LEVEL: ${workingDirLogsLevel}. Defaulting to none.`);
|
|
617
|
-
if ("info" === workingDirLogsLevel || "verbose" === workingDirLogsLevel) logInfo("Getting root working directory from environment variable ROOT_WORKING_DIRECTORY...");
|
|
618
|
-
const isVerbose = "verbose" === workingDirLogsLevel;
|
|
619
|
-
const isInfo = "info" === workingDirLogsLevel || isVerbose;
|
|
620
|
-
const currentWorkingDirectory = realpathSync(process.cwd());
|
|
621
|
-
const nodeModulesPathList = node_module._nodeModulePaths(currentWorkingDirectory);
|
|
622
|
-
isVerbose && logInfo("Current working directory:", currentWorkingDirectory);
|
|
623
|
-
isVerbose && logInfo("Node modules path list:", nodeModulesPathList);
|
|
624
|
-
const packageJsonPathList = nodeModulesPathList.map((nodeModulesPath)=>{
|
|
625
|
-
const packageJsonPath = nodeModulesPath.replace("node_modules", "package.json");
|
|
626
|
-
return packageJsonPath;
|
|
627
|
-
});
|
|
628
|
-
isVerbose && logInfo("Package.json path list:", packageJsonPathList);
|
|
629
|
-
const packageJsonExistsPathList = packageJsonPathList.filter((packageJsonPath)=>{
|
|
630
|
-
try {
|
|
631
|
-
realpathSync(packageJsonPath);
|
|
632
|
-
return true;
|
|
633
|
-
} catch {
|
|
634
|
-
return false;
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
isVerbose && logInfo("Existing package.json path list:", packageJsonExistsPathList);
|
|
638
|
-
if (0 === packageJsonExistsPathList.length) isInfo && logInfo("No package.json found in node modules paths.");
|
|
639
|
-
const workspacePackageJsonList = packageJsonExistsPathList.filter((packageJsonPath)=>{
|
|
640
|
-
const packageJsonBuffer = readFileSync(packageJsonPath);
|
|
641
|
-
const packageJsonContent = JSON.parse(packageJsonBuffer);
|
|
642
|
-
if (packageJsonContent?.workspaces && packageJsonContent?.workspaces.length > 0) return true;
|
|
643
|
-
return false;
|
|
644
|
-
});
|
|
645
|
-
isVerbose && logInfo("Workspace package.json list:", workspacePackageJsonList);
|
|
646
|
-
if (0 === workspacePackageJsonList.length) {
|
|
647
|
-
isInfo && logInfo("No workspace package.json found in node modules paths.");
|
|
648
|
-
const rootWorkingDirectory = currentWorkingDirectory;
|
|
649
|
-
if (!rootWorkingDirectory) throw new Error("Environment variable ROOT_WORKING_DIRECTORY is not set.");
|
|
650
|
-
isInfo && logInfo(`Current working directory determined: ${currentWorkingDirectory}`);
|
|
651
|
-
isInfo && logInfo(`Root working directory determined: ${rootWorkingDirectory}`);
|
|
652
|
-
process.env["ROOT_WORKING_DIRECTORY"] = rootWorkingDirectory;
|
|
653
|
-
return rootWorkingDirectory;
|
|
654
|
-
}
|
|
655
|
-
if (1 === workspacePackageJsonList.length) {
|
|
656
|
-
isInfo && logInfo(`Single workspace package.json file found: ${workspacePackageJsonList[0]}`);
|
|
657
|
-
const rootPackageJsonPath = realpathSync(workspacePackageJsonList[0]);
|
|
658
|
-
const rootWorkingDirectory = rootPackageJsonPath.replace("/package.json", "");
|
|
659
|
-
isInfo && logInfo(`Current working directory determined: ${currentWorkingDirectory}`);
|
|
660
|
-
isInfo && logInfo(`Root working directory determined: ${rootWorkingDirectory}`);
|
|
661
|
-
process.env["ROOT_WORKING_DIRECTORY"] = rootWorkingDirectory;
|
|
662
|
-
return rootWorkingDirectory;
|
|
663
|
-
}
|
|
664
|
-
if (workspacePackageJsonList.length > 1) {
|
|
665
|
-
isInfo && logInfo(`Multiple workspace package.json files found: ${workspacePackageJsonList.join(", ")}`);
|
|
666
|
-
const rootWorkingDirectory = currentWorkingDirectory;
|
|
667
|
-
isInfo && logInfo(`Current working directory determined (fallback): ${currentWorkingDirectory}`);
|
|
668
|
-
isInfo && logInfo(`Root working directory determined (fallback): ${rootWorkingDirectory}`);
|
|
669
|
-
process.env["ROOT_WORKING_DIRECTORY"] = rootWorkingDirectory;
|
|
670
|
-
return rootWorkingDirectory;
|
|
671
|
-
}
|
|
672
|
-
console.error("Unable to determine root working directory.");
|
|
673
|
-
}
|
|
674
|
-
getRootWorkingDirectory();
|
|
675
|
-
const paths_currentWorkingDirectory = realpathSync(process.cwd());
|
|
676
|
-
const paths_rootWorkingDirectory = realpathSync(process.env["ROOT_WORKING_DIRECTORY"] || paths_currentWorkingDirectory);
|
|
677
|
-
function resolveRootPath(relativePath) {
|
|
678
|
-
if (!paths_rootWorkingDirectory) {
|
|
679
|
-
console.log("Define \"process.env[ProcessEnvProp.WorkingDirLogsLevel]\"='none' | 'info' | 'verbose' to enable logging of the working directory resolution process.");
|
|
680
|
-
throw new Error("Root working directory is not defined. Please set the environment variable ROOT_WORKING_DIRECTORY to the desired root working directory path.");
|
|
681
|
-
}
|
|
682
|
-
return resolve(paths_rootWorkingDirectory, relativePath);
|
|
683
|
-
}
|
|
684
|
-
function resolveWorkspaceDirectory(relativePath) {
|
|
685
|
-
if (!paths_currentWorkingDirectory) throw new Error("Current working directory is not defined. Please set the environment variable ROOT_WORKING_DIRECTORY to the desired root working directory path.");
|
|
686
|
-
return resolve(paths_currentWorkingDirectory, relativePath);
|
|
687
|
-
}
|
|
688
|
-
export { asyncExpandDotEnv, resolveRootPath, resolveWorkspaceDirectory, syncExpandDotEnv };
|
|
1
|
+
export * from "./dotenv/index.js";
|
|
2
|
+
export * from "./paths/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/paths/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../../src/paths/paths.ts"],"names":[],"mappings":"AASA,iBAAS,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAWrD;AAED,iBAAS,yBAAyB,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,CAQ/D;AAED,OAAO,EAAE,eAAe,EAAE,yBAAyB,EAAE,CAAC"}
|