@meadown/logger 1.8.10 → 1.8.11

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 (61) hide show
  1. package/dist/cjs/core/writeLog/{formatLocation.d.ts → helpers/formatLocation.d.ts} +1 -1
  2. package/dist/cjs/core/writeLog/{formatLocation.js → helpers/formatLocation.js} +3 -2
  3. package/dist/cjs/core/writeLog/helpers/index.d.ts +3 -0
  4. package/dist/cjs/core/writeLog/helpers/index.js +17 -0
  5. package/dist/cjs/core/writeLog/{renderMessage.js → helpers/renderMessage.js} +2 -2
  6. package/dist/cjs/core/writeLog/{visibleLines.js → helpers/visibleLines.js} +1 -1
  7. package/dist/cjs/core/writeLog/index.d.ts +2 -15
  8. package/dist/cjs/core/writeLog/index.js +6 -40
  9. package/dist/cjs/core/writeLog/writeLog.d.ts +14 -0
  10. package/dist/cjs/core/writeLog/writeLog.js +43 -0
  11. package/dist/cjs/index.d.ts +46 -17
  12. package/dist/cjs/index.js +17 -7
  13. package/dist/cjs/tap/createTap.js +4 -4
  14. package/dist/cjs/tap/tapAsync/helpers/buildBlock.d.ts +19 -0
  15. package/dist/cjs/tap/tapAsync/helpers/buildBlock.js +56 -0
  16. package/dist/cjs/tap/tapAsync/helpers/format.d.ts +4 -0
  17. package/dist/cjs/tap/tapAsync/helpers/format.js +30 -0
  18. package/dist/cjs/tap/tapAsync/helpers/index.d.ts +4 -0
  19. package/dist/cjs/tap/tapAsync/helpers/index.js +20 -0
  20. package/dist/cjs/tap/tapAsync/helpers/isThenable.d.ts +2 -0
  21. package/dist/cjs/tap/tapAsync/helpers/isThenable.js +15 -0
  22. package/dist/cjs/tap/tapAsync/helpers/response.d.ts +21 -0
  23. package/dist/cjs/tap/tapAsync/helpers/response.js +62 -0
  24. package/dist/cjs/tap/tapAsync/index.d.ts +2 -0
  25. package/dist/cjs/tap/tapAsync/index.js +13 -0
  26. package/dist/{tap → cjs/tap/tapAsync}/tapAsync.d.ts +1 -3
  27. package/dist/cjs/tap/tapAsync/tapAsync.js +92 -0
  28. package/dist/core/writeLog/{formatLocation.d.ts → helpers/formatLocation.d.ts} +1 -1
  29. package/dist/core/writeLog/{formatLocation.js → helpers/formatLocation.js} +3 -2
  30. package/dist/core/writeLog/helpers/index.d.ts +3 -0
  31. package/dist/core/writeLog/helpers/index.js +9 -0
  32. package/dist/core/writeLog/{renderMessage.js → helpers/renderMessage.js} +2 -2
  33. package/dist/core/writeLog/{visibleLines.js → helpers/visibleLines.js} +1 -1
  34. package/dist/core/writeLog/index.d.ts +2 -15
  35. package/dist/core/writeLog/index.js +2 -33
  36. package/dist/core/writeLog/writeLog.d.ts +14 -0
  37. package/dist/core/writeLog/writeLog.js +37 -0
  38. package/dist/index.d.ts +46 -17
  39. package/dist/index.js +17 -7
  40. package/dist/tap/createTap.js +2 -2
  41. package/dist/tap/tapAsync/helpers/buildBlock.d.ts +19 -0
  42. package/dist/tap/tapAsync/helpers/buildBlock.js +53 -0
  43. package/dist/tap/tapAsync/helpers/format.d.ts +4 -0
  44. package/dist/tap/tapAsync/helpers/format.js +26 -0
  45. package/dist/tap/tapAsync/helpers/index.d.ts +4 -0
  46. package/dist/tap/tapAsync/helpers/index.js +10 -0
  47. package/dist/tap/tapAsync/helpers/isThenable.d.ts +2 -0
  48. package/dist/tap/tapAsync/helpers/isThenable.js +12 -0
  49. package/dist/tap/tapAsync/helpers/response.d.ts +21 -0
  50. package/dist/tap/tapAsync/helpers/response.js +57 -0
  51. package/dist/tap/tapAsync/index.d.ts +2 -0
  52. package/dist/tap/tapAsync/index.js +8 -0
  53. package/dist/{cjs/tap → tap/tapAsync}/tapAsync.d.ts +1 -3
  54. package/dist/tap/tapAsync/tapAsync.js +89 -0
  55. package/package.json +7 -4
  56. package/dist/cjs/tap/tapAsync.js +0 -192
  57. package/dist/tap/tapAsync.js +0 -188
  58. /package/dist/cjs/core/writeLog/{renderMessage.d.ts → helpers/renderMessage.d.ts} +0 -0
  59. /package/dist/cjs/core/writeLog/{visibleLines.d.ts → helpers/visibleLines.d.ts} +0 -0
  60. /package/dist/core/writeLog/{renderMessage.d.ts → helpers/renderMessage.d.ts} +0 -0
  61. /package/dist/core/writeLog/{visibleLines.d.ts → helpers/visibleLines.d.ts} +0 -0
@@ -0,0 +1,89 @@
1
+ /*
2
+ * tapAsync.ts
3
+ * Created by Dewan Mobashirul
4
+ * Copyright (c) 2026 dewan-meadown
5
+ * All rights reserved
6
+ */
7
+ import { performance } from "node:perf_hooks";
8
+ import { formatDuration, formatBytes, isResponse, readBody, buildBlock, } from "./helpers/index.js";
9
+ import { isTTY } from "../../terminal/isTTY.js";
10
+ import { writeLog } from "../../core/writeLog/index.js";
11
+ /**
12
+ * The async tap. Fire-and-forget: returns `promise` immediately (unchanged),
13
+ * and logs a rich block once it resolves. For a `Response`, reads the body from
14
+ * a clone so the caller's original stays consumable. A rejection logs an error
15
+ * to stderr. `caller` MUST be resolved by `tap` (the user-facing function) so
16
+ * the logged location points at the user's file.
17
+ */
18
+ export function tapAsync(promise, label, caller) {
19
+ const useColor = isTTY("stdout");
20
+ const start = performance.now();
21
+ void promise.then((resolved) => {
22
+ const ms = Math.round(performance.now() - start);
23
+ if (isResponse(resolved)) {
24
+ let clone = null;
25
+ try {
26
+ clone = resolved.clone();
27
+ }
28
+ catch {
29
+ clone = null;
30
+ }
31
+ if (clone === null) {
32
+ writeLog({
33
+ channel: "log",
34
+ tag: "[TAP]",
35
+ args: buildBlock(label, ms, resolved, { data: undefined, size: "unknown" }, useColor),
36
+ caller,
37
+ });
38
+ return;
39
+ }
40
+ const cl = resolved.headers?.get?.("content-length");
41
+ const tooLarge = cl != null && cl !== "" && Number(cl) > 512 * 1024;
42
+ if (tooLarge) {
43
+ writeLog({
44
+ channel: "log",
45
+ tag: "[TAP]",
46
+ args: buildBlock(label, ms, resolved, {
47
+ data: "(body too large to display)",
48
+ size: formatBytes(Number(cl)),
49
+ }, useColor),
50
+ caller,
51
+ });
52
+ return;
53
+ }
54
+ void readBody(clone).then((body) => {
55
+ writeLog({
56
+ channel: "log",
57
+ tag: "[TAP]",
58
+ args: buildBlock(label, ms, resolved, body, useColor),
59
+ caller,
60
+ });
61
+ });
62
+ return;
63
+ }
64
+ // Non-Response promise — plain value with elapsed time.
65
+ const elapsed = formatDuration(ms, useColor);
66
+ writeLog({
67
+ channel: "log",
68
+ tag: "[TAP]",
69
+ args: label === undefined
70
+ ? [elapsed, resolved]
71
+ : [`${label} ${elapsed}`, resolved],
72
+ caller,
73
+ });
74
+ }, (err) => {
75
+ const ms = Math.round(performance.now() - start);
76
+ const elapsed = formatDuration(ms, useColor);
77
+ writeLog({
78
+ channel: "error",
79
+ tag: "[ERROR]",
80
+ args: [
81
+ label === undefined
82
+ ? `rejected after ${elapsed}`
83
+ : `${label} rejected after ${elapsed}`,
84
+ err,
85
+ ],
86
+ caller,
87
+ });
88
+ });
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meadown/logger",
3
- "version": "1.8.10",
3
+ "version": "1.8.11",
4
4
  "description": "A development-focused logger for Node.js and TypeScript — zero dependencies, clickable source links, and API response logging built in.",
5
5
  "keywords": [
6
6
  "logger",
@@ -53,9 +53,12 @@
53
53
  "test": "tsc && node --test \"test/**/*.test.mjs\"",
54
54
  "lint": "eslint src",
55
55
  "lint:fix": "eslint src --fix",
56
- "demo": "pnpm build && node examples/demo.mjs",
57
- "demo:calls": "pnpm build && node examples/call-sites.mjs",
58
- "demo:api": "pnpm build && node examples/api.mjs",
56
+ "demo": "pnpm build && node --experimental-strip-types examples/ts/demo.ts",
57
+ "demo:calls": "pnpm build && node --experimental-strip-types examples/ts/call-sites.ts",
58
+ "demo:api": "pnpm build && node --experimental-strip-types examples/ts/api.ts",
59
+ "demo-mjs": "pnpm build && node examples/mjs/demo.mjs",
60
+ "demo:calls-mjs": "pnpm build && node examples/mjs/call-sites.mjs",
61
+ "demo:api-mjs": "pnpm build && node examples/mjs/api.mjs",
59
62
  "prepublishOnly": "pnpm run lint && pnpm test && pnpm run build",
60
63
  "prepare": "husky",
61
64
  "release": "semantic-release"
@@ -1,192 +0,0 @@
1
- "use strict";
2
- /*
3
- * tapAsync.ts
4
- * Created by Dewan Mobashirul
5
- * Copyright (c) 2026 dewan-meadown
6
- * All rights reserved
7
- *
8
- * The async side of `tap`: times a promise and logs a rich response block when
9
- * it resolves to a `Response` — status color, slow-request highlighting, size,
10
- * and the actual body — all fire-and-forget so the caller never waits.
11
- */
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.isThenable = isThenable;
14
- exports.tapAsync = tapAsync;
15
- const node_perf_hooks_1 = require("node:perf_hooks");
16
- const node_util_1 = require("node:util");
17
- const index_js_1 = require("../core/writeLog/index.js");
18
- const color_js_1 = require("../colors/color.js");
19
- const isTTY_js_1 = require("../terminal/isTTY.js");
20
- /** Whether `value` is thenable (a promise we can await + time). */
21
- function isThenable(value) {
22
- return (typeof value === "object" &&
23
- value !== null &&
24
- typeof value.then === "function");
25
- }
26
- /** Whether the resolved value is a fetch `Response` we can read. */
27
- function isResponse(value) {
28
- const v = value;
29
- return (typeof v?.status === "number" &&
30
- typeof v.clone === "function" &&
31
- typeof v.text === "function");
32
- }
33
- /** `65ms` (green) · `1.2s` (yellow) · `5.8s` (red). */
34
- function formatDuration(ms, useColor) {
35
- const text = ms >= 1000 ? `${(ms / 1000).toFixed(2)}s` : `${ms}ms`;
36
- if (!useColor)
37
- return text;
38
- if (ms >= 2000)
39
- return (0, color_js_1.colorize)(text, "red");
40
- if (ms >= 500)
41
- return (0, color_js_1.colorize)(text, "yellow");
42
- return (0, color_js_1.colorize)(text, "green");
43
- }
44
- /** `848 B` / `1.84 KB` / `2.10 MB`. */
45
- function formatBytes(bytes) {
46
- if (bytes < 1024)
47
- return `${bytes} B`;
48
- if (bytes < 1024 * 1024)
49
- return `${(bytes / 1024).toFixed(2)} KB`;
50
- return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
51
- }
52
- /**
53
- * Status badge color:
54
- * 2xx → green · 3xx → cyan · 4xx → yellow · 5xx → red
55
- */
56
- function statusColor(status) {
57
- if (status >= 500)
58
- return "red";
59
- if (status >= 400)
60
- return "yellow";
61
- if (status >= 300)
62
- return "cyan";
63
- return "green";
64
- }
65
- function formatStatus(res, useColor) {
66
- const text = typeof res.statusText === "string" && res.statusText
67
- ? `${res.status} ${res.statusText}`
68
- : `${res.status}`;
69
- return useColor ? (0, color_js_1.colorize)(text, statusColor(res.status)) : text;
70
- }
71
- /**
72
- * Reads a (cloned) response body and returns both the parsed value and the
73
- * actual byte size. Size is calculated from the body text — not `Content-Length`,
74
- * which is absent on compressed responses — so size is always shown.
75
- */
76
- async function readBody(res) {
77
- try {
78
- const text = await res.text();
79
- const bytes = new TextEncoder().encode(text).length;
80
- const size = formatBytes(bytes);
81
- if (text === "")
82
- return { data: undefined, size };
83
- try {
84
- return { data: JSON.parse(text), size };
85
- }
86
- catch {
87
- return { data: text, size };
88
- }
89
- }
90
- catch {
91
- return { data: undefined, size: "unknown" };
92
- }
93
- }
94
- /**
95
- * Renders the nested tree block the user asked for:
96
- *
97
- * GET /users/1
98
- * │
99
- * │ response:
100
- * │ ├── time: 65ms
101
- * │ ├── status: 200 OK
102
- * │ └── size: 848 B
103
- * │
104
- * │ body:
105
- * │ ├── id: 1
106
- * │ └── name: Leanne Graham
107
- */
108
- function buildBlock(label, ms, res, body, useColor) {
109
- const paint = (s, c) => useColor ? (0, color_js_1.colorize)(s, c) : s;
110
- const pipe = paint("│", "gray");
111
- const branch = paint("├──", "gray");
112
- const last = paint("└──", "gray");
113
- const indent = `${pipe} `;
114
- const timeLine = `${indent}${branch} time: ${formatDuration(ms, useColor)}`;
115
- const statusLine = `${indent}${branch} status: ${formatStatus(res, useColor)}`;
116
- const sizeLine = `${indent}${last} size: ${body.size}`;
117
- const responseLines = [`${pipe}`, `${indent}response:`, timeLine, statusLine, sizeLine];
118
- const head = label === undefined ? "" : `${label}\n`;
119
- if (body.data === undefined) {
120
- return [`${head}${responseLines.join("\n")}`];
121
- }
122
- // Render the body using util.formatWithOptions so objects/arrays look like
123
- // console.log output — colors, proper nesting, no JSON.stringify quirkiness.
124
- const bodyText = (0, node_util_1.formatWithOptions)({ colors: useColor }, body.data);
125
- const bodyLines = bodyText.split("\n");
126
- const lastIdx = bodyLines.length - 1;
127
- const bodyBlock = bodyLines
128
- .map((line, i) => `${indent}${i === lastIdx ? last : branch} ${line}`)
129
- .join("\n");
130
- const full = [...responseLines, `${pipe}`, `${indent}body:`, bodyBlock].join("\n");
131
- return [`${head}${full}`];
132
- }
133
- /**
134
- * The async tap. Fire-and-forget: returns `promise` immediately (unchanged),
135
- * and logs a rich block once it resolves. For a `Response`, reads the body from
136
- * a clone so the caller's original stays consumable. A rejection logs an error
137
- * to stderr. `caller` MUST be resolved by `tap` (the user-facing function) so
138
- * the logged location points at the user's file.
139
- */
140
- function tapAsync(promise, label, caller) {
141
- const useColor = (0, isTTY_js_1.isTTY)("stdout");
142
- const start = node_perf_hooks_1.performance.now();
143
- void promise.then((resolved) => {
144
- const ms = Math.round(node_perf_hooks_1.performance.now() - start);
145
- if (isResponse(resolved)) {
146
- let clone = null;
147
- try {
148
- clone = resolved.clone();
149
- }
150
- catch {
151
- clone = null;
152
- }
153
- if (clone === null) {
154
- (0, index_js_1.writeLog)({
155
- channel: "log", tag: "[TAP]",
156
- args: buildBlock(label, ms, resolved, { data: undefined, size: "unknown" }, useColor),
157
- caller,
158
- });
159
- return;
160
- }
161
- const cl = resolved.headers?.get?.("content-length");
162
- const tooLarge = cl != null && cl !== "" && Number(cl) > 512 * 1024;
163
- if (tooLarge) {
164
- (0, index_js_1.writeLog)({
165
- channel: "log", tag: "[TAP]",
166
- args: buildBlock(label, ms, resolved, { data: "(body too large to display)", size: formatBytes(Number(cl)) }, useColor),
167
- caller,
168
- });
169
- return;
170
- }
171
- void readBody(clone).then((body) => {
172
- (0, index_js_1.writeLog)({ channel: "log", tag: "[TAP]", args: buildBlock(label, ms, resolved, body, useColor), caller });
173
- });
174
- return;
175
- }
176
- // Non-Response promise — plain value with elapsed time.
177
- const elapsed = formatDuration(ms, useColor);
178
- (0, index_js_1.writeLog)({
179
- channel: "log", tag: "[TAP]",
180
- args: label === undefined ? [elapsed, resolved] : [`${label} ${elapsed}`, resolved],
181
- caller,
182
- });
183
- }, (err) => {
184
- const ms = Math.round(node_perf_hooks_1.performance.now() - start);
185
- const elapsed = formatDuration(ms, useColor);
186
- (0, index_js_1.writeLog)({
187
- channel: "error", tag: "[TAP]",
188
- args: [label === undefined ? `rejected after ${elapsed}` : `${label} rejected after ${elapsed}`, err],
189
- caller,
190
- });
191
- });
192
- }
@@ -1,188 +0,0 @@
1
- /*
2
- * tapAsync.ts
3
- * Created by Dewan Mobashirul
4
- * Copyright (c) 2026 dewan-meadown
5
- * All rights reserved
6
- *
7
- * The async side of `tap`: times a promise and logs a rich response block when
8
- * it resolves to a `Response` — status color, slow-request highlighting, size,
9
- * and the actual body — all fire-and-forget so the caller never waits.
10
- */
11
- import { performance } from "node:perf_hooks";
12
- import { formatWithOptions } from "node:util";
13
- import { writeLog } from "../core/writeLog/index.js";
14
- import { colorize } from "../colors/color.js";
15
- import { isTTY } from "../terminal/isTTY.js";
16
- /** Whether `value` is thenable (a promise we can await + time). */
17
- export function isThenable(value) {
18
- return (typeof value === "object" &&
19
- value !== null &&
20
- typeof value.then === "function");
21
- }
22
- /** Whether the resolved value is a fetch `Response` we can read. */
23
- function isResponse(value) {
24
- const v = value;
25
- return (typeof v?.status === "number" &&
26
- typeof v.clone === "function" &&
27
- typeof v.text === "function");
28
- }
29
- /** `65ms` (green) · `1.2s` (yellow) · `5.8s` (red). */
30
- function formatDuration(ms, useColor) {
31
- const text = ms >= 1000 ? `${(ms / 1000).toFixed(2)}s` : `${ms}ms`;
32
- if (!useColor)
33
- return text;
34
- if (ms >= 2000)
35
- return colorize(text, "red");
36
- if (ms >= 500)
37
- return colorize(text, "yellow");
38
- return colorize(text, "green");
39
- }
40
- /** `848 B` / `1.84 KB` / `2.10 MB`. */
41
- function formatBytes(bytes) {
42
- if (bytes < 1024)
43
- return `${bytes} B`;
44
- if (bytes < 1024 * 1024)
45
- return `${(bytes / 1024).toFixed(2)} KB`;
46
- return `${(bytes / (1024 * 1024)).toFixed(2)} MB`;
47
- }
48
- /**
49
- * Status badge color:
50
- * 2xx → green · 3xx → cyan · 4xx → yellow · 5xx → red
51
- */
52
- function statusColor(status) {
53
- if (status >= 500)
54
- return "red";
55
- if (status >= 400)
56
- return "yellow";
57
- if (status >= 300)
58
- return "cyan";
59
- return "green";
60
- }
61
- function formatStatus(res, useColor) {
62
- const text = typeof res.statusText === "string" && res.statusText
63
- ? `${res.status} ${res.statusText}`
64
- : `${res.status}`;
65
- return useColor ? colorize(text, statusColor(res.status)) : text;
66
- }
67
- /**
68
- * Reads a (cloned) response body and returns both the parsed value and the
69
- * actual byte size. Size is calculated from the body text — not `Content-Length`,
70
- * which is absent on compressed responses — so size is always shown.
71
- */
72
- async function readBody(res) {
73
- try {
74
- const text = await res.text();
75
- const bytes = new TextEncoder().encode(text).length;
76
- const size = formatBytes(bytes);
77
- if (text === "")
78
- return { data: undefined, size };
79
- try {
80
- return { data: JSON.parse(text), size };
81
- }
82
- catch {
83
- return { data: text, size };
84
- }
85
- }
86
- catch {
87
- return { data: undefined, size: "unknown" };
88
- }
89
- }
90
- /**
91
- * Renders the nested tree block the user asked for:
92
- *
93
- * GET /users/1
94
- * │
95
- * │ response:
96
- * │ ├── time: 65ms
97
- * │ ├── status: 200 OK
98
- * │ └── size: 848 B
99
- * │
100
- * │ body:
101
- * │ ├── id: 1
102
- * │ └── name: Leanne Graham
103
- */
104
- function buildBlock(label, ms, res, body, useColor) {
105
- const paint = (s, c) => useColor ? colorize(s, c) : s;
106
- const pipe = paint("│", "gray");
107
- const branch = paint("├──", "gray");
108
- const last = paint("└──", "gray");
109
- const indent = `${pipe} `;
110
- const timeLine = `${indent}${branch} time: ${formatDuration(ms, useColor)}`;
111
- const statusLine = `${indent}${branch} status: ${formatStatus(res, useColor)}`;
112
- const sizeLine = `${indent}${last} size: ${body.size}`;
113
- const responseLines = [`${pipe}`, `${indent}response:`, timeLine, statusLine, sizeLine];
114
- const head = label === undefined ? "" : `${label}\n`;
115
- if (body.data === undefined) {
116
- return [`${head}${responseLines.join("\n")}`];
117
- }
118
- // Render the body using util.formatWithOptions so objects/arrays look like
119
- // console.log output — colors, proper nesting, no JSON.stringify quirkiness.
120
- const bodyText = formatWithOptions({ colors: useColor }, body.data);
121
- const bodyLines = bodyText.split("\n");
122
- const lastIdx = bodyLines.length - 1;
123
- const bodyBlock = bodyLines
124
- .map((line, i) => `${indent}${i === lastIdx ? last : branch} ${line}`)
125
- .join("\n");
126
- const full = [...responseLines, `${pipe}`, `${indent}body:`, bodyBlock].join("\n");
127
- return [`${head}${full}`];
128
- }
129
- /**
130
- * The async tap. Fire-and-forget: returns `promise` immediately (unchanged),
131
- * and logs a rich block once it resolves. For a `Response`, reads the body from
132
- * a clone so the caller's original stays consumable. A rejection logs an error
133
- * to stderr. `caller` MUST be resolved by `tap` (the user-facing function) so
134
- * the logged location points at the user's file.
135
- */
136
- export function tapAsync(promise, label, caller) {
137
- const useColor = isTTY("stdout");
138
- const start = performance.now();
139
- void promise.then((resolved) => {
140
- const ms = Math.round(performance.now() - start);
141
- if (isResponse(resolved)) {
142
- let clone = null;
143
- try {
144
- clone = resolved.clone();
145
- }
146
- catch {
147
- clone = null;
148
- }
149
- if (clone === null) {
150
- writeLog({
151
- channel: "log", tag: "[TAP]",
152
- args: buildBlock(label, ms, resolved, { data: undefined, size: "unknown" }, useColor),
153
- caller,
154
- });
155
- return;
156
- }
157
- const cl = resolved.headers?.get?.("content-length");
158
- const tooLarge = cl != null && cl !== "" && Number(cl) > 512 * 1024;
159
- if (tooLarge) {
160
- writeLog({
161
- channel: "log", tag: "[TAP]",
162
- args: buildBlock(label, ms, resolved, { data: "(body too large to display)", size: formatBytes(Number(cl)) }, useColor),
163
- caller,
164
- });
165
- return;
166
- }
167
- void readBody(clone).then((body) => {
168
- writeLog({ channel: "log", tag: "[TAP]", args: buildBlock(label, ms, resolved, body, useColor), caller });
169
- });
170
- return;
171
- }
172
- // Non-Response promise — plain value with elapsed time.
173
- const elapsed = formatDuration(ms, useColor);
174
- writeLog({
175
- channel: "log", tag: "[TAP]",
176
- args: label === undefined ? [elapsed, resolved] : [`${label} ${elapsed}`, resolved],
177
- caller,
178
- });
179
- }, (err) => {
180
- const ms = Math.round(performance.now() - start);
181
- const elapsed = formatDuration(ms, useColor);
182
- writeLog({
183
- channel: "error", tag: "[TAP]",
184
- args: [label === undefined ? `rejected after ${elapsed}` : `${label} rejected after ${elapsed}`, err],
185
- caller,
186
- });
187
- });
188
- }