@socketsecurity/lib 1.3.2 → 1.3.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.
Files changed (338) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/abort.js +1 -60
  3. package/dist/abort.js.map +2 -2
  4. package/dist/agent.js +1 -289
  5. package/dist/agent.js.map +2 -2
  6. package/dist/ansi.js +1 -60
  7. package/dist/ansi.js.map +2 -2
  8. package/dist/argv/flags.js +1 -282
  9. package/dist/argv/flags.js.map +2 -2
  10. package/dist/argv/parse.js +1 -171
  11. package/dist/argv/parse.js.map +2 -2
  12. package/dist/arrays.js +1 -85
  13. package/dist/arrays.js.map +2 -2
  14. package/dist/bin.js +1 -402
  15. package/dist/bin.js.map +2 -2
  16. package/dist/cacache.js +1 -137
  17. package/dist/cacache.js.map +2 -2
  18. package/dist/cache-with-ttl.js +1 -223
  19. package/dist/cache-with-ttl.js.map +2 -2
  20. package/dist/constants/agents.js +1 -126
  21. package/dist/constants/agents.js.map +2 -2
  22. package/dist/constants/core.js +2 -57
  23. package/dist/constants/core.js.map +2 -2
  24. package/dist/constants/encoding.js +1 -48
  25. package/dist/constants/encoding.js.map +2 -2
  26. package/dist/constants/github.js +1 -30
  27. package/dist/constants/github.js.map +2 -2
  28. package/dist/constants/licenses.js +1 -66
  29. package/dist/constants/licenses.js.map +2 -2
  30. package/dist/constants/node.d.ts +2 -3
  31. package/dist/constants/node.js +1 -171
  32. package/dist/constants/node.js.map +3 -3
  33. package/dist/constants/packages.js +1 -128
  34. package/dist/constants/packages.js.map +2 -2
  35. package/dist/constants/paths.js +1 -150
  36. package/dist/constants/paths.js.map +2 -2
  37. package/dist/constants/platform.js +1 -41
  38. package/dist/constants/platform.js.map +2 -2
  39. package/dist/constants/process.js +1 -52
  40. package/dist/constants/process.js.map +2 -2
  41. package/dist/constants/socket.js +1 -81
  42. package/dist/constants/socket.js.map +2 -2
  43. package/dist/constants/testing.js +1 -36
  44. package/dist/constants/testing.js.map +2 -2
  45. package/dist/constants/time.js +1 -39
  46. package/dist/constants/time.js.map +2 -2
  47. package/dist/constants/typescript.js +1 -54
  48. package/dist/constants/typescript.js.map +2 -2
  49. package/dist/cover/code.js +1 -135
  50. package/dist/cover/code.js.map +2 -2
  51. package/dist/cover/formatters.js +11 -101
  52. package/dist/cover/formatters.js.map +2 -2
  53. package/dist/cover/type.js +1 -63
  54. package/dist/cover/type.js.map +2 -2
  55. package/dist/cover/types.js +1 -15
  56. package/dist/cover/types.js.map +2 -2
  57. package/dist/debug.js +2 -343
  58. package/dist/debug.js.map +2 -2
  59. package/dist/dlx-binary.js +1 -259
  60. package/dist/dlx-binary.js.map +2 -2
  61. package/dist/dlx-package.js +1 -149
  62. package/dist/dlx-package.js.map +2 -2
  63. package/dist/dlx.js +1 -166
  64. package/dist/dlx.js.map +2 -2
  65. package/dist/download-lock.js +1 -137
  66. package/dist/download-lock.js.map +2 -2
  67. package/dist/effects/pulse-frames.js +1 -64
  68. package/dist/effects/pulse-frames.js.map +2 -2
  69. package/dist/effects/text-shimmer.js +1 -174
  70. package/dist/effects/text-shimmer.js.map +2 -2
  71. package/dist/effects/types.js +1 -15
  72. package/dist/effects/types.js.map +2 -2
  73. package/dist/effects/ultra.js +1 -61
  74. package/dist/effects/ultra.js.map +2 -2
  75. package/dist/env/appdata.js +1 -28
  76. package/dist/env/appdata.js.map +2 -2
  77. package/dist/env/ci.js +1 -29
  78. package/dist/env/ci.js.map +2 -2
  79. package/dist/env/comspec.js +1 -28
  80. package/dist/env/comspec.js.map +2 -2
  81. package/dist/env/debug.js +1 -28
  82. package/dist/env/debug.js.map +2 -2
  83. package/dist/env/getters.js +1 -281
  84. package/dist/env/getters.js.map +2 -2
  85. package/dist/env/github-api-url.js +1 -28
  86. package/dist/env/github-api-url.js.map +2 -2
  87. package/dist/env/github-base-ref.js +1 -28
  88. package/dist/env/github-base-ref.js.map +2 -2
  89. package/dist/env/github-ref-name.js +1 -28
  90. package/dist/env/github-ref-name.js.map +2 -2
  91. package/dist/env/github-ref-type.js +1 -28
  92. package/dist/env/github-ref-type.js.map +2 -2
  93. package/dist/env/github-repository.js +1 -28
  94. package/dist/env/github-repository.js.map +2 -2
  95. package/dist/env/github-server-url.js +1 -28
  96. package/dist/env/github-server-url.js.map +2 -2
  97. package/dist/env/github-token.js +1 -28
  98. package/dist/env/github-token.js.map +2 -2
  99. package/dist/env/helpers.js +1 -47
  100. package/dist/env/helpers.js.map +2 -2
  101. package/dist/env/home.js +1 -28
  102. package/dist/env/home.js.map +2 -2
  103. package/dist/env/jest-worker-id.js +1 -28
  104. package/dist/env/jest-worker-id.js.map +2 -2
  105. package/dist/env/lang.js +1 -28
  106. package/dist/env/lang.js.map +2 -2
  107. package/dist/env/lc-all.js +1 -28
  108. package/dist/env/lc-all.js.map +2 -2
  109. package/dist/env/lc-messages.js +1 -28
  110. package/dist/env/lc-messages.js.map +2 -2
  111. package/dist/env/localappdata.js +1 -28
  112. package/dist/env/localappdata.js.map +2 -2
  113. package/dist/env/node-auth-token.js +1 -28
  114. package/dist/env/node-auth-token.js.map +2 -2
  115. package/dist/env/node-env.js +1 -28
  116. package/dist/env/node-env.js.map +2 -2
  117. package/dist/env/npm-config-registry.js +1 -28
  118. package/dist/env/npm-config-registry.js.map +2 -2
  119. package/dist/env/npm-config-user-agent.js +1 -28
  120. package/dist/env/npm-config-user-agent.js.map +2 -2
  121. package/dist/env/npm-lifecycle-event.js +1 -28
  122. package/dist/env/npm-lifecycle-event.js.map +2 -2
  123. package/dist/env/npm-registry.js +1 -28
  124. package/dist/env/npm-registry.js.map +2 -2
  125. package/dist/env/npm-token.js +1 -28
  126. package/dist/env/npm-token.js.map +2 -2
  127. package/dist/env/path.js +1 -28
  128. package/dist/env/path.js.map +2 -2
  129. package/dist/env/pre-commit.js +1 -29
  130. package/dist/env/pre-commit.js.map +2 -2
  131. package/dist/env/shell.js +1 -28
  132. package/dist/env/shell.js.map +2 -2
  133. package/dist/env/socket-accept-risks.js +1 -29
  134. package/dist/env/socket-accept-risks.js.map +2 -2
  135. package/dist/env/socket-api-base-url.js +1 -28
  136. package/dist/env/socket-api-base-url.js.map +2 -2
  137. package/dist/env/socket-api-proxy.js +1 -28
  138. package/dist/env/socket-api-proxy.js.map +2 -2
  139. package/dist/env/socket-api-timeout.js +1 -29
  140. package/dist/env/socket-api-timeout.js.map +2 -2
  141. package/dist/env/socket-api-token.js +1 -28
  142. package/dist/env/socket-api-token.js.map +2 -2
  143. package/dist/env/socket-cacache-dir.js +1 -28
  144. package/dist/env/socket-cacache-dir.js.map +2 -2
  145. package/dist/env/socket-cli-accept-risks.js +1 -31
  146. package/dist/env/socket-cli-accept-risks.js.map +2 -2
  147. package/dist/env/socket-cli-api-base-url.js +1 -28
  148. package/dist/env/socket-cli-api-base-url.js.map +2 -2
  149. package/dist/env/socket-cli-api-proxy.js +1 -28
  150. package/dist/env/socket-cli-api-proxy.js.map +2 -2
  151. package/dist/env/socket-cli-api-timeout.js +1 -29
  152. package/dist/env/socket-cli-api-timeout.js.map +2 -2
  153. package/dist/env/socket-cli-api-token.js +1 -28
  154. package/dist/env/socket-cli-api-token.js.map +2 -2
  155. package/dist/env/socket-cli-config.js +1 -28
  156. package/dist/env/socket-cli-config.js.map +2 -2
  157. package/dist/env/socket-cli-fix.js +1 -28
  158. package/dist/env/socket-cli-fix.js.map +2 -2
  159. package/dist/env/socket-cli-no-api-token.js +1 -31
  160. package/dist/env/socket-cli-no-api-token.js.map +2 -2
  161. package/dist/env/socket-cli-optimize.js +1 -29
  162. package/dist/env/socket-cli-optimize.js.map +2 -2
  163. package/dist/env/socket-cli-org-slug.js +1 -28
  164. package/dist/env/socket-cli-org-slug.js.map +2 -2
  165. package/dist/env/socket-cli-shadow-accept-risks.js +1 -31
  166. package/dist/env/socket-cli-shadow-accept-risks.js.map +2 -2
  167. package/dist/env/socket-cli-shadow-api-token.js +1 -28
  168. package/dist/env/socket-cli-shadow-api-token.js.map +2 -2
  169. package/dist/env/socket-cli-shadow-bin.js +1 -28
  170. package/dist/env/socket-cli-shadow-bin.js.map +2 -2
  171. package/dist/env/socket-cli-shadow-progress.js +1 -31
  172. package/dist/env/socket-cli-shadow-progress.js.map +2 -2
  173. package/dist/env/socket-cli-shadow-silent.js +1 -31
  174. package/dist/env/socket-cli-shadow-silent.js.map +2 -2
  175. package/dist/env/socket-cli-view-all-risks.js +1 -31
  176. package/dist/env/socket-cli-view-all-risks.js.map +2 -2
  177. package/dist/env/socket-config.js +1 -28
  178. package/dist/env/socket-config.js.map +2 -2
  179. package/dist/env/socket-debug.js +1 -28
  180. package/dist/env/socket-debug.js.map +2 -2
  181. package/dist/env/socket-home.js +1 -28
  182. package/dist/env/socket-home.js.map +2 -2
  183. package/dist/env/socket-no-api-token.js +1 -29
  184. package/dist/env/socket-no-api-token.js.map +2 -2
  185. package/dist/env/socket-npm-registry.js +1 -28
  186. package/dist/env/socket-npm-registry.js.map +2 -2
  187. package/dist/env/socket-org-slug.js +1 -28
  188. package/dist/env/socket-org-slug.js.map +2 -2
  189. package/dist/env/socket-registry-url.js +1 -28
  190. package/dist/env/socket-registry-url.js.map +2 -2
  191. package/dist/env/socket-view-all-risks.js +1 -29
  192. package/dist/env/socket-view-all-risks.js.map +2 -2
  193. package/dist/env/temp.js +1 -28
  194. package/dist/env/temp.js.map +2 -2
  195. package/dist/env/term.js +1 -28
  196. package/dist/env/term.js.map +2 -2
  197. package/dist/env/tmp.js +1 -28
  198. package/dist/env/tmp.js.map +2 -2
  199. package/dist/env/tmpdir.js +1 -28
  200. package/dist/env/tmpdir.js.map +2 -2
  201. package/dist/env/userprofile.js +1 -28
  202. package/dist/env/userprofile.js.map +2 -2
  203. package/dist/env/vitest.js +1 -29
  204. package/dist/env/vitest.js.map +2 -2
  205. package/dist/env/xdg-cache-home.js +1 -28
  206. package/dist/env/xdg-cache-home.js.map +2 -2
  207. package/dist/env/xdg-config-home.js +1 -28
  208. package/dist/env/xdg-config-home.js.map +2 -2
  209. package/dist/env/xdg-data-home.js +1 -28
  210. package/dist/env/xdg-data-home.js.map +2 -2
  211. package/dist/env.js +1 -61
  212. package/dist/env.js.map +2 -2
  213. package/dist/fs.js +3 -626
  214. package/dist/fs.js.map +2 -2
  215. package/dist/functions.js +1 -68
  216. package/dist/functions.js.map +2 -2
  217. package/dist/git.js +2 -320
  218. package/dist/git.js.map +2 -2
  219. package/dist/github.js +1 -201
  220. package/dist/github.js.map +2 -2
  221. package/dist/globs.js +1 -152
  222. package/dist/globs.js.map +2 -2
  223. package/dist/http-request.js +1 -313
  224. package/dist/http-request.js.map +2 -2
  225. package/dist/index.js +1 -62
  226. package/dist/index.js.map +2 -2
  227. package/dist/ipc.js +1 -232
  228. package/dist/ipc.js.map +2 -2
  229. package/dist/json.js +1 -73
  230. package/dist/json.js.map +2 -2
  231. package/dist/logger.js +1 -1254
  232. package/dist/logger.js.map +2 -2
  233. package/dist/maintained-node-versions.js +1 -35
  234. package/dist/maintained-node-versions.js.map +2 -2
  235. package/dist/memoization.js +1 -210
  236. package/dist/memoization.js.map +2 -2
  237. package/dist/objects.d.ts +0 -3
  238. package/dist/objects.js +1 -319
  239. package/dist/objects.js.map +3 -3
  240. package/dist/packages/editable.js +9 -356
  241. package/dist/packages/editable.js.map +2 -2
  242. package/dist/packages/exports.js +1 -162
  243. package/dist/packages/exports.js.map +2 -2
  244. package/dist/packages/isolation.js +1 -195
  245. package/dist/packages/isolation.js.map +2 -2
  246. package/dist/packages/licenses.js +1 -214
  247. package/dist/packages/licenses.js.map +2 -2
  248. package/dist/packages/manifest.js +1 -190
  249. package/dist/packages/manifest.js.map +2 -2
  250. package/dist/packages/normalize.js +1 -120
  251. package/dist/packages/normalize.js.map +2 -2
  252. package/dist/packages/operations.js +1 -304
  253. package/dist/packages/operations.js.map +2 -2
  254. package/dist/packages/paths.js +1 -53
  255. package/dist/packages/paths.js.map +2 -2
  256. package/dist/packages/provenance.js +1 -178
  257. package/dist/packages/provenance.js.map +2 -2
  258. package/dist/packages/registry.js +1 -28
  259. package/dist/packages/registry.js.map +2 -2
  260. package/dist/packages/specs.js +1 -83
  261. package/dist/packages/specs.js.map +2 -2
  262. package/dist/packages/validation.js +1 -51
  263. package/dist/packages/validation.js.map +2 -2
  264. package/dist/packages.js +1 -129
  265. package/dist/packages.js.map +2 -2
  266. package/dist/path.js +1 -448
  267. package/dist/path.js.map +2 -2
  268. package/dist/paths.js +1 -143
  269. package/dist/paths.js.map +2 -2
  270. package/dist/performance.js +15 -216
  271. package/dist/performance.js.map +2 -2
  272. package/dist/promise-queue.js +1 -109
  273. package/dist/promise-queue.js.map +2 -2
  274. package/dist/promises.js +1 -269
  275. package/dist/promises.js.map +2 -2
  276. package/dist/prompts.js +1 -58
  277. package/dist/prompts.js.map +2 -2
  278. package/dist/regexps.js +1 -30
  279. package/dist/regexps.js.map +2 -2
  280. package/dist/sea.js +1 -44
  281. package/dist/sea.js.map +2 -2
  282. package/dist/shadow.js +1 -58
  283. package/dist/shadow.js.map +2 -2
  284. package/dist/signal-exit.js +1 -248
  285. package/dist/signal-exit.js.map +2 -2
  286. package/dist/sorts.js +1 -94
  287. package/dist/sorts.js.map +2 -2
  288. package/dist/spawn.js +1 -199
  289. package/dist/spawn.js.map +2 -2
  290. package/dist/spinner.js +1 -865
  291. package/dist/spinner.js.map +2 -2
  292. package/dist/ssri.js +1 -71
  293. package/dist/ssri.js.map +2 -2
  294. package/dist/stdio/clear.js +1 -82
  295. package/dist/stdio/clear.js.map +2 -2
  296. package/dist/stdio/divider.js +3 -89
  297. package/dist/stdio/divider.js.map +2 -2
  298. package/dist/stdio/footer.js +2 -94
  299. package/dist/stdio/footer.js.map +2 -2
  300. package/dist/stdio/header.js +2 -100
  301. package/dist/stdio/header.js.map +2 -2
  302. package/dist/stdio/mask.js +5 -206
  303. package/dist/stdio/mask.js.map +2 -2
  304. package/dist/stdio/progress.js +2 -209
  305. package/dist/stdio/progress.js.map +2 -2
  306. package/dist/stdio/prompts.js +1 -88
  307. package/dist/stdio/prompts.js.map +2 -2
  308. package/dist/stdio/stderr.js +2 -89
  309. package/dist/stdio/stderr.js.map +2 -2
  310. package/dist/stdio/stdout.js +2 -103
  311. package/dist/stdio/stdout.js.map +2 -2
  312. package/dist/streams.js +1 -78
  313. package/dist/streams.js.map +2 -2
  314. package/dist/strings.js +3 -251
  315. package/dist/strings.js.map +2 -2
  316. package/dist/suppress-warnings.js +1 -98
  317. package/dist/suppress-warnings.js.map +2 -2
  318. package/dist/tables.js +3 -128
  319. package/dist/tables.js.map +2 -2
  320. package/dist/temporary-executor.js +1 -53
  321. package/dist/temporary-executor.js.map +2 -2
  322. package/dist/types.js +1 -72
  323. package/dist/types.js.map +2 -2
  324. package/dist/url.js +1 -142
  325. package/dist/url.js.map +2 -2
  326. package/dist/utils/get-ipc.js +1 -58
  327. package/dist/utils/get-ipc.js.map +2 -2
  328. package/dist/validation/json-parser.js +1 -127
  329. package/dist/validation/json-parser.js.map +2 -2
  330. package/dist/validation/types.js +1 -15
  331. package/dist/validation/types.js.map +2 -2
  332. package/dist/versions.js +1 -153
  333. package/dist/versions.js.map +2 -2
  334. package/dist/words.js +1 -50
  335. package/dist/words.js.map +2 -2
  336. package/dist/zod.js +1 -27
  337. package/dist/zod.js.map +2 -2
  338. package/package.json +4 -4
package/dist/logger.js CHANGED
@@ -1,1256 +1,3 @@
1
1
  /* Socket Lib - Built with esbuild */
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var logger_exports = {};
30
- __export(logger_exports, {
31
- LOG_SYMBOLS: () => LOG_SYMBOLS,
32
- Logger: () => Logger,
33
- incLogCallCountSymbol: () => incLogCallCountSymbol,
34
- lastWasBlankSymbol: () => lastWasBlankSymbol,
35
- logger: () => logger
36
- });
37
- module.exports = __toCommonJS(logger_exports);
38
- var import_is_unicode_supported = __toESM(require("./external/@socketregistry/is-unicode-supported"));
39
- var import_yoctocolors_cjs = __toESM(require("./external/yoctocolors-cjs"));
40
- var import_objects = require("./objects");
41
- var import_strings = require("./strings");
42
- const globalConsole = console;
43
- const ReflectApply = Reflect.apply;
44
- const ReflectConstruct = Reflect.construct;
45
- let _Console;
46
- // @__NO_SIDE_EFFECTS__
47
- function constructConsole(...args) {
48
- if (_Console === void 0) {
49
- const nodeConsole = require("node:console");
50
- _Console = nodeConsole.Console;
51
- }
52
- return ReflectConstruct(
53
- _Console,
54
- // eslint-disable-line no-undef
55
- args
56
- );
57
- }
58
- // @__NO_SIDE_EFFECTS__
59
- function getYoctocolors() {
60
- return import_yoctocolors_cjs.default;
61
- }
62
- const LOG_SYMBOLS = /* @__PURE__ */ (() => {
63
- const target = {
64
- __proto__: null
65
- };
66
- const handler = {
67
- __proto__: null
68
- };
69
- const init = () => {
70
- const supported = (0, import_is_unicode_supported.default)();
71
- const colors = /* @__PURE__ */ getYoctocolors();
72
- (0, import_objects.objectAssign)(target, {
73
- fail: colors.red(supported ? "\u2716" : "\xD7"),
74
- info: colors.blue(supported ? "\u2139" : "i"),
75
- success: colors.green(supported ? "\u2714" : "\u221A"),
76
- warn: colors.yellow(supported ? "\u26A0" : "\u203C")
77
- });
78
- (0, import_objects.objectFreeze)(target);
79
- for (const trapName in handler) {
80
- delete handler[trapName];
81
- }
82
- };
83
- for (const trapName of Reflect.ownKeys(Reflect)) {
84
- const fn = Reflect[trapName];
85
- if (typeof fn === "function") {
86
- ;
87
- handler[trapName] = (...args) => {
88
- init();
89
- return fn(...args);
90
- };
91
- }
92
- }
93
- return new Proxy(target, handler);
94
- })();
95
- const boundConsoleEntries = [
96
- // Add bound properties from console[kBindProperties](ignoreErrors, colorMode, groupIndentation).
97
- // https://github.com/nodejs/node/blob/v24.0.1/lib/internal/console/constructor.js#L230-L265
98
- "_stderrErrorHandler",
99
- "_stdoutErrorHandler",
100
- // Add methods that need to be bound to function properly.
101
- "assert",
102
- "clear",
103
- "count",
104
- "countReset",
105
- "createTask",
106
- "debug",
107
- "dir",
108
- "dirxml",
109
- "error",
110
- // Skip group methods because in at least Node 20 with the Node --frozen-intrinsics
111
- // flag it triggers a readonly property for Symbol(kGroupIndent). Instead, we
112
- // implement these methods ourselves.
113
- //'group',
114
- //'groupCollapsed',
115
- //'groupEnd',
116
- "info",
117
- "log",
118
- "table",
119
- "time",
120
- "timeEnd",
121
- "timeLog",
122
- "trace",
123
- "warn"
124
- ].filter((n) => typeof globalConsole[n] === "function").map((n) => [n, globalConsole[n].bind(globalConsole)]);
125
- const consolePropAttributes = {
126
- __proto__: null,
127
- writable: true,
128
- enumerable: false,
129
- configurable: true
130
- };
131
- const maxIndentation = 1e3;
132
- const privateConsole = /* @__PURE__ */ new WeakMap();
133
- const consoleSymbols = Object.getOwnPropertySymbols(globalConsole);
134
- const incLogCallCountSymbol = Symbol.for("logger.logCallCount++");
135
- const kGroupIndentationWidthSymbol = consoleSymbols.find((s) => s.label === "kGroupIndentWidth") ?? Symbol("kGroupIndentWidth");
136
- const lastWasBlankSymbol = Symbol.for("logger.lastWasBlank");
137
- class Logger {
138
- /**
139
- * Static reference to log symbols for convenience.
140
- *
141
- * @example
142
- * ```typescript
143
- * console.log(`${Logger.LOG_SYMBOLS.success} Done`)
144
- * ```
145
- */
146
- static LOG_SYMBOLS = LOG_SYMBOLS;
147
- #parent;
148
- #boundStream;
149
- #stderrLogger;
150
- #stdoutLogger;
151
- #stderrIndention = "";
152
- #stdoutIndention = "";
153
- #lastWasBlank = false;
154
- #logCallCount = 0;
155
- #constructorArgs;
156
- #options;
157
- /**
158
- * Creates a new Logger instance.
159
- *
160
- * When called without arguments, creates a logger using the default
161
- * `process.stdout` and `process.stderr` streams. Can accept custom
162
- * console constructor arguments for advanced use cases.
163
- *
164
- * @param args - Optional console constructor arguments
165
- *
166
- * @example
167
- * ```typescript
168
- * // Default logger
169
- * const logger = new Logger()
170
- *
171
- * // Custom streams (advanced)
172
- * const customLogger = new Logger({
173
- * stdout: customWritableStream,
174
- * stderr: customErrorStream
175
- * })
176
- * ```
177
- */
178
- constructor(...args) {
179
- this.#constructorArgs = args;
180
- const options = args["0"];
181
- if (typeof options === "object" && options !== null) {
182
- this.#options = { __proto__: null, ...options };
183
- } else {
184
- this.#options = { __proto__: null };
185
- }
186
- if (args.length) {
187
- privateConsole.set(this, /* @__PURE__ */ constructConsole(...args));
188
- } else {
189
- const con = /* @__PURE__ */ constructConsole({
190
- stdout: process.stdout,
191
- stderr: process.stderr
192
- });
193
- for (const { 0: key, 1: method } of boundConsoleEntries) {
194
- con[key] = method;
195
- }
196
- privateConsole.set(this, con);
197
- }
198
- }
199
- /**
200
- * Gets a logger instance bound exclusively to stderr.
201
- *
202
- * All logging operations on this instance will write to stderr only.
203
- * Indentation is tracked separately from stdout. The instance is
204
- * cached and reused on subsequent accesses.
205
- *
206
- * @returns A logger instance bound to stderr
207
- *
208
- * @example
209
- * ```typescript
210
- * // Write errors to stderr
211
- * logger.stderr.error('Configuration invalid')
212
- * logger.stderr.warn('Using fallback settings')
213
- *
214
- * // Indent only affects stderr
215
- * logger.stderr.indent()
216
- * logger.stderr.error('Nested error details')
217
- * logger.stderr.dedent()
218
- * ```
219
- */
220
- get stderr() {
221
- if (!this.#stderrLogger) {
222
- const instance = new Logger(...this.#constructorArgs);
223
- instance.#parent = this;
224
- instance.#boundStream = "stderr";
225
- instance.#options = { __proto__: null, ...this.#options };
226
- this.#stderrLogger = instance;
227
- }
228
- return this.#stderrLogger;
229
- }
230
- /**
231
- * Gets a logger instance bound exclusively to stdout.
232
- *
233
- * All logging operations on this instance will write to stdout only.
234
- * Indentation is tracked separately from stderr. The instance is
235
- * cached and reused on subsequent accesses.
236
- *
237
- * @returns A logger instance bound to stdout
238
- *
239
- * @example
240
- * ```typescript
241
- * // Write normal output to stdout
242
- * logger.stdout.log('Processing started')
243
- * logger.stdout.log('Items processed: 42')
244
- *
245
- * // Indent only affects stdout
246
- * logger.stdout.indent()
247
- * logger.stdout.log('Detailed output')
248
- * logger.stdout.dedent()
249
- * ```
250
- */
251
- get stdout() {
252
- if (!this.#stdoutLogger) {
253
- const instance = new Logger(...this.#constructorArgs);
254
- instance.#parent = this;
255
- instance.#boundStream = "stdout";
256
- instance.#options = { __proto__: null, ...this.#options };
257
- this.#stdoutLogger = instance;
258
- }
259
- return this.#stdoutLogger;
260
- }
261
- /**
262
- * Get the root logger (for accessing shared indentation state).
263
- * @private
264
- */
265
- #getRoot() {
266
- return this.#parent || this;
267
- }
268
- /**
269
- * Get indentation for a specific stream.
270
- * @private
271
- */
272
- #getIndent(stream) {
273
- const root = this.#getRoot();
274
- return stream === "stderr" ? root.#stderrIndention : root.#stdoutIndention;
275
- }
276
- /**
277
- * Set indentation for a specific stream.
278
- * @private
279
- */
280
- #setIndent(stream, value) {
281
- const root = this.#getRoot();
282
- if (stream === "stderr") {
283
- root.#stderrIndention = value;
284
- } else {
285
- root.#stdoutIndention = value;
286
- }
287
- }
288
- /**
289
- * Get the target stream for this logger instance.
290
- * @private
291
- */
292
- #getTargetStream() {
293
- return this.#boundStream || "stderr";
294
- }
295
- /**
296
- * Apply a console method with indentation.
297
- * @private
298
- */
299
- #apply(methodName, args, stream) {
300
- const con = privateConsole.get(this);
301
- const text = args.at(0);
302
- const hasText = typeof text === "string";
303
- const targetStream = stream || (methodName === "log" ? "stdout" : "stderr");
304
- const indent = this.#getIndent(targetStream);
305
- const logArgs = hasText ? [(0, import_strings.applyLinePrefix)(text, { prefix: indent }), ...args.slice(1)] : args;
306
- ReflectApply(
307
- con[methodName],
308
- con,
309
- logArgs
310
- );
311
- this[lastWasBlankSymbol](hasText && (0, import_strings.isBlankString)(logArgs[0]));
312
- this[incLogCallCountSymbol]();
313
- return this;
314
- }
315
- /**
316
- * Strip log symbols from the start of text.
317
- * @private
318
- */
319
- #stripSymbols(text) {
320
- return text.replace(/^[✖✗×⚠‼✔✓√ℹ]\uFE0F?\s*/u, "");
321
- }
322
- /**
323
- * Apply a method with a symbol prefix.
324
- * @private
325
- */
326
- #symbolApply(symbolType, args) {
327
- const con = privateConsole.get(this);
328
- let text = args.at(0);
329
- let extras;
330
- if (typeof text === "string") {
331
- text = this.#stripSymbols(text);
332
- extras = args.slice(1);
333
- } else {
334
- extras = args;
335
- text = "";
336
- }
337
- const indent = this.#getIndent("stderr");
338
- con.error(
339
- (0, import_strings.applyLinePrefix)(`${LOG_SYMBOLS[symbolType]} ${text}`, {
340
- prefix: indent
341
- }),
342
- ...extras
343
- );
344
- this.#lastWasBlank = false;
345
- this[incLogCallCountSymbol]();
346
- return this;
347
- }
348
- /**
349
- * Gets the total number of log calls made on this logger instance.
350
- *
351
- * Tracks all logging method calls including `log()`, `error()`, `warn()`,
352
- * `success()`, `fail()`, etc. Useful for testing and monitoring logging activity.
353
- *
354
- * @returns The number of times logging methods have been called
355
- *
356
- * @example
357
- * ```typescript
358
- * logger.log('Message 1')
359
- * logger.error('Message 2')
360
- * console.log(logger.logCallCount) // 2
361
- * ```
362
- */
363
- get logCallCount() {
364
- return this.#logCallCount;
365
- }
366
- /**
367
- * Increments the internal log call counter.
368
- *
369
- * This is called automatically by logging methods and should not
370
- * be called directly in normal usage.
371
- *
372
- * @returns The logger instance for chaining
373
- */
374
- [incLogCallCountSymbol]() {
375
- this.#logCallCount += 1;
376
- return this;
377
- }
378
- /**
379
- * Sets whether the last logged line was blank.
380
- *
381
- * Used internally to track blank lines and prevent duplicate spacing.
382
- * This is called automatically by logging methods.
383
- *
384
- * @param value - Whether the last line was blank
385
- * @returns The logger instance for chaining
386
- */
387
- [lastWasBlankSymbol](value) {
388
- this.#lastWasBlank = !!value;
389
- return this;
390
- }
391
- /**
392
- * Logs an assertion failure message if the value is falsy.
393
- *
394
- * Works like `console.assert()` but returns the logger for chaining.
395
- * If the value is truthy, nothing is logged. If falsy, logs an error
396
- * message with an assertion failure.
397
- *
398
- * @param value - The value to test
399
- * @param message - Optional message and additional arguments to log
400
- * @returns The logger instance for chaining
401
- *
402
- * @example
403
- * ```typescript
404
- * logger.assert(true, 'This will not log')
405
- * logger.assert(false, 'Assertion failed: value is false')
406
- * logger.assert(items.length > 0, 'No items found')
407
- * ```
408
- */
409
- assert(value, ...message) {
410
- const con = privateConsole.get(this);
411
- con.assert(value, ...message);
412
- this[lastWasBlankSymbol](false);
413
- return value ? this : this[incLogCallCountSymbol]();
414
- }
415
- /**
416
- * Clears the visible terminal screen.
417
- *
418
- * Only available on the main logger instance, not on stream-bound instances
419
- * (`.stderr` or `.stdout`). Resets the log call count and blank line tracking
420
- * if the output is a TTY.
421
- *
422
- * @returns The logger instance for chaining
423
- * @throws {Error} If called on a stream-bound logger instance
424
- *
425
- * @example
426
- * ```typescript
427
- * logger.log('Some output')
428
- * logger.clearVisible() // Screen is now clear
429
- *
430
- * // Error: Can't call on stream-bound instance
431
- * logger.stderr.clearVisible() // throws
432
- * ```
433
- */
434
- clearVisible() {
435
- if (this.#boundStream) {
436
- throw new Error(
437
- "clearVisible() is only available on the main logger instance, not on stream-bound instances"
438
- );
439
- }
440
- const con = privateConsole.get(this);
441
- con.clear();
442
- if (con._stdout.isTTY) {
443
- ;
444
- this[lastWasBlankSymbol](true);
445
- this.#logCallCount = 0;
446
- }
447
- return this;
448
- }
449
- /**
450
- * Increments and logs a counter for the given label.
451
- *
452
- * Each unique label maintains its own counter. Works like `console.count()`.
453
- *
454
- * @param label - Optional label for the counter
455
- * @default 'default'
456
- * @returns The logger instance for chaining
457
- *
458
- * @example
459
- * ```typescript
460
- * logger.count('requests') // requests: 1
461
- * logger.count('requests') // requests: 2
462
- * logger.count('errors') // errors: 1
463
- * logger.count() // default: 1
464
- * ```
465
- */
466
- count(label) {
467
- const con = privateConsole.get(this);
468
- con.count(label);
469
- this[lastWasBlankSymbol](false);
470
- return this[incLogCallCountSymbol]();
471
- }
472
- /**
473
- * Creates a task that logs start and completion messages automatically.
474
- *
475
- * Returns a task object with a `run()` method that executes the provided
476
- * function and logs "Starting task: {name}" before execution and
477
- * "Completed task: {name}" after completion.
478
- *
479
- * @param name - The name of the task
480
- * @returns A task object with a `run()` method
481
- *
482
- * @example
483
- * ```typescript
484
- * const task = logger.createTask('Database Migration')
485
- * const result = task.run(() => {
486
- * // Logs: "Starting task: Database Migration"
487
- * migrateDatabase()
488
- * return 'success'
489
- * // Logs: "Completed task: Database Migration"
490
- * })
491
- * console.log(result) // 'success'
492
- * ```
493
- */
494
- createTask(name) {
495
- return {
496
- run: (f) => {
497
- this.log(`Starting task: ${name}`);
498
- const result = f();
499
- this.log(`Completed task: ${name}`);
500
- return result;
501
- }
502
- };
503
- }
504
- /**
505
- * Decreases the indentation level by removing spaces from the prefix.
506
- *
507
- * When called on the main logger, affects both stderr and stdout indentation.
508
- * When called on a stream-bound logger (`.stderr` or `.stdout`), affects
509
- * only that stream's indentation.
510
- *
511
- * @param spaces - Number of spaces to remove from indentation
512
- * @default 2
513
- * @returns The logger instance for chaining
514
- *
515
- * @example
516
- * ```typescript
517
- * logger.indent()
518
- * logger.log('Indented')
519
- * logger.dedent()
520
- * logger.log('Back to normal')
521
- *
522
- * // Remove custom amount
523
- * logger.indent(4)
524
- * logger.log('Four spaces')
525
- * logger.dedent(4)
526
- *
527
- * // Stream-specific dedent
528
- * logger.stdout.indent()
529
- * logger.stdout.log('Indented stdout')
530
- * logger.stdout.dedent()
531
- * ```
532
- */
533
- dedent(spaces = 2) {
534
- if (this.#boundStream) {
535
- const current = this.#getIndent(this.#boundStream);
536
- this.#setIndent(this.#boundStream, current.slice(0, -spaces));
537
- } else {
538
- const stderrCurrent = this.#getIndent("stderr");
539
- const stdoutCurrent = this.#getIndent("stdout");
540
- this.#setIndent("stderr", stderrCurrent.slice(0, -spaces));
541
- this.#setIndent("stdout", stdoutCurrent.slice(0, -spaces));
542
- }
543
- return this;
544
- }
545
- /**
546
- * Displays an object's properties in a formatted way.
547
- *
548
- * Works like `console.dir()` with customizable options for depth,
549
- * colors, etc. Useful for inspecting complex objects.
550
- *
551
- * @param obj - The object to display
552
- * @param options - Optional formatting options (Node.js inspect options)
553
- * @returns The logger instance for chaining
554
- *
555
- * @example
556
- * ```typescript
557
- * const obj = { a: 1, b: { c: 2, d: { e: 3 } } }
558
- * logger.dir(obj)
559
- * logger.dir(obj, { depth: 1 }) // Limit nesting depth
560
- * logger.dir(obj, { colors: true }) // Enable colors
561
- * ```
562
- */
563
- dir(obj, options) {
564
- const con = privateConsole.get(this);
565
- con.dir(obj, options);
566
- this[lastWasBlankSymbol](false);
567
- return this[incLogCallCountSymbol]();
568
- }
569
- /**
570
- * Displays data as XML/HTML in a formatted way.
571
- *
572
- * Works like `console.dirxml()`. In Node.js, behaves the same as `dir()`.
573
- *
574
- * @param data - The data to display
575
- * @returns The logger instance for chaining
576
- *
577
- * @example
578
- * ```typescript
579
- * logger.dirxml(document.body) // In browser environments
580
- * logger.dirxml(xmlObject) // In Node.js
581
- * ```
582
- */
583
- dirxml(...data) {
584
- const con = privateConsole.get(this);
585
- con.dirxml(data);
586
- this[lastWasBlankSymbol](false);
587
- return this[incLogCallCountSymbol]();
588
- }
589
- /**
590
- * Logs an error message to stderr.
591
- *
592
- * Automatically applies current indentation. All arguments are formatted
593
- * and logged like `console.error()`.
594
- *
595
- * @param args - Message and additional arguments to log
596
- * @returns The logger instance for chaining
597
- *
598
- * @example
599
- * ```typescript
600
- * logger.error('Build failed')
601
- * logger.error('Error code:', 500)
602
- * logger.error('Details:', { message: 'Not found' })
603
- * ```
604
- */
605
- error(...args) {
606
- return this.#apply("error", args);
607
- }
608
- /**
609
- * Logs a newline to stderr only if the last line wasn't already blank.
610
- *
611
- * Prevents multiple consecutive blank lines. Useful for adding spacing
612
- * between sections without creating excessive whitespace.
613
- *
614
- * @returns The logger instance for chaining
615
- *
616
- * @example
617
- * ```typescript
618
- * logger.error('Error message')
619
- * logger.errorNewline() // Adds blank line
620
- * logger.errorNewline() // Does nothing (already blank)
621
- * logger.error('Next section')
622
- * ```
623
- */
624
- errorNewline() {
625
- return this.#lastWasBlank ? this : this.error("");
626
- }
627
- /**
628
- * Logs a failure message with a red colored fail symbol.
629
- *
630
- * Automatically prefixes the message with `LOG_SYMBOLS.fail` (red ✖).
631
- * Always outputs to stderr. If the message starts with an existing
632
- * symbol, it will be stripped and replaced.
633
- *
634
- * @param args - Message and additional arguments to log
635
- * @returns The logger instance for chaining
636
- *
637
- * @example
638
- * ```typescript
639
- * logger.fail('Build failed')
640
- * logger.fail('Test suite failed:', { passed: 5, failed: 3 })
641
- * ```
642
- */
643
- fail(...args) {
644
- return this.#symbolApply("fail", args);
645
- }
646
- /**
647
- * Starts a new indented log group.
648
- *
649
- * If a label is provided, it's logged before increasing indentation.
650
- * Groups can be nested. Each group increases indentation by the
651
- * `kGroupIndentWidth` (default 2 spaces). Call `groupEnd()` to close.
652
- *
653
- * @param label - Optional label to display before the group
654
- * @returns The logger instance for chaining
655
- *
656
- * @example
657
- * ```typescript
658
- * logger.group('Processing files:')
659
- * logger.log('file1.js')
660
- * logger.log('file2.js')
661
- * logger.groupEnd()
662
- *
663
- * // Nested groups
664
- * logger.group('Outer')
665
- * logger.log('Outer content')
666
- * logger.group('Inner')
667
- * logger.log('Inner content')
668
- * logger.groupEnd()
669
- * logger.groupEnd()
670
- * ```
671
- */
672
- group(...label) {
673
- const { length } = label;
674
- if (length) {
675
- ReflectApply(this.log, this, label);
676
- }
677
- this.indent(this[kGroupIndentationWidthSymbol]);
678
- if (length) {
679
- ;
680
- this[lastWasBlankSymbol](false);
681
- this[incLogCallCountSymbol]();
682
- }
683
- return this;
684
- }
685
- /**
686
- * Starts a new collapsed log group (alias for `group()`).
687
- *
688
- * In browser consoles, this creates a collapsed group. In Node.js,
689
- * it behaves identically to `group()`.
690
- *
691
- * @param label - Optional label to display before the group
692
- * @returns The logger instance for chaining
693
- *
694
- * @example
695
- * ```typescript
696
- * logger.groupCollapsed('Details')
697
- * logger.log('Hidden by default in browsers')
698
- * logger.groupEnd()
699
- * ```
700
- */
701
- // groupCollapsed is an alias of group.
702
- // https://nodejs.org/api/console.html#consolegroupcollapsed
703
- groupCollapsed(...label) {
704
- return ReflectApply(this.group, this, label);
705
- }
706
- /**
707
- * Ends the current log group and decreases indentation.
708
- *
709
- * Must be called once for each `group()` or `groupCollapsed()` call
710
- * to properly close the group and restore indentation.
711
- *
712
- * @returns The logger instance for chaining
713
- *
714
- * @example
715
- * ```typescript
716
- * logger.group('Group 1')
717
- * logger.log('Content')
718
- * logger.groupEnd() // Closes 'Group 1'
719
- * ```
720
- */
721
- groupEnd() {
722
- this.dedent(this[kGroupIndentationWidthSymbol]);
723
- return this;
724
- }
725
- /**
726
- * Increases the indentation level by adding spaces to the prefix.
727
- *
728
- * When called on the main logger, affects both stderr and stdout indentation.
729
- * When called on a stream-bound logger (`.stderr` or `.stdout`), affects
730
- * only that stream's indentation. Maximum indentation is 1000 spaces.
731
- *
732
- * @param spaces - Number of spaces to add to indentation
733
- * @default 2
734
- * @returns The logger instance for chaining
735
- *
736
- * @example
737
- * ```typescript
738
- * logger.log('Level 0')
739
- * logger.indent()
740
- * logger.log('Level 1')
741
- * logger.indent()
742
- * logger.log('Level 2')
743
- * logger.dedent()
744
- * logger.dedent()
745
- *
746
- * // Custom indent amount
747
- * logger.indent(4)
748
- * logger.log('Indented 4 spaces')
749
- * logger.dedent(4)
750
- *
751
- * // Stream-specific indent
752
- * logger.stdout.indent()
753
- * logger.stdout.log('Only stdout is indented')
754
- * ```
755
- */
756
- indent(spaces = 2) {
757
- const spacesToAdd = " ".repeat(Math.min(spaces, maxIndentation));
758
- if (this.#boundStream) {
759
- const current = this.#getIndent(this.#boundStream);
760
- this.#setIndent(this.#boundStream, current + spacesToAdd);
761
- } else {
762
- const stderrCurrent = this.#getIndent("stderr");
763
- const stdoutCurrent = this.#getIndent("stdout");
764
- this.#setIndent("stderr", stderrCurrent + spacesToAdd);
765
- this.#setIndent("stdout", stdoutCurrent + spacesToAdd);
766
- }
767
- return this;
768
- }
769
- /**
770
- * Logs an informational message with a blue colored info symbol.
771
- *
772
- * Automatically prefixes the message with `LOG_SYMBOLS.info` (blue ℹ).
773
- * Always outputs to stderr. If the message starts with an existing
774
- * symbol, it will be stripped and replaced.
775
- *
776
- * @param args - Message and additional arguments to log
777
- * @returns The logger instance for chaining
778
- *
779
- * @example
780
- * ```typescript
781
- * logger.info('Starting build process')
782
- * logger.info('Configuration loaded:', config)
783
- * logger.info('Using cache directory:', cacheDir)
784
- * ```
785
- */
786
- info(...args) {
787
- return this.#symbolApply("info", args);
788
- }
789
- /**
790
- * Logs a message to stdout.
791
- *
792
- * Automatically applies current indentation. All arguments are formatted
793
- * and logged like `console.log()`. This is the primary method for
794
- * standard output.
795
- *
796
- * @param args - Message and additional arguments to log
797
- * @returns The logger instance for chaining
798
- *
799
- * @example
800
- * ```typescript
801
- * logger.log('Processing complete')
802
- * logger.log('Items processed:', 42)
803
- * logger.log('Results:', { success: true, count: 10 })
804
- *
805
- * // Method chaining
806
- * logger.log('Step 1').log('Step 2').log('Step 3')
807
- * ```
808
- */
809
- log(...args) {
810
- return this.#apply("log", args);
811
- }
812
- /**
813
- * Logs a newline to stdout only if the last line wasn't already blank.
814
- *
815
- * Prevents multiple consecutive blank lines. Useful for adding spacing
816
- * between sections without creating excessive whitespace.
817
- *
818
- * @returns The logger instance for chaining
819
- *
820
- * @example
821
- * ```typescript
822
- * logger.log('Section 1')
823
- * logger.logNewline() // Adds blank line
824
- * logger.logNewline() // Does nothing (already blank)
825
- * logger.log('Section 2')
826
- * ```
827
- */
828
- logNewline() {
829
- return this.#lastWasBlank ? this : this.log("");
830
- }
831
- /**
832
- * Resets all indentation to zero.
833
- *
834
- * When called on the main logger, resets both stderr and stdout indentation.
835
- * When called on a stream-bound logger (`.stderr` or `.stdout`), resets
836
- * only that stream's indentation.
837
- *
838
- * @returns The logger instance for chaining
839
- *
840
- * @example
841
- * ```typescript
842
- * logger.indent().indent().indent()
843
- * logger.log('Very indented')
844
- * logger.resetIndent()
845
- * logger.log('Back to zero indentation')
846
- *
847
- * // Reset only stdout
848
- * logger.stdout.resetIndent()
849
- * ```
850
- */
851
- resetIndent() {
852
- if (this.#boundStream) {
853
- this.#setIndent(this.#boundStream, "");
854
- } else {
855
- this.#setIndent("stderr", "");
856
- this.#setIndent("stdout", "");
857
- }
858
- return this;
859
- }
860
- /**
861
- * Logs a main step message with a blank line before it (stateless).
862
- *
863
- * Automatically adds a blank line before the message unless the last
864
- * line was already blank. Useful for marking major steps in a process
865
- * with clear visual separation.
866
- *
867
- * @param msg - The step message to log
868
- * @param extras - Additional arguments to log
869
- * @returns The logger instance for chaining
870
- *
871
- * @example
872
- * ```typescript
873
- * logger.step('Building project')
874
- * logger.log('Compiling TypeScript...')
875
- * logger.step('Running tests')
876
- * logger.log('Running test suite...')
877
- * // Output:
878
- * // [blank line]
879
- * // Building project
880
- * // Compiling TypeScript...
881
- * // [blank line]
882
- * // Running tests
883
- * // Running test suite...
884
- * ```
885
- */
886
- step(msg, ...extras) {
887
- if (!this.#lastWasBlank) {
888
- this.log("");
889
- }
890
- return this.log(msg, ...extras);
891
- }
892
- /**
893
- * Logs an indented substep message (stateless).
894
- *
895
- * Adds a 2-space indent to the message without affecting the logger's
896
- * indentation state. Useful for showing sub-items under a main step.
897
- *
898
- * @param msg - The substep message to log
899
- * @param extras - Additional arguments to log
900
- * @returns The logger instance for chaining
901
- *
902
- * @example
903
- * ```typescript
904
- * logger.log('Installing dependencies:')
905
- * logger.substep('Installing react')
906
- * logger.substep('Installing typescript')
907
- * logger.substep('Installing eslint')
908
- * // Output:
909
- * // Installing dependencies:
910
- * // Installing react
911
- * // Installing typescript
912
- * // Installing eslint
913
- * ```
914
- */
915
- substep(msg, ...extras) {
916
- const indentedMsg = ` ${msg}`;
917
- return this.log(indentedMsg, ...extras);
918
- }
919
- /**
920
- * Logs a success message with a green colored success symbol.
921
- *
922
- * Automatically prefixes the message with `LOG_SYMBOLS.success` (green ✔).
923
- * Always outputs to stderr. If the message starts with an existing
924
- * symbol, it will be stripped and replaced.
925
- *
926
- * @param args - Message and additional arguments to log
927
- * @returns The logger instance for chaining
928
- *
929
- * @example
930
- * ```typescript
931
- * logger.success('Build completed')
932
- * logger.success('Tests passed:', { total: 42, passed: 42 })
933
- * logger.success('Deployment successful')
934
- * ```
935
- */
936
- success(...args) {
937
- return this.#symbolApply("success", args);
938
- }
939
- /**
940
- * Logs a completion message with a success symbol (alias for `success()`).
941
- *
942
- * Provides semantic clarity when marking something as "done". Does NOT
943
- * automatically clear the current line - call `clearLine()` first if
944
- * needed after using `progress()`.
945
- *
946
- * @param args - Message and additional arguments to log
947
- * @returns The logger instance for chaining
948
- *
949
- * @example
950
- * ```typescript
951
- * logger.done('Task completed')
952
- *
953
- * // After progress indicator
954
- * logger.progress('Processing...')
955
- * // ... do work ...
956
- * logger.clearLine()
957
- * logger.done('Processing complete')
958
- * ```
959
- */
960
- done(...args) {
961
- return this.#symbolApply("success", args);
962
- }
963
- /**
964
- * Displays data in a table format.
965
- *
966
- * Works like `console.table()`. Accepts arrays of objects or
967
- * objects with nested objects. Optionally specify which properties
968
- * to include in the table.
969
- *
970
- * @param tabularData - The data to display as a table
971
- * @param properties - Optional array of property names to include
972
- * @returns The logger instance for chaining
973
- *
974
- * @example
975
- * ```typescript
976
- * // Array of objects
977
- * logger.table([
978
- * { name: 'Alice', age: 30 },
979
- * { name: 'Bob', age: 25 }
980
- * ])
981
- *
982
- * // Specify properties to show
983
- * logger.table(users, ['name', 'email'])
984
- *
985
- * // Object with nested objects
986
- * logger.table({
987
- * user1: { name: 'Alice', age: 30 },
988
- * user2: { name: 'Bob', age: 25 }
989
- * })
990
- * ```
991
- */
992
- table(tabularData, properties) {
993
- const con = privateConsole.get(this);
994
- con.table(tabularData, properties);
995
- this[lastWasBlankSymbol](false);
996
- return this[incLogCallCountSymbol]();
997
- }
998
- /**
999
- * Ends a timer and logs the elapsed time.
1000
- *
1001
- * Logs the duration since `console.time()` was called with the same
1002
- * label. The timer is stopped and removed.
1003
- *
1004
- * @param label - Optional label for the timer
1005
- * @default 'default'
1006
- * @returns The logger instance for chaining
1007
- *
1008
- * @example
1009
- * ```typescript
1010
- * console.time('operation')
1011
- * // ... do work ...
1012
- * logger.timeEnd('operation')
1013
- * // Logs: "operation: 123.456ms"
1014
- *
1015
- * console.time()
1016
- * // ... do work ...
1017
- * logger.timeEnd()
1018
- * // Logs: "default: 123.456ms"
1019
- * ```
1020
- */
1021
- timeEnd(label) {
1022
- const con = privateConsole.get(this);
1023
- con.timeEnd(label);
1024
- this[lastWasBlankSymbol](false);
1025
- return this[incLogCallCountSymbol]();
1026
- }
1027
- /**
1028
- * Logs the current value of a timer without stopping it.
1029
- *
1030
- * Logs the duration since `console.time()` was called with the same
1031
- * label, but keeps the timer running. Can include additional data
1032
- * to log alongside the time.
1033
- *
1034
- * @param label - Optional label for the timer
1035
- * @param data - Additional data to log with the time
1036
- * @default 'default'
1037
- * @returns The logger instance for chaining
1038
- *
1039
- * @example
1040
- * ```typescript
1041
- * console.time('process')
1042
- * // ... partial work ...
1043
- * logger.timeLog('process', 'Checkpoint 1')
1044
- * // Logs: "process: 123.456ms Checkpoint 1"
1045
- * // ... more work ...
1046
- * logger.timeLog('process', 'Checkpoint 2')
1047
- * // Logs: "process: 234.567ms Checkpoint 2"
1048
- * console.timeEnd('process')
1049
- * ```
1050
- */
1051
- timeLog(label, ...data) {
1052
- const con = privateConsole.get(this);
1053
- con.timeLog(label, ...data);
1054
- this[lastWasBlankSymbol](false);
1055
- return this[incLogCallCountSymbol]();
1056
- }
1057
- /**
1058
- * Logs a stack trace to the console.
1059
- *
1060
- * Works like `console.trace()`. Shows the call stack leading to
1061
- * where this method was called. Useful for debugging.
1062
- *
1063
- * @param message - Optional message to display with the trace
1064
- * @param args - Additional arguments to log
1065
- * @returns The logger instance for chaining
1066
- *
1067
- * @example
1068
- * ```typescript
1069
- * function debugFunction() {
1070
- * logger.trace('Debug point reached')
1071
- * }
1072
- *
1073
- * logger.trace('Trace from here')
1074
- * logger.trace('Error context:', { userId: 123 })
1075
- * ```
1076
- */
1077
- trace(message, ...args) {
1078
- const con = privateConsole.get(this);
1079
- con.trace(message, ...args);
1080
- this[lastWasBlankSymbol](false);
1081
- return this[incLogCallCountSymbol]();
1082
- }
1083
- /**
1084
- * Logs a warning message with a yellow colored warning symbol.
1085
- *
1086
- * Automatically prefixes the message with `LOG_SYMBOLS.warn` (yellow ⚠).
1087
- * Always outputs to stderr. If the message starts with an existing
1088
- * symbol, it will be stripped and replaced.
1089
- *
1090
- * @param args - Message and additional arguments to log
1091
- * @returns The logger instance for chaining
1092
- *
1093
- * @example
1094
- * ```typescript
1095
- * logger.warn('Deprecated API used')
1096
- * logger.warn('Low memory:', { available: '100MB' })
1097
- * logger.warn('Missing optional configuration')
1098
- * ```
1099
- */
1100
- warn(...args) {
1101
- return this.#symbolApply("warn", args);
1102
- }
1103
- /**
1104
- * Writes text directly to stdout without a newline or indentation.
1105
- *
1106
- * Useful for progress indicators or custom formatting where you need
1107
- * low-level control. Does not apply any indentation or formatting.
1108
- *
1109
- * @param text - The text to write
1110
- * @returns The logger instance for chaining
1111
- *
1112
- * @example
1113
- * ```typescript
1114
- * logger.write('Processing... ')
1115
- * // ... do work ...
1116
- * logger.write('done\n')
1117
- *
1118
- * // Build a line incrementally
1119
- * logger.write('Step 1')
1120
- * logger.write('... Step 2')
1121
- * logger.write('... Step 3\n')
1122
- * ```
1123
- */
1124
- write(text) {
1125
- const con = privateConsole.get(this);
1126
- con._stdout.write(text);
1127
- this[lastWasBlankSymbol](false);
1128
- return this;
1129
- }
1130
- /**
1131
- * Shows a progress indicator that can be cleared with `clearLine()`.
1132
- *
1133
- * Displays a simple status message with a '∴' prefix. Does not include
1134
- * animation or spinner. Intended to be cleared once the operation completes.
1135
- * The output stream (stderr or stdout) depends on whether the logger is
1136
- * stream-bound.
1137
- *
1138
- * @param text - The progress message to display
1139
- * @returns The logger instance for chaining
1140
- *
1141
- * @example
1142
- * ```typescript
1143
- * logger.progress('Processing files...')
1144
- * // ... do work ...
1145
- * logger.clearLine()
1146
- * logger.success('Files processed')
1147
- *
1148
- * // Stream-specific progress
1149
- * logger.stdout.progress('Loading...')
1150
- * // ... do work ...
1151
- * logger.stdout.clearLine()
1152
- * logger.stdout.log('Done')
1153
- * ```
1154
- */
1155
- progress(text) {
1156
- const con = privateConsole.get(this);
1157
- const stream = this.#getTargetStream();
1158
- const streamObj = stream === "stderr" ? con._stderr : con._stdout;
1159
- streamObj.write(`\u2234 ${text}`);
1160
- this[lastWasBlankSymbol](false);
1161
- return this;
1162
- }
1163
- /**
1164
- * Clears the current line in the terminal.
1165
- *
1166
- * Moves the cursor to the beginning of the line and clears all content.
1167
- * Works in both TTY and non-TTY environments. Useful for clearing
1168
- * progress indicators created with `progress()`.
1169
- *
1170
- * The stream to clear (stderr or stdout) depends on whether the logger
1171
- * is stream-bound.
1172
- *
1173
- * @returns The logger instance for chaining
1174
- *
1175
- * @example
1176
- * ```typescript
1177
- * logger.progress('Loading...')
1178
- * // ... do work ...
1179
- * logger.clearLine()
1180
- * logger.success('Loaded')
1181
- *
1182
- * // Clear multiple progress updates
1183
- * for (const file of files) {
1184
- * logger.progress(`Processing ${file}`)
1185
- * processFile(file)
1186
- * logger.clearLine()
1187
- * }
1188
- * logger.success('All files processed')
1189
- * ```
1190
- */
1191
- clearLine() {
1192
- const con = privateConsole.get(this);
1193
- const stream = this.#getTargetStream();
1194
- const streamObj = stream === "stderr" ? con._stderr : con._stdout;
1195
- if (streamObj.isTTY) {
1196
- streamObj.cursorTo(0);
1197
- streamObj.clearLine(0);
1198
- } else {
1199
- streamObj.write("\r\x1B[K");
1200
- }
1201
- return this;
1202
- }
1203
- }
1204
- Object.defineProperties(
1205
- Logger.prototype,
1206
- Object.fromEntries(
1207
- (() => {
1208
- const entries = [
1209
- [
1210
- kGroupIndentationWidthSymbol,
1211
- {
1212
- ...consolePropAttributes,
1213
- value: 2
1214
- }
1215
- ],
1216
- [
1217
- Symbol.toStringTag,
1218
- {
1219
- __proto__: null,
1220
- configurable: true,
1221
- value: "logger"
1222
- }
1223
- ]
1224
- ];
1225
- for (const { 0: key, 1: value } of Object.entries(globalConsole)) {
1226
- if (!Logger.prototype[key] && typeof value === "function") {
1227
- const { [key]: func } = {
1228
- [key](...args) {
1229
- const con = privateConsole.get(this);
1230
- const result = con[key](...args);
1231
- return result === void 0 || result === con ? this : result;
1232
- }
1233
- };
1234
- entries.push([
1235
- key,
1236
- {
1237
- ...consolePropAttributes,
1238
- value: func
1239
- }
1240
- ]);
1241
- }
1242
- }
1243
- return entries;
1244
- })()
1245
- )
1246
- );
1247
- const logger = new Logger();
1248
- // Annotate the CommonJS export names for ESM import in node:
1249
- 0 && (module.exports = {
1250
- LOG_SYMBOLS,
1251
- Logger,
1252
- incLogCallCountSymbol,
1253
- lastWasBlankSymbol,
1254
- logger
1255
- });
2
+ var O=Object.create;var g=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var A=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var I=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},b=(e,t,n,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of P(t))!E.call(e,o)&&o!==n&&g(e,o,{get:()=>t[o],enumerable:!(s=j(t,o))||s.enumerable});return e};var _=(e,t,n)=>(n=e!=null?O(A(e)):{},b(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),M=e=>b(g({},"__esModule",{value:!0}),e);var H={};I(H,{LOG_SYMBOLS:()=>w,Logger:()=>h,incLogCallCountSymbol:()=>u,lastWasBlankSymbol:()=>c,logger:()=>G});module.exports=M(H);var L=_(require("./external/@socketregistry/is-unicode-supported")),S=_(require("./external/yoctocolors-cjs")),f=require("./objects"),d=require("./strings");const a=console,p=Reflect.apply,W=Reflect.construct;let y;function C(...e){return y===void 0&&(y=require("node:console").Console),W(y,e)}function B(){return S.default}const w=(()=>{const e={__proto__:null},t={__proto__:null},n=()=>{const s=(0,L.default)(),o=B();(0,f.objectAssign)(e,{fail:o.red(s?"\u2716":"\xD7"),info:o.blue(s?"\u2139":"i"),success:o.green(s?"\u2714":"\u221A"),warn:o.yellow(s?"\u26A0":"\u203C")}),(0,f.objectFreeze)(e);for(const i in t)delete t[i]};for(const s of Reflect.ownKeys(Reflect)){const o=Reflect[s];typeof o=="function"&&(t[s]=(...i)=>(n(),o(...i)))}return new Proxy(e,t)})(),K=["_stderrErrorHandler","_stdoutErrorHandler","assert","clear","count","countReset","createTask","debug","dir","dirxml","error","info","log","table","time","timeEnd","timeLog","trace","warn"].filter(e=>typeof a[e]=="function").map(e=>[e,a[e].bind(a)]),x={__proto__:null,writable:!0,enumerable:!1,configurable:!0},$=1e3,r=new WeakMap,v=Object.getOwnPropertySymbols(a),u=Symbol.for("logger.logCallCount++"),k=v.find(e=>e.label==="kGroupIndentWidth")??Symbol("kGroupIndentWidth"),c=Symbol.for("logger.lastWasBlank");class h{static LOG_SYMBOLS=w;#i;#t;#c;#u;#a="";#d="";#o=!1;#l=0;#h;#e;constructor(...t){this.#h=t;const n=t[0];if(typeof n=="object"&&n!==null?this.#e={__proto__:null,...n}:this.#e={__proto__:null},t.length)r.set(this,C(...t));else{const s=C({stdout:process.stdout,stderr:process.stderr});for(const{0:o,1:i}of K)s[o]=i;r.set(this,s)}}get stderr(){if(!this.#c){const t=new h(...this.#h);t.#i=this,t.#t="stderr",t.#e={__proto__:null,...this.#e},this.#c=t}return this.#c}get stdout(){if(!this.#u){const t=new h(...this.#h);t.#i=this,t.#t="stdout",t.#e={__proto__:null,...this.#e},this.#u=t}return this.#u}#g(){return this.#i||this}#s(t){const n=this.#g();return t==="stderr"?n.#a:n.#d}#n(t,n){const s=this.#g();t==="stderr"?s.#a=n:s.#d=n}#f(){return this.#t||"stderr"}#p(t,n,s){const o=r.get(this),i=n.at(0),l=typeof i=="string",T=s||(t==="log"?"stdout":"stderr"),R=this.#s(T),m=l?[(0,d.applyLinePrefix)(i,{prefix:R}),...n.slice(1)]:n;return p(o[t],o,m),this[c](l&&(0,d.isBlankString)(m[0])),this[u](),this}#y(t){return t.replace(/^[✖✗×⚠‼✔✓√ℹ]\uFE0F?\s*/u,"")}#r(t,n){const s=r.get(this);let o=n.at(0),i;typeof o=="string"?(o=this.#y(o),i=n.slice(1)):(i=n,o="");const l=this.#s("stderr");return s.error((0,d.applyLinePrefix)(`${w[t]} ${o}`,{prefix:l}),...i),this.#o=!1,this[u](),this}get logCallCount(){return this.#l}[u](){return this.#l+=1,this}[c](t){return this.#o=!!t,this}assert(t,...n){return r.get(this).assert(t,...n),this[c](!1),t?this:this[u]()}clearVisible(){if(this.#t)throw new Error("clearVisible() is only available on the main logger instance, not on stream-bound instances");const t=r.get(this);return t.clear(),t._stdout.isTTY&&(this[c](!0),this.#l=0),this}count(t){return r.get(this).count(t),this[c](!1),this[u]()}createTask(t){return{run:n=>{this.log(`Starting task: ${t}`);const s=n();return this.log(`Completed task: ${t}`),s}}}dedent(t=2){if(this.#t){const n=this.#s(this.#t);this.#n(this.#t,n.slice(0,-t))}else{const n=this.#s("stderr"),s=this.#s("stdout");this.#n("stderr",n.slice(0,-t)),this.#n("stdout",s.slice(0,-t))}return this}dir(t,n){return r.get(this).dir(t,n),this[c](!1),this[u]()}dirxml(...t){return r.get(this).dirxml(t),this[c](!1),this[u]()}error(...t){return this.#p("error",t)}errorNewline(){return this.#o?this:this.error("")}fail(...t){return this.#r("fail",t)}group(...t){const{length:n}=t;return n&&p(this.log,this,t),this.indent(this[k]),n&&(this[c](!1),this[u]()),this}groupCollapsed(...t){return p(this.group,this,t)}groupEnd(){return this.dedent(this[k]),this}indent(t=2){const n=" ".repeat(Math.min(t,$));if(this.#t){const s=this.#s(this.#t);this.#n(this.#t,s+n)}else{const s=this.#s("stderr"),o=this.#s("stdout");this.#n("stderr",s+n),this.#n("stdout",o+n)}return this}info(...t){return this.#r("info",t)}log(...t){return this.#p("log",t)}logNewline(){return this.#o?this:this.log("")}resetIndent(){return this.#t?this.#n(this.#t,""):(this.#n("stderr",""),this.#n("stdout","")),this}step(t,...n){return this.#o||this.log(""),this.log(t,...n)}substep(t,...n){const s=` ${t}`;return this.log(s,...n)}success(...t){return this.#r("success",t)}done(...t){return this.#r("success",t)}table(t,n){return r.get(this).table(t,n),this[c](!1),this[u]()}timeEnd(t){return r.get(this).timeEnd(t),this[c](!1),this[u]()}timeLog(t,...n){return r.get(this).timeLog(t,...n),this[c](!1),this[u]()}trace(t,...n){return r.get(this).trace(t,...n),this[c](!1),this[u]()}warn(...t){return this.#r("warn",t)}write(t){return r.get(this)._stdout.write(t),this[c](!1),this}progress(t){const n=r.get(this);return(this.#f()==="stderr"?n._stderr:n._stdout).write(`\u2234 ${t}`),this[c](!1),this}clearLine(){const t=r.get(this),s=this.#f()==="stderr"?t._stderr:t._stdout;return s.isTTY?(s.cursorTo(0),s.clearLine(0)):s.write("\r\x1B[K"),this}}Object.defineProperties(h.prototype,Object.fromEntries((()=>{const e=[[k,{...x,value:2}],[Symbol.toStringTag,{__proto__:null,configurable:!0,value:"logger"}]];for(const{0:t,1:n}of Object.entries(a))if(!h.prototype[t]&&typeof n=="function"){const{[t]:s}={[t](...o){const i=r.get(this),l=i[t](...o);return l===void 0||l===i?this:l}};e.push([t,{...x,value:s}])}return e})()));const G=new h;0&&(module.exports={LOG_SYMBOLS,Logger,incLogCallCountSymbol,lastWasBlankSymbol,logger});
1256
3
  //# sourceMappingURL=logger.js.map