visaljs 0.0.10 → 0.0.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.
- package/README.md +12 -4
- package/THIRD_PARTY_LICENSES +31 -1
- package/cli.js +962 -68
- package/node/include/js_node.h +11 -1
- package/node/prelude/_http_common.js +29 -0
- package/node/prelude/async_hooks.js +50 -11
- package/node/prelude/child_process.js +31 -4
- package/node/prelude/console.js +311 -143
- package/node/prelude/crypto.js +6 -4
- package/node/prelude/dgram.js +1169 -0
- package/node/prelude/diagnostics_channel.js +3 -1
- package/node/prelude/dns.js +250 -45
- package/node/prelude/dns_promises.js +8 -2
- package/node/prelude/fs_promises.js +9 -1
- package/node/prelude/http.js +395 -86
- package/node/prelude/https.js +13 -4
- package/node/prelude/internal/console_class.js +7 -0
- package/node/prelude/internal/console_global.js +25 -0
- package/node/prelude/internal/crypto/key_encryption.js +217 -0
- package/node/prelude/internal/crypto/keys.js +161 -26
- package/node/prelude/internal/crypto/random.js +24 -0
- package/node/prelude/internal/crypto/util.js +2 -1
- package/node/prelude/internal/crypto_x509.js +161 -0
- package/node/prelude/internal/dns_classes.js +6 -0
- package/node/prelude/internal/dns_resolver.js +371 -0
- package/node/prelude/internal/errors.js +9 -0
- package/node/prelude/internal/events_on.js +82 -37
- package/node/prelude/internal/features.js +8 -4
- package/node/prelude/internal/fs_filehandle.js +10 -4
- package/node/prelude/internal/perf_histogram.js +1 -1
- package/node/prelude/internal/process_more.js +32 -17
- package/node/prelude/internal/process_signals.js +8 -2
- package/node/prelude/internal/punycode.ts +163 -0
- package/node/prelude/internal/readline.js +648 -274
- package/node/prelude/internal/readline_editor.js +1240 -0
- package/node/prelude/internal/string_width.js +43 -0
- package/node/prelude/internal/tls/common.js +145 -33
- package/node/prelude/internal/tls/wrap.js +182 -49
- package/node/prelude/internal/tls/x509.js +4 -1
- package/node/prelude/internal/udp.js +177 -0
- package/node/prelude/net.js +13 -1
- package/node/prelude/os.js +24 -6
- package/node/prelude/perf_hooks.js +37 -2
- package/node/prelude/punycode.js +2 -130
- package/node/prelude/readline.js +113 -4
- package/node/prelude/readline_promises.js +56 -32
- package/node/prelude/tls.js +21 -4
- package/node/prelude/util.js +3 -16
- package/node/src/host_dns.c +623 -0
- package/node/src/host_http.c +12 -0
- package/node/src/host_net.c +46 -0
- package/node/src/host_os.c +1 -6
- package/node/src/host_sys.c +70 -0
- package/node/src/host_udp.c +418 -0
- package/node/third_party/c-ares/LICENSE.md +24 -0
- package/node/third_party/c-ares/config/darwin/ares_config.h +573 -0
- package/node/third_party/c-ares/config/freebsd/ares_config.h +573 -0
- package/node/third_party/c-ares/config/linux/ares_config.h +573 -0
- package/node/third_party/c-ares/config/openbsd/ares_config.h +583 -0
- package/node/third_party/c-ares/include/ares.h +1237 -0
- package/node/third_party/c-ares/include/ares_build.h +202 -0
- package/node/third_party/c-ares/include/ares_dns.h +127 -0
- package/node/third_party/c-ares/include/ares_dns_record.h +1119 -0
- package/node/third_party/c-ares/include/ares_nameser.h +510 -0
- package/node/third_party/c-ares/include/ares_version.h +47 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo2hostent.c +305 -0
- package/node/third_party/c-ares/src/lib/ares_addrinfo_localhost.c +245 -0
- package/node/third_party/c-ares/src/lib/ares_android.c +496 -0
- package/node/third_party/c-ares/src/lib/ares_android.h +38 -0
- package/node/third_party/c-ares/src/lib/ares_cancel.c +87 -0
- package/node/third_party/c-ares/src/lib/ares_close_sockets.c +137 -0
- package/node/third_party/c-ares/src/lib/ares_conn.c +511 -0
- package/node/third_party/c-ares/src/lib/ares_conn.h +202 -0
- package/node/third_party/c-ares/src/lib/ares_cookie.c +461 -0
- package/node/third_party/c-ares/src/lib/ares_data.c +168 -0
- package/node/third_party/c-ares/src/lib/ares_data.h +92 -0
- package/node/third_party/c-ares/src/lib/ares_destroy.c +159 -0
- package/node/third_party/c-ares/src/lib/ares_free_hostent.c +54 -0
- package/node/third_party/c-ares/src/lib/ares_free_string.c +33 -0
- package/node/third_party/c-ares/src/lib/ares_freeaddrinfo.c +67 -0
- package/node/third_party/c-ares/src/lib/ares_getaddrinfo.c +806 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.c +38 -0
- package/node/third_party/c-ares/src/lib/ares_getenv.h +34 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyaddr.c +229 -0
- package/node/third_party/c-ares/src/lib/ares_gethostbyname.c +341 -0
- package/node/third_party/c-ares/src/lib/ares_getnameinfo.c +437 -0
- package/node/third_party/c-ares/src/lib/ares_hosts_file.c +960 -0
- package/node/third_party/c-ares/src/lib/ares_inet_net_pton.h +31 -0
- package/node/third_party/c-ares/src/lib/ares_init.c +631 -0
- package/node/third_party/c-ares/src/lib/ares_ipv6.h +115 -0
- package/node/third_party/c-ares/src/lib/ares_library_init.c +190 -0
- package/node/third_party/c-ares/src/lib/ares_metrics.c +261 -0
- package/node/third_party/c-ares/src/lib/ares_options.c +492 -0
- package/node/third_party/c-ares/src/lib/ares_parse_into_addrinfo.c +179 -0
- package/node/third_party/c-ares/src/lib/ares_private.h +648 -0
- package/node/third_party/c-ares/src/lib/ares_process.c +1649 -0
- package/node/third_party/c-ares/src/lib/ares_qcache.c +442 -0
- package/node/third_party/c-ares/src/lib/ares_query.c +151 -0
- package/node/third_party/c-ares/src/lib/ares_search.c +623 -0
- package/node/third_party/c-ares/src/lib/ares_send.c +300 -0
- package/node/third_party/c-ares/src/lib/ares_set_socket_functions.c +590 -0
- package/node/third_party/c-ares/src/lib/ares_setup.h +224 -0
- package/node/third_party/c-ares/src/lib/ares_socket.c +427 -0
- package/node/third_party/c-ares/src/lib/ares_socket.h +163 -0
- package/node/third_party/c-ares/src/lib/ares_sortaddrinfo.c +447 -0
- package/node/third_party/c-ares/src/lib/ares_strerror.c +91 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig.c +642 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_files.c +851 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_mac.c +373 -0
- package/node/third_party/c-ares/src/lib/ares_sysconfig_win.c +673 -0
- package/node/third_party/c-ares/src/lib/ares_timeout.c +162 -0
- package/node/third_party/c-ares/src/lib/ares_update_servers.c +1376 -0
- package/node/third_party/c-ares/src/lib/ares_version.c +36 -0
- package/node/third_party/c-ares/src/lib/config-dos.h +114 -0
- package/node/third_party/c-ares/src/lib/config-win32.h +396 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_array.c +409 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.c +451 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable.h +174 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_asvp.c +224 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_dict.c +230 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_strvp.c +210 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_szvp.c +188 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpstr.c +186 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_htable_vpvp.c +194 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_llist.c +385 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.c +479 -0
- package/node/third_party/c-ares/src/lib/dsa/ares_slist.h +207 -0
- package/node/third_party/c-ares/src/lib/event/ares_event.h +191 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_configchg.c +746 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_epoll.c +192 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_kqueue.c +248 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_poll.c +140 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_select.c +159 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_thread.c +575 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_wake_pipe.c +172 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.c +981 -0
- package/node/third_party/c-ares/src/lib/event/ares_event_win32.h +161 -0
- package/node/third_party/c-ares/src/lib/include/ares_array.h +276 -0
- package/node/third_party/c-ares/src/lib/include/ares_buf.h +732 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_asvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_dict.h +123 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_strvp.h +130 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_szvp.h +118 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpstr.h +111 -0
- package/node/third_party/c-ares/src/lib/include/ares_htable_vpvp.h +128 -0
- package/node/third_party/c-ares/src/lib/include/ares_llist.h +239 -0
- package/node/third_party/c-ares/src/lib/include/ares_mem.h +41 -0
- package/node/third_party/c-ares/src/lib/include/ares_str.h +261 -0
- package/node/third_party/c-ares/src/lib/inet_net_pton.c +451 -0
- package/node/third_party/c-ares/src/lib/inet_ntop.c +219 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_create_query.c +78 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_name.c +99 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_expand_string.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_fds.c +80 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_getsock.c +85 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_a_reply.c +107 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_aaaa_reply.c +109 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_caa_reply.c +137 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_mx_reply.c +110 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_naptr_reply.c +132 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ns_reply.c +154 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_ptr_reply.c +213 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_soa_reply.c +115 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_srv_reply.c +114 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_txt_reply.c +144 -0
- package/node/third_party/c-ares/src/lib/legacy/ares_parse_uri_reply.c +113 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_mapping.c +982 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.c +309 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_multistring.h +72 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_name.c +736 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_parse.c +1360 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_private.h +273 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_record.c +1701 -0
- package/node/third_party/c-ares/src/lib/record/ares_dns_write.c +1229 -0
- package/node/third_party/c-ares/src/lib/str/ares_buf.c +1510 -0
- package/node/third_party/c-ares/src/lib/str/ares_str.c +562 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.c +90 -0
- package/node/third_party/c-ares/src/lib/str/ares_strsplit.h +51 -0
- package/node/third_party/c-ares/src/lib/thirdparty/apple/dnsinfo.h +122 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.c +640 -0
- package/node/third_party/c-ares/src/lib/util/ares_iface_ips.h +140 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.c +167 -0
- package/node/third_party/c-ares/src/lib/util/ares_math.h +58 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.c +389 -0
- package/node/third_party/c-ares/src/lib/util/ares_rand.h +36 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.c +613 -0
- package/node/third_party/c-ares/src/lib/util/ares_threads.h +60 -0
- package/node/third_party/c-ares/src/lib/util/ares_time.h +49 -0
- package/node/third_party/c-ares/src/lib/util/ares_timeval.c +95 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.c +1627 -0
- package/node/third_party/c-ares/src/lib/util/ares_uri.h +252 -0
- package/node/third_party/c-ares/src/lib/windows_port.c +29 -0
- package/package.json +1 -1
- package/prebuilt/darwin-arm64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/darwin-x64/cares-a6286c65ca9374a3.a +0 -0
- package/prebuilt/linux-arm64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-arm64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/linux-x64-musl/cares-4ba05ac8e948af8e.a +0 -0
- package/prebuilt/win32-x64/boringssl-ce573858472b7fc9.a +0 -0
- package/prebuilt/win32-x64/brotli-20d86a61f30baeb3.a +0 -0
- package/prebuilt/win32-x64/cares-49c9ec95162b912d.a +0 -0
- package/prebuilt/win32-x64/uv-b11bae65d7fced82.a +0 -0
- package/prebuilt/win32-x64/zlib-4ce2317a4c3f5fb5.a +0 -0
- package/prebuilt/win32-x64/zstd-015315ac7c784c73.a +0 -0
- package/runtime/include/js_builtins.h +5 -0
- package/runtime/include/js_crypto.h +11 -0
- package/runtime/include/js_gc.h +13 -10
- package/runtime/include/js_jobs.h +2 -0
- package/runtime/include/js_object.h +58 -0
- package/runtime/include/jscontext.h +1 -0
- package/runtime/src/crypto_internal.h +1 -0
- package/runtime/src/crypto_subtle.c +66 -7
- package/runtime/src/crypto_tls.c +265 -19
- package/runtime/src/gc.c +73 -92
- package/runtime/src/inspect.c +18 -1
- package/runtime/src/jobs.c +37 -22
- package/runtime/src/object.c +49 -2
- package/runtime/src/os.c +16 -6
- package/runtime/src/os.h +2 -0
- package/runtime/src/process.c +97 -10
package/node/prelude/console.js
CHANGED
|
@@ -1,38 +1,44 @@
|
|
|
1
|
-
// node:console
|
|
2
|
-
// streams it's given
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
import {
|
|
1
|
+
// node:console (Node's lib/internal/console/constructor.js and internal/cli_table.js): Console, a
|
|
2
|
+
// console writing to the streams it's given. The global console is the runtime's (in C), writing
|
|
3
|
+
// to the fds; a program that replaces a stdio stream's write gets Node's instead
|
|
4
|
+
// (internal/console_global.js, over this module's Console).
|
|
5
|
+
// Ported from Node.js (Copyright Node.js contributors, MIT): node/third_party/nodejs/LICENSE.
|
|
6
|
+
import { previewEntries } from "visaljs:host";
|
|
7
|
+
import { channel } from "./diagnostics_channel.js";
|
|
8
|
+
import { codeError, invalidArgType, invalidArgValue, outOfRange } from "./internal/errors.js";
|
|
9
|
+
import { getStringWidth } from "./internal/string_width.js";
|
|
10
|
+
import { formatWithOptions, inspect } from "./util.js";
|
|
11
|
+
import { isMap, isMapIterator, isSet, isSetIterator, isTypedArray } from "./util_types.js";
|
|
7
12
|
|
|
8
|
-
const kIsConsole = Symbol("kIsConsole");
|
|
9
13
|
const kSecond = 1000;
|
|
10
14
|
const kMinute = 60 * kSecond;
|
|
11
15
|
const kHour = 60 * kMinute;
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
17
|
+
const onLog = channel("console.log");
|
|
18
|
+
const onWarn = channel("console.warn");
|
|
19
|
+
const onError = channel("console.error");
|
|
20
|
+
const onInfo = channel("console.info");
|
|
21
|
+
const onDebug = channel("console.debug");
|
|
22
|
+
|
|
23
|
+
const kMaxGroupIndentation = 1000;
|
|
24
|
+
const kCounts = Symbol("counts");
|
|
25
|
+
const kGroupIndentationWidth = Symbol("kGroupIndentWidth");
|
|
26
|
+
const kFormatForStderr = Symbol("kFormatForStderr");
|
|
27
|
+
const kFormatForStdout = Symbol("kFormatForStdout");
|
|
28
|
+
const kGetInspectOptions = Symbol("kGetInspectOptions");
|
|
29
|
+
const kColorMode = Symbol("kColorMode");
|
|
30
|
+
const kIsConsole = Symbol("kIsConsole");
|
|
31
|
+
const kWriteToConsole = Symbol("kWriteToConsole");
|
|
32
|
+
export const kBindProperties = Symbol("kBindProperties");
|
|
33
|
+
const kBindStreamsEager = Symbol("kBindStreamsEager");
|
|
34
|
+
export const kBindStreamsLazy = Symbol("kBindStreamsLazy");
|
|
35
|
+
const kUseStdout = Symbol("kUseStdout");
|
|
36
|
+
const kUseStderr = Symbol("kUseStderr");
|
|
37
|
+
const kGroupIndentationString = Symbol("kGroupIndentationString");
|
|
38
|
+
|
|
39
|
+
const optionsMap = new WeakMap();
|
|
40
|
+
|
|
41
|
+
/* ---- console.table (Node's internal/cli_table.js) ------------------------------------------- */
|
|
36
42
|
|
|
37
43
|
const tableChars = {
|
|
38
44
|
middleMiddle: "─", rowMiddle: "┼", topRight: "┐", topLeft: "┌", leftMiddle: "├", topMiddle: "┬", bottomRight: "┘",
|
|
@@ -43,13 +49,14 @@ function renderRow(row, columnWidths) {
|
|
|
43
49
|
let out = tableChars.left;
|
|
44
50
|
for (let i = 0; i < row.length; i++) {
|
|
45
51
|
const cell = row[i];
|
|
46
|
-
|
|
52
|
+
const needed = columnWidths[i] - getStringWidth(cell);
|
|
53
|
+
out += cell + " ".repeat(Math.ceil(needed));
|
|
47
54
|
if (i !== row.length - 1) out += tableChars.middle;
|
|
48
55
|
}
|
|
49
56
|
return out + tableChars.right;
|
|
50
57
|
}
|
|
51
58
|
|
|
52
|
-
function
|
|
59
|
+
function cliTable(head, columns) {
|
|
53
60
|
const rows = [];
|
|
54
61
|
const columnWidths = head.map((h) => getStringWidth(h));
|
|
55
62
|
const longestColumn = Math.max(...columns.map((a) => a.length));
|
|
@@ -57,17 +64,19 @@ function renderTable(head, columns) {
|
|
|
57
64
|
const column = columns[i];
|
|
58
65
|
for (let j = 0; j < longestColumn; j++) {
|
|
59
66
|
if (rows[j] === undefined) rows[j] = [];
|
|
60
|
-
const value =
|
|
67
|
+
const value = rows[j][i] = Object.hasOwn(column, j) ? column[j] : "";
|
|
61
68
|
columnWidths[i] = Math.max(columnWidths[i] || 0, getStringWidth(value));
|
|
62
69
|
}
|
|
63
70
|
}
|
|
64
|
-
const divider = columnWidths.map((
|
|
65
|
-
let result = tableChars.topLeft + divider.join(tableChars.topMiddle) + tableChars.topRight + "\n" +
|
|
66
|
-
|
|
71
|
+
const divider = columnWidths.map((i) => tableChars.middleMiddle.repeat(i + 2));
|
|
72
|
+
let result = tableChars.topLeft + divider.join(tableChars.topMiddle) + tableChars.topRight + "\n" + renderRow(head, columnWidths) + "\n" +
|
|
73
|
+
tableChars.leftMiddle + divider.join(tableChars.rowMiddle) + tableChars.rightMiddle + "\n";
|
|
67
74
|
for (const row of rows) result += `${renderRow(row, columnWidths)}\n`;
|
|
68
75
|
return result + tableChars.bottomLeft + divider.join(tableChars.bottomMiddle) + tableChars.bottomRight;
|
|
69
76
|
}
|
|
70
77
|
|
|
78
|
+
/* ---- console.time (Node's internal/util/debuglog.js) --------------------------------------- */
|
|
79
|
+
|
|
71
80
|
/* "1.234ms", "1.500s", "1:02.345 (m:ss.mmm)", "1:02:03.456 (h:mm:ss.mmm)" */
|
|
72
81
|
function formatTime(ms) {
|
|
73
82
|
let hours = 0;
|
|
@@ -99,87 +108,231 @@ const now = () => {
|
|
|
99
108
|
return s * 1e3 + ns / 1e6;
|
|
100
109
|
};
|
|
101
110
|
|
|
111
|
+
function timeLogImpl(console, label, implementation, data) {
|
|
112
|
+
const start = console._times.get(label);
|
|
113
|
+
if (start === undefined) {
|
|
114
|
+
process.emitWarning(`No such label '${label}' for ${implementation}`);
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
console.log("%s: %s", label, formatTime(now() - start), ...(data ?? []));
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/* ---- colors (Node's internal/util/colors.js shouldColorize) --------------------------------- */
|
|
122
|
+
|
|
123
|
+
/* Node's FORCE_COLOR levels (tty's getColorDepth): '', 1, true, 2 and 3 give colors */
|
|
124
|
+
const FORCE_COLORS = new Set(["", "1", "true", "2", "3"]);
|
|
125
|
+
|
|
126
|
+
function shouldColorize(stream) {
|
|
127
|
+
if (process.env.FORCE_COLOR !== undefined) return FORCE_COLORS.has(process.env.FORCE_COLOR);
|
|
128
|
+
return Boolean(stream?.isTTY) && (typeof stream.getColorDepth === "function" ? stream.getColorDepth() > 2 : true);
|
|
129
|
+
}
|
|
130
|
+
|
|
102
131
|
/* ---- Console ---------------------------------------------------------------------------------- */
|
|
103
132
|
|
|
104
|
-
/** Console(stdout[, stderr[, ignoreErrors]]) or Console({ stdout, stderr, ignoreErrors,
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
export function Console(options, stderr, ignoreErrors) {
|
|
108
|
-
if (
|
|
109
|
-
if (!options || typeof options.write === "function") options = { stdout: options, stderr, ignoreErrors };
|
|
110
|
-
const { stdout, ignoreErrors
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if (
|
|
115
|
-
throw codeError(TypeError, "
|
|
133
|
+
/** Console(stdout[, stderr[, ignoreErrors]]) or Console({ stdout, stderr, ignoreErrors, colorMode,
|
|
134
|
+
* inspectOptions, groupIndentation }); callable without new; its methods bound, so they can be
|
|
135
|
+
* passed around */
|
|
136
|
+
export function Console(options /* or: stdout, stderr, ignoreErrors = true */) {
|
|
137
|
+
if (new.target === undefined) return Reflect.construct(Console, arguments);
|
|
138
|
+
if (!options || typeof options.write === "function") options = { stdout: options, stderr: arguments[1], ignoreErrors: arguments[2] };
|
|
139
|
+
const { stdout, stderr = stdout, ignoreErrors = true, colorMode = "auto", inspectOptions, groupIndentation } = options;
|
|
140
|
+
if (!stdout || typeof stdout.write !== "function") {
|
|
141
|
+
throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stdout");
|
|
142
|
+
}
|
|
143
|
+
if (!stderr || typeof stderr.write !== "function") {
|
|
144
|
+
throw codeError(TypeError, "ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for stderr");
|
|
116
145
|
}
|
|
117
|
-
if (
|
|
118
|
-
throw
|
|
146
|
+
if (colorMode !== "auto" && colorMode !== true && colorMode !== false) {
|
|
147
|
+
throw invalidArgValue("colorMode", "must be one of: 'auto', true, false", colorMode);
|
|
119
148
|
}
|
|
120
|
-
if (
|
|
121
|
-
throw invalidArgType("
|
|
149
|
+
if (groupIndentation !== undefined) {
|
|
150
|
+
if (typeof groupIndentation !== "number") throw invalidArgType("groupIndentation", "of type number", groupIndentation);
|
|
151
|
+
if (!Number.isInteger(groupIndentation)) throw outOfRange("groupIndentation", "an integer", groupIndentation);
|
|
152
|
+
if (groupIndentation < 0 || groupIndentation > kMaxGroupIndentation) {
|
|
153
|
+
throw outOfRange("groupIndentation", `>= 0 && <= ${kMaxGroupIndentation}`, groupIndentation);
|
|
154
|
+
}
|
|
122
155
|
}
|
|
123
|
-
if (inspectOptions
|
|
124
|
-
|
|
156
|
+
if (inspectOptions !== undefined) {
|
|
157
|
+
if (inspectOptions === null || typeof inspectOptions !== "object" || Array.isArray(inspectOptions)) {
|
|
158
|
+
throw invalidArgType("options.inspectOptions", "of type object", inspectOptions);
|
|
159
|
+
}
|
|
160
|
+
/* one set of options for both streams, or a Map from a stream to its own */
|
|
161
|
+
const inspectOptionsMap = isMap(inspectOptions) ? inspectOptions : new Map([[stdout, inspectOptions], [stderr, inspectOptions]]);
|
|
162
|
+
for (const streamOptions of inspectOptionsMap.values()) {
|
|
163
|
+
if (streamOptions.colors !== undefined && options.colorMode !== undefined) {
|
|
164
|
+
throw codeError(TypeError, "ERR_INCOMPATIBLE_OPTION_PAIR", 'Option "options.inspectOptions.color" cannot be used in combination with option "colorMode"');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
optionsMap.set(this, inspectOptionsMap);
|
|
125
168
|
}
|
|
126
|
-
|
|
127
|
-
_stdout: { value: stdout, writable: true, configurable: true },
|
|
128
|
-
_stderr: { value: err, writable: true, configurable: true },
|
|
129
|
-
_ignoreErrors: { value: Boolean(ignore), writable: true, configurable: true },
|
|
130
|
-
});
|
|
131
|
-
this[kIsConsole] = true;
|
|
132
|
-
this._colorMode = colorMode;
|
|
133
|
-
this._inspectOptions = inspectOptions;
|
|
134
|
-
this._groupIndent = "";
|
|
135
|
-
this._groupIndentation = groupIndentation;
|
|
136
|
-
this._counts = new Map();
|
|
137
|
-
this._times = new Map();
|
|
138
|
-
/* bound, as Node's: const { log } = console works */
|
|
169
|
+
/* bound, as Node's: const { log } = console works; a subclass's methods are the ones bound */
|
|
139
170
|
for (const key of Object.keys(Console.prototype)) {
|
|
140
|
-
this[key] =
|
|
171
|
+
this[key] = this[key].bind(this);
|
|
141
172
|
Object.defineProperty(this[key], "name", { value: key });
|
|
142
173
|
}
|
|
174
|
+
this[kBindStreamsEager](stdout, stderr);
|
|
175
|
+
this[kBindProperties](ignoreErrors, colorMode, groupIndentation);
|
|
143
176
|
}
|
|
144
177
|
|
|
178
|
+
const consolePropAttributes = { writable: true, enumerable: false, configurable: true };
|
|
179
|
+
|
|
145
180
|
Object.defineProperty(Console, Symbol.hasInstance, {
|
|
146
|
-
value: (instance)
|
|
181
|
+
value: function (instance) {
|
|
182
|
+
return instance?.[kIsConsole] === true || instance === globalThis.console;
|
|
183
|
+
},
|
|
147
184
|
});
|
|
148
185
|
|
|
149
|
-
const
|
|
186
|
+
const kColorInspectOptions = { colors: true };
|
|
187
|
+
const kNoColorInspectOptions = {};
|
|
150
188
|
|
|
151
|
-
|
|
152
|
-
proto._write = function (useStderr, string) {
|
|
153
|
-
const stream = useStderr ? this._stderr : this._stdout;
|
|
154
|
-
if (this._groupIndent.length !== 0) {
|
|
155
|
-
if (string.includes("\n")) string = string.replaceAll("\n", `\n${this._groupIndent}`);
|
|
156
|
-
string = this._groupIndent + string;
|
|
157
|
-
}
|
|
158
|
-
string += "\n";
|
|
159
|
-
if (!this._ignoreErrors) return stream.write(string);
|
|
160
|
-
try {
|
|
161
|
-
if (typeof stream.listenerCount === "function" && stream.listenerCount("error") === 0) stream.once("error", () => {});
|
|
162
|
-
stream.write(string, () => {});
|
|
163
|
-
} catch {
|
|
164
|
-
/* the console doesn't throw for its stream */
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
Object.defineProperty(proto, "_write", { enumerable: false });
|
|
189
|
+
function noop() {}
|
|
168
190
|
|
|
169
|
-
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
|
|
191
|
+
function createWriteErrorHandler(instance, streamSymbol) {
|
|
192
|
+
return (err) => {
|
|
193
|
+
/* the stream's 'error' listener that write() adds: kept until the error is emitted */
|
|
194
|
+
const stream = streamSymbol === kUseStdout ? instance._stdout : instance._stderr;
|
|
195
|
+
if (err !== null && !stream._writableState?.errorEmitted) {
|
|
196
|
+
if (stream.listenerCount?.("error") === 0) stream.once("error", noop);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
173
200
|
|
|
174
|
-
|
|
201
|
+
const isStackOverflowError = (e) => e instanceof RangeError && e.message === "Maximum call stack size exceeded";
|
|
202
|
+
|
|
203
|
+
Object.defineProperties(Console.prototype, {
|
|
204
|
+
[kBindStreamsEager]: {
|
|
205
|
+
...consolePropAttributes,
|
|
206
|
+
value: function (stdout, stderr) {
|
|
207
|
+
Object.defineProperties(this, {
|
|
208
|
+
_stdout: { ...consolePropAttributes, value: stdout },
|
|
209
|
+
_stderr: { ...consolePropAttributes, value: stderr },
|
|
210
|
+
});
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
/* the global console's: process.stdout and process.stderr, looked up when first written */
|
|
214
|
+
[kBindStreamsLazy]: {
|
|
215
|
+
...consolePropAttributes,
|
|
216
|
+
value: function (object) {
|
|
217
|
+
let stdout;
|
|
218
|
+
let stderr;
|
|
219
|
+
Object.defineProperties(this, {
|
|
220
|
+
_stdout: {
|
|
221
|
+
enumerable: false,
|
|
222
|
+
configurable: true,
|
|
223
|
+
get() { return stdout ||= object.stdout; },
|
|
224
|
+
set(value) { stdout = value; },
|
|
225
|
+
},
|
|
226
|
+
_stderr: {
|
|
227
|
+
enumerable: false,
|
|
228
|
+
configurable: true,
|
|
229
|
+
get() { return stderr ||= object.stderr; },
|
|
230
|
+
set(value) { stderr = value; },
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
},
|
|
234
|
+
},
|
|
235
|
+
[kBindProperties]: {
|
|
236
|
+
...consolePropAttributes,
|
|
237
|
+
value: function (ignoreErrors, colorMode, groupIndentation = 2) {
|
|
238
|
+
Object.defineProperties(this, {
|
|
239
|
+
_stdoutErrorHandler: { ...consolePropAttributes, value: createWriteErrorHandler(this, kUseStdout) },
|
|
240
|
+
_stderrErrorHandler: { ...consolePropAttributes, value: createWriteErrorHandler(this, kUseStderr) },
|
|
241
|
+
_ignoreErrors: { ...consolePropAttributes, value: Boolean(ignoreErrors) },
|
|
242
|
+
_times: { ...consolePropAttributes, value: new Map() },
|
|
243
|
+
[kCounts]: { ...consolePropAttributes, value: new Map() },
|
|
244
|
+
[kColorMode]: { ...consolePropAttributes, value: colorMode },
|
|
245
|
+
[kIsConsole]: { ...consolePropAttributes, value: true },
|
|
246
|
+
[kGroupIndentationWidth]: { ...consolePropAttributes, value: groupIndentation },
|
|
247
|
+
[kGroupIndentationString]: { ...consolePropAttributes, value: "" },
|
|
248
|
+
[Symbol.toStringTag]: { writable: false, enumerable: false, configurable: true, value: "console" },
|
|
249
|
+
});
|
|
250
|
+
},
|
|
251
|
+
},
|
|
252
|
+
[kWriteToConsole]: {
|
|
253
|
+
...consolePropAttributes,
|
|
254
|
+
value: function (streamSymbol, string) {
|
|
255
|
+
const ignoreErrors = this._ignoreErrors;
|
|
256
|
+
const groupIndent = this[kGroupIndentationString];
|
|
257
|
+
const useStdout = streamSymbol === kUseStdout;
|
|
258
|
+
const stream = useStdout ? this._stdout : this._stderr;
|
|
259
|
+
const errorHandler = useStdout ? this._stdoutErrorHandler : this._stderrErrorHandler;
|
|
260
|
+
if (groupIndent.length !== 0) {
|
|
261
|
+
if (string.includes("\n")) string = string.replace(/\n/g, `\n${groupIndent}`);
|
|
262
|
+
string = groupIndent + string;
|
|
263
|
+
}
|
|
264
|
+
string += "\n";
|
|
265
|
+
if (ignoreErrors === false) return stream.write(string);
|
|
266
|
+
/* errors ignored, but for a stack overflow (Node's), which the program should see */
|
|
267
|
+
try {
|
|
268
|
+
if (stream.listenerCount?.("error") === 0) stream.once("error", noop);
|
|
269
|
+
stream.write(string, errorHandler);
|
|
270
|
+
} catch (e) {
|
|
271
|
+
if (isStackOverflowError(e)) throw e;
|
|
272
|
+
} finally {
|
|
273
|
+
stream.removeListener?.("error", noop);
|
|
274
|
+
}
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
[kGetInspectOptions]: {
|
|
278
|
+
...consolePropAttributes,
|
|
279
|
+
value: function (stream) {
|
|
280
|
+
let color = this[kColorMode];
|
|
281
|
+
if (color === "auto") color = shouldColorize(stream);
|
|
282
|
+
const options = optionsMap.get(this)?.get(stream);
|
|
283
|
+
if (options) {
|
|
284
|
+
if (options.colors === undefined) options.colors = color;
|
|
285
|
+
return options;
|
|
286
|
+
}
|
|
287
|
+
return color ? kColorInspectOptions : kNoColorInspectOptions;
|
|
288
|
+
},
|
|
289
|
+
},
|
|
290
|
+
[kFormatForStdout]: {
|
|
291
|
+
...consolePropAttributes,
|
|
292
|
+
value: function (args) {
|
|
293
|
+
if (args.length === 1 && typeof args[0] === "string") return args[0];
|
|
294
|
+
return formatWithOptions(this[kGetInspectOptions](this._stdout), ...args);
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
[kFormatForStderr]: {
|
|
298
|
+
...consolePropAttributes,
|
|
299
|
+
value: function (args) {
|
|
300
|
+
if (args.length === 1 && typeof args[0] === "string") return args[0];
|
|
301
|
+
return formatWithOptions(this[kGetInspectOptions](this._stderr), ...args);
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
const keyKey = "Key";
|
|
307
|
+
const valuesKey = "Values";
|
|
308
|
+
const indexKey = "(index)";
|
|
309
|
+
const iterKey = "(iteration index)";
|
|
310
|
+
|
|
311
|
+
const isArray = (v) => Array.isArray(v) || isTypedArray(v) || Buffer.isBuffer(v);
|
|
312
|
+
|
|
313
|
+
const consoleMethods = {
|
|
175
314
|
log(...args) {
|
|
176
|
-
|
|
315
|
+
if (onLog.hasSubscribers) onLog.publish(args);
|
|
316
|
+
this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));
|
|
317
|
+
},
|
|
318
|
+
info(...args) {
|
|
319
|
+
if (onInfo.hasSubscribers) onInfo.publish(args);
|
|
320
|
+
this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));
|
|
321
|
+
},
|
|
322
|
+
debug(...args) {
|
|
323
|
+
if (onDebug.hasSubscribers) onDebug.publish(args);
|
|
324
|
+
this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));
|
|
177
325
|
},
|
|
178
326
|
warn(...args) {
|
|
179
|
-
|
|
327
|
+
if (onWarn.hasSubscribers) onWarn.publish(args);
|
|
328
|
+
this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args));
|
|
329
|
+
},
|
|
330
|
+
error(...args) {
|
|
331
|
+
if (onError.hasSubscribers) onError.publish(args);
|
|
332
|
+
this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args));
|
|
180
333
|
},
|
|
181
334
|
dir(object, options) {
|
|
182
|
-
this
|
|
335
|
+
this[kWriteToConsole](kUseStdout, inspect(object, { customInspect: false, ...this[kGetInspectOptions](this._stdout), ...options }));
|
|
183
336
|
},
|
|
184
337
|
time(label = "default") {
|
|
185
338
|
label = `${label}`;
|
|
@@ -191,19 +344,20 @@ Object.assign(proto, {
|
|
|
191
344
|
},
|
|
192
345
|
timeEnd(label = "default") {
|
|
193
346
|
label = `${label}`;
|
|
194
|
-
if (this
|
|
347
|
+
if (timeLogImpl(this, label, "console.timeEnd()")) this._times.delete(label);
|
|
195
348
|
},
|
|
196
349
|
timeLog(label = "default", ...data) {
|
|
197
|
-
this
|
|
350
|
+
timeLogImpl(this, `${label}`, "console.timeLog()", data);
|
|
198
351
|
},
|
|
352
|
+
/* compiled code has no stack frames: the trace is its message */
|
|
199
353
|
trace(...args) {
|
|
200
|
-
this.
|
|
354
|
+
this.error(`Trace${args.length ? `: ${this[kFormatForStderr](args)}` : ""}`);
|
|
201
355
|
},
|
|
202
356
|
assert(expression, ...args) {
|
|
203
357
|
if (!expression) {
|
|
204
|
-
if (typeof args[0] === "string") args[0] = `Assertion failed: ${args[0]}`;
|
|
358
|
+
if (args.length && typeof args[0] === "string") args[0] = `Assertion failed: ${args[0]}`;
|
|
205
359
|
else args.unshift("Assertion failed");
|
|
206
|
-
this.warn
|
|
360
|
+
Reflect.apply(this.warn, this, args);
|
|
207
361
|
}
|
|
208
362
|
},
|
|
209
363
|
/* only on a terminal: the cursor home, and the screen below it cleared */
|
|
@@ -212,53 +366,77 @@ Object.assign(proto, {
|
|
|
212
366
|
},
|
|
213
367
|
count(label = "default") {
|
|
214
368
|
label = `${label}`;
|
|
215
|
-
const
|
|
216
|
-
|
|
369
|
+
const counts = this[kCounts];
|
|
370
|
+
const count = (counts.get(label) ?? 0) + 1;
|
|
371
|
+
counts.set(label, count);
|
|
217
372
|
this.log(`${label}: ${count}`);
|
|
218
373
|
},
|
|
219
374
|
countReset(label = "default") {
|
|
220
|
-
|
|
221
|
-
if (!
|
|
375
|
+
const counts = this[kCounts];
|
|
376
|
+
if (!counts.has(label)) {
|
|
222
377
|
process.emitWarning(`Count for '${label}' does not exist`);
|
|
223
378
|
return;
|
|
224
379
|
}
|
|
225
|
-
|
|
380
|
+
counts.delete(`${label}`);
|
|
226
381
|
},
|
|
227
382
|
group(...data) {
|
|
228
|
-
if (data.length > 0) this.log
|
|
229
|
-
this
|
|
383
|
+
if (data.length > 0) Reflect.apply(this.log, this, data);
|
|
384
|
+
this[kGroupIndentationString] += " ".repeat(this[kGroupIndentationWidth]);
|
|
230
385
|
},
|
|
231
386
|
groupEnd() {
|
|
232
|
-
|
|
387
|
+
const currentIndentation = this[kGroupIndentationString];
|
|
388
|
+
this[kGroupIndentationString] = currentIndentation.slice(0, currentIndentation.length - this[kGroupIndentationWidth]);
|
|
233
389
|
},
|
|
234
390
|
table(tabularData, properties) {
|
|
235
391
|
if (properties !== undefined && !Array.isArray(properties)) throw invalidArgType("properties", "an instance of Array", properties);
|
|
236
392
|
if (tabularData === null || typeof tabularData !== "object") return this.log(tabularData);
|
|
237
|
-
const final = (k, v) => this.log(
|
|
393
|
+
const final = (k, v) => this.log(cliTable(k, v));
|
|
238
394
|
const _inspect = (v) => {
|
|
239
|
-
const depth = v !== null && typeof v === "object" && !
|
|
240
|
-
return inspect(v, { depth, maxArrayLength: 3, breakLength: Infinity, ...this.
|
|
395
|
+
const depth = v !== null && typeof v === "object" && !isArray(v) && Object.keys(v).length > 2 ? -1 : 0;
|
|
396
|
+
return inspect(v, { depth, maxArrayLength: 3, breakLength: Infinity, ...this[kGetInspectOptions](this._stdout) });
|
|
241
397
|
};
|
|
242
398
|
const getIndexArray = (length) => Array.from({ length }, (_, i) => _inspect(i));
|
|
243
|
-
|
|
399
|
+
const mapIter = isMapIterator(tabularData);
|
|
400
|
+
let isKeyValue = false;
|
|
401
|
+
let i = 0;
|
|
402
|
+
if (mapIter) {
|
|
403
|
+
[tabularData, isKeyValue] = previewEntries(tabularData, true);
|
|
404
|
+
}
|
|
405
|
+
if (isKeyValue || isMap(tabularData)) {
|
|
244
406
|
const keys = [];
|
|
245
407
|
const values = [];
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
408
|
+
let length = 0;
|
|
409
|
+
if (mapIter) {
|
|
410
|
+
for (; i < tabularData.length / 2; ++i) {
|
|
411
|
+
keys.push(_inspect(tabularData[i * 2]));
|
|
412
|
+
values.push(_inspect(tabularData[i * 2 + 1]));
|
|
413
|
+
length++;
|
|
414
|
+
}
|
|
415
|
+
} else {
|
|
416
|
+
for (const { 0: k, 1: v } of tabularData) {
|
|
417
|
+
keys.push(_inspect(k));
|
|
418
|
+
values.push(_inspect(v));
|
|
419
|
+
length++;
|
|
420
|
+
}
|
|
249
421
|
}
|
|
250
|
-
return final([
|
|
422
|
+
return final([iterKey, keyKey, valuesKey], [getIndexArray(length), keys, values]);
|
|
251
423
|
}
|
|
252
|
-
|
|
424
|
+
const setIter = isSetIterator(tabularData);
|
|
425
|
+
if (setIter) tabularData = previewEntries(tabularData);
|
|
426
|
+
if (setIter || mapIter || isSet(tabularData)) {
|
|
253
427
|
const values = [];
|
|
254
|
-
|
|
255
|
-
|
|
428
|
+
let length = 0;
|
|
429
|
+
for (const v of tabularData) {
|
|
430
|
+
values.push(_inspect(v));
|
|
431
|
+
length++;
|
|
432
|
+
}
|
|
433
|
+
return final([iterKey, valuesKey], [getIndexArray(length), values]);
|
|
256
434
|
}
|
|
257
|
-
const map =
|
|
435
|
+
const map = { __proto__: null };
|
|
258
436
|
let hasPrimitives = false;
|
|
259
437
|
const valuesKeyArray = [];
|
|
260
438
|
const indexKeyArray = Object.keys(tabularData);
|
|
261
|
-
for (
|
|
439
|
+
for (; i < indexKeyArray.length; i++) {
|
|
262
440
|
const item = tabularData[indexKeyArray[i]];
|
|
263
441
|
const primitive = item === null || (typeof item !== "function" && typeof item !== "object");
|
|
264
442
|
if (properties === undefined && primitive) {
|
|
@@ -276,14 +454,21 @@ Object.assign(proto, {
|
|
|
276
454
|
const keys = Object.keys(map);
|
|
277
455
|
const values = Object.values(map);
|
|
278
456
|
if (hasPrimitives) {
|
|
279
|
-
keys.push(
|
|
457
|
+
keys.push(valuesKey);
|
|
280
458
|
values.push(valuesKeyArray);
|
|
281
459
|
}
|
|
282
|
-
keys.unshift(
|
|
460
|
+
keys.unshift(indexKey);
|
|
283
461
|
values.unshift(indexKeyArray);
|
|
284
462
|
return final(keys, values);
|
|
285
463
|
},
|
|
286
|
-
|
|
464
|
+
};
|
|
465
|
+
|
|
466
|
+
for (const method of Reflect.ownKeys(consoleMethods)) Console.prototype[method] = consoleMethods[method];
|
|
467
|
+
Console.prototype.dirxml = Console.prototype.log;
|
|
468
|
+
Console.prototype.groupCollapsed = Console.prototype.group;
|
|
469
|
+
|
|
470
|
+
/* V8 inspector APIs the global console has: nothing to report to here */
|
|
471
|
+
const inspectorMethods = {
|
|
287
472
|
profile() {},
|
|
288
473
|
profileEnd() {},
|
|
289
474
|
timeStamp() {},
|
|
@@ -293,30 +478,13 @@ Object.assign(proto, {
|
|
|
293
478
|
createTask() {
|
|
294
479
|
return { run: (f) => f() };
|
|
295
480
|
},
|
|
296
|
-
});
|
|
297
|
-
proto.debug = proto.log;
|
|
298
|
-
proto.info = proto.log;
|
|
299
|
-
proto.dirxml = proto.log;
|
|
300
|
-
proto.error = proto.warn;
|
|
301
|
-
proto.groupCollapsed = proto.group;
|
|
302
|
-
|
|
303
|
-
proto._timeLog = function (label, name, data) {
|
|
304
|
-
const start = this._times.get(label);
|
|
305
|
-
if (start === undefined) {
|
|
306
|
-
process.emitWarning(`No such label '${label}' for ${name}`);
|
|
307
|
-
return false;
|
|
308
|
-
}
|
|
309
|
-
const ms = now() - start;
|
|
310
|
-
this.log("%s: %s", label, formatTime(ms), ...data);
|
|
311
|
-
return true;
|
|
312
481
|
};
|
|
313
|
-
Object.defineProperty(proto, "_timeLog", { enumerable: false });
|
|
314
482
|
|
|
315
483
|
/* ---- the module: the global console, with Console, and the V8 extras it lacks ------------------ */
|
|
316
484
|
|
|
317
485
|
const console = globalThis.console;
|
|
318
|
-
for (const key of
|
|
319
|
-
if (typeof console[key] !== "function") Object.defineProperty(console, key, { value:
|
|
486
|
+
for (const key of Object.keys(inspectorMethods)) {
|
|
487
|
+
if (typeof console[key] !== "function") Object.defineProperty(console, key, { value: inspectorMethods[key], writable: true, configurable: true });
|
|
320
488
|
}
|
|
321
489
|
if (console.Console === undefined) Object.defineProperty(console, "Console", { value: Console, writable: true, configurable: true });
|
|
322
490
|
|
package/node/prelude/crypto.js
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
// provided yet throws ERR_VISALJS_UNSUPPORTED when called.
|
|
4
4
|
import { cryptoTimingSafeEqual } from "visaljs:host";
|
|
5
5
|
import { codeError, notSupported } from "./internal/errors.js";
|
|
6
|
+
import { lazyClass } from "./internal/features.js";
|
|
6
7
|
import {
|
|
7
8
|
createECDH, createSign, createVerify, diffieHellman, ECDH, getCurves, privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt, Sign,
|
|
8
9
|
sign, Verify, verify,
|
|
@@ -17,10 +18,10 @@ import {
|
|
|
17
18
|
createPrivateKey, createPublicKey, createSecretKey, generateKey, generateKeyPair, generateKeyPairSync, generateKeySync, KeyObject,
|
|
18
19
|
} from "./internal/crypto/keys.js";
|
|
19
20
|
import { hkdf, hkdfSync, pbkdf2, pbkdf2Sync, scrypt, scryptSync } from "./internal/crypto/kdf.js";
|
|
20
|
-
import { randomBytes, randomFill, randomFillSync, randomInt, randomUUID } from "./internal/crypto/random.js";
|
|
21
|
+
import { randomBytes, randomFill, randomFillSync, randomInt, randomUUID, randomUUIDv7 } from "./internal/crypto/random.js";
|
|
21
22
|
import { isAnyArrayBuffer, isArrayBufferView } from "./internal/crypto/util.js";
|
|
22
23
|
|
|
23
|
-
export { createHash, createHmac, getHashes, Hash, hash, Hmac, randomBytes, randomFill, randomFillSync, randomInt, randomUUID };
|
|
24
|
+
export { createHash, createHmac, getHashes, Hash, hash, Hmac, randomBytes, randomFill, randomFillSync, randomInt, randomUUID, randomUUIDv7 };
|
|
24
25
|
export { hkdf, hkdfSync, pbkdf2, pbkdf2Sync, scrypt, scryptSync };
|
|
25
26
|
export { createPrivateKey, createPublicKey, createSecretKey, generateKey, generateKeyPair, generateKeyPairSync, generateKeySync, KeyObject };
|
|
26
27
|
export { createECDH, createSign, createVerify, diffieHellman, ECDH, getCurves, privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt };
|
|
@@ -97,7 +98,8 @@ const unsupported = (name) =>
|
|
|
97
98
|
export const Certificate = unsupported("Certificate");
|
|
98
99
|
export const Cipher = unsupported("Cipher");
|
|
99
100
|
export const Decipher = unsupported("Decipher");
|
|
100
|
-
|
|
101
|
+
|
|
102
|
+
export const X509Certificate = lazyClass("X509Certificate");
|
|
101
103
|
|
|
102
104
|
export default {
|
|
103
105
|
Certificate, Cipher, Cipheriv, Decipher, Decipheriv, DiffieHellman, DiffieHellmanGroup, ECDH, Hash, Hmac, KeyObject, Sign,
|
|
@@ -106,6 +108,6 @@ export default {
|
|
|
106
108
|
createVerify, diffieHellman, generateKey, generateKeyPair, generateKeyPairSync, generateKeySync, generatePrime,
|
|
107
109
|
generatePrimeSync, getCipherInfo, getCiphers, getCurves, getDiffieHellman, getFips, getHashes, getRandomValues, hash, hkdf,
|
|
108
110
|
hkdfSync, pbkdf2, pbkdf2Sync, privateDecrypt, privateEncrypt, publicDecrypt, publicEncrypt, randomBytes, randomFill,
|
|
109
|
-
randomFillSync, randomInt, randomUUID, scrypt, scryptSync, secureHeapUsed, setEngine, setFips, sign, subtle, timingSafeEqual,
|
|
111
|
+
randomFillSync, randomInt, randomUUID, randomUUIDv7, scrypt, scryptSync, secureHeapUsed, setEngine, setFips, sign, subtle, timingSafeEqual,
|
|
110
112
|
verify, webcrypto,
|
|
111
113
|
};
|