diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 56632fda4c67eb..f99a8abb394d14 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,9 +1,9 @@ -The `DiffieHellmanGroup` class takes a well-known modp group as its argument but -otherwise works the same as `DiffieHellman`. +The `DiffieHellmanGroup` class takes a well-known modp group as its argument. +It works the same as `DiffieHellman`, except that it does not allow changing +its keys after creation. In other words, it does not implement `setPublicKey()` +or `setPrivateKey()` methods. ```mjs const { createDiffieHellmanGroup } = await import('crypto'); @@ -1399,7 +1401,7 @@ Example (obtaining a shared secret): const { createECDH, createHash, -} = await crypto('crypto'); +} = await import('crypto'); const alice = createECDH('secp256k1'); const bob = createECDH('secp256k1'); diff --git a/doc/api/debugger.md b/doc/api/debugger.md index f17750ac116302..66a97f36ec5ee9 100644 --- a/doc/api/debugger.md +++ b/doc/api/debugger.md @@ -67,7 +67,7 @@ break in myscript.js:4 5 }, 1000); 6 console.log('hello'); debug> repl -Press Ctrl + C to leave debug repl +Press Ctrl+C to leave debug repl > x 5 > 2 + 2 diff --git a/doc/api/deprecations.md b/doc/api/deprecations.md index cc6b61206c5efe..a0140b16e9b7cc 100644 --- a/doc/api/deprecations.md +++ b/doc/api/deprecations.md @@ -831,12 +831,15 @@ The [`require.extensions`][] property is deprecated. ### DEP0040: `punycode` module -Type: Documentation-only +Type: Documentation-only (supports [`--pending-deprecation`][]) The [`punycode`][] module is deprecated. Please use a userland alternative instead. diff --git a/doc/api/errors.md b/doc/api/errors.md index e8b416949da7c8..3ff3c5c1797332 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -714,6 +714,22 @@ Used when a child process is being forked without specifying an IPC channel. Used when the main process is trying to read data from the child process's STDERR/STDOUT, and the data's length is longer than the `maxBuffer` option. + +### `ERR_CLOSED_MESSAGE_PORT` + + +There was an attempt to use a `MessagePort` instance in a closed +state, usually after `.close()` has been called. + ### `ERR_CONSOLE_WRITABLE_STREAM` @@ -2460,16 +2476,6 @@ removed: v12.5.0 The value passed to `postMessage()` contained an object that is not supported for transferring. - -### `ERR_CLOSED_MESSAGE_PORT` - - -There was an attempt to use a `MessagePort` instance in a closed -state, usually after `.close()` has been called. - ### `ERR_CRYPTO_HASH_DIGEST_NO_UTF16` +* `stream` {Http2Stream} A reference to the stream +* `headers` {HTTP/2 Headers Object} An object describing the headers +* `flags` {number} The associated numeric flags +* `rawHeaders` {Array} An array containing the raw header names followed by + their respective values. + The `'stream'` event is emitted when a `'stream'` event has been emitted by an `Http2Session` associated with the server. +See also [`Http2Session`'s `'stream'` event][]. + ```js const http2 = require('http2'); const { @@ -2003,9 +2018,17 @@ an `Http2Session` object associated with the `Http2SecureServer`. added: v8.4.0 --> +* `stream` {Http2Stream} A reference to the stream +* `headers` {HTTP/2 Headers Object} An object describing the headers +* `flags` {number} The associated numeric flags +* `rawHeaders` {Array} An array containing the raw header names followed by + their respective values. + The `'stream'` event is emitted when a `'stream'` event has been emitted by an `Http2Session` associated with the server. +See also [`Http2Session`'s `'stream'` event][]. + ```js const http2 = require('http2'); const { @@ -3838,6 +3861,7 @@ you need to implement any fall-back behaviour yourself. [`Http2ServerRequest`]: #http2_class_http2_http2serverrequest [`Http2ServerResponse`]: #http2_class_http2_http2serverresponse [`Http2Session` and Sockets]: #http2_http2session_and_sockets +[`Http2Session`'s `'stream'` event]: #http2_event_stream [`Http2Stream`]: #http2_class_http2stream [`ServerHttp2Stream`]: #http2_class_serverhttp2stream [`TypeError`]: errors.md#errors_class_typeerror diff --git a/doc/api/n-api.md b/doc/api/n-api.md index 01e365ac050183..3e31c638cece40 100644 --- a/doc/api/n-api.md +++ b/doc/api/n-api.md @@ -286,12 +286,14 @@ listed as supporting a later version. 5 6 7 + 8 v10.x v10.16.0 v10.17.0 v10.20.0 + v10.23.0 @@ -300,6 +302,7 @@ listed as supporting a later version. + v12.x @@ -307,6 +310,7 @@ listed as supporting a later version. v12.11.0 v12.17.0 v12.19.0 + v12.22.0 v13.x @@ -314,6 +318,7 @@ listed as supporting a later version. v13.0.0 + v14.x @@ -321,6 +326,23 @@ listed as supporting a later version. v14.0.0 v14.0.0 v14.12.0 + + + + v15.x + v15.0.0 + v15.0.0 + v15.0.0 + v15.0.0 + v15.12.0 + + + v16.x + v16.0.0 + v16.0.0 + v16.0.0 + v16.0.0 + v16.0.0 diff --git a/doc/api/net.md b/doc/api/net.md index 699b1ba4d573b8..5066179046c8c1 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -551,9 +551,10 @@ changes: * `options` {Object} Available options are: * `fd` {number} If specified, wrap around an existing socket with the given file descriptor, otherwise a new socket will be created. - * `allowHalfOpen` {boolean} Indicates whether half-opened TCP connections - are allowed. See [`net.createServer()`][] and the [`'end'`][] event - for details. **Default:** `false`. + * `allowHalfOpen` {boolean} If set to `false`, then the socket will + automatically end the writable side when the readable side ends. See + [`net.createServer()`][] and the [`'end'`][] event for details. **Default:** + `false`. * `readable` {boolean} Allow reads on the socket when an `fd` is passed, otherwise ignored. **Default:** `false`. * `writable` {boolean} Allow writes on the socket when an `fd` is passed, @@ -612,14 +613,14 @@ See also: the return values of `socket.write()`. added: v0.1.90 --> -Emitted when the other end of the socket sends a FIN packet, thus ending the -readable side of the socket. +Emitted when the other end of the socket signals the end of transmission, thus +ending the readable side of the socket. -By default (`allowHalfOpen` is `false`) the socket will send a FIN packet -back and destroy its file descriptor once it has written out its pending -write queue. However, if `allowHalfOpen` is set to `true`, the socket will -not automatically [`end()`][`socket.end()`] its writable side, allowing the -user to write arbitrary amounts of data. The user must call +By default (`allowHalfOpen` is `false`) the socket will send an end of +transmission packet back and destroy its file descriptor once it has written out +its pending write queue. However, if `allowHalfOpen` is set to `true`, the +socket will not automatically [`end()`][`socket.end()`] its writable side, +allowing the user to write arbitrary amounts of data. The user must call [`end()`][`socket.end()`] explicitly to close the connection (i.e. sending a FIN packet back). @@ -1006,6 +1007,12 @@ Set the encoding for the socket as a [Readable Stream][]. See ### `socket.setKeepAlive([enable][, initialDelay])` * `enable` {boolean} **Default:** `false` @@ -1020,6 +1027,12 @@ data packet received and the first keepalive probe. Setting `0` for `initialDelay` will leave the value unchanged from the default (or previous) setting. +Enabling the keep-alive functionality will set the following socket options: +* `SO_KEEPALIVE=1` +* `TCP_KEEPIDLE=initialDelay` +* `TCP_KEEPCNT=10` +* `TCP_KEEPINTVL=1` + ### `socket.setNoDelay([noDelay])` * `options` {Object} - * `allowHalfOpen` {boolean} Indicates whether half-opened TCP - connections are allowed. **Default:** `false`. + * `allowHalfOpen` {boolean} If set to `false`, then the socket will + automatically end the writable side when the readable side ends. + **Default:** `false`. * `pauseOnConnect` {boolean} Indicates whether the socket should be paused on incoming connections. **Default:** `false`. * `connectionListener` {Function} Automatically set as a listener for the @@ -1306,10 +1320,12 @@ added: v0.5.0 Creates a new TCP or [IPC][] server. If `allowHalfOpen` is set to `true`, when the other end of the socket -sends a FIN packet, the server will only send a FIN packet back when -[`socket.end()`][] is explicitly called, until then the connection is -half-closed (non-readable but still writable). See [`'end'`][] event -and [RFC 1122][half-closed] (section 4.2.2.13) for more information. +signals the end of transmission, the server will only send back the end of +transmission when [`socket.end()`][] is explicitly called. For example, in the +context of TCP, when a FIN packed is received, a FIN packed is sent +back only when [`socket.end()`][] is explicitly called. Until then the +connection is half-closed (non-readable but still writable). See [`'end'`][] +event and [RFC 1122][half-closed] (section 4.2.2.13) for more information. If `pauseOnConnect` is set to `true`, then the socket associated with each incoming connection will be paused, and no data will be read from its handle. diff --git a/doc/api/os.md b/doc/api/os.md index 6e84a322207a57..f3d3f2d65249a4 100644 --- a/doc/api/os.md +++ b/doc/api/os.md @@ -368,18 +368,6 @@ changes: Returns the system uptime in number of seconds. -The value returned can be inaccurate in some -rare virtualization cases. The issue arises when the virtualized -guest instance shares the kernel with the host system. -Due to the fact that libuv uses a syscall that -provides host's uptime instead of guest's -uptime on OpenVZ, `os.uptime()` may also provide -erroneous result. - -Please refer to and - for an exploration of -this issue, until it is resolved by libuv. - ## `os.userInfo([options])` For packages with a small number of exports or imports, we recommend @@ -428,7 +428,7 @@ The benefit of patterns over folder exports is that packages can always be imported by consumers without subpath file extensions being necessary. ### Exports sugar - @@ -455,7 +455,7 @@ can be written: ``` ### Conditional exports - * Type: {Object} diff --git a/doc/api/path.md b/doc/api/path.md index ca62e2f3628bfe..839c45da906677 100644 --- a/doc/api/path.md +++ b/doc/api/path.md @@ -203,7 +203,7 @@ A [`TypeError`][] is thrown if `path` is not a string. added: v0.11.15 --> -* `pathObject` {Object} +* `pathObject` {Object} Any JavaScript object having the following properties: * `dir` {string} * `root` {string} * `base` {string} diff --git a/doc/api/perf_hooks.md b/doc/api/perf_hooks.md index 11795b98dc71fa..80a3c46f36a281 100644 --- a/doc/api/perf_hooks.md +++ b/doc/api/perf_hooks.md @@ -261,6 +261,14 @@ If the wrapped function returns a promise, a finally handler will be attached to the promise and the duration will be reported once the finally handler is invoked. +### `performance.toJSON()` + + +An object which is JSON representation of the `performance` object. It +is similar to [`window.performance.toJSON`][] in browsers. + ## Class: `PerformanceEntry` +> Stability: 3 - Legacy. Use [`process.hrtime.bigint()`][] instead. + * `time` {integer[]} The result of a previous call to `process.hrtime()` * Returns: {integer[]} diff --git a/doc/api/querystring.md b/doc/api/querystring.md index 2b8755df413914..4b7db7afc3b948 100644 --- a/doc/api/querystring.md +++ b/doc/api/querystring.md @@ -2,7 +2,7 @@ -> Stability: 2 - Stable +> Stability: 3 - Legacy @@ -15,6 +15,9 @@ query strings. It can be accessed using: const querystring = require('querystring'); ``` +The `querystring` API is considered Legacy. While it is still maintained, +new code should use the {URLSearchParams} API instead. + ## `querystring.decode()` -* `keys` {Buffer} A 48-byte buffer containing the session ticket keys. +* `keys` {Buffer|TypedArray|DataView} A 48-byte buffer containing the session + ticket keys. Sets the session ticket keys. @@ -849,6 +850,9 @@ determine if the server certificate was signed by one of the specified CAs. If `tlsSocket.alpnProtocol` property can be checked to determine the negotiated protocol. +The `'secureConnect'` event is not emitted when a {tls.TLSSocket} is created +using the `new tls.TLSSocket()` constructor. + ### Event: `'session'` @@ -666,7 +666,7 @@ Depending on how a `Buffer` instance was created, it may or may not own its underlying `ArrayBuffer`. An `ArrayBuffer` must not be transferred unless it is known that the `Buffer` instance owns it. In particular, for `Buffer`s created from the internal -`Buffer` pool (using, for instance `Buffer.from()` or `Buffer.alloc()`), +`Buffer` pool (using, for instance `Buffer.from()` or `Buffer.allocUnsafe()`), transferring them is not possible and they are always cloned, which sends a copy of the entire `Buffer` pool. This behavior may come with unintended higher memory diff --git a/doc/changelogs/CHANGELOG_V16.md b/doc/changelogs/CHANGELOG_V16.md index a198d504fe49ed..08ce83663289d5 100644 --- a/doc/changelogs/CHANGELOG_V16.md +++ b/doc/changelogs/CHANGELOG_V16.md @@ -10,6 +10,7 @@ +16.1.0
16.0.0
@@ -33,6 +34,125 @@ * [io.js](CHANGELOG_IOJS.md) * [Archive](CHANGELOG_ARCHIVE.md) + +## 2021-05-04, Version 16.1.0 (Current), @targos + +### Notable Changes + +* [[`8a90f55a05`](https://github.com/nodejs/node/commit/8a90f55a05)] - **(SEMVER-MINOR)** **fs**: allow no-params fsPromises fileHandle read (Nitzan Uziely) [#38287](https://github.com/nodejs/node/pull/38287) + +### Commits + +* [[`28e16488cf`](https://github.com/nodejs/node/commit/28e16488cf)] - **async_hooks,doc**: replace process.stdout.fd with 1 (Darshan Sen) [#38382](https://github.com/nodejs/node/pull/38382) +* [[`cbab7ec6e5`](https://github.com/nodejs/node/commit/cbab7ec6e5)] - **benchmark**: avoid using `console.log()` (Antoine du Hamel) [#38370](https://github.com/nodejs/node/pull/38370) +* [[`ba15b20062`](https://github.com/nodejs/node/commit/ba15b20062)] - **benchmark**: use `process.hrtime.bigint()` (Antoine du Hamel) [#38369](https://github.com/nodejs/node/pull/38369) +* [[`bc6e719884`](https://github.com/nodejs/node/commit/bc6e719884)] - **bootstrap**: freeze more intrinsics (Antoine du Hamel) [#38217](https://github.com/nodejs/node/pull/38217) +* [[`29faf0f12e`](https://github.com/nodejs/node/commit/29faf0f12e)] - **build**: fix label-pr workflow (Michaël Zasso) [#38399](https://github.com/nodejs/node/pull/38399) +* [[`b5d669a6ea`](https://github.com/nodejs/node/commit/b5d669a6ea)] - **build**: label PRs with GitHub Action instead of nodejs-github-bot (Phillip Johnsen) [#38301](https://github.com/nodejs/node/pull/38301) +* [[`195f679331`](https://github.com/nodejs/node/commit/195f679331)] - **crypto**: don't crash with some selfsigned certs (Nils Dralle) [#37990](https://github.com/nodejs/node/pull/37990) +* [[`4b073b0beb`](https://github.com/nodejs/node/commit/4b073b0beb)] - **crypto**: fix generateKeyPair type checks (Nitzan Uziely) [#38364](https://github.com/nodejs/node/pull/38364) +* [[`c1d9b5b386`](https://github.com/nodejs/node/commit/c1d9b5b386)] - **crypto**: fix scrypt keylen validation (Antoine du Hamel) [#38385](https://github.com/nodejs/node/pull/38385) +* [[`7354479ad5`](https://github.com/nodejs/node/commit/7354479ad5)] - **crypto**: fix DiffieHellman `generator` validation (eladkeyshawn) [#38311](https://github.com/nodejs/node/pull/38311) +* [[`0e446d6048`](https://github.com/nodejs/node/commit/0e446d6048)] - **debugger**: enable linter on `internal/inspector/inspect_client` (Antoine du Hamel) [#38417](https://github.com/nodejs/node/pull/38417) +* [[`9f0e80aa4d`](https://github.com/nodejs/node/commit/9f0e80aa4d)] - **debugger**: refactor `internal/inspector/_inspect` to use more primordials (Antoine du Hamel) [#38406](https://github.com/nodejs/node/pull/38406) +* [[`a0c566f85a`](https://github.com/nodejs/node/commit/a0c566f85a)] - **debugger**: apply automatic lint fixes for inspect\_repl.js (Rich Trott) [#38411](https://github.com/nodejs/node/pull/38411) +* [[`b884ea739b`](https://github.com/nodejs/node/commit/b884ea739b)] - **debugger**: apply automatic lint fixes for \_inspect.js (Rich Trott) [#38411](https://github.com/nodejs/node/pull/38411) +* [[`f946aa0360`](https://github.com/nodejs/node/commit/f946aa0360)] - **debugger**: remove unused function argument (Rich Trott) [#38400](https://github.com/nodejs/node/pull/38400) +* [[`203a9689a3`](https://github.com/nodejs/node/commit/203a9689a3)] - **debugger**: align message with Node.js standard (Rich Trott) [#38400](https://github.com/nodejs/node/pull/38400) +* [[`ef617dcbb0`](https://github.com/nodejs/node/commit/ef617dcbb0)] - **debugger**: add usage example for `--port` (Rafael Gonzaga) [#38400](https://github.com/nodejs/node/pull/38400) +* [[`37b5ce2d5a`](https://github.com/nodejs/node/commit/37b5ce2d5a)] - **debugger**: fix race condition/deadlock on initialization (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`2a6203d155`](https://github.com/nodejs/node/commit/2a6203d155)] - **debugger**: replace internal use of deprecated API (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`6fff9fff97`](https://github.com/nodejs/node/commit/6fff9fff97)] - **debugger**: allow longer time to connect (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`def85daace`](https://github.com/nodejs/node/commit/def85daace)] - **debugger**: accommodate line chunking in Windows (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`07361e6b77`](https://github.com/nodejs/node/commit/07361e6b77)] - **debugger**: fix inspect restart on Windows (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`d65615e119`](https://github.com/nodejs/node/commit/d65615e119)] - **debugger**: remove unused code (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`62b03bc4f6`](https://github.com/nodejs/node/commit/62b03bc4f6)] - **debugger**: move node-inspect to internal library (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`e3b75cb5aa`](https://github.com/nodejs/node/commit/e3b75cb5aa)] - **deps**: V8: cherry-pick fd75c97d3f56 (Michaël Zasso) [#38455](https://github.com/nodejs/node/pull/38455) +* [[`aabddfbeb5`](https://github.com/nodejs/node/commit/aabddfbeb5)] - **deps**: upgrade npm to 7.11.2 (Ruy Adorno) [#38475](https://github.com/nodejs/node/pull/38475) +* [[`7b9fb92d51`](https://github.com/nodejs/node/commit/7b9fb92d51)] - **deps**: update to cjs-module-lexer@1.2.1 (Guy Bedford) [#38450](https://github.com/nodejs/node/pull/38450) +* [[`47626c52a3`](https://github.com/nodejs/node/commit/47626c52a3)] - **deps**: patch V8 to 9.0.257.24 (Michaël Zasso) [#38423](https://github.com/nodejs/node/pull/38423) +* [[`f455e08621`](https://github.com/nodejs/node/commit/f455e08621)] - **deps**: patch V8 to 9.0.257.21 (Michaël Zasso) [#38333](https://github.com/nodejs/node/pull/38333) +* [[`dd61a26d8c`](https://github.com/nodejs/node/commit/dd61a26d8c)] - **deps**: update llhttp to 6.0.1 (Fedor Indutny) [#38359](https://github.com/nodejs/node/pull/38359) +* [[`05f41cdbcc`](https://github.com/nodejs/node/commit/05f41cdbcc)] - **deps**: patch V8 to 9.0.257.19 (Michaël Zasso) [#38270](https://github.com/nodejs/node/pull/38270) +* [[`224faa0a05`](https://github.com/nodejs/node/commit/224faa0a05)] - ***Revert*** "**doc**: os.uptime() temporary bug notice" (Michaël Zasso) [#38494](https://github.com/nodejs/node/pull/38494) +* [[`3b0480dde8`](https://github.com/nodejs/node/commit/3b0480dde8)] - **doc**: document `'secureConnect'` event limitation (James M Snell) [#38447](https://github.com/nodejs/node/pull/38447) +* [[`92586046ec`](https://github.com/nodejs/node/commit/92586046ec)] - **doc**: fix outdated util inspect documentation and layout example (Ruben Bridgewater) [#37079](https://github.com/nodejs/node/pull/37079) +* [[`13de4cf1ca`](https://github.com/nodejs/node/commit/13de4cf1ca)] - **doc**: mark Node.js 10 as End-of-Life (Richard Lau) [#38482](https://github.com/nodejs/node/pull/38482) +* [[`3cbfde1f25`](https://github.com/nodejs/node/commit/3cbfde1f25)] - **doc**: mark querystring api as legacy (James M Snell) [#38436](https://github.com/nodejs/node/pull/38436) +* [[`a5929c2487`](https://github.com/nodejs/node/commit/a5929c2487)] - **doc**: update node-api support matrix (Michael Dawson) [#38424](https://github.com/nodejs/node/pull/38424) +* [[`f08650cefe`](https://github.com/nodejs/node/commit/f08650cefe)] - **doc**: add arguments for stream event of Http2Server and Http2SecureServer (Qingyu Deng) [#37892](https://github.com/nodejs/node/pull/37892) +* [[`2d59273bed`](https://github.com/nodejs/node/commit/2d59273bed)] - **doc**: indicate that abort tests do not generate core files (Rich Trott) [#38422](https://github.com/nodejs/node/pull/38422) +* [[`f1970127ee`](https://github.com/nodejs/node/commit/f1970127ee)] - **doc**: add try/catch in http2 respondWithFile example (Matteo Collina) [#38410](https://github.com/nodejs/node/pull/38410) +* [[`f6f1317f43`](https://github.com/nodejs/node/commit/f6f1317f43)] - **doc**: note the system requirements for V8 tests (DeeDeeG) [#38319](https://github.com/nodejs/node/pull/38319) +* [[`4b19beaf3c`](https://github.com/nodejs/node/commit/4b19beaf3c)] - **doc**: minor clarification to pathObject (James M Snell) [#38437](https://github.com/nodejs/node/pull/38437) +* [[`1eae4af6f7`](https://github.com/nodejs/node/commit/1eae4af6f7)] - **doc**: clarify that fs.Dir async iterator closes automatically (James M Snell) [#38438](https://github.com/nodejs/node/pull/38438) +* [[`14afb39259`](https://github.com/nodejs/node/commit/14afb39259)] - **doc**: document new TCP\_KEEPCNT and TCP\_KEEPINTVL socket option defaults (Arnold Zokas) [#38313](https://github.com/nodejs/node/pull/38313) +* [[`ed5ef21690`](https://github.com/nodejs/node/commit/ed5ef21690)] - **doc**: do not mention TCP in the allowHalfOpen option description (Luigi Pinca) [#38360](https://github.com/nodejs/node/pull/38360) +* [[`042985c139`](https://github.com/nodejs/node/commit/042985c139)] - **doc**: update message to match actual output (Rich Trott) [#35271](https://github.com/nodejs/node/pull/35271) +* [[`bcc5e2af76`](https://github.com/nodejs/node/commit/bcc5e2af76)] - **doc**: request default snap track be updated for LTS (Rod Vagg) [#37708](https://github.com/nodejs/node/pull/37708) +* [[`dfd4c7ba93`](https://github.com/nodejs/node/commit/dfd4c7ba93)] - **doc**: mark `process.hrtime()` as legacy (Antoine du Hamel) [#38371](https://github.com/nodejs/node/pull/38371) +* [[`67cd88da00`](https://github.com/nodejs/node/commit/67cd88da00)] - **doc**: fix typo in worker\_threads.md (takayama) [#38368](https://github.com/nodejs/node/pull/38368) +* [[`a9314cda7d`](https://github.com/nodejs/node/commit/a9314cda7d)] - **doc**: fix version history for `"exports"` patterns (Antoine du Hamel) [#38355](https://github.com/nodejs/node/pull/38355) +* [[`76885cd578`](https://github.com/nodejs/node/commit/76885cd578)] - **doc**: fix `package.json` `"imports"` field history (Antoine du Hamel) [#38356](https://github.com/nodejs/node/pull/38356) +* [[`0e88ae7ec1`](https://github.com/nodejs/node/commit/0e88ae7ec1)] - **doc**: fix typo in buffer.md (divlo) [#38323](https://github.com/nodejs/node/pull/38323) +* [[`1cccc2da51`](https://github.com/nodejs/node/commit/1cccc2da51)] - **doc**: fix YAML comment opening tags (Jayden Seric) [#38324](https://github.com/nodejs/node/pull/38324) +* [[`25052dc987`](https://github.com/nodejs/node/commit/25052dc987)] - **doc**: add nodejs-sec email template (Daniel Bevenius) [#38290](https://github.com/nodejs/node/pull/38290) +* [[`3858029262`](https://github.com/nodejs/node/commit/3858029262)] - **doc**: update TSC members list with three new members (Rich Trott) [#38352](https://github.com/nodejs/node/pull/38352) +* [[`2eef587674`](https://github.com/nodejs/node/commit/2eef587674)] - **doc**: use `foo.prototype.bar` notation in buffer.md (Voltrex) [#38032](https://github.com/nodejs/node/pull/38032) +* [[`8a90f55a05`](https://github.com/nodejs/node/commit/8a90f55a05)] - **(SEMVER-MINOR)** **fs**: allow no-params fsPromises fileHandle read (Nitzan Uziely) [#38287](https://github.com/nodejs/node/pull/38287) +* [[`a696f1080c`](https://github.com/nodejs/node/commit/a696f1080c)] - **inspector**: remove redundant method for connection check (Yash Ladha) [#37986](https://github.com/nodejs/node/pull/37986) +* [[`fcac2e0363`](https://github.com/nodejs/node/commit/fcac2e0363)] - **lib**: harden lint checks for globals (Antoine du Hamel) [#38419](https://github.com/nodejs/node/pull/38419) +* [[`277122e1fa`](https://github.com/nodejs/node/commit/277122e1fa)] - **lib**: fix and improve os typings (Akhil Marsonya) [#38316](https://github.com/nodejs/node/pull/38316) +* [[`f2c0258b4c`](https://github.com/nodejs/node/commit/f2c0258b4c)] - **lib**: add support for JSTransferable as a mixin (James M Snell) [#38383](https://github.com/nodejs/node/pull/38383) +* [[`96f54d3446`](https://github.com/nodejs/node/commit/96f54d3446)] - **meta**: post comment when pr labeled fast-track (James M Snell) [#38446](https://github.com/nodejs/node/pull/38446) +* [[`4711f57cf2`](https://github.com/nodejs/node/commit/4711f57cf2)] - **perf_hooks**: add toJSON to performance class (Yash Ladha) [#37771](https://github.com/nodejs/node/pull/37771) +* [[`013fa59602`](https://github.com/nodejs/node/commit/013fa59602)] - **perf_hooks**: fix PerformanceObserver 'gc' crash (James M Snell) [#38414](https://github.com/nodejs/node/pull/38414) +* [[`10147f191e`](https://github.com/nodejs/node/commit/10147f191e)] - **readline**: move utilities to internal modules (Antoine du Hamel) [#38466](https://github.com/nodejs/node/pull/38466) +* [[`620ee42ab4`](https://github.com/nodejs/node/commit/620ee42ab4)] - **repl**: document top level await limitation with const/let (James M Snell) [#38449](https://github.com/nodejs/node/pull/38449) +* [[`aa24681dcb`](https://github.com/nodejs/node/commit/aa24681dcb)] - **repl**: display prompt once after error callback (Anna Henningsen) [#38314](https://github.com/nodejs/node/pull/38314) +* [[`9c06103a4f`](https://github.com/nodejs/node/commit/9c06103a4f)] - **src**: fix validation of negative offset to avoid abort (James M Snell) [#38421](https://github.com/nodejs/node/pull/38421) +* [[`7d8cc2abf1`](https://github.com/nodejs/node/commit/7d8cc2abf1)] - **src**: use %progbits instead of @progbits (Stephen Gallagher) [#38312](https://github.com/nodejs/node/pull/38312) +* [[`17856f1f88`](https://github.com/nodejs/node/commit/17856f1f88)] - **src**: print arbitrary javascript exception value in node report (legendecas) [#38009](https://github.com/nodejs/node/pull/38009) +* [[`769a210d55`](https://github.com/nodejs/node/commit/769a210d55)] - **src**: refactor to use THROW\_\* argument based snprintf (Filip Skokan) [#38357](https://github.com/nodejs/node/pull/38357) +* [[`e3538bbcd2`](https://github.com/nodejs/node/commit/e3538bbcd2)] - **src**: fix abort in pbkdf2 (Tobias Nießen) [#38354](https://github.com/nodejs/node/pull/38354) +* [[`09cacd7418`](https://github.com/nodejs/node/commit/09cacd7418)] - **src**: fix setting Converter sub char length (James M Snell) [#38331](https://github.com/nodejs/node/pull/38331) +* [[`3649ec5276`](https://github.com/nodejs/node/commit/3649ec5276)] - **src**: avoid deferred gc/cleanup for Buffer.from (James M Snell) [#38337](https://github.com/nodejs/node/pull/38337) +* [[`f2ffaba78c`](https://github.com/nodejs/node/commit/f2ffaba78c)] - **stream**: the position of \_read() is wrong (helloyou2012) [#38292](https://github.com/nodejs/node/pull/38292) +* [[`7ce39b8608`](https://github.com/nodejs/node/commit/7ce39b8608)] - **test**: fix `common.mustCall` `length` and `name` properties (Antoine du Hamel) [#38464](https://github.com/nodejs/node/pull/38464) +* [[`d1cd1178e7`](https://github.com/nodejs/node/commit/d1cd1178e7)] - **test**: address deprecation warning (Rich Trott) [#38448](https://github.com/nodejs/node/pull/38448) +* [[`67e9e71f75`](https://github.com/nodejs/node/commit/67e9e71f75)] - **test**: crypto KeyObject.from() ERR\_INVALID\_ARG\_TYPE (pezhmanparsaee) [#37890](https://github.com/nodejs/node/pull/37890) +* [[`9ad611c0b2`](https://github.com/nodejs/node/commit/9ad611c0b2)] - **test**: fix flaky test-crypto-timing-safe-dqual-benchmarks (Rich Trott) [#38476](https://github.com/nodejs/node/pull/38476) +* [[`10b6b4e244`](https://github.com/nodejs/node/commit/10b6b4e244)] - **test**: update url Web Platform Tests (Leko) [#38435](https://github.com/nodejs/node/pull/38435) +* [[`4f6c4eb144`](https://github.com/nodejs/node/commit/4f6c4eb144)] - **test**: move abort test from pummel to abort directory (Rich Trott) [#38396](https://github.com/nodejs/node/pull/38396) +* [[`231ef4b0ce`](https://github.com/nodejs/node/commit/231ef4b0ce)] - **test**: move slower tests into pummel and skip on slow devices (Rich Trott) [#38395](https://github.com/nodejs/node/pull/38395) +* [[`45322dfa12`](https://github.com/nodejs/node/commit/45322dfa12)] - **test**: skip some pummel tests on slower machines (Rich Trott) [#38394](https://github.com/nodejs/node/pull/38394) +* [[`1bc47a4c0f`](https://github.com/nodejs/node/commit/1bc47a4c0f)] - **test**: fix test to allow quictls fork of OpenSSL 3 (Richard Lau) [#38372](https://github.com/nodejs/node/pull/38372) +* [[`6ac02755f5`](https://github.com/nodejs/node/commit/6ac02755f5)] - **test**: extend timeout on debugger tests for slower machines (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`93b0c78de0`](https://github.com/nodejs/node/commit/93b0c78de0)] - **test**: fix comment typo (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`6c3e5043b0`](https://github.com/nodejs/node/commit/6c3e5043b0)] - **test**: fix test-inspector-cli-address (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`27d7588ad5`](https://github.com/nodejs/node/commit/27d7588ad5)] - **test**: add ancestor package.json checks for tmpdir (Richard Lau) [#38285](https://github.com/nodejs/node/pull/38285) +* [[`30de03630e`](https://github.com/nodejs/node/commit/30de03630e)] - **test**: replace function with arrow function and remove unused argument (Andres) [#38235](https://github.com/nodejs/node/pull/38235) +* [[`eb8f5ce44f`](https://github.com/nodejs/node/commit/eb8f5ce44f)] - **test**: use .test domain for not found address (Richard Lau) [#38286](https://github.com/nodejs/node/pull/38286) +* [[`a4084d66c6`](https://github.com/nodejs/node/commit/a4084d66c6)] - **test,debugger**: migrate node-inspect tests to core (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`16eb078aa8`](https://github.com/nodejs/node/commit/16eb078aa8)] - **test,readline**: improve tab completion coverage (Antoine du Hamel) [#38465](https://github.com/nodejs/node/pull/38465) +* [[`b3ca1b358e`](https://github.com/nodejs/node/commit/b3ca1b358e)] - **timers**: remove redundant unref calls (Giora Guttsait) [#38320](https://github.com/nodejs/node/pull/38320) +* [[`5b393d9258`](https://github.com/nodejs/node/commit/5b393d9258)] - **tls**: validate ticket keys buffer (Antoine du Hamel) [#38308](https://github.com/nodejs/node/pull/38308) +* [[`f6745e9370`](https://github.com/nodejs/node/commit/f6745e9370)] - **tls**: fix `tlsSocket.setMaxSendFragment` abort (eladkeyshawn) [#38170](https://github.com/nodejs/node/pull/38170) +* [[`499da2d9e3`](https://github.com/nodejs/node/commit/499da2d9e3)] - **tools**: use mktemp to create the workspace directory (Luigi Pinca) [#38432](https://github.com/nodejs/node/pull/38432) +* [[`8a83bfd1bd`](https://github.com/nodejs/node/commit/8a83bfd1bd)] - **tools**: use a shallow clone of the npm/cli repository (Luigi Pinca) [#38463](https://github.com/nodejs/node/pull/38463) +* [[`bec959ef8b`](https://github.com/nodejs/node/commit/bec959ef8b)] - **tools**: disable LTO for "v8\_cppgc\_shared" target (Jesse Chan) [#38346](https://github.com/nodejs/node/pull/38346) +* [[`6350d35b3c`](https://github.com/nodejs/node/commit/6350d35b3c)] - **tools**: remove fixer for non-ascii-character ESLint custom rule (Rich Trott) [#38413](https://github.com/nodejs/node/pull/38413) +* [[`dce8d2968a`](https://github.com/nodejs/node/commit/dce8d2968a)] - **tools**: fix doc generation when version info is not available (Antoine du Hamel) [#38398](https://github.com/nodejs/node/pull/38398) +* [[`1033f6c8cb`](https://github.com/nodejs/node/commit/1033f6c8cb)] - **tools**: add \_depot\_tools to PATH (for V8 tests) (DeeDeeG) [#38299](https://github.com/nodejs/node/pull/38299) +* [[`28f02cb8cf`](https://github.com/nodejs/node/commit/28f02cb8cf)] - **tools**: update ESLint to 7.25.0 (Colin Ihrig) [#38378](https://github.com/nodejs/node/pull/38378) +* [[`f1ea2c8e2b`](https://github.com/nodejs/node/commit/f1ea2c8e2b)] - **tools**: update markdown linter rules (Rich Trott) [#38384](https://github.com/nodejs/node/pull/38384) +* [[`02e875c645`](https://github.com/nodejs/node/commit/02e875c645)] - **tools**: remove node-inspect from license (Rich Trott) [#38161](https://github.com/nodejs/node/pull/38161) +* [[`d3bd4b4771`](https://github.com/nodejs/node/commit/d3bd4b4771)] - **tools**: fix type mismatch in test runner (Richard Lau) [#38289](https://github.com/nodejs/node/pull/38289) +* [[`9a2651352b`](https://github.com/nodejs/node/commit/9a2651352b)] - **typings**: add JSDoc typings for fs (Voltrex) [#38306](https://github.com/nodejs/node/pull/38306) +* [[`e389e86b6b`](https://github.com/nodejs/node/commit/e389e86b6b)] - **typings**: add JSDoc typings for util (Rohit Gohri) [#38213](https://github.com/nodejs/node/pull/38213) +* [[`ec5b06eae3`](https://github.com/nodejs/node/commit/ec5b06eae3)] - **util**: fix infinite recursion during inspection (Ruben Bridgewater) [#37079](https://github.com/nodejs/node/pull/37079) +* [[`67bd0ec15c`](https://github.com/nodejs/node/commit/67bd0ec15c)] - **zlib**: fix brotli flush range (Khaidi Chu) [#38408](https://github.com/nodejs/node/pull/38408) + ## 2021-04-20, Version 16.0.0 (Current), @BethGriggs diff --git a/doc/guides/maintaining-V8.md b/doc/guides/maintaining-V8.md index 730244bc065d1f..da940758a25d94 100644 --- a/doc/guides/maintaining-V8.md +++ b/doc/guides/maintaining-V8.md @@ -229,7 +229,7 @@ to be cherry-picked in the Node.js repository and V8-CI must test the change. * Run the Node.js [V8 CI][] in addition to the [Node.js CI][]. The CI uses the `test-v8` target in the `Makefile`, which uses `tools/make-v8.sh` to reconstruct a git tree in the `deps/v8` directory to - run V8 tests. + run V8 tests2. The [`git-node`][] tool can be used to simplify this task. Run `git node v8 backport ` to cherry-pick a commit. @@ -414,6 +414,11 @@ This would require some tooling to: 1Node.js 0.12 and older are intentionally omitted from this document as their support has ended. +2The V8 tests still require Python 2. To run these tests locally, +you can run `PYTHON2 ./configure.py` before running `make test-v8`, in the root +of this repository. On macOS, this also requires a full Xcode install, +not just the "command line tools" for Xcode. + [ChromiumReleaseCalendar]: https://www.chromium.org/developers/calendar [Node.js CI]: https://ci.nodejs.org/job/node-test-pull-request/ [Node.js `canary` branch]: https://github.com/nodejs/node-v8/tree/canary diff --git a/doc/guides/releases.md b/doc/guides/releases.md index 2309460e3d1b3a..eac14469a09a2f 100644 --- a/doc/guides/releases.md +++ b/doc/guides/releases.md @@ -896,9 +896,20 @@ test, or doc-related are to be listed as notable changes. Some SEMVER-MINOR commits may be listed as notable changes on a case-by-case basis. Use your judgment there. +### Snap + +The Node.js [Snap][] package has a "default" for installs where the user hasn't +specified a release line ("track" in Snap terminology). This should be updated +to point to the most recently activated LTS. A member of the Node.js Build +Infrastructure team is able to perform the switch of the default. An issue +should be opened on the [Node.js Snap management repository][] requesting this +take place once a new LTS line has been released. + [Build issue tracker]: https://github.com/nodejs/build/issues/new [CI lockdown procedure]: https://github.com/nodejs/build/blob/HEAD/doc/jenkins-guide.md#restricting-access-for-security-releases +[Node.js Snap management repository]: https://github.com/nodejs/snap [Partner Communities]: https://github.com/nodejs/community-committee/blob/HEAD/governance/PARTNER_COMMUNITIES.md +[Snap]: https://snapcraft.io/node [nodejs.org release-post.js script]: https://github.com/nodejs/nodejs.org/blob/HEAD/scripts/release-post.js [nodejs.org repository]: https://github.com/nodejs/nodejs.org [webchat.freenode.net]: https://webchat.freenode.net/ diff --git a/doc/guides/security-release-process.md b/doc/guides/security-release-process.md index 5609e40739d3fb..10465c57501328 100644 --- a/doc/guides/security-release-process.md +++ b/doc/guides/security-release-process.md @@ -38,6 +38,12 @@ information described. * Described in the pre/post announcements * [ ] Pre-release announcement [email][]: ***LINK TO EMAIL*** + ```text + Security updates for all active release lines, Month Year + + The Node.js project will release new versions of all supported release lines on or shortly after Day of week, Month Day of Month, Year + For more information see: https://nodejs.org/en/blog/vulnerability/month-year-security-releases/ + ``` (Get access from existing manager: Ben Noordhuis, Rod Vagg, Michael Dawson) * [ ] Pre-release announcement to nodejs.org blog: ***LINK TO BLOG*** @@ -64,6 +70,12 @@ information described. * [ ] [Unlock CI](https://github.com/nodejs/build/blob/HEAD/doc/jenkins-guide.md#after-the-release) * [ ] Post-release announcement in reply [email][]: ***LINK TO EMAIL*** + ```text + Security updates for all active release lines, Month Year + + The Node.js project has now released new versions of all supported release lines. + For more information see: https://nodejs.org/en/blog/vulnerability/month-year-security-releases/ + ``` * [ ] Post-release announcement to Nodejs.org blog: ***LINK TO BLOG POST*** * (Re-PR the pre-approved branch from nodejs-private/nodejs.org-private to diff --git a/doc/node.1 b/doc/node.1 index d2d573151f879b..5f5a23319cfd8a 100644 --- a/doc/node.1 +++ b/doc/node.1 @@ -454,7 +454,7 @@ Print stack traces for process warnings (including deprecations). .It Fl -track-heap-objects Track heap object allocations for heap snapshots. . -.It Fl --unhandled-rejections=mode +.It Fl -unhandled-rejections=mode Define the behavior for unhandled rejections. Can be one of `strict` (raise an error), `warn` (enforce warnings) or `none` (silence warnings). . .It Fl -use-bundled-ca , Fl -use-openssl-ca @@ -685,7 +685,7 @@ Node.js is available under the MIT license. .Pp Node.js also includes external libraries that are available under a variety of licenses. See -.Sy https://github.com/nodejs/node/blob/master/LICENSE +.Sy https://github.com/nodejs/node/blob/HEAD/LICENSE for the full license text. . .\"====================================================================== @@ -713,4 +713,4 @@ IRC (Node.js core development): .\"====================================================================== .Sh AUTHORS Written and maintained by 1000+ contributors: -.Sy https://github.com/nodejs/node/blob/master/AUTHORS +.Sy https://github.com/nodejs/node/blob/HEAD/AUTHORS diff --git a/glossary.md b/glossary.md index eb44536e6eca79..ccc1e495dfffe6 100644 --- a/glossary.md +++ b/glossary.md @@ -1,4 +1,4 @@ -You may also need to check . +You may also need to check . * LGTM: "Looks good to me", commonly used to approve a code review. * PTAL: Please take a look. diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 9a0450449fbad2..38ca7683247b8c 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -27,16 +27,65 @@ rules: message: "Use 'overrideStackTrace' from 'lib/internal/errors.js' instead of 'Error.prepareStackTrace'." no-restricted-globals: - error - - name: globalThis - message: "Use `const { globalThis } = primordials;` instead of the global." + - name: AbortController + message: "Use `const { AbortController } = require('internal/abort_controller');` instead of the global." + - name: AbortSignal + message: "Use `const { AbortSignal } = require('internal/abort_controller');` instead of the global." + # Atomics is not available in primordials because it can be + # disabled with --no-harmony-atomics CLI flag. + - name: Atomics + message: "Use `const { Atomics } = globalThis;` instead of the global." + - name: Buffer + message: "Use `const { Buffer } = require('buffer');` instead of the global." + - name: Event + message: "Use `const { Event } = require('internal/event_target');` instead of the global." + - name: EventTarget + message: "Use `const { EventTarget } = require('internal/event_target');` instead of the global." + # Intl is not available in primordials because it can be + # disabled with --without-intl build flag. + - name: Intl + message: "Use `const { Intl } = globalThis;` instead of the global." + - name: MessageChannel + message: "Use `const { MessageChannel } = require('internal/worker/io');` instead of the global." + - name: MessageEvent + message: "Use `const { MessageEvent } = require('internal/worker/io');` instead of the global." + - name: MessagePort + message: "Use `const { MessagePort } = require('internal/worker/io');` instead of the global." + # SharedArrayBuffer is not available in primordials because it can be + # disabled with --no-harmony-sharedarraybuffer CLI flag. + - name: SharedArrayBuffer + message: "Use `const { SharedArrayBuffer } = globalThis;` instead of the global." + - name: TextDecoder + message: "Use `const { TextDecoder } = require('internal/encoding');` instead of the global." + - name: TextEncoder + message: "Use `const { TextEncoder } = require('internal/encoding');` instead of the global." + - name: URL + message: "Use `const { URL } = require('internal/url');` instead of the global." + - name: URLSearchParams + message: "Use `const { URLSearchParams } = require('internal/url');` instead of the global." + # WebAssembly is not available in primordials because it can be + # disabled with --jitless CLI flag. + - name: WebAssembly + message: "Use `const { WebAssembly } = globalThis;` instead of the global." + - name: atob + message: "Use `const { atob } = require('buffer');` instead of the global." + - name: btoa + message: "Use `const { btoa } = require('buffer');` instead of the global." - name: global message: "Use `const { globalThis } = primordials;` instead of `global`." + - name: globalThis + message: "Use `const { globalThis } = primordials;` instead of the global." + - name: performance + message: "Use `const { performance } = require('perf_hooks');` instead of the global." + - name: queueMicrotask + message: "Use `const { queueMicrotask } = require('internal/process/task_queues');` instead of the global." # Custom rules in tools/eslint-rules node-core/lowercase-name-for-primitive: error node-core/non-ascii-character: error node-core/no-array-destructuring: error node-core/prefer-primordials: - error + - name: AggregateError - name: Array - name: ArrayBuffer - name: BigInt @@ -76,6 +125,7 @@ rules: into: Number - name: parseInt into: Number + - name: Proxy - name: Promise - name: RangeError - name: ReferenceError diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index a54bd0d0d35777..66ebc7b77869f7 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -1396,6 +1396,9 @@ Server.prototype.getTicketKeys = function getTicketKeys() { Server.prototype.setTicketKeys = function setTicketKeys(keys) { + validateBuffer(keys); + assert(keys.byteLength === 48, + 'Session ticket keys must be a 48-byte buffer'); this._sharedCreds.context.setTicketKeys(keys); }; diff --git a/lib/fs.js b/lib/fs.js index e6cf8527e8720d..310397bbed39e1 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -207,6 +207,14 @@ function isFileType(stats, fileType) { return (mode & S_IFMT) === fileType; } +/** + * Tests a user's permissions for the file or directory + * specified by `path`. + * @param {string | Buffer | URL} path + * @param {number} [mode] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function access(path, mode, callback) { if (typeof mode === 'function') { callback = mode; @@ -222,6 +230,13 @@ function access(path, mode, callback) { binding.access(pathModule.toNamespacedPath(path), mode, req); } +/** + * Synchronously tests a user's permissions for the file or + * directory specified by `path`. + * @param {string | Buffer | URL} path + * @param {number} [mode] + * @returns {void | never} + */ function accessSync(path, mode) { path = getValidatedPath(path); mode = getValidMode(mode, 'access'); @@ -231,6 +246,12 @@ function accessSync(path, mode) { handleErrorFromBinding(ctx); } +/** + * Tests whether or not the given path exists. + * @param {string | Buffer | URL} path + * @param {(exists?: boolean) => any} callback + * @returns {void} + */ function exists(path, callback) { maybeCallback(callback); @@ -257,6 +278,11 @@ ObjectDefineProperty(exists, internalUtil.promisify.custom, { // fs.existsSync(), would only get a false in return, so we cannot signal // validation errors to users properly out of compatibility concerns. // TODO(joyeecheung): deprecate the never-throw-on-invalid-arguments behavior +/** + * Synchronously tests whether or not the given path exists. + * @param {string | Buffer | URL} path + * @returns {boolean} + */ function existsSync(path) { try { path = getValidatedPath(path); @@ -326,6 +352,20 @@ function checkAborted(signal, callback) { return false; } +/** + * Asynchronously reads the entire contents of a file. + * @param {string | Buffer | URL | number} path + * @param {{ + * encoding?: string | null; + * flag?: string; + * signal?: AbortSignal; + * } | string} [options] + * @param {( + * err?: Error, + * data?: string | Buffer + * ) => any} callback + * @returns {void} + */ function readFile(path, options, callback) { callback = maybeCallback(callback || options); options = getOptions(options, { flag: 'r' }); @@ -396,6 +436,15 @@ function tryReadSync(fd, isUserFd, buffer, pos, len) { return bytesRead; } +/** + * Synchronously reads the entire contents of a file. + * @param {string | Buffer | URL | number} path + * @param {{ + * encoding?: string | null; + * flag?: string; + * }} [options] + * @returns {string | Buffer} + */ function readFileSync(path, options) { options = getOptions(options, { flag: 'r' }); const isUserFd = isFd(path); // File descriptor ownership @@ -451,6 +500,12 @@ function defaultCloseCallback(err) { if (err != null) throw err; } +/** + * Closes the file descriptor. + * @param {number} fd + * @param {(err?: Error) => any} [callback] + * @returns {void} + */ function close(fd, callback = defaultCloseCallback) { fd = getValidatedFd(fd); if (callback !== defaultCloseCallback) @@ -461,6 +516,11 @@ function close(fd, callback = defaultCloseCallback) { binding.close(fd, req); } +/** + * Synchronously closes the file descriptor. + * @param {number} fd + * @returns {void} + */ function closeSync(fd) { fd = getValidatedFd(fd); @@ -469,6 +529,17 @@ function closeSync(fd) { handleErrorFromBinding(ctx); } +/** + * Asynchronously opens a file. + * @param {string | Buffer | URL} path + * @param {string | number} [flags] + * @param {string | number} [mode] + * @param {( + * err?: Error, + * fd?: number + * ) => any} callback + * @returns {void} + */ function open(path, flags, mode, callback) { path = getValidatedPath(path); if (arguments.length < 3) { @@ -493,7 +564,13 @@ function open(path, flags, mode, callback) { req); } - +/** + * Synchronously opens a file. + * @param {string | Buffer | URL} path + * @param {string | number} [flags] + * @param {string | number} [mode] + * @returns {number} + */ function openSync(path, flags, mode) { path = getValidatedPath(path); const flagsNumber = stringToFlags(flags); @@ -507,10 +584,20 @@ function openSync(path, flags, mode) { return result; } -// usage: -// fs.read(fd, buffer, offset, length, position, callback); -// OR -// fs.read(fd, {}, callback) +/** + * Reads file from the specified `fd` (file descriptor). + * @param {number} fd + * @param {Buffer | TypedArray | DataView} buffer + * @param {number} offset + * @param {number} length + * @param {number | bigint} position + * @param {( + * err?: Error, + * bytesRead?: number, + * buffer?: Buffer + * ) => any} callback + * @returns {void} + */ function read(fd, buffer, offset, length, position, callback) { fd = getValidatedFd(fd); @@ -543,7 +630,7 @@ function read(fd, buffer, offset, length, position, callback) { if (offset == null) { offset = 0; } else { - validateInteger(offset, 'offset'); + validateInteger(offset, 'offset', 0); } length |= 0; @@ -580,10 +667,18 @@ function read(fd, buffer, offset, length, position, callback) { ObjectDefineProperty(read, internalUtil.customPromisifyArgs, { value: ['bytesRead', 'buffer'], enumerable: false }); -// usage: -// fs.readSync(fd, buffer, offset, length, position); -// OR -// fs.readSync(fd, buffer, {}) or fs.readSync(fd, buffer) +/** + * Synchronously reads the file from the + * specified `fd` (file descriptor). + * @param {number} fd + * @param {Buffer | TypedArray | DataView} buffer + * @param {{ + * offset?: number; + * length?: number; + * position?: number | bigint; + * }} [offset] + * @returns {number} + */ function readSync(fd, buffer, offset, length, position) { fd = getValidatedFd(fd); @@ -599,7 +694,7 @@ function readSync(fd, buffer, offset, length, position) { if (offset == null) { offset = 0; } else { - validateInteger(offset, 'offset'); + validateInteger(offset, 'offset', 0); } length |= 0; @@ -627,6 +722,19 @@ function readSync(fd, buffer, offset, length, position) { return result; } +/** + * Reads file from the specified `fd` (file descriptor) + * and writes to an array of `ArrayBufferView`s. + * @param {number} fd + * @param {ArrayBufferView[]} buffers + * @param {number} [position] + * @param {( + * err?: Error, + * bytesRead?: number, + * buffers?: ArrayBufferView[]; + * ) => any} callback + * @returns {void} + */ function readv(fd, buffers, position, callback) { function wrapper(err, read) { callback(err, read || 0, buffers); @@ -648,6 +756,15 @@ function readv(fd, buffers, position, callback) { ObjectDefineProperty(readv, internalUtil.customPromisifyArgs, { value: ['bytesRead', 'buffers'], enumerable: false }); +/** + * Synchronously reads file from the + * specified `fd` (file descriptor) and writes to an array + * of `ArrayBufferView`s. + * @param {number} fd + * @param {ArrayBufferView[]} buffers + * @param {number} [position] + * @returns {number} + */ function readvSync(fd, buffers, position) { fd = getValidatedFd(fd); validateBufferArray(buffers); @@ -662,10 +779,20 @@ function readvSync(fd, buffers, position) { return result; } -// usage: -// fs.write(fd, buffer[, offset[, length[, position]]], callback); -// OR -// fs.write(fd, string[, position[, encoding]], callback); +/** + * Writes `buffer` to the specified `fd` (file descriptor). + * @param {number} fd + * @param {Buffer | TypedArray | DataView | string | Object} buffer + * @param {number} [offset] + * @param {number} [length] + * @param {number} [position] + * @param {( + * err?: Error, + * bytesWritten?: number; + * buffer?: Buffer | TypedArray | DataView + * ) => any} callback + * @returns {void} + */ function write(fd, buffer, offset, length, position, callback) { function wrapper(err, written) { // Retain a reference to buffer so that it can't be GC'ed too soon. @@ -679,7 +806,7 @@ function write(fd, buffer, offset, length, position, callback) { if (offset == null || typeof offset === 'function') { offset = 0; } else { - validateInteger(offset, 'offset'); + validateInteger(offset, 'offset', 0); } if (typeof length !== 'number') length = buffer.byteLength - offset; @@ -716,10 +843,16 @@ function write(fd, buffer, offset, length, position, callback) { ObjectDefineProperty(write, internalUtil.customPromisifyArgs, { value: ['bytesWritten', 'buffer'], enumerable: false }); -// Usage: -// fs.writeSync(fd, buffer[, offset[, length[, position]]]); -// OR -// fs.writeSync(fd, string[, position[, encoding]]); +/** + * Synchronously writes `buffer` to the + * specified `fd` (file descriptor). + * @param {number} fd + * @param {Buffer | TypedArray | DataView | string | Object} buffer + * @param {number} [offset] + * @param {number} [length] + * @param {number} [position] + * @returns {number} + */ function writeSync(fd, buffer, offset, length, position) { fd = getValidatedFd(fd); const ctx = {}; @@ -730,7 +863,7 @@ function writeSync(fd, buffer, offset, length, position) { if (offset == null) { offset = 0; } else { - validateInteger(offset, 'offset'); + validateInteger(offset, 'offset', 0); } if (typeof length !== 'number') length = buffer.byteLength - offset; @@ -750,8 +883,19 @@ function writeSync(fd, buffer, offset, length, position) { return result; } -// usage: -// fs.writev(fd, buffers[, position], callback); +/** + * Writes an array of `ArrayBufferView`s to the + * specified `fd` (file descriptor). + * @param {number} fd + * @param {ArrayBufferView[]} buffers + * @param {number} [position] + * @param {( + * err?: Error, + * bytesWritten?: number, + * buffers?: ArrayBufferView[] + * ) => any} callback + * @returns {void} + */ function writev(fd, buffers, position, callback) { function wrapper(err, written) { callback(err, written || 0, buffers); @@ -775,6 +919,14 @@ ObjectDefineProperty(writev, internalUtil.customPromisifyArgs, { enumerable: false }); +/** + * Synchronously writes an array of `ArrayBufferView`s + * to the specified `fd` (file descriptor). + * @param {number} fd + * @param {ArrayBufferView[]} buffers + * @param {number} [position] + * @returns {number} + */ function writevSync(fd, buffers, position) { fd = getValidatedFd(fd); validateBufferArray(buffers); @@ -790,6 +942,14 @@ function writevSync(fd, buffers, position) { return result; } +/** + * Asynchronously renames file at `oldPath` to + * the pathname provided as `newPath`. + * @param {string | Buffer | URL} oldPath + * @param {string | Buffer | URL} newPath + * @param {(err?: Error) => any} callback + * @returns {void} + */ function rename(oldPath, newPath, callback) { callback = makeCallback(callback); oldPath = getValidatedPath(oldPath, 'oldPath'); @@ -801,6 +961,14 @@ function rename(oldPath, newPath, callback) { req); } + +/** + * Synchronously renames file at `oldPath` to + * the pathname provided as `newPath`. + * @param {string | Buffer | URL} oldPath + * @param {string | Buffer | URL} newPath + * @returns {void} + */ function renameSync(oldPath, newPath) { oldPath = getValidatedPath(oldPath, 'oldPath'); newPath = getValidatedPath(newPath, 'newPath'); @@ -810,6 +978,13 @@ function renameSync(oldPath, newPath) { handleErrorFromBinding(ctx); } +/** + * Truncates the file. + * @param {string | Buffer | URL} path + * @param {number} [len] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function truncate(path, len, callback) { if (typeof path === 'number') { showTruncateDeprecation(); @@ -837,6 +1012,12 @@ function truncate(path, len, callback) { }); } +/** + * Synchronously truncates the file. + * @param {string | Buffer | URL} path + * @param {number} [len] + * @returns {void} + */ function truncateSync(path, len) { if (typeof path === 'number') { // legacy @@ -858,6 +1039,13 @@ function truncateSync(path, len) { return ret; } +/** + * Truncates the file descriptor. + * @param {number} fd + * @param {number} [len] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function ftruncate(fd, len = 0, callback) { if (typeof len === 'function') { callback = len; @@ -873,6 +1061,12 @@ function ftruncate(fd, len = 0, callback) { binding.ftruncate(fd, len, req); } +/** + * Synchronously truncates the file descriptor. + * @param {number} fd + * @param {number} [len] + * @returns {void} + */ function ftruncateSync(fd, len = 0) { fd = getValidatedFd(fd); validateInteger(len, 'len'); @@ -888,6 +1082,17 @@ function lazyLoadRimraf() { ({ rimraf, rimrafSync } = require('internal/fs/rimraf')); } +/** + * Asynchronously removes a directory. + * @param {string | Buffer | URL} path + * @param {{ + * maxRetries?: number; + * recursive?: boolean; + * retryDelay?: number; + * }} [options] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function rmdir(path, options, callback) { if (typeof options === 'function') { callback = options; @@ -924,6 +1129,16 @@ function rmdir(path, options, callback) { } } +/** + * Synchronously removes a directory. + * @param {string | Buffer | URL} path + * @param {{ + * maxRetries?: number; + * recursive?: boolean; + * retryDelay?: number; + * }} [options] + * @returns {void} + */ function rmdirSync(path, options) { path = getValidatedPath(path); @@ -943,6 +1158,19 @@ function rmdirSync(path, options) { return handleErrorFromBinding(ctx); } +/** + * Asynchronously removes files and + * directories (modeled on the standard POSIX `rm` utility). + * @param {string | Buffer | URL} path + * @param {{ + * force?: boolean; + * maxRetries?: number; + * recursive?: boolean; + * retryDelay?: number; + * }} [options] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function rm(path, options, callback) { if (typeof options === 'function') { callback = options; @@ -958,6 +1186,18 @@ function rm(path, options, callback) { }); } +/** + * Synchronously removes files and + * directories (modeled on the standard POSIX `rm` utility). + * @param {string | Buffer | URL} path + * @param {{ + * force?: boolean; + * maxRetries?: number; + * recursive?: boolean; + * retryDelay?: number; + * }} [options] + * @returns {void} + */ function rmSync(path, options) { options = validateRmOptionsSync(path, options, false); @@ -965,6 +1205,14 @@ function rmSync(path, options) { return rimrafSync(pathModule.toNamespacedPath(path), options); } +/** + * Forces all currently queued I/O operations associated + * with the file to the operating system's synchronized + * I/O completion state. + * @param {number} fd + * @param {(err?: Error) => any} callback + * @returns {void} + */ function fdatasync(fd, callback) { fd = getValidatedFd(fd); const req = new FSReqCallback(); @@ -972,6 +1220,13 @@ function fdatasync(fd, callback) { binding.fdatasync(fd, req); } +/** + * Synchronously forces all currently queued I/O operations + * associated with the file to the operating + * system's synchronized I/O completion state. + * @param {number} fd + * @returns {void} + */ function fdatasyncSync(fd) { fd = getValidatedFd(fd); const ctx = {}; @@ -979,6 +1234,13 @@ function fdatasyncSync(fd) { handleErrorFromBinding(ctx); } +/** + * Requests for all data for the open file descriptor + * to be flushed to the storage device. + * @param {number} fd + * @param {(err?: Error) => any} callback + * @returns {void} + */ function fsync(fd, callback) { fd = getValidatedFd(fd); const req = new FSReqCallback(); @@ -986,6 +1248,12 @@ function fsync(fd, callback) { binding.fsync(fd, req); } +/** + * Synchronously requests for all data for the open + * file descriptor to be flushed to the storage device. + * @param {number} fd + * @returns {void} + */ function fsyncSync(fd) { fd = getValidatedFd(fd); const ctx = {}; @@ -993,6 +1261,16 @@ function fsyncSync(fd) { handleErrorFromBinding(ctx); } +/** + * Asynchronously creates a directory. + * @param {string | Buffer | URL} path + * @param {{ + * recursive?: boolean; + * mode?: string | number; + * } | number} [options] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function mkdir(path, options, callback) { let mode = 0o777; let recursive = false; @@ -1017,6 +1295,15 @@ function mkdir(path, options, callback) { parseFileMode(mode, 'mode'), recursive, req); } +/** + * Synchronously creates a directory. + * @param {string | Buffer | URL} path + * @param {{ + * recursive?: boolean; + * mode?: string | number; + * } | number} [options] + * @returns {string | void} + */ function mkdirSync(path, options) { let mode = 0o777; let recursive = false; @@ -1041,6 +1328,19 @@ function mkdirSync(path, options) { } } +/** + * Reads the contents of a directory. + * @param {string | Buffer | URL} path + * @param {string | { + * encoding?: string; + * withFileTypes?: boolean; + * }} [options] + * @param {( + * err?: Error, + * files?: string[] | Buffer[] | Direct[]; + * ) => any} callback + * @returns {void} + */ function readdir(path, options, callback) { callback = makeCallback(typeof options === 'function' ? options : callback); options = getOptions(options, {}); @@ -1062,6 +1362,15 @@ function readdir(path, options, callback) { !!options.withFileTypes, req); } +/** + * Synchronously reads the contents of a directory. + * @param {string | Buffer | URL} path + * @param {string | { + * encoding?: string; + * withFileTypes?: boolean; + * }} [options] + * @returns {string | Buffer[] | Dirent[]} + */ function readdirSync(path, options) { options = getOptions(options, {}); path = getValidatedPath(path); @@ -1073,6 +1382,17 @@ function readdirSync(path, options) { return options.withFileTypes ? getDirents(path, result) : result; } +/** + * Invokes the callback with the `fs.Stats` + * for the file descriptor. + * @param {number} fd + * @param {{ bigint?: boolean; }} [options] + * @param {( + * err?: Error, + * stats?: Stats + * ) => any} callback + * @returns {void} + */ function fstat(fd, options = { bigint: false }, callback) { if (typeof options === 'function') { callback = options; @@ -1086,6 +1406,17 @@ function fstat(fd, options = { bigint: false }, callback) { binding.fstat(fd, options.bigint, req); } +/** + * Retrieves the `fs.Stats` for the symbolic link + * referred to by the `path`. + * @param {string | Buffer | URL} path + * @param {{ bigint?: boolean; }} [options] + * @param {( + * err?: Error, + * stats?: Stats + * ) => any} callback + * @returns {void} + */ function lstat(path, options = { bigint: false }, callback) { if (typeof options === 'function') { callback = options; @@ -1099,6 +1430,16 @@ function lstat(path, options = { bigint: false }, callback) { binding.lstat(pathModule.toNamespacedPath(path), options.bigint, req); } +/** + * Asynchronously gets the stats of a file. + * @param {string | Buffer | URL} path + * @param {{ bigint?: boolean; }} [options] + * @param {( + * err?: Error, + * stats?: Stats + * ) => any} callback + * @returns {void} + */ function stat(path, options = { bigint: false }, callback) { if (typeof options === 'function') { callback = options; @@ -1125,6 +1466,16 @@ function hasNoEntryError(ctx) { return false; } +/** + * Synchronously retrieves the `fs.Stats` for + * the file descriptor. + * @param {number} fd + * @param {{ + * bigint?: boolean; + * throwIfNoEntry?: boolean; + * }} [options] + * @returns {Stats} + */ function fstatSync(fd, options = { bigint: false, throwIfNoEntry: true }) { fd = getValidatedFd(fd); const ctx = { fd }; @@ -1133,6 +1484,16 @@ function fstatSync(fd, options = { bigint: false, throwIfNoEntry: true }) { return getStatsFromBinding(stats); } +/** + * Synchronously retrieves the `fs.Stats` for + * the symbolic link referred to by the `path`. + * @param {string | Buffer | URL} path + * @param {{ + * bigint?: boolean; + * throwIfNoEntry?: boolean; + * }} [options] + * @returns {Stats} + */ function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) { path = getValidatedPath(path); const ctx = { path }; @@ -1145,6 +1506,16 @@ function lstatSync(path, options = { bigint: false, throwIfNoEntry: true }) { return getStatsFromBinding(stats); } +/** + * Synchronously retrieves the `fs.Stats` + * for the `path`. + * @param {string | Buffer | URL} path + * @param {{ + * bigint?: boolean; + * throwIfNoEntry?: boolean; + * }} [options] + * @returns {Stats} + */ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) { path = getValidatedPath(path); const ctx = { path }; @@ -1157,6 +1528,17 @@ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) { return getStatsFromBinding(stats); } +/** + * Reads the contents of a symbolic link + * referred to by `path`. + * @param {string | Buffer | URL} path + * @param {{ encoding?: string; } | string} [options] + * @param {( + * err?: Error, + * linkString?: string | Buffer + * ) => any} callback + * @returns {void} + */ function readlink(path, options, callback) { callback = makeCallback(typeof options === 'function' ? options : callback); options = getOptions(options, {}); @@ -1166,6 +1548,13 @@ function readlink(path, options, callback) { binding.readlink(pathModule.toNamespacedPath(path), options.encoding, req); } +/** + * Synchronously reads the contents of a symbolic link + * referred to by `path`. + * @param {string | Buffer | URL} path + * @param {{ encoding?: string; } | string} [options] + * @returns {string | Buffer} + */ function readlinkSync(path, options) { options = getOptions(options, {}); path = getValidatedPath(path, 'oldPath'); @@ -1176,6 +1565,14 @@ function readlinkSync(path, options) { return result; } +/** + * Creates the link called `path` pointing to `target`. + * @param {string | Buffer | URL} target + * @param {string | Buffer | URL} path + * @param {string} [type_] + * @param {(err?: Error) => any} callback_ + * @returns {void} + */ function symlink(target, path, type_, callback_) { const type = (typeof type_ === 'string' ? type_ : null); const callback = makeCallback(arguments[arguments.length - 1]); @@ -1218,6 +1615,14 @@ function symlink(target, path, type_, callback_) { binding.symlink(destination, pathModule.toNamespacedPath(path), flags, req); } +/** + * Synchronously creates the link called `path` + * pointing to `target`. + * @param {string | Buffer | URL} target + * @param {string | Buffer | URL} path + * @param {string} [type] + * @returns {void} + */ function symlinkSync(target, path, type) { type = (typeof type === 'string' ? type : null); if (isWindows && type === null) { @@ -1237,6 +1642,14 @@ function symlinkSync(target, path, type) { handleErrorFromBinding(ctx); } +/** + * Creates a new link from the `existingPath` + * to the `newPath`. + * @param {string | Buffer | URL} existingPath + * @param {string | Buffer | URL} newPath + * @param {(err?: Error) => any} callback + * @returns {void} + */ function link(existingPath, newPath, callback) { callback = makeCallback(callback); @@ -1251,6 +1664,13 @@ function link(existingPath, newPath, callback) { req); } +/** + * Synchronously creates a new link from the `existingPath` + * to the `newPath`. + * @param {string | Buffer | URL} existingPath + * @param {string | Buffer | URL} newPath + * @returns {void} + */ function linkSync(existingPath, newPath) { existingPath = getValidatedPath(existingPath, 'existingPath'); newPath = getValidatedPath(newPath, 'newPath'); @@ -1263,6 +1683,12 @@ function linkSync(existingPath, newPath) { return result; } +/** + * Asynchronously removes a file or symbolic link. + * @param {string | Buffer | URL} path + * @param {(err?: Error) => any} callback + * @returns {void} + */ function unlink(path, callback) { callback = makeCallback(callback); path = getValidatedPath(path); @@ -1271,6 +1697,11 @@ function unlink(path, callback) { binding.unlink(pathModule.toNamespacedPath(path), req); } +/** + * Synchronously removes a file or symbolic link. + * @param {string | Buffer | URL} path + * @returns {void} + */ function unlinkSync(path) { path = getValidatedPath(path); const ctx = { path }; @@ -1278,6 +1709,13 @@ function unlinkSync(path) { handleErrorFromBinding(ctx); } +/** + * Sets the permissions on the file. + * @param {number} fd + * @param {string | number} mode + * @param {(err?: Error) => any} callback + * @returns {void} + */ function fchmod(fd, mode, callback) { fd = getValidatedFd(fd); mode = parseFileMode(mode, 'mode'); @@ -1288,6 +1726,12 @@ function fchmod(fd, mode, callback) { binding.fchmod(fd, mode, req); } +/** + * Synchronously sets the permissions on the file. + * @param {number} fd + * @param {string | number} mode + * @returns {void} + */ function fchmodSync(fd, mode) { fd = getValidatedFd(fd); mode = parseFileMode(mode, 'mode'); @@ -1296,6 +1740,13 @@ function fchmodSync(fd, mode) { handleErrorFromBinding(ctx); } +/** + * Changes the permissions on a symbolic link. + * @param {string | Buffer | URL} path + * @param {number} mode + * @param {(err?: Error) => any} callback + * @returns {void} + */ function lchmod(path, mode, callback) { callback = maybeCallback(callback); mode = parseFileMode(mode, 'mode'); @@ -1314,6 +1765,12 @@ function lchmod(path, mode, callback) { }); } +/** + * Synchronously changes the permissions on a symbolic link. + * @param {string | Buffer | URL} path + * @param {number} mode + * @returns {void} + */ function lchmodSync(path, mode) { const fd = fs.openSync(path, O_WRONLY | O_SYMLINK); @@ -1328,7 +1785,13 @@ function lchmodSync(path, mode) { return ret; } - +/** + * Asynchronously changes the permissions of a file. + * @param {string | Buffer | URL} path + * @param {string | number} mode + * @param {(err?: Error) => any} callback + * @returns {void} + */ function chmod(path, mode, callback) { path = getValidatedPath(path); mode = parseFileMode(mode, 'mode'); @@ -1339,6 +1802,12 @@ function chmod(path, mode, callback) { binding.chmod(pathModule.toNamespacedPath(path), mode, req); } +/** + * Synchronously changes the permissions of a file. + * @param {string | Buffer | URL} path + * @param {string | number} mode + * @returns {void} + */ function chmodSync(path, mode) { path = getValidatedPath(path); mode = parseFileMode(mode, 'mode'); @@ -1348,6 +1817,14 @@ function chmodSync(path, mode) { handleErrorFromBinding(ctx); } +/** + * Sets the owner of the symbolic link. + * @param {string | Buffer | URL} path + * @param {number} uid + * @param {number} gid + * @param {(err?: Error) => any} callback + * @returns {void} + */ function lchown(path, uid, gid, callback) { callback = makeCallback(callback); path = getValidatedPath(path); @@ -1358,6 +1835,13 @@ function lchown(path, uid, gid, callback) { binding.lchown(pathModule.toNamespacedPath(path), uid, gid, req); } +/** + * Synchronously sets the owner of the symbolic link. + * @param {string | Buffer | URL} path + * @param {number} uid + * @param {number} gid + * @returns {void} + */ function lchownSync(path, uid, gid) { path = getValidatedPath(path); validateInteger(uid, 'uid', -1, kMaxUserId); @@ -1367,6 +1851,14 @@ function lchownSync(path, uid, gid) { handleErrorFromBinding(ctx); } +/** + * Sets the owner of the file. + * @param {number} fd + * @param {number} uid + * @param {number} gid + * @param {(err?: Error) => any} callback + * @returns {void} + */ function fchown(fd, uid, gid, callback) { fd = getValidatedFd(fd); validateInteger(uid, 'uid', -1, kMaxUserId); @@ -1378,6 +1870,13 @@ function fchown(fd, uid, gid, callback) { binding.fchown(fd, uid, gid, req); } +/** + * Synchronously sets the owner of the file. + * @param {number} fd + * @param {number} uid + * @param {number} gid + * @returns {void} + */ function fchownSync(fd, uid, gid) { fd = getValidatedFd(fd); validateInteger(uid, 'uid', -1, kMaxUserId); @@ -1388,6 +1887,15 @@ function fchownSync(fd, uid, gid) { handleErrorFromBinding(ctx); } +/** + * Asynchronously changes the owner and group + * of a file. + * @param {string | Buffer | URL} path + * @param {number} uid + * @param {number} gid + * @param {(err?: Error) => any} callback + * @returns {void} + */ function chown(path, uid, gid, callback) { callback = makeCallback(callback); path = getValidatedPath(path); @@ -1399,6 +1907,14 @@ function chown(path, uid, gid, callback) { binding.chown(pathModule.toNamespacedPath(path), uid, gid, req); } +/** + * Synchronously changes the owner and group + * of a file. + * @param {string | Buffer | URL} path + * @param {number} uid + * @param {number} gid + * @returns {void} + */ function chownSync(path, uid, gid) { path = getValidatedPath(path); validateInteger(uid, 'uid', -1, kMaxUserId); @@ -1408,6 +1924,15 @@ function chownSync(path, uid, gid) { handleErrorFromBinding(ctx); } +/** + * Changes the file system timestamps of the object + * referenced by `path`. + * @param {string | Buffer | URL} path + * @param {number | string | Date} atime + * @param {number | string | Date} mtime + * @param {(err?: Error) => any} callback + * @returns {void} + */ function utimes(path, atime, mtime, callback) { callback = makeCallback(callback); path = getValidatedPath(path); @@ -1420,6 +1945,14 @@ function utimes(path, atime, mtime, callback) { req); } +/** + * Synchronously changes the file system timestamps + * of the object referenced by `path`. + * @param {string | Buffer | URL} path + * @param {number | string | Date} atime + * @param {number | string | Date} mtime + * @returns {void} + */ function utimesSync(path, atime, mtime) { path = getValidatedPath(path); const ctx = { path }; @@ -1429,6 +1962,15 @@ function utimesSync(path, atime, mtime) { handleErrorFromBinding(ctx); } +/** + * Changes the file system timestamps of the object + * referenced by the supplied `fd` (file descriptor). + * @param {number} fd + * @param {number | string | Date} atime + * @param {number | string | Date} mtime + * @param {(err?: Error) => any} callback + * @returns {void} + */ function futimes(fd, atime, mtime, callback) { fd = getValidatedFd(fd); atime = toUnixTimestamp(atime, 'atime'); @@ -1440,6 +1982,15 @@ function futimes(fd, atime, mtime, callback) { binding.futimes(fd, atime, mtime, req); } +/** + * Synchronously changes the file system timestamps + * of the object referenced by the + * supplied `fd` (file descriptor). + * @param {number} fd + * @param {number | string | Date} atime + * @param {number | string | Date} mtime + * @returns {void} + */ function futimesSync(fd, atime, mtime) { fd = getValidatedFd(fd); atime = toUnixTimestamp(atime, 'atime'); @@ -1449,6 +2000,15 @@ function futimesSync(fd, atime, mtime) { handleErrorFromBinding(ctx); } +/** + * Changes the access and modification times of + * a file in the same way as `fs.utimes()`. + * @param {string | Buffer | URL} path + * @param {number | string | Date} atime + * @param {number | string | Date} mtime + * @param {(err?: Error) => any} callback + * @returns {void} + */ function lutimes(path, atime, mtime, callback) { callback = makeCallback(callback); path = getValidatedPath(path); @@ -1461,6 +2021,14 @@ function lutimes(path, atime, mtime, callback) { req); } +/** + * Synchronously changes the access and modification + * times of a file in the same way as `fs.utimesSync()`. + * @param {string | Buffer | URL} path + * @param {number | string | Date} atime + * @param {number | string | Date} mtime + * @returns {void} + */ function lutimesSync(path, atime, mtime) { path = getValidatedPath(path); const ctx = { path }; @@ -1507,6 +2075,19 @@ function writeAll(fd, isUserFd, buffer, offset, length, signal, callback) { }); } +/** + * Asynchronously writes data to the file. + * @param {string | Buffer | URL | number} path + * @param {string | Buffer | TypedArray | DataView | Object} data + * @param {{ + * encoding?: string | null; + * mode?: number; + * flag?: string; + * signal?: AbortSignal; + * } | string} [options] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function writeFile(path, data, options, callback) { callback = maybeCallback(callback || options); options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'w' }); @@ -1538,6 +2119,17 @@ function writeFile(path, data, options, callback) { }); } +/** + * Synchronously writes data to the file. + * @param {string | Buffer | URL | number} path + * @param {string | Buffer | TypedArray | DataView | Object} data + * @param {{ + * encoding?: string | null; + * mode?: number; + * flag?: string; + * } | string} [options] + * @returns {void} + */ function writeFileSync(path, data, options) { options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'w' }); @@ -1564,6 +2156,18 @@ function writeFileSync(path, data, options) { } } +/** + * Asynchronously appends data to a file. + * @param {string | Buffer | URL | number} path + * @param {string | Buffer} data + * @param {{ + * encoding?: string | null; + * mode?: number; + * flag?: string; + * } | string} [options] + * @param {(err?: Error) => any} callback + * @returns {void} + */ function appendFile(path, data, options, callback) { callback = maybeCallback(callback || options); options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' }); @@ -1578,6 +2182,17 @@ function appendFile(path, data, options, callback) { fs.writeFile(path, data, options, callback); } +/** + * Synchronously appends data to a file. + * @param {string | Buffer | URL | number} path + * @param {string | Buffer} data + * @param {{ + * encoding?: string | null; + * mode?: number; + * flag?: string; + * } | string} [options] + * @returns {void} + */ function appendFileSync(path, data, options) { options = getOptions(options, { encoding: 'utf8', mode: 0o666, flag: 'a' }); @@ -1591,6 +2206,21 @@ function appendFileSync(path, data, options) { fs.writeFileSync(path, data, options); } +/** + * Watches for the changes on `filename`. + * @param {string | Buffer | URL} filename + * @param {string | { + * persistent?: boolean; + * recursive?: boolean; + * encoding?: string; + * signal?: AbortSignal; + * }} [options] + * @param {( + * eventType?: string, + * filename?: string | Buffer + * ) => any} [listener] + * @returns {watchers.FSWatcher} + */ function watch(filename, options, listener) { if (typeof options === 'function') { listener = options; @@ -1633,6 +2263,20 @@ function watch(filename, options, listener) { const statWatchers = new SafeMap(); +/** + * Watches for changes on `filename`. + * @param {string | Buffer | URL} filename + * @param {{ + * bigint?: boolean; + * persistent?: boolean; + * interval?: number; + * }} [options] + * @param {( + * current?: Stats, + * previous?: Stats + * ) => any} listener + * @returns {watchers.StatWatcher} + */ function watchFile(filename, options, listener) { filename = getValidatedPath(filename); filename = pathModule.resolve(filename); @@ -1671,6 +2315,12 @@ function watchFile(filename, options, listener) { return stat; } +/** + * Stops watching for changes on `filename`. + * @param {string | Buffer | URL} filename + * @param {() => any} [listener] + * @returns {void} + */ function unwatchFile(filename, listener) { filename = getValidatedPath(filename); filename = pathModule.resolve(filename); @@ -1743,6 +2393,13 @@ if (isWindows) { } const emptyObj = ObjectCreate(null); + +/** + * Returns the resolved pathname. + * @param {string | Buffer | URL} p + * @param {string | { encoding?: string | null; }} [options] + * @returns {string | Buffer} + */ function realpathSync(p, options) { options = getOptions(options, emptyObj); p = toPathIfFileURL(p); @@ -1874,7 +2531,12 @@ function realpathSync(p, options) { return encodeRealpathResult(p, options); } - +/** + * Returns the resolved pathname. + * @param {string | Buffer | URL} p + * @param {string | { encoding?: string; }} [options] + * @returns {string | Buffer} + */ realpathSync.native = (path, options) => { options = getOptions(options, {}); path = getValidatedPath(path); @@ -1884,7 +2546,17 @@ realpathSync.native = (path, options) => { return result; }; - +/** + * Asynchronously computes the canonical pathname by + * resolving `.`, `..` and symbolic links. + * @param {string | Buffer | URL} p + * @param {string | { encoding?: string; }} [options] + * @param {( + * err?: Error, + * resolvedPath?: string | Buffer + * ) => any} callback + * @returns {void} + */ function realpath(p, options, callback) { callback = typeof options === 'function' ? options : maybeCallback(callback); options = getOptions(options, {}); @@ -2012,7 +2684,17 @@ function realpath(p, options, callback) { } } - +/** + * Asynchronously computes the canonical pathname by + * resolving `.`, `..` and symbolic links. + * @param {string | Buffer | URL} p + * @param {string | { encoding?: string; }} [options] + * @param {( + * err?: Error, + * resolvedPath?: string | Buffer + * ) => any} callback + * @returns {void} + */ realpath.native = (path, options, callback) => { callback = makeCallback(callback || options); options = getOptions(options, {}); @@ -2022,6 +2704,16 @@ realpath.native = (path, options, callback) => { return binding.realpath(path, options.encoding, req); }; +/** + * Creates a unique temporary directory. + * @param {string} prefix + * @param {string | { encoding?: string; }} [options] + * @param {( + * err?: Error, + * directory?: string + * ) => any} callback + * @returns {void} + */ function mkdtemp(prefix, options, callback) { callback = makeCallback(typeof options === 'function' ? options : callback); options = getOptions(options, {}); @@ -2035,7 +2727,12 @@ function mkdtemp(prefix, options, callback) { binding.mkdtemp(`${prefix}XXXXXX`, options.encoding, req); } - +/** + * Synchronously creates a unique temporary directory. + * @param {string} prefix + * @param {string | { encoding?: string; }} [options] + * @returns {string} + */ function mkdtempSync(prefix, options) { options = getOptions(options, {}); if (!prefix || typeof prefix !== 'string') { @@ -2051,7 +2748,15 @@ function mkdtempSync(prefix, options) { return result; } - +/** + * Asynchronously copies `src` to `dest`. By + * default, `dest` is overwritten if it already exists. + * @param {string | Buffer | URL} src + * @param {string | Buffer | URL} dest + * @param {number} [mode] + * @param {() => any} callback + * @returns {void} + */ function copyFile(src, dest, mode, callback) { if (typeof mode === 'function') { callback = mode; @@ -2071,7 +2776,14 @@ function copyFile(src, dest, mode, callback) { binding.copyFile(src, dest, mode, req); } - +/** + * Synchronously copies `src` to `dest`. By + * default, `dest` is overwritten if it already exists. + * @param {string | Buffer | URL} src + * @param {string | Buffer | URL} dest + * @param {number} [mode] + * @returns {void} + */ function copyFileSync(src, dest, mode) { src = getValidatedPath(src, 'src'); dest = getValidatedPath(dest, 'dest'); @@ -2093,11 +2805,44 @@ function lazyLoadStreams() { } } +/** + * Creates a readable stream with a default `highWaterMark` + * of 64 kb. + * @param {string | Buffer | URL} path + * @param {string | { + * flags?: string; + * encoding?: string; + * fd?: number | FileHandle; + * mode?: number; + * autoClose?: boolean; + * emitClose?: boolean; + * start: number; + * end?: number; + * highWaterMark?: number; + * fs?: Object | null; + * }} [options] + * @returns {ReadStream} + */ function createReadStream(path, options) { lazyLoadStreams(); return new ReadStream(path, options); } +/** + * Creates a write stream. + * @param {string | Buffer | URL} path + * @param {string | { + * flags?: string; + * encoding?: string; + * fd?: number | FileHandle; + * mode?: number; + * autoClose?: boolean; + * emitClose?: boolean; + * start: number; + * fs?: Object | null; + * }} [options] + * @returns {WriteStream} + */ function createWriteStream(path, options) { lazyLoadStreams(); return new WriteStream(path, options); diff --git a/lib/internal/async_hooks.js b/lib/internal/async_hooks.js index b8955f644d15d7..eac2471ff79fb2 100644 --- a/lib/internal/async_hooks.js +++ b/lib/internal/async_hooks.js @@ -5,7 +5,6 @@ const { ErrorCaptureStackTrace, ObjectPrototypeHasOwnProperty, ObjectDefineProperty, - Promise, Symbol, } = primordials; @@ -53,7 +52,7 @@ const { clearAsyncIdStack, } = async_wrap; // For performance reasons, only track Promises when a hook is enabled. -const { enablePromiseHook, disablePromiseHook } = async_wrap; +const { enablePromiseHook, disablePromiseHook, setPromiseHooks } = async_wrap; // Properties in active_hooks are used to keep track of the set of hooks being // executed in case another hook is enabled/disabled. The new set of hooks is // then restored once the active set of hooks is finished executing. @@ -303,53 +302,50 @@ function restoreActiveHooks() { active_hooks.tmp_fields = null; } -function trackPromise(promise, parent, silent) { - const asyncId = getOrSetAsyncId(promise); +function trackPromise(promise, parent) { + if (promise[async_id_symbol]) { + return; + } + promise[async_id_symbol] = newAsyncId(); promise[trigger_async_id_symbol] = parent ? getOrSetAsyncId(parent) : getDefaultTriggerAsyncId(); +} - if (!silent && initHooksExist()) { - const triggerId = promise[trigger_async_id_symbol]; - emitInitScript(asyncId, 'PROMISE', triggerId, promise); - } +function promiseInitHook(promise, parent) { + trackPromise(promise, parent); + const asyncId = promise[async_id_symbol]; + const triggerAsyncId = promise[trigger_async_id_symbol]; + emitInitScript(asyncId, 'PROMISE', triggerAsyncId, promise); } -function fastPromiseHook(type, promise, parent) { - if (type === kInit || !promise[async_id_symbol]) { - const silent = type !== kInit; - if (parent instanceof Promise) { - trackPromise(promise, parent, silent); - } else { - trackPromise(promise, null, silent); - } +function promiseBeforeHook(promise) { + trackPromise(promise); + const asyncId = promise[async_id_symbol]; + const triggerId = promise[trigger_async_id_symbol]; + emitBeforeScript(asyncId, triggerId, promise); +} - if (!silent) return; +function promiseAfterHook(promise) { + trackPromise(promise); + const asyncId = promise[async_id_symbol]; + if (hasHooks(kAfter)) { + emitAfterNative(asyncId); } + if (asyncId === executionAsyncId()) { + // This condition might not be true if async_hooks was enabled during + // the promise callback execution. + // Popping it off the stack can be skipped in that case, because it is + // known that it would correspond to exactly one call with + // PromiseHookType::kBefore that was not witnessed by the PromiseHook. + popAsyncContext(asyncId); + } +} +function promiseResolveHook(promise) { + trackPromise(promise); const asyncId = promise[async_id_symbol]; - switch (type) { - case kBefore: - const triggerId = promise[trigger_async_id_symbol]; - emitBeforeScript(asyncId, triggerId, promise); - break; - case kAfter: - if (hasHooks(kAfter)) { - emitAfterNative(asyncId); - } - if (asyncId === executionAsyncId()) { - // This condition might not be true if async_hooks was enabled during - // the promise callback execution. - // Popping it off the stack can be skipped in that case, because it is - // known that it would correspond to exactly one call with - // PromiseHookType::kBefore that was not witnessed by the PromiseHook. - popAsyncContext(asyncId); - } - break; - case kPromiseResolve: - emitPromiseResolveNative(asyncId); - break; - } + emitPromiseResolveNative(asyncId); } let wantPromiseHook = false; @@ -357,17 +353,17 @@ function enableHooks() { async_hook_fields[kCheck] += 1; } -let promiseHookMode = -1; function updatePromiseHookMode() { wantPromiseHook = true; if (destroyHooksExist()) { - if (promiseHookMode !== 1) { - promiseHookMode = 1; - enablePromiseHook(); - } - } else if (promiseHookMode !== 0) { - promiseHookMode = 0; - enablePromiseHook(fastPromiseHook); + enablePromiseHook(); + } else { + setPromiseHooks( + initHooksExist() ? promiseInitHook : undefined, + promiseBeforeHook, + promiseAfterHook, + promiseResolveHooksExist() ? promiseResolveHook : undefined, + ); } } @@ -383,8 +379,8 @@ function disableHooks() { function disablePromiseHookIfNecessary() { if (!wantPromiseHook) { - promiseHookMode = -1; disablePromiseHook(); + setPromiseHooks(undefined, undefined, undefined, undefined); } } @@ -458,6 +454,10 @@ function destroyHooksExist() { return hasHooks(kDestroy); } +function promiseResolveHooksExist() { + return hasHooks(kPromiseResolve); +} + function emitInitScript(asyncId, type, triggerAsyncId, resource) { // Short circuit all checks for the common case. Which is that no hooks have diff --git a/lib/internal/blob.js b/lib/internal/blob.js index b767426dcb2b7d..927b9f54046bf2 100644 --- a/lib/internal/blob.js +++ b/lib/internal/blob.js @@ -20,6 +20,8 @@ const { FixedSizeBlobCopyJob, } = internalBinding('buffer'); +const { TextDecoder } = require('internal/encoding'); + const { JSTransferable, kClone, diff --git a/lib/internal/bootstrap/node.js b/lib/internal/bootstrap/node.js index 46e0e967f79991..81a9547b9071bc 100644 --- a/lib/internal/bootstrap/node.js +++ b/lib/internal/bootstrap/node.js @@ -107,8 +107,10 @@ const deprecationHandler = { get(target, key, receiver) { const val = ReflectGet(target, key, receiver); - if (val != null && typeof val === 'object') + if (val != null && typeof val === 'object') { + // eslint-disable-next-line node-core/prefer-primordials return new Proxy(val, deprecationHandler); + } return val; }, @@ -118,6 +120,7 @@ const deprecationHandler = { } }; +// eslint-disable-next-line node-core/prefer-primordials let processConfig = new Proxy( JSONParse(nativeModule.config), deprecationHandler); diff --git a/lib/internal/console/constructor.js b/lib/internal/console/constructor.js index c3716a8acda8b5..22b84e5e42b956 100644 --- a/lib/internal/console/constructor.js +++ b/lib/internal/console/constructor.js @@ -429,7 +429,10 @@ const consoleMethods = { if (this._stdout.isTTY && process.env.TERM !== 'dumb') { // The require is here intentionally to avoid readline being // required too early when console is first loaded. - const { cursorTo, clearScreenDown } = require('readline'); + const { + cursorTo, + clearScreenDown, + } = require('internal/readline/callbacks'); cursorTo(this._stdout, 0, 0); clearScreenDown(this._stdout); } diff --git a/lib/internal/crypto/diffiehellman.js b/lib/internal/crypto/diffiehellman.js index e2106b211ba01b..2e38e95ea1d774 100644 --- a/lib/internal/crypto/diffiehellman.js +++ b/lib/internal/crypto/diffiehellman.js @@ -122,9 +122,9 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) { generator = DH_GENERATOR; } else if (typeof generator === 'number') { validateInt32(generator, 'generator'); - } else if (generator !== true) { + } else if (typeof generator === 'string') { generator = toBuf(generator, genEncoding); - } else { + } else if (!isArrayBufferView(generator) && !isAnyArrayBuffer(generator)) { throw new ERR_INVALID_ARG_TYPE( 'generator', ['number', 'string', 'ArrayBuffer', 'Buffer', 'TypedArray', 'DataView'], diff --git a/lib/internal/crypto/keygen.js b/lib/internal/crypto/keygen.js index 6fc06936a4fb03..06490e24a9c24f 100644 --- a/lib/internal/crypto/keygen.js +++ b/lib/internal/crypto/keygen.js @@ -40,6 +40,7 @@ const { const { customPromisifyArgs } = require('internal/util'); const { + isInt32, isUint32, validateCallback, validateString, @@ -194,7 +195,7 @@ function createJob(mode, type, options) { throw new ERR_INVALID_ARG_VALUE('options.hash', hash); if (mgf1Hash !== undefined && typeof mgf1Hash !== 'string') throw new ERR_INVALID_ARG_VALUE('options.mgf1Hash', mgf1Hash); - if (saltLength !== undefined && !isUint32(saltLength)) + if (saltLength !== undefined && (!isInt32(saltLength) || saltLength < 0)) throw new ERR_INVALID_ARG_VALUE('options.saltLength', saltLength); return new RsaKeyPairGenJob( @@ -217,7 +218,7 @@ function createJob(mode, type, options) { let { divisorLength } = options; if (divisorLength == null) { divisorLength = -1; - } else if (!isUint32(divisorLength)) { + } else if (!isInt32(divisorLength) || divisorLength < 0) { throw new ERR_INVALID_ARG_VALUE('options.divisorLength', divisorLength); } @@ -292,7 +293,7 @@ function createJob(mode, type, options) { if (!isArrayBufferView(prime)) throw new ERR_INVALID_ARG_VALUE('options.prime', prime); } else if (primeLength != null) { - if (!isUint32(primeLength)) + if (!isInt32(primeLength) || primeLength < 0) throw new ERR_INVALID_ARG_VALUE('options.primeLength', primeLength); } else { throw new ERR_MISSING_OPTION( @@ -300,7 +301,7 @@ function createJob(mode, type, options) { } if (generator != null) { - if (!isUint32(generator)) + if (!isInt32(generator) || generator < 0) throw new ERR_INVALID_ARG_VALUE('options.generator', generator); } return new DhKeyPairGenJob( diff --git a/lib/internal/crypto/scrypt.js b/lib/internal/crypto/scrypt.js index 458723df28ffca..45a04905bfd447 100644 --- a/lib/internal/crypto/scrypt.js +++ b/lib/internal/crypto/scrypt.js @@ -16,6 +16,7 @@ const { const { validateCallback, validateInteger, + validateInt32, validateUint32, } = require('internal/validators'); @@ -90,7 +91,7 @@ function check(password, salt, keylen, options) { password = getArrayBufferOrView(password, 'password'); salt = getArrayBufferOrView(salt, 'salt'); - validateUint32(keylen, 'keylen'); + validateInt32(keylen, 'keylen', 0); let { N, r, p, maxmem } = defaults; if (options && options !== defaults) { diff --git a/lib/internal/crypto/util.js b/lib/internal/crypto/util.js index 3c96f34f90e97e..8343940b99e169 100644 --- a/lib/internal/crypto/util.js +++ b/lib/internal/crypto/util.js @@ -305,7 +305,7 @@ function jobPromise(job) { // number of leading zero bits. Our conventional APIs for reading // an unsigned int from a Buffer are not adequate. The implementation // here is adapted from the chromium implementation here: -// https://github.com/chromium/chromium/blob/master/third_party/blink/public/platform/web_crypto_algorithm_params.h, but ported to JavaScript +// https://github.com/chromium/chromium/blob/HEAD/third_party/blink/public/platform/web_crypto_algorithm_params.h, but ported to JavaScript // Returns undefined if the conversion was unsuccessful. function bigIntArrayToUnsignedInt(input) { let result = 0; diff --git a/lib/internal/crypto/webcrypto.js b/lib/internal/crypto/webcrypto.js index 47c34b9ca0d665..b28ee9b8167be5 100644 --- a/lib/internal/crypto/webcrypto.js +++ b/lib/internal/crypto/webcrypto.js @@ -26,7 +26,7 @@ const { validateString, } = require('internal/validators'); -const { TextDecoder } = require('internal/encoding'); +const { TextDecoder, TextEncoder } = require('internal/encoding'); const { codes: { diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index ca73559c3eb0cf..ea613966980c96 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -15,11 +15,11 @@ // SPDX-License-Identifier: Apache-2.0 // Based upon: -// https://github.com/google/caja/blob/master/src/com/google/caja/ses/startSES.js -// https://github.com/google/caja/blob/master/src/com/google/caja/ses/repairES5.js +// https://github.com/google/caja/blob/HEAD/src/com/google/caja/ses/startSES.js +// https://github.com/google/caja/blob/HEAD/src/com/google/caja/ses/repairES5.js // https://github.com/tc39/proposal-ses/blob/e5271cc42a257a05dcae2fd94713ed2f46c08620/shim/src/freeze.js -/* global WebAssembly, SharedArrayBuffer, console */ +/* global console */ 'use strict'; const { @@ -78,6 +78,7 @@ const { ObjectPrototypeHasOwnProperty, Promise, PromisePrototype, + Proxy, RangeError, RangeErrorPrototype, ReferenceError, @@ -124,6 +125,13 @@ const { globalThis, } = primordials; +const { + Atomics, + Intl, + SharedArrayBuffer, + WebAssembly +} = globalThis; + module.exports = function() { const { clearImmediate, diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 6ec895f1a0c556..7a575e69491e38 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -10,6 +10,7 @@ const { PromisePrototypeFinally, PromisePrototypeThen, PromiseResolve, + PromiseReject, SafeArrayIterator, Symbol, Uint8Array, @@ -33,6 +34,7 @@ const { ERR_METHOD_NOT_IMPLEMENTED, }, AbortError, + aggregateTwoErrors, } = require('internal/errors'); const { isArrayBufferView } = require('internal/util/types'); const { rimrafPromises } = require('internal/fs/rimraf'); @@ -78,6 +80,7 @@ const { promisify } = require('internal/util'); const { EventEmitterMixin } = require('internal/event_target'); const { watch } = require('internal/fs/watchers'); const { isIterable } = require('internal/streams/utils'); +const assert = require('internal/assert'); const kHandle = Symbol('kHandle'); const kFd = Symbol('kFd'); @@ -250,10 +253,22 @@ class FileHandle extends EventEmitterMixin(JSTransferable) { } } +async function handleFdClose(fileOpPromise, closeFunc) { + return PromisePrototypeThen( + fileOpPromise, + (result) => PromisePrototypeThen(closeFunc(), () => result), + (opError) => + PromisePrototypeThen( + closeFunc(), + () => PromiseReject(opError), + (closeError) => PromiseReject(aggregateTwoErrors(closeError, opError)) + ) + ); +} + async function fsCall(fn, handle, ...args) { - if (handle[kRefs] === undefined) { - throw new ERR_INVALID_ARG_TYPE('filehandle', 'FileHandle', handle); - } + assert(handle[kRefs] !== undefined, + 'handle must be an instance of FileHandle'); if (handle.fd === -1) { // eslint-disable-next-line no-restricted-syntax @@ -417,7 +432,7 @@ async function read(handle, bufferOrOptions, offset, length, position) { if (offset == null) { offset = 0; } else { - validateInteger(offset, 'offset'); + validateInteger(offset, 'offset', 0); } length |= 0; @@ -460,7 +475,7 @@ async function write(handle, buffer, offset, length, position) { if (offset == null) { offset = 0; } else { - validateInteger(offset, 'offset'); + validateInteger(offset, 'offset', 0); } if (typeof length !== 'number') length = buffer.byteLength - offset; @@ -501,7 +516,7 @@ async function rename(oldPath, newPath) { async function truncate(path, len = 0) { const fd = await open(path, 'r+'); - return PromisePrototypeFinally(ftruncate(fd, len), fd.close); + return handleFdClose(ftruncate(fd, len), fd.close); } async function ftruncate(handle, len = 0) { @@ -632,7 +647,7 @@ async function lchmod(path, mode) { throw new ERR_METHOD_NOT_IMPLEMENTED('lchmod()'); const fd = await open(path, O_WRONLY | O_SYMLINK); - return PromisePrototypeFinally(fchmod(fd, mode), fd.close); + return handleFdClose(fchmod(fd, mode), fd.close); } async function lchown(path, uid, gid) { @@ -711,7 +726,7 @@ async function writeFile(path, data, options) { checkAborted(options.signal); const fd = await open(path, flag, options.mode); - return PromisePrototypeFinally( + return handleFdClose( writeFileHandle(fd, data, options.signal, options.encoding), fd.close); } @@ -736,7 +751,7 @@ async function readFile(path, options) { checkAborted(options.signal); const fd = await open(path, flag, 0o666); - return PromisePrototypeFinally(readFileHandle(fd, options), fd.close); + return handleFdClose(readFileHandle(fd, options), fd.close); } module.exports = { diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 57c2304fca82cc..b388bad80c74a5 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -255,6 +255,10 @@ ReadStream.prototype._read = function(n) { if (er) { errorOrDestroy(this, er); } else if (bytesRead > 0) { + if (this.pos !== undefined) { + this.pos += bytesRead; + } + this.bytesRead += bytesRead; if (bytesRead !== buf.length) { @@ -271,10 +275,6 @@ ReadStream.prototype._read = function(n) { this.push(null); } }); - - if (this.pos !== undefined) { - this.pos += n; - } }; ReadStream.prototype._destroy = function(err, cb) { diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index bf4d8457531c0b..3b7754292821f3 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -655,6 +655,10 @@ const validateOffsetLengthWrite = hideStackFrames( if (length > byteLength - offset) { throw new ERR_OUT_OF_RANGE('length', `<= ${byteLength - offset}`, length); } + + if (length < 0) { + throw new ERR_OUT_OF_RANGE('length', '>= 0', length); + } } ); diff --git a/lib/internal/http2/compat.js b/lib/internal/http2/compat.js index 4795e59581d993..a1ee6cdbbc7777 100644 --- a/lib/internal/http2/compat.js +++ b/lib/internal/http2/compat.js @@ -9,6 +9,7 @@ const { ObjectCreate, ObjectKeys, ObjectPrototypeHasOwnProperty, + Proxy, ReflectApply, ReflectGetPrototypeOf, StringPrototypeIncludes, diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 5427f74a5f2b59..1654f2460cdd5a 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -18,6 +18,7 @@ const { ObjectPrototypeHasOwnProperty, Promise, PromisePrototypeCatch, + Proxy, ReflectApply, ReflectGet, ReflectGetPrototypeOf, diff --git a/lib/internal/inspector/_inspect.js b/lib/internal/inspector/_inspect.js new file mode 100644 index 00000000000000..f695fd53f1fda6 --- /dev/null +++ b/lib/internal/inspector/_inspect.js @@ -0,0 +1,383 @@ +/* + * Copyright Node.js contributors. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +// TODO(aduh95): remove restricted syntax errors +/* eslint-disable no-restricted-syntax */ + +'use strict'; + +const { + ArrayPrototypeConcat, + ArrayPrototypeForEach, + ArrayPrototypeJoin, + ArrayPrototypeMap, + ArrayPrototypePop, + ArrayPrototypeShift, + ArrayPrototypeSlice, + Error, + FunctionPrototypeBind, + Number, + Promise, + PromisePrototypeCatch, + PromisePrototypeThen, + PromiseResolve, + Proxy, + RegExpPrototypeSymbolMatch, + RegExpPrototypeSymbolSplit, + RegExpPrototypeTest, + StringPrototypeEndsWith, + StringPrototypeSplit, +} = primordials; + +const { spawn } = require('child_process'); +const { EventEmitter } = require('events'); +const net = require('net'); +const util = require('util'); +const { + setInterval, + setTimeout, +} = require('timers/promises'); +const { + AbortController, +} = require('internal/abort_controller'); + +// TODO(aduh95): remove console calls +const console = require('internal/console/global'); + +const { 0: InspectClient, 1: createRepl } = + [ + require('internal/inspector/inspect_client'), + require('internal/inspector/inspect_repl'), + ]; + +const debuglog = util.debuglog('inspect'); + +class StartupError extends Error { + constructor(message) { + super(message); + this.name = 'StartupError'; + } +} + +async function portIsFree(host, port, timeout = 9999) { + if (port === 0) return; // Binding to a random port. + + const retryDelay = 150; + const ac = new AbortController(); + const { signal } = ac; + + setTimeout(timeout).then(() => ac.abort()); + + // eslint-disable-next-line no-unused-vars + for await (const _ of setInterval(retryDelay)) { + if (signal.aborted) { + throw new StartupError( + `Timeout (${timeout}) waiting for ${host}:${port} to be free`); + } + const error = await new Promise((resolve) => { + const socket = net.connect(port, host); + socket.on('error', resolve); + socket.on('connect', resolve); + }); + if (error?.code === 'ECONNREFUSED') { + return; + } + } +} + +const debugRegex = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//; +async function runScript(script, scriptArgs, inspectHost, inspectPort, + childPrint) { + await portIsFree(inspectHost, inspectPort); + const args = ArrayPrototypeConcat( + [`--inspect-brk=${inspectPort}`, script], + scriptArgs); + const child = spawn(process.execPath, args); + child.stdout.setEncoding('utf8'); + child.stderr.setEncoding('utf8'); + child.stdout.on('data', (chunk) => childPrint(chunk, 'stdout')); + child.stderr.on('data', (chunk) => childPrint(chunk, 'stderr')); + + let output = ''; + return new Promise((resolve) => { + function waitForListenHint(text) { + output += text; + const debug = RegExpPrototypeSymbolMatch(debugRegex, output); + if (debug) { + const host = debug[1]; + const port = Number(debug[2]); + child.stderr.removeListener('data', waitForListenHint); + resolve([child, port, host]); + } + } + + child.stderr.on('data', waitForListenHint); + }); +} + +function createAgentProxy(domain, client) { + const agent = new EventEmitter(); + agent.then = (then, _catch) => { + // TODO: potentially fetch the protocol and pretty-print it here. + const descriptor = { + [util.inspect.custom](depth, { stylize }) { + return stylize(`[Agent ${domain}]`, 'special'); + }, + }; + return PromisePrototypeThen(PromiseResolve(descriptor), then, _catch); + }; + + return new Proxy(agent, { + get(target, name) { + if (name in target) return target[name]; + return function callVirtualMethod(params) { + return client.callMethod(`${domain}.${name}`, params); + }; + }, + }); +} + +class NodeInspector { + constructor(options, stdin, stdout) { + this.options = options; + this.stdin = stdin; + this.stdout = stdout; + + this.paused = true; + this.child = null; + + if (options.script) { + this._runScript = FunctionPrototypeBind( + runScript, null, + options.script, + options.scriptArgs, + options.host, + options.port, + FunctionPrototypeBind(this.childPrint, this)); + } else { + this._runScript = + () => PromiseResolve([null, options.port, options.host]); + } + + this.client = new InspectClient(); + + this.domainNames = ['Debugger', 'HeapProfiler', 'Profiler', 'Runtime']; + ArrayPrototypeForEach(this.domainNames, (domain) => { + this[domain] = createAgentProxy(domain, this.client); + }); + this.handleDebugEvent = (fullName, params) => { + const { 0: domain, 1: name } = StringPrototypeSplit(fullName, '.'); + if (domain in this) { + this[domain].emit(name, params); + } + }; + this.client.on('debugEvent', this.handleDebugEvent); + const startRepl = createRepl(this); + + // Handle all possible exits + process.on('exit', () => this.killChild()); + const exitCodeZero = () => process.exit(0); + process.once('SIGTERM', exitCodeZero); + process.once('SIGHUP', exitCodeZero); + + PromisePrototypeCatch(PromisePrototypeThen(this.run(), () => { + const repl = startRepl(); + this.repl = repl; + this.repl.on('exit', exitCodeZero); + this.paused = false; + }), (error) => process.nextTick(() => { throw error; })); + } + + suspendReplWhile(fn) { + if (this.repl) { + this.repl.pause(); + } + this.stdin.pause(); + this.paused = true; + return PromisePrototypeCatch(PromisePrototypeThen(new Promise((resolve) => { + resolve(fn()); + }), () => { + this.paused = false; + if (this.repl) { + this.repl.resume(); + this.repl.displayPrompt(); + } + this.stdin.resume(); + }), (error) => process.nextTick(() => { throw error; })); + } + + killChild() { + this.client.reset(); + if (this.child) { + this.child.kill(); + this.child = null; + } + } + + async run() { + this.killChild(); + + const { 0: child, 1: port, 2: host } = await this._runScript(); + this.child = child; + + this.print(`connecting to ${host}:${port} ..`, false); + for (let attempt = 0; attempt < 5; attempt++) { + debuglog('connection attempt #%d', attempt); + this.stdout.write('.'); + try { + await this.client.connect(port, host); + debuglog('connection established'); + this.stdout.write(' ok\n'); + return; + } catch (error) { + debuglog('connect failed', error); + await setTimeout(1000); + } + } + this.stdout.write(' failed to connect, please retry\n'); + process.exit(1); + } + + clearLine() { + if (this.stdout.isTTY) { + this.stdout.cursorTo(0); + this.stdout.clearLine(1); + } else { + this.stdout.write('\b'); + } + } + + print(text, appendNewline = false) { + this.clearLine(); + this.stdout.write(appendNewline ? `${text}\n` : text); + } + + #stdioBuffers = { stdout: '', stderr: '' }; + childPrint(text, which) { + const lines = RegExpPrototypeSymbolSplit( + /\r\n|\r|\n/g, + this.#stdioBuffers[which] + text); + + this.#stdioBuffers[which] = ''; + + if (lines[lines.length - 1] !== '') { + this.#stdioBuffers[which] = ArrayPrototypePop(lines); + } + + const textToPrint = ArrayPrototypeJoin( + ArrayPrototypeMap(lines, (chunk) => `< ${chunk}`), + '\n'); + + if (lines.length) { + this.print(textToPrint, true); + if (!this.paused) { + this.repl.displayPrompt(true); + } + } + + if (StringPrototypeEndsWith( + textToPrint, + 'Waiting for the debugger to disconnect...\n' + )) { + this.killChild(); + } + } +} + +function parseArgv(args) { + const target = ArrayPrototypeShift(args); + let host = '127.0.0.1'; + let port = 9229; + let isRemote = false; + let script = target; + let scriptArgs = args; + + const hostMatch = RegExpPrototypeSymbolMatch(/^([^:]+):(\d+)$/, target); + const portMatch = RegExpPrototypeSymbolMatch(/^--port=(\d+)$/, target); + + if (hostMatch) { + // Connecting to remote debugger + host = hostMatch[1]; + port = Number(hostMatch[2]); + isRemote = true; + script = null; + } else if (portMatch) { + // Start on custom port + port = Number(portMatch[1]); + script = args[0]; + scriptArgs = ArrayPrototypeSlice(args, 1); + } else if (args.length === 1 && RegExpPrototypeTest(/^\d+$/, args[0]) && + target === '-p') { + // Start debugger against a given pid + const pid = Number(args[0]); + try { + process._debugProcess(pid); + } catch (e) { + if (e.code === 'ESRCH') { + console.error(`Target process: ${pid} doesn't exist.`); + process.exit(1); + } + throw e; + } + script = null; + isRemote = true; + } + + return { + host, port, isRemote, script, scriptArgs, + }; +} + +function startInspect(argv = ArrayPrototypeSlice(process.argv, 2), + stdin = process.stdin, + stdout = process.stdout) { + if (argv.length < 1) { + const invokedAs = `${process.argv0} ${process.argv[1]}`; + + console.error(`Usage: ${invokedAs} script.js`); + console.error(` ${invokedAs} :`); + console.error(` ${invokedAs} --port=`); + console.error(` ${invokedAs} -p `); + process.exit(1); + } + + const options = parseArgv(argv); + const inspector = new NodeInspector(options, stdin, stdout); + + stdin.resume(); + + function handleUnexpectedError(e) { + if (!(e instanceof StartupError)) { + console.error('There was an internal error in Node.js. ' + + 'Please report this bug.'); + console.error(e.message); + console.error(e.stack); + } else { + console.error(e.message); + } + if (inspector.child) inspector.child.kill(); + process.exit(1); + } + + process.on('uncaughtException', handleUnexpectedError); +} +exports.start = startInspect; diff --git a/deps/node-inspect/lib/internal/inspect_client.js b/lib/internal/inspector/inspect_client.js similarity index 87% rename from deps/node-inspect/lib/internal/inspect_client.js rename to lib/internal/inspector/inspect_client.js index 9b8529de21aae2..ba1e9bc30ce5ce 100644 --- a/deps/node-inspect/lib/internal/inspect_client.js +++ b/lib/internal/inspector/inspect_client.js @@ -19,15 +19,29 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ + +// TODO(aduh95): use errors exported by the internal/errors module +/* eslint-disable no-restricted-syntax */ + 'use strict'; + +const { + ArrayPrototypePush, + Error, + ErrorCaptureStackTrace, + FunctionPrototypeBind, + JSONParse, + JSONStringify, + ObjectKeys, + Promise, +} = primordials; + const Buffer = require('buffer').Buffer; -const crypto = require('crypto'); const { EventEmitter } = require('events'); const http = require('http'); const URL = require('url'); -const util = require('util'); -const debuglog = util.debuglog('inspect'); +const debuglog = require('internal/util/debuglog').debuglog('inspect'); const kOpCodeText = 0x1; const kOpCodeClose = 0x8; @@ -46,14 +60,10 @@ const kTwoBytePayloadLengthField = 126; const kEightBytePayloadLengthField = 127; const kMaskingKeyWidthInBytes = 4; -function isEmpty(obj) { - return Object.keys(obj).length === 0; -} - function unpackError({ code, message, data }) { const err = new Error(`${message} - ${data}`); err.code = code; - Error.captureStackTrace(err, unpackError); + ErrorCaptureStackTrace(err, unpackError); return err; } @@ -166,7 +176,7 @@ function decodeFrameHybi17(data) { class Client extends EventEmitter { constructor() { super(); - this.handleChunk = this._handleChunk.bind(this); + this.handleChunk = FunctionPrototypeBind(this._handleChunk, this); this._port = undefined; this._host = undefined; @@ -189,7 +199,7 @@ class Client extends EventEmitter { this.reset(); return; } - if (payloadBuffer === null) break; + if (payloadBuffer === null || payloadBuffer.length === 0) break; const payloadStr = payloadBuffer.toString(); debuglog('< %s', payloadStr); @@ -199,7 +209,7 @@ class Client extends EventEmitter { } let payload; try { - payload = JSON.parse(payloadStr); + payload = JSONParse(payloadStr); } catch (parseError) { parseError.string = payloadStr; throw parseError; @@ -225,6 +235,9 @@ class Client extends EventEmitter { if (this._http) { this._http.destroy(); } + if (this._socket) { + this._socket.destroy(); + } this._http = null; this._lastId = 0; this._socket = null; @@ -241,9 +254,9 @@ class Client extends EventEmitter { const data = { id: ++this._lastId, method, params }; this._pending[data.id] = (error, result) => { if (error) reject(unpackError(error)); - else resolve(isEmpty(result) ? undefined : result); + else resolve(ObjectKeys(result).length ? result : undefined); }; - const json = JSON.stringify(data); + const json = JSONStringify(data); debuglog('> %s', json); this._socket.write(encodeFrameHybi17(Buffer.from(json))); }); @@ -267,15 +280,15 @@ class Client extends EventEmitter { return; } try { - resolve(JSON.parse(resBody)); - } catch (parseError) { + resolve(JSONParse(resBody)); + } catch { reject(new Error(`Response didn't contain JSON: ${resBody}`)); - return; + } } httpRes.on('error', reject); - httpRes.on('data', (chunk) => chunks.push(chunk)); + httpRes.on('data', (chunk) => ArrayPrototypePush(chunks, chunk)); httpRes.on('end', parseChunks); } @@ -284,23 +297,22 @@ class Client extends EventEmitter { }); } - connect(port, host) { + async connect(port, host) { this._port = port; this._host = host; - return this._discoverWebsocketPath() - .then((urlPath) => this._connectWebsocket(urlPath)); + const urlPath = await this._discoverWebsocketPath(); + return this._connectWebsocket(urlPath); } - _discoverWebsocketPath() { - return this._fetchJSON('/json') - .then(([{ webSocketDebuggerUrl }]) => - URL.parse(webSocketDebuggerUrl).path); + async _discoverWebsocketPath() { + const { 0: { webSocketDebuggerUrl } } = await this._fetchJSON('/json'); + return URL.parse(webSocketDebuggerUrl).path; } _connectWebsocket(urlPath) { this.reset(); - const key1 = crypto.randomBytes(16).toString('base64'); + const key1 = require('crypto').randomBytes(16).toString('base64'); debuglog('request websocket', key1); const httpReq = this._http = http.request({ @@ -308,8 +320,8 @@ class Client extends EventEmitter { port: this._port, path: urlPath, headers: { - Connection: 'Upgrade', - Upgrade: 'websocket', + 'Connection': 'Upgrade', + 'Upgrade': 'websocket', 'Sec-WebSocket-Key': key1, 'Sec-WebSocket-Version': '13', }, diff --git a/deps/node-inspect/lib/internal/inspect_repl.js b/lib/internal/inspector/inspect_repl.js similarity index 91% rename from deps/node-inspect/lib/internal/inspect_repl.js rename to lib/internal/inspector/inspect_repl.js index bfbedf66a71b79..1b23196b2138de 100644 --- a/deps/node-inspect/lib/internal/inspect_repl.js +++ b/lib/internal/inspector/inspect_repl.js @@ -19,15 +19,21 @@ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ + +// TODO(trott): enable ESLint +/* eslint-disable getter-return, no-restricted-syntax, + node-core/prefer-primordials */ + 'use strict'; const FS = require('fs'); const Path = require('path'); const Repl = require('repl'); -const util = require('util'); const vm = require('vm'); -const fileURLToPath = require('url').fileURLToPath; +const { fileURLToPath } = require('internal/url'); -const debuglog = util.debuglog('inspect'); +const { customInspectSymbol } = require('internal/util'); +const { inspect: utilInspect } = require('internal/util/inspect'); +const debuglog = require('internal/util/debuglog').debuglog('inspect'); const SHORTCUTS = { cont: 'c', @@ -86,11 +92,11 @@ function extractFunctionName(description) { } const PUBLIC_BUILTINS = require('module').builtinModules; -const NATIVES = PUBLIC_BUILTINS ? process.binding('natives') : {}; +const NATIVES = PUBLIC_BUILTINS ? internalBinding('natives') : {}; function isNativeUrl(url) { url = url.replace(/\.js$/, ''); if (PUBLIC_BUILTINS) { - if (url.startsWith('internal/') || PUBLIC_BUILTINS.includes(url)) + if (url.startsWith('node:internal/') || PUBLIC_BUILTINS.includes(url)) return true; } @@ -165,12 +171,12 @@ class RemoteObject { } } - [util.inspect.custom](depth, opts) { + [customInspectSymbol](depth, opts) { function formatProperty(prop) { switch (prop.type) { case 'string': case 'undefined': - return util.inspect(prop.value, opts); + return utilInspect(prop.value, opts); case 'number': case 'boolean': @@ -179,7 +185,7 @@ class RemoteObject { case 'object': case 'symbol': if (prop.subtype === 'date') { - return util.inspect(new Date(prop.value), opts); + return utilInspect(new Date(prop.value), opts); } if (prop.subtype === 'array') { return opts.stylize(prop.value, 'special'); @@ -195,7 +201,7 @@ class RemoteObject { case 'number': case 'string': case 'undefined': - return util.inspect(this.value, opts); + return utilInspect(this.value, opts); case 'symbol': return opts.stylize(this.description, 'special'); @@ -209,10 +215,10 @@ class RemoteObject { case 'object': switch (this.subtype) { case 'date': - return util.inspect(new Date(this.description), opts); + return utilInspect(new Date(this.description), opts); case 'null': - return util.inspect(null, opts); + return utilInspect(null, opts); case 'regexp': return opts.stylize(this.description, 'regexp'); @@ -260,11 +266,11 @@ class ScopeSnapshot { this.completionGroup = properties.map((prop) => prop.name); } - [util.inspect.custom](depth, opts) { + [customInspectSymbol](depth, opts) { const type = `${this.type[0].toUpperCase()}${this.type.slice(1)}`; const name = this.name ? `<${this.name}>` : ''; const prefix = `${type}${name} `; - return util.inspect(this.properties, opts) + return utilInspect(this.properties, opts) .replace(/^Map /, prefix); } } @@ -286,7 +292,7 @@ function aliasProperties(target, mapping) { function createRepl(inspector) { const { Debugger, HeapProfiler, Profiler, Runtime } = inspector; - let repl; // eslint-disable-line prefer-const + let repl; // Things we want to keep around const history = { control: [], debug: [] }; @@ -313,12 +319,12 @@ function createRepl(inspector) { const INSPECT_OPTIONS = { colors: inspector.stdout.isTTY }; function inspect(value) { - return util.inspect(value, INSPECT_OPTIONS); + return utilInspect(value, INSPECT_OPTIONS); } - function print(value, oneline = false) { + function print(value, addNewline = true) { const text = typeof value === 'string' ? value : inspect(value); - return inspector.print(text, oneline); + return inspector.print(text, addNewline); } function getCurrentLocation() { @@ -349,10 +355,11 @@ function createRepl(inspector) { }) .join('\n'); } + function listScripts(displayNatives = false) { print(formatScripts(displayNatives)); } - listScripts[util.inspect.custom] = function listWithoutInternal() { + listScripts[customInspectSymbol] = function listWithoutInternal() { return formatScripts(); }; @@ -368,9 +375,10 @@ function createRepl(inspector) { return p; } - [util.inspect.custom](depth, { stylize }) { + [customInspectSymbol](depth, { stylize }) { const { startTime, endTime } = this.data; - return stylize(`[Profile ${endTime - startTime}μs]`, 'special'); + const MU = String.fromChar(956); + return stylize(`[Profile ${endTime - startTime}${MU}s]`, 'special'); } save(filename = 'node.cpuprofile') { @@ -388,7 +396,7 @@ function createRepl(inspector) { this.delta = delta; } - [util.inspect.custom](depth, options) { + [customInspectSymbol](depth, options) { const { scriptId, lineNumber, columnNumber, delta, scriptSource } = this; const start = Math.max(1, lineNumber - delta + 1); const end = lineNumber + delta + 1; @@ -398,9 +406,9 @@ function createRepl(inspector) { const i = start + offset; const isCurrent = i === (lineNumber + 1); - const markedLine = isCurrent - ? markSourceColumn(lineText, columnNumber, options.colors) - : lineText; + const markedLine = isCurrent ? + markSourceColumn(lineText, columnNumber, options.colors) : + lineText; let isBreakpoint = false; knownBreakpoints.forEach(({ location }) => { @@ -454,7 +462,7 @@ function createRepl(inspector) { } class Backtrace extends Array { - [util.inspect.custom]() { + [customInspectSymbol]() { return this.map((callFrame, idx) => { const { location: { scriptId, lineNumber, columnNumber }, @@ -484,7 +492,7 @@ function createRepl(inspector) { function prepareControlCode(input) { if (input === '\n') return lastCommand; - // exec process.title => exec("process.title"); + // Add parentheses: exec process.title => exec("process.title"); const match = input.match(/^\s*exec\s+([^\n]*)/); if (match) { lastCommand = `exec(${JSON.stringify(match[1])})`; @@ -577,7 +585,7 @@ function createRepl(inspector) { const lines = watchedExpressions .map((expr, idx) => { const prefix = `${leftPad(idx, ' ', lastIndex)}: ${expr} =`; - const value = inspect(values[idx], { colors: true }); + const value = inspect(values[idx]); if (value.indexOf('\n') === -1) { return `${prefix} ${value}`; } @@ -674,13 +682,13 @@ function createRepl(inspector) { // setBreakpoint('fn()'): Break when a function is called if (script.endsWith('()')) { const debugExpr = `debug(${script.slice(0, -2)})`; - const debugCall = selectedFrame - ? Debugger.evaluateOnCallFrame({ + const debugCall = selectedFrame ? + Debugger.evaluateOnCallFrame({ callFrameId: selectedFrame.callFrameId, expression: debugExpr, includeCommandLineAPI: true, - }) - : Runtime.evaluate({ + }) : + Runtime.evaluate({ expression: debugExpr, includeCommandLineAPI: true, }); @@ -803,7 +811,7 @@ function createRepl(inspector) { inspector.suspendReplWhile(() => Promise.all([formatWatchers(true), selectedFrame.list(2)]) - .then(([watcherList, context]) => { + .then(({ 0: watcherList, 1: context }) => { if (watcherList) { return `${watcherList}\n${inspect(context)}`; } @@ -825,9 +833,7 @@ function createRepl(inspector) { Debugger.on('scriptParsed', (script) => { const { scriptId, url } = script; if (url) { - knownScripts[scriptId] = Object.assign({ - isNative: isNativeUrl(url), - }, script); + knownScripts[scriptId] = { isNative: isNativeUrl(url), ...script }; } }); @@ -835,7 +841,7 @@ function createRepl(inspector) { Profile.createAndRegister({ profile }); print([ 'Captured new CPU profile.', - `Access it with profiles[${profiles.length - 1}]` + `Access it with profiles[${profiles.length - 1}]`, ].join('\n')); }); @@ -924,14 +930,16 @@ function createRepl(inspector) { if (finished) { print('Heap snaphost prepared.'); } else { - print(`Heap snapshot: ${done}/${total}`, true); + print(`Heap snapshot: ${done}/${total}`, false); } } + function onChunk({ chunk }) { sizeWritten += chunk.length; writer.write(chunk); - print(`Writing snapshot: ${sizeWritten}`, true); + print(`Writing snapshot: ${sizeWritten}`, false); } + function onResolve() { writer.end(() => { teardown(); @@ -939,10 +947,12 @@ function createRepl(inspector) { resolve(); }); } + function onReject(error) { teardown(); reject(error); } + function teardown() { HeapProfiler.removeListener( 'reportHeapSnapshotProgress', onProgress); @@ -952,7 +962,7 @@ function createRepl(inspector) { HeapProfiler.on('reportHeapSnapshotProgress', onProgress); HeapProfiler.on('addHeapSnapshotChunk', onChunk); - print('Heap snapshot: 0/0', true); + print('Heap snapshot: 0/0', false); HeapProfiler.takeHeapSnapshot({ reportProgress: true }) .then(onResolve, onReject); }); @@ -1023,7 +1033,7 @@ function createRepl(inspector) { repl.setPrompt('> '); - print('Press Ctrl + C to leave debug repl'); + print('Press Ctrl+C to leave debug repl'); repl.displayPrompt(); }, @@ -1058,19 +1068,17 @@ function createRepl(inspector) { } function initAfterStart() { - const setupTasks = [ - Runtime.enable(), - Profiler.enable(), - Profiler.setSamplingInterval({ interval: 100 }), - Debugger.enable(), - Debugger.setPauseOnExceptions({ state: 'none' }), - Debugger.setAsyncCallStackDepth({ maxDepth: 0 }), - Debugger.setBlackboxPatterns({ patterns: [] }), - Debugger.setPauseOnExceptions({ state: pauseOnExceptionState }), - restoreBreakpoints(), - Runtime.runIfWaitingForDebugger(), - ]; - return Promise.all(setupTasks); + return Runtime.enable() + .then(() => Profiler.enable()) + .then(() => Profiler.setSamplingInterval({ interval: 100 })) + .then(() => Debugger.enable()) + .then(() => Debugger.setPauseOnExceptions({ state: 'none' })) + .then(() => Debugger.setAsyncCallStackDepth({ maxDepth: 0 })) + .then(() => Debugger.setBlackboxPatterns({ patterns: [] })) + .then(() => + Debugger.setPauseOnExceptions({ state: pauseOnExceptionState })) + .then(() => restoreBreakpoints()) + .then(() => Runtime.runIfWaitingForDebugger()); } return function startRepl() { @@ -1090,12 +1098,12 @@ function createRepl(inspector) { ignoreUndefined: true, }; - repl = Repl.start(replOptions); // eslint-disable-line prefer-const + repl = Repl.start(replOptions); initializeContext(repl.context); repl.on('reset', initializeContext); repl.defineCommand('interrupt', () => { - // We want this for testing purposes where sending CTRL-C can be tricky. + // We want this for testing purposes where sending Ctrl+C can be tricky. repl.emit('SIGINT'); }); diff --git a/lib/internal/main/inspect.js b/lib/internal/main/inspect.js index 4873683048cc79..d9dab0dc92b118 100644 --- a/lib/internal/main/inspect.js +++ b/lib/internal/main/inspect.js @@ -13,5 +13,5 @@ markBootstrapComplete(); // Start the debugger agent. process.nextTick(() => { - require('internal/deps/node-inspect/lib/_inspect').start(); + require('internal/inspector/_inspect').start(); }); diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js index cd092381eaef73..e22fd17fa2d214 100644 --- a/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js @@ -9,6 +9,7 @@ const { ArrayPrototypeSplice, ObjectDefineProperty, PromisePrototypeCatch, + globalThis: { Atomics }, } = primordials; const { diff --git a/lib/internal/modules/cjs/loader.js b/lib/internal/modules/cjs/loader.js index 61f6e9cb786e94..fbfc17ba6d1885 100644 --- a/lib/internal/modules/cjs/loader.js +++ b/lib/internal/modules/cjs/loader.js @@ -45,6 +45,7 @@ const { ObjectPrototype, ObjectPrototypeHasOwnProperty, ObjectSetPrototypeOf, + Proxy, ReflectApply, ReflectSet, RegExpPrototypeTest, diff --git a/lib/internal/modules/esm/translators.js b/lib/internal/modules/esm/translators.js index 43cc31c633c169..6d295089e42c70 100644 --- a/lib/internal/modules/esm/translators.js +++ b/lib/internal/modules/esm/translators.js @@ -1,7 +1,5 @@ 'use strict'; -/* global WebAssembly */ - const { ArrayPrototypeForEach, ArrayPrototypeMap, @@ -21,6 +19,7 @@ const { StringPrototypeSplit, StringPrototypeStartsWith, SyntaxErrorPrototype, + globalThis: { WebAssembly }, } = primordials; let _TYPES = null; @@ -63,6 +62,7 @@ const experimentalImportMetaResolve = getOptionValue('--experimental-import-meta-resolve'); const asyncESM = require('internal/process/esm_loader'); const { emitWarningSync } = require('internal/process/warning'); +const { TextDecoder } = require('internal/encoding'); let cjsParse; async function initCJSParse() { diff --git a/lib/internal/per_context/primordials.js b/lib/internal/per_context/primordials.js index f6832030381b6b..78f778b65703c5 100644 --- a/lib/internal/per_context/primordials.js +++ b/lib/internal/per_context/primordials.js @@ -137,6 +137,7 @@ function copyPrototype(src, dest, prefix) { // Create copies of configurable value properties of the global object [ + 'Proxy', 'globalThis', ].forEach((name) => { // eslint-disable-next-line no-restricted-globals @@ -157,6 +158,7 @@ function copyPrototype(src, dest, prefix) { [ 'JSON', 'Math', + 'Proxy', 'Reflect', ].forEach((name) => { // eslint-disable-next-line no-restricted-globals diff --git a/lib/internal/perf/observe.js b/lib/internal/perf/observe.js index 4d71666882a3ba..c96925c723f64e 100644 --- a/lib/internal/perf/observe.js +++ b/lib/internal/perf/observe.js @@ -72,6 +72,8 @@ const kDeprecationMessage = const kTypeSingle = 0; const kTypeMultiple = 1; +let gcTrackingInstalled = false; + const kSupportedEntryTypes = ObjectFreeze([ 'function', 'gc', @@ -124,8 +126,11 @@ function maybeIncrementObserverCount(type) { if (observerType !== undefined) { observerCounts[observerType]++; - if (observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC) + if (!gcTrackingInstalled && + observerType === NODE_PERFORMANCE_ENTRY_TYPE_GC) { installGarbageCollectionTracking(); + gcTrackingInstalled = true; + } } } diff --git a/lib/internal/process/execution.js b/lib/internal/process/execution.js index e370770643ca6f..e2d9898012d2d7 100644 --- a/lib/internal/process/execution.js +++ b/lib/internal/process/execution.js @@ -152,10 +152,13 @@ function createOnGlobalUncaughtException() { try { const report = internalBinding('report'); if (report != null && report.shouldReportOnUncaughtException()) { - report.writeReport(er ? er.message : 'Exception', - 'Exception', - null, - er ? er : {}); + report.writeReport( + typeof er?.message === 'string' ? + er.message : + 'Exception', + 'Exception', + null, + er ? er : {}); } } catch {} // Ignore the exception. Diagnostic reporting is unavailable. } diff --git a/lib/internal/readline/callbacks.js b/lib/internal/readline/callbacks.js new file mode 100644 index 00000000000000..ae7cf0c07dda0b --- /dev/null +++ b/lib/internal/readline/callbacks.js @@ -0,0 +1,132 @@ +'use strict'; + +const { + NumberIsNaN, +} = primordials; + +const { + codes: { + ERR_INVALID_ARG_VALUE, + ERR_INVALID_CURSOR_POS, + }, +} = require('internal/errors'); + +const { + validateCallback, +} = require('internal/validators'); +const { + CSI, +} = require('internal/readline/utils'); + +const { + kClearLine, + kClearScreenDown, + kClearToLineBeginning, + kClearToLineEnd, +} = CSI; + + +/** + * moves the cursor to the x and y coordinate on the given stream + */ + +function cursorTo(stream, x, y, callback) { + if (callback !== undefined) { + validateCallback(callback); + } + + if (typeof y === 'function') { + callback = y; + y = undefined; + } + + if (NumberIsNaN(x)) throw new ERR_INVALID_ARG_VALUE('x', x); + if (NumberIsNaN(y)) throw new ERR_INVALID_ARG_VALUE('y', y); + + if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) { + if (typeof callback === 'function') process.nextTick(callback, null); + return true; + } + + if (typeof x !== 'number') throw new ERR_INVALID_CURSOR_POS(); + + const data = typeof y !== 'number' ? CSI`${x + 1}G` : CSI`${y + 1};${x + 1}H`; + return stream.write(data, callback); +} + +/** + * moves the cursor relative to its current location + */ + +function moveCursor(stream, dx, dy, callback) { + if (callback !== undefined) { + validateCallback(callback); + } + + if (stream == null || !(dx || dy)) { + if (typeof callback === 'function') process.nextTick(callback, null); + return true; + } + + let data = ''; + + if (dx < 0) { + data += CSI`${-dx}D`; + } else if (dx > 0) { + data += CSI`${dx}C`; + } + + if (dy < 0) { + data += CSI`${-dy}A`; + } else if (dy > 0) { + data += CSI`${dy}B`; + } + + return stream.write(data, callback); +} + +/** + * clears the current line the cursor is on: + * -1 for left of the cursor + * +1 for right of the cursor + * 0 for the entire line + */ + +function clearLine(stream, dir, callback) { + if (callback !== undefined) { + validateCallback(callback); + } + + if (stream === null || stream === undefined) { + if (typeof callback === 'function') process.nextTick(callback, null); + return true; + } + + const type = + dir < 0 ? kClearToLineBeginning : dir > 0 ? kClearToLineEnd : kClearLine; + return stream.write(type, callback); +} + +/** + * clears the screen from the current position of the cursor down + */ + +function clearScreenDown(stream, callback) { + if (callback !== undefined) { + validateCallback(callback); + } + + if (stream === null || stream === undefined) { + if (typeof callback === 'function') process.nextTick(callback, null); + return true; + } + + return stream.write(kClearScreenDown, callback); +} + +module.exports = { + clearLine, + clearScreenDown, + cursorTo, + moveCursor, +}; diff --git a/lib/internal/readline/emitKeypressEvents.js b/lib/internal/readline/emitKeypressEvents.js new file mode 100644 index 00000000000000..9c5a2554de9d22 --- /dev/null +++ b/lib/internal/readline/emitKeypressEvents.js @@ -0,0 +1,96 @@ +'use strict'; + +const { + SafeStringIterator, + Symbol, +} = primordials; + +const { + charLengthAt, + CSI, + emitKeys, +} = require('internal/readline/utils'); + +const { clearTimeout, setTimeout } = require('timers'); +const { + kEscape, +} = CSI; + +const { StringDecoder } = require('string_decoder'); + +const KEYPRESS_DECODER = Symbol('keypress-decoder'); +const ESCAPE_DECODER = Symbol('escape-decoder'); + +// GNU readline library - keyseq-timeout is 500ms (default) +const ESCAPE_CODE_TIMEOUT = 500; + +/** + * accepts a readable Stream instance and makes it emit "keypress" events + */ + +function emitKeypressEvents(stream, iface = {}) { + if (stream[KEYPRESS_DECODER]) return; + + stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); + + stream[ESCAPE_DECODER] = emitKeys(stream); + stream[ESCAPE_DECODER].next(); + + const triggerEscape = () => stream[ESCAPE_DECODER].next(''); + const { escapeCodeTimeout = ESCAPE_CODE_TIMEOUT } = iface; + let timeoutId; + + function onData(input) { + if (stream.listenerCount('keypress') > 0) { + const string = stream[KEYPRESS_DECODER].write(input); + if (string) { + clearTimeout(timeoutId); + + // This supports characters of length 2. + iface._sawKeyPress = charLengthAt(string, 0) === string.length; + iface.isCompletionEnabled = false; + + let length = 0; + for (const character of new SafeStringIterator(string)) { + length += character.length; + if (length === string.length) { + iface.isCompletionEnabled = true; + } + + try { + stream[ESCAPE_DECODER].next(character); + // Escape letter at the tail position + if (length === string.length && character === kEscape) { + timeoutId = setTimeout(triggerEscape, escapeCodeTimeout); + } + } catch (err) { + // If the generator throws (it could happen in the `keypress` + // event), we need to restart it. + stream[ESCAPE_DECODER] = emitKeys(stream); + stream[ESCAPE_DECODER].next(); + throw err; + } + } + } + } else { + // Nobody's watching anyway + stream.removeListener('data', onData); + stream.on('newListener', onNewListener); + } + } + + function onNewListener(event) { + if (event === 'keypress') { + stream.on('data', onData); + stream.removeListener('newListener', onNewListener); + } + } + + if (stream.listenerCount('keypress') > 0) { + stream.on('data', onData); + } else { + stream.on('newListener', onNewListener); + } +} + +module.exports = emitKeypressEvents; diff --git a/lib/internal/repl/utils.js b/lib/internal/repl/utils.js index 80c56144051e19..aff7dafe16e95a 100644 --- a/lib/internal/repl/utils.js +++ b/lib/internal/repl/utils.js @@ -41,7 +41,7 @@ const { clearScreenDown, cursorTo, moveCursor, -} = require('readline'); +} = require('internal/readline/callbacks'); const { commonPrefix, diff --git a/lib/internal/test/transfer.js b/lib/internal/test/transfer.js new file mode 100644 index 00000000000000..b814c37fe6dc6d --- /dev/null +++ b/lib/internal/test/transfer.js @@ -0,0 +1,42 @@ +'use strict'; + +const { + makeTransferable, + kClone, + kDeserialize, +} = require('internal/worker/js_transferable'); + +process.emitWarning( + 'These APIs are for internal testing only. Do not use them.', + 'internal/test/transfer'); + +// Used as part of parallel/test-messaging-maketransferable. +// This has to exist within the lib/internal/ path in order +// for deserialization to work. + +class E { + constructor(b) { + this.b = b; + } +} + +class F extends E { + constructor(b) { + super(b); + /* eslint-disable-next-line no-constructor-return */ + return makeTransferable(this); + } + + [kClone]() { + return { + data: { b: this.b }, + deserializeInfo: 'internal/test/transfer:F' + }; + } + + [kDeserialize]({ b }) { + this.b = b; + } +} + +module.exports = { E, F }; diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js index dd9ef50228a296..62746517729a2e 100644 --- a/lib/internal/util/inspect.js +++ b/lib/internal/util/inspect.js @@ -5,6 +5,7 @@ const { ArrayIsArray, ArrayPrototypeFilter, ArrayPrototypeForEach, + ArrayPrototypePop, ArrayPrototypePush, ArrayPrototypePushApply, ArrayPrototypeSort, @@ -217,7 +218,7 @@ const meta = [ ]; // Regex used for ansi escape code splitting -// Adopted from https://github.com/chalk/ansi-regex/blob/master/index.js +// Adopted from https://github.com/chalk/ansi-regex/blob/HEAD/index.js // License: MIT, authors: @sindresorhus, Qix-, arjunmehta and LitoMore // Matches all ansi escape code sequences in a string const ansiPattern = '[\\u001B\\u009B][[\\]()#;?]*' + @@ -620,6 +621,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) { } // Get all own property names and symbols. keys = ReflectOwnKeys(obj); + ArrayPrototypePush(ctx.seen, main); for (const key of keys) { // Ignore the `constructor` property and keys that exist on layers above. if (key === 'constructor' || @@ -640,6 +642,7 @@ function addPrototypeProperties(ctx, main, obj, recurseTimes, output) { ArrayPrototypePush(output, value); } } + ArrayPrototypePop(ctx.seen); // Limit the inspection to up to three prototype layers. Using `recurseTimes` // is not a good choice here, because it's as if the properties are declared // on the current object from the users perspective. diff --git a/lib/internal/util/iterable_weak_map.js b/lib/internal/util/iterable_weak_map.js index 0842622d2451b3..67e51ec8619be9 100644 --- a/lib/internal/util/iterable_weak_map.js +++ b/lib/internal/util/iterable_weak_map.js @@ -12,7 +12,7 @@ const { // This class is modified from the example code in the WeakRefs specification: // https://github.com/tc39/proposal-weakrefs // Licensed under ECMA's MIT-style license, see: -// https://github.com/tc39/ecma262/blob/master/LICENSE.md +// https://github.com/tc39/ecma262/blob/HEAD/LICENSE.md class IterableWeakMap { #weakMap = new SafeWeakMap(); #refSet = new SafeSet(); @@ -54,13 +54,22 @@ class IterableWeakMap { return true; } - *[SymbolIterator]() { - for (const ref of this.#refSet) { - const key = ref.deref(); - if (!key) continue; + [SymbolIterator]() { + const iterator = this.#refSet[SymbolIterator](); + + const next = () => { + const result = iterator.next(); + if (result.done) return result; + const key = result.value.deref(); + if (key == null) return next(); const { value } = this.#weakMap.get(key); - yield value; - } + return { done: false, value }; + }; + + return { + [SymbolIterator]() { return this; }, + next, + }; } } diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 2b6b90c58d1147..21d9b932c10f4b 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -28,7 +28,7 @@ 'use strict'; /* eslint-disable node-core/prefer-primordials */ -/* global Buffer, console */ +/* global console */ module.exports = { versionCheck }; @@ -40,6 +40,7 @@ if (module.id === 'internal/v8_prof_polyfill') return; // Node polyfill const fs = require('fs'); const cp = require('child_process'); +const { Buffer } = require('buffer'); const os = { system: function(name, args) { if (process.platform === 'linux' && name === 'nm') { diff --git a/lib/internal/worker.js b/lib/internal/worker.js index 0d60235395d9c0..f1da0d4ded4cea 100644 --- a/lib/internal/worker.js +++ b/lib/internal/worker.js @@ -1,7 +1,5 @@ 'use strict'; -/* global SharedArrayBuffer */ - const { ArrayIsArray, ArrayPrototypeForEach, @@ -24,6 +22,7 @@ const { SymbolFor, TypedArrayPrototypeFill, Uint32Array, + globalThis: { Atomics, SharedArrayBuffer }, } = primordials; const EventEmitter = require('events'); diff --git a/lib/internal/worker/io.js b/lib/internal/worker/io.js index fdfbe10b5fefcf..adacdd913c6693 100644 --- a/lib/internal/worker/io.js +++ b/lib/internal/worker/io.js @@ -41,6 +41,7 @@ const { const { Readable, Writable } = require('stream'); const { Event, + EventTarget, NodeEventTarget, defineEventHandler, initNodeEventTarget, diff --git a/lib/internal/worker/js_transferable.js b/lib/internal/worker/js_transferable.js index ce95cf64e21987..7bd6c8cafc32e2 100644 --- a/lib/internal/worker/js_transferable.js +++ b/lib/internal/worker/js_transferable.js @@ -1,6 +1,11 @@ 'use strict'; const { Error, + ObjectDefineProperties, + ObjectGetOwnPropertyDescriptors, + ObjectGetPrototypeOf, + ObjectSetPrototypeOf, + ReflectConstruct, StringPrototypeSplit, } = primordials; const { @@ -22,21 +27,30 @@ function setup() { const { 0: module, 1: ctor } = StringPrototypeSplit(deserializeInfo, ':'); const Ctor = require(module)[ctor]; if (typeof Ctor !== 'function' || - !(Ctor.prototype instanceof JSTransferable)) { + typeof Ctor.prototype[messaging_deserialize_symbol] !== 'function') { // Not one of the official errors because one should not be able to get // here without messing with Node.js internals. // eslint-disable-next-line no-restricted-syntax throw new Error(`Unknown deserialize spec ${deserializeInfo}`); } + return new Ctor(); }); } +function makeTransferable(obj) { + const inst = ReflectConstruct(JSTransferable, [], obj.constructor); + ObjectDefineProperties(inst, ObjectGetOwnPropertyDescriptors(obj)); + ObjectSetPrototypeOf(inst, ObjectGetPrototypeOf(obj)); + return inst; +} + module.exports = { + makeTransferable, setup, JSTransferable, kClone: messaging_clone_symbol, kDeserialize: messaging_deserialize_symbol, kTransfer: messaging_transfer_symbol, - kTransferList: messaging_transfer_list_symbol + kTransferList: messaging_transfer_list_symbol, }; diff --git a/lib/os.js b/lib/os.js index 7e23110b3085ae..4396fcefd533c4 100644 --- a/lib/os.js +++ b/lib/os.js @@ -286,7 +286,7 @@ function networkInterfaces() { } /** - * @param {number} pid + * @param {number} [pid=0] * @param {number} priority * @returns {void} */ @@ -306,7 +306,7 @@ function setPriority(pid, priority) { } /** - * @param {number} pid + * @param {number} [pid=0] * @returns {number} */ function getPriority(pid) { @@ -325,9 +325,9 @@ function getPriority(pid) { } /** - * @param {{ encoding?: string }} options If `encoding` is set to `'buffer'`, - * the `username`, `shell`, and `homedir` values will be `Buffer` instances. - * Default: `'utf8'` + * @param {{ encoding?: string }} [options=utf8] If `encoding` is set to + * `'buffer'`, the `username`, `shell`, and `homedir` values will + * be `Buffer` instances. * @returns {{ * uid: number * gid: number diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 1f9a665a3ca006..a92a040f2de839 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -59,6 +59,15 @@ class Performance extends EventTarget { timeOrigin: this.timeOrigin, }, opts)}`; } + +} + +function toJSON() { + return { + nodeTiming: this.nodeTiming, + timeOrigin: this.timeOrigin, + eventLoopUtilization: this.eventLoopUtilization() + }; } class InternalPerformance extends EventTarget {} @@ -105,6 +114,11 @@ ObjectDefineProperties(Performance.prototype, { configurable: true, enumerable: true, value: timeOriginTimestamp, + }, + toJSON: { + configurable: true, + enumerable: true, + value: toJSON, } }); diff --git a/lib/punycode.js b/lib/punycode.js index 67905e3d7670e1..3483fd667bf40a 100644 --- a/lib/punycode.js +++ b/lib/punycode.js @@ -1,5 +1,15 @@ 'use strict'; +const { getOptionValue } = require('internal/options'); +if (getOptionValue('--pending-deprecation')){ + process.emitWarning( + 'The `punycode` module is deprecated. Please use a userland ' + + 'alternative instead.', + 'DeprecationWarning', + 'DEP0040', + ); +} + /** Highest positive signed 32-bit float value */ const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1 diff --git a/lib/readline.js b/lib/readline.js index 582fc26baf7a97..b40c8019746120 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -65,6 +65,14 @@ const { SafeStringIterator, } = primordials; +const { + clearLine, + clearScreenDown, + cursorTo, + moveCursor, +} = require('internal/readline/callbacks'); +const emitKeypressEvents = require('internal/readline/emitKeypressEvents'); + const { AbortError, codes @@ -72,12 +80,10 @@ const { const { ERR_INVALID_ARG_VALUE, - ERR_INVALID_CURSOR_POS, } = codes; const { validateAbortSignal, validateArray, - validateCallback, validateString, validateUint32, } = require('internal/validators'); @@ -91,28 +97,21 @@ const { charLengthAt, charLengthLeft, commonPrefix, - CSI, - emitKeys, kSubstringSearch, } = require('internal/readline/utils'); const { promisify } = require('internal/util'); -const { clearTimeout, setTimeout } = require('timers'); -const { - kEscape, - kClearToLineBeginning, - kClearToLineEnd, - kClearLine, - kClearScreenDown -} = CSI; - - const { StringDecoder } = require('string_decoder'); // Lazy load Readable for startup performance. let Readable; +/** + * @typedef {import('./stream.js').Readable} Readable + * @typedef {import('./stream.js').Writable} Writable + */ + const kHistorySize = 30; const kMincrlfDelay = 100; // \r\n, \n, or \r followed by something other than \n @@ -121,12 +120,30 @@ const lineEnding = /\r?\n|\r(?!\n)/; const kLineObjectStream = Symbol('line object stream'); const kQuestionCancel = Symbol('kQuestionCancel'); -const KEYPRESS_DECODER = Symbol('keypress-decoder'); -const ESCAPE_DECODER = Symbol('escape-decoder'); - // GNU readline library - keyseq-timeout is 500ms (default) const ESCAPE_CODE_TIMEOUT = 500; +/** + * Creates a new `readline.Interface` instance. + * @param {Readable | { + * input: Readable; + * output: Writable; + * completer?: Function; + * terminal?: boolean; + * history?: string[]; + * historySize?: number; + * removeHistoryDuplicates?: boolean; + * prompt?: string; + * crlfDelay?: number; + * escapeCodeTimeout?: number; + * tabSize?: number; + * signal?: AbortSignal; + * }} input + * @param {Writable} [output] + * @param {Function} [completer] + * @param {boolean} [terminal] + * @returns {Interface} + */ function createInterface(input, output, completer, terminal) { return new Interface(input, output, completer, terminal); } @@ -357,11 +374,19 @@ ObjectDefineProperty(Interface.prototype, 'columns', { } }); +/** + * Sets the prompt written to the output. + * @param {string} prompt + * @returns {void} + */ Interface.prototype.setPrompt = function(prompt) { this._prompt = prompt; }; - +/** + * Returns the current prompt used by `rl.prompt()`. + * @returns {string} + */ Interface.prototype.getPrompt = function() { return this._prompt; }; @@ -377,7 +402,11 @@ Interface.prototype._setRawMode = function(mode) { return wasInRawMode; }; - +/** + * Writes the configured `prompt` to a new line in `output`. + * @param {boolean} [preserveCursor] + * @returns {void} + */ Interface.prototype.prompt = function(preserveCursor) { if (this.paused) this.resume(); if (this.terminal && process.env.TERM !== 'dumb') { @@ -388,7 +417,13 @@ Interface.prototype.prompt = function(preserveCursor) { } }; - +/** + * Displays `query` by writing it to the `output`. + * @param {string} query + * @param {{ signal?: AbortSignal; }} [options] + * @param {Function} cb + * @returns {void} + */ Interface.prototype.question = function(query, options, cb) { cb = typeof options === 'function' ? options : cb; options = typeof options === 'object' && options !== null ? options : {}; @@ -537,7 +572,10 @@ Interface.prototype._refreshLine = function() { this.prevRows = cursorPos.rows; }; - +/** + * Closes the `readline.Interface` instance. + * @returns {void} + */ Interface.prototype.close = function() { if (this.closed) return; this.pause(); @@ -548,7 +586,10 @@ Interface.prototype.close = function() { this.emit('close'); }; - +/** + * Pauses the `input` stream. + * @returns {void | Interface} + */ Interface.prototype.pause = function() { if (this.paused) return; this.input.pause(); @@ -557,7 +598,10 @@ Interface.prototype.pause = function() { return this; }; - +/** + * Resumes the `input` stream if paused. + * @returns {void | Interface} + */ Interface.prototype.resume = function() { if (!this.paused) return; this.input.resume(); @@ -566,7 +610,18 @@ Interface.prototype.resume = function() { return this; }; - +/** + * Writes either `data` or a `key` sequence identified by + * `key` to the `output`. + * @param {string} d + * @param {{ + * ctrl?: boolean; + * meta?: boolean; + * shift?: boolean; + * name?: string; + * }} [key] + * @returns {void} + */ Interface.prototype.write = function(d, key) { if (this.paused) this.resume(); if (this.terminal) { @@ -877,7 +932,14 @@ Interface.prototype._getDisplayPos = function(str) { return { cols, rows }; }; -// Returns current cursor's position and line +/** + * Returns the real position of the cursor in relation + * to the input prompt + string. + * @returns {{ + * rows: number; + * cols: number; + * }} + */ Interface.prototype.getCursorPos = function() { const strBeforeCursor = this._prompt + StringPrototypeSlice(this.line, 0, this.cursor); @@ -1206,6 +1268,11 @@ Interface.prototype._ttyWrite = function(s, key) { } }; +/** + * Creates an `AsyncIterator` object that iterates through + * each line in the input stream as a string. + * @returns {Symbol.AsyncIterator} + */ Interface.prototype[SymbolAsyncIterator] = function() { if (this[kLineObjectStream] === undefined) { if (Readable === undefined) { @@ -1244,183 +1311,6 @@ Interface.prototype[SymbolAsyncIterator] = function() { return this[kLineObjectStream][SymbolAsyncIterator](); }; -/** - * accepts a readable Stream instance and makes it emit "keypress" events - */ - -function emitKeypressEvents(stream, iface = {}) { - if (stream[KEYPRESS_DECODER]) return; - - stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); - - stream[ESCAPE_DECODER] = emitKeys(stream); - stream[ESCAPE_DECODER].next(); - - const triggerEscape = () => stream[ESCAPE_DECODER].next(''); - const { escapeCodeTimeout = ESCAPE_CODE_TIMEOUT } = iface; - let timeoutId; - - function onData(input) { - if (stream.listenerCount('keypress') > 0) { - const string = stream[KEYPRESS_DECODER].write(input); - if (string) { - clearTimeout(timeoutId); - - // This supports characters of length 2. - iface._sawKeyPress = charLengthAt(string, 0) === string.length; - iface.isCompletionEnabled = false; - - let length = 0; - for (const character of new SafeStringIterator(string)) { - length += character.length; - if (length === string.length) { - iface.isCompletionEnabled = true; - } - - try { - stream[ESCAPE_DECODER].next(character); - // Escape letter at the tail position - if (length === string.length && character === kEscape) { - timeoutId = setTimeout(triggerEscape, escapeCodeTimeout); - } - } catch (err) { - // If the generator throws (it could happen in the `keypress` - // event), we need to restart it. - stream[ESCAPE_DECODER] = emitKeys(stream); - stream[ESCAPE_DECODER].next(); - throw err; - } - } - } - } else { - // Nobody's watching anyway - stream.removeListener('data', onData); - stream.on('newListener', onNewListener); - } - } - - function onNewListener(event) { - if (event === 'keypress') { - stream.on('data', onData); - stream.removeListener('newListener', onNewListener); - } - } - - if (stream.listenerCount('keypress') > 0) { - stream.on('data', onData); - } else { - stream.on('newListener', onNewListener); - } -} - -/** - * moves the cursor to the x and y coordinate on the given stream - */ - -function cursorTo(stream, x, y, callback) { - if (callback !== undefined) { - validateCallback(callback); - } - - if (typeof y === 'function') { - callback = y; - y = undefined; - } - - if (NumberIsNaN(x)) - throw new ERR_INVALID_ARG_VALUE('x', x); - if (NumberIsNaN(y)) - throw new ERR_INVALID_ARG_VALUE('y', y); - - if (stream == null || (typeof x !== 'number' && typeof y !== 'number')) { - if (typeof callback === 'function') - process.nextTick(callback, null); - return true; - } - - if (typeof x !== 'number') - throw new ERR_INVALID_CURSOR_POS(); - - const data = typeof y !== 'number' ? CSI`${x + 1}G` : CSI`${y + 1};${x + 1}H`; - return stream.write(data, callback); -} - -/** - * moves the cursor relative to its current location - */ - -function moveCursor(stream, dx, dy, callback) { - if (callback !== undefined) { - validateCallback(callback); - } - - if (stream == null || !(dx || dy)) { - if (typeof callback === 'function') - process.nextTick(callback, null); - return true; - } - - let data = ''; - - if (dx < 0) { - data += CSI`${-dx}D`; - } else if (dx > 0) { - data += CSI`${dx}C`; - } - - if (dy < 0) { - data += CSI`${-dy}A`; - } else if (dy > 0) { - data += CSI`${dy}B`; - } - - return stream.write(data, callback); -} - -/** - * clears the current line the cursor is on: - * -1 for left of the cursor - * +1 for right of the cursor - * 0 for the entire line - */ - -function clearLine(stream, dir, callback) { - if (callback !== undefined) { - validateCallback(callback); - } - - if (stream === null || stream === undefined) { - if (typeof callback === 'function') - process.nextTick(callback, null); - return true; - } - - const type = dir < 0 ? - kClearToLineBeginning : - dir > 0 ? - kClearToLineEnd : - kClearLine; - return stream.write(type, callback); -} - -/** - * clears the screen from the current position of the cursor down - */ - -function clearScreenDown(stream, callback) { - if (callback !== undefined) { - validateCallback(callback); - } - - if (stream === null || stream === undefined) { - if (typeof callback === 'function') - process.nextTick(callback, null); - return true; - } - - return stream.write(kClearScreenDown, callback); -} - module.exports = { Interface, clearLine, diff --git a/lib/timers/promises.js b/lib/timers/promises.js index ec13e873d8443c..1f245580f86ab5 100644 --- a/lib/timers/promises.js +++ b/lib/timers/promises.js @@ -61,8 +61,7 @@ function setTimeout(after, value, options = {}) { } let oncancel; const ret = new Promise((resolve, reject) => { - const timeout = new Timeout(resolve, after, args, false, true); - if (!ref) timeout.unref(); + const timeout = new Timeout(resolve, after, args, false, ref); insert(timeout, timeout._idleTimeout); if (signal) { oncancel = FunctionPrototypeBind(cancelListenerHandler, @@ -141,8 +140,7 @@ async function* setInterval(after, value, options = {}) { callback(); callback = undefined; } - }, after, undefined, true, true); - if (!ref) interval.unref(); + }, after, undefined, true, ref); insert(interval, interval._idleTimeout); if (signal) { onCancel = () => { diff --git a/lib/util.js b/lib/util.js index f3c10bb7720e58..bcb1c81933c0c0 100644 --- a/lib/util.js +++ b/lib/util.js @@ -74,51 +74,109 @@ const { let internalDeepEqual; +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is boolean} + */ function isBoolean(arg) { return typeof arg === 'boolean'; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is null} + */ function isNull(arg) { return arg === null; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is (null | undefined)} + */ function isNullOrUndefined(arg) { return arg === null || arg === undefined; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is number} + */ function isNumber(arg) { return typeof arg === 'number'; } +/** + * @param {any} arg + * @returns {arg is string} + */ function isString(arg) { return typeof arg === 'string'; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is symbol} + */ function isSymbol(arg) { return typeof arg === 'symbol'; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is undefined} + */ function isUndefined(arg) { return arg === undefined; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {a is NonNullable} + */ function isObject(arg) { return arg !== null && typeof arg === 'object'; } +/** + * @deprecated since v4.0.0 + * @param {any} e + * @returns {arg is Error} + */ function isError(e) { return ObjectPrototypeToString(e) === '[object Error]' || e instanceof Error; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is Function} + */ function isFunction(arg) { return typeof arg === 'function'; } +/** + * @deprecated since v4.0.0 + * @param {any} arg + * @returns {arg is (boolean | null | number | string | symbol | undefined)} + */ function isPrimitive(arg) { return arg === null || (typeof arg !== 'object' && typeof arg !== 'function'); } +/** + * @param {number} n + * @returns {string} + */ function pad(n) { return StringPrototypePadStart(n.toString(), 2, '0'); } @@ -126,7 +184,9 @@ function pad(n) { const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']; -// 26 Feb 16:19:34 +/** + * @returns {string} 26 Feb 16:19:34 + */ function timestamp() { const d = new Date(); const t = ArrayPrototypeJoin([ @@ -138,7 +198,11 @@ function timestamp() { } let console; -// Log is just a thin wrapper to console.log that prepends a timestamp +/** + * Log is just a thin wrapper to console.log that prepends a timestamp + * @deprecated since v6.0.0 + * @type {(...args: any[]) => void} + */ function log(...args) { if (!console) { console = require('internal/console/global'); @@ -155,9 +219,9 @@ function log(...args) { * functions as prototype setup using normal JavaScript does not work as * expected during bootstrapping (see mirror.js in r114903). * - * @param {function} ctor Constructor function which needs to inherit the + * @param {Function} ctor Constructor function which needs to inherit the * prototype. - * @param {function} superCtor Constructor function to inherit prototype from. + * @param {Function} superCtor Constructor function to inherit prototype from. * @throws {TypeError} Will error if either constructor is null, or if * the super constructor lacks a prototype. */ @@ -181,6 +245,14 @@ function inherits(ctor, superCtor) { ObjectSetPrototypeOf(ctor.prototype, superCtor.prototype); } +/** + * @deprecated since v6.0.0 + * @template T + * @template S + * @param {T} target + * @param {S} source + * @returns {S extends null ? T : (T & S)} + */ function _extend(target, source) { // Don't do anything if source isn't an object if (source === null || typeof source !== 'object') return target; @@ -204,6 +276,14 @@ const callbackifyOnRejected = hideStackFrames((reason, cb) => { return cb(reason); }); +/** + * @template {(...args: any[]) => Promise} T + * @param {T} original + * @returns {T extends (...args: infer TArgs) => Promise ? + * ((...params: [...TArgs, ((err: Error, ret: TReturn) => any)]) => void) : + * never + * } + */ function callbackify(original) { if (typeof original !== 'function') { throw new ERR_INVALID_ARG_TYPE('original', 'Function', original); @@ -238,6 +318,10 @@ function callbackify(original) { return callbackified; } +/** + * @param {number} err + * @returns {string} + */ function getSystemErrorName(err) { validateNumber(err, 'err'); if (err >= 0 || !NumberIsSafeInteger(err)) { diff --git a/lib/zlib.js b/lib/zlib.js index 5fcd736f6652a1..c0c7f601758224 100644 --- a/lib/zlib.js +++ b/lib/zlib.js @@ -89,7 +89,7 @@ const { BROTLI_DECODE, BROTLI_ENCODE, // Brotli operations (~flush levels) BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_FLUSH, - BROTLI_OPERATION_FINISH + BROTLI_OPERATION_FINISH, BROTLI_OPERATION_EMIT_METADATA, } = constants; // Translation table for return codes. @@ -238,6 +238,13 @@ const checkRangesOrGetDefault = hideStackFrames( } ); +const FLUSH_BOUND = [ + [ Z_NO_FLUSH, Z_BLOCK ], + [ BROTLI_OPERATION_PROCESS, BROTLI_OPERATION_EMIT_METADATA ], +]; +const FLUSH_BOUND_IDX_NORMAL = 0; +const FLUSH_BOUND_IDX_BROTLI = 1; + // The base class for all Zlib-style streams. function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) { let chunkSize = Z_DEFAULT_CHUNK; @@ -247,6 +254,13 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) { assert(typeof mode === 'number'); assert(mode >= DEFLATE && mode <= BROTLI_ENCODE); + let flushBoundIdx; + if (mode !== BROTLI_ENCODE && mode !== BROTLI_DECODE) { + flushBoundIdx = FLUSH_BOUND_IDX_NORMAL; + } else { + flushBoundIdx = FLUSH_BOUND_IDX_BROTLI; + } + if (opts) { chunkSize = opts.chunkSize; if (!checkFiniteNumber(chunkSize, 'options.chunkSize')) { @@ -258,11 +272,12 @@ function ZlibBase(opts, mode, handle, { flush, finishFlush, fullFlush }) { flush = checkRangesOrGetDefault( opts.flush, 'options.flush', - Z_NO_FLUSH, Z_BLOCK, flush); + FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], flush); finishFlush = checkRangesOrGetDefault( opts.finishFlush, 'options.finishFlush', - Z_NO_FLUSH, Z_BLOCK, finishFlush); + FLUSH_BOUND[flushBoundIdx][0], FLUSH_BOUND[flushBoundIdx][1], + finishFlush); maxOutputLength = checkRangesOrGetDefault( opts.maxOutputLength, 'options.maxOutputLength', diff --git a/node.gyp b/node.gyp index acae34fa393339..642a9767fb64d8 100644 --- a/node.gyp +++ b/node.gyp @@ -166,6 +166,9 @@ 'lib/internal/heap_utils.js', 'lib/internal/histogram.js', 'lib/internal/idna.js', + 'lib/internal/inspector/_inspect.js', + 'lib/internal/inspector/inspect_client.js', + 'lib/internal/inspector/inspect_repl.js', 'lib/internal/inspector_async_hook.js', 'lib/internal/js_stream_socket.js', 'lib/internal/legacy/processbinding.js', @@ -215,6 +218,8 @@ 'lib/internal/process/signal.js', 'lib/internal/process/task_queues.js', 'lib/internal/querystring.js', + 'lib/internal/readline/callbacks.js', + 'lib/internal/readline/emitKeypressEvents.js', 'lib/internal/readline/utils.js', 'lib/internal/repl.js', 'lib/internal/repl/await.js', @@ -226,6 +231,7 @@ 'lib/internal/source_map/source_map.js', 'lib/internal/source_map/source_map_cache.js', 'lib/internal/test/binding.js', + 'lib/internal/test/transfer.js', 'lib/internal/timers.js', 'lib/internal/tls.js', 'lib/internal/trace_events_async_hooks.js', @@ -277,9 +283,6 @@ 'deps/v8/tools/tickprocessor.mjs', 'deps/v8/tools/sourcemap.mjs', 'deps/v8/tools/tickprocessor-driver.mjs', - 'deps/node-inspect/lib/_inspect.js', - 'deps/node-inspect/lib/internal/inspect_client.js', - 'deps/node-inspect/lib/internal/inspect_repl.js', 'deps/acorn/acorn/dist/acorn.js', 'deps/acorn/acorn-walk/dist/walk.js', 'deps/acorn-plugins/acorn-class-fields/index.js', diff --git a/src/api/environment.cc b/src/api/environment.cc index 46e3360ef9c023..3d061d38a5717a 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -465,7 +465,8 @@ MultiIsolatePlatform* CreatePlatform( MultiIsolatePlatform* CreatePlatform( int thread_pool_size, v8::TracingController* tracing_controller) { - return MultiIsolatePlatform::Create(thread_pool_size, tracing_controller) + return MultiIsolatePlatform::Create(thread_pool_size, + tracing_controller) .release(); } @@ -475,8 +476,11 @@ void FreePlatform(MultiIsolatePlatform* platform) { std::unique_ptr MultiIsolatePlatform::Create( int thread_pool_size, - v8::TracingController* tracing_controller) { - return std::make_unique(thread_pool_size, tracing_controller); + v8::TracingController* tracing_controller, + v8::PageAllocator* page_allocator) { + return std::make_unique(thread_pool_size, + tracing_controller, + page_allocator); } MaybeLocal GetPerContextExports(Local context) { diff --git a/src/async_wrap.cc b/src/async_wrap.cc index 0baf8010907043..a1c76b94138762 100644 --- a/src/async_wrap.cc +++ b/src/async_wrap.cc @@ -452,6 +452,15 @@ static void EnablePromiseHook(const FunctionCallbackInfo& args) { } } +static void SetPromiseHooks(const FunctionCallbackInfo& args) { + Environment* env = Environment::GetCurrent(args); + Local ctx = env->context(); + ctx->SetPromiseHooks( + args[0]->IsFunction() ? args[0].As() : Local(), + args[1]->IsFunction() ? args[1].As() : Local(), + args[2]->IsFunction() ? args[2].As() : Local(), + args[3]->IsFunction() ? args[3].As() : Local()); +} static void DisablePromiseHook(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -631,6 +640,7 @@ void AsyncWrap::Initialize(Local target, env->SetMethod(target, "clearAsyncIdStack", ClearAsyncIdStack); env->SetMethod(target, "queueDestroyAsyncId", QueueDestroyAsyncId); env->SetMethod(target, "enablePromiseHook", EnablePromiseHook); + env->SetMethod(target, "setPromiseHooks", SetPromiseHooks); env->SetMethod(target, "disablePromiseHook", DisablePromiseHook); env->SetMethod(target, "registerDestroyHook", RegisterDestroyHook); @@ -725,6 +735,7 @@ void AsyncWrap::RegisterExternalReferences( registry->Register(ClearAsyncIdStack); registry->Register(QueueDestroyAsyncId); registry->Register(EnablePromiseHook); + registry->Register(SetPromiseHooks); registry->Register(DisablePromiseHook); registry->Register(RegisterDestroyHook); registry->Register(AsyncWrap::GetAsyncId); diff --git a/src/crypto/README.md b/src/crypto/README.md index 3317334cd71d3c..479ac3378ef7d0 100644 --- a/src/crypto/README.md +++ b/src/crypto/README.md @@ -1,4 +1,4 @@ -# Node.js src/crypto Documentation +# Node.js `src/crypto` documentation Welcome. You've found your way to the Node.js native crypto subsystem. @@ -64,7 +64,7 @@ instead.) This section aims to explain some of the utilities that have been provided to make working with the OpenSSL APIs a bit easier. -### Pointer Types +### Pointer types Most of the key OpenSSL types need to be explicitly freed when they are no longer needed. Failure to do so introduces memory leaks. To make this @@ -123,7 +123,7 @@ crypto functions (generated hash values, or ciphertext, for instance). to directly using the `v8::BackingStore` API. This will take some time. New uses of `AllocatedBuffer` should be avoided if possible.* -### Key Objects +### Key objects Most crypto operations involve the use of keys -- cryptographic inputs that protect data. There are three general types of keys: @@ -272,9 +272,9 @@ These can be called from within the C++ code as functions, like `THROW_ERR_CRYPTO_INVALID_IV(env)`. These methods should be used to throw JavaScript errors when necessary. -## Crypto API Patterns +## Crypto API patterns -### Operation Mode +### Operation mode All crypto functions in Node.js operate in one of three modes: diff --git a/src/crypto/crypto_cipher.cc b/src/crypto/crypto_cipher.cc index b15795b691ea0b..5ce466582823ae 100644 --- a/src/crypto/crypto_cipher.cc +++ b/src/crypto/crypto_cipher.cc @@ -511,10 +511,10 @@ bool CipherBase::InitAuthenticated( if (mode == EVP_CIPH_GCM_MODE) { if (auth_tag_len != kNoAuthTagLength) { if (!IsValidGCMTagLength(auth_tag_len)) { - char msg[50]; - snprintf(msg, sizeof(msg), - "Invalid authentication tag length: %u", auth_tag_len); - THROW_ERR_CRYPTO_INVALID_AUTH_TAG(env(), msg); + THROW_ERR_CRYPTO_INVALID_AUTH_TAG( + env(), + "Invalid authentication tag length: %u", + auth_tag_len); return false; } @@ -523,9 +523,8 @@ bool CipherBase::InitAuthenticated( } } else { if (auth_tag_len == kNoAuthTagLength) { - char msg[128]; - snprintf(msg, sizeof(msg), "authTagLength required for %s", cipher_type); - THROW_ERR_CRYPTO_INVALID_AUTH_TAG(env(), msg); + THROW_ERR_CRYPTO_INVALID_AUTH_TAG( + env(), "authTagLength required for %s", cipher_type); return false; } @@ -633,10 +632,8 @@ void CipherBase::SetAuthTag(const FunctionCallbackInfo& args) { } if (!is_valid) { - char msg[50]; - snprintf(msg, sizeof(msg), - "Invalid authentication tag length: %u", tag_len); - return THROW_ERR_CRYPTO_INVALID_AUTH_TAG(env, msg); + return THROW_ERR_CRYPTO_INVALID_AUTH_TAG( + env, "Invalid authentication tag length: %u", tag_len); } cipher->auth_tag_len_ = tag_len; diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 1b863a1241edb3..f4b7bd3ad8548a 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -480,8 +480,16 @@ MaybeLocal GetLastIssuedCert( return MaybeLocal(); issuer_chain = ca_info; + // Take the value of cert->get() before the call to cert->reset() + // in order to compare it to ca after and provide a way to exit this loop + // in case it gets stuck. + X509* value_before_reset = cert->get(); + // Delete previous cert and continue aggregating issuers. cert->reset(ca); + + if (value_before_reset == ca) + break; } return MaybeLocal(issuer_chain); } diff --git a/src/crypto/crypto_dsa.cc b/src/crypto/crypto_dsa.cc index 6ee8cf7e18c02e..271db427fa8539 100644 --- a/src/crypto/crypto_dsa.cc +++ b/src/crypto/crypto_dsa.cc @@ -84,9 +84,7 @@ Maybe DsaKeyGenTraits::AdditionalConfig( params->params.modulus_bits = args[*offset].As()->Value(); params->params.divisor_bits = args[*offset + 1].As()->Value(); if (params->params.divisor_bits < -1) { - char msg[1024]; - snprintf(msg, sizeof(msg), "invalid value for divisor_bits"); - THROW_ERR_OUT_OF_RANGE(env, msg); + THROW_ERR_OUT_OF_RANGE(env, "invalid value for divisor_bits"); return Nothing(); } diff --git a/src/crypto/crypto_hash.cc b/src/crypto/crypto_hash.cc index 664ffb847215af..ba2c52268a23ff 100644 --- a/src/crypto/crypto_hash.cc +++ b/src/crypto/crypto_hash.cc @@ -233,9 +233,7 @@ Maybe HashTraits::AdditionalConfig( Utf8Value digest(env->isolate(), args[offset]); params->digest = EVP_get_digestbyname(*digest); if (UNLIKELY(params->digest == nullptr)) { - char msg[1024]; - snprintf(msg, sizeof(msg), "Invalid digest: %s", *digest); - THROW_ERR_CRYPTO_INVALID_DIGEST(env); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *digest); return Nothing(); } diff --git a/src/crypto/crypto_keys.cc b/src/crypto/crypto_keys.cc index be12022bdb7f1d..21cc988cee6a18 100644 --- a/src/crypto/crypto_keys.cc +++ b/src/crypto/crypto_keys.cc @@ -515,9 +515,7 @@ std::shared_ptr ImportJWKAsymmetricKey( return ImportJWKEcKey(env, jwk, args, offset); } - char msg[1024]; - snprintf(msg, sizeof(msg), "%s is not a supported JWK key type", kty); - THROW_ERR_CRYPTO_INVALID_JWK(env, msg); + THROW_ERR_CRYPTO_INVALID_JWK(env, "%s is not a supported JWK key type", kty); return std::shared_ptr(); } diff --git a/src/crypto/crypto_pbkdf2.cc b/src/crypto/crypto_pbkdf2.cc index cc9a0d072ad13c..495722927ab5be 100644 --- a/src/crypto/crypto_pbkdf2.cc +++ b/src/crypto/crypto_pbkdf2.cc @@ -92,26 +92,20 @@ Maybe PBKDF2Traits::AdditionalConfig( params->iterations = args[offset + 2].As()->Value(); if (params->iterations < 0) { - char msg[1024]; - snprintf(msg, sizeof(msg), "iterations must be <= %d", INT_MAX); - THROW_ERR_OUT_OF_RANGE(env, msg); + THROW_ERR_OUT_OF_RANGE(env, "iterations must be <= %d", INT_MAX); return Nothing(); } params->length = args[offset + 3].As()->Value(); if (params->length < 0) { - char msg[1024]; - snprintf(msg, sizeof(msg), "length must be <= %d", INT_MAX); - THROW_ERR_OUT_OF_RANGE(env, msg); + THROW_ERR_OUT_OF_RANGE(env, "length must be <= %d", INT_MAX); return Nothing(); } Utf8Value name(args.GetIsolate(), args[offset + 4]); params->digest = EVP_get_digestbyname(*name); if (params->digest == nullptr) { - char errmsg[1024]; - snprintf(errmsg, sizeof(errmsg), "Invalid digest: %s", *name); - THROW_ERR_CRYPTO_INVALID_DIGEST(env, errmsg); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "Invalid digest: %s", *name); return Nothing(); } diff --git a/src/crypto/crypto_rsa.cc b/src/crypto/crypto_rsa.cc index a77ded918ebdda..5fa91cce1a6ad2 100644 --- a/src/crypto/crypto_rsa.cc +++ b/src/crypto/crypto_rsa.cc @@ -138,9 +138,7 @@ Maybe RsaKeyGenTraits::AdditionalConfig( Utf8Value digest(env->isolate(), args[*offset]); params->params.md = EVP_get_digestbyname(*digest); if (params->params.md == nullptr) { - char msg[1024]; - snprintf(msg, sizeof(msg), "md specifies an invalid digest"); - THROW_ERR_CRYPTO_INVALID_DIGEST(env, msg); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, "md specifies an invalid digest"); return Nothing(); } } @@ -150,9 +148,8 @@ Maybe RsaKeyGenTraits::AdditionalConfig( Utf8Value digest(env->isolate(), args[*offset + 1]); params->params.mgf1_md = EVP_get_digestbyname(*digest); if (params->params.mgf1_md == nullptr) { - char msg[1024]; - snprintf(msg, sizeof(msg), "mgf1_md specifies an invalid digest"); - THROW_ERR_CRYPTO_INVALID_DIGEST(env, msg); + THROW_ERR_CRYPTO_INVALID_DIGEST(env, + "mgf1_md specifies an invalid digest"); return Nothing(); } } @@ -161,9 +158,9 @@ Maybe RsaKeyGenTraits::AdditionalConfig( CHECK(args[*offset + 2]->IsInt32()); params->params.saltlen = args[*offset + 2].As()->Value(); if (params->params.saltlen < 0) { - char msg[1024]; - snprintf(msg, sizeof(msg), "salt length is out of range"); - THROW_ERR_OUT_OF_RANGE(env, msg); + THROW_ERR_OUT_OF_RANGE( + env, + "salt length is out of range"); return Nothing(); } } diff --git a/src/crypto/crypto_scrypt.cc b/src/crypto/crypto_scrypt.cc index 39d6b3fd0d8d6a..077c26554b2f1f 100644 --- a/src/crypto/crypto_scrypt.cc +++ b/src/crypto/crypto_scrypt.cc @@ -111,9 +111,7 @@ Maybe ScryptTraits::AdditionalConfig( params->length = args[offset + 6].As()->Value(); if (params->length < 0) { - char msg[1024]; - snprintf(msg, sizeof(msg), "length must be <= %d", INT_MAX); - THROW_ERR_OUT_OF_RANGE(env, msg); + THROW_ERR_OUT_OF_RANGE(env, "length must be <= %d", INT_MAX); return Nothing(); } @@ -151,4 +149,3 @@ bool ScryptTraits::DeriveBits( } // namespace crypto } // namespace node - diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc index 2226c432839e18..4b30c177bea55c 100644 --- a/src/inspector_agent.cc +++ b/src/inspector_agent.cc @@ -898,13 +898,6 @@ void Agent::ContextCreated(Local context, const ContextInfo& info) { client_->contextCreated(context, info); } -bool Agent::WillWaitForConnect() { - if (debug_options_.wait_for_connect()) return true; - if (parent_handle_) - return parent_handle_->WaitForConnect(); - return false; -} - bool Agent::IsActive() { if (client_ == nullptr) return false; diff --git a/src/inspector_agent.h b/src/inspector_agent.h index 08b8817f436286..1c8d496ba27a9e 100644 --- a/src/inspector_agent.h +++ b/src/inspector_agent.h @@ -59,8 +59,6 @@ class Agent { // --inspect command line flag) or if inspector JS API had been used. bool IsActive(); - // Option is set to wait for session connection - bool WillWaitForConnect(); // Blocks till frontend connects and sends "runIfWaitingForDebugger" void WaitForConnect(); // Blocks till all the sessions with "WaitForDisconnectOnShutdown" disconnect diff --git a/src/large_pages/node_text_start.S b/src/large_pages/node_text_start.S index 3227b62464932c..d27dd39cc236f0 100644 --- a/src/large_pages/node_text_start.S +++ b/src/large_pages/node_text_start.S @@ -1,5 +1,5 @@ #if defined(__ELF__) -.section .note.GNU-stack,"",@progbits +.section .note.GNU-stack,"",%progbits #endif .text .align 0x2000 diff --git a/src/node.h b/src/node.h index 4348dfba5b2be8..066c0eadfb6b05 100644 --- a/src/node.h +++ b/src/node.h @@ -310,7 +310,8 @@ class NODE_EXTERN MultiIsolatePlatform : public v8::Platform { static std::unique_ptr Create( int thread_pool_size, - v8::TracingController* tracing_controller = nullptr); + v8::TracingController* tracing_controller = nullptr, + v8::PageAllocator* page_allocator = nullptr); }; enum IsolateSettingsFlags { diff --git a/src/node_api.cc b/src/node_api.cc index 8dbf48d466dfe1..4216356cb59593 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -12,6 +12,7 @@ #include "tracing/traced_value.h" #include "util-inl.h" +#include #include struct node_napi_env__ : public napi_env__ { @@ -137,6 +138,7 @@ class ThreadSafeFunction : public node::AsyncResource { *v8::String::Utf8Value(env_->isolate, name)), thread_count(thread_count_), is_closing(false), + dispatch_state(kDispatchIdle), context(context_), max_queue_size(max_queue_size_), env(env_), @@ -176,10 +178,8 @@ class ThreadSafeFunction : public node::AsyncResource { return napi_closing; } } else { - if (uv_async_send(&async) != 0) { - return napi_generic_failure; - } queue.push(data); + Send(); return napi_ok; } } @@ -211,9 +211,7 @@ class ThreadSafeFunction : public node::AsyncResource { if (is_closing && max_queue_size > 0) { cond->Signal(lock); } - if (uv_async_send(&async) != 0) { - return napi_generic_failure; - } + Send(); } } @@ -238,7 +236,6 @@ class ThreadSafeFunction : public node::AsyncResource { cond = std::make_unique(); } if (max_queue_size == 0 || cond) { - CHECK_EQ(0, uv_idle_init(loop, &idle)); return napi_ok; } @@ -263,21 +260,46 @@ class ThreadSafeFunction : public node::AsyncResource { napi_status Unref() { uv_unref(reinterpret_cast(&async)); - uv_unref(reinterpret_cast(&idle)); return napi_ok; } napi_status Ref() { uv_ref(reinterpret_cast(&async)); - uv_ref(reinterpret_cast(&idle)); return napi_ok; } - void DispatchOne() { + inline void* Context() { + return context; + } + + protected: + void Dispatch() { + bool has_more = true; + + // Limit maximum synchronous iteration count to prevent event loop + // starvation. See `src/node_messaging.cc` for an inspiration. + unsigned int iterations_left = kMaxIterationCount; + while (has_more && --iterations_left != 0) { + dispatch_state = kDispatchRunning; + has_more = DispatchOne(); + + // Send() was called while we were executing the JS function + if (dispatch_state.exchange(kDispatchIdle) != kDispatchRunning) { + has_more = true; + } + } + + if (has_more) { + Send(); + } + } + + bool DispatchOne() { void* data = nullptr; bool popped_value = false; + bool has_more = false; { node::Mutex::ScopedLock lock(this->mutex); @@ -302,9 +324,9 @@ class ThreadSafeFunction : public node::AsyncResource { cond->Signal(lock); } CloseHandlesAndMaybeDelete(); - } else { - CHECK_EQ(0, uv_idle_stop(&idle)); } + } else { + has_more = true; } } } @@ -322,6 +344,8 @@ class ThreadSafeFunction : public node::AsyncResource { call_js_cb(env, js_callback, context, data); }); } + + return has_more; } void Finalize() { @@ -335,10 +359,6 @@ class ThreadSafeFunction : public node::AsyncResource { EmptyQueueAndDelete(); } - inline void* Context() { - return context; - } - void CloseHandlesAndMaybeDelete(bool set_closing = false) { v8::HandleScope scope(env->isolate); if (set_closing) { @@ -358,18 +378,20 @@ class ThreadSafeFunction : public node::AsyncResource { ThreadSafeFunction* ts_fn = node::ContainerOf(&ThreadSafeFunction::async, reinterpret_cast(handle)); - v8::HandleScope scope(ts_fn->env->isolate); - ts_fn->env->node_env()->CloseHandle( - reinterpret_cast(&ts_fn->idle), - [](uv_handle_t* handle) -> void { - ThreadSafeFunction* ts_fn = - node::ContainerOf(&ThreadSafeFunction::idle, - reinterpret_cast(handle)); - ts_fn->Finalize(); - }); + ts_fn->Finalize(); }); } + void Send() { + // Ask currently running Dispatch() to make one more iteration + unsigned char current_state = dispatch_state.fetch_or(kDispatchPending); + if ((current_state & kDispatchRunning) == kDispatchRunning) { + return; + } + + CHECK_EQ(0, uv_async_send(&async)); + } + // Default way of calling into JavaScript. Used when ThreadSafeFunction is // without a call_js_cb_. static void CallJs(napi_env env, napi_value cb, void* context, void* data) { @@ -393,16 +415,10 @@ class ThreadSafeFunction : public node::AsyncResource { } } - static void IdleCb(uv_idle_t* idle) { - ThreadSafeFunction* ts_fn = - node::ContainerOf(&ThreadSafeFunction::idle, idle); - ts_fn->DispatchOne(); - } - static void AsyncCb(uv_async_t* async) { ThreadSafeFunction* ts_fn = node::ContainerOf(&ThreadSafeFunction::async, async); - CHECK_EQ(0, uv_idle_start(&ts_fn->idle, IdleCb)); + ts_fn->Dispatch(); } static void Cleanup(void* data) { @@ -411,14 +427,20 @@ class ThreadSafeFunction : public node::AsyncResource { } private: + static const unsigned char kDispatchIdle = 0; + static const unsigned char kDispatchRunning = 1 << 0; + static const unsigned char kDispatchPending = 1 << 1; + + static const unsigned int kMaxIterationCount = 1000; + // These are variables protected by the mutex. node::Mutex mutex; std::unique_ptr cond; std::queue queue; uv_async_t async; - uv_idle_t idle; size_t thread_count; bool is_closing; + std::atomic_uchar dispatch_state; // These are variables set once, upon creation, and then never again, which // means we don't need the mutex to read them. diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 485e273f2fbe9e..9006c1de767533 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -303,28 +303,36 @@ MaybeLocal New(Isolate* isolate, if (!StringBytes::Size(isolate, string, enc).To(&length)) return Local(); size_t actual = 0; - char* data = nullptr; + std::unique_ptr store; if (length > 0) { - data = UncheckedMalloc(length); + store = ArrayBuffer::NewBackingStore(isolate, length); - if (data == nullptr) { + if (UNLIKELY(!store)) { THROW_ERR_MEMORY_ALLOCATION_FAILED(isolate); return Local(); } - actual = StringBytes::Write(isolate, data, length, string, enc); + actual = StringBytes::Write( + isolate, + static_cast(store->Data()), + length, + string, + enc); CHECK(actual <= length); - if (actual == 0) { - free(data); - data = nullptr; - } else if (actual < length) { - data = node::Realloc(data, actual); + if (LIKELY(actual > 0)) { + if (actual < length) + store = BackingStore::Reallocate(isolate, std::move(store), actual); + Local buf = ArrayBuffer::New(isolate, std::move(store)); + Local obj; + if (UNLIKELY(!New(isolate, buf, 0, actual).ToLocal(&obj))) + return MaybeLocal(); + return scope.Escape(obj); } } - return scope.EscapeMaybe(New(isolate, data, actual)); + return scope.EscapeMaybe(New(isolate, 0)); } diff --git a/src/node_errors.h b/src/node_errors.h index 291365fa3b4dc9..96659f3a400826 100644 --- a/src/node_errors.h +++ b/src/node_errors.h @@ -32,6 +32,7 @@ void OnFatalError(const char* location, const char* message); V(ERR_BUFFER_CONTEXT_NOT_AVAILABLE, Error) \ V(ERR_BUFFER_OUT_OF_BOUNDS, RangeError) \ V(ERR_BUFFER_TOO_LARGE, Error) \ + V(ERR_CLOSED_MESSAGE_PORT, Error) \ V(ERR_CONSTRUCT_CALL_REQUIRED, TypeError) \ V(ERR_CONSTRUCT_CALL_INVALID, TypeError) \ V(ERR_CRYPTO_INITIALIZATION_FAILED, Error) \ @@ -118,6 +119,7 @@ ERRORS_WITH_CODE(V) #define PREDEFINED_ERROR_MESSAGES(V) \ V(ERR_BUFFER_CONTEXT_NOT_AVAILABLE, \ "Buffer is not available for the current Context") \ + V(ERR_CLOSED_MESSAGE_PORT, "Cannot send data on closed MessagePort") \ V(ERR_CONSTRUCT_CALL_INVALID, "Constructor cannot be called") \ V(ERR_CONSTRUCT_CALL_REQUIRED, "Cannot call constructor without `new`") \ V(ERR_CRYPTO_INITIALIZATION_FAILED, "Initialization failed") \ diff --git a/src/node_i18n.cc b/src/node_i18n.cc index 48f95ceb68d9c1..42e618ac30181f 100644 --- a/src/node_i18n.cc +++ b/src/node_i18n.cc @@ -148,8 +148,13 @@ MaybeLocal Transcode(Environment* env, *status = U_ZERO_ERROR; MaybeLocal ret; MaybeStackBuffer result; - Converter to(toEncoding, "?"); + Converter to(toEncoding); Converter from(fromEncoding); + + size_t sublen = ucnv_getMinCharSize(to.conv()); + std::string sub(sublen, '?'); + to.set_subst_chars(sub.c_str()); + const uint32_t limit = source_length * to.max_char_size(); result.AllocateSufficientStorage(limit); char* target = *result; @@ -190,7 +195,12 @@ MaybeLocal TranscodeFromUcs2(Environment* env, *status = U_ZERO_ERROR; MaybeStackBuffer sourcebuf; MaybeLocal ret; - Converter to(toEncoding, "?"); + Converter to(toEncoding); + + size_t sublen = ucnv_getMinCharSize(to.conv()); + std::string sub(sublen, '?'); + to.set_subst_chars(sub.c_str()); + const size_t length_in_chars = source_length / sizeof(UChar); CopySourceBuffer(&sourcebuf, source, source_length, length_in_chars); MaybeStackBuffer destbuf(length_in_chars); diff --git a/src/node_messaging.cc b/src/node_messaging.cc index fbe6c407a6cea2..ac4abc3af01568 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -1065,7 +1065,11 @@ void MessagePort::MoveToContext(const FunctionCallbackInfo& args) { "The \"port\" argument must be a MessagePort instance"); } MessagePort* port = Unwrap(args[0].As()); - CHECK_NOT_NULL(port); + if (port == nullptr || port->IsHandleClosing()) { + Isolate* isolate = env->isolate(); + THROW_ERR_CLOSED_MESSAGE_PORT(isolate); + return; + } Local context_arg = args[1]; ContextifyContext* context_wrapper; diff --git a/src/node_platform.cc b/src/node_platform.cc index eb918bdd559c40..9787cbb3edc2e2 100644 --- a/src/node_platform.cc +++ b/src/node_platform.cc @@ -324,12 +324,17 @@ void PerIsolatePlatformData::DecreaseHandleCount() { } NodePlatform::NodePlatform(int thread_pool_size, - v8::TracingController* tracing_controller) { + v8::TracingController* tracing_controller, + v8::PageAllocator* page_allocator) { if (tracing_controller != nullptr) { tracing_controller_ = tracing_controller; } else { tracing_controller_ = new v8::TracingController(); } + + // V8 will default to its built in allocator if none is provided. + page_allocator_ = page_allocator; + // TODO(addaleax): It's a bit icky that we use global state here, but we can't // really do anything about it unless V8 starts exposing a way to access the // current v8::Platform instance. @@ -550,6 +555,10 @@ Platform::StackTracePrinter NodePlatform::GetStackTracePrinter() { }; } +v8::PageAllocator* NodePlatform::GetPageAllocator() { + return page_allocator_; +} + template TaskQueue::TaskQueue() : lock_(), tasks_available_(), tasks_drained_(), diff --git a/src/node_platform.h b/src/node_platform.h index a7139ebdcc28d2..4a05f3bba58c8e 100644 --- a/src/node_platform.h +++ b/src/node_platform.h @@ -138,7 +138,8 @@ class WorkerThreadsTaskRunner { class NodePlatform : public MultiIsolatePlatform { public: NodePlatform(int thread_pool_size, - v8::TracingController* tracing_controller); + v8::TracingController* tracing_controller, + v8::PageAllocator* page_allocator = nullptr); ~NodePlatform() override; void DrainTasks(v8::Isolate* isolate) override; @@ -170,6 +171,7 @@ class NodePlatform : public MultiIsolatePlatform { v8::Isolate* isolate) override; Platform::StackTracePrinter GetStackTracePrinter() override; + v8::PageAllocator* GetPageAllocator() override; private: IsolatePlatformDelegate* ForIsolate(v8::Isolate* isolate); @@ -181,6 +183,7 @@ class NodePlatform : public MultiIsolatePlatform { std::unordered_map per_isolate_; v8::TracingController* tracing_controller_; + v8::PageAllocator* page_allocator_; std::shared_ptr worker_thread_task_runner_; bool has_shut_down_ = false; }; diff --git a/src/node_report.cc b/src/node_report.cc index 13f87b1e52e5d6..0144d22c17d13b 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -39,10 +39,15 @@ using node::TIME_TYPE; using node::worker::Worker; using v8::Array; using v8::Context; +using v8::HandleScope; using v8::HeapSpaceStatistics; using v8::HeapStatistics; using v8::Isolate; +using v8::Just; using v8::Local; +using v8::Maybe; +using v8::MaybeLocal; +using v8::Nothing; using v8::Object; using v8::String; using v8::TryCatch; @@ -58,16 +63,16 @@ static void WriteNodeReport(Isolate* isolate, const char* trigger, const std::string& filename, std::ostream& out, - Local error, + Local error, bool compact); static void PrintVersionInformation(JSONWriter* writer); static void PrintJavaScriptErrorStack(JSONWriter* writer, Isolate* isolate, - Local error, + Local error, const char* trigger); static void PrintJavaScriptErrorProperties(JSONWriter* writer, Isolate* isolate, - Local error); + Local error); static void PrintNativeStack(JSONWriter* writer); static void PrintResourceUsage(JSONWriter* writer); static void PrintGCStatistics(JSONWriter* writer, Isolate* isolate); @@ -84,7 +89,7 @@ std::string TriggerNodeReport(Isolate* isolate, const char* message, const char* trigger, const std::string& name, - Local error) { + Local error) { std::string filename; // Determine the required report filename. In order of priority: @@ -169,7 +174,7 @@ void GetNodeReport(Isolate* isolate, Environment* env, const char* message, const char* trigger, - Local error, + Local error, std::ostream& out) { WriteNodeReport(isolate, env, message, trigger, "", out, error, false); } @@ -182,7 +187,7 @@ static void WriteNodeReport(Isolate* isolate, const char* trigger, const std::string& filename, std::ostream& out, - Local error, + Local error, bool compact) { // Obtain the current time and the pid. TIME_TYPE tm_struct; @@ -474,13 +479,14 @@ static void PrintNetworkInterfaceInfo(JSONWriter* writer) { static void PrintJavaScriptErrorProperties(JSONWriter* writer, Isolate* isolate, - Local error) { + Local error) { writer->json_objectstart("errorProperties"); - if (!error.IsEmpty()) { + if (!error.IsEmpty() && error->IsObject()) { TryCatch try_catch(isolate); - Local context = error->GetIsolate()->GetCurrentContext(); + Local error_obj = error.As(); + Local context = error_obj->GetIsolate()->GetCurrentContext(); Local keys; - if (!error->GetOwnPropertyNames(context).ToLocal(&keys)) { + if (!error_obj->GetOwnPropertyNames(context).ToLocal(&keys)) { return writer->json_objectend(); // the end of 'errorProperties' } uint32_t keys_length = keys->Length(); @@ -491,7 +497,7 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer, } Local value; Local value_string; - if (!error->Get(context, key).ToLocal(&value) || + if (!error_obj->Get(context, key).ToLocal(&value) || !value->ToString(context).ToLocal(&value_string)) { continue; } @@ -505,26 +511,50 @@ static void PrintJavaScriptErrorProperties(JSONWriter* writer, writer->json_objectend(); // the end of 'errorProperties' } +static Maybe ErrorToString(Isolate* isolate, + Local context, + Local error) { + if (error.IsEmpty()) { + return Nothing(); + } + + MaybeLocal maybe_str; + // `ToString` is not available to Symbols. + if (error->IsSymbol()) { + maybe_str = error.As()->ToDetailString(context); + } else if (!error->IsObject()) { + maybe_str = error->ToString(context); + } else if (error->IsObject()) { + MaybeLocal stack = error.As()->Get( + context, node::FIXED_ONE_BYTE_STRING(isolate, "stack")); + if (!stack.IsEmpty() && stack.ToLocalChecked()->IsString()) { + maybe_str = stack.ToLocalChecked().As(); + } + } + + Local js_str; + if (!maybe_str.ToLocal(&js_str)) { + return Nothing(); + } + String::Utf8Value sv(isolate, js_str); + return Just<>(std::string(*sv, sv.length())); +} + // Report the JavaScript stack. static void PrintJavaScriptErrorStack(JSONWriter* writer, - Isolate* isolate, - Local error, - const char* trigger) { - Local stackstr; - std::string ss = ""; + Isolate* isolate, + Local error, + const char* trigger) { TryCatch try_catch(isolate); + HandleScope scope(isolate); + Local context = isolate->GetCurrentContext(); + std::string ss = ""; if ((!strcmp(trigger, "FatalError")) || - (!strcmp(trigger, "Signal"))) { + (!strcmp(trigger, "Signal")) || + (!ErrorToString(isolate, context, error).To(&ss))) { ss = "No stack.\nUnavailable.\n"; - } else if (!error.IsEmpty() && - error - ->Get(isolate->GetCurrentContext(), - node::FIXED_ONE_BYTE_STRING(isolate, - "stack")) - .ToLocal(&stackstr)) { - String::Utf8Value sv(isolate, stackstr); - ss = std::string(*sv, sv.length()); } + int line = ss.find('\n'); if (line == -1) { writer->json_keyvalue("message", ss); diff --git a/src/node_report.h b/src/node_report.h index f4992f220221ed..a8292eb2dd477d 100644 --- a/src/node_report.h +++ b/src/node_report.h @@ -20,12 +20,12 @@ std::string TriggerNodeReport(v8::Isolate* isolate, const char* message, const char* trigger, const std::string& name, - v8::Local error); + v8::Local error); void GetNodeReport(v8::Isolate* isolate, node::Environment* env, const char* message, const char* trigger, - v8::Local error, + v8::Local error, std::ostream& out); // Function declarations - utility functions in src/node_report_utils.cc diff --git a/src/node_report_module.cc b/src/node_report_module.cc index 97c6bea3ad5ec5..190755a85b2369 100644 --- a/src/node_report_module.cc +++ b/src/node_report_module.cc @@ -32,7 +32,7 @@ void WriteReport(const FunctionCallbackInfo& info) { Isolate* isolate = env->isolate(); HandleScope scope(isolate); std::string filename; - Local error; + Local error; CHECK_EQ(info.Length(), 4); String::Utf8Value message(isolate, info[0].As()); @@ -40,10 +40,10 @@ void WriteReport(const FunctionCallbackInfo& info) { if (info[2]->IsString()) filename = *String::Utf8Value(isolate, info[2]); - if (!info[3].IsEmpty() && info[3]->IsObject()) - error = info[3].As(); + if (!info[3].IsEmpty()) + error = info[3]; else - error = Local(); + error = Local(); filename = TriggerNodeReport( isolate, env, *message, *trigger, filename, error); diff --git a/src/node_version.h b/src/node_version.h index c01a6450eb0e25..b0265b02a3cae5 100644 --- a/src/node_version.h +++ b/src/node_version.h @@ -84,7 +84,7 @@ * if it can be made ABI compatible with the previous version. * * The registry of used NODE_MODULE_VERSION numbers is located at - * https://github.com/nodejs/node/blob/master/doc/abi_version_registry.json + * https://github.com/nodejs/node/blob/HEAD/doc/abi_version_registry.json * Extenders, embedders and other consumers of Node.js that require ABI * version matching should open a pull request to reserve a number in this * registry. diff --git a/test/README.md b/test/README.md index 834af7dc5896a2..e535605080199a 100644 --- a/test/README.md +++ b/test/README.md @@ -15,7 +15,7 @@ For the tests to run on Windows, be sure to clone Node.js source code with the | Directory | Runs on CI | Purpose | | ---------------- | ---------- | --------------- | -| `abort` | Yes | Tests for when the `--abort-on-uncaught-exception` flag is used. | +| `abort` | Yes | Tests that use `--abort-on-uncaught-exception` and other situations where we want to test something but avoid generating a core file. | | `addons` | Yes | Tests for [addon](https://nodejs.org/api/addons.html) functionality along with some tests that require an addon. | | `async-hooks` | Yes | Tests for [async_hooks](https://nodejs.org/api/async_hooks.html) functionality. | | `benchmark` | Yes | Test minimal functionality of benchmarks. | @@ -25,6 +25,7 @@ For the tests to run on Windows, be sure to clone Node.js source code with the | `doctool` | Yes | Tests for the documentation generator. | | `es-module` | Yes | Test ESM module loading. | | `fixtures` | | Test fixtures used in various tests throughout the test suite. | +| `inspector-cli` | Yes | Tests for `node inspect` | | `internet` | No | Tests that make real outbound network connections. Tests for networking related modules may also be present in other directories, but those tests do not make outbound connections. | | `js-native-api` | Yes | Tests for Node.js-agnostic [n-api](https://nodejs.org/api/n-api.html) functionality. | | `known_issues` | Yes | Tests reproducing known issues within the system. All tests inside of this directory are expected to fail. If a test doesn't fail on certain platforms, those should be skipped via `known_issues.status`. | diff --git a/test/pummel/test-abort-fatal-error.js b/test/abort/test-abort-fatal-error.js similarity index 100% rename from test/pummel/test-abort-fatal-error.js rename to test/abort/test-abort-fatal-error.js diff --git a/test/benchmark/test-benchmark-crypto.js b/test/benchmark/test-benchmark-crypto.js index 7f6988acf234d8..f7f155ac8e55d8 100644 --- a/test/benchmark/test-benchmark-crypto.js +++ b/test/benchmark/test-benchmark-crypto.js @@ -8,6 +8,10 @@ if (!common.hasCrypto) if (common.hasFipsCrypto) common.skip('some benchmarks are FIPS-incompatible'); +if (common.hasOpenSSL3) { + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); +} + const runBenchmark = require('../common/benchmark'); runBenchmark('crypto', { NODEJS_BENCHMARK_ZERO_ALLOWED: 1 }); diff --git a/test/cctest/gtest/gtest-all.cc b/test/cctest/gtest/gtest-all.cc index 69925f4f68d392..a73baecaa67883 100644 --- a/test/cctest/gtest/gtest-all.cc +++ b/test/cctest/gtest/gtest-all.cc @@ -6901,7 +6901,7 @@ bool ShouldRunTestOnShard(int total_shards, int shard_index, int test_id) { // each TestSuite and TestInfo object. // If shard_tests == true, further filters tests based on sharding // variables in the environment - see -// https://github.com/google/googletest/blob/master/googletest/docs/advanced.md +// https://github.com/google/googletest/blob/HEAD/googletest/docs/advanced.md // . Returns the number of tests that should run. int UnitTestImpl::FilterTests(ReactionToSharding shard_tests) { const Int32 total_shards = shard_tests == HONOR_SHARDING_PROTOCOL ? @@ -7831,7 +7831,7 @@ static std::string DeathTestThreadWarning(size_t thread_count) { msg << "detected " << thread_count << " threads."; } msg << " See " - "https://github.com/google/googletest/blob/master/googletest/docs/" + "https://github.com/google/googletest/blob/HEAD/googletest/docs/" "advanced.md#death-tests-and-threads" << " for more explanation and suggested solutions, especially if" << " this is the last message you see before your test times out."; diff --git a/test/common/README.md b/test/common/README.md index 2f2ee17a0f01e4..ea4d4e401be64e 100644 --- a/test/common/README.md +++ b/test/common/README.md @@ -9,6 +9,7 @@ This directory contains modules used to test the Node.js implementation. * [Common module API](#common-module-api) * [Countdown module](#countdown-module) * [CPU Profiler module](#cpu-profiler-module) +* [Debugger module](#debugger-module) * [DNS module](#dns-module) * [Duplex pair helper](#duplex-pair-helper) * [Environment variables](#environment-variables) @@ -370,10 +371,12 @@ const { spawn } = require('child_process'); spawn(...common.pwdCommand, { stdio: ['pipe'] }); ``` -### `requireNoPackageJSONAbove()` +### `requireNoPackageJSONAbove([dir])` -Throws an `AssertionError` if a `package.json` file is in any ancestor -directory. Such files may interfere with proper test functionality. +* `dir` [<string>][] default = \_\_dirname + +Throws an `AssertionError` if a `package.json` file exists in any ancestor +directory above `dir`. Such files may interfere with proper test functionality. ### `runWithInvalidFD(func)` @@ -503,6 +506,34 @@ Sampling interval in microseconds. Throws an `AssertionError` if there are no call frames with the expected `suffix` in the profiling data contained in `file`. +## Debugger module + +Provides common functionality for tests for `node inspect`. + +### `startCLI(args[[, flags], spawnOpts])` + +* `args` [<string>][] +* `flags` [<string>][] default = [] +* `showOpts` [<Object>][] default = {} +* return [<Object>][] + +Returns a null-prototype object with properties that are functions and getters +used to interact with the `node inspect` CLI. These functions are: + +* `flushOutput()` +* `waitFor()` +* `waitForPrompt()` +* `waitForInitialBreak()` +* `breakInfo` +* `ctrlC()` +* `output` +* `rawOutput` +* `parseSourceLines()` +* `writeLine()` +* `command()` +* `stepCommand()` +* `quit()` + ## `DNS` Module The `DNS` module provides utilities related to the `dns` built-in module. diff --git a/deps/node-inspect/test/cli/start-cli.js b/test/common/debugger.js similarity index 66% rename from deps/node-inspect/test/cli/start-cli.js rename to test/common/debugger.js index 32c666c7647c68..c127b1dc292e7f 100644 --- a/deps/node-inspect/test/cli/start-cli.js +++ b/test/common/debugger.js @@ -1,42 +1,36 @@ 'use strict'; +const common = require('../common'); const spawn = require('child_process').spawn; -// This allows us to keep the helper inside of `test/` without tap warning -// about "pending" test files. -const tap = require('tap'); -tap.test('startCLI', (t) => t.end()); - -const CLI = - process.env.USE_EMBEDDED_NODE_INSPECT === '1' ? - 'inspect' : - require.resolve('../../cli.js'); - const BREAK_MESSAGE = new RegExp('(?:' + [ 'assert', 'break', 'break on start', 'debugCommand', 'exception', 'other', 'promiseRejection', ].join('|') + ') in', 'i'); +const TIMEOUT = common.platformTimeout(5000); + function isPreBreak(output) { return /Break on start/.test(output) && /1 \(function \(exports/.test(output); } function startCLI(args, flags = [], spawnOpts = {}) { - const child = spawn(process.execPath, [...flags, CLI, ...args], spawnOpts); - let isFirstStdoutChunk = true; + let stderrOutput = ''; + const child = + spawn(process.execPath, [...flags, 'inspect', ...args], spawnOpts); const outputBuffer = []; function bufferOutput(chunk) { - if (isFirstStdoutChunk) { - isFirstStdoutChunk = false; - outputBuffer.push(chunk.replace(/^debug>\s*/, '')); - } else { - outputBuffer.push(chunk); + if (this === child.stderr) { + stderrOutput += chunk; } + // TODO(trott): Figure out why the "breakpoints restored." message appears + // in unpredictable places especially on AIX in CI. We shouldn't be + // excluding it, but it gets in the way of the output checking for tests. + outputBuffer.push(chunk.replace(/\n*\d+ breakpoints restored\.\n*/mg, '')); } function getOutput() { - return outputBuffer.join('').toString() - .replace(/^[^\n]*?[\b]/mg, ''); + return outputBuffer.join('\n').replaceAll('\b', ''); } child.stdout.setEncoding('utf8'); @@ -45,7 +39,7 @@ function startCLI(args, flags = [], spawnOpts = {}) { child.stderr.on('data', bufferOutput); if (process.env.VERBOSE === '1') { - child.stdout.pipe(process.stderr); + child.stdout.pipe(process.stdout); child.stderr.pipe(process.stderr); } @@ -56,7 +50,7 @@ function startCLI(args, flags = [], spawnOpts = {}) { return output; }, - waitFor(pattern, timeout = 2000) { + waitFor(pattern) { function checkPattern(str) { if (Array.isArray(pattern)) { return pattern.every((p) => p.test(str)); @@ -67,47 +61,57 @@ function startCLI(args, flags = [], spawnOpts = {}) { return new Promise((resolve, reject) => { function checkOutput() { if (checkPattern(getOutput())) { - tearDown(); // eslint-disable-line no-use-before-define + tearDown(); resolve(); } } - function onChildExit() { - tearDown(); // eslint-disable-line no-use-before-define - reject(new Error( - `Child quit while waiting for ${pattern}; found: ${this.output}`)); + function onChildClose(code, signal) { + tearDown(); + let message = 'Child exited'; + if (code) { + message += `, code ${code}`; + } + if (signal) { + message += `, signal ${signal}`; + } + message += ` while waiting for ${pattern}; found: ${this.output}`; + if (stderrOutput) { + message += `\n STDERR: ${stderrOutput}`; + } + reject(new Error(message)); } const timer = setTimeout(() => { - tearDown(); // eslint-disable-line no-use-before-define + tearDown(); reject(new Error([ - `Timeout (${timeout}) while waiting for ${pattern}`, + `Timeout (${TIMEOUT}) while waiting for ${pattern}`, `found: ${this.output}`, ].join('; '))); - }, timeout); + }, TIMEOUT); function tearDown() { clearTimeout(timer); child.stdout.removeListener('data', checkOutput); - child.removeListener('exit', onChildExit); + child.removeListener('close', onChildClose); } - child.on('exit', onChildExit); + child.on('close', onChildClose); child.stdout.on('data', checkOutput); checkOutput(); }); }, - waitForPrompt(timeout = 2000) { - return this.waitFor(/>\s+$/, timeout); + waitForPrompt() { + return this.waitFor(/>\s+$/); }, - waitForInitialBreak(timeout = 2000) { - return this.waitFor(/break (?:on start )?in/i, timeout) + waitForInitialBreak() { + return this.waitFor(/break (?:on start )?in/i) .then(() => { if (isPreBreak(this.output)) { return this.command('next', false) - .then(() => this.waitFor(/break in/, timeout)); + .then(() => this.waitFor(/break in/)); } }); }, @@ -169,7 +173,7 @@ function startCLI(args, flags = [], spawnOpts = {}) { quit() { return new Promise((resolve) => { child.stdin.end(); - child.on('exit', resolve); + child.on('close', resolve); }); }, }; diff --git a/test/common/index.js b/test/common/index.js index f0d8c72d4a1017..d67baa5caf0ad1 100644 --- a/test/common/index.js +++ b/test/common/index.js @@ -387,10 +387,28 @@ function _mustCallInner(fn, criteria = 1, field) { mustCallChecks.push(context); - return function() { + const _return = function() { // eslint-disable-line func-style context.actual++; return fn.apply(this, arguments); }; + // Function instances have own properties that may be relevant. + // Let's replicate those properties to the returned function. + // Refs: https://tc39.es/ecma262/#sec-function-instances + Object.defineProperties(_return, { + name: { + value: fn.name, + writable: false, + enumerable: false, + configurable: true, + }, + length: { + value: fn.length, + writable: false, + enumerable: false, + configurable: true, + }, + }); + return _return; } function hasMultiLocalhost() { @@ -708,8 +726,8 @@ function gcUntil(name, condition) { }); } -function requireNoPackageJSONAbove() { - let possiblePackage = path.join(__dirname, '..', 'package.json'); +function requireNoPackageJSONAbove(dir = __dirname) { + let possiblePackage = path.join(dir, '..', 'package.json'); let lastPackage = null; while (possiblePackage !== lastPackage) { if (fs.existsSync(possiblePackage)) { diff --git a/test/common/wpt.js b/test/common/wpt.js index 137ea59e0e6114..74508f0c8d2a56 100644 --- a/test/common/wpt.js +++ b/test/common/wpt.js @@ -9,7 +9,7 @@ const path = require('path'); const { inspect } = require('util'); const { Worker } = require('worker_threads'); -// https://github.com/web-platform-tests/wpt/blob/master/resources/testharness.js +// https://github.com/web-platform-tests/wpt/blob/HEAD/resources/testharness.js // TODO: get rid of this half-baked harness in favor of the one // pulled from WPT const harnessMock = { diff --git a/test/fixtures/es-modules/cjs-exports.mjs b/test/fixtures/es-modules/cjs-exports.mjs index ac6f60e6aa9dc1..6001ce06364454 100644 --- a/test/fixtures/es-modules/cjs-exports.mjs +++ b/test/fixtures/es-modules/cjs-exports.mjs @@ -3,11 +3,14 @@ import { strictEqual, deepEqual } from 'assert'; import m, { π } from './exports-cases.js'; import * as ns from './exports-cases.js'; -deepEqual(Object.keys(ns), ['default', 'isObject', 'z', 'π']); +deepEqual(Object.keys(ns), ['?invalid', 'default', 'invalid identifier', 'isObject', 'package', 'z', 'π', '\u{d83c}\u{df10}']); strictEqual(π, 'yes'); strictEqual(typeof m.isObject, 'undefined'); strictEqual(m.π, 'yes'); strictEqual(m.z, 'yes'); +strictEqual(m.package, 10); +strictEqual(m['invalid identifier'], 'yes'); +strictEqual(m['?invalid'], 'yes'); import m2, { __esModule as __esModule2, name as name2 } from './exports-cases2.js'; import * as ns2 from './exports-cases2.js'; diff --git a/test/fixtures/es-modules/exports-cases.js b/test/fixtures/es-modules/exports-cases.js index eec3d31bc7290c..94bbde74d1d40e 100644 --- a/test/fixtures/es-modules/exports-cases.js +++ b/test/fixtures/es-modules/exports-cases.js @@ -1,7 +1,9 @@ if (global.maybe) module.exports = require('../is-object'); -exports['invalid identifier'] = 'no'; -module.exports['?invalid'] = 'no'; +exports['invalid identifier'] = 'yes'; +module.exports['?invalid'] = 'yes'; module.exports['π'] = 'yes'; -exports.package = 10; // reserved word -> not used +exports['\u{D83C}'] = 'no'; +exports['\u{D83C}\u{DF10}'] = 'yes'; +exports.package = 10; // reserved word Object.defineProperty(exports, 'z', { value: 'yes' }); diff --git a/deps/node-inspect/examples/alive.js b/test/fixtures/inspector-cli/alive.js similarity index 100% rename from deps/node-inspect/examples/alive.js rename to test/fixtures/inspector-cli/alive.js diff --git a/deps/node-inspect/examples/backtrace.js b/test/fixtures/inspector-cli/backtrace.js similarity index 100% rename from deps/node-inspect/examples/backtrace.js rename to test/fixtures/inspector-cli/backtrace.js diff --git a/deps/node-inspect/examples/break.js b/test/fixtures/inspector-cli/break.js similarity index 100% rename from deps/node-inspect/examples/break.js rename to test/fixtures/inspector-cli/break.js diff --git a/deps/node-inspect/examples/cjs/index.js b/test/fixtures/inspector-cli/cjs/index.js similarity index 100% rename from deps/node-inspect/examples/cjs/index.js rename to test/fixtures/inspector-cli/cjs/index.js diff --git a/deps/node-inspect/examples/cjs/other.js b/test/fixtures/inspector-cli/cjs/other.js similarity index 100% rename from deps/node-inspect/examples/cjs/other.js rename to test/fixtures/inspector-cli/cjs/other.js diff --git a/deps/node-inspect/examples/empty.js b/test/fixtures/inspector-cli/empty.js similarity index 100% rename from deps/node-inspect/examples/empty.js rename to test/fixtures/inspector-cli/empty.js diff --git a/deps/node-inspect/examples/exceptions.js b/test/fixtures/inspector-cli/exceptions.js similarity index 100% rename from deps/node-inspect/examples/exceptions.js rename to test/fixtures/inspector-cli/exceptions.js diff --git a/deps/node-inspect/examples/three-lines.js b/test/fixtures/inspector-cli/three-lines.js similarity index 100% rename from deps/node-inspect/examples/three-lines.js rename to test/fixtures/inspector-cli/three-lines.js diff --git a/deps/node-inspect/examples/use-strict.js b/test/fixtures/inspector-cli/use-strict.js similarity index 100% rename from deps/node-inspect/examples/use-strict.js rename to test/fixtures/inspector-cli/use-strict.js diff --git a/test/fixtures/keys/selfsigned-no-keycertsign/README.md b/test/fixtures/keys/selfsigned-no-keycertsign/README.md new file mode 100644 index 00000000000000..0dcd69007a9142 --- /dev/null +++ b/test/fixtures/keys/selfsigned-no-keycertsign/README.md @@ -0,0 +1,2 @@ +# Self-signed certificate without keyCertSign bit +The self-signed certificate ([cert.pem](./cert.pem)) and the key ([key.pem](./key.pem)) in this folder are used by the test [test-https-selfsigned-no-keycertsign-no-crash](../../../parallel/test-https-selfsigned-no-keycertsign-no-crash.js). The config ([cert.conf](./cert.conf)) and the file used to generate key and certificate in this folder ([https-renew-cert.sh](./https_renew_cert.sh)) are not used by the test but for reference. diff --git a/test/fixtures/keys/selfsigned-no-keycertsign/cert.conf b/test/fixtures/keys/selfsigned-no-keycertsign/cert.conf new file mode 100644 index 00000000000000..60901bb26d6937 --- /dev/null +++ b/test/fixtures/keys/selfsigned-no-keycertsign/cert.conf @@ -0,0 +1,17 @@ +[req] +distinguished_name = req_distinguished_name +req_extensions = v3_req +prompt = no + +[req_distinguished_name] +C = DE +CN = localhost + +[v3_req] +keyUsage = digitalSignature, keyEncipherment +extendedKeyUsage = serverAuth +subjectAltName = @alt_names +[alt_names] +DNS.1 = 127.0.0.1 +DNS.2 = localhost +IP.1 = 127.0.0.1 diff --git a/test/fixtures/keys/selfsigned-no-keycertsign/cert.pem b/test/fixtures/keys/selfsigned-no-keycertsign/cert.pem new file mode 100644 index 00000000000000..c0829b82caf8d3 --- /dev/null +++ b/test/fixtures/keys/selfsigned-no-keycertsign/cert.pem @@ -0,0 +1,18 @@ +-----BEGIN CERTIFICATE----- +MIIC9jCCAd6gAwIBAgIJANHflGRpZM1IMA0GCSqGSIb3DQEBCwUAMBQxEjAQBgNV +BAMMCWxvY2FsaG9zdDAeFw0yMTAzMTUwOTEzMjdaFw0yMjAzMTUwOTEzMjdaMBQx +EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC +ggEBANMt6TLw9gIxucRgZBn8owavEIMAddxMTjkHiR7jGfaBrvvVTB8ymsIizw/Q +KTANmu2r3EOqeR9Ht25KZFKxOKCDMd3aKHht38HInXIF6CQe8c5P0xsVKZAWkell +8ohL05EsFpcrJODIdHfaovODrtX8w1WexqDsUoPQdEk7pISJ2HhmXzpf7QmV00Ux +8J+64v2pTg8/C9VgpSgxE4oXlfJEqdSIAzGDT+VX96GWXTh7QqLjiQ9T96QHUJEn +Bx0Sr4rO9mY2lOQG408QuCLR/ng2J+lYx+03SC8Lq7lrtt4M06Ffr8TQRgpDAjkU +0YitbuysD5XgtCeFq0Fi3v1z700CAwEAAaNLMEkwCwYDVR0PBAQDAgWgMBMGA1Ud +JQQMMAoGCCsGAQUFBwMBMCUGA1UdEQQeMByCCTEyNy4wLjAuMYIJbG9jYWxob3N0 +hwR/AAABMA0GCSqGSIb3DQEBCwUAA4IBAQDAUCt/8Le2EO0ONOkQYUcPmSut6Siz +UIQrJ8Lwfs0fb+Zk9ElNGLwYTzooKDgzK8cLQ8g8F2WkolBEPXDsy1Ab+e66WkJH +NH/zAgEyG6cXXRNc+ObM5KbjY0YuDGiajKcndknuuCB+onlC1Pv5oFUSNa3/06+S +sziFloGbg5S0AHT6lYnwZSM6G7Pre8mcRNRxL6Yw1FOOUpQZKPd7juy4GBRlCucn +wmp/Fl0wIBDs91Vprig2TO+U6GvtqJ3n/RKXUz1ykUKETtRneSkqa6hFYjwRzawd +ANpjy/orrVkqXriAbI/1xvBMInWdcMpXNeiOkxQeQdy8TLBk0ZViSJnf +-----END CERTIFICATE----- diff --git a/test/fixtures/keys/selfsigned-no-keycertsign/https_renew_cert.sh b/test/fixtures/keys/selfsigned-no-keycertsign/https_renew_cert.sh new file mode 100644 index 00000000000000..092f27a8867cbb --- /dev/null +++ b/test/fixtures/keys/selfsigned-no-keycertsign/https_renew_cert.sh @@ -0,0 +1,6 @@ +#!/bin/bash +openssl genrsa -out rsa.pem 2048 +openssl rsa -in rsa.pem -out key.pem +openssl req -sha256 -new -key key.pem -out csr.pem -subj "/CN=localhost" +openssl x509 -req -extfile cert.conf -extensions v3_req -days 365 -in csr.pem -signkey key.pem -out cert.pem + diff --git a/test/fixtures/keys/selfsigned-no-keycertsign/key.pem b/test/fixtures/keys/selfsigned-no-keycertsign/key.pem new file mode 100644 index 00000000000000..5f0549276a4cae --- /dev/null +++ b/test/fixtures/keys/selfsigned-no-keycertsign/key.pem @@ -0,0 +1,27 @@ +-----BEGIN RSA PRIVATE KEY----- +MIIEogIBAAKCAQEA0y3pMvD2AjG5xGBkGfyjBq8QgwB13ExOOQeJHuMZ9oGu+9VM +HzKawiLPD9ApMA2a7avcQ6p5H0e3bkpkUrE4oIMx3dooeG3fwcidcgXoJB7xzk/T +GxUpkBaR6WXyiEvTkSwWlysk4Mh0d9qi84Ou1fzDVZ7GoOxSg9B0STukhInYeGZf +Ol/tCZXTRTHwn7ri/alODz8L1WClKDETiheV8kSp1IgDMYNP5Vf3oZZdOHtCouOJ +D1P3pAdQkScHHRKvis72ZjaU5AbjTxC4ItH+eDYn6VjH7TdILwuruWu23gzToV+v +xNBGCkMCORTRiK1u7KwPleC0J4WrQWLe/XPvTQIDAQABAoIBAFIlWMIVE0z1NNLb +v/SP3oaaEK00v6QLFp5+fOtD4fSOq5eQeATmtWZxDeSTz4G+uRZctNipdmYhiovf +ajj0cReXEQ3Ab9+wtcp2lDAndg6e7uaXDIJLcBh5fxawLnCwNkMRSFRTVwwNTajV +pm9dOORKZ11l3tP4OXzG2IUoKy3Wj/1SKLL4zrdHi7802+L/GstK6/BGma+NFrFz +U6yNqpvuzv7BH7w9G3nSz7u+8SjcY22Vs6q69GAQG3yf356cYCJhV7QIJXU0/VAF +GFx5UDwlsOT2NhoOd/b9Q9RexKDl+qDupXQo0YFOObHIjHs8UGLOZkBtv4apCarA +6u+BOwECgYEA9GbrP/5SfmN8xvF2XVjqjk9IUcvWAuTM4Bxav72e6aR9IOdye9vi ++GhwM6qON+LOnMVNhUKJ0+R/jjLy6Jq+00uKU65Q79x7lCBVSDDXWacV0IFIoAOp +P4LkykjRZyzpIvjK5HGL1JYqZi89im93uuOiyMjoFS2syU+19b83UUECgYEA3TNk +JVGWYLMcD3uVTe2e/yZSsX+0+QL8hm3bUSOIJ/mIe2dqCXb6MK0ndMS0aCLGtDSt +wGTWwuc4rFattHYEI8Iro+tshgQs9bLM037hmiCrZvmcQsgt+3FNuYv4oCGp5U85 +mWYF5SVUYRyv8M9aZoKTjc8meR0Wv3ZGGC9iDw0CgYA0XKyAPGO+MmB0Wx1J6Jfw +P2o2JB7I5e5DAbArrluSoSwx1YSApt6c6/tGBn+L16r+iYMPTu8ql6UAeUfzr9u8 +d02+mfU7Ppi3Zqn+2n/49ERHNLuzlLU5JzkPYcSDf2q/lGAby3vy4u1YkTx1IWac +gtLIg8q9ZtjDFLHeYcZfQQKBgCCOpdjQT1/gPOsSd4FGzjYjv9wcPdjA1cY7eSJS +JoIruijfqb3G40Ay3DHVmfAR3kk7z68XqHx7Z94Fy/9Zt3ZD6ARybEC1cKChNoCS +lkYHNPMtHhC+QfZWUOhUb72x9r2nkYTAfXGisu6wOD0rZ9TatzkSGkmNPIHluJ9q +qfYpAoGAPJiBBdSt7DC9ZZraQGMEHfRkE5CxEIRbIHJ9+U3Z7LTQT6MJ1y3VfcGs +PetHcWtbU0Cl8blShaSwpxyCI01x3tUPw/b7tXMan/ImzjUgRe7kQXh2sf39V3b/ +fvzKXWBvOvc1lgG0pFgI/2xtGQQGTe74MzX5xFgw6eadRUnJeKI= +-----END RSA PRIVATE KEY----- diff --git a/test/fixtures/wpt/README.md b/test/fixtures/wpt/README.md index 37d52a069aebc9..fef6bb0fd8c30d 100644 --- a/test/fixtures/wpt/README.md +++ b/test/fixtures/wpt/README.md @@ -21,7 +21,7 @@ Last update: - html/webappapis/timers: https://github.com/web-platform-tests/wpt/tree/5873f2d8f1/html/webappapis/timers - interfaces: https://github.com/web-platform-tests/wpt/tree/79fa4cf76e/interfaces - resources: https://github.com/web-platform-tests/wpt/tree/972ca5b669/resources -- url: https://github.com/web-platform-tests/wpt/tree/5eebfdb1f6/url +- url: https://github.com/web-platform-tests/wpt/tree/1439087f27/url [Web Platform Tests]: https://github.com/web-platform-tests/wpt [`git node wpt`]: https://github.com/nodejs/node-core-utils/blob/master/docs/git-node.md#git-node-wpt diff --git a/test/fixtures/wpt/url/resources/urltestdata.json b/test/fixtures/wpt/url/resources/urltestdata.json index dfb226deacde13..bb156f126bf9b6 100644 --- a/test/fixtures/wpt/url/resources/urltestdata.json +++ b/test/fixtures/wpt/url/resources/urltestdata.json @@ -5945,6 +5945,120 @@ "search": "", "hash": "" }, + "# Copy the host from the base URL in the following cases", + { + "input": "C|/", + "base": "file://host/", + "href": "file://host/C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "host", + "hostname": "host", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, + { + "input": "/C:/", + "base": "file://host/", + "href": "file://host/C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "host", + "hostname": "host", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, + { + "input": "file:C:/", + "base": "file://host/", + "href": "file://host/C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "host", + "hostname": "host", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, + { + "input": "file:/C:/", + "base": "file://host/", + "href": "file://host/C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "host", + "hostname": "host", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, + "# Copy the empty host from the input in the following cases", + { + "input": "//C:/", + "base": "file://host/", + "href": "file:///C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, + { + "input": "file://C:/", + "base": "file://host/", + "href": "file:///C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, + { + "input": "///C:/", + "base": "file://host/", + "href": "file:///C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, + { + "input": "file:///C:/", + "base": "file://host/", + "href": "file:///C:/", + "protocol": "file:", + "username": "", + "password": "", + "host": "", + "hostname": "", + "port": "", + "pathname": "/C:/", + "search": "", + "hash": "" + }, "# Windows drive letter quirk (no host)", { "input": "file:/C|/", diff --git a/test/fixtures/wpt/url/urlsearchparams-stringifier.any.js b/test/fixtures/wpt/url/urlsearchparams-stringifier.any.js index bc7bedd533f58d..6187db64b1747d 100644 --- a/test/fixtures/wpt/url/urlsearchparams-stringifier.any.js +++ b/test/fixtures/wpt/url/urlsearchparams-stringifier.any.js @@ -133,3 +133,13 @@ test(() => { assert_equals(url.toString(), 'http://www.example.com/?a=b%2Cc&x=y'); assert_equals(params.toString(), 'a=b%2Cc&x=y'); }, 'URLSearchParams connected to URL'); + +test(() => { + const url = new URL('http://www.example.com/'); + const params = url.searchParams; + + params.append('a\nb', 'c\rd'); + params.append('e\n\rf', 'g\r\nh'); + + assert_equals(params.toString(), "a%0Ab=c%0Dd&e%0A%0Df=g%0D%0Ah"); +}, 'URLSearchParams must not do newline normalization'); diff --git a/test/fixtures/wpt/versions.json b/test/fixtures/wpt/versions.json index b637bc8a8ab344..67df1aaa931761 100644 --- a/test/fixtures/wpt/versions.json +++ b/test/fixtures/wpt/versions.json @@ -44,7 +44,7 @@ "path": "resources" }, "url": { - "commit": "5eebfdb1f68059549b3efff380dd190bc6078266", + "commit": "1439087f27135b06deb70ffbf43e65ff64ff1ee6", "path": "url" } } \ No newline at end of file diff --git a/test/inspector-cli/inspector-cli.status b/test/inspector-cli/inspector-cli.status new file mode 100644 index 00000000000000..23a6558541513a --- /dev/null +++ b/test/inspector-cli/inspector-cli.status @@ -0,0 +1,7 @@ +prefix inspector-cli + +# To mark a test as flaky, list the test name in the appropriate section +# below, without ".js", followed by ": PASS,FLAKY". Example: +# sample-test : PASS,FLAKY + +[true] # This section applies to all platforms diff --git a/deps/node-inspect/test/cli/address.test.js b/test/inspector-cli/test-inspector-cli-address.js similarity index 68% rename from deps/node-inspect/test/cli/address.test.js rename to test/inspector-cli/test-inspector-cli-address.js index 1dbe4f37b42175..ff31747016c2d4 100644 --- a/deps/node-inspect/test/cli/address.test.js +++ b/test/inspector-cli/test-inspector-cli-address.js @@ -1,9 +1,13 @@ 'use strict'; -const { spawn } = require('child_process'); -const Path = require('path'); -const { test } = require('tap'); +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); -const startCLI = require('./start-cli'); +const assert = require('assert'); +const { spawn } = require('child_process'); // NOTE(oyyd): We might want to import this regexp from "lib/_inspect.js"? const kDebuggerMsgReg = /Debugger listening on ws:\/\/\[?(.+?)\]?:(\d+)\//; @@ -12,11 +16,13 @@ function launchTarget(...args) { const childProc = spawn(process.execPath, args); return new Promise((resolve, reject) => { const onExit = () => { - reject(new Error('Child process exits unexpectly')); + reject(new Error('Child process exits unexpectedly')); }; childProc.on('exit', onExit); childProc.stderr.setEncoding('utf8'); - childProc.stderr.on('data', (data) => { + let data = ''; + childProc.stderr.on('data', (chunk) => { + data += chunk; const ret = kDebuggerMsgReg.exec(data); childProc.removeListener('exit', onExit); if (ret) { @@ -30,12 +36,8 @@ function launchTarget(...args) { }); } -// process.debugPort is our proxy for "the version of node used to run this -// test suite doesn't support SIGUSR1 for enabling --inspect for a process". -const defaultsToOldProtocol = process.debugPort === 5858; - -test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => { - const script = Path.join('examples', 'alive.js'); +{ + const script = fixtures.path('inspector-cli/alive.js'); let cli = null; let target = null; @@ -48,7 +50,7 @@ test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => { target.kill(); target = null; } - if (error) throw error; + assert.ifError(error); } return launchTarget('--inspect=0', script) @@ -61,11 +63,11 @@ test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => { .then(() => cli.waitFor(/break/)) .then(() => cli.waitForPrompt()) .then(() => { - t.match( + assert.match( cli.output, - '> 3 ++x;', + /> 3 \+\+x;/, 'marks the 3rd line'); }) .then(() => cleanup()) .then(null, cleanup); -}); +} diff --git a/test/inspector-cli/test-inspector-cli-auto-resume.js b/test/inspector-cli/test-inspector-cli-auto-resume.js new file mode 100644 index 00000000000000..9a210176a51705 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-auto-resume.js @@ -0,0 +1,36 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); +const { addLibraryPath } = require('../common/shared-lib-util'); + +const assert = require('assert'); +const path = require('path'); + +addLibraryPath(process.env); + +// Auto-resume on start if the environment variable is defined. +{ + const scriptFullPath = fixtures.path('inspector-cli', 'break.js'); + const script = path.relative(process.cwd(), scriptFullPath); + + const env = { ...process.env }; + env.NODE_INSPECT_RESUME_ON_START = '1'; + + const cli = startCLI([script], [], { env }); + + cli.waitForInitialBreak() + .then(() => { + assert.deepStrictEqual( + cli.breakInfo, + { filename: script, line: 10 }, + ); + }) + .then(() => cli.quit()) + .then((code) => { + assert.strictEqual(code, 0); + }); +} diff --git a/test/inspector-cli/test-inspector-cli-backtrace.js b/test/inspector-cli/test-inspector-cli-backtrace.js new file mode 100644 index 00000000000000..baf2cfe8b58673 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-backtrace.js @@ -0,0 +1,36 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const path = require('path'); + +// Display and navigate backtrace. +{ + const scriptFullPath = fixtures.path('inspector-cli', 'backtrace.js'); + const script = path.relative(process.cwd(), scriptFullPath); + const cli = startCLI([script]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + return cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.stepCommand('c')) + .then(() => cli.command('bt')) + .then(() => { + assert.ok(cli.output.includes(`#0 topFn ${script}:7:2`)); + }) + .then(() => cli.command('backtrace')) + .then(() => { + assert.ok(cli.output.includes(`#0 topFn ${script}:7:2`)); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-break.js b/test/inspector-cli/test-inspector-cli-break.js new file mode 100644 index 00000000000000..ec6f354a7e7169 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-break.js @@ -0,0 +1,131 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const path = require('path'); + +// Stepping through breakpoints. +{ + const scriptFullPath = fixtures.path('inspector-cli', 'break.js'); + const script = path.relative(process.cwd(), scriptFullPath); + const cli = startCLI([script]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => { + assert.deepStrictEqual( + cli.breakInfo, + { filename: script, line: 1 }, + ); + assert.match( + cli.output, + /> 1 (?:\(function \([^)]+\) \{ )?const x = 10;/, + 'shows the source and marks the current line'); + }) + .then(() => cli.stepCommand('n')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${script}:2`), + 'pauses in next line of the script'); + assert.match( + cli.output, + /> 2 let name = 'World';/, + 'marks the 2nd line'); + }) + .then(() => cli.stepCommand('next')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${script}:3`), + 'pauses in next line of the script'); + assert.match( + cli.output, + /> 3 name = 'Robin';/, + 'marks the 3nd line'); + }) + .then(() => cli.stepCommand('cont')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${script}:10`), + 'pauses on the next breakpoint'); + assert.match( + cli.output, + />10 debugger;/, + 'marks the debugger line'); + }) + + // Prepare additional breakpoints + .then(() => cli.command('sb("break.js", 6)')) + .then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/)) + .then(() => cli.command('sb("otherFunction()")')) + .then(() => cli.command('sb(16)')) + .then(() => assert.doesNotMatch(cli.output, /Could not resolve breakpoint/)) + .then(() => cli.command('breakpoints')) + .then(() => { + assert.ok(cli.output.includes(`#0 ${script}:6`)); + assert.ok(cli.output.includes(`#1 ${script}:16`)); + }) + + .then(() => cli.command('list()')) + .then(() => { + assert.match( + cli.output, + />10 debugger;/, + 'prints and marks current line' + ); + assert.deepStrictEqual( + cli.parseSourceLines(), + [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], + ); + }) + .then(() => cli.command('list(2)')) + .then(() => { + assert.match( + cli.output, + />10 debugger;/, + 'prints and marks current line' + ); + assert.deepStrictEqual( + cli.parseSourceLines(), + [8, 9, 10, 11, 12], + ); + }) + + .then(() => cli.stepCommand('s')) + .then(() => cli.stepCommand('')) + .then(() => { + assert.match( + cli.output, + /break in node:timers/, + 'entered timers.js'); + }) + .then(() => cli.stepCommand('cont')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${script}:16`), + 'found breakpoint we set above w/ line number only'); + }) + .then(() => cli.stepCommand('cont')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${script}:6`), + 'found breakpoint we set above w/ line number & script'); + }) + .then(() => cli.stepCommand('')) + .then(() => { + assert.ok( + cli.output.includes(`debugCommand in ${script}:14`), + 'found function breakpoint we set above'); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-clear-breakpoints.js b/test/inspector-cli/test-inspector-cli-clear-breakpoints.js new file mode 100644 index 00000000000000..0b9f3b113d5b2f --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-clear-breakpoints.js @@ -0,0 +1,53 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const path = require('path'); + +// clearBreakpoint +{ + const scriptFullPath = fixtures.path('inspector-cli', 'break.js'); + const script = path.relative(process.cwd(), scriptFullPath); + const cli = startCLI([script]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + return cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.command('sb("break.js", 3)')) + .then(() => cli.command('sb("break.js", 9)')) + .then(() => cli.command('breakpoints')) + .then(() => { + assert.ok(cli.output.includes(`#0 ${script}:3`)); + assert.ok(cli.output.includes(`#1 ${script}:9`)); + }) + .then(() => cli.command('clearBreakpoint("break.js", 4)')) + .then(() => { + assert.match(cli.output, /Could not find breakpoint/); + }) + .then(() => cli.command('clearBreakpoint("not-such-script.js", 3)')) + .then(() => { + assert.match(cli.output, /Could not find breakpoint/); + }) + .then(() => cli.command('clearBreakpoint("break.js", 3)')) + .then(() => cli.command('breakpoints')) + .then(() => { + assert.ok(cli.output.includes(`#0 ${script}:9`)); + }) + .then(() => cli.stepCommand('cont')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${script}:9`), + 'hits the 2nd breakpoint because the 1st was cleared'); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-custom-port.js b/test/inspector-cli/test-inspector-cli-custom-port.js new file mode 100644 index 00000000000000..85d7e4154a16fe --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-custom-port.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +// Custom port. +{ + const script = fixtures.path('inspector-cli', 'three-lines.js'); + + const cli = startCLI([`--port=${common.PORT}`, script]); + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => { + assert.match(cli.output, /debug>/, 'prints a prompt'); + assert.match( + cli.output, + new RegExp(`< Debugger listening on [^\n]*${common.PORT}`), + 'forwards child output'); + }) + .then(() => cli.quit()) + .then((code) => { + assert.strictEqual(code, 0); + }); +} diff --git a/deps/node-inspect/test/cli/exceptions.test.js b/test/inspector-cli/test-inspector-cli-exceptions.js similarity index 55% rename from deps/node-inspect/test/cli/exceptions.test.js rename to test/inspector-cli/test-inspector-cli-exceptions.js index 69d42d0a25bb1a..dc579d0197303a 100644 --- a/deps/node-inspect/test/cli/exceptions.test.js +++ b/test/inspector-cli/test-inspector-cli-exceptions.js @@ -1,12 +1,18 @@ 'use strict'; -const Path = require('path'); +const common = require('../common'); -const { test } = require('tap'); +common.skipIfInspectorDisabled(); -const startCLI = require('./start-cli'); +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); -test('break on (uncaught) exceptions', (t) => { - const script = Path.join('examples', 'exceptions.js'); +const assert = require('assert'); +const path = require('path'); + +// Break on (uncaught) exceptions. +{ + const scriptFullPath = fixtures.path('inspector-cli', 'exceptions.js'); + const script = path.relative(process.cwd(), scriptFullPath); const cli = startCLI([script]); function onFatal(error) { @@ -14,42 +20,42 @@ test('break on (uncaught) exceptions', (t) => { throw error; } - return cli.waitForInitialBreak() + cli.waitForInitialBreak() .then(() => cli.waitForPrompt()) .then(() => { - t.match(cli.breakInfo, { filename: script, line: 1 }); + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); }) - // making sure it will die by default: + // Making sure it will die by default: .then(() => cli.command('c')) - // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore + // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore. .then(() => cli.waitFor(/disconnect|FATAL ERROR/)) - // Next run: With `breakOnException` it pauses in both places + // Next run: With `breakOnException` it pauses in both places. .then(() => cli.stepCommand('r')) .then(() => cli.waitForInitialBreak()) .then(() => { - t.match(cli.breakInfo, { filename: script, line: 1 }); + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); }) .then(() => cli.command('breakOnException')) .then(() => cli.stepCommand('c')) .then(() => { - t.match(cli.output, `exception in ${script}:3`); + assert.ok(cli.output.includes(`exception in ${script}:3`)); }) .then(() => cli.stepCommand('c')) .then(() => { - t.match(cli.output, `exception in ${script}:9`); + assert.ok(cli.output.includes(`exception in ${script}:9`)); }) - // Next run: With `breakOnUncaught` it only pauses on the 2nd exception + // Next run: With `breakOnUncaught` it only pauses on the 2nd exception. .then(() => cli.command('breakOnUncaught')) - .then(() => cli.stepCommand('r')) // also, the setting survives the restart + .then(() => cli.stepCommand('r')) // Also, the setting survives the restart. .then(() => cli.waitForInitialBreak()) .then(() => { - t.match(cli.breakInfo, { filename: script, line: 1 }); + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); }) .then(() => cli.stepCommand('c')) .then(() => { - t.match(cli.output, `exception in ${script}:9`); + assert.ok(cli.output.includes(`exception in ${script}:9`)); }) // Next run: Back to the initial state! It should die again. @@ -57,7 +63,7 @@ test('break on (uncaught) exceptions', (t) => { .then(() => cli.stepCommand('r')) .then(() => cli.waitForInitialBreak()) .then(() => { - t.match(cli.breakInfo, { filename: script, line: 1 }); + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); }) .then(() => cli.command('c')) // TODO: Remove FATAL ERROR once node doesn't show a FATAL ERROR anymore @@ -65,4 +71,4 @@ test('break on (uncaught) exceptions', (t) => { .then(() => cli.quit()) .then(null, onFatal); -}); +} diff --git a/test/inspector-cli/test-inspector-cli-exec-scope.js b/test/inspector-cli/test-inspector-cli-exec-scope.js new file mode 100644 index 00000000000000..23e376815319c8 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-exec-scope.js @@ -0,0 +1,38 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +// exec .scope +{ + const cli = startCLI([fixtures.path('inspector-cli/backtrace.js')]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.stepCommand('c')) + .then(() => cli.command('exec .scope')) + .then(() => { + assert.match( + cli.output, + /'moduleScoped'/, 'displays closure from module body'); + assert.match(cli.output, /'a'/, 'displays local / function arg'); + assert.match(cli.output, /'l1'/, 'displays local scope'); + assert.doesNotMatch( + cli.output, + /'encodeURIComponent'/, + 'omits global scope' + ); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-exec.js b/test/inspector-cli/test-inspector-cli-exec.js new file mode 100644 index 00000000000000..e1de786ab21302 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-exec.js @@ -0,0 +1,67 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +{ + + const cli = startCLI([fixtures.path('inspector-cli/alive.js')]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.command('exec [typeof heartbeat, typeof process.exit]')) + .then(() => { + assert.match( + cli.output, + /\[ 'function', 'function' \]/, + 'works w/o paren' + ); + }) + .then(() => cli.command('repl')) + .then(() => { + assert.match( + cli.output, + /Press Ctrl\+C to leave debug repl\n+> /, + 'shows hint for how to leave repl'); + assert.doesNotMatch(cli.output, /debug>/, 'changes the repl style'); + }) + .then(() => cli.command('[typeof heartbeat, typeof process.exit]')) + .then(() => cli.waitFor(/function/)) + .then(() => cli.waitForPrompt()) + .then(() => { + assert.match( + cli.output, + /\[ 'function', 'function' \]/, 'can evaluate in the repl'); + assert.match(cli.output, /> $/); + }) + .then(() => cli.ctrlC()) + .then(() => cli.waitFor(/debug> $/)) + .then(() => cli.command('exec("[typeof heartbeat, typeof process.exit]")')) + .then(() => { + assert.match( + cli.output, + /\[ 'function', 'function' \]/, + 'works w/ paren' + ); + }) + .then(() => cli.command('cont')) + .then(() => cli.command('exec [typeof heartbeat, typeof process.exit]')) + .then(() => { + assert.match( + cli.output, + /\[ 'undefined', 'function' \]/, + 'non-paused exec can see global but not module-scope values'); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-heap-profiler.js b/test/inspector-cli/test-inspector-cli-heap-profiler.js new file mode 100644 index 00000000000000..8602b8f8d11268 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-heap-profiler.js @@ -0,0 +1,37 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +if (!common.isMainThread) { + common.skip('process.chdir() is not available in workers'); +} + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); +const tmpdir = require('../common/tmpdir'); + +tmpdir.refresh(); +process.chdir(tmpdir.path); + +const { readFileSync } = require('fs'); + +const filename = 'node.heapsnapshot'; + +// Heap profiler take snapshot. +{ + const cli = startCLI([fixtures.path('inspector-cli/empty.js')]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + // Check that the snapshot is valid JSON. + return cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.command('takeHeapSnapshot()')) + .then(() => JSON.parse(readFileSync(filename, 'utf8'))) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-help.js b/test/inspector-cli/test-inspector-cli-help.js new file mode 100644 index 00000000000000..78a48b6f9ab159 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-help.js @@ -0,0 +1,27 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +{ + const cli = startCLI([fixtures.path('inspector-cli/empty.js')]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + return cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.command('help')) + .then(() => { + assert.match(cli.output, /run, restart, r\s+/m); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-invalid-args.js b/test/inspector-cli/test-inspector-cli-invalid-args.js new file mode 100644 index 00000000000000..327b076d78cfb8 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-invalid-args.js @@ -0,0 +1,59 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const { createServer } = require('net'); + +// Launch CLI w/o args. +{ + const cli = startCLI([]); + cli.quit() + .then((code) => { + assert.strictEqual(code, 1); + assert.match(cli.output, /^Usage:/, 'Prints usage info'); + }); +} + +// Launch w/ invalid host:port. +{ + const cli = startCLI(['localhost:914']); + cli.quit() + .then((code) => { + assert.match( + cli.output, + /failed to connect/, + 'Tells the user that the connection failed'); + assert.strictEqual(code, 1); + }); +} + +// Launch w/ unavailable port. +(async () => { + const blocker = createServer((socket) => socket.end()); + const port = await new Promise((resolve, reject) => { + blocker.on('error', reject); + blocker.listen(0, '127.0.0.1', () => resolve(blocker.address().port)); + }); + + try { + const script = fixtures.path('inspector-cli', 'three-lines.js'); + const cli = startCLI([`--port=${port}`, script]); + const code = await cli.quit(); + + assert.doesNotMatch( + cli.output, + /report this bug/, + 'Omits message about reporting this as a bug'); + assert.ok( + cli.output.includes(`waiting for 127.0.0.1:${port} to be free`), + 'Tells the user that the port wasn\'t available'); + assert.strictEqual(code, 1); + } finally { + blocker.close(); + } +})().then(common.mustCall()); diff --git a/test/inspector-cli/test-inspector-cli-launch.js b/test/inspector-cli/test-inspector-cli-launch.js new file mode 100644 index 00000000000000..e501a6b6123c47 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-launch.js @@ -0,0 +1,47 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +{ + const script = fixtures.path('inspector-cli', 'three-lines.js'); + const cli = startCLI([script]); + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => { + assert.match(cli.output, /debug>/, 'prints a prompt'); + assert.match( + cli.output, + /< Debugger listening on [^\n]*9229/, + 'forwards child output'); + }) + .then(() => cli.command('["hello", "world"].join(" ")')) + .then(() => { + assert.match(cli.output, /hello world/, 'prints the result'); + }) + .then(() => cli.command('')) + .then(() => { + assert.match( + cli.output, + /hello world/, + 'repeats the last command on ' + ); + }) + .then(() => cli.command('version')) + .then(() => { + assert.ok( + cli.output.includes(process.versions.v8), + 'version prints the v8 version' + ); + }) + .then(() => cli.quit()) + .then((code) => { + assert.strictEqual(code, 0); + }); +} diff --git a/deps/node-inspect/test/cli/low-level.test.js b/test/inspector-cli/test-inspector-cli-low-level.js similarity index 57% rename from deps/node-inspect/test/cli/low-level.test.js rename to test/inspector-cli/test-inspector-cli-low-level.js index 2a41359825612f..2613e4a4bbc2a3 100644 --- a/deps/node-inspect/test/cli/low-level.test.js +++ b/test/inspector-cli/test-inspector-cli-low-level.js @@ -1,11 +1,16 @@ 'use strict'; -const { test } = require('tap'); +const common = require('../common'); -const startCLI = require('./start-cli'); +common.skipIfInspectorDisabled(); -test('Debugger agent direct access', (t) => { - const cli = startCLI(['examples/three-lines.js']); - const scriptPattern = /^\* (\d+): examples(?:\/|\\)three-lines.js/; +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); +const assert = require('assert'); + +// Debugger agent direct access. +{ + const cli = startCLI([fixtures.path('inspector-cli/three-lines.js')]); + const scriptPattern = /^\* (\d+): \S+inspector-cli(?:\/|\\)three-lines\.js/m; function onFatal(error) { cli.quit(); @@ -22,13 +27,13 @@ test('Debugger agent direct access', (t) => { ); }) .then(() => { - t.match( + assert.match( cli.output, /scriptSource:[ \n]*'(?:\(function \(|let x = 1)/); - t.match( + assert.match( cli.output, /let x = 1;/); }) .then(() => cli.quit()) .then(null, onFatal); -}); +} diff --git a/deps/node-inspect/test/cli/pid.test.js b/test/inspector-cli/test-inspector-cli-pid.js similarity index 61% rename from deps/node-inspect/test/cli/pid.test.js rename to test/inspector-cli/test-inspector-cli-pid.js index 15d7fdeaa5f49b..97de9f40369d2d 100644 --- a/deps/node-inspect/test/cli/pid.test.js +++ b/test/inspector-cli/test-inspector-cli-pid.js @@ -1,22 +1,22 @@ 'use strict'; -const { spawn } = require('child_process'); -const Path = require('path'); +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); -const { test } = require('tap'); +const assert = require('assert'); +const { spawn } = require('child_process'); -const startCLI = require('./start-cli'); function launchTarget(...args) { const childProc = spawn(process.execPath, args); return Promise.resolve(childProc); } -// process.debugPort is our proxy for "the version of node used to run this -// test suite doesn't support SIGUSR1 for enabling --inspect for a process". -const defaultsToOldProtocol = process.debugPort === 5858; - -test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => { - const script = Path.join('examples', 'alive.js'); +{ + const script = fixtures.path('inspector-cli', 'alive.js'); let cli = null; let target = null; @@ -29,7 +29,7 @@ test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => { target.kill(); target = null; } - if (error) throw error; + assert.ifError(error); } return launchTarget(script) @@ -42,11 +42,11 @@ test('examples/alive.js', { skip: defaultsToOldProtocol }, (t) => { .then(() => cli.waitFor(/break/)) .then(() => cli.waitForPrompt()) .then(() => { - t.match( + assert.match( cli.output, - '> 3 ++x;', + /> 3 \+\+x;/, 'marks the 3rd line'); }) .then(() => cleanup()) .then(null, cleanup); -}); +} diff --git a/test/inspector-cli/test-inspector-cli-preserve-breaks.js b/test/inspector-cli/test-inspector-cli-preserve-breaks.js new file mode 100644 index 00000000000000..6863aaa45ae1b6 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-preserve-breaks.js @@ -0,0 +1,72 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const path = require('path'); + +// Run after quit. +{ + const scriptFullPath = fixtures.path('inspector-cli', 'three-lines.js'); + const script = path.relative(process.cwd(), scriptFullPath); + const cli = startCLI([script]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + return cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.command('breakpoints')) + .then(() => { + assert.match(cli.output, /No breakpoints yet/); + }) + .then(() => cli.command('sb(2)')) + .then(() => cli.command('sb(3)')) + .then(() => cli.command('breakpoints')) + .then(() => { + assert.ok(cli.output.includes(`#0 ${script}:2`)); + assert.ok(cli.output.includes(`#1 ${script}:3`)); + }) + .then(() => cli.stepCommand('c')) // hit line 2 + .then(() => cli.stepCommand('c')) // hit line 3 + .then(() => { + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 }); + }) + .then(() => cli.command('restart')) + .then(() => cli.waitForInitialBreak()) + .then(() => { + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 1 }); + }) + .then(() => cli.stepCommand('c')) + .then(() => { + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 2 }); + }) + .then(() => cli.stepCommand('c')) + .then(() => { + assert.deepStrictEqual(cli.breakInfo, { filename: script, line: 3 }); + }) + .then(() => cli.command('breakpoints')) + .then(() => { + // TODO: There is a known issue on AIX and some other operating systems + // where the breakpoints aren't properly resolved yet when we reach this + // point. Eventually that should be figured out but for now we don't + // want to fail builds because of it. + // What it should be: + // + // const msg = `SCRIPT: ${script}, OUTPUT: ${cli.output}`; + // assert.ok(cli.output.includes(`#0 ${script}:2`), msg); + // assert.ok(cli.output.includes(`#1 ${script}:3`), msg); + // + // What we're doing for now instead: + assert.match(cli.output, /#0 [^\n]+three-lines\.js\$?:2/); + assert.match(cli.output, /#1 [^\n]+three-lines\.js\$?:3/); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/deps/node-inspect/test/cli/profile.test.js b/test/inspector-cli/test-inspector-cli-profile.js similarity index 52% rename from deps/node-inspect/test/cli/profile.test.js rename to test/inspector-cli/test-inspector-cli-profile.js index 0f900c5a2b06f8..39b57448ffe628 100644 --- a/deps/node-inspect/test/cli/profile.test.js +++ b/test/inspector-cli/test-inspector-cli-profile.js @@ -1,14 +1,20 @@ 'use strict'; -const { test } = require('tap'); +const common = require('../common'); -const startCLI = require('./start-cli'); +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); function delay(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); } -test('profiles', (t) => { - const cli = startCLI(['examples/empty.js']); +// Profiles. +{ + const cli = startCLI([fixtures.path('inspector-cli/empty.js')]); function onFatal(error) { cli.quit(); @@ -19,14 +25,14 @@ test('profiles', (t) => { .then(() => cli.waitForPrompt()) .then(() => cli.command('exec console.profile()')) .then(() => { - t.match(cli.output, 'undefined'); + assert.match(cli.output, /undefined/); }) .then(() => cli.command('exec console.profileEnd()')) .then(() => delay(250)) .then(() => { - t.match(cli.output, 'undefined'); - t.match(cli.output, 'Captured new CPU profile.'); + assert.match(cli.output, /undefined/); + assert.match(cli.output, /Captured new CPU profile\./); }) .then(() => cli.quit()) .then(null, onFatal); -}); +} diff --git a/test/inspector-cli/test-inspector-cli-random-port-with-inspect-port.js b/test/inspector-cli/test-inspector-cli-random-port-with-inspect-port.js new file mode 100644 index 00000000000000..83c2b68b014b48 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-random-port-with-inspect-port.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +// Random port with --inspect-port=0. +{ + const script = fixtures.path('inspector-cli', 'three-lines.js'); + + const cli = startCLI(['--inspect-port=0', script]); + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => { + assert.match(cli.output, /debug>/, 'prints a prompt'); + assert.match( + cli.output, + /< Debugger listening on /, + 'forwards child output'); + }) + .then(() => cli.quit()) + .then((code) => { + assert.strictEqual(code, 0); + }); +} diff --git a/test/inspector-cli/test-inspector-cli-random-port.js b/test/inspector-cli/test-inspector-cli-random-port.js new file mode 100644 index 00000000000000..22de14661b8f64 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-random-port.js @@ -0,0 +1,30 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +// Random port. +{ + const script = fixtures.path('inspector-cli', 'three-lines.js'); + + const cli = startCLI(['--port=0', script]); + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => { + assert.match(cli.output, /debug>/, 'prints a prompt'); + assert.match( + cli.output, + /< Debugger listening on /, + 'forwards child output'); + }) + .then(() => cli.quit()) + .then((code) => { + assert.strictEqual(code, 0); + }); +} diff --git a/test/inspector-cli/test-inspector-cli-run-after-quit-restart.js b/test/inspector-cli/test-inspector-cli-run-after-quit-restart.js new file mode 100644 index 00000000000000..7f31d467198f23 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-run-after-quit-restart.js @@ -0,0 +1,90 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const path = require('path'); + +// Run after quit/restart. +{ + const scriptFullPath = fixtures.path('inspector-cli', 'three-lines.js'); + const script = path.relative(process.cwd(), scriptFullPath); + const cli = startCLI([script]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.stepCommand('n')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${script}:2`), + 'steps to the 2nd line' + ); + }) + .then(() => cli.command('cont')) + .then(() => cli.waitFor(/disconnect/)) + .then(() => { + assert.match( + cli.output, + /Waiting for the debugger to disconnect/, + 'the child was done'); + }) + .then(() => { + // On windows the socket won't close by itself + return cli.command('kill'); + }) + .then(() => cli.command('cont')) + .then(() => cli.waitFor(/start the app/)) + .then(() => { + assert.match(cli.output, /Use `run` to start the app again/); + }) + .then(() => cli.stepCommand('run')) + .then(() => cli.waitForInitialBreak()) + .then(() => cli.waitForPrompt()) + .then(() => { + assert.deepStrictEqual( + cli.breakInfo, + { filename: script, line: 1 }, + ); + }) + .then(() => cli.stepCommand('n')) + .then(() => { + assert.deepStrictEqual( + cli.breakInfo, + { filename: script, line: 2 }, + ); + }) + .then(() => cli.stepCommand('restart')) + .then(() => cli.waitForInitialBreak()) + .then(() => { + assert.deepStrictEqual( + cli.breakInfo, + { filename: script, line: 1 }, + ); + }) + .then(() => cli.command('kill')) + .then(() => cli.command('cont')) + .then(() => cli.waitFor(/start the app/)) + .then(() => { + assert.match(cli.output, /Use `run` to start the app again/); + }) + .then(() => cli.stepCommand('run')) + .then(() => cli.waitForInitialBreak()) + .then(() => cli.waitForPrompt()) + .then(() => { + assert.deepStrictEqual( + cli.breakInfo, + { filename: script, line: 1 }, + ); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/test/inspector-cli/test-inspector-cli-sb-before-load.js b/test/inspector-cli/test-inspector-cli-sb-before-load.js new file mode 100644 index 00000000000000..c99fb664a70768 --- /dev/null +++ b/test/inspector-cli/test-inspector-cli-sb-before-load.js @@ -0,0 +1,44 @@ +'use strict'; +const common = require('../common'); + +common.skipIfInspectorDisabled(); + +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); +const path = require('path'); + +// Using sb before loading file. +{ + const scriptFullPath = fixtures.path('inspector-cli', 'cjs', 'index.js'); + const script = path.relative(process.cwd(), scriptFullPath); + + const otherScriptFullPath = fixtures.path('inspector-cli', 'cjs', 'other.js'); + const otherScript = path.relative(process.cwd(), otherScriptFullPath); + + const cli = startCLI([script]); + + function onFatal(error) { + cli.quit(); + throw error; + } + + cli.waitForInitialBreak() + .then(() => cli.waitForPrompt()) + .then(() => cli.command('sb("other.js", 2)')) + .then(() => { + assert.match( + cli.output, + /not loaded yet/, + 'warns that the script was not loaded yet'); + }) + .then(() => cli.stepCommand('cont')) + .then(() => { + assert.ok( + cli.output.includes(`break in ${otherScript}:2`), + 'found breakpoint in file that was not loaded yet'); + }) + .then(() => cli.quit()) + .then(null, onFatal); +} diff --git a/deps/node-inspect/test/cli/scripts.test.js b/test/inspector-cli/test-inspector-cli-scripts.js similarity index 51% rename from deps/node-inspect/test/cli/scripts.test.js rename to test/inspector-cli/test-inspector-cli-scripts.js index f6e3f30dcafce0..893420d2aa4c2d 100644 --- a/deps/node-inspect/test/cli/scripts.test.js +++ b/test/inspector-cli/test-inspector-cli-scripts.js @@ -1,12 +1,16 @@ 'use strict'; -const Path = require('path'); +const common = require('../common'); -const { test } = require('tap'); +common.skipIfInspectorDisabled(); -const startCLI = require('./start-cli'); +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); -test('list scripts', (t) => { - const script = Path.join('examples', 'three-lines.js'); +const assert = require('assert'); + +// List scripts. +{ + const script = fixtures.path('inspector-cli', 'three-lines.js'); const cli = startCLI([script]); function onFatal(error) { @@ -18,26 +22,26 @@ test('list scripts', (t) => { .then(() => cli.waitForPrompt()) .then(() => cli.command('scripts')) .then(() => { - t.match( + assert.match( cli.output, - /^\* \d+: examples(?:\/|\\)three-lines\.js/, + /^\* \d+: \S+inspector-cli(?:\/|\\)three-lines\.js/m, 'lists the user script'); - t.notMatch( + assert.doesNotMatch( cli.output, - /\d+: buffer\.js /, + /\d+: node:internal\/buffer/, 'omits node-internal scripts'); }) .then(() => cli.command('scripts(true)')) .then(() => { - t.match( + assert.match( cli.output, - /\* \d+: examples(?:\/|\\)three-lines\.js/, + /\* \d+: \S+inspector-cli(?:\/|\\)three-lines\.js/, 'lists the user script'); - t.match( + assert.match( cli.output, - /\d+: buffer\.js /, + /\d+: node:internal\/buffer/, 'includes node-internal scripts'); }) .then(() => cli.quit()) .then(null, onFatal); -}); +} diff --git a/deps/node-inspect/test/cli/use-strict.test.js b/test/inspector-cli/test-inspector-cli-use-strict.js similarity index 54% rename from deps/node-inspect/test/cli/use-strict.test.js rename to test/inspector-cli/test-inspector-cli-use-strict.js index c6dc8f31cd82b5..c5b46b4f00e839 100644 --- a/deps/node-inspect/test/cli/use-strict.test.js +++ b/test/inspector-cli/test-inspector-cli-use-strict.js @@ -1,12 +1,16 @@ 'use strict'; -const Path = require('path'); +const common = require('../common'); -const { test } = require('tap'); +common.skipIfInspectorDisabled(); -const startCLI = require('./start-cli'); +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); -test('for whiles that starts with strict directive', (t) => { - const script = Path.join('examples', 'use-strict.js'); +const assert = require('assert'); + +// Test for files that start with strict directive. +{ + const script = fixtures.path('inspector-cli', 'use-strict.js'); const cli = startCLI([script]); function onFatal(error) { @@ -18,11 +22,11 @@ test('for whiles that starts with strict directive', (t) => { .then(() => cli.waitForPrompt()) .then(() => { const brk = cli.breakInfo; - t.match( + assert.match( `${brk.line}`, /^(1|2)$/, 'pauses either on strict directive or first "real" line'); }) .then(() => cli.quit()) .then(null, onFatal); -}); +} diff --git a/deps/node-inspect/test/cli/watchers.test.js b/test/inspector-cli/test-inspector-cli-watchers.js similarity index 56% rename from deps/node-inspect/test/cli/watchers.test.js rename to test/inspector-cli/test-inspector-cli-watchers.js index 46bcde19a2a4cf..e239e7ac74c216 100644 --- a/deps/node-inspect/test/cli/watchers.test.js +++ b/test/inspector-cli/test-inspector-cli-watchers.js @@ -1,10 +1,16 @@ 'use strict'; -const { test } = require('tap'); +const common = require('../common'); -const startCLI = require('./start-cli'); +common.skipIfInspectorDisabled(); -test('stepping through breakpoints', (t) => { - const cli = startCLI(['examples/break.js']); +const fixtures = require('../common/fixtures'); +const startCLI = require('../common/debugger'); + +const assert = require('assert'); + +// Stepping through breakpoints. +{ + const cli = startCLI([fixtures.path('inspector-cli/break.js')]); function onFatal(error) { cli.quit(); @@ -22,21 +28,21 @@ test('stepping through breakpoints', (t) => { .then(() => cli.command('watch("process.env")')) .then(() => cli.command('watchers')) .then(() => { - t.match(cli.output, 'x is not defined'); + assert.match(cli.output, /x is not defined/); }) .then(() => cli.command('unwatch("42")')) .then(() => cli.stepCommand('n')) .then(() => { - t.match(cli.output, '0: x = 10'); - t.match(cli.output, '1: "Hello" = \'Hello\''); - t.match(cli.output, '2: NaN = NaN'); - t.match(cli.output, '3: true = true'); - t.match(cli.output, '4: [1, 2] = [ 1, 2 ]'); - t.match( + assert.match(cli.output, /0: x = 10/); + assert.match(cli.output, /1: "Hello" = 'Hello'/); + assert.match(cli.output, /2: NaN = NaN/); + assert.match(cli.output, /3: true = true/); + assert.match(cli.output, /4: \[1, 2\] = \[ 1, 2 \]/); + assert.match( cli.output, /5: process\.env =\n\s+\{[\s\S]+,\n\s+\.\.\. \}/, 'shows "..." for process.env'); }) .then(() => cli.quit()) .then(null, onFatal); -}); +} diff --git a/test/inspector-cli/testcfg.py b/test/inspector-cli/testcfg.py new file mode 100644 index 00000000000000..d45972ac3f1357 --- /dev/null +++ b/test/inspector-cli/testcfg.py @@ -0,0 +1,6 @@ +import sys, os +sys.path.append(os.path.join(os.path.dirname(__file__), '..')) +import testpy + +def GetConfiguration(context, root): + return testpy.SimpleTestConfiguration(context, root, 'inspector-cli') diff --git a/test/message/core_line_numbers.out b/test/message/core_line_numbers.out index 215542404be02f..97b017f66e2395 100644 --- a/test/message/core_line_numbers.out +++ b/test/message/core_line_numbers.out @@ -1,9 +1,9 @@ -node:punycode:42 +node:punycode:52 throw new RangeError(errors[type]); ^ RangeError: Invalid input - at error (node:punycode:42:8) + at error (node:punycode:52:8) at Object.decode (node:punycode:*:*) at Object. (*test*message*core_line_numbers.js:*:*) at Module._compile (node:internal/modules/cjs/loader:*:*) diff --git a/test/message/testcfg.py b/test/message/testcfg.py index bd56a8eba8c4ce..4be454b55c9053 100644 --- a/test/message/testcfg.py +++ b/test/message/testcfg.py @@ -43,6 +43,7 @@ def __init__(self, path, file, expected, arch, mode, context, config): self.config = config self.arch = arch self.mode = mode + self.parallel = True def IgnoreLine(self, str): """Ignore empty lines and valgrind output.""" diff --git a/test/node-api/test_threadsafe_function/binding.c b/test/node-api/test_threadsafe_function/binding.c index 7e586aaba61c56..d64b9058b11326 100644 --- a/test/node-api/test_threadsafe_function/binding.c +++ b/test/node-api/test_threadsafe_function/binding.c @@ -7,7 +7,7 @@ #include #include "../../js-native-api/common.h" -#define ARRAY_LENGTH 10 +#define ARRAY_LENGTH 10000 #define MAX_QUEUE_SIZE 2 static uv_thread_t uv_threads[2]; @@ -72,7 +72,7 @@ static void data_source_thread(void* data) { for (index = ARRAY_LENGTH - 1; index > -1 && !queue_was_closing; index--) { status = napi_call_threadsafe_function(ts_fn, &ints[index], ts_fn_info->block_on_full); - if (ts_fn_info->max_queue_size == 0) { + if (ts_fn_info->max_queue_size == 0 && (index % 1000 == 0)) { // Let's make this thread really busy for 200 ms to give the main thread a // chance to abort. uint64_t start = uv_hrtime(); diff --git a/test/node-api/test_threadsafe_function/test.js b/test/node-api/test_threadsafe_function/test.js index 01542e4edb97e6..ff8a7d80849079 100644 --- a/test/node-api/test_threadsafe_function/test.js +++ b/test/node-api/test_threadsafe_function/test.js @@ -211,6 +211,15 @@ new Promise(function testWithoutJSMarshaller(resolve) { })) .then((result) => assert.strictEqual(result.indexOf(0), -1)) +// Make sure that threadsafe function isn't stalled when we hit +// `kMaxIterationCount` in `src/node_api.cc` +.then(() => testWithJSMarshaller({ + threadStarter: 'StartThreadNonblocking', + maxQueueSize: binding.ARRAY_LENGTH >>> 1, + quitAfter: binding.ARRAY_LENGTH +})) +.then((result) => assert.deepStrictEqual(result, expectedArray)) + // Start a child process to test rapid teardown .then(() => testUnref(binding.MAX_QUEUE_SIZE)) diff --git a/test/parallel/test-abortcontroller.js b/test/parallel/test-abortcontroller.js index 2f4fb495c75590..f7a70fbddbc89e 100644 --- a/test/parallel/test-abortcontroller.js +++ b/test/parallel/test-abortcontroller.js @@ -2,6 +2,7 @@ 'use strict'; const common = require('../common'); +const { inspect } = require('util'); const { ok, strictEqual, throws } = require('assert'); @@ -132,3 +133,11 @@ const { ok, strictEqual, throws } = require('assert'); ); } } + +{ + const ac = new AbortController(); + strictEqual(inspect(ac, { depth: 1 }), + 'AbortController { signal: [AbortSignal] }'); + strictEqual(inspect(ac, { depth: null }), + 'AbortController { signal: AbortSignal { aborted: false } }'); +} diff --git a/test/parallel/test-blob.js b/test/parallel/test-blob.js index 359ce3ba214412..6c880e9dea1c84 100644 --- a/test/parallel/test-blob.js +++ b/test/parallel/test-blob.js @@ -3,6 +3,7 @@ const common = require('../common'); const assert = require('assert'); const { Blob } = require('buffer'); +const { inspect } = require('util'); { const b = new Blob(); @@ -190,3 +191,10 @@ assert.throws(() => new Blob({}), { assert.strictEqual(text, 'test42'); })); } + +{ + const b = new Blob(); + assert.strictEqual(inspect(b, { depth: null }), + 'Blob { size: 0, type: \'\' }'); + assert.strictEqual(inspect(b, { depth: -1 }), '[Blob]'); +} diff --git a/test/parallel/test-crypto-async-sign-verify.js b/test/parallel/test-crypto-async-sign-verify.js index 4e3c32fdcd23fb..2e6c9e0bc539f4 100644 --- a/test/parallel/test-crypto-async-sign-verify.js +++ b/test/parallel/test-crypto-async-sign-verify.js @@ -3,6 +3,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const util = require('util'); const crypto = require('crypto'); diff --git a/test/parallel/test-crypto-dh-stateless.js b/test/parallel/test-crypto-dh-stateless.js index 6f99ebfb111e8a..658bd38fff655a 100644 --- a/test/parallel/test-crypto-dh-stateless.js +++ b/test/parallel/test-crypto-dh-stateless.js @@ -3,6 +3,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const crypto = require('crypto'); @@ -226,7 +229,7 @@ assert.throws(() => { crypto.generateKeyPairSync('ec', { namedCurve: not256k1 })); }, common.hasOpenSSL3 ? { name: 'Error', - code: 'ERR_OSSL_EC_INCOMPATIBLE_OBJECTS' + code: 'ERR_OSSL_MISMATCHING_SHARED_PARAMETERS' } : { name: 'Error', code: 'ERR_OSSL_EVP_DIFFERENT_PARAMETERS' diff --git a/test/parallel/test-crypto-dh.js b/test/parallel/test-crypto-dh.js index e35585e8eb19d1..cae9301517c37c 100644 --- a/test/parallel/test-crypto-dh.js +++ b/test/parallel/test-crypto-dh.js @@ -495,3 +495,7 @@ assert.throws( code: 'ERR_INVALID_ARG_TYPE' } ); +[true, Symbol(), {}, () => {}, []].forEach((generator) => assert.throws( + () => crypto.createDiffieHellman('', 'base64', generator), + { code: 'ERR_INVALID_ARG_TYPE' } +)); diff --git a/test/parallel/test-crypto-key-objects.js b/test/parallel/test-crypto-key-objects.js index d7b3f9af83acd9..6692dec4686e31 100644 --- a/test/parallel/test-crypto-key-objects.js +++ b/test/parallel/test-crypto-key-objects.js @@ -4,6 +4,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { createCipheriv, @@ -66,6 +69,16 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', }); } +{ + assert.throws(() => KeyObject.from('invalid_key'), { + name: 'TypeError', + code: 'ERR_INVALID_ARG_TYPE', + message: + 'The "key" argument must be an instance of CryptoKey. Received type ' + + "string ('invalid_key')" + }); +} + { const keybuf = randomBytes(32); const key = createSecretKey(keybuf); @@ -318,7 +331,10 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', type: 'pkcs1' }); createPrivateKey({ key, format: 'der', type: 'pkcs1' }); - }, { + }, common.hasOpenSSL3 ? { + message: /error:1E08010C:DECODER routines::unsupported/, + library: 'DECODER routines' + } : { message: /asn1 encoding/, library: 'asn1 encoding routines' }); @@ -504,7 +520,8 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', // Reading an encrypted key without a passphrase should fail. assert.throws(() => createPrivateKey(privateDsa), common.hasOpenSSL3 ? { name: 'Error', - message: 'Failed to read private key', + message: 'error:07880109:common libcrypto routines::interrupted or ' + + 'cancelled', } : { name: 'TypeError', code: 'ERR_MISSING_PASSPHRASE', @@ -530,7 +547,7 @@ const privateDsa = fixtures.readKey('dsa_private_encrypted_1025.pem', passphrase: Buffer.alloc(1024, 'a') }), { message: common.hasOpenSSL3 ? - 'Failed to read private key' : + 'error:07880109:common libcrypto routines::interrupted or cancelled' : /bad decrypt/ }); diff --git a/test/parallel/test-crypto-keygen.js b/test/parallel/test-crypto-keygen.js index cbf797c0ea2388..4612fc4a1ac40a 100644 --- a/test/parallel/test-crypto-keygen.js +++ b/test/parallel/test-crypto-keygen.js @@ -4,6 +4,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { constants, @@ -213,7 +216,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); const publicKey = { key: publicKeyDER, ...publicKeyEncoding }; const expectedError = common.hasOpenSSL3 ? { name: 'Error', - message: 'Failed to read private key' + message: 'error:07880109:common libcrypto routines::interrupted or ' + + 'cancelled' } : { name: 'TypeError', code: 'ERR_MISSING_PASSPHRASE', @@ -477,7 +481,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), common.hasOpenSSL3 ? { - message: 'Failed to read private key' + message: 'error:07880109:common libcrypto ' + + 'routines::interrupted or cancelled' } : { name: 'TypeError', code: 'ERR_MISSING_PASSPHRASE', @@ -510,7 +515,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), common.hasOpenSSL3 ? { - message: 'Failed to read private key' + message: 'error:07880109:common libcrypto ' + + 'routines::interrupted or cancelled' } : { name: 'TypeError', code: 'ERR_MISSING_PASSPHRASE', @@ -546,7 +552,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), common.hasOpenSSL3 ? { - message: 'Failed to read private key' + message: 'error:07880109:common libcrypto ' + + 'routines::interrupted or cancelled' } : { name: 'TypeError', code: 'ERR_MISSING_PASSPHRASE', @@ -583,7 +590,8 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); // Since the private key is encrypted, signing shouldn't work anymore. assert.throws(() => testSignVerify(publicKey, privateKey), common.hasOpenSSL3 ? { - message: 'Failed to read private key' + message: 'error:07880109:common libcrypto ' + + 'routines::interrupted or cancelled' } : { name: 'TypeError', code: 'ERR_MISSING_PASSPHRASE', @@ -958,7 +966,7 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); } // Test invalid divisor lengths. - for (const divisorLength of ['a', true, {}, [], 4096.1]) { + for (const divisorLength of ['a', true, {}, [], 4096.1, 2147483648, -1]) { assert.throws(() => generateKeyPair('dsa', { modulusLength: 2048, divisorLength @@ -1081,6 +1089,52 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); message: 'Unknown DH group' }); + assert.throws(() => { + generateKeyPair('dh', { + primeLength: 2147483648 + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.primeLength' is invalid. " + + 'Received 2147483648', + }); + + assert.throws(() => { + generateKeyPair('dh', { + primeLength: -1 + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.primeLength' is invalid. " + + 'Received -1', + }); + + assert.throws(() => { + generateKeyPair('dh', { + primeLength: 2, + generator: 2147483648, + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.generator' is invalid. " + + 'Received 2147483648', + }); + + assert.throws(() => { + generateKeyPair('dh', { + primeLength: 2, + generator: -1, + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.generator' is invalid. " + + 'Received -1', + }); + // Test incompatible options. const allOpts = { group: 'modp5', @@ -1142,6 +1196,35 @@ const sec1EncExp = (cipher) => getRegExpForPEM('EC PRIVATE KEY', cipher); }); } + // too long salt length + assert.throws(() => { + generateKeyPair('rsa-pss', { + modulusLength: 512, + saltLength: 2147483648, + hash: 'sha256', + mgf1Hash: 'sha256' + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.saltLength' is invalid. " + + 'Received 2147483648' + }); + + assert.throws(() => { + generateKeyPair('rsa-pss', { + modulusLength: 512, + saltLength: -1, + hash: 'sha256', + mgf1Hash: 'sha256' + }, common.mustNotCall()); + }, { + name: 'TypeError', + code: 'ERR_INVALID_ARG_VALUE', + message: "The property 'options.saltLength' is invalid. " + + 'Received -1' + }); + // Invalid private key type. for (const type of ['foo', 'spki']) { assert.throws(() => { diff --git a/test/parallel/test-crypto-pbkdf2.js b/test/parallel/test-crypto-pbkdf2.js index 260bdd394ce05e..c9ab6a9c48438e 100644 --- a/test/parallel/test-crypto-pbkdf2.js +++ b/test/parallel/test-crypto-pbkdf2.js @@ -231,3 +231,15 @@ if (!common.hasOpenSSL3) { runPBKDF2(new Uint8Array(10), 'salt', 8, 8, hash); }); } + +{ + // This should not crash. + assert.throws( + () => crypto.pbkdf2Sync('1', '2', 1, 1, '%'), + { + code: 'ERR_CRYPTO_INVALID_DIGEST', + name: 'TypeError', + message: 'Invalid digest: %' + } + ); +} diff --git a/test/parallel/test-crypto-private-decrypt-gh32240.js b/test/parallel/test-crypto-private-decrypt-gh32240.js index 875888622cb5f7..1785f5eef3d202 100644 --- a/test/parallel/test-crypto-private-decrypt-gh32240.js +++ b/test/parallel/test-crypto-private-decrypt-gh32240.js @@ -35,6 +35,7 @@ function decrypt(key) { decrypt(pkey); assert.throws(() => decrypt(pkeyEncrypted), common.hasOpenSSL3 ? - { message: 'Failed to read asymmetric key' } : + { message: 'error:07880109:common libcrypto routines::interrupted or ' + + 'cancelled' } : { code: 'ERR_MISSING_PASSPHRASE' }); decrypt(pkey); // Should not throw. diff --git a/test/parallel/test-crypto-rsa-dsa.js b/test/parallel/test-crypto-rsa-dsa.js index 94c810fa6f24c6..567d8650c5a177 100644 --- a/test/parallel/test-crypto-rsa-dsa.js +++ b/test/parallel/test-crypto-rsa-dsa.js @@ -3,6 +3,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const crypto = require('crypto'); @@ -37,10 +40,11 @@ const openssl1DecryptError = { }; const decryptError = common.hasOpenSSL3 ? - { message: 'Failed to read asymmetric key' } : openssl1DecryptError; + { message: 'error:1C800064:Provider routines::bad decrypt' } : + openssl1DecryptError; const decryptPrivateKeyError = common.hasOpenSSL3 ? { - message: 'Failed to read private key', + message: 'error:1C800064:Provider routines::bad decrypt', } : openssl1DecryptError; function getBufferCopy(buf) { diff --git a/test/parallel/test-crypto-scrypt.js b/test/parallel/test-crypto-scrypt.js index 9db69646bbfb0a..7b695a36f2b5a4 100644 --- a/test/parallel/test-crypto-scrypt.js +++ b/test/parallel/test-crypto-scrypt.js @@ -143,6 +143,10 @@ const badargs = [ args: ['', '', -42], expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, }, + { + args: ['', '', 2147485780], + expected: { code: 'ERR_OUT_OF_RANGE', message: /"keylen"/ }, + }, ]; for (const options of good) { diff --git a/test/parallel/test-crypto-sign-verify.js b/test/parallel/test-crypto-sign-verify.js index 1de8a42514e2b1..15fa3db4a69f19 100644 --- a/test/parallel/test-crypto-sign-verify.js +++ b/test/parallel/test-crypto-sign-verify.js @@ -3,6 +3,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const fs = require('fs'); const path = require('path'); @@ -44,9 +47,7 @@ const keySize = 2048; `-----BEGIN RSA PRIVATE KEY----- AAAAAAAAAAAA -----END RSA PRIVATE KEY-----`); - }, { message: common.hasOpenSSL3 ? - 'Failed to read private key' : - 'bye, bye, library' }); + }, { message: 'bye, bye, library' }); delete Object.prototype.library; diff --git a/test/parallel/test-eslint-non-ascii-character.js b/test/parallel/test-eslint-non-ascii-character.js new file mode 100644 index 00000000000000..0b4a09f813431b --- /dev/null +++ b/test/parallel/test-eslint-non-ascii-character.js @@ -0,0 +1,26 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); + +common.skipIfEslintMissing(); + +const RuleTester = require('../../tools/node_modules/eslint').RuleTester; +const rule = require('../../tools/eslint-rules/non-ascii-character'); + +new RuleTester().run('non-ascii-characters', rule, { + valid: [ + { + code: 'console.log("fhqwhgads")', + options: [] + }, + ], + invalid: [ + { + code: 'console.log("μ")', + options: [], + errors: [{ message: "Non-ASCII character 'μ' detected." }], + }, + ] +}); diff --git a/test/parallel/test-fs-promises-file-handle-aggregate-errors.js b/test/parallel/test-fs-promises-file-handle-aggregate-errors.js new file mode 100644 index 00000000000000..d4c3b37d652d12 --- /dev/null +++ b/test/parallel/test-fs-promises-file-handle-aggregate-errors.js @@ -0,0 +1,72 @@ +'use strict'; +// Flags: --expose-internals + +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); + +// The following tests validate aggregate errors are thrown correctly +// when both an operation and close throw. + +const path = require('path'); +const { + readFile, + writeFile, + truncate, + lchmod, +} = require('fs/promises'); +const { + FileHandle, +} = require('internal/fs/promises'); + +const assert = require('assert'); +const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd'); + +let count = 0; +async function createFile() { + const filePath = path.join(tmpdir.path, `aggregate_errors_${++count}.txt`); + await writeFile(filePath, 'content'); + return filePath; +} + +async function checkAggregateError(op) { + try { + const filePath = await createFile(); + Object.defineProperty(FileHandle.prototype, 'fd', { + get: function() { + // Close is set by using a setter, + // so it needs to be set on the instance. + const originalClose = this.close; + this.close = async () => { + // close the file + await originalClose.call(this); + const closeError = new Error('CLOSE_ERROR'); + closeError.code = 456; + throw closeError; + }; + const opError = new Error('INTERNAL_ERROR'); + opError.code = 123; + throw opError; + } + }); + + await assert.rejects(op(filePath), common.mustCall((err) => { + assert.strictEqual(err.name, 'AggregateError'); + assert.strictEqual(err.code, 123); + assert.strictEqual(err.errors.length, 2); + assert.strictEqual(err.errors[0].message, 'INTERNAL_ERROR'); + assert.strictEqual(err.errors[1].message, 'CLOSE_ERROR'); + return true; + })); + } finally { + Object.defineProperty(FileHandle.prototype, 'fd', originalFd); + } +} +(async function() { + tmpdir.refresh(); + await checkAggregateError((filePath) => truncate(filePath)); + await checkAggregateError((filePath) => readFile(filePath)); + await checkAggregateError((filePath) => writeFile(filePath, '123')); + if (common.isOSX) { + await checkAggregateError((filePath) => lchmod(filePath, 0o777)); + } +})().then(common.mustCall()); diff --git a/test/parallel/test-fs-promises-file-handle-close-errors.js b/test/parallel/test-fs-promises-file-handle-close-errors.js new file mode 100644 index 00000000000000..b975b3f3e1583c --- /dev/null +++ b/test/parallel/test-fs-promises-file-handle-close-errors.js @@ -0,0 +1,67 @@ +'use strict'; +// Flags: --expose-internals + +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); + +// The following tests validate aggregate errors are thrown correctly +// when both an operation and close throw. + +const path = require('path'); +const { + readFile, + writeFile, + truncate, + lchmod, +} = require('fs/promises'); +const { + FileHandle, +} = require('internal/fs/promises'); + +const assert = require('assert'); +const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd'); + +let count = 0; +async function createFile() { + const filePath = path.join(tmpdir.path, `close_errors_${++count}.txt`); + await writeFile(filePath, 'content'); + return filePath; +} + +async function checkCloseError(op) { + try { + const filePath = await createFile(); + Object.defineProperty(FileHandle.prototype, 'fd', { + get: function() { + // Close is set by using a setter, + // so it needs to be set on the instance. + const originalClose = this.close; + this.close = async () => { + // close the file + await originalClose.call(this); + const closeError = new Error('CLOSE_ERROR'); + closeError.code = 456; + throw closeError; + }; + return originalFd.get.call(this); + } + }); + + await assert.rejects(op(filePath), { + name: 'Error', + message: 'CLOSE_ERROR', + code: 456, + }); + } finally { + Object.defineProperty(FileHandle.prototype, 'fd', originalFd); + } +} +(async function() { + tmpdir.refresh(); + await checkCloseError((filePath) => truncate(filePath)); + await checkCloseError((filePath) => readFile(filePath)); + await checkCloseError((filePath) => writeFile(filePath, '123')); + if (common.isOSX) { + await checkCloseError((filePath) => lchmod(filePath, 0o777)); + } +})().then(common.mustCall()); diff --git a/test/parallel/test-fs-promises-file-handle-op-errors.js b/test/parallel/test-fs-promises-file-handle-op-errors.js new file mode 100644 index 00000000000000..7110b5d9d40467 --- /dev/null +++ b/test/parallel/test-fs-promises-file-handle-op-errors.js @@ -0,0 +1,61 @@ +'use strict'; +// Flags: --expose-internals + +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); + +// The following tests validate aggregate errors are thrown correctly +// when both an operation and close throw. + +const path = require('path'); +const { + readFile, + writeFile, + truncate, + lchmod, +} = require('fs/promises'); +const { + FileHandle, +} = require('internal/fs/promises'); + +const assert = require('assert'); +const originalFd = Object.getOwnPropertyDescriptor(FileHandle.prototype, 'fd'); + +let count = 0; +async function createFile() { + const filePath = path.join(tmpdir.path, `op_errors_${++count}.txt`); + await writeFile(filePath, 'content'); + return filePath; +} + +async function checkOperationError(op) { + try { + const filePath = await createFile(); + Object.defineProperty(FileHandle.prototype, 'fd', { + get: function() { + // Verify that close is called when an error is thrown + this.close = common.mustCall(this.close); + const opError = new Error('INTERNAL_ERROR'); + opError.code = 123; + throw opError; + } + }); + + await assert.rejects(op(filePath), { + name: 'Error', + message: 'INTERNAL_ERROR', + code: 123, + }); + } finally { + Object.defineProperty(FileHandle.prototype, 'fd', originalFd); + } +} +(async function() { + tmpdir.refresh(); + await checkOperationError((filePath) => truncate(filePath)); + await checkOperationError((filePath) => readFile(filePath)); + await checkOperationError((filePath) => writeFile(filePath, '123')); + if (common.isOSX) { + await checkOperationError((filePath) => lchmod(filePath, 0o777)); + } +})().then(common.mustCall()); diff --git a/test/parallel/test-fs-promises.js b/test/parallel/test-fs-promises.js index df7fa3e4733cba..f0140084732056 100644 --- a/test/parallel/test-fs-promises.js +++ b/test/parallel/test-fs-promises.js @@ -452,6 +452,16 @@ async function getHandle(dest) { assert.strictEqual(ret.bytesWritten, 2); await handle.close(); } + + // Test prototype methods calling with contexts other than FileHandle + { + const handle = await getHandle(dest); + assert.rejects(() => handle.stat.call({}), { + code: 'ERR_INTERNAL_ASSERTION', + message: /handle must be an instance of FileHandle/ + }); + await handle.close(); + } } doTest().then(common.mustCall()); diff --git a/test/parallel/test-fs-read-stream-pos.js b/test/parallel/test-fs-read-stream-pos.js new file mode 100644 index 00000000000000..c9470cb23ddeb6 --- /dev/null +++ b/test/parallel/test-fs-read-stream-pos.js @@ -0,0 +1,69 @@ +'use strict'; + +// Refs: https://github.com/nodejs/node/issues/33940 + +const common = require('../common'); +const tmpdir = require('../common/tmpdir'); +const fs = require('fs'); +const assert = require('assert'); +const path = require('path'); + +tmpdir.refresh(); + +const file = path.join(tmpdir.path, '/read_stream_pos_test.txt'); + +fs.writeFileSync(file, ''); + +let counter = 0; + +setInterval(() => { + counter = counter + 1; + const line = `hello at ${counter}\n`; + fs.writeFileSync(file, line, { flag: 'a' }); +}, 1); + +const hwm = 10; +let bufs = []; +let isLow = false; +let cur = 0; +let stream; + +setInterval(() => { + if (stream) return; + + stream = fs.createReadStream(file, { + highWaterMark: hwm, + start: cur + }); + stream.on('data', common.mustCallAtLeast((chunk) => { + cur += chunk.length; + bufs.push(chunk); + if (isLow) { + const brokenLines = Buffer.concat(bufs).toString() + .split('\n') + .filter((line) => { + const s = 'hello at'.slice(0, line.length); + if (line && !line.startsWith(s)) { + return true; + } + return false; + }); + assert.strictEqual(brokenLines.length, 0); + process.exit(); + return; + } + if (chunk.length !== hwm) { + isLow = true; + } + })); + stream.on('end', () => { + stream = null; + isLow = false; + bufs = []; + }); +}, 10); + +// Time longer than 90 seconds to exit safely +setTimeout(() => { + process.exit(); +}, 90000); diff --git a/test/parallel/test-fs-read-type.js b/test/parallel/test-fs-read-type.js index 81440ab57eb802..2baab18dc9f483 100644 --- a/test/parallel/test-fs-read-type.js +++ b/test/parallel/test-fs-read-type.js @@ -44,8 +44,6 @@ assert.throws(() => { }, { code: 'ERR_OUT_OF_RANGE', name: 'RangeError', - message: 'The value of "offset" is out of range. It must be >= 0. ' + - 'Received -1' }); assert.throws(() => { @@ -157,8 +155,6 @@ assert.throws(() => { }, { code: 'ERR_OUT_OF_RANGE', name: 'RangeError', - message: 'The value of "offset" is out of range. ' + - 'It must be >= 0. Received -1' }); assert.throws(() => { diff --git a/test/parallel/test-fs-read.js b/test/parallel/test-fs-read.js index 531eba00d2847d..5c9e59795fc39f 100644 --- a/test/parallel/test-fs-read.js +++ b/test/parallel/test-fs-read.js @@ -78,13 +78,21 @@ assert.throws( } ); -['buffer', 'offset', 'length'].forEach((option) => - assert.throws( - () => fs.read(fd, { - [option]: null - }), - `not throws when options.${option} is null` - )); +assert.throws( + () => fs.read(fd, { buffer: null }, common.mustNotCall()), + /TypeError: Cannot read property 'byteLength' of null/, + 'throws when options.buffer is null' +); + +assert.throws( + () => fs.readSync(fd, { buffer: null }), + { + name: 'TypeError', + message: 'The "buffer" argument must be an instance of Buffer, ' + + 'TypedArray, or DataView. Received an instance of Object', + }, + 'throws when options.buffer is null' +); assert.throws( () => fs.read(null, Buffer.alloc(1), 0, 1, 0), diff --git a/test/parallel/test-fs-readfile.js b/test/parallel/test-fs-readfile.js index a081eec099890d..c0dd16255b44fd 100644 --- a/test/parallel/test-fs-readfile.js +++ b/test/parallel/test-fs-readfile.js @@ -52,6 +52,23 @@ for (const e of fileInfo) { assert.deepStrictEqual(buf, e.contents); })); } +// Test readFile size too large +{ + const kIoMaxLength = 2 ** 31 - 1; + + const file = path.join(tmpdir.path, `${prefix}-too-large.txt`); + fs.writeFileSync(file, Buffer.from('0')); + fs.truncateSync(file, kIoMaxLength + 1); + + fs.readFile(file, common.expectsError({ + code: 'ERR_FS_FILE_TOO_LARGE', + name: 'RangeError', + })); + assert.throws(() => { + fs.readFileSync(file); + }, { code: 'ERR_FS_FILE_TOO_LARGE', name: 'RangeError' }); +} + { // Test cancellation, before const signal = AbortSignal.abort(); diff --git a/test/parallel/test-fs-write-negativeoffset.js b/test/parallel/test-fs-write-negativeoffset.js new file mode 100644 index 00000000000000..b1c6ed9039b7d7 --- /dev/null +++ b/test/parallel/test-fs-write-negativeoffset.js @@ -0,0 +1,55 @@ +'use strict'; + +// Tests that passing a negative offset does not crash the process + +const common = require('../common'); + +const { + join, +} = require('path'); + +const { + closeSync, + open, + write, + writeSync, +} = require('fs'); + +const assert = require('assert'); + +const tmpdir = require('../common/tmpdir'); +tmpdir.refresh(); + +const filename = join(tmpdir.path, 'test.txt'); + +open(filename, 'w+', common.mustSucceed((fd) => { + assert.throws(() => { + write(fd, Buffer.alloc(0), -1, common.mustNotCall()); + }, { + code: 'ERR_OUT_OF_RANGE', + }); + assert.throws(() => { + writeSync(fd, Buffer.alloc(0), -1); + }, { + code: 'ERR_OUT_OF_RANGE', + }); + closeSync(fd); +})); + +const filename2 = join(tmpdir.path, 'test2.txt'); + +// Make sure negative length's don't cause aborts either + +open(filename2, 'w+', common.mustSucceed((fd) => { + assert.throws(() => { + write(fd, Buffer.alloc(0), 0, -1, common.mustNotCall()); + }, { + code: 'ERR_OUT_OF_RANGE', + }); + assert.throws(() => { + writeSync(fd, Buffer.alloc(0), 0, -1); + }, { + code: 'ERR_OUT_OF_RANGE', + }); + closeSync(fd); +})); diff --git a/test/parallel/test-http-methods.js b/test/parallel/test-http-methods.js index d562f639503d0f..1142c175ecdb20 100644 --- a/test/parallel/test-http-methods.js +++ b/test/parallel/test-http-methods.js @@ -48,7 +48,6 @@ const methods = [ 'OPTIONS', 'PATCH', 'POST', - 'PRI', 'PROPFIND', 'PROPPATCH', 'PURGE', diff --git a/test/parallel/test-https-selfsigned-no-keycertsign-no-crash.js b/test/parallel/test-https-selfsigned-no-keycertsign-no-crash.js new file mode 100644 index 00000000000000..2dd46ac878c5b0 --- /dev/null +++ b/test/parallel/test-https-selfsigned-no-keycertsign-no-crash.js @@ -0,0 +1,63 @@ +'use strict'; +const common = require('../common'); +const fixtures = require('../common/fixtures'); + +// This test starts an https server and tries +// to connect to it using a self-signed certificate. +// This certificate´s keyUsage does not include the keyCertSign +// bit, which used to crash node. The test ensures node +// will not crash. Key and certificate are from #37889. +// Note: This test assumes that the connection will succeed. + +if (!common.hasCrypto) + common.skip('missing crypto'); + +const crypto = require('crypto'); + +// See #37990 for details on why this is problematic with FIPS. +if (process.config.variables.openssl_is_fips) + common.skip('Skipping as test uses non-fips compliant EC curve'); + +// This test will fail for OpenSSL < 1.1.1h +const minOpenSSL = 269488271; + +if (crypto.constants.OPENSSL_VERSION_NUMBER < minOpenSSL) + common.skip('OpenSSL < 1.1.1h'); + +const https = require('https'); +const path = require('path'); + +const key = + fixtures.readKey(path.join('selfsigned-no-keycertsign', 'key.pem')); + +const cert = + fixtures.readKey(path.join('selfsigned-no-keycertsign', 'cert.pem')); + +const serverOptions = { + key: key, + cert: cert +}; + +// Start the server +const httpsServer = https.createServer(serverOptions, (req, res) => { + res.writeHead(200); + res.end('hello world\n'); +}); +httpsServer.listen(0); + +httpsServer.on('listening', () => { + // Once the server started listening, built the client config + // with the server´s used port + const clientOptions = { + hostname: '127.0.0.1', + port: httpsServer.address().port, + ca: cert + }; + // Try to connect + const req = https.request(clientOptions, common.mustCall((res) => { + httpsServer.close(); + })); + + req.on('error', common.mustNotCall()); + req.end(); +}); diff --git a/test/parallel/test-icu-transcode.js b/test/parallel/test-icu-transcode.js index 20ecab7213b292..e9aced128eec21 100644 --- a/test/parallel/test-icu-transcode.js +++ b/test/parallel/test-icu-transcode.js @@ -83,3 +83,8 @@ assert.deepStrictEqual( const dest = buffer.transcode(new Uint8Array(), 'utf8', 'latin1'); assert.strictEqual(dest.length, 0); } + +// Test that it doesn't crash +{ + buffer.transcode(new buffer.SlowBuffer(1), 'utf16le', 'ucs2'); +} diff --git a/test/parallel/test-internal-iterable-weak-map.js b/test/parallel/test-internal-iterable-weak-map.js index e0282c9081ee33..f2befe13da87f3 100644 --- a/test/parallel/test-internal-iterable-weak-map.js +++ b/test/parallel/test-internal-iterable-weak-map.js @@ -1,10 +1,16 @@ // Flags: --expose-gc --expose-internals 'use strict'; -require('../common'); +const common = require('../common'); const { deepStrictEqual, strictEqual } = require('assert'); const { IterableWeakMap } = require('internal/util/iterable_weak_map'); +// Ensures iterating over the map does not rely on methods which can be +// mutated by users. +Reflect.getPrototypeOf(function*() {}).prototype.next = common.mustNotCall(); +Reflect.getPrototypeOf(new Set()[Symbol.iterator]()).next = + common.mustNotCall(); + // It drops entry if a reference is no longer held. { const wm = new IterableWeakMap(); diff --git a/test/parallel/test-messaging-maketransferable.js b/test/parallel/test-messaging-maketransferable.js new file mode 100644 index 00000000000000..07b1081045d99f --- /dev/null +++ b/test/parallel/test-messaging-maketransferable.js @@ -0,0 +1,27 @@ +// Flags: --expose-internals +'use strict'; + +const common = require('../common'); + +const assert = require('assert'); +const { + JSTransferable, +} = require('internal/worker/js_transferable'); +const { E, F } = require('internal/test/transfer'); + +// Tests that F is transferable even tho it does not directly, +// observably extend the JSTransferable class. + +const mc = new MessageChannel(); + +mc.port1.onmessageerror = common.mustNotCall(); + +mc.port1.onmessage = common.mustCall(({ data }) => { + assert(!(data instanceof JSTransferable)); + assert(data instanceof F); + assert(data instanceof E); + assert.strictEqual(data.b, 1); + mc.port1.close(); +}); + +mc.port2.postMessage(new F(1)); diff --git a/test/parallel/test-performanceobserver-gc.js b/test/parallel/test-performanceobserver-gc.js new file mode 100644 index 00000000000000..fe9397631c2d42 --- /dev/null +++ b/test/parallel/test-performanceobserver-gc.js @@ -0,0 +1,17 @@ +'use strict'; + +require('../common'); + +// Verifies that setting up two observers to listen +// to gc performance does not crash. + +const { + PerformanceObserver, +} = require('perf_hooks'); + +// We don't actually care if the callback is ever invoked in this test +const obs = new PerformanceObserver(() => {}); +const obs2 = new PerformanceObserver(() => {}); + +obs.observe({ type: 'gc' }); +obs2.observe({ type: 'gc' }); diff --git a/test/parallel/test-process-versions.js b/test/parallel/test-process-versions.js index 56e3dc67e6a81c..ab2f217e963261 100644 --- a/test/parallel/test-process-versions.js +++ b/test/parallel/test-process-versions.js @@ -54,7 +54,7 @@ if (common.hasCrypto) { // The following also matches a development version of OpenSSL 3.x which // can be in the format '3.0.0-alpha4-dev'. This can be handy when building // and linking against the main development branch of OpenSSL. - /^\d+\.\d+\.\d+(-[-a-z0-9]+)?$/ : + /^\d+\.\d+\.\d+(?:[-+][a-z0-9]+)*$/ : /^\d+\.\d+\.\d+[a-z]?(\+quic)?(-fips)?$/; assert(versionRegex.test(process.versions.openssl)); } diff --git a/test/parallel/test-punycode.js b/test/parallel/test-punycode.js index 190c0b22b313dc..efd3b92a6e7e50 100644 --- a/test/parallel/test-punycode.js +++ b/test/parallel/test-punycode.js @@ -1,3 +1,5 @@ +// Flags: --pending-deprecation + // Copyright Joyent, Inc. and other Node contributors. // // Permission is hereby granted, free of charge, to any person obtaining a @@ -20,7 +22,13 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); + +const punycodeWarning = + 'The `punycode` module is deprecated. Please use a userland alternative ' + + 'instead.'; +common.expectWarning('DeprecationWarning', punycodeWarning, 'DEP0040'); + const punycode = require('punycode'); const assert = require('assert'); diff --git a/test/parallel/test-querystring.js b/test/parallel/test-querystring.js index 105bcc56a9878e..eda94bf8df9164 100644 --- a/test/parallel/test-querystring.js +++ b/test/parallel/test-querystring.js @@ -307,6 +307,7 @@ assert.strictEqual(qs.stringify({ foo: -0 }), 'foo=0'); assert.strictEqual(qs.stringify({ foo: 3 }), 'foo=3'); assert.strictEqual(qs.stringify({ foo: -72.42 }), 'foo=-72.42'); assert.strictEqual(qs.stringify({ foo: NaN }), 'foo='); +assert.strictEqual(qs.stringify({ foo: 1e21 }), 'foo=1e%2B21'); assert.strictEqual(qs.stringify({ foo: Infinity }), 'foo='); // nested @@ -450,6 +451,14 @@ check(qs.parse('%\u0100=%\u0101'), { '%Ā': '%ā' }); 'a=a&b=b&c=c'); } +// Test custom encode for different types +{ + const obj = { number: 1, bigint: 2n, true: true, false: false, object: {} }; + assert.strictEqual( + qs.stringify(obj, null, null, { encodeURIComponent: (v) => v }), + 'number=1&bigint=2&true=true&false=false&object='); +} + // Test QueryString.unescapeBuffer qsUnescapeTestCases.forEach((testCase) => { assert.strictEqual(qs.unescape(testCase[0]), testCase[1]); diff --git a/test/parallel/test-readline-tab-complete.js b/test/parallel/test-readline-tab-complete.js index 7ccdef116492b7..c283d446f9af28 100644 --- a/test/parallel/test-readline-tab-complete.js +++ b/test/parallel/test-readline-tab-complete.js @@ -31,15 +31,15 @@ common.skipIfDumbTerminal(); const width = getStringWidth(char) - 1; class FakeInput extends EventEmitter { - columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3 + columns = ((width + 1) * 10 + (lineBreak ? 0 : 10)) * 3 - write = common.mustCall((data) => { - output += data; - }, 6) + write = common.mustCall((data) => { + output += data; + }, 6) - resume() {} - pause() {} - end() {} + resume() {} + pause() {} + end() {} } const fi = new FakeInput(); @@ -47,7 +47,7 @@ common.skipIfDumbTerminal(); input: fi, output: fi, terminal: true, - completer: completer + completer: common.mustCallAtLeast(completer), }); const last = '\r\nFirst group\r\n\r\n' + @@ -68,3 +68,35 @@ common.skipIfDumbTerminal(); rli.close(); }); }); + +{ + let output = ''; + class FakeInput extends EventEmitter { + columns = 80 + + write = common.mustCall((data) => { + output += data; + }, 1) + + resume() {} + pause() {} + end() {} + } + + const fi = new FakeInput(); + const rli = new readline.Interface({ + input: fi, + output: fi, + terminal: true, + completer: + common.mustCallAtLeast((_, cb) => cb(new Error('message'))), + }); + + rli.on('line', common.mustNotCall()); + fi.emit('data', '\t'); + queueMicrotask(() => { + assert.match(output, /^Tab completion error: Error: message/); + output = ''; + }); + rli.close(); +} diff --git a/test/parallel/test-tls-passphrase.js b/test/parallel/test-tls-passphrase.js index c0d0051ff8bbc2..ce77dd18a6e620 100644 --- a/test/parallel/test-tls-passphrase.js +++ b/test/parallel/test-tls-passphrase.js @@ -224,7 +224,7 @@ server.listen(0, common.mustCall(function() { })).unref(); const errMessagePassword = common.hasOpenSSL3 ? - /Error: PEM_read_bio_PrivateKey/ : /bad decrypt/; + /Error: error:1400006B:UI routines::processing error/ : /bad decrypt/; // Missing passphrase assert.throws(function() { @@ -254,8 +254,7 @@ assert.throws(function() { }); }, errMessagePassword); -const errMessageDecrypt = common.hasOpenSSL3 ? - /Error: PEM_read_bio_PrivateKey/ : /bad decrypt/; +const errMessageDecrypt = /bad decrypt/; // Invalid passphrase assert.throws(function() { diff --git a/test/parallel/test-tls-ticket-invalid-arg.js b/test/parallel/test-tls-ticket-invalid-arg.js new file mode 100644 index 00000000000000..55143cdca31e77 --- /dev/null +++ b/test/parallel/test-tls-ticket-invalid-arg.js @@ -0,0 +1,24 @@ +'use strict'; +const common = require('../common'); +if (!common.hasCrypto) { + common.skip('missing crypto'); +} + +const assert = require('assert'); +const tls = require('tls'); + +const server = new tls.Server(); + +[null, undefined, 0, 1, 1n, Symbol(), {}, [], true, false, '', () => {}] + .forEach((arg) => + assert.throws( + () => server.setTicketKeys(arg), + { code: 'ERR_INVALID_ARG_TYPE' } + )); + +[new Uint8Array(1), Buffer.from([1]), new DataView(new ArrayBuffer(2))].forEach( + (arg) => + assert.throws(() => { + server.setTicketKeys(arg); + }, /Session ticket keys must be a 48-byte buffer/) +); diff --git a/test/parallel/test-tls-transport-destroy-after-own-gc.js b/test/parallel/test-tls-transport-destroy-after-own-gc.js index 9b9c8353077dfe..819aa0a03d6cb4 100644 --- a/test/parallel/test-tls-transport-destroy-after-own-gc.js +++ b/test/parallel/test-tls-transport-destroy-after-own-gc.js @@ -15,12 +15,12 @@ const makeDuplexPair = require('../common/duplexpair'); let { clientSide } = makeDuplexPair(); let clientTLS = new TLSSocket(clientSide, { isServer: false }); -let clientTLSHandle = clientTLS._handle; +let clientTLSHandle = clientTLS._handle; // eslint-disable-line no-unused-vars setImmediate(() => { clientTLS = null; global.gc(); - clientTLSHandle = null; // eslint-disable-line no-unused-vars + clientTLSHandle = null; global.gc(); setImmediate(() => { clientSide = null; diff --git a/test/parallel/test-tojson-perf_hooks.js b/test/parallel/test-tojson-perf_hooks.js new file mode 100644 index 00000000000000..2a716fc4478c29 --- /dev/null +++ b/test/parallel/test-tojson-perf_hooks.js @@ -0,0 +1,14 @@ +'use strict'; + +require('../common'); +const assert = require('assert'); +const { performance } = require('perf_hooks'); + +// Test toJSON for performance object +{ + assert.strictEqual(typeof performance.toJSON, 'function'); + const jsonObject = performance.toJSON(); + assert.strictEqual(typeof jsonObject, 'object'); + assert.strictEqual(jsonObject.timeOrigin, performance.timeOrigin); + assert.strictEqual(typeof jsonObject.nodeTiming, 'object'); +} diff --git a/test/parallel/test-util-inspect-getters-accessing-this.js b/test/parallel/test-util-inspect-getters-accessing-this.js index 3d185b134e852d..998cd82db8f4b3 100644 --- a/test/parallel/test-util-inspect-getters-accessing-this.js +++ b/test/parallel/test-util-inspect-getters-accessing-this.js @@ -7,24 +7,61 @@ require('../common'); const assert = require('assert'); -const util = require('util'); +const { inspect } = require('util'); -class X { - constructor() { - this._y = 123; - } +{ + class X { + constructor() { + this._y = 123; + } - get y() { - return this._y; + get y() { + return this._y; + } } + + const result = inspect(new X(), { + getters: true, + showHidden: true + }); + + assert.strictEqual( + result, + 'X { _y: 123, [y]: [Getter: 123] }' + ); } -const result = util.inspect(new X(), { - getters: true, - showHidden: true -}); +// Regression test for https://github.com/nodejs/node/issues/37054 +{ + class A { + constructor(B) { + this.B = B; + } + get b() { + return this.B; + } + } + + class B { + constructor() { + this.A = new A(this); + } + get a() { + return this.A; + } + } + + const result = inspect(new B(), { + depth: 1, + getters: true, + showHidden: true + }); -assert.strictEqual( - result, - 'X { _y: 123, [y]: [Getter: 123] }' -); + assert.strictEqual( + result, + ' B {\n' + + ' A: A { B: [Circular *1], [b]: [Getter] [Circular *1] },\n' + + ' [a]: [Getter] A { B: [Circular *1], [b]: [Getter] [Circular *1] }\n' + + '}', + ); +} diff --git a/test/parallel/test-webcrypto-derivebits-ecdh.js b/test/parallel/test-webcrypto-derivebits-ecdh.js index 64cbae7cec6a03..49076ce443a54a 100644 --- a/test/parallel/test-webcrypto-derivebits-ecdh.js +++ b/test/parallel/test-webcrypto-derivebits-ecdh.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle, getRandomValues } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-derivebits-node-dh.js b/test/parallel/test-webcrypto-derivebits-node-dh.js index 2503bc17032e0d..cab7d40c1a7abf 100644 --- a/test/parallel/test-webcrypto-derivebits-node-dh.js +++ b/test/parallel/test-webcrypto-derivebits-node-dh.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-derivekey-ecdh.js b/test/parallel/test-webcrypto-derivekey-ecdh.js index bdd9bd7588a763..a0bf28e89e4e3a 100644 --- a/test/parallel/test-webcrypto-derivekey-ecdh.js +++ b/test/parallel/test-webcrypto-derivekey-ecdh.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle, getRandomValues } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-encrypt-decrypt-rsa.js b/test/parallel/test-webcrypto-encrypt-decrypt-rsa.js index 151eebd36c9765..e01152c07f294d 100644 --- a/test/parallel/test-webcrypto-encrypt-decrypt-rsa.js +++ b/test/parallel/test-webcrypto-encrypt-decrypt-rsa.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-export-import-dsa.js b/test/parallel/test-webcrypto-export-import-dsa.js index 3fddd9dd9c4559..6b47b99c1ddbf8 100644 --- a/test/parallel/test-webcrypto-export-import-dsa.js +++ b/test/parallel/test-webcrypto-export-import-dsa.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-export-import-ec.js b/test/parallel/test-webcrypto-export-import-ec.js index 31ab2c09cdb1f9..e5453878a19050 100644 --- a/test/parallel/test-webcrypto-export-import-ec.js +++ b/test/parallel/test-webcrypto-export-import-ec.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-export-import-rsa.js b/test/parallel/test-webcrypto-export-import-rsa.js index f43259fd22faea..46e96628a33f8c 100644 --- a/test/parallel/test-webcrypto-export-import-rsa.js +++ b/test/parallel/test-webcrypto-export-import-rsa.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-export-import.js b/test/parallel/test-webcrypto-export-import.js index d7db433b364011..9cf8833cecfc47 100644 --- a/test/parallel/test-webcrypto-export-import.js +++ b/test/parallel/test-webcrypto-export-import.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle, getRandomValues } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-rsa-pss-params.js b/test/parallel/test-webcrypto-rsa-pss-params.js index 964eaf32e890fd..d52a9bf6add223 100644 --- a/test/parallel/test-webcrypto-rsa-pss-params.js +++ b/test/parallel/test-webcrypto-rsa-pss-params.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const { createPrivateKey, createPublicKey, diff --git a/test/parallel/test-webcrypto-sign-verify-ecdsa.js b/test/parallel/test-webcrypto-sign-verify-ecdsa.js index 2f8f3a2fd229bd..8620498d89b00c 100644 --- a/test/parallel/test-webcrypto-sign-verify-ecdsa.js +++ b/test/parallel/test-webcrypto-sign-verify-ecdsa.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-sign-verify-node-dsa.js b/test/parallel/test-webcrypto-sign-verify-node-dsa.js index 73b006b9236249..24d739062fb098 100644 --- a/test/parallel/test-webcrypto-sign-verify-node-dsa.js +++ b/test/parallel/test-webcrypto-sign-verify-node-dsa.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-sign-verify-rsa.js b/test/parallel/test-webcrypto-sign-verify-rsa.js index 60815c5ea0451d..2cfcf6e2ec02bd 100644 --- a/test/parallel/test-webcrypto-sign-verify-rsa.js +++ b/test/parallel/test-webcrypto-sign-verify-rsa.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-webcrypto-wrap-unwrap.js b/test/parallel/test-webcrypto-wrap-unwrap.js index 1094845c73e143..54a5a782a09586 100644 --- a/test/parallel/test-webcrypto-wrap-unwrap.js +++ b/test/parallel/test-webcrypto-wrap-unwrap.js @@ -5,6 +5,9 @@ const common = require('../common'); if (!common.hasCrypto) common.skip('missing crypto'); +if (common.hasOpenSSL3) + common.skip('temporarily skipping for OpenSSL 3.0-alpha15'); + const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/parallel/test-worker-message-port-close.js b/test/parallel/test-worker-message-port-close.js index 17a10559e4e61d..6abc01d1b7b568 100644 --- a/test/parallel/test-worker-message-port-close.js +++ b/test/parallel/test-worker-message-port-close.js @@ -1,6 +1,7 @@ 'use strict'; const common = require('../common'); -const { MessageChannel } = require('worker_threads'); +const assert = require('assert'); +const { MessageChannel, moveMessagePortToContext } = require('worker_threads'); // Make sure that .start() and .stop() do not throw on closing/closed // MessagePorts. @@ -29,3 +30,12 @@ function dummy() {} port1.off('message', dummy); })); } + +{ + const { port2 } = new MessageChannel(); + port2.close(); + assert.throws(() => moveMessagePortToContext(port2, {}), { + code: 'ERR_CLOSED_MESSAGE_PORT', + message: 'Cannot send data on closed MessagePort' + }); +} diff --git a/test/parallel/test-zlib-brotli.js b/test/parallel/test-zlib-brotli.js index 772b655177aa18..ef31db3dd64ac4 100644 --- a/test/parallel/test-zlib-brotli.js +++ b/test/parallel/test-zlib-brotli.js @@ -71,3 +71,24 @@ const sampleBuffer = fixtures.readSync('/pss-vectors.json'); message: 'Initialization failed' }); } + +{ + // Test options.flush range + assert.throws(() => { + zlib.brotliCompressSync('', { flush: zlib.constants.Z_FINISH }); + }, { + code: 'ERR_OUT_OF_RANGE', + name: 'RangeError', + message: 'The value of "options.flush" is out of range. It must be >= 0 ' + + 'and <= 3. Received 4', + }); + + assert.throws(() => { + zlib.brotliCompressSync('', { finishFlush: zlib.constants.Z_FINISH }); + }, { + code: 'ERR_OUT_OF_RANGE', + name: 'RangeError', + message: 'The value of "options.finishFlush" is out of range. It must be ' + + '>= 0 and <= 3. Received 4', + }); +} diff --git a/test/pseudo-tty/testcfg.py b/test/pseudo-tty/testcfg.py index ad9461f026366f..df380ad31eff1e 100644 --- a/test/pseudo-tty/testcfg.py +++ b/test/pseudo-tty/testcfg.py @@ -48,6 +48,7 @@ def __init__(self, path, file, expected, input_arg, arch, mode, context, config) self.config = config self.arch = arch self.mode = mode + self.parallel = True def IgnoreLine(self, str_arg): """Ignore empty lines and valgrind output.""" diff --git a/test/pummel/test-crypto-dh-hash-modp18.js b/test/pummel/test-crypto-dh-hash-modp18.js index 288a647bdd321d..06121d1f6dc956 100644 --- a/test/pummel/test-crypto-dh-hash-modp18.js +++ b/test/pummel/test-crypto-dh-hash-modp18.js @@ -21,8 +21,15 @@ 'use strict'; const common = require('../common'); -if (!common.hasCrypto) + +if (!common.hasCrypto) { common.skip('node compiled without OpenSSL.'); +} + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} const assert = require('assert'); const crypto = require('crypto'); diff --git a/test/pummel/test-crypto-dh-hash.js b/test/pummel/test-crypto-dh-hash.js index 7188fbb32b9197..5b7002ce7fe16b 100644 --- a/test/pummel/test-crypto-dh-hash.js +++ b/test/pummel/test-crypto-dh-hash.js @@ -21,8 +21,15 @@ 'use strict'; const common = require('../common'); -if (!common.hasCrypto) + +if (!common.hasCrypto) { common.skip('node compiled without OpenSSL.'); +} + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} const assert = require('assert'); const crypto = require('crypto'); diff --git a/test/pummel/test-crypto-dh-keys.js b/test/pummel/test-crypto-dh-keys.js index 37095135f85174..33c2ed86073045 100644 --- a/test/pummel/test-crypto-dh-keys.js +++ b/test/pummel/test-crypto-dh-keys.js @@ -21,6 +21,7 @@ 'use strict'; const common = require('../common'); + if (!common.hasCrypto) { common.skip('node compiled without OpenSSL.'); } diff --git a/test/pummel/test-crypto-timing-safe-equal-benchmarks.js b/test/pummel/test-crypto-timing-safe-equal-benchmarks.js index b649b071e1e49d..3c6e31e8294cc8 100644 --- a/test/pummel/test-crypto-timing-safe-equal-benchmarks.js +++ b/test/pummel/test-crypto-timing-safe-equal-benchmarks.js @@ -111,7 +111,7 @@ assert( `timingSafeEqual should not leak information from its execution time (t=${t})` ); -// As a sanity check to make sure the statistical tests are working, run the +// As a coherence check to make sure the statistical tests are working, run the // same benchmarks again, this time with an unsafe comparison function. In this // case the t-value should be above the threshold. const unsafeCompare = (bufA, bufB) => bufA.equals(bufB); diff --git a/test/pummel/test-dh-regr.js b/test/pummel/test-dh-regr.js index bb041e4c5d1033..fff20c3ed08816 100644 --- a/test/pummel/test-dh-regr.js +++ b/test/pummel/test-dh-regr.js @@ -21,8 +21,15 @@ 'use strict'; const common = require('../common'); -if (!common.hasCrypto) + +if (!common.hasCrypto) { common.skip('missing crypto'); +} + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} const assert = require('assert'); const crypto = require('crypto'); diff --git a/test/pummel/test-fs-largefile.js b/test/pummel/test-fs-largefile.js index 409d7a2112f027..9c2b26782d9c96 100644 --- a/test/pummel/test-fs-largefile.js +++ b/test/pummel/test-fs-largefile.js @@ -34,7 +34,7 @@ const fd = fs.openSync(filepath, 'w+'); const offset = 5 * 1024 * 1024 * 1024; // 5GB const message = 'Large File'; -fs.truncateSync(fd, offset); +fs.ftruncateSync(fd, offset); assert.strictEqual(fs.statSync(filepath).size, offset); const writeBuf = Buffer.from(message); fs.writeSync(fd, writeBuf, 0, writeBuf.length, offset); diff --git a/test/pummel/test-fs-watch-system-limit.js b/test/pummel/test-fs-watch-system-limit.js index ce390dd3d0bb83..6662986a1a8ee0 100644 --- a/test/pummel/test-fs-watch-system-limit.js +++ b/test/pummel/test-fs-watch-system-limit.js @@ -5,10 +5,18 @@ const child_process = require('child_process'); const fs = require('fs'); const stream = require('stream'); -if (!common.isLinux) +if (!common.isLinux) { common.skip('The fs watch limit is OS-dependent'); -if (!common.enoughTestCpu) +} + +if (!common.enoughTestCpu) { common.skip('This test is resource-intensive'); +} + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} try { // Ensure inotify limit is low enough for the test to actually exercise the diff --git a/test/parallel/test-heapsnapshot-near-heap-limit-bounded.js b/test/pummel/test-heapsnapshot-near-heap-limit-bounded.js similarity index 82% rename from test/parallel/test-heapsnapshot-near-heap-limit-bounded.js rename to test/pummel/test-heapsnapshot-near-heap-limit-bounded.js index a57b9a8fc4b5e5..0ad6a898d126eb 100644 --- a/test/parallel/test-heapsnapshot-near-heap-limit-bounded.js +++ b/test/pummel/test-heapsnapshot-near-heap-limit-bounded.js @@ -1,6 +1,12 @@ 'use strict'; -require('../common'); +const common = require('../common'); + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} + const tmpdir = require('../common/tmpdir'); const assert = require('assert'); const { spawnSync } = require('child_process'); diff --git a/test/parallel/test-heapsnapshot-near-heap-limit.js b/test/pummel/test-heapsnapshot-near-heap-limit.js similarity index 94% rename from test/parallel/test-heapsnapshot-near-heap-limit.js rename to test/pummel/test-heapsnapshot-near-heap-limit.js index 5743f71a3f568c..6651f2ae9f52d9 100644 --- a/test/parallel/test-heapsnapshot-near-heap-limit.js +++ b/test/pummel/test-heapsnapshot-near-heap-limit.js @@ -1,6 +1,12 @@ 'use strict'; const common = require('../common'); + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} + const tmpdir = require('../common/tmpdir'); const assert = require('assert'); const { spawnSync } = require('child_process'); diff --git a/test/sequential/test-net-bytes-per-incoming-chunk-overhead.js b/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js similarity index 85% rename from test/sequential/test-net-bytes-per-incoming-chunk-overhead.js rename to test/pummel/test-net-bytes-per-incoming-chunk-overhead.js index 7bcdfaa9f6f6aa..fed903c2639d99 100644 --- a/test/sequential/test-net-bytes-per-incoming-chunk-overhead.js +++ b/test/pummel/test-net-bytes-per-incoming-chunk-overhead.js @@ -2,8 +2,15 @@ 'use strict'; const common = require('../common'); -if (process.config.variables.asan) + +if (process.config.variables.asan) { common.skip('ASAN messes with memory measurements'); +} + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} const assert = require('assert'); const net = require('net'); diff --git a/test/pummel/test-next-tick-infinite-calls.js b/test/pummel/test-next-tick-infinite-calls.js index 5ee44076dcc2f3..7ae3b2261358af 100644 --- a/test/pummel/test-next-tick-infinite-calls.js +++ b/test/pummel/test-next-tick-infinite-calls.js @@ -20,7 +20,12 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} let complete = 0; diff --git a/test/pummel/test-policy-integrity.js b/test/pummel/test-policy-integrity.js index 15124aefd46904..9383f881fbe514 100644 --- a/test/pummel/test-policy-integrity.js +++ b/test/pummel/test-policy-integrity.js @@ -1,7 +1,16 @@ 'use strict'; const common = require('../common'); -if (!common.hasCrypto) common.skip('missing crypto'); + +if (!common.hasCrypto) { + common.skip('missing crypto'); +} + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} + common.requireNoPackageJSONAbove(); const { debuglog } = require('util'); @@ -76,6 +85,7 @@ function newTestId() { return nextTestId++; } tmpdir.refresh(); +common.requireNoPackageJSONAbove(tmpdir.path); let spawned = 0; const toSpawn = []; diff --git a/test/parallel/test-webcrypto-derivebits-pbkdf2.js b/test/pummel/test-webcrypto-derivebits-pbkdf2.js similarity index 99% rename from test/parallel/test-webcrypto-derivebits-pbkdf2.js rename to test/pummel/test-webcrypto-derivebits-pbkdf2.js index ed8279dae134dc..745071f3458aba 100644 --- a/test/parallel/test-webcrypto-derivebits-pbkdf2.js +++ b/test/pummel/test-webcrypto-derivebits-pbkdf2.js @@ -2,8 +2,14 @@ const common = require('../common'); -if (!common.hasCrypto) +if (!common.hasCrypto) { common.skip('missing crypto'); +} + +if ((process.config.variables.arm_version === '6') || + (process.config.variables.arm_version === '7')) { + common.skip('Too slow for armv6 and armv7 bots'); +} const assert = require('assert'); const { subtle } = require('crypto').webcrypto; diff --git a/test/report/test-report-uncaught-exception-primitives.js b/test/report/test-report-uncaught-exception-primitives.js new file mode 100644 index 00000000000000..75a05f335cf2e2 --- /dev/null +++ b/test/report/test-report-uncaught-exception-primitives.js @@ -0,0 +1,25 @@ +// Flags: --report-uncaught-exception +'use strict'; +// Test producing a report on uncaught exception. +const common = require('../common'); +const assert = require('assert'); +const helper = require('../common/report'); +const tmpdir = require('../common/tmpdir'); + +const exception = 1; + +tmpdir.refresh(); +process.report.directory = tmpdir.path; + +process.on('uncaughtException', common.mustCall((err) => { + assert.strictEqual(err, exception); + const reports = helper.findReports(process.pid, tmpdir.path); + assert.strictEqual(reports.length, 1); + console.log(reports[0]); + helper.validate(reports[0], [ + ['header.event', 'Exception'], + ['javascriptStack.message', `${exception}`], + ]); +})); + +throw exception; diff --git a/test/report/test-report-uncaught-exception-symbols.js b/test/report/test-report-uncaught-exception-symbols.js new file mode 100644 index 00000000000000..5997d0e0898ac0 --- /dev/null +++ b/test/report/test-report-uncaught-exception-symbols.js @@ -0,0 +1,25 @@ +// Flags: --report-uncaught-exception +'use strict'; +// Test producing a report on uncaught exception. +const common = require('../common'); +const assert = require('assert'); +const helper = require('../common/report'); +const tmpdir = require('../common/tmpdir'); + +const exception = Symbol('foobar'); + +tmpdir.refresh(); +process.report.directory = tmpdir.path; + +process.on('uncaughtException', common.mustCall((err) => { + assert.strictEqual(err, exception); + const reports = helper.findReports(process.pid, tmpdir.path); + assert.strictEqual(reports.length, 1); + console.log(reports[0]); + helper.validate(reports[0], [ + ['header.event', 'Exception'], + ['javascriptStack.message', 'Symbol(foobar)'], + ]); +})); + +throw exception; diff --git a/test/pummel/test-net-connect-econnrefused.js b/test/sequential/test-net-connect-econnrefused.js similarity index 100% rename from test/pummel/test-net-connect-econnrefused.js rename to test/sequential/test-net-connect-econnrefused.js diff --git a/tools/bootstrap/windows_boxstarter b/tools/bootstrap/windows_boxstarter index dd6dd25ba03a2f..eb0b2d72e98381 100644 --- a/tools/bootstrap/windows_boxstarter +++ b/tools/bootstrap/windows_boxstarter @@ -1,15 +1,15 @@ # Boxstarter (http://boxstarter.org/) script for Node.js prerequisites # # To install either open this link in IE or Edge: -# http://boxstarter.org/package/nr/url?https://raw.githubusercontent.com/nodejs/node/master/tools/bootstrap/windows_boxstarter +# http://boxstarter.org/package/nr/url?https://raw.githubusercontent.com/nodejs/node/HEAD/tools/bootstrap/windows_boxstarter # # Or run those commands in an elevated Powershell terminal: # iex ((New-Object System.Net.WebClient).DownloadString('http://boxstarter.org/bootstrapper.ps1')) # get-boxstarter -Force -# Install-BoxstarterPackage https://raw.githubusercontent.com/nodejs/node/master/tools/bootstrap/windows_boxstarter -DisableReboots +# Install-BoxstarterPackage https://raw.githubusercontent.com/nodejs/node/HEAD/tools/bootstrap/windows_boxstarter -DisableReboots # # For more detail see -# https://github.com/nodejs/node/blob/master/tools/bootstrap/README.md +# https://github.com/nodejs/node/blob/HEAD/tools/bootstrap/README.md # # Git and Unix tools will be added to the PATH diff --git a/tools/doc/generate.js b/tools/doc/generate.js index f49acb6207c9b4..d2f3aea27f25a4 100644 --- a/tools/doc/generate.js +++ b/tools/doc/generate.js @@ -43,7 +43,7 @@ let filename = null; let nodeVersion = null; let outputDir = null; let apilinks = {}; -let versions = {}; +let versions = []; async function main() { for (const arg of args) { diff --git a/tools/doc/versions.js b/tools/doc/versions.js index 52f5648ecae92f..6f16b4d1d74ddf 100644 --- a/tools/doc/versions.js +++ b/tools/doc/versions.js @@ -36,7 +36,7 @@ async function versions() { // The CHANGELOG.md on release branches may not reference newer semver // majors of Node.js so fetch and parse the version from the master branch. const url = - 'https://raw.githubusercontent.com/nodejs/node/master/CHANGELOG.md'; + 'https://raw.githubusercontent.com/nodejs/node/HEAD/CHANGELOG.md'; let changelog; const file = path.join(srcRoot, 'CHANGELOG.md'); if (kNoInternet) { diff --git a/tools/eslint-rules/non-ascii-character.js b/tools/eslint-rules/non-ascii-character.js index 6588125d33d201..f9ee24273fdcb6 100644 --- a/tools/eslint-rules/non-ascii-character.js +++ b/tools/eslint-rules/non-ascii-character.js @@ -46,12 +46,6 @@ module.exports = (context) => { node, message, loc: sourceCode.getLocFromIndex(offendingCharacterPosition), - fix: (fixer) => { - return fixer.replaceText( - node, - suggestion ? `${suggestion}` : '' - ); - } }); }; @@ -59,7 +53,3 @@ module.exports = (context) => { Program: (node) => reportIfError(node, context.getSourceCode()) }; }; - -module.exports.meta = { - fixable: 'code' -}; diff --git a/tools/inspector_protocol/lib/encoding_cpp.template b/tools/inspector_protocol/lib/encoding_cpp.template index 6776471b6637c5..2fc7dd623fdcc3 100644 --- a/tools/inspector_protocol/lib/encoding_cpp.template +++ b/tools/inspector_protocol/lib/encoding_cpp.template @@ -739,7 +739,7 @@ span CBORTokenizer::GetEnvelopeContents() const { // and then checking whether the sum went past it. // // See also -// https://chromium.googlesource.com/chromium/src/+/master/docs/security/integer-semantics.md +// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/security/integer-semantics.md static const uint64_t kMaxValidLength = std::min(std::numeric_limits::max() >> 2, std::numeric_limits::max()); diff --git a/tools/license-builder.sh b/tools/license-builder.sh index 05a15471c7e77f..04b631a09b7d54 100755 --- a/tools/license-builder.sh +++ b/tools/license-builder.sh @@ -63,7 +63,7 @@ addlicense "llhttp" "deps/llhttp" "$(cat deps/llhttp/LICENSE-MIT)" addlicense "OpenSSL" "deps/openssl" \ "$(sed -e '/^ \*\/$/,$d' -e '/^ [^*].*$/d' -e '/\/\*.*$/d' -e '/^$/d' -e 's/^[/ ]\* *//' "${rootdir}"/deps/openssl/openssl/LICENSE)" addlicense "Punycode.js" "lib/punycode.js" \ - "$(curl -sL https://raw.githubusercontent.com/bestiejs/punycode.js/master/LICENSE-MIT.txt)" + "$(curl -sL https://raw.githubusercontent.com/bestiejs/punycode.js/HEAD/LICENSE-MIT.txt)" addlicense "V8" "deps/v8" "$(cat "${rootdir}"/deps/v8/LICENSE)" addlicense "SipHash" "deps/v8/src/third_party/siphash" \ "$(sed -e '/You should have received a copy of the CC0/,$d' -e 's/^\/\* *//' -e 's/^ \* *//' deps/v8/src/third_party/siphash/halfsiphash.cc)" @@ -89,9 +89,6 @@ addlicense "gtest" "test/cctest/gtest" "$(cat "${rootdir}"/test/cctest/gtest/LIC # nghttp2 addlicense "nghttp2" "deps/nghttp2" "$(cat "${rootdir}"/deps/nghttp2/COPYING)" -# node-inspect -addlicense "node-inspect" "deps/node-inspect" "$(cat "${rootdir}"/deps/node-inspect/LICENSE)" - # large_pages addlicense "large_pages" "src/large_pages" "$(sed -e '/SPDX-License-Identifier/,$d' -e 's/^\/\///' "${rootdir}"/src/large_pages/node_large_page.h)" diff --git a/tools/lint-md.js b/tools/lint-md.js index 5c2f40abc7b43a..57aeb202322736 100644 --- a/tools/lint-md.js +++ b/tools/lint-md.js @@ -49667,6 +49667,11 @@ function validateMeta(node, file, meta) { function validateYAMLComments(tree, file) { unistUtilVisit(tree, "html", function visitor(node) { + if (node.value.startsWith("".length)); diff --git a/tools/make-v8.sh b/tools/make-v8.sh index 5a23432b589001..79ab02af275aa9 100755 --- a/tools/make-v8.sh +++ b/tools/make-v8.sh @@ -36,7 +36,8 @@ if [ "$ARCH" = "s390x" ] || [ "$ARCH" = "ppc64le" ]; then gn gen -v "out.gn/$BUILD_ARCH_TYPE" --args="is_component_build=false is_debug=false use_goma=false goma_dir=\"None\" use_custom_libcxx=false v8_target_cpu=\"$TARGET_ARCH\" target_cpu=\"$TARGET_ARCH\" v8_enable_backtrace=true" ninja -v -C "out.gn/$BUILD_ARCH_TYPE" d8 cctest inspector-test else + DEPOT_TOOLS_DIR="$(cd _depot_tools && pwd)" # shellcheck disable=SC2086 - PATH=~/_depot_tools:$PATH tools/dev/v8gen.py "$BUILD_ARCH_TYPE" --no-goma $V8_BUILD_OPTIONS - PATH=~/_depot_tools:$PATH ninja -C "out.gn/$BUILD_ARCH_TYPE/" d8 cctest inspector-test + PATH="$DEPOT_TOOLS_DIR":$PATH tools/dev/v8gen.py "$BUILD_ARCH_TYPE" --no-goma $V8_BUILD_OPTIONS + PATH="$DEPOT_TOOLS_DIR":$PATH ninja -C "out.gn/$BUILD_ARCH_TYPE/" d8 cctest inspector-test fi diff --git a/tools/node-lint-md-cli-rollup/package-lock.json b/tools/node-lint-md-cli-rollup/package-lock.json index f2e9be4fc61bb5..5fccba999a5ecf 100644 --- a/tools/node-lint-md-cli-rollup/package-lock.json +++ b/tools/node-lint-md-cli-rollup/package-lock.json @@ -2111,9 +2111,9 @@ } }, "node_modules/remark-preset-lint-node": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.1.1.tgz", - "integrity": "sha512-3Cv4kDVaC8V0XsiK/ntdpOEztOx0v8L9DczQ3KRIN7QwyPS3Gjaq2DJ7wNglXVK4z7PekcND0mXK78eLduhwwA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.2.0.tgz", + "integrity": "sha512-85wnJs7HyQlY3Ae5HRxPjJx5cFBvAAOSfSpmyNVb6Fs9HYoR9ipimAxWfl2M1gYVT2rBrod8Jzu415dOMukzOw==", "dependencies": { "js-yaml": "^4.0.0", "remark-lint": "^8.0.0", @@ -4226,9 +4226,9 @@ } }, "remark-preset-lint-node": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.1.1.tgz", - "integrity": "sha512-3Cv4kDVaC8V0XsiK/ntdpOEztOx0v8L9DczQ3KRIN7QwyPS3Gjaq2DJ7wNglXVK4z7PekcND0mXK78eLduhwwA==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/remark-preset-lint-node/-/remark-preset-lint-node-2.2.0.tgz", + "integrity": "sha512-85wnJs7HyQlY3Ae5HRxPjJx5cFBvAAOSfSpmyNVb6Fs9HYoR9ipimAxWfl2M1gYVT2rBrod8Jzu415dOMukzOw==", "requires": { "js-yaml": "^4.0.0", "remark-lint": "^8.0.0", diff --git a/tools/node_modules/eslint/README.md b/tools/node_modules/eslint/README.md index 14ba7e2cb32d9a..1aa25ee3d1d47b 100644 --- a/tools/node_modules/eslint/README.md +++ b/tools/node_modules/eslint/README.md @@ -283,7 +283,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Automattic

Gold Sponsors

Nx (by Nrwl) Chrome's Web Framework & Tools Performance Fund Shopify Salesforce Airbnb Microsoft Substack

Silver Sponsors

Retool Liftoff

Bronze Sponsors

-

Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

+

Buy.Fineproxy.Org Anagram Solver Bugsnag Stability Monitoring Mixpanel VPS Server Icons8: free icons, photos, illustrations, and music Discord ThemeIsle Fire Stick Tricks

## Technology Sponsors diff --git a/tools/node_modules/eslint/lib/linter/linter.js b/tools/node_modules/eslint/lib/linter/linter.js index adb5c215590251..576816b5b7ba6f 100644 --- a/tools/node_modules/eslint/lib/linter/linter.js +++ b/tools/node_modules/eslint/lib/linter/linter.js @@ -1308,9 +1308,9 @@ class Linter { return []; } - // Resolve configuration again if the file extension was changed. - if (configForRecursive && path.extname(blockName) !== originalExtname) { - debug("Resolving configuration again because the file extension was changed."); + // Resolve configuration again if the file content or extension was changed. + if (configForRecursive && (text !== blockText || path.extname(blockName) !== originalExtname)) { + debug("Resolving configuration again because the file content or extension was changed."); return this._verifyWithConfigArray( blockText, configForRecursive, diff --git a/tools/node_modules/eslint/lib/rules/no-unused-vars.js b/tools/node_modules/eslint/lib/rules/no-unused-vars.js index 32589099cf4be7..7619be331fa436 100644 --- a/tools/node_modules/eslint/lib/rules/no-unused-vars.js +++ b/tools/node_modules/eslint/lib/rules/no-unused-vars.js @@ -624,10 +624,18 @@ module.exports = { // Report the first declaration. if (unusedVar.defs.length > 0) { + + // report last write reference, https://github.com/eslint/eslint/issues/14324 + const writeReferences = unusedVar.references.filter(ref => ref.isWrite() && ref.from.variableScope === unusedVar.scope.variableScope); + + let referenceToReport; + + if (writeReferences.length > 0) { + referenceToReport = writeReferences[writeReferences.length - 1]; + } + context.report({ - node: unusedVar.references.length ? unusedVar.references[ - unusedVar.references.length - 1 - ].identifier : unusedVar.identifiers[0], + node: referenceToReport ? referenceToReport.identifier : unusedVar.identifiers[0], messageId: "unusedVar", data: unusedVar.references.some(ref => ref.isWrite()) ? getAssignedMessageData(unusedVar) diff --git a/tools/node_modules/eslint/node_modules/call-bind/LICENSE b/tools/node_modules/eslint/node_modules/call-bind/LICENSE deleted file mode 100644 index 48f05d01d0acae..00000000000000 --- a/tools/node_modules/eslint/node_modules/call-bind/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Jordan Harband - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/tools/node_modules/eslint/node_modules/call-bind/README.md b/tools/node_modules/eslint/node_modules/call-bind/README.md deleted file mode 100644 index 53649eb4622446..00000000000000 --- a/tools/node_modules/eslint/node_modules/call-bind/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# call-bind -Robustly `.call.bind()` a function. diff --git a/tools/node_modules/eslint/node_modules/call-bind/callBound.js b/tools/node_modules/eslint/node_modules/call-bind/callBound.js deleted file mode 100644 index 8374adfd0549fe..00000000000000 --- a/tools/node_modules/eslint/node_modules/call-bind/callBound.js +++ /dev/null @@ -1,15 +0,0 @@ -'use strict'; - -var GetIntrinsic = require('get-intrinsic'); - -var callBind = require('./'); - -var $indexOf = callBind(GetIntrinsic('String.prototype.indexOf')); - -module.exports = function callBoundIntrinsic(name, allowMissing) { - var intrinsic = GetIntrinsic(name, !!allowMissing); - if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) { - return callBind(intrinsic); - } - return intrinsic; -}; diff --git a/tools/node_modules/eslint/node_modules/call-bind/index.js b/tools/node_modules/eslint/node_modules/call-bind/index.js deleted file mode 100644 index 6fa3e4af7e19fd..00000000000000 --- a/tools/node_modules/eslint/node_modules/call-bind/index.js +++ /dev/null @@ -1,47 +0,0 @@ -'use strict'; - -var bind = require('function-bind'); -var GetIntrinsic = require('get-intrinsic'); - -var $apply = GetIntrinsic('%Function.prototype.apply%'); -var $call = GetIntrinsic('%Function.prototype.call%'); -var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply); - -var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true); -var $defineProperty = GetIntrinsic('%Object.defineProperty%', true); -var $max = GetIntrinsic('%Math.max%'); - -if ($defineProperty) { - try { - $defineProperty({}, 'a', { value: 1 }); - } catch (e) { - // IE 8 has a broken defineProperty - $defineProperty = null; - } -} - -module.exports = function callBind(originalFunction) { - var func = $reflectApply(bind, $call, arguments); - if ($gOPD && $defineProperty) { - var desc = $gOPD(func, 'length'); - if (desc.configurable) { - // original length, plus the receiver, minus any additional arguments (after the receiver) - $defineProperty( - func, - 'length', - { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) } - ); - } - } - return func; -}; - -var applyBind = function applyBind() { - return $reflectApply(bind, $apply, arguments); -}; - -if ($defineProperty) { - $defineProperty(module.exports, 'apply', { value: applyBind }); -} else { - module.exports.apply = applyBind; -} diff --git a/tools/node_modules/eslint/node_modules/call-bind/package.json b/tools/node_modules/eslint/node_modules/call-bind/package.json deleted file mode 100644 index 4360556a7fa0f1..00000000000000 --- a/tools/node_modules/eslint/node_modules/call-bind/package.json +++ /dev/null @@ -1,80 +0,0 @@ -{ - "name": "call-bind", - "version": "1.0.2", - "description": "Robustly `.call.bind()` a function", - "main": "index.js", - "exports": { - ".": [ - { - "default": "./index.js" - }, - "./index.js" - ], - "./callBound": [ - { - "default": "./callBound.js" - }, - "./callBound.js" - ], - "./package.json": "./package.json" - }, - "scripts": { - "prepublish": "safe-publish-latest", - "lint": "eslint --ext=.js,.mjs .", - "pretest": "npm run lint", - "tests-only": "nyc tape 'test/*'", - "test": "npm run tests-only", - "posttest": "aud --production", - "version": "auto-changelog && git add CHANGELOG.md", - "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/ljharb/call-bind.git" - }, - "keywords": [ - "javascript", - "ecmascript", - "es", - "js", - "callbind", - "callbound", - "call", - "bind", - "bound", - "call-bind", - "call-bound", - "function", - "es-abstract" - ], - "author": "Jordan Harband ", - "funding": { - "url": "https://github.com/sponsors/ljharb" - }, - "license": "MIT", - "bugs": { - "url": "https://github.com/ljharb/call-bind/issues" - }, - "homepage": "https://github.com/ljharb/call-bind#readme", - "devDependencies": { - "@ljharb/eslint-config": "^17.3.0", - "aud": "^1.1.3", - "auto-changelog": "^2.2.1", - "eslint": "^7.17.0", - "nyc": "^10.3.2", - "safe-publish-latest": "^1.1.4", - "tape": "^5.1.1" - }, - "dependencies": { - "function-bind": "^1.1.1", - "get-intrinsic": "^1.0.2" - }, - "auto-changelog": { - "output": "CHANGELOG.md", - "template": "keepachangelog", - "unreleased": false, - "commitLimit": false, - "backfillLimit": false, - "hideCredit": true - } -} diff --git a/tools/node_modules/eslint/node_modules/chalk/package.json b/tools/node_modules/eslint/node_modules/chalk/package.json index 0d99f0f28621f2..c2d63f67e5e955 100644 --- a/tools/node_modules/eslint/node_modules/chalk/package.json +++ b/tools/node_modules/eslint/node_modules/chalk/package.json @@ -1,6 +1,6 @@ { "name": "chalk", - "version": "4.1.0", + "version": "4.1.1", "description": "Terminal string styling done right", "license": "MIT", "repository": "chalk/chalk", diff --git a/tools/node_modules/eslint/node_modules/chalk/readme.md b/tools/node_modules/eslint/node_modules/chalk/readme.md index 338f42cb8b525b..851259216bc193 100644 --- a/tools/node_modules/eslint/node_modules/chalk/readme.md +++ b/tools/node_modules/eslint/node_modules/chalk/readme.md @@ -13,6 +13,48 @@ +
+ +--- + + + +--- + +
+ ## Highlights - Expressive API diff --git a/tools/node_modules/eslint/node_modules/function-bind/.jscs.json b/tools/node_modules/eslint/node_modules/function-bind/.jscs.json deleted file mode 100644 index 8c4479480be70d..00000000000000 --- a/tools/node_modules/eslint/node_modules/function-bind/.jscs.json +++ /dev/null @@ -1,176 +0,0 @@ -{ - "es3": true, - - "additionalRules": [], - - "requireSemicolons": true, - - "disallowMultipleSpaces": true, - - "disallowIdentifierNames": [], - - "requireCurlyBraces": { - "allExcept": [], - "keywords": ["if", "else", "for", "while", "do", "try", "catch"] - }, - - "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch", "function"], - - "disallowSpaceAfterKeywords": [], - - "disallowSpaceBeforeComma": true, - "disallowSpaceAfterComma": false, - "disallowSpaceBeforeSemicolon": true, - - "disallowNodeTypes": [ - "DebuggerStatement", - "ForInStatement", - "LabeledStatement", - "SwitchCase", - "SwitchStatement", - "WithStatement" - ], - - "requireObjectKeysOnNewLine": { "allExcept": ["sameLine"] }, - - "requireSpacesInAnonymousFunctionExpression": { "beforeOpeningRoundBrace": true, "beforeOpeningCurlyBrace": true }, - "requireSpacesInNamedFunctionExpression": { "beforeOpeningCurlyBrace": true }, - "disallowSpacesInNamedFunctionExpression": { "beforeOpeningRoundBrace": true }, - "requireSpacesInFunctionDeclaration": { "beforeOpeningCurlyBrace": true }, - "disallowSpacesInFunctionDeclaration": { "beforeOpeningRoundBrace": true }, - - "requireSpaceBetweenArguments": true, - - "disallowSpacesInsideParentheses": true, - - "disallowSpacesInsideArrayBrackets": true, - - "disallowQuotedKeysInObjects": { "allExcept": ["reserved"] }, - - "disallowSpaceAfterObjectKeys": true, - - "requireCommaBeforeLineBreak": true, - - "disallowSpaceAfterPrefixUnaryOperators": ["++", "--", "+", "-", "~", "!"], - "requireSpaceAfterPrefixUnaryOperators": [], - - "disallowSpaceBeforePostfixUnaryOperators": ["++", "--"], - "requireSpaceBeforePostfixUnaryOperators": [], - - "disallowSpaceBeforeBinaryOperators": [], - "requireSpaceBeforeBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], - - "requireSpaceAfterBinaryOperators": ["+", "-", "/", "*", "=", "==", "===", "!=", "!=="], - "disallowSpaceAfterBinaryOperators": [], - - "disallowImplicitTypeConversion": ["binary", "string"], - - "disallowKeywords": ["with", "eval"], - - "requireKeywordsOnNewLine": [], - "disallowKeywordsOnNewLine": ["else"], - - "requireLineFeedAtFileEnd": true, - - "disallowTrailingWhitespace": true, - - "disallowTrailingComma": true, - - "excludeFiles": ["node_modules/**", "vendor/**"], - - "disallowMultipleLineStrings": true, - - "requireDotNotation": { "allExcept": ["keywords"] }, - - "requireParenthesesAroundIIFE": true, - - "validateLineBreaks": "LF", - - "validateQuoteMarks": { - "escape": true, - "mark": "'" - }, - - "disallowOperatorBeforeLineBreak": [], - - "requireSpaceBeforeKeywords": [ - "do", - "for", - "if", - "else", - "switch", - "case", - "try", - "catch", - "finally", - "while", - "with", - "return" - ], - - "validateAlignedFunctionParameters": { - "lineBreakAfterOpeningBraces": true, - "lineBreakBeforeClosingBraces": true - }, - - "requirePaddingNewLinesBeforeExport": true, - - "validateNewlineAfterArrayElements": { - "maximum": 8 - }, - - "requirePaddingNewLinesAfterUseStrict": true, - - "disallowArrowFunctions": true, - - "disallowMultiLineTernary": true, - - "validateOrderInObjectKeys": "asc-insensitive", - - "disallowIdenticalDestructuringNames": true, - - "disallowNestedTernaries": { "maxLevel": 1 }, - - "requireSpaceAfterComma": { "allExcept": ["trailing"] }, - "requireAlignedMultilineParams": false, - - "requireSpacesInGenerator": { - "afterStar": true - }, - - "disallowSpacesInGenerator": { - "beforeStar": true - }, - - "disallowVar": false, - - "requireArrayDestructuring": false, - - "requireEnhancedObjectLiterals": false, - - "requireObjectDestructuring": false, - - "requireEarlyReturn": false, - - "requireCapitalizedConstructorsNew": { - "allExcept": ["Function", "String", "Object", "Symbol", "Number", "Date", "RegExp", "Error", "Boolean", "Array"] - }, - - "requireImportAlphabetized": false, - - "requireSpaceBeforeObjectValues": true, - "requireSpaceBeforeDestructuredValues": true, - - "disallowSpacesInsideTemplateStringPlaceholders": true, - - "disallowArrayDestructuringReturn": false, - - "requireNewlineBeforeSingleStatementsInIf": false, - - "disallowUnusedVariables": true, - - "requireSpacesInsideImportedObjectBraces": true, - - "requireUseStrict": true -} - diff --git a/tools/node_modules/eslint/node_modules/function-bind/LICENSE b/tools/node_modules/eslint/node_modules/function-bind/LICENSE deleted file mode 100644 index 62d6d237ff179b..00000000000000 --- a/tools/node_modules/eslint/node_modules/function-bind/LICENSE +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2013 Raynos. - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - diff --git a/tools/node_modules/eslint/node_modules/function-bind/README.md b/tools/node_modules/eslint/node_modules/function-bind/README.md deleted file mode 100644 index 81862a02cb940c..00000000000000 --- a/tools/node_modules/eslint/node_modules/function-bind/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# function-bind - - - - - -Implementation of function.prototype.bind - -## Example - -I mainly do this for unit tests I run on phantomjs. -PhantomJS does not have Function.prototype.bind :( - -```js -Function.prototype.bind = require("function-bind") -``` - -## Installation - -`npm install function-bind` - -## Contributors - - - Raynos - -## MIT Licenced - - [travis-svg]: https://travis-ci.org/Raynos/function-bind.svg - [travis-url]: https://travis-ci.org/Raynos/function-bind - [npm-badge-svg]: https://badge.fury.io/js/function-bind.svg - [npm-url]: https://npmjs.org/package/function-bind - [5]: https://coveralls.io/repos/Raynos/function-bind/badge.png - [6]: https://coveralls.io/r/Raynos/function-bind - [7]: https://gemnasium.com/Raynos/function-bind.png - [8]: https://gemnasium.com/Raynos/function-bind - [deps-svg]: https://david-dm.org/Raynos/function-bind.svg - [deps-url]: https://david-dm.org/Raynos/function-bind - [dev-deps-svg]: https://david-dm.org/Raynos/function-bind/dev-status.svg - [dev-deps-url]: https://david-dm.org/Raynos/function-bind#info=devDependencies - [11]: https://ci.testling.com/Raynos/function-bind.png - [12]: https://ci.testling.com/Raynos/function-bind diff --git a/tools/node_modules/eslint/node_modules/function-bind/implementation.js b/tools/node_modules/eslint/node_modules/function-bind/implementation.js deleted file mode 100644 index cc4daec1b080a1..00000000000000 --- a/tools/node_modules/eslint/node_modules/function-bind/implementation.js +++ /dev/null @@ -1,52 +0,0 @@ -'use strict'; - -/* eslint no-invalid-this: 1 */ - -var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible '; -var slice = Array.prototype.slice; -var toStr = Object.prototype.toString; -var funcType = '[object Function]'; - -module.exports = function bind(that) { - var target = this; - if (typeof target !== 'function' || toStr.call(target) !== funcType) { - throw new TypeError(ERROR_MESSAGE + target); - } - var args = slice.call(arguments, 1); - - var bound; - var binder = function () { - if (this instanceof bound) { - var result = target.apply( - this, - args.concat(slice.call(arguments)) - ); - if (Object(result) === result) { - return result; - } - return this; - } else { - return target.apply( - that, - args.concat(slice.call(arguments)) - ); - } - }; - - var boundLength = Math.max(0, target.length - args.length); - var boundArgs = []; - for (var i = 0; i < boundLength; i++) { - boundArgs.push('$' + i); - } - - bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder); - - if (target.prototype) { - var Empty = function Empty() {}; - Empty.prototype = target.prototype; - bound.prototype = new Empty(); - Empty.prototype = null; - } - - return bound; -}; diff --git a/tools/node_modules/eslint/node_modules/function-bind/index.js b/tools/node_modules/eslint/node_modules/function-bind/index.js deleted file mode 100644 index 3bb6b9609889f8..00000000000000 --- a/tools/node_modules/eslint/node_modules/function-bind/index.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -var implementation = require('./implementation'); - -module.exports = Function.prototype.bind || implementation; diff --git a/tools/node_modules/eslint/node_modules/function-bind/package.json b/tools/node_modules/eslint/node_modules/function-bind/package.json deleted file mode 100644 index 20a1727cbf8711..00000000000000 --- a/tools/node_modules/eslint/node_modules/function-bind/package.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "name": "function-bind", - "version": "1.1.1", - "description": "Implementation of Function.prototype.bind", - "keywords": [ - "function", - "bind", - "shim", - "es5" - ], - "author": "Raynos ", - "repository": "git://github.com/Raynos/function-bind.git", - "main": "index", - "homepage": "https://github.com/Raynos/function-bind", - "contributors": [ - { - "name": "Raynos" - }, - { - "name": "Jordan Harband", - "url": "https://github.com/ljharb" - } - ], - "bugs": { - "url": "https://github.com/Raynos/function-bind/issues", - "email": "raynos2@gmail.com" - }, - "dependencies": {}, - "devDependencies": { - "@ljharb/eslint-config": "^12.2.1", - "covert": "^1.1.0", - "eslint": "^4.5.0", - "jscs": "^3.0.7", - "tape": "^4.8.0" - }, - "license": "MIT", - "scripts": { - "pretest": "npm run lint", - "test": "npm run tests-only", - "posttest": "npm run coverage -- --quiet", - "tests-only": "node test", - "coverage": "covert test/*.js", - "lint": "npm run jscs && npm run eslint", - "jscs": "jscs *.js */*.js", - "eslint": "eslint *.js */*.js" - }, - "testling": { - "files": "test/index.js", - "browsers": [ - "ie/8..latest", - "firefox/16..latest", - "firefox/nightly", - "chrome/22..latest", - "chrome/canary", - "opera/12..latest", - "opera/next", - "safari/5.1..latest", - "ipad/6.0..latest", - "iphone/6.0..latest", - "android-browser/4.2..latest" - ] - } -} diff --git a/tools/node_modules/eslint/node_modules/get-intrinsic/LICENSE b/tools/node_modules/eslint/node_modules/get-intrinsic/LICENSE deleted file mode 100644 index 48f05d01d0acae..00000000000000 --- a/tools/node_modules/eslint/node_modules/get-intrinsic/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2020 Jordan Harband - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/tools/node_modules/eslint/node_modules/get-intrinsic/README.md b/tools/node_modules/eslint/node_modules/get-intrinsic/README.md deleted file mode 100644 index 335a3b49b2ebe6..00000000000000 --- a/tools/node_modules/eslint/node_modules/get-intrinsic/README.md +++ /dev/null @@ -1,65 +0,0 @@ -# get-intrinsic [![Version Badge][npm-version-svg]][package-url] - -[![dependency status][deps-svg]][deps-url] -[![dev dependency status][dev-deps-svg]][dev-deps-url] -[![License][license-image]][license-url] -[![Downloads][downloads-image]][downloads-url] - -[![npm badge][npm-badge-png]][package-url] - -Get and robustly cache all JS language-level intrinsics at first require time. - -See the syntax described [in the JS spec](https://tc39.es/ecma262/#sec-well-known-intrinsic-objects) for reference. - -## Example - -```js -var GetIntrinsic = require('get-intrinsic'); -var assert = require('assert'); - -// static methods -assert.equal(GetIntrinsic('%Math.pow%'), Math.pow); -assert.equal(Math.pow(2, 3), 8); -assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8); -delete Math.pow; -assert.equal(GetIntrinsic('%Math.pow%')(2, 3), 8); - -// instance methods -var arr = [1]; -assert.equal(GetIntrinsic('%Array.prototype.push%'), Array.prototype.push); -assert.deepEqual(arr, [1]); - -arr.push(2); -assert.deepEqual(arr, [1, 2]); - -GetIntrinsic('%Array.prototype.push%').call(arr, 3); -assert.deepEqual(arr, [1, 2, 3]); - -delete Array.prototype.push; -GetIntrinsic('%Array.prototype.push%').call(arr, 4); -assert.deepEqual(arr, [1, 2, 3, 4]); - -// missing features -delete JSON.parse; // to simulate a real intrinsic that is missing in the environment -assert.throws(() => GetIntrinsic('%JSON.parse%')); -assert.equal(undefined, GetIntrinsic('%JSON.parse%', true)); -``` - -## Tests -Simply clone the repo, `npm install`, and run `npm test` - -## Security - -Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report. - -[package-url]: https://npmjs.org/package/get-intrinsic -[npm-version-svg]: http://versionbadg.es/ljharb/get-intrinsic.svg -[deps-svg]: https://david-dm.org/ljharb/get-intrinsic.svg -[deps-url]: https://david-dm.org/ljharb/get-intrinsic -[dev-deps-svg]: https://david-dm.org/ljharb/get-intrinsic/dev-status.svg -[dev-deps-url]: https://david-dm.org/ljharb/get-intrinsic#info=devDependencies -[npm-badge-png]: https://nodei.co/npm/get-intrinsic.png?downloads=true&stars=true -[license-image]: https://img.shields.io/npm/l/get-intrinsic.svg -[license-url]: LICENSE -[downloads-image]: https://img.shields.io/npm/dm/get-intrinsic.svg -[downloads-url]: https://npm-stat.com/charts.html?package=get-intrinsic diff --git a/tools/node_modules/eslint/node_modules/get-intrinsic/index.js b/tools/node_modules/eslint/node_modules/get-intrinsic/index.js deleted file mode 100644 index d6c06c281c0ac7..00000000000000 --- a/tools/node_modules/eslint/node_modules/get-intrinsic/index.js +++ /dev/null @@ -1,330 +0,0 @@ -'use strict'; - -var undefined; - -var $SyntaxError = SyntaxError; -var $Function = Function; -var $TypeError = TypeError; - -// eslint-disable-next-line consistent-return -var getEvalledConstructor = function (expressionSyntax) { - try { - return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')(); - } catch (e) {} -}; - -var $gOPD = Object.getOwnPropertyDescriptor; -if ($gOPD) { - try { - $gOPD({}, ''); - } catch (e) { - $gOPD = null; // this is IE 8, which has a broken gOPD - } -} - -var throwTypeError = function () { - throw new $TypeError(); -}; -var ThrowTypeError = $gOPD - ? (function () { - try { - // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties - arguments.callee; // IE 8 does not throw here - return throwTypeError; - } catch (calleeThrows) { - try { - // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') - return $gOPD(arguments, 'callee').get; - } catch (gOPDthrows) { - return throwTypeError; - } - } - }()) - : throwTypeError; - -var hasSymbols = require('has-symbols')(); - -var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; }; // eslint-disable-line no-proto - -var needsEval = {}; - -var TypedArray = typeof Uint8Array === 'undefined' ? undefined : getProto(Uint8Array); - -var INTRINSICS = { - '%AggregateError%': typeof AggregateError === 'undefined' ? undefined : AggregateError, - '%Array%': Array, - '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined : ArrayBuffer, - '%ArrayIteratorPrototype%': hasSymbols ? getProto([][Symbol.iterator]()) : undefined, - '%AsyncFromSyncIteratorPrototype%': undefined, - '%AsyncFunction%': needsEval, - '%AsyncGenerator%': needsEval, - '%AsyncGeneratorFunction%': needsEval, - '%AsyncIteratorPrototype%': needsEval, - '%Atomics%': typeof Atomics === 'undefined' ? undefined : Atomics, - '%BigInt%': typeof BigInt === 'undefined' ? undefined : BigInt, - '%Boolean%': Boolean, - '%DataView%': typeof DataView === 'undefined' ? undefined : DataView, - '%Date%': Date, - '%decodeURI%': decodeURI, - '%decodeURIComponent%': decodeURIComponent, - '%encodeURI%': encodeURI, - '%encodeURIComponent%': encodeURIComponent, - '%Error%': Error, - '%eval%': eval, // eslint-disable-line no-eval - '%EvalError%': EvalError, - '%Float32Array%': typeof Float32Array === 'undefined' ? undefined : Float32Array, - '%Float64Array%': typeof Float64Array === 'undefined' ? undefined : Float64Array, - '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined : FinalizationRegistry, - '%Function%': $Function, - '%GeneratorFunction%': needsEval, - '%Int8Array%': typeof Int8Array === 'undefined' ? undefined : Int8Array, - '%Int16Array%': typeof Int16Array === 'undefined' ? undefined : Int16Array, - '%Int32Array%': typeof Int32Array === 'undefined' ? undefined : Int32Array, - '%isFinite%': isFinite, - '%isNaN%': isNaN, - '%IteratorPrototype%': hasSymbols ? getProto(getProto([][Symbol.iterator]())) : undefined, - '%JSON%': typeof JSON === 'object' ? JSON : undefined, - '%Map%': typeof Map === 'undefined' ? undefined : Map, - '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols ? undefined : getProto(new Map()[Symbol.iterator]()), - '%Math%': Math, - '%Number%': Number, - '%Object%': Object, - '%parseFloat%': parseFloat, - '%parseInt%': parseInt, - '%Promise%': typeof Promise === 'undefined' ? undefined : Promise, - '%Proxy%': typeof Proxy === 'undefined' ? undefined : Proxy, - '%RangeError%': RangeError, - '%ReferenceError%': ReferenceError, - '%Reflect%': typeof Reflect === 'undefined' ? undefined : Reflect, - '%RegExp%': RegExp, - '%Set%': typeof Set === 'undefined' ? undefined : Set, - '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols ? undefined : getProto(new Set()[Symbol.iterator]()), - '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined : SharedArrayBuffer, - '%String%': String, - '%StringIteratorPrototype%': hasSymbols ? getProto(''[Symbol.iterator]()) : undefined, - '%Symbol%': hasSymbols ? Symbol : undefined, - '%SyntaxError%': $SyntaxError, - '%ThrowTypeError%': ThrowTypeError, - '%TypedArray%': TypedArray, - '%TypeError%': $TypeError, - '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined : Uint8Array, - '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined : Uint8ClampedArray, - '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined : Uint16Array, - '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined : Uint32Array, - '%URIError%': URIError, - '%WeakMap%': typeof WeakMap === 'undefined' ? undefined : WeakMap, - '%WeakRef%': typeof WeakRef === 'undefined' ? undefined : WeakRef, - '%WeakSet%': typeof WeakSet === 'undefined' ? undefined : WeakSet -}; - -var doEval = function doEval(name) { - var value; - if (name === '%AsyncFunction%') { - value = getEvalledConstructor('async function () {}'); - } else if (name === '%GeneratorFunction%') { - value = getEvalledConstructor('function* () {}'); - } else if (name === '%AsyncGeneratorFunction%') { - value = getEvalledConstructor('async function* () {}'); - } else if (name === '%AsyncGenerator%') { - var fn = doEval('%AsyncGeneratorFunction%'); - if (fn) { - value = fn.prototype; - } - } else if (name === '%AsyncIteratorPrototype%') { - var gen = doEval('%AsyncGenerator%'); - if (gen) { - value = getProto(gen.prototype); - } - } - - INTRINSICS[name] = value; - - return value; -}; - -var LEGACY_ALIASES = { - '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'], - '%ArrayPrototype%': ['Array', 'prototype'], - '%ArrayProto_entries%': ['Array', 'prototype', 'entries'], - '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'], - '%ArrayProto_keys%': ['Array', 'prototype', 'keys'], - '%ArrayProto_values%': ['Array', 'prototype', 'values'], - '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'], - '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'], - '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'], - '%BooleanPrototype%': ['Boolean', 'prototype'], - '%DataViewPrototype%': ['DataView', 'prototype'], - '%DatePrototype%': ['Date', 'prototype'], - '%ErrorPrototype%': ['Error', 'prototype'], - '%EvalErrorPrototype%': ['EvalError', 'prototype'], - '%Float32ArrayPrototype%': ['Float32Array', 'prototype'], - '%Float64ArrayPrototype%': ['Float64Array', 'prototype'], - '%FunctionPrototype%': ['Function', 'prototype'], - '%Generator%': ['GeneratorFunction', 'prototype'], - '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'], - '%Int8ArrayPrototype%': ['Int8Array', 'prototype'], - '%Int16ArrayPrototype%': ['Int16Array', 'prototype'], - '%Int32ArrayPrototype%': ['Int32Array', 'prototype'], - '%JSONParse%': ['JSON', 'parse'], - '%JSONStringify%': ['JSON', 'stringify'], - '%MapPrototype%': ['Map', 'prototype'], - '%NumberPrototype%': ['Number', 'prototype'], - '%ObjectPrototype%': ['Object', 'prototype'], - '%ObjProto_toString%': ['Object', 'prototype', 'toString'], - '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'], - '%PromisePrototype%': ['Promise', 'prototype'], - '%PromiseProto_then%': ['Promise', 'prototype', 'then'], - '%Promise_all%': ['Promise', 'all'], - '%Promise_reject%': ['Promise', 'reject'], - '%Promise_resolve%': ['Promise', 'resolve'], - '%RangeErrorPrototype%': ['RangeError', 'prototype'], - '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'], - '%RegExpPrototype%': ['RegExp', 'prototype'], - '%SetPrototype%': ['Set', 'prototype'], - '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'], - '%StringPrototype%': ['String', 'prototype'], - '%SymbolPrototype%': ['Symbol', 'prototype'], - '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'], - '%TypedArrayPrototype%': ['TypedArray', 'prototype'], - '%TypeErrorPrototype%': ['TypeError', 'prototype'], - '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'], - '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'], - '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'], - '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'], - '%URIErrorPrototype%': ['URIError', 'prototype'], - '%WeakMapPrototype%': ['WeakMap', 'prototype'], - '%WeakSetPrototype%': ['WeakSet', 'prototype'] -}; - -var bind = require('function-bind'); -var hasOwn = require('has'); -var $concat = bind.call(Function.call, Array.prototype.concat); -var $spliceApply = bind.call(Function.apply, Array.prototype.splice); -var $replace = bind.call(Function.call, String.prototype.replace); -var $strSlice = bind.call(Function.call, String.prototype.slice); - -/* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ -var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; -var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ -var stringToPath = function stringToPath(string) { - var first = $strSlice(string, 0, 1); - var last = $strSlice(string, -1); - if (first === '%' && last !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`'); - } else if (last === '%' && first !== '%') { - throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`'); - } - var result = []; - $replace(string, rePropName, function (match, number, quote, subString) { - result[result.length] = quote ? $replace(subString, reEscapeChar, '$1') : number || match; - }); - return result; -}; -/* end adaptation */ - -var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { - var intrinsicName = name; - var alias; - if (hasOwn(LEGACY_ALIASES, intrinsicName)) { - alias = LEGACY_ALIASES[intrinsicName]; - intrinsicName = '%' + alias[0] + '%'; - } - - if (hasOwn(INTRINSICS, intrinsicName)) { - var value = INTRINSICS[intrinsicName]; - if (value === needsEval) { - value = doEval(intrinsicName); - } - if (typeof value === 'undefined' && !allowMissing) { - throw new $TypeError('intrinsic ' + name + ' exists, but is not available. Please file an issue!'); - } - - return { - alias: alias, - name: intrinsicName, - value: value - }; - } - - throw new $SyntaxError('intrinsic ' + name + ' does not exist!'); -}; - -module.exports = function GetIntrinsic(name, allowMissing) { - if (typeof name !== 'string' || name.length === 0) { - throw new $TypeError('intrinsic name must be a non-empty string'); - } - if (arguments.length > 1 && typeof allowMissing !== 'boolean') { - throw new $TypeError('"allowMissing" argument must be a boolean'); - } - - var parts = stringToPath(name); - var intrinsicBaseName = parts.length > 0 ? parts[0] : ''; - - var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing); - var intrinsicRealName = intrinsic.name; - var value = intrinsic.value; - var skipFurtherCaching = false; - - var alias = intrinsic.alias; - if (alias) { - intrinsicBaseName = alias[0]; - $spliceApply(parts, $concat([0, 1], alias)); - } - - for (var i = 1, isOwn = true; i < parts.length; i += 1) { - var part = parts[i]; - var first = $strSlice(part, 0, 1); - var last = $strSlice(part, -1); - if ( - ( - (first === '"' || first === "'" || first === '`') - || (last === '"' || last === "'" || last === '`') - ) - && first !== last - ) { - throw new $SyntaxError('property names with quotes must have matching quotes'); - } - if (part === 'constructor' || !isOwn) { - skipFurtherCaching = true; - } - - intrinsicBaseName += '.' + part; - intrinsicRealName = '%' + intrinsicBaseName + '%'; - - if (hasOwn(INTRINSICS, intrinsicRealName)) { - value = INTRINSICS[intrinsicRealName]; - } else if (value != null) { - if (!(part in value)) { - if (!allowMissing) { - throw new $TypeError('base intrinsic for ' + name + ' exists, but the property is not available.'); - } - return void undefined; - } - if ($gOPD && (i + 1) >= parts.length) { - var desc = $gOPD(value, part); - isOwn = !!desc; - - // By convention, when a data property is converted to an accessor - // property to emulate a data property that does not suffer from - // the override mistake, that accessor's getter is marked with - // an `originalValue` property. Here, when we detect this, we - // uphold the illusion by pretending to see that original data - // property, i.e., returning the value rather than the getter - // itself. - if (isOwn && 'get' in desc && !('originalValue' in desc.get)) { - value = desc.get; - } else { - value = value[part]; - } - } else { - isOwn = hasOwn(value, part); - value = value[part]; - } - - if (isOwn && !skipFurtherCaching) { - INTRINSICS[intrinsicRealName] = value; - } - } - } - return value; -}; diff --git a/tools/node_modules/eslint/node_modules/get-intrinsic/package.json b/tools/node_modules/eslint/node_modules/get-intrinsic/package.json deleted file mode 100644 index d34894a0681d27..00000000000000 --- a/tools/node_modules/eslint/node_modules/get-intrinsic/package.json +++ /dev/null @@ -1,78 +0,0 @@ -{ - "name": "get-intrinsic", - "version": "1.1.1", - "description": "Get and robustly cache all JS language-level intrinsics at first require time", - "main": "index.js", - "exports": { - ".": [ - { - "default": "./index.js" - }, - "./index.js" - ], - "./package.json": "./package.json" - }, - "scripts": { - "prelint": "evalmd README.md", - "lint": "eslint --ext=.js,.mjs .", - "pretest": "npm run lint", - "tests-only": "nyc tape 'test/**/*.js'", - "test": "npm run tests-only", - "posttest": "aud --production", - "version": "auto-changelog && git add CHANGELOG.md", - "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/ljharb/get-intrinsic.git" - }, - "keywords": [ - "javascript", - "ecmascript", - "es", - "js", - "intrinsic", - "getintrinsic", - "es-abstract" - ], - "author": "Jordan Harband ", - "funding": { - "url": "https://github.com/sponsors/ljharb" - }, - "license": "MIT", - "bugs": { - "url": "https://github.com/ljharb/get-intrinsic/issues" - }, - "homepage": "https://github.com/ljharb/get-intrinsic#readme", - "devDependencies": { - "@ljharb/eslint-config": "^17.5.0", - "aud": "^1.1.3", - "auto-changelog": "^2.2.1", - "call-bind": "^1.0.2", - "es-abstract": "^1.18.0-next.2", - "es-value-fixtures": "^1.0.0", - "eslint": "^7.19.0", - "evalmd": "^0.0.19", - "foreach": "^2.0.5", - "has-bigints": "^1.0.1", - "make-async-function": "^1.0.0", - "make-async-generator-function": "^1.0.0", - "make-generator-function": "^2.0.0", - "nyc": "^10.3.2", - "object-inspect": "^1.9.0", - "tape": "^5.1.1" - }, - "auto-changelog": { - "output": "CHANGELOG.md", - "template": "keepachangelog", - "unreleased": false, - "commitLimit": false, - "backfillLimit": false, - "hideCredit": true - }, - "dependencies": { - "function-bind": "^1.1.1", - "has": "^1.0.3", - "has-symbols": "^1.0.1" - } -} diff --git a/tools/node_modules/eslint/node_modules/has-symbols/LICENSE b/tools/node_modules/eslint/node_modules/has-symbols/LICENSE deleted file mode 100644 index df31cbf3c064d0..00000000000000 --- a/tools/node_modules/eslint/node_modules/has-symbols/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2016 Jordan Harband - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/tools/node_modules/eslint/node_modules/has-symbols/README.md b/tools/node_modules/eslint/node_modules/has-symbols/README.md deleted file mode 100644 index 3875d7e58d7ea9..00000000000000 --- a/tools/node_modules/eslint/node_modules/has-symbols/README.md +++ /dev/null @@ -1,40 +0,0 @@ -# has-symbols [![Version Badge][2]][1] - -[![dependency status][5]][6] -[![dev dependency status][7]][8] -[![License][license-image]][license-url] -[![Downloads][downloads-image]][downloads-url] - -[![npm badge][11]][1] - -Determine if the JS environment has Symbol support. Supports spec, or shams. - -## Example - -```js -var hasSymbols = require('has-symbols'); - -hasSymbols() === true; // if the environment has native Symbol support. Not polyfillable, not forgeable. - -var hasSymbolsKinda = require('has-symbols/shams'); -hasSymbolsKinda() === true; // if the environment has a Symbol sham that mostly follows the spec. -``` - -## Supported Symbol shams - - get-own-property-symbols [npm](https://www.npmjs.com/package/get-own-property-symbols) | [github](https://github.com/WebReflection/get-own-property-symbols) - - core-js [npm](https://www.npmjs.com/package/core-js) | [github](https://github.com/zloirock/core-js) - -## Tests -Simply clone the repo, `npm install`, and run `npm test` - -[1]: https://npmjs.org/package/has-symbols -[2]: https://versionbadg.es/inspect-js/has-symbols.svg -[5]: https://david-dm.org/inspect-js/has-symbols.svg -[6]: https://david-dm.org/inspect-js/has-symbols -[7]: https://david-dm.org/inspect-js/has-symbols/dev-status.svg -[8]: https://david-dm.org/inspect-js/has-symbols#info=devDependencies -[11]: https://nodei.co/npm/has-symbols.png?downloads=true&stars=true -[license-image]: https://img.shields.io/npm/l/has-symbols.svg -[license-url]: LICENSE -[downloads-image]: https://img.shields.io/npm/dm/has-symbols.svg -[downloads-url]: https://npm-stat.com/charts.html?package=has-symbols diff --git a/tools/node_modules/eslint/node_modules/has-symbols/index.js b/tools/node_modules/eslint/node_modules/has-symbols/index.js deleted file mode 100644 index 17044fa21daa70..00000000000000 --- a/tools/node_modules/eslint/node_modules/has-symbols/index.js +++ /dev/null @@ -1,13 +0,0 @@ -'use strict'; - -var origSymbol = typeof Symbol !== 'undefined' && Symbol; -var hasSymbolSham = require('./shams'); - -module.exports = function hasNativeSymbols() { - if (typeof origSymbol !== 'function') { return false; } - if (typeof Symbol !== 'function') { return false; } - if (typeof origSymbol('foo') !== 'symbol') { return false; } - if (typeof Symbol('bar') !== 'symbol') { return false; } - - return hasSymbolSham(); -}; diff --git a/tools/node_modules/eslint/node_modules/has-symbols/package.json b/tools/node_modules/eslint/node_modules/has-symbols/package.json deleted file mode 100644 index 2c2f57278b1747..00000000000000 --- a/tools/node_modules/eslint/node_modules/has-symbols/package.json +++ /dev/null @@ -1,96 +0,0 @@ -{ - "name": "has-symbols", - "version": "1.0.2", - "author": { - "name": "Jordan Harband", - "email": "ljharb@gmail.com", - "url": "http://ljharb.codes" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - }, - "contributors": [ - { - "name": "Jordan Harband", - "email": "ljharb@gmail.com", - "url": "http://ljharb.codes" - } - ], - "description": "Determine if the JS environment has Symbol support. Supports spec, or shams.", - "license": "MIT", - "main": "index.js", - "scripts": { - "prepublish": "safe-publish-latest", - "pretest": "npm run --silent lint", - "test": "npm run tests-only", - "posttest": "aud --production", - "tests-only": "npm run test:stock && npm run test:staging && npm run test:shams", - "test:stock": "nyc node test", - "test:staging": "nyc node --harmony --es-staging test", - "test:shams": "npm run --silent test:shams:getownpropertysymbols && npm run --silent test:shams:corejs", - "test:shams:corejs": "nyc node test/shams/core-js.js", - "test:shams:getownpropertysymbols": "nyc node test/shams/get-own-property-symbols.js", - "lint": "eslint --ext=js,mjs .", - "version": "auto-changelog && git add CHANGELOG.md", - "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" - }, - "repository": { - "type": "git", - "url": "git://github.com/inspect-js/has-symbols.git" - }, - "keywords": [ - "Symbol", - "symbols", - "typeof", - "sham", - "polyfill", - "native", - "core-js", - "ES6" - ], - "devDependencies": { - "@ljharb/eslint-config": "^17.5.1", - "aud": "^1.1.4", - "auto-changelog": "^2.2.1", - "core-js": "^2.6.12", - "eslint": "^7.20.0", - "get-own-property-symbols": "^0.9.5", - "nyc": "^10.3.2", - "safe-publish-latest": "^1.1.4", - "tape": "^5.2.0" - }, - "testling": { - "files": "test/index.js", - "browsers": [ - "iexplore/6.0..latest", - "firefox/3.0..6.0", - "firefox/15.0..latest", - "firefox/nightly", - "chrome/4.0..10.0", - "chrome/20.0..latest", - "chrome/canary", - "opera/10.0..latest", - "opera/next", - "safari/4.0..latest", - "ipad/6.0..latest", - "iphone/6.0..latest", - "android-browser/4.2" - ] - }, - "engines": { - "node": ">= 0.4" - }, - "auto-changelog": { - "output": "CHANGELOG.md", - "template": "keepachangelog", - "unreleased": false, - "commitLimit": false, - "backfillLimit": false, - "hideCredit": true - }, - "greenkeeper": { - "ignore": [ - "core-js" - ] - } -} diff --git a/tools/node_modules/eslint/node_modules/has-symbols/shams.js b/tools/node_modules/eslint/node_modules/has-symbols/shams.js deleted file mode 100644 index 1285210ef7ccef..00000000000000 --- a/tools/node_modules/eslint/node_modules/has-symbols/shams.js +++ /dev/null @@ -1,42 +0,0 @@ -'use strict'; - -/* eslint complexity: [2, 18], max-statements: [2, 33] */ -module.exports = function hasSymbols() { - if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; } - if (typeof Symbol.iterator === 'symbol') { return true; } - - var obj = {}; - var sym = Symbol('test'); - var symObj = Object(sym); - if (typeof sym === 'string') { return false; } - - if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; } - if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; } - - // temp disabled per https://github.com/ljharb/object.assign/issues/17 - // if (sym instanceof Symbol) { return false; } - // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4 - // if (!(symObj instanceof Symbol)) { return false; } - - // if (typeof Symbol.prototype.toString !== 'function') { return false; } - // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; } - - var symVal = 42; - obj[sym] = symVal; - for (sym in obj) { return false; } // eslint-disable-line no-restricted-syntax, no-unreachable-loop - if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; } - - if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; } - - var syms = Object.getOwnPropertySymbols(obj); - if (syms.length !== 1 || syms[0] !== sym) { return false; } - - if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; } - - if (typeof Object.getOwnPropertyDescriptor === 'function') { - var descriptor = Object.getOwnPropertyDescriptor(obj, sym); - if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; } - } - - return true; -}; diff --git a/tools/node_modules/eslint/node_modules/has/LICENSE-MIT b/tools/node_modules/eslint/node_modules/has/LICENSE-MIT deleted file mode 100644 index ae7014d385df3d..00000000000000 --- a/tools/node_modules/eslint/node_modules/has/LICENSE-MIT +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2013 Thiago de Arruda - -Permission is hereby granted, free of charge, to any person -obtaining a copy of this software and associated documentation -files (the "Software"), to deal in the Software without -restriction, including without limitation the rights to use, -copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the -Software is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES -OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT -HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, -WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. diff --git a/tools/node_modules/eslint/node_modules/has/README.md b/tools/node_modules/eslint/node_modules/has/README.md deleted file mode 100644 index 635e3a4baab00b..00000000000000 --- a/tools/node_modules/eslint/node_modules/has/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# has - -> Object.prototype.hasOwnProperty.call shortcut - -## Installation - -```sh -npm install --save has -``` - -## Usage - -```js -var has = require('has'); - -has({}, 'hasOwnProperty'); // false -has(Object.prototype, 'hasOwnProperty'); // true -``` diff --git a/tools/node_modules/eslint/node_modules/has/package.json b/tools/node_modules/eslint/node_modules/has/package.json deleted file mode 100644 index 7c4592f16de071..00000000000000 --- a/tools/node_modules/eslint/node_modules/has/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "has", - "description": "Object.prototype.hasOwnProperty.call shortcut", - "version": "1.0.3", - "homepage": "https://github.com/tarruda/has", - "author": { - "name": "Thiago de Arruda", - "email": "tpadilha84@gmail.com" - }, - "contributors": [ - { - "name": "Jordan Harband", - "email": "ljharb@gmail.com", - "url": "http://ljharb.codes" - } - ], - "repository": { - "type": "git", - "url": "git://github.com/tarruda/has.git" - }, - "bugs": { - "url": "https://github.com/tarruda/has/issues" - }, - "license": "MIT", - "licenses": [ - { - "type": "MIT", - "url": "https://github.com/tarruda/has/blob/master/LICENSE-MIT" - } - ], - "main": "./src", - "dependencies": { - "function-bind": "^1.1.1" - }, - "devDependencies": { - "@ljharb/eslint-config": "^12.2.1", - "eslint": "^4.19.1", - "tape": "^4.9.0" - }, - "engines": { - "node": ">= 0.4.0" - }, - "scripts": { - "lint": "eslint .", - "pretest": "npm run lint", - "test": "tape test" - } -} diff --git a/tools/node_modules/eslint/node_modules/has/src/index.js b/tools/node_modules/eslint/node_modules/has/src/index.js deleted file mode 100644 index dd92dd9094edb0..00000000000000 --- a/tools/node_modules/eslint/node_modules/has/src/index.js +++ /dev/null @@ -1,5 +0,0 @@ -'use strict'; - -var bind = require('function-bind'); - -module.exports = bind.call(Function.call, Object.prototype.hasOwnProperty); diff --git a/tools/node_modules/eslint/node_modules/is-boolean-object/LICENSE b/tools/node_modules/eslint/node_modules/is-boolean-object/LICENSE deleted file mode 100644 index b43df444e51828..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-boolean-object/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Jordan Harband - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/tools/node_modules/eslint/node_modules/is-boolean-object/README.md b/tools/node_modules/eslint/node_modules/is-boolean-object/README.md deleted file mode 100644 index aeadb7c816c545..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-boolean-object/README.md +++ /dev/null @@ -1,58 +0,0 @@ -# is-boolean-object [![Version Badge][2]][1] - -[![Build Status][3]][4] -[![dependency status][5]][6] -[![dev dependency status][7]][8] -[![License][license-image]][license-url] -[![Downloads][downloads-image]][downloads-url] - -[![npm badge][11]][1] - -[![browser support][9]][10] - -Is this value a JS Boolean? This module works cross-realm/iframe, and despite ES6 @@toStringTag. - -## Example - -```js -var isBoolean = require('is-boolean-object'); -var assert = require('assert'); - -assert.notOk(isBoolean(undefined)); -assert.notOk(isBoolean(null)); -assert.notOk(isBoolean('foo')); -assert.notOk(isBoolean(function () {})); -assert.notOk(isBoolean([])); -assert.notOk(isBoolean({})); -assert.notOk(isBoolean(/a/g)); -assert.notOk(isBoolean(new RegExp('a', 'g'))); -assert.notOk(isBoolean(new Date())); -assert.notOk(isBoolean(42)); -assert.notOk(isBoolean(NaN)); -assert.notOk(isBoolean(Infinity)); - -assert.ok(isBoolean(new Boolean(42))); -assert.ok(isBoolean(false)); -assert.ok(isBoolean(Object(false))); -assert.ok(isBoolean(true)); -assert.ok(isBoolean(Object(true))); -``` - -## Tests -Simply clone the repo, `npm install`, and run `npm test` - -[1]: https://npmjs.org/package/is-boolean-object -[2]: http://versionbadg.es/ljharb/is-boolean-object.svg -[3]: https://travis-ci.org/ljharb/is-boolean-object.svg -[4]: https://travis-ci.org/ljharb/is-boolean-object -[5]: https://david-dm.org/ljharb/is-boolean-object.svg -[6]: https://david-dm.org/ljharb/is-boolean-object -[7]: https://david-dm.org/ljharb/is-boolean-object/dev-status.svg -[8]: https://david-dm.org/ljharb/is-boolean-object#info=devDependencies -[9]: https://ci.testling.com/ljharb/is-boolean-object.png -[10]: https://ci.testling.com/ljharb/is-boolean-object -[11]: https://nodei.co/npm/is-boolean-object.png?downloads=true&stars=true -[license-image]: http://img.shields.io/npm/l/is-boolean-object.svg -[license-url]: LICENSE -[downloads-image]: http://img.shields.io/npm/dm/is-boolean-object.svg -[downloads-url]: http://npm-stat.com/charts.html?package=is-boolean-object diff --git a/tools/node_modules/eslint/node_modules/is-boolean-object/index.js b/tools/node_modules/eslint/node_modules/is-boolean-object/index.js deleted file mode 100644 index 69864eb56013af..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-boolean-object/index.js +++ /dev/null @@ -1,26 +0,0 @@ -'use strict'; - -var callBound = require('call-bind/callBound'); -var $boolToStr = callBound('Boolean.prototype.toString'); -var $toString = callBound('Object.prototype.toString'); - -var tryBooleanObject = function booleanBrandCheck(value) { - try { - $boolToStr(value); - return true; - } catch (e) { - return false; - } -}; -var boolClass = '[object Boolean]'; -var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; - -module.exports = function isBoolean(value) { - if (typeof value === 'boolean') { - return true; - } - if (value === null || typeof value !== 'object') { - return false; - } - return hasToStringTag && Symbol.toStringTag in value ? tryBooleanObject(value) : $toString(value) === boolClass; -}; diff --git a/tools/node_modules/eslint/node_modules/is-boolean-object/package.json b/tools/node_modules/eslint/node_modules/is-boolean-object/package.json deleted file mode 100644 index a2af900f00905b..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-boolean-object/package.json +++ /dev/null @@ -1,83 +0,0 @@ -{ - "name": "is-boolean-object", - "version": "1.1.0", - "author": "Jordan Harband ", - "funding": { - "url": "https://github.com/sponsors/ljharb" - }, - "description": "Is this value a JS Boolean? This module works cross-realm/iframe, and despite ES6 @@toStringTag.", - "license": "MIT", - "main": "index.js", - "scripts": { - "prepublish": "safe-publish-latest", - "pretest": "npm run lint", - "test": "npm run tests-only && npm run test:harmony", - "tests-only": "nyc tape 'test/**/*.js'", - "test:harmony": "node --harmony --es-staging test", - "posttest": "aud --production", - "prelint": "npm run eccheck", - "lint": "eslint --ext=js,mjs .", - "eccheck": "eclint check $(git ls-files)", - "version": "auto-changelog && git add CHANGELOG.md", - "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" - }, - "repository": { - "type": "git", - "url": "git://github.com/ljharb/is-boolean-object.git" - }, - "keywords": [ - "Boolean", - "ES6", - "toStringTag", - "@@toStringTag", - "Boolean object", - "true", - "false", - "is-boolean" - ], - "dependencies": { - "call-bind": "^1.0.0" - }, - "devDependencies": { - "@ljharb/eslint-config": "^17.3.0", - "aud": "^1.1.3", - "auto-changelog": "^2.2.1", - "eclint": "^2.8.1", - "eslint": "^7.15.0", - "foreach": "^2.0.5", - "indexof": "^0.0.1", - "is": "^3.3.0", - "nyc": "^10.3.2", - "safe-publish-latest": "^1.1.4", - "tape": "^5.0.1" - }, - "testling": { - "files": "test.js", - "browsers": [ - "iexplore/6.0..latest", - "firefox/3.0..6.0", - "firefox/15.0..latest", - "firefox/nightly", - "chrome/4.0..10.0", - "chrome/20.0..latest", - "chrome/canary", - "opera/10.0..latest", - "opera/next", - "safari/4.0..latest", - "ipad/6.0..latest", - "iphone/6.0..latest", - "android-browser/4.2" - ] - }, - "engines": { - "node": ">= 0.4" - }, - "auto-changelog": { - "output": "CHANGELOG.md", - "template": "keepachangelog", - "unreleased": false, - "commitLimit": false, - "backfillLimit": false, - "hideCredit": true - } -} diff --git a/tools/node_modules/eslint/node_modules/is-number-object/LICENSE b/tools/node_modules/eslint/node_modules/is-number-object/LICENSE deleted file mode 100644 index b43df444e51828..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-number-object/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Jordan Harband - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/tools/node_modules/eslint/node_modules/is-number-object/README.md b/tools/node_modules/eslint/node_modules/is-number-object/README.md deleted file mode 100644 index 5617d7ec6bf981..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-number-object/README.md +++ /dev/null @@ -1,52 +0,0 @@ -# is-number-object [![Version Badge][2]][1] - -[![Build Status][3]][4] -[![dependency status][5]][6] -[![dev dependency status][7]][8] -[![License][license-image]][license-url] -[![Downloads][downloads-image]][downloads-url] - -[![npm badge][11]][1] - -Is this value a JS Number object? This module works cross-realm/iframe, and despite ES6 @@toStringTag. - -## Example - -```js -var isNumber = require('is-number-object'); -var assert = require('assert'); - -assert.notOk(isNumber(undefined)); -assert.notOk(isNumber(null)); -assert.notOk(isNumber(false)); -assert.notOk(isNumber(true)); -assert.notOk(isNumber('foo')); -assert.notOk(isNumber(function () {})); -assert.notOk(isNumber([])); -assert.notOk(isNumber({})); -assert.notOk(isNumber(/a/g)); -assert.notOk(isNumber(new RegExp('a', 'g'))); -assert.notOk(isNumber(new Date())); - -assert.ok(isNumber(42)); -assert.ok(isNumber(NaN)); -assert.ok(isNumber(Infinity)); -assert.ok(isNumber(new Number(42))); -``` - -## Tests -Simply clone the repo, `npm install`, and run `npm test` - -[1]: https://npmjs.org/package/is-number-object -[2]: http://versionbadg.es/inspect-js/is-number-object.svg -[3]: https://travis-ci.org/inspect-js/is-number-object.svg -[4]: https://travis-ci.org/inspect-js/is-number-object -[5]: https://david-dm.org/inspect-js/is-number-object.svg -[6]: https://david-dm.org/inspect-js/is-number-object -[7]: https://david-dm.org/inspect-js/is-number-object/dev-status.svg -[8]: https://david-dm.org/inspect-js/is-number-object#info=devDependencies -[11]: https://nodei.co/npm/is-number-object.png?downloads=true&stars=true -[license-image]: http://img.shields.io/npm/l/is-number-object.svg -[license-url]: LICENSE -[downloads-image]: http://img.shields.io/npm/dm/is-number-object.svg -[downloads-url]: http://npm-stat.com/charts.html?package=is-number-object diff --git a/tools/node_modules/eslint/node_modules/is-number-object/index.js b/tools/node_modules/eslint/node_modules/is-number-object/index.js deleted file mode 100644 index de303abe1aae6c..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-number-object/index.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -var numToStr = Number.prototype.toString; -var tryNumberObject = function tryNumberObject(value) { - try { - numToStr.call(value); - return true; - } catch (e) { - return false; - } -}; -var toStr = Object.prototype.toString; -var numClass = '[object Number]'; -var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; - -module.exports = function isNumberObject(value) { - if (typeof value === 'number') { - return true; - } - if (typeof value !== 'object') { - return false; - } - return hasToStringTag ? tryNumberObject(value) : toStr.call(value) === numClass; -}; diff --git a/tools/node_modules/eslint/node_modules/is-number-object/package.json b/tools/node_modules/eslint/node_modules/is-number-object/package.json deleted file mode 100644 index f6ab725f69a7b5..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-number-object/package.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "name": "is-number-object", - "version": "1.0.4", - "author": "Jordan Harband ", - "funding": { - "url": "https://github.com/sponsors/ljharb" - }, - "description": "Is this value a JS Number object? This module works cross-realm/iframe, and despite ES6 @@toStringTag.", - "license": "MIT", - "main": "index.js", - "scripts": { - "prepublish": "safe-publish-latest", - "pretest": "npm run lint", - "tests-only": "node --harmony --es-staging test", - "test": "npm run tests-only", - "posttest": "npx aud", - "coverage": "covert test/index.js", - "lint": "eslint .", - "eccheck": "eclint check *.js **/*.js > /dev/null", - "version": "auto-changelog && git add CHANGELOG.md", - "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" - }, - "repository": { - "type": "git", - "url": "git://github.com/inspect-js/is-number-object.git" - }, - "keywords": [ - "Number", - "ES6", - "toStringTag", - "@@toStringTag", - "Number object" - ], - "dependencies": {}, - "devDependencies": { - "@ljharb/eslint-config": "^15.0.2", - "auto-changelog": "^1.16.2", - "covert": "^1.1.1", - "eclint": "^2.8.1", - "eslint": "^6.7.2", - "foreach": "^2.0.5", - "has-symbols": "^1.0.1", - "indexof": "^0.0.1", - "is": "^3.3.0", - "safe-publish-latest": "^1.1.4", - "tape": "^4.12.0" - }, - "testling": { - "files": "test/index.js", - "browsers": [ - "iexplore/6.0..latest", - "firefox/3.0..6.0", - "firefox/15.0..latest", - "firefox/nightly", - "chrome/4.0..10.0", - "chrome/20.0..latest", - "chrome/canary", - "opera/10.0..latest", - "opera/next", - "safari/4.0..latest", - "ipad/6.0..latest", - "iphone/6.0..latest", - "android-browser/4.2" - ] - }, - "engines": { - "node": ">= 0.4" - }, - "auto-changelog": { - "output": "CHANGELOG.md", - "template": "keepachangelog", - "unreleased": false, - "commitLimit": false, - "backfillLimit": false - } -} diff --git a/tools/node_modules/eslint/node_modules/is-string/LICENSE b/tools/node_modules/eslint/node_modules/is-string/LICENSE deleted file mode 100644 index b43df444e51828..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-string/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -The MIT License (MIT) - -Copyright (c) 2015 Jordan Harband - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - diff --git a/tools/node_modules/eslint/node_modules/is-string/README.md b/tools/node_modules/eslint/node_modules/is-string/README.md deleted file mode 100644 index 13895e5f490076..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-string/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# is-string [![Version Badge][2]][1] - -[![Build Status][3]][4] -[![dependency status][5]][6] -[![dev dependency status][7]][8] -[![License][license-image]][license-url] -[![Downloads][downloads-image]][downloads-url] - -[![npm badge][11]][1] - -[![browser support][9]][10] - -Is this value a JS String object or primitive? This module works cross-realm/iframe, and despite ES6 @@toStringTag. - -## Example - -```js -var isString = require('is-string'); -var assert = require('assert'); - -assert.notOk(isString(undefined)); -assert.notOk(isString(null)); -assert.notOk(isString(false)); -assert.notOk(isString(true)); -assert.notOk(isString(function () {})); -assert.notOk(isString([])); -assert.notOk(isString({})); -assert.notOk(isString(/a/g)); -assert.notOk(isString(new RegExp('a', 'g'))); -assert.notOk(isString(new Date())); -assert.notOk(isString(42)); -assert.notOk(isString(NaN)); -assert.notOk(isString(Infinity)); -assert.notOk(isString(new Number(42))); - -assert.ok(isString('foo')); -assert.ok(isString(Object('foo'))); -``` - -## Tests -Simply clone the repo, `npm install`, and run `npm test` - -[1]: https://npmjs.org/package/is-string -[2]: http://versionbadg.es/ljharb/is-string.svg -[3]: https://travis-ci.org/ljharb/is-string.svg -[4]: https://travis-ci.org/ljharb/is-string -[5]: https://david-dm.org/ljharb/is-string.svg -[6]: https://david-dm.org/ljharb/is-string -[7]: https://david-dm.org/ljharb/is-string/dev-status.svg -[8]: https://david-dm.org/ljharb/is-string#info=devDependencies -[9]: https://ci.testling.com/ljharb/is-string.png -[10]: https://ci.testling.com/ljharb/is-string -[11]: https://nodei.co/npm/is-string.png?downloads=true&stars=true -[license-image]: http://img.shields.io/npm/l/is-string.svg -[license-url]: LICENSE -[downloads-image]: http://img.shields.io/npm/dm/is-string.svg -[downloads-url]: http://npm-stat.com/charts.html?package=is-string diff --git a/tools/node_modules/eslint/node_modules/is-string/index.js b/tools/node_modules/eslint/node_modules/is-string/index.js deleted file mode 100644 index 95b7050cc68b55..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-string/index.js +++ /dev/null @@ -1,24 +0,0 @@ -'use strict'; - -var strValue = String.prototype.valueOf; -var tryStringObject = function tryStringObject(value) { - try { - strValue.call(value); - return true; - } catch (e) { - return false; - } -}; -var toStr = Object.prototype.toString; -var strClass = '[object String]'; -var hasToStringTag = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol'; - -module.exports = function isString(value) { - if (typeof value === 'string') { - return true; - } - if (typeof value !== 'object') { - return false; - } - return hasToStringTag ? tryStringObject(value) : toStr.call(value) === strClass; -}; diff --git a/tools/node_modules/eslint/node_modules/is-string/package.json b/tools/node_modules/eslint/node_modules/is-string/package.json deleted file mode 100644 index a0870540424604..00000000000000 --- a/tools/node_modules/eslint/node_modules/is-string/package.json +++ /dev/null @@ -1,76 +0,0 @@ -{ - "name": "is-string", - "version": "1.0.5", - "author": "Jordan Harband ", - "funding": { - "url": "https://github.com/sponsors/ljharb" - }, - "description": "Is this value a JS String object or primitive? This module works cross-realm/iframe, and despite ES6 @@toStringTag.", - "license": "MIT", - "main": "index.js", - "scripts": { - "prepublish": "safe-publish-latest", - "pretest": "npm run lint", - "tests-only": "node --harmony --es-staging test", - "test": "npm run tests-only", - "posttest": "npx aud", - "coverage": "covert test/index.js", - "lint": "eslint .", - "eccheck": "eclint check *.js **/*.js > /dev/null", - "version": "auto-changelog && git add CHANGELOG.md", - "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" - }, - "repository": { - "type": "git", - "url": "git://github.com/ljharb/is-string.git" - }, - "keywords": [ - "String", - "string", - "ES6", - "toStringTag", - "@@toStringTag", - "String object" - ], - "dependencies": {}, - "devDependencies": { - "@ljharb/eslint-config": "^15.0.2", - "auto-changelog": "^1.16.2", - "covert": "^1.1.1", - "eclint": "^2.8.1", - "eslint": "^6.7.2", - "foreach": "^2.0.5", - "indexof": "^0.0.1", - "is": "^3.3.0", - "safe-publish-latest": "^1.1.4", - "tape": "^4.12.0" - }, - "testling": { - "files": "test/index.js", - "browsers": [ - "iexplore/6.0..latest", - "firefox/3.0..6.0", - "firefox/15.0..latest", - "firefox/nightly", - "chrome/4.0..10.0", - "chrome/20.0..latest", - "chrome/canary", - "opera/10.0..latest", - "opera/next", - "safari/4.0..latest", - "ipad/6.0..latest", - "iphone/6.0..latest", - "android-browser/4.2" - ] - }, - "engines": { - "node": ">= 0.4" - }, - "auto-changelog": { - "output": "CHANGELOG.md", - "template": "keepachangelog", - "unreleased": false, - "commitLimit": false, - "backfillLimit": false - } -} diff --git a/tools/node_modules/eslint/node_modules/table/README.md b/tools/node_modules/eslint/node_modules/table/README.md index 22a79962a1a2ee..f34656c5021aa7 100644 --- a/tools/node_modules/eslint/node_modules/table/README.md +++ b/tools/node_modules/eslint/node_modules/table/README.md @@ -14,6 +14,7 @@ * [Cell Content Alignment](#table-usage-cell-content-alignment) * [Column Width](#table-usage-column-width) * [Custom Border](#table-usage-custom-border) + * [Draw Vertical Line](#table-usage-draw-vertical-line) * [Draw Horizontal Line](#table-usage-draw-horizontal-line) * [Single Line Mode](#table-usage-single-line-mode) * [Padding Cell Content](#table-usage-padding-cell-content) @@ -292,6 +293,57 @@ console.log(output); └────┴────┴────┘ ``` + +### Draw Vertical Line + +`{function} config.drawVerticalLine` property is a function that is called for every non-content column in the table. The result of the function `{boolean}` determines whether a border is drawn. + +```js +let data, + output, + options; + +data = [ + ['0A', '0B', '0C'], + ['1A', '1B', '1C'], + ['2A', '2B', '2C'], + ['3A', '3B', '3C'], + ['4A', '4B', '4C'] +]; + +options = { + /** + * @typedef {function} drawVerticalLine + * @param {number} index + * @param {number} size + * @return {boolean} + */ + drawVerticalLine: (index, size) => { + return index === 0 || index === size; + } +}; + +output = table(data, options); + +console.log(output); + +``` + +``` +╔════════════╗ +║ 0A 0B 0C ║ +╟────────────╢ +║ 1A 1B 1C ║ +╟────────────╢ +║ 2A 2B 2C ║ +╟────────────╢ +║ 3A 3B 3C ║ +╟────────────╢ +║ 4A 4B 4C ║ +╚════════════╝ + +``` + ### Draw Horizontal Line @@ -647,7 +699,7 @@ console.log(output); ║ t amet, consectetur ║ ║ adipiscing elit. Pha ║ ║ sellus pulvinar nibh ║ -║ sed mauris conva... ║ +║ sed mauris convall… ║ ╚══════════════════════╝ ``` diff --git a/tools/node_modules/eslint/node_modules/table/dist/alignString.js b/tools/node_modules/eslint/node_modules/table/dist/alignString.js index 09412798ec27f0..c3ff7f3d631a7a 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/alignString.js +++ b/tools/node_modules/eslint/node_modules/table/dist/alignString.js @@ -1,107 +1,47 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _isNumberObject = _interopRequireDefault(require("is-number-object")); - -var _isString = _interopRequireDefault(require("is-string")); - -var _stringWidth = _interopRequireDefault(require("string-width")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -const alignments = ['left', 'right', 'center']; -/** - * @param {string} subject - * @param {number} width - * @returns {string} - */ - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const string_width_1 = __importDefault(require("string-width")); const alignLeft = (subject, width) => { - return subject + ' '.repeat(width); + return subject + ' '.repeat(width); }; -/** - * @param {string} subject - * @param {number} width - * @returns {string} - */ - - const alignRight = (subject, width) => { - return ' '.repeat(width) + subject; + return ' '.repeat(width) + subject; }; -/** - * @param {string} subject - * @param {number} width - * @returns {string} - */ - - const alignCenter = (subject, width) => { - let halfWidth; - halfWidth = width / 2; - - if (width % 2 === 0) { - return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth); - } else { - halfWidth = Math.floor(halfWidth); - return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1); - } + let halfWidth; + halfWidth = width / 2; + if (width % 2 === 0) { + return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth); + } + else { + halfWidth = Math.floor(halfWidth); + return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1); + } }; /** * Pads a string to the left and/or right to position the subject * text in a desired alignment within a container. - * - * @param {string} subject - * @param {number} containerWidth - * @param {string} alignment One of the valid options (left, right, center). - * @returns {string} */ - - -const alignString = (subject, containerWidth, alignment) => { - if (!(0, _isString.default)(subject)) { - throw new TypeError('Subject parameter value must be a string.'); - } - - if (!(0, _isNumberObject.default)(containerWidth)) { - throw new TypeError('Container width parameter value must be a number.'); - } - - const subjectWidth = (0, _stringWidth.default)(subject); - - if (subjectWidth > containerWidth) { - // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject); - throw new Error('Subject parameter value width cannot be greater than the container width.'); - } - - if (!(0, _isString.default)(alignment)) { - throw new TypeError('Alignment parameter value must be a string.'); - } - - if (!alignments.includes(alignment)) { - throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).'); - } - - if (subjectWidth === 0) { - return ' '.repeat(containerWidth); - } - - const availableWidth = containerWidth - subjectWidth; - - if (alignment === 'left') { - return alignLeft(subject, availableWidth); - } - - if (alignment === 'right') { - return alignRight(subject, availableWidth); - } - - return alignCenter(subject, availableWidth); +exports.default = (subject, containerWidth, alignment) => { + if (typeof subject !== 'string') { + throw new TypeError('Subject parameter value must be a string.'); + } + const subjectWidth = string_width_1.default(subject); + if (subjectWidth > containerWidth) { + throw new Error('Subject parameter value width cannot be greater than the container width.'); + } + if (subjectWidth === 0) { + return ' '.repeat(containerWidth); + } + const availableWidth = containerWidth - subjectWidth; + if (alignment === 'left') { + return alignLeft(subject, availableWidth); + } + if (alignment === 'right') { + return alignRight(subject, availableWidth); + } + return alignCenter(subject, availableWidth); }; - -var _default = alignString; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/alignString.js.flow b/tools/node_modules/eslint/node_modules/table/dist/alignString.js.flow deleted file mode 100644 index a3739bc2748df5..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/alignString.js.flow +++ /dev/null @@ -1,97 +0,0 @@ -import isNumber from 'is-number-object'; -import isString from 'is-string'; -import stringWidth from 'string-width'; - -const alignments = [ - 'left', - 'right', - 'center', -]; - -/** - * @param {string} subject - * @param {number} width - * @returns {string} - */ -const alignLeft = (subject, width) => { - return subject + ' '.repeat(width); -}; - -/** - * @param {string} subject - * @param {number} width - * @returns {string} - */ -const alignRight = (subject, width) => { - return ' '.repeat(width) + subject; -}; - -/** - * @param {string} subject - * @param {number} width - * @returns {string} - */ -const alignCenter = (subject, width) => { - let halfWidth; - - halfWidth = width / 2; - - if (width % 2 === 0) { - return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth); - } else { - halfWidth = Math.floor(halfWidth); - - return ' '.repeat(halfWidth) + subject + ' '.repeat(halfWidth + 1); - } -}; - -/** - * Pads a string to the left and/or right to position the subject - * text in a desired alignment within a container. - * - * @param {string} subject - * @param {number} containerWidth - * @param {string} alignment One of the valid options (left, right, center). - * @returns {string} - */ -export default (subject, containerWidth, alignment) => { - if (!isString(subject)) { - throw new TypeError('Subject parameter value must be a string.'); - } - - if (!isNumber(containerWidth)) { - throw new TypeError('Container width parameter value must be a number.'); - } - - const subjectWidth = stringWidth(subject); - - if (subjectWidth > containerWidth) { - // console.log('subjectWidth', subjectWidth, 'containerWidth', containerWidth, 'subject', subject); - - throw new Error('Subject parameter value width cannot be greater than the container width.'); - } - - if (!isString(alignment)) { - throw new TypeError('Alignment parameter value must be a string.'); - } - - if (!alignments.includes(alignment)) { - throw new Error('Alignment parameter value must be a known alignment parameter value (left, right, center).'); - } - - if (subjectWidth === 0) { - return ' '.repeat(containerWidth); - } - - const availableWidth = containerWidth - subjectWidth; - - if (alignment === 'left') { - return alignLeft(subject, availableWidth); - } - - if (alignment === 'right') { - return alignRight(subject, availableWidth); - } - - return alignCenter(subject, availableWidth); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/alignTableData.js b/tools/node_modules/eslint/node_modules/table/dist/alignTableData.js index fc60afe85c1e43..884a26ba5f58dd 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/alignTableData.js +++ b/tools/node_modules/eslint/node_modules/table/dist/alignTableData.js @@ -1,34 +1,20 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _stringWidth = _interopRequireDefault(require("string-width")); - -var _alignString = _interopRequireDefault(require("./alignString")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * @param {table~row[]} rows - * @param {object} config - * @returns {table~row[]} - */ -const alignTableData = (rows, config) => { - return rows.map(cells => { - return cells.map((value, index1) => { - const column = config.columns[index1]; - - if ((0, _stringWidth.default)(value) === column.width) { - return value; - } else { - return (0, _alignString.default)(value, column.width, column.alignment); - } +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const string_width_1 = __importDefault(require("string-width")); +const alignString_1 = __importDefault(require("./alignString")); +exports.default = (rows, config) => { + return rows.map((row) => { + return row.map((cell, index) => { + const column = config.columns[index]; + if (string_width_1.default(cell) === column.width) { + return cell; + } + else { + return alignString_1.default(cell, column.width, column.alignment); + } + }); }); - }); }; - -var _default = alignTableData; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/alignTableData.js.flow b/tools/node_modules/eslint/node_modules/table/dist/alignTableData.js.flow deleted file mode 100644 index c82c31e261b70b..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/alignTableData.js.flow +++ /dev/null @@ -1,21 +0,0 @@ -import stringWidth from 'string-width'; -import alignString from './alignString'; - -/** - * @param {table~row[]} rows - * @param {object} config - * @returns {table~row[]} - */ -export default (rows, config) => { - return rows.map((cells) => { - return cells.map((value, index1) => { - const column = config.columns[index1]; - - if (stringWidth(value) === column.width) { - return value; - } else { - return alignString(value, column.width, column.alignment); - } - }); - }); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateCellHeight.js b/tools/node_modules/eslint/node_modules/table/dist/calculateCellHeight.js index 8f7ed9fc8b0e2b..fbe9aa9cf424c6 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateCellHeight.js +++ b/tools/node_modules/eslint/node_modules/table/dist/calculateCellHeight.js @@ -1,37 +1,12 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _isString = _interopRequireDefault(require("is-string")); - -var _wrapCell = _interopRequireDefault(require("./wrapCell")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * @param {string} value - * @param {number} columnWidth - * @param {boolean} useWrapWord - * @returns {number} - */ -const calculateCellHeight = (value, columnWidth, useWrapWord = false) => { - if (!(0, _isString.default)(value)) { - throw new TypeError('Value must be a string.'); - } - - if (!Number.isInteger(columnWidth)) { - throw new TypeError('Column width must be an integer.'); - } - - if (columnWidth < 1) { - throw new Error('Column width must be greater than 0.'); - } - - return (0, _wrapCell.default)(value, columnWidth, useWrapWord).length; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const wrapCell_1 = __importDefault(require("./wrapCell")); +exports.default = (value, columnWidth, useWrapWord = false) => { + if (typeof value !== 'string') { + throw new TypeError('Value must be a string.'); + } + return wrapCell_1.default(value, columnWidth, useWrapWord).length; }; - -var _default = calculateCellHeight; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateCellHeight.js.flow b/tools/node_modules/eslint/node_modules/table/dist/calculateCellHeight.js.flow deleted file mode 100644 index 172604390b2ecb..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateCellHeight.js.flow +++ /dev/null @@ -1,24 +0,0 @@ -import isString from 'is-string'; -import wrapCell from './wrapCell'; - -/** - * @param {string} value - * @param {number} columnWidth - * @param {boolean} useWrapWord - * @returns {number} - */ -export default (value, columnWidth, useWrapWord = false) => { - if (!isString(value)) { - throw new TypeError('Value must be a string.'); - } - - if (!Number.isInteger(columnWidth)) { - throw new TypeError('Column width must be an integer.'); - } - - if (columnWidth < 1) { - throw new Error('Column width must be greater than 0.'); - } - - return wrapCell(value, columnWidth, useWrapWord).length; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateCellWidthIndex.js b/tools/node_modules/eslint/node_modules/table/dist/calculateCellWidthIndex.js index c46fb861ddf123..d267e7906d1475 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateCellWidthIndex.js +++ b/tools/node_modules/eslint/node_modules/table/dist/calculateCellWidthIndex.js @@ -1,27 +1,16 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _stringWidth = _interopRequireDefault(require("string-width")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const string_width_1 = __importDefault(require("string-width")); /** * Calculates width of each cell contents. - * - * @param {string[]} cells - * @returns {number[]} */ -const calculateCellWidthIndex = cells => { - return cells.map(value => { - return Math.max(...value.split('\n').map(line => { - return (0, _stringWidth.default)(line); - })); - }); +exports.default = (cells) => { + return cells.map((value) => { + return Math.max(...value.split('\n').map((line) => { + return string_width_1.default(line); + })); + }); }; - -var _default = calculateCellWidthIndex; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateCellWidthIndex.js.flow b/tools/node_modules/eslint/node_modules/table/dist/calculateCellWidthIndex.js.flow deleted file mode 100644 index e2539539a5d15d..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateCellWidthIndex.js.flow +++ /dev/null @@ -1,17 +0,0 @@ -import stringWidth from 'string-width'; - -/** - * Calculates width of each cell contents. - * - * @param {string[]} cells - * @returns {number[]} - */ -export default (cells) => { - return cells.map((value) => { - return Math.max( - ...value.split('\n').map((line) => { - return stringWidth(line); - }), - ); - }); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateMaximumColumnWidthIndex.js b/tools/node_modules/eslint/node_modules/table/dist/calculateMaximumColumnWidthIndex.js index 057d0a506d64da..3312f451d876ea 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateMaximumColumnWidthIndex.js +++ b/tools/node_modules/eslint/node_modules/table/dist/calculateMaximumColumnWidthIndex.js @@ -1,36 +1,24 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex")); /** * Produces an array of values that describe the largest value length (width) in every column. - * - * @param {Array[]} rows - * @returns {number[]} */ -const calculateMaximumColumnWidthIndex = rows => { - if (!rows[0]) { - throw new Error('Dataset must have at least one row.'); - } - - const columns = new Array(rows[0].length).fill(0); - rows.forEach(row => { - const columnWidthIndex = (0, _calculateCellWidthIndex.default)(row); - columnWidthIndex.forEach((valueWidth, index0) => { - if (columns[index0] < valueWidth) { - columns[index0] = valueWidth; - } +exports.default = (rows) => { + if (!rows[0]) { + throw new Error('Dataset must have at least one row.'); + } + const columns = new Array(rows[0].length).fill(0); + rows.forEach((row) => { + const columnWidthIndex = calculateCellWidthIndex_1.default(row); + columnWidthIndex.forEach((valueWidth, index0) => { + if (columns[index0] < valueWidth) { + columns[index0] = valueWidth; + } + }); }); - }); - return columns; + return columns; }; - -var _default = calculateMaximumColumnWidthIndex; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateMaximumColumnWidthIndex.js.flow b/tools/node_modules/eslint/node_modules/table/dist/calculateMaximumColumnWidthIndex.js.flow deleted file mode 100644 index 5c8c10981cc63b..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateMaximumColumnWidthIndex.js.flow +++ /dev/null @@ -1,27 +0,0 @@ -import calculateCellWidthIndex from './calculateCellWidthIndex'; - -/** - * Produces an array of values that describe the largest value length (width) in every column. - * - * @param {Array[]} rows - * @returns {number[]} - */ -export default (rows) => { - if (!rows[0]) { - throw new Error('Dataset must have at least one row.'); - } - - const columns = new Array(rows[0].length).fill(0); - - rows.forEach((row) => { - const columnWidthIndex = calculateCellWidthIndex(row); - - columnWidthIndex.forEach((valueWidth, index0) => { - if (columns[index0] < valueWidth) { - columns[index0] = valueWidth; - } - }); - }); - - return columns; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateRowHeightIndex.js b/tools/node_modules/eslint/node_modules/table/dist/calculateRowHeightIndex.js index b8175d65626cde..3db65542cd9bfe 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateRowHeightIndex.js +++ b/tools/node_modules/eslint/node_modules/table/dist/calculateRowHeightIndex.js @@ -1,45 +1,21 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _isBooleanObject = _interopRequireDefault(require("is-boolean-object")); - -var _isNumberObject = _interopRequireDefault(require("is-number-object")); - -var _calculateCellHeight = _interopRequireDefault(require("./calculateCellHeight")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const calculateCellHeight_1 = __importDefault(require("./calculateCellHeight")); /** * Calculates the vertical row span index. - * - * @param {Array[]} rows - * @param {object} config - * @returns {number[]} */ -const calculateRowHeightIndex = (rows, config) => { - const tableWidth = rows[0].length; - const rowSpanIndex = []; - rows.forEach(cells => { - const cellHeightIndex = new Array(tableWidth).fill(1); - cells.forEach((value, index1) => { - if (!(0, _isNumberObject.default)(config.columns[index1].width)) { - throw new TypeError('column[index].width must be a number.'); - } - - if (!(0, _isBooleanObject.default)(config.columns[index1].wrapWord)) { - throw new TypeError('column[index].wrapWord must be a boolean.'); - } - - cellHeightIndex[index1] = (0, _calculateCellHeight.default)(value, config.columns[index1].width, config.columns[index1].wrapWord); +exports.default = (rows, config) => { + const tableWidth = rows[0].length; + const rowSpanIndex = []; + rows.forEach((cells) => { + const cellHeightIndex = new Array(tableWidth).fill(1); + cells.forEach((value, index1) => { + cellHeightIndex[index1] = calculateCellHeight_1.default(value, config.columns[index1].width, config.columns[index1].wrapWord); + }); + rowSpanIndex.push(Math.max(...cellHeightIndex)); }); - rowSpanIndex.push(Math.max(...cellHeightIndex)); - }); - return rowSpanIndex; + return rowSpanIndex; }; - -var _default = calculateRowHeightIndex; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/calculateRowHeightIndex.js.flow b/tools/node_modules/eslint/node_modules/table/dist/calculateRowHeightIndex.js.flow deleted file mode 100644 index 04c61b3ea040a3..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/calculateRowHeightIndex.js.flow +++ /dev/null @@ -1,36 +0,0 @@ -import isBoolean from 'is-boolean-object'; -import isNumber from 'is-number-object'; -import calculateCellHeight from './calculateCellHeight'; - -/** - * Calculates the vertical row span index. - * - * @param {Array[]} rows - * @param {object} config - * @returns {number[]} - */ -export default (rows, config) => { - const tableWidth = rows[0].length; - - const rowSpanIndex = []; - - rows.forEach((cells) => { - const cellHeightIndex = new Array(tableWidth).fill(1); - - cells.forEach((value, index1) => { - if (!isNumber(config.columns[index1].width)) { - throw new TypeError('column[index].width must be a number.'); - } - - if (!isBoolean(config.columns[index1].wrapWord)) { - throw new TypeError('column[index].wrapWord must be a boolean.'); - } - - cellHeightIndex[index1] = calculateCellHeight(value, config.columns[index1].width, config.columns[index1].wrapWord); - }); - - rowSpanIndex.push(Math.max(...cellHeightIndex)); - }); - - return rowSpanIndex; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/createStream.js b/tools/node_modules/eslint/node_modules/table/dist/createStream.js index 731f12035d0511..ffe611f8fb2dc3 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/createStream.js +++ b/tools/node_modules/eslint/node_modules/table/dist/createStream.js @@ -1,124 +1,73 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _alignTableData = _interopRequireDefault(require("./alignTableData")); - -var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex")); - -var _drawBorder = require("./drawBorder"); - -var _drawRow = _interopRequireDefault(require("./drawRow")); - -var _makeStreamConfig = _interopRequireDefault(require("./makeStreamConfig")); - -var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex")); - -var _padTableData = _interopRequireDefault(require("./padTableData")); - -var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData")); - -var _truncateTableData = _interopRequireDefault(require("./truncateTableData")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * @param {Array} data - * @param {object} config - * @returns {Array} - */ +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const alignTableData_1 = __importDefault(require("./alignTableData")); +const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex")); +const drawBorder_1 = require("./drawBorder"); +const drawRow_1 = __importDefault(require("./drawRow")); +const makeStreamConfig_1 = __importDefault(require("./makeStreamConfig")); +const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex")); +const padTableData_1 = __importDefault(require("./padTableData")); +const stringifyTableData_1 = __importDefault(require("./stringifyTableData")); +const truncateTableData_1 = __importDefault(require("./truncateTableData")); const prepareData = (data, config) => { - let rows; - rows = (0, _stringifyTableData.default)(data); - rows = (0, _truncateTableData.default)(data, config); - const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config); - rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config); - rows = (0, _alignTableData.default)(rows, config); - rows = (0, _padTableData.default)(rows, config); - return rows; + let rows = stringifyTableData_1.default(data); + rows = truncateTableData_1.default(rows, config); + const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config); + rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config); + rows = alignTableData_1.default(rows, config); + rows = padTableData_1.default(rows, config); + return rows; }; -/** - * @param {string[]} row - * @param {number[]} columnWidthIndex - * @param {object} config - * @returns {undefined} - */ - - const create = (row, columnWidthIndex, config) => { - const rows = prepareData([row], config); - const body = rows.map(literalRow => { - return (0, _drawRow.default)(literalRow, config.border); - }).join(''); - let output; - output = ''; - output += (0, _drawBorder.drawBorderTop)(columnWidthIndex, config.border); - output += body; - output += (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config.border); - output = output.trimEnd(); - process.stdout.write(output); + const rows = prepareData([row], config); + const body = rows.map((literalRow) => { + return drawRow_1.default(literalRow, config); + }).join(''); + let output; + output = ''; + output += drawBorder_1.drawBorderTop(columnWidthIndex, config); + output += body; + output += drawBorder_1.drawBorderBottom(columnWidthIndex, config); + output = output.trimEnd(); + process.stdout.write(output); }; -/** - * @param {string[]} row - * @param {number[]} columnWidthIndex - * @param {object} config - * @returns {undefined} - */ - - const append = (row, columnWidthIndex, config) => { - const rows = prepareData([row], config); - const body = rows.map(literalRow => { - return (0, _drawRow.default)(literalRow, config.border); - }).join(''); - let output = ''; - const bottom = (0, _drawBorder.drawBorderBottom)(columnWidthIndex, config.border); - - if (bottom !== '\n') { - output = '\r\u001B[K'; - } - - output += (0, _drawBorder.drawBorderJoin)(columnWidthIndex, config.border); - output += body; - output += bottom; - output = output.trimEnd(); - process.stdout.write(output); -}; -/** - * @param {object} userConfig - * @returns {object} - */ - - -const createStream = (userConfig = {}) => { - const config = (0, _makeStreamConfig.default)(userConfig); - const columnWidthIndex = Object.values(config.columns).map(column => { - return column.width + column.paddingLeft + column.paddingRight; - }); - let empty; - empty = true; - return { - /** - * @param {string[]} row - * @returns {undefined} - */ - write: row => { - if (row.length !== config.columnCount) { - throw new Error('Row cell count does not match the config.columnCount.'); - } - - if (empty) { - empty = false; - return create(row, columnWidthIndex, config); - } else { - return append(row, columnWidthIndex, config); - } + const rows = prepareData([row], config); + const body = rows.map((literalRow) => { + return drawRow_1.default(literalRow, config); + }).join(''); + let output = ''; + const bottom = drawBorder_1.drawBorderBottom(columnWidthIndex, config); + if (bottom !== '\n') { + output = '\r\u001B[K'; } - }; + output += drawBorder_1.drawBorderJoin(columnWidthIndex, config); + output += body; + output += bottom; + output = output.trimEnd(); + process.stdout.write(output); +}; +exports.default = (userConfig) => { + const config = makeStreamConfig_1.default(userConfig); + const columnWidthIndex = Object.values(config.columns).map((column) => { + return column.width + column.paddingLeft + column.paddingRight; + }); + let empty = true; + return { + write: (row) => { + if (row.length !== config.columnCount) { + throw new Error('Row cell count does not match the config.columnCount.'); + } + if (empty) { + empty = false; + create(row, columnWidthIndex, config); + } + else { + append(row, columnWidthIndex, config); + } + }, + }; }; - -var _default = createStream; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/createStream.js.flow b/tools/node_modules/eslint/node_modules/table/dist/createStream.js.flow deleted file mode 100644 index 747ba6a7595bd4..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/createStream.js.flow +++ /dev/null @@ -1,125 +0,0 @@ -import alignTableData from './alignTableData'; -import calculateRowHeightIndex from './calculateRowHeightIndex'; -import { - drawBorderBottom, - drawBorderJoin, - drawBorderTop, -} from './drawBorder'; -import drawRow from './drawRow'; -import makeStreamConfig from './makeStreamConfig'; -import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex'; -import padTableData from './padTableData'; -import stringifyTableData from './stringifyTableData'; -import truncateTableData from './truncateTableData'; - -/** - * @param {Array} data - * @param {object} config - * @returns {Array} - */ -const prepareData = (data, config) => { - let rows; - - rows = stringifyTableData(data); - - rows = truncateTableData(data, config); - - const rowHeightIndex = calculateRowHeightIndex(rows, config); - - rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config); - rows = alignTableData(rows, config); - rows = padTableData(rows, config); - - return rows; -}; - -/** - * @param {string[]} row - * @param {number[]} columnWidthIndex - * @param {object} config - * @returns {undefined} - */ -const create = (row, columnWidthIndex, config) => { - const rows = prepareData([row], config); - - const body = rows.map((literalRow) => { - return drawRow(literalRow, config.border); - }).join(''); - - let output; - - output = ''; - - output += drawBorderTop(columnWidthIndex, config.border); - output += body; - output += drawBorderBottom(columnWidthIndex, config.border); - - output = output.trimEnd(); - - process.stdout.write(output); -}; - -/** - * @param {string[]} row - * @param {number[]} columnWidthIndex - * @param {object} config - * @returns {undefined} - */ -const append = (row, columnWidthIndex, config) => { - const rows = prepareData([row], config); - - const body = rows.map((literalRow) => { - return drawRow(literalRow, config.border); - }).join(''); - - let output = ''; - const bottom = drawBorderBottom(columnWidthIndex, config.border); - - if (bottom !== '\n') { - output = '\r\u001B[K'; - } - - output += drawBorderJoin(columnWidthIndex, config.border); - output += body; - output += bottom; - - output = output.trimEnd(); - - process.stdout.write(output); -}; - -/** - * @param {object} userConfig - * @returns {object} - */ -export default (userConfig = {}) => { - const config = makeStreamConfig(userConfig); - - const columnWidthIndex = Object.values(config.columns).map((column) => { - return column.width + column.paddingLeft + column.paddingRight; - }); - - let empty; - - empty = true; - - return { - /** - * @param {string[]} row - * @returns {undefined} - */ - write: (row) => { - if (row.length !== config.columnCount) { - throw new Error('Row cell count does not match the config.columnCount.'); - } - - if (empty) { - empty = false; - - return create(row, columnWidthIndex, config); - } else { - return append(row, columnWidthIndex, config); - } - }, - }; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/drawBorder.js b/tools/node_modules/eslint/node_modules/table/dist/drawBorder.js index 965e8539d42749..7620eba3dd5cdf 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/drawBorder.js +++ b/tools/node_modules/eslint/node_modules/table/dist/drawBorder.js @@ -1,109 +1,54 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); exports.drawBorderTop = exports.drawBorderJoin = exports.drawBorderBottom = exports.drawBorder = void 0; - -/** - * @typedef drawBorder~parts - * @property {string} left - * @property {string} right - * @property {string} body - * @property {string} join - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorder~parts} parts - * @returns {string} - */ -const drawBorder = (columnSizeIndex, parts) => { - const columns = columnSizeIndex.map(size => { - return parts.body.repeat(size); - }).join(parts.join); - return parts.left + columns + parts.right + '\n'; +const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent")); +const drawBorder = (columnSizeIndex, config) => { + const columns = columnSizeIndex.map((size) => { + return config.separator.body.repeat(size); + }); + return drawHorizontalContent_1.default(columns, config); }; -/** - * @typedef drawBorderTop~parts - * @property {string} topLeft - * @property {string} topRight - * @property {string} topBody - * @property {string} topJoin - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorderTop~parts} parts - * @returns {string} - */ - - exports.drawBorder = drawBorder; - -const drawBorderTop = (columnSizeIndex, parts) => { - const border = drawBorder(columnSizeIndex, { - body: parts.topBody, - join: parts.topJoin, - left: parts.topLeft, - right: parts.topRight - }); - - if (border === '\n') { - return ''; - } - - return border; +const drawBorderTop = (columnSizeIndex, config) => { + const result = drawBorder(columnSizeIndex, { + ...config, + separator: { + body: config.border.topBody, + join: config.border.topJoin, + left: config.border.topLeft, + right: config.border.topRight, + }, + }); + if (result === '\n') { + return ''; + } + return result; }; -/** - * @typedef drawBorderJoin~parts - * @property {string} joinLeft - * @property {string} joinRight - * @property {string} joinBody - * @property {string} joinJoin - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorderJoin~parts} parts - * @returns {string} - */ - - exports.drawBorderTop = drawBorderTop; - -const drawBorderJoin = (columnSizeIndex, parts) => { - return drawBorder(columnSizeIndex, { - body: parts.joinBody, - join: parts.joinJoin, - left: parts.joinLeft, - right: parts.joinRight - }); +const drawBorderJoin = (columnSizeIndex, config) => { + return drawBorder(columnSizeIndex, { + ...config, + separator: { + body: config.border.joinBody, + join: config.border.joinJoin, + left: config.border.joinLeft, + right: config.border.joinRight, + }, + }); }; -/** - * @typedef drawBorderBottom~parts - * @property {string} topLeft - * @property {string} topRight - * @property {string} topBody - * @property {string} topJoin - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorderBottom~parts} parts - * @returns {string} - */ - - exports.drawBorderJoin = drawBorderJoin; - -const drawBorderBottom = (columnSizeIndex, parts) => { - return drawBorder(columnSizeIndex, { - body: parts.bottomBody, - join: parts.bottomJoin, - left: parts.bottomLeft, - right: parts.bottomRight - }); +const drawBorderBottom = (columnSizeIndex, config) => { + return drawBorder(columnSizeIndex, { + ...config, + separator: { + body: config.border.bottomBody, + join: config.border.bottomJoin, + left: config.border.bottomLeft, + right: config.border.bottomRight, + }, + }); }; - -exports.drawBorderBottom = drawBorderBottom; \ No newline at end of file +exports.drawBorderBottom = drawBorderBottom; diff --git a/tools/node_modules/eslint/node_modules/table/dist/drawBorder.js.flow b/tools/node_modules/eslint/node_modules/table/dist/drawBorder.js.flow deleted file mode 100644 index 85de2475e8b294..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/drawBorder.js.flow +++ /dev/null @@ -1,101 +0,0 @@ -/** - * @typedef drawBorder~parts - * @property {string} left - * @property {string} right - * @property {string} body - * @property {string} join - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorder~parts} parts - * @returns {string} - */ -const drawBorder = (columnSizeIndex, parts) => { - const columns = columnSizeIndex - .map((size) => { - return parts.body.repeat(size); - }) - .join(parts.join); - - return parts.left + columns + parts.right + '\n'; -}; - -/** - * @typedef drawBorderTop~parts - * @property {string} topLeft - * @property {string} topRight - * @property {string} topBody - * @property {string} topJoin - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorderTop~parts} parts - * @returns {string} - */ -const drawBorderTop = (columnSizeIndex, parts) => { - const border = drawBorder(columnSizeIndex, { - body: parts.topBody, - join: parts.topJoin, - left: parts.topLeft, - right: parts.topRight, - }); - - if (border === '\n') { - return ''; - } - - return border; -}; - -/** - * @typedef drawBorderJoin~parts - * @property {string} joinLeft - * @property {string} joinRight - * @property {string} joinBody - * @property {string} joinJoin - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorderJoin~parts} parts - * @returns {string} - */ -const drawBorderJoin = (columnSizeIndex, parts) => { - return drawBorder(columnSizeIndex, { - body: parts.joinBody, - join: parts.joinJoin, - left: parts.joinLeft, - right: parts.joinRight, - }); -}; - -/** - * @typedef drawBorderBottom~parts - * @property {string} topLeft - * @property {string} topRight - * @property {string} topBody - * @property {string} topJoin - */ - -/** - * @param {number[]} columnSizeIndex - * @param {drawBorderBottom~parts} parts - * @returns {string} - */ -const drawBorderBottom = (columnSizeIndex, parts) => { - return drawBorder(columnSizeIndex, { - body: parts.bottomBody, - join: parts.bottomJoin, - left: parts.bottomLeft, - right: parts.bottomRight, - }); -}; - -export { - drawBorder, - drawBorderBottom, - drawBorderJoin, - drawBorderTop, -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/drawHorizontalContent.js b/tools/node_modules/eslint/node_modules/table/dist/drawHorizontalContent.js new file mode 100644 index 00000000000000..ceee448495f579 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/table/dist/drawHorizontalContent.js @@ -0,0 +1,18 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +function drawHorizontalContent(contents, config) { + const { separator, drawVerticalLine } = config; + const contentSize = contents.length; + const result = []; + result.push(drawVerticalLine(0, contentSize) ? separator.left : ''); + contents.forEach((content, index) => { + result.push(content); + // Only append the join separator if it is not the last content + if (index + 1 < contentSize) { + result.push(drawVerticalLine(index + 1, contentSize) ? separator.join : ''); + } + }); + result.push(drawVerticalLine(contentSize, contentSize) ? separator.right : ''); + return result.join('') + '\n'; +} +exports.default = drawHorizontalContent; diff --git a/tools/node_modules/eslint/node_modules/table/dist/drawRow.js b/tools/node_modules/eslint/node_modules/table/dist/drawRow.js index 432f5bce1f9cdd..c03fb780b1174e 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/drawRow.js +++ b/tools/node_modules/eslint/node_modules/table/dist/drawRow.js @@ -1,25 +1,16 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -/** - * @typedef {object} drawRow~border - * @property {string} bodyLeft - * @property {string} bodyRight - * @property {string} bodyJoin - */ - -/** - * @param {number[]} columns - * @param {drawRow~border} border - * @returns {string} - */ -const drawRow = (columns, border) => { - return border.bodyLeft + columns.join(border.bodyJoin) + border.bodyRight + '\n'; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const drawHorizontalContent_1 = __importDefault(require("./drawHorizontalContent")); +exports.default = (row, config) => { + return drawHorizontalContent_1.default(row, { + ...config, + separator: { + join: config.border.bodyJoin, + left: config.border.bodyLeft, + right: config.border.bodyRight, + }, + }); }; - -var _default = drawRow; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/drawRow.js.flow b/tools/node_modules/eslint/node_modules/table/dist/drawRow.js.flow deleted file mode 100644 index 978eab2de19941..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/drawRow.js.flow +++ /dev/null @@ -1,15 +0,0 @@ -/** - * @typedef {object} drawRow~border - * @property {string} bodyLeft - * @property {string} bodyRight - * @property {string} bodyJoin - */ - -/** - * @param {number[]} columns - * @param {drawRow~border} border - * @returns {string} - */ -export default (columns, border) => { - return border.bodyLeft + columns.join(border.bodyJoin) + border.bodyRight + '\n'; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/drawTable.js b/tools/node_modules/eslint/node_modules/table/dist/drawTable.js index 4c49d0fff50de8..a7e10193d62d45 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/drawTable.js +++ b/tools/node_modules/eslint/node_modules/table/dist/drawTable.js @@ -1,58 +1,48 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _drawBorder = require("./drawBorder"); - -var _drawRow = _interopRequireDefault(require("./drawRow")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const drawBorder_1 = require("./drawBorder"); +const drawRow_1 = __importDefault(require("./drawRow")); /** - * @param {Array} rows - * @param {object} border - * @param {Array} columnSizeIndex - * @param {Array} rowSpanIndex - * @param {Function} drawHorizontalLine - * @param {boolean} singleLine - * @returns {string} + * Group the array into sub-arrays by sizes. + * + * @example + * chunkBySizes(['a', 'b', 'c', 'd', 'e'], [2, 1, 2]) = [ ['a', 'b'], ['c'], ['d', 'e'] ] */ -const drawTable = (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine, singleLine) => { - let output; - let realRowIndex; - let rowHeight; - const rowCount = rows.length; - realRowIndex = 0; - output = ''; - - if (drawHorizontalLine(realRowIndex, rowCount)) { - output += (0, _drawBorder.drawBorderTop)(columnSizeIndex, border); - } - - rows.forEach((row, index0) => { - output += (0, _drawRow.default)(row, border); - - if (!rowHeight) { - rowHeight = rowSpanIndex[realRowIndex]; - realRowIndex++; +const groupBySizes = (array, sizes) => { + let startIndex = 0; + return sizes.map((rowHeight) => { + const chunk = array.slice(startIndex, startIndex + rowHeight); + startIndex += rowHeight; + return chunk; + }); +}; +const shouldDrawBorderJoin = (rowIndex, rowCount, config) => { + const { singleLine, drawHorizontalLine } = config; + return !singleLine && rowIndex + 1 < rowCount && drawHorizontalLine(rowIndex + 1, rowCount); +}; +exports.default = (rows, columnWidths, rowHeights, config) => { + const { drawHorizontalLine, } = config; + const groupedRows = groupBySizes(rows, rowHeights).map((group) => { + return group.map((row) => { + return drawRow_1.default(row, config); + }).join(''); + }); + const rowCount = groupedRows.length; + let output = ''; + if (drawHorizontalLine(0, rowCount)) { + output += drawBorder_1.drawBorderTop(columnWidths, config); } - - rowHeight--; - - if (!singleLine && rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) { - output += (0, _drawBorder.drawBorderJoin)(columnSizeIndex, border); + groupedRows.forEach((row, rowIndex) => { + output += row; + if (shouldDrawBorderJoin(rowIndex, rowCount, config)) { + output += drawBorder_1.drawBorderJoin(columnWidths, config); + } + }); + if (drawHorizontalLine(rowCount, rowCount)) { + output += drawBorder_1.drawBorderBottom(columnWidths, config); } - }); - - if (drawHorizontalLine(realRowIndex, rowCount)) { - output += (0, _drawBorder.drawBorderBottom)(columnSizeIndex, border); - } - - return output; + return output; }; - -var _default = drawTable; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/drawTable.js.flow b/tools/node_modules/eslint/node_modules/table/dist/drawTable.js.flow deleted file mode 100644 index 84707caa83d04b..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/drawTable.js.flow +++ /dev/null @@ -1,53 +0,0 @@ -import { - drawBorderTop, - drawBorderJoin, - drawBorderBottom, -} from './drawBorder'; -import drawRow from './drawRow'; - -/** - * @param {Array} rows - * @param {object} border - * @param {Array} columnSizeIndex - * @param {Array} rowSpanIndex - * @param {Function} drawHorizontalLine - * @param {boolean} singleLine - * @returns {string} - */ -export default (rows, border, columnSizeIndex, rowSpanIndex, drawHorizontalLine, singleLine) => { - let output; - let realRowIndex; - let rowHeight; - - const rowCount = rows.length; - - realRowIndex = 0; - - output = ''; - - if (drawHorizontalLine(realRowIndex, rowCount)) { - output += drawBorderTop(columnSizeIndex, border); - } - - rows.forEach((row, index0) => { - output += drawRow(row, border); - - if (!rowHeight) { - rowHeight = rowSpanIndex[realRowIndex]; - - realRowIndex++; - } - - rowHeight--; - - if (!singleLine && rowHeight === 0 && index0 !== rowCount - 1 && drawHorizontalLine(realRowIndex, rowCount)) { - output += drawBorderJoin(columnSizeIndex, border); - } - }); - - if (drawHorizontalLine(realRowIndex, rowCount)) { - output += drawBorderBottom(columnSizeIndex, border); - } - - return output; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/validators.js b/tools/node_modules/eslint/node_modules/table/dist/generated/validators.js similarity index 63% rename from tools/node_modules/eslint/node_modules/table/dist/validators.js rename to tools/node_modules/eslint/node_modules/table/dist/generated/validators.js index 51783aa08b8595..99119828de034a 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/validators.js +++ b/tools/node_modules/eslint/node_modules/table/dist/generated/validators.js @@ -14,6 +14,9 @@ const schema13 = { "columnDefault": { "$ref": "shared.json#/definitions/column" }, + "drawVerticalLine": { + "typeof": "function" + }, "drawHorizontalLine": { "typeof": "function" }, @@ -78,13 +81,7 @@ const func8 = Object.prototype.hasOwnProperty; const schema16 = { "type": "string" }; - -function validate46(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate46(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; if (typeof data !== "string") { @@ -99,7 +96,8 @@ function validate46(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -107,13 +105,7 @@ function validate46(data, { validate46.errors = vErrors; return errors === 0; } - -function validate45(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate45(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) { @@ -130,7 +122,8 @@ function validate45(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -138,170 +131,171 @@ function validate45(data, { } if (data.topBody !== undefined) { if (!(validate46(data.topBody, { - instancePath: instancePath + "/topBody", - parentData: data, - parentDataProperty: "topBody", - rootData - }))) { + instancePath: instancePath + "/topBody", + parentData: data, + parentDataProperty: "topBody", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.topJoin !== undefined) { if (!(validate46(data.topJoin, { - instancePath: instancePath + "/topJoin", - parentData: data, - parentDataProperty: "topJoin", - rootData - }))) { + instancePath: instancePath + "/topJoin", + parentData: data, + parentDataProperty: "topJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.topLeft !== undefined) { if (!(validate46(data.topLeft, { - instancePath: instancePath + "/topLeft", - parentData: data, - parentDataProperty: "topLeft", - rootData - }))) { + instancePath: instancePath + "/topLeft", + parentData: data, + parentDataProperty: "topLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.topRight !== undefined) { if (!(validate46(data.topRight, { - instancePath: instancePath + "/topRight", - parentData: data, - parentDataProperty: "topRight", - rootData - }))) { + instancePath: instancePath + "/topRight", + parentData: data, + parentDataProperty: "topRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomBody !== undefined) { if (!(validate46(data.bottomBody, { - instancePath: instancePath + "/bottomBody", - parentData: data, - parentDataProperty: "bottomBody", - rootData - }))) { + instancePath: instancePath + "/bottomBody", + parentData: data, + parentDataProperty: "bottomBody", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomJoin !== undefined) { if (!(validate46(data.bottomJoin, { - instancePath: instancePath + "/bottomJoin", - parentData: data, - parentDataProperty: "bottomJoin", - rootData - }))) { + instancePath: instancePath + "/bottomJoin", + parentData: data, + parentDataProperty: "bottomJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomLeft !== undefined) { if (!(validate46(data.bottomLeft, { - instancePath: instancePath + "/bottomLeft", - parentData: data, - parentDataProperty: "bottomLeft", - rootData - }))) { + instancePath: instancePath + "/bottomLeft", + parentData: data, + parentDataProperty: "bottomLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomRight !== undefined) { if (!(validate46(data.bottomRight, { - instancePath: instancePath + "/bottomRight", - parentData: data, - parentDataProperty: "bottomRight", - rootData - }))) { + instancePath: instancePath + "/bottomRight", + parentData: data, + parentDataProperty: "bottomRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bodyLeft !== undefined) { if (!(validate46(data.bodyLeft, { - instancePath: instancePath + "/bodyLeft", - parentData: data, - parentDataProperty: "bodyLeft", - rootData - }))) { + instancePath: instancePath + "/bodyLeft", + parentData: data, + parentDataProperty: "bodyLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bodyRight !== undefined) { if (!(validate46(data.bodyRight, { - instancePath: instancePath + "/bodyRight", - parentData: data, - parentDataProperty: "bodyRight", - rootData - }))) { + instancePath: instancePath + "/bodyRight", + parentData: data, + parentDataProperty: "bodyRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bodyJoin !== undefined) { if (!(validate46(data.bodyJoin, { - instancePath: instancePath + "/bodyJoin", - parentData: data, - parentDataProperty: "bodyJoin", - rootData - }))) { + instancePath: instancePath + "/bodyJoin", + parentData: data, + parentDataProperty: "bodyJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinBody !== undefined) { if (!(validate46(data.joinBody, { - instancePath: instancePath + "/joinBody", - parentData: data, - parentDataProperty: "joinBody", - rootData - }))) { + instancePath: instancePath + "/joinBody", + parentData: data, + parentDataProperty: "joinBody", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinLeft !== undefined) { if (!(validate46(data.joinLeft, { - instancePath: instancePath + "/joinLeft", - parentData: data, - parentDataProperty: "joinLeft", - rootData - }))) { + instancePath: instancePath + "/joinLeft", + parentData: data, + parentDataProperty: "joinLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinRight !== undefined) { if (!(validate46(data.joinRight, { - instancePath: instancePath + "/joinRight", - parentData: data, - parentDataProperty: "joinRight", - rootData - }))) { + instancePath: instancePath + "/joinRight", + parentData: data, + parentDataProperty: "joinRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinJoin !== undefined) { if (!(validate46(data.joinJoin, { - instancePath: instancePath + "/joinJoin", - parentData: data, - parentDataProperty: "joinJoin", - rootData - }))) { + instancePath: instancePath + "/joinJoin", + parentData: data, + parentDataProperty: "joinJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } - } else { + } + else { const err1 = { instancePath, schemaPath: "#/type", @@ -313,7 +307,8 @@ function validate45(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; @@ -322,13 +317,20 @@ function validate45(data, { return errors === 0; } const schema17 = { - "type": "object", - "patternProperties": { - "^[0-9]+$": { - "$ref": "#/definitions/column" - } - }, - "additionalProperties": false + "oneOf": [{ + "type": "object", + "patternProperties": { + "^[0-9]+$": { + "$ref": "#/definitions/column" + } + }, + "additionalProperties": false + }, { + "type": "array", + "items": { + "$ref": "#/definitions/column" + } + }] }; const pattern0 = new RegExp("^[0-9]+$", "u"); const schema18 = { @@ -339,7 +341,9 @@ const schema18 = { "enum": ["left", "right", "center"] }, "width": { - "type": "number" + "type": "number", + "minimum": 1, + "multipleOf": 1 }, "wrapWord": { "type": "boolean" @@ -357,13 +361,7 @@ const schema18 = { "additionalProperties": false }; const func0 = require("ajv/dist/runtime/equal").default; - -function validate64(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate64(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) { @@ -380,7 +378,8 @@ function validate64(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -400,7 +399,8 @@ function validate64(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; @@ -417,7 +417,8 @@ function validate64(data, { }; if (vErrors === null) { vErrors = [err2]; - } else { + } + else { vErrors.push(err2); } errors++; @@ -425,8 +426,48 @@ function validate64(data, { } if (data.width !== undefined) { let data1 = data.width; - if (!((typeof data1 == "number") && (isFinite(data1)))) { - const err3 = { + if ((typeof data1 == "number") && (isFinite(data1))) { + if (data1 < 1 || isNaN(data1)) { + const err3 = { + instancePath: instancePath + "/width", + schemaPath: "#/properties/width/minimum", + keyword: "minimum", + params: { + comparison: ">=", + limit: 1 + }, + message: "must be >= 1" + }; + if (vErrors === null) { + vErrors = [err3]; + } + else { + vErrors.push(err3); + } + errors++; + } + let res0; + if ((1 === 0 || (res0 = data1 / 1, res0 !== parseInt(res0)))) { + const err4 = { + instancePath: instancePath + "/width", + schemaPath: "#/properties/width/multipleOf", + keyword: "multipleOf", + params: { + multipleOf: 1 + }, + message: "must be multiple of 1" + }; + if (vErrors === null) { + vErrors = [err4]; + } + else { + vErrors.push(err4); + } + errors++; + } + } + else { + const err5 = { instancePath: instancePath + "/width", schemaPath: "#/properties/width/type", keyword: "type", @@ -436,16 +477,17 @@ function validate64(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err3]; - } else { - vErrors.push(err3); + vErrors = [err5]; + } + else { + vErrors.push(err5); } errors++; } } if (data.wrapWord !== undefined) { if (typeof data.wrapWord !== "boolean") { - const err4 = { + const err6 = { instancePath: instancePath + "/wrapWord", schemaPath: "#/properties/wrapWord/type", keyword: "type", @@ -455,9 +497,10 @@ function validate64(data, { message: "must be boolean" }; if (vErrors === null) { - vErrors = [err4]; - } else { - vErrors.push(err4); + vErrors = [err6]; + } + else { + vErrors.push(err6); } errors++; } @@ -465,7 +508,7 @@ function validate64(data, { if (data.truncate !== undefined) { let data3 = data.truncate; if (!((typeof data3 == "number") && (isFinite(data3)))) { - const err5 = { + const err7 = { instancePath: instancePath + "/truncate", schemaPath: "#/properties/truncate/type", keyword: "type", @@ -475,9 +518,10 @@ function validate64(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err5]; - } else { - vErrors.push(err5); + vErrors = [err7]; + } + else { + vErrors.push(err7); } errors++; } @@ -485,7 +529,7 @@ function validate64(data, { if (data.paddingLeft !== undefined) { let data4 = data.paddingLeft; if (!((typeof data4 == "number") && (isFinite(data4)))) { - const err6 = { + const err8 = { instancePath: instancePath + "/paddingLeft", schemaPath: "#/properties/paddingLeft/type", keyword: "type", @@ -495,9 +539,10 @@ function validate64(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err6]; - } else { - vErrors.push(err6); + vErrors = [err8]; + } + else { + vErrors.push(err8); } errors++; } @@ -505,7 +550,7 @@ function validate64(data, { if (data.paddingRight !== undefined) { let data5 = data.paddingRight; if (!((typeof data5 == "number") && (isFinite(data5)))) { - const err7 = { + const err9 = { instancePath: instancePath + "/paddingRight", schemaPath: "#/properties/paddingRight/type", keyword: "type", @@ -515,15 +560,17 @@ function validate64(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err7]; - } else { - vErrors.push(err7); + vErrors = [err9]; + } + else { + vErrors.push(err9); } errors++; } } - } else { - const err8 = { + } + else { + const err10 = { instancePath, schemaPath: "#/type", keyword: "type", @@ -533,30 +580,29 @@ function validate64(data, { message: "must be object" }; if (vErrors === null) { - vErrors = [err8]; - } else { - vErrors.push(err8); + vErrors = [err10]; + } + else { + vErrors.push(err10); } errors++; } validate64.errors = vErrors; return errors === 0; } - -function validate63(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate63(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; + const _errs0 = errors; + let valid0 = false; + let passing0 = null; + const _errs1 = errors; if (data && typeof data == "object" && !Array.isArray(data)) { for (const key0 in data) { if (!(pattern0.test(key0))) { const err0 = { instancePath, - schemaPath: "#/additionalProperties", + schemaPath: "#/oneOf/0/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 @@ -565,7 +611,8 @@ function validate63(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -574,20 +621,21 @@ function validate63(data, { for (const key1 in data) { if (pattern0.test(key1)) { if (!(validate64(data[key1], { - instancePath: instancePath + "/" + key1.replace(/~/g, "~0").replace(/\//g, "~1"), - parentData: data, - parentDataProperty: key1, - rootData - }))) { + instancePath: instancePath + "/" + key1.replace(/~/g, "~0").replace(/\//g, "~1"), + parentData: data, + parentDataProperty: key1, + rootData + }))) { vErrors = vErrors === null ? validate64.errors : vErrors.concat(validate64.errors); errors = vErrors.length; } } } - } else { + } + else { const err1 = { instancePath, - schemaPath: "#/type", + schemaPath: "#/oneOf/0/type", keyword: "type", params: { type: "object" @@ -596,21 +644,94 @@ function validate63(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; } + var _valid0 = _errs1 === errors; + if (_valid0) { + valid0 = true; + passing0 = 0; + } + const _errs5 = errors; + if (Array.isArray(data)) { + const len0 = data.length; + for (let i0 = 0; i0 < len0; i0++) { + if (!(validate64(data[i0], { + instancePath: instancePath + "/" + i0, + parentData: data, + parentDataProperty: i0, + rootData + }))) { + vErrors = vErrors === null ? validate64.errors : vErrors.concat(validate64.errors); + errors = vErrors.length; + } + } + } + else { + const err2 = { + instancePath, + schemaPath: "#/oneOf/1/type", + keyword: "type", + params: { + type: "array" + }, + message: "must be array" + }; + if (vErrors === null) { + vErrors = [err2]; + } + else { + vErrors.push(err2); + } + errors++; + } + var _valid0 = _errs5 === errors; + if (_valid0 && valid0) { + valid0 = false; + passing0 = [passing0, 1]; + } + else { + if (_valid0) { + valid0 = true; + passing0 = 1; + } + } + if (!valid0) { + const err3 = { + instancePath, + schemaPath: "#/oneOf", + keyword: "oneOf", + params: { + passingSchemas: passing0 + }, + message: "must match exactly one schema in oneOf" + }; + if (vErrors === null) { + vErrors = [err3]; + } + else { + vErrors.push(err3); + } + errors++; + } + else { + errors = _errs0; + if (vErrors !== null) { + if (_errs0) { + vErrors.length = _errs0; + } + else { + vErrors = null; + } + } + } validate63.errors = vErrors; return errors === 0; } - -function validate67(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate68(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) { @@ -627,7 +748,8 @@ function validate67(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -647,7 +769,8 @@ function validate67(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; @@ -664,7 +787,8 @@ function validate67(data, { }; if (vErrors === null) { vErrors = [err2]; - } else { + } + else { vErrors.push(err2); } errors++; @@ -672,8 +796,48 @@ function validate67(data, { } if (data.width !== undefined) { let data1 = data.width; - if (!((typeof data1 == "number") && (isFinite(data1)))) { - const err3 = { + if ((typeof data1 == "number") && (isFinite(data1))) { + if (data1 < 1 || isNaN(data1)) { + const err3 = { + instancePath: instancePath + "/width", + schemaPath: "#/properties/width/minimum", + keyword: "minimum", + params: { + comparison: ">=", + limit: 1 + }, + message: "must be >= 1" + }; + if (vErrors === null) { + vErrors = [err3]; + } + else { + vErrors.push(err3); + } + errors++; + } + let res0; + if ((1 === 0 || (res0 = data1 / 1, res0 !== parseInt(res0)))) { + const err4 = { + instancePath: instancePath + "/width", + schemaPath: "#/properties/width/multipleOf", + keyword: "multipleOf", + params: { + multipleOf: 1 + }, + message: "must be multiple of 1" + }; + if (vErrors === null) { + vErrors = [err4]; + } + else { + vErrors.push(err4); + } + errors++; + } + } + else { + const err5 = { instancePath: instancePath + "/width", schemaPath: "#/properties/width/type", keyword: "type", @@ -683,16 +847,17 @@ function validate67(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err3]; - } else { - vErrors.push(err3); + vErrors = [err5]; + } + else { + vErrors.push(err5); } errors++; } } if (data.wrapWord !== undefined) { if (typeof data.wrapWord !== "boolean") { - const err4 = { + const err6 = { instancePath: instancePath + "/wrapWord", schemaPath: "#/properties/wrapWord/type", keyword: "type", @@ -702,9 +867,10 @@ function validate67(data, { message: "must be boolean" }; if (vErrors === null) { - vErrors = [err4]; - } else { - vErrors.push(err4); + vErrors = [err6]; + } + else { + vErrors.push(err6); } errors++; } @@ -712,7 +878,7 @@ function validate67(data, { if (data.truncate !== undefined) { let data3 = data.truncate; if (!((typeof data3 == "number") && (isFinite(data3)))) { - const err5 = { + const err7 = { instancePath: instancePath + "/truncate", schemaPath: "#/properties/truncate/type", keyword: "type", @@ -722,9 +888,10 @@ function validate67(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err5]; - } else { - vErrors.push(err5); + vErrors = [err7]; + } + else { + vErrors.push(err7); } errors++; } @@ -732,7 +899,7 @@ function validate67(data, { if (data.paddingLeft !== undefined) { let data4 = data.paddingLeft; if (!((typeof data4 == "number") && (isFinite(data4)))) { - const err6 = { + const err8 = { instancePath: instancePath + "/paddingLeft", schemaPath: "#/properties/paddingLeft/type", keyword: "type", @@ -742,9 +909,10 @@ function validate67(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err6]; - } else { - vErrors.push(err6); + vErrors = [err8]; + } + else { + vErrors.push(err8); } errors++; } @@ -752,7 +920,7 @@ function validate67(data, { if (data.paddingRight !== undefined) { let data5 = data.paddingRight; if (!((typeof data5 == "number") && (isFinite(data5)))) { - const err7 = { + const err9 = { instancePath: instancePath + "/paddingRight", schemaPath: "#/properties/paddingRight/type", keyword: "type", @@ -762,15 +930,17 @@ function validate67(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err7]; - } else { - vErrors.push(err7); + vErrors = [err9]; + } + else { + vErrors.push(err9); } errors++; } } - } else { - const err8 = { + } + else { + const err10 = { instancePath, schemaPath: "#/type", keyword: "type", @@ -780,28 +950,23 @@ function validate67(data, { message: "must be object" }; if (vErrors === null) { - vErrors = [err8]; - } else { - vErrors.push(err8); + vErrors = [err10]; + } + else { + vErrors.push(err10); } errors++; } - validate67.errors = vErrors; + validate68.errors = vErrors; return errors === 0; } - -function validate43(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate43(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { /*# sourceURL="config.json" */ ; let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) { for (const key0 in data) { - if (!(((((key0 === "border") || (key0 === "columns")) || (key0 === "columnDefault")) || (key0 === "drawHorizontalLine")) || (key0 === "singleLine"))) { + if (!((((((key0 === "border") || (key0 === "columns")) || (key0 === "columnDefault")) || (key0 === "drawVerticalLine")) || (key0 === "drawHorizontalLine")) || (key0 === "singleLine"))) { const err0 = { instancePath, schemaPath: "#/additionalProperties", @@ -813,7 +978,8 @@ function validate43(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -821,40 +987,58 @@ function validate43(data, { } if (data.border !== undefined) { if (!(validate45(data.border, { - instancePath: instancePath + "/border", - parentData: data, - parentDataProperty: "border", - rootData - }))) { + instancePath: instancePath + "/border", + parentData: data, + parentDataProperty: "border", + rootData + }))) { vErrors = vErrors === null ? validate45.errors : vErrors.concat(validate45.errors); errors = vErrors.length; } } if (data.columns !== undefined) { if (!(validate63(data.columns, { - instancePath: instancePath + "/columns", - parentData: data, - parentDataProperty: "columns", - rootData - }))) { + instancePath: instancePath + "/columns", + parentData: data, + parentDataProperty: "columns", + rootData + }))) { vErrors = vErrors === null ? validate63.errors : vErrors.concat(validate63.errors); errors = vErrors.length; } } if (data.columnDefault !== undefined) { - if (!(validate67(data.columnDefault, { - instancePath: instancePath + "/columnDefault", - parentData: data, - parentDataProperty: "columnDefault", - rootData - }))) { - vErrors = vErrors === null ? validate67.errors : vErrors.concat(validate67.errors); + if (!(validate68(data.columnDefault, { + instancePath: instancePath + "/columnDefault", + parentData: data, + parentDataProperty: "columnDefault", + rootData + }))) { + vErrors = vErrors === null ? validate68.errors : vErrors.concat(validate68.errors); errors = vErrors.length; } } + if (data.drawVerticalLine !== undefined) { + if (typeof data.drawVerticalLine != "function") { + const err1 = { + instancePath: instancePath + "/drawVerticalLine", + schemaPath: "#/properties/drawVerticalLine/typeof", + keyword: "typeof", + params: {}, + message: "should pass \"typeof\" keyword validation" + }; + if (vErrors === null) { + vErrors = [err1]; + } + else { + vErrors.push(err1); + } + errors++; + } + } if (data.drawHorizontalLine !== undefined) { if (typeof data.drawHorizontalLine != "function") { - const err1 = { + const err2 = { instancePath: instancePath + "/drawHorizontalLine", schemaPath: "#/properties/drawHorizontalLine/typeof", keyword: "typeof", @@ -862,16 +1046,17 @@ function validate43(data, { message: "should pass \"typeof\" keyword validation" }; if (vErrors === null) { - vErrors = [err1]; - } else { - vErrors.push(err1); + vErrors = [err2]; + } + else { + vErrors.push(err2); } errors++; } } if (data.singleLine !== undefined) { if (typeof data.singleLine != "boolean") { - const err2 = { + const err3 = { instancePath: instancePath + "/singleLine", schemaPath: "#/properties/singleLine/typeof", keyword: "typeof", @@ -879,15 +1064,17 @@ function validate43(data, { message: "should pass \"typeof\" keyword validation" }; if (vErrors === null) { - vErrors = [err2]; - } else { - vErrors.push(err2); + vErrors = [err3]; + } + else { + vErrors.push(err3); } errors++; } } - } else { - const err3 = { + } + else { + const err4 = { instancePath, schemaPath: "#/type", keyword: "type", @@ -897,16 +1084,17 @@ function validate43(data, { message: "must be object" }; if (vErrors === null) { - vErrors = [err3]; - } else { - vErrors.push(err3); + vErrors = [err4]; + } + else { + vErrors.push(err4); } errors++; } validate43.errors = vErrors; return errors === 0; } -exports["streamConfig.json"] = validate69; +exports["streamConfig.json"] = validate70; const schema20 = { "$id": "streamConfig.json", "$schema": "http://json-schema.org/draft-07/schema#", @@ -923,17 +1111,14 @@ const schema20 = { }, "columnCount": { "type": "number" + }, + "drawVerticalLine": { + "typeof": "function" } }, "additionalProperties": false }; - -function validate70(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate71(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) { @@ -950,7 +1135,8 @@ function validate70(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -958,170 +1144,171 @@ function validate70(data, { } if (data.topBody !== undefined) { if (!(validate46(data.topBody, { - instancePath: instancePath + "/topBody", - parentData: data, - parentDataProperty: "topBody", - rootData - }))) { + instancePath: instancePath + "/topBody", + parentData: data, + parentDataProperty: "topBody", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.topJoin !== undefined) { if (!(validate46(data.topJoin, { - instancePath: instancePath + "/topJoin", - parentData: data, - parentDataProperty: "topJoin", - rootData - }))) { + instancePath: instancePath + "/topJoin", + parentData: data, + parentDataProperty: "topJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.topLeft !== undefined) { if (!(validate46(data.topLeft, { - instancePath: instancePath + "/topLeft", - parentData: data, - parentDataProperty: "topLeft", - rootData - }))) { + instancePath: instancePath + "/topLeft", + parentData: data, + parentDataProperty: "topLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.topRight !== undefined) { if (!(validate46(data.topRight, { - instancePath: instancePath + "/topRight", - parentData: data, - parentDataProperty: "topRight", - rootData - }))) { + instancePath: instancePath + "/topRight", + parentData: data, + parentDataProperty: "topRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomBody !== undefined) { if (!(validate46(data.bottomBody, { - instancePath: instancePath + "/bottomBody", - parentData: data, - parentDataProperty: "bottomBody", - rootData - }))) { + instancePath: instancePath + "/bottomBody", + parentData: data, + parentDataProperty: "bottomBody", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomJoin !== undefined) { if (!(validate46(data.bottomJoin, { - instancePath: instancePath + "/bottomJoin", - parentData: data, - parentDataProperty: "bottomJoin", - rootData - }))) { + instancePath: instancePath + "/bottomJoin", + parentData: data, + parentDataProperty: "bottomJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomLeft !== undefined) { if (!(validate46(data.bottomLeft, { - instancePath: instancePath + "/bottomLeft", - parentData: data, - parentDataProperty: "bottomLeft", - rootData - }))) { + instancePath: instancePath + "/bottomLeft", + parentData: data, + parentDataProperty: "bottomLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bottomRight !== undefined) { if (!(validate46(data.bottomRight, { - instancePath: instancePath + "/bottomRight", - parentData: data, - parentDataProperty: "bottomRight", - rootData - }))) { + instancePath: instancePath + "/bottomRight", + parentData: data, + parentDataProperty: "bottomRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bodyLeft !== undefined) { if (!(validate46(data.bodyLeft, { - instancePath: instancePath + "/bodyLeft", - parentData: data, - parentDataProperty: "bodyLeft", - rootData - }))) { + instancePath: instancePath + "/bodyLeft", + parentData: data, + parentDataProperty: "bodyLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bodyRight !== undefined) { if (!(validate46(data.bodyRight, { - instancePath: instancePath + "/bodyRight", - parentData: data, - parentDataProperty: "bodyRight", - rootData - }))) { + instancePath: instancePath + "/bodyRight", + parentData: data, + parentDataProperty: "bodyRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.bodyJoin !== undefined) { if (!(validate46(data.bodyJoin, { - instancePath: instancePath + "/bodyJoin", - parentData: data, - parentDataProperty: "bodyJoin", - rootData - }))) { + instancePath: instancePath + "/bodyJoin", + parentData: data, + parentDataProperty: "bodyJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinBody !== undefined) { if (!(validate46(data.joinBody, { - instancePath: instancePath + "/joinBody", - parentData: data, - parentDataProperty: "joinBody", - rootData - }))) { + instancePath: instancePath + "/joinBody", + parentData: data, + parentDataProperty: "joinBody", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinLeft !== undefined) { if (!(validate46(data.joinLeft, { - instancePath: instancePath + "/joinLeft", - parentData: data, - parentDataProperty: "joinLeft", - rootData - }))) { + instancePath: instancePath + "/joinLeft", + parentData: data, + parentDataProperty: "joinLeft", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinRight !== undefined) { if (!(validate46(data.joinRight, { - instancePath: instancePath + "/joinRight", - parentData: data, - parentDataProperty: "joinRight", - rootData - }))) { + instancePath: instancePath + "/joinRight", + parentData: data, + parentDataProperty: "joinRight", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } if (data.joinJoin !== undefined) { if (!(validate46(data.joinJoin, { - instancePath: instancePath + "/joinJoin", - parentData: data, - parentDataProperty: "joinJoin", - rootData - }))) { + instancePath: instancePath + "/joinJoin", + parentData: data, + parentDataProperty: "joinJoin", + rootData + }))) { vErrors = vErrors === null ? validate46.errors : vErrors.concat(validate46.errors); errors = vErrors.length; } } - } else { + } + else { const err1 = { instancePath, schemaPath: "#/type", @@ -1133,29 +1320,28 @@ function validate70(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; } - validate70.errors = vErrors; + validate71.errors = vErrors; return errors === 0; } - -function validate87(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate88(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; + const _errs0 = errors; + let valid0 = false; + let passing0 = null; + const _errs1 = errors; if (data && typeof data == "object" && !Array.isArray(data)) { for (const key0 in data) { if (!(pattern0.test(key0))) { const err0 = { instancePath, - schemaPath: "#/additionalProperties", + schemaPath: "#/oneOf/0/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 @@ -1164,7 +1350,8 @@ function validate87(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -1173,20 +1360,21 @@ function validate87(data, { for (const key1 in data) { if (pattern0.test(key1)) { if (!(validate64(data[key1], { - instancePath: instancePath + "/" + key1.replace(/~/g, "~0").replace(/\//g, "~1"), - parentData: data, - parentDataProperty: key1, - rootData - }))) { + instancePath: instancePath + "/" + key1.replace(/~/g, "~0").replace(/\//g, "~1"), + parentData: data, + parentDataProperty: key1, + rootData + }))) { vErrors = vErrors === null ? validate64.errors : vErrors.concat(validate64.errors); errors = vErrors.length; } } } - } else { + } + else { const err1 = { instancePath, - schemaPath: "#/type", + schemaPath: "#/oneOf/0/type", keyword: "type", params: { type: "object" @@ -1195,21 +1383,94 @@ function validate87(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; } - validate87.errors = vErrors; + var _valid0 = _errs1 === errors; + if (_valid0) { + valid0 = true; + passing0 = 0; + } + const _errs5 = errors; + if (Array.isArray(data)) { + const len0 = data.length; + for (let i0 = 0; i0 < len0; i0++) { + if (!(validate64(data[i0], { + instancePath: instancePath + "/" + i0, + parentData: data, + parentDataProperty: i0, + rootData + }))) { + vErrors = vErrors === null ? validate64.errors : vErrors.concat(validate64.errors); + errors = vErrors.length; + } + } + } + else { + const err2 = { + instancePath, + schemaPath: "#/oneOf/1/type", + keyword: "type", + params: { + type: "array" + }, + message: "must be array" + }; + if (vErrors === null) { + vErrors = [err2]; + } + else { + vErrors.push(err2); + } + errors++; + } + var _valid0 = _errs5 === errors; + if (_valid0 && valid0) { + valid0 = false; + passing0 = [passing0, 1]; + } + else { + if (_valid0) { + valid0 = true; + passing0 = 1; + } + } + if (!valid0) { + const err3 = { + instancePath, + schemaPath: "#/oneOf", + keyword: "oneOf", + params: { + passingSchemas: passing0 + }, + message: "must match exactly one schema in oneOf" + }; + if (vErrors === null) { + vErrors = [err3]; + } + else { + vErrors.push(err3); + } + errors++; + } + else { + errors = _errs0; + if (vErrors !== null) { + if (_errs0) { + vErrors.length = _errs0; + } + else { + vErrors = null; + } + } + } + validate88.errors = vErrors; return errors === 0; } - -function validate90(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate92(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) { @@ -1226,7 +1487,8 @@ function validate90(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; @@ -1246,7 +1508,8 @@ function validate90(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; @@ -1263,7 +1526,8 @@ function validate90(data, { }; if (vErrors === null) { vErrors = [err2]; - } else { + } + else { vErrors.push(err2); } errors++; @@ -1271,8 +1535,48 @@ function validate90(data, { } if (data.width !== undefined) { let data1 = data.width; - if (!((typeof data1 == "number") && (isFinite(data1)))) { - const err3 = { + if ((typeof data1 == "number") && (isFinite(data1))) { + if (data1 < 1 || isNaN(data1)) { + const err3 = { + instancePath: instancePath + "/width", + schemaPath: "#/properties/width/minimum", + keyword: "minimum", + params: { + comparison: ">=", + limit: 1 + }, + message: "must be >= 1" + }; + if (vErrors === null) { + vErrors = [err3]; + } + else { + vErrors.push(err3); + } + errors++; + } + let res0; + if ((1 === 0 || (res0 = data1 / 1, res0 !== parseInt(res0)))) { + const err4 = { + instancePath: instancePath + "/width", + schemaPath: "#/properties/width/multipleOf", + keyword: "multipleOf", + params: { + multipleOf: 1 + }, + message: "must be multiple of 1" + }; + if (vErrors === null) { + vErrors = [err4]; + } + else { + vErrors.push(err4); + } + errors++; + } + } + else { + const err5 = { instancePath: instancePath + "/width", schemaPath: "#/properties/width/type", keyword: "type", @@ -1282,16 +1586,17 @@ function validate90(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err3]; - } else { - vErrors.push(err3); + vErrors = [err5]; + } + else { + vErrors.push(err5); } errors++; } } if (data.wrapWord !== undefined) { if (typeof data.wrapWord !== "boolean") { - const err4 = { + const err6 = { instancePath: instancePath + "/wrapWord", schemaPath: "#/properties/wrapWord/type", keyword: "type", @@ -1301,9 +1606,10 @@ function validate90(data, { message: "must be boolean" }; if (vErrors === null) { - vErrors = [err4]; - } else { - vErrors.push(err4); + vErrors = [err6]; + } + else { + vErrors.push(err6); } errors++; } @@ -1311,7 +1617,7 @@ function validate90(data, { if (data.truncate !== undefined) { let data3 = data.truncate; if (!((typeof data3 == "number") && (isFinite(data3)))) { - const err5 = { + const err7 = { instancePath: instancePath + "/truncate", schemaPath: "#/properties/truncate/type", keyword: "type", @@ -1321,9 +1627,10 @@ function validate90(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err5]; - } else { - vErrors.push(err5); + vErrors = [err7]; + } + else { + vErrors.push(err7); } errors++; } @@ -1331,7 +1638,7 @@ function validate90(data, { if (data.paddingLeft !== undefined) { let data4 = data.paddingLeft; if (!((typeof data4 == "number") && (isFinite(data4)))) { - const err6 = { + const err8 = { instancePath: instancePath + "/paddingLeft", schemaPath: "#/properties/paddingLeft/type", keyword: "type", @@ -1341,9 +1648,10 @@ function validate90(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err6]; - } else { - vErrors.push(err6); + vErrors = [err8]; + } + else { + vErrors.push(err8); } errors++; } @@ -1351,7 +1659,7 @@ function validate90(data, { if (data.paddingRight !== undefined) { let data5 = data.paddingRight; if (!((typeof data5 == "number") && (isFinite(data5)))) { - const err7 = { + const err9 = { instancePath: instancePath + "/paddingRight", schemaPath: "#/properties/paddingRight/type", keyword: "type", @@ -1361,15 +1669,17 @@ function validate90(data, { message: "must be number" }; if (vErrors === null) { - vErrors = [err7]; - } else { - vErrors.push(err7); + vErrors = [err9]; + } + else { + vErrors.push(err9); } errors++; } } - } else { - const err8 = { + } + else { + const err10 = { instancePath, schemaPath: "#/type", keyword: "type", @@ -1379,28 +1689,23 @@ function validate90(data, { message: "must be object" }; if (vErrors === null) { - vErrors = [err8]; - } else { - vErrors.push(err8); + vErrors = [err10]; + } + else { + vErrors.push(err10); } errors++; } - validate90.errors = vErrors; + validate92.errors = vErrors; return errors === 0; } - -function validate69(data, { - instancePath = "", - parentData, - parentDataProperty, - rootData = data -} = {}) { +function validate70(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { /*# sourceURL="streamConfig.json" */ ; let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) { for (const key0 in data) { - if (!((((key0 === "border") || (key0 === "columns")) || (key0 === "columnDefault")) || (key0 === "columnCount"))) { + if (!(((((key0 === "border") || (key0 === "columns")) || (key0 === "columnDefault")) || (key0 === "columnCount")) || (key0 === "drawVerticalLine"))) { const err0 = { instancePath, schemaPath: "#/additionalProperties", @@ -1412,42 +1717,43 @@ function validate69(data, { }; if (vErrors === null) { vErrors = [err0]; - } else { + } + else { vErrors.push(err0); } errors++; } } if (data.border !== undefined) { - if (!(validate70(data.border, { - instancePath: instancePath + "/border", - parentData: data, - parentDataProperty: "border", - rootData - }))) { - vErrors = vErrors === null ? validate70.errors : vErrors.concat(validate70.errors); + if (!(validate71(data.border, { + instancePath: instancePath + "/border", + parentData: data, + parentDataProperty: "border", + rootData + }))) { + vErrors = vErrors === null ? validate71.errors : vErrors.concat(validate71.errors); errors = vErrors.length; } } if (data.columns !== undefined) { - if (!(validate87(data.columns, { - instancePath: instancePath + "/columns", - parentData: data, - parentDataProperty: "columns", - rootData - }))) { - vErrors = vErrors === null ? validate87.errors : vErrors.concat(validate87.errors); + if (!(validate88(data.columns, { + instancePath: instancePath + "/columns", + parentData: data, + parentDataProperty: "columns", + rootData + }))) { + vErrors = vErrors === null ? validate88.errors : vErrors.concat(validate88.errors); errors = vErrors.length; } } if (data.columnDefault !== undefined) { - if (!(validate90(data.columnDefault, { - instancePath: instancePath + "/columnDefault", - parentData: data, - parentDataProperty: "columnDefault", - rootData - }))) { - vErrors = vErrors === null ? validate90.errors : vErrors.concat(validate90.errors); + if (!(validate92(data.columnDefault, { + instancePath: instancePath + "/columnDefault", + parentData: data, + parentDataProperty: "columnDefault", + rootData + }))) { + vErrors = vErrors === null ? validate92.errors : vErrors.concat(validate92.errors); errors = vErrors.length; } } @@ -1465,14 +1771,34 @@ function validate69(data, { }; if (vErrors === null) { vErrors = [err1]; - } else { + } + else { vErrors.push(err1); } errors++; } } - } else { - const err2 = { + if (data.drawVerticalLine !== undefined) { + if (typeof data.drawVerticalLine != "function") { + const err2 = { + instancePath: instancePath + "/drawVerticalLine", + schemaPath: "#/properties/drawVerticalLine/typeof", + keyword: "typeof", + params: {}, + message: "should pass \"typeof\" keyword validation" + }; + if (vErrors === null) { + vErrors = [err2]; + } + else { + vErrors.push(err2); + } + errors++; + } + } + } + else { + const err3 = { instancePath, schemaPath: "#/type", keyword: "type", @@ -1482,12 +1808,13 @@ function validate69(data, { message: "must be object" }; if (vErrors === null) { - vErrors = [err2]; - } else { - vErrors.push(err2); + vErrors = [err3]; + } + else { + vErrors.push(err3); } errors++; } - validate69.errors = vErrors; + validate70.errors = vErrors; return errors === 0; -} \ No newline at end of file +} diff --git a/tools/node_modules/eslint/node_modules/table/dist/getBorderCharacters.js b/tools/node_modules/eslint/node_modules/table/dist/getBorderCharacters.js index e7fe968a4b54b1..6d96a0ce29863e 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/getBorderCharacters.js +++ b/tools/node_modules/eslint/node_modules/table/dist/getBorderCharacters.js @@ -1,118 +1,82 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - /* eslint-disable sort-keys-fix/sort-keys-fix */ - -/** - * @typedef border - * @property {string} topBody - * @property {string} topJoin - * @property {string} topLeft - * @property {string} topRight - * @property {string} bottomBody - * @property {string} bottomJoin - * @property {string} bottomLeft - * @property {string} bottomRight - * @property {string} bodyLeft - * @property {string} bodyRight - * @property {string} bodyJoin - * @property {string} joinBody - * @property {string} joinLeft - * @property {string} joinRight - * @property {string} joinJoin - */ - -/** - * @param {string} name - * @returns {border} - */ -const getBorderCharacters = name => { - if (name === 'honeywell') { - return { - topBody: '═', - topJoin: '╤', - topLeft: '╔', - topRight: '╗', - bottomBody: '═', - bottomJoin: '╧', - bottomLeft: '╚', - bottomRight: '╝', - bodyLeft: '║', - bodyRight: '║', - bodyJoin: '│', - joinBody: '─', - joinLeft: '╟', - joinRight: '╢', - joinJoin: '┼' - }; - } - - if (name === 'norc') { - return { - topBody: '─', - topJoin: '┬', - topLeft: '┌', - topRight: '┐', - bottomBody: '─', - bottomJoin: '┴', - bottomLeft: '└', - bottomRight: '┘', - bodyLeft: '│', - bodyRight: '│', - bodyJoin: '│', - joinBody: '─', - joinLeft: '├', - joinRight: '┤', - joinJoin: '┼' - }; - } - - if (name === 'ramac') { - return { - topBody: '-', - topJoin: '+', - topLeft: '+', - topRight: '+', - bottomBody: '-', - bottomJoin: '+', - bottomLeft: '+', - bottomRight: '+', - bodyLeft: '|', - bodyRight: '|', - bodyJoin: '|', - joinBody: '-', - joinLeft: '|', - joinRight: '|', - joinJoin: '|' - }; - } - - if (name === 'void') { - return { - topBody: '', - topJoin: '', - topLeft: '', - topRight: '', - bottomBody: '', - bottomJoin: '', - bottomLeft: '', - bottomRight: '', - bodyLeft: '', - bodyRight: '', - bodyJoin: '', - joinBody: '', - joinLeft: '', - joinRight: '', - joinJoin: '' - }; - } - - throw new Error('Unknown border template "' + name + '".'); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = (name) => { + if (name === 'honeywell') { + return { + topBody: '═', + topJoin: '╤', + topLeft: '╔', + topRight: '╗', + bottomBody: '═', + bottomJoin: '╧', + bottomLeft: '╚', + bottomRight: '╝', + bodyLeft: '║', + bodyRight: '║', + bodyJoin: '│', + joinBody: '─', + joinLeft: '╟', + joinRight: '╢', + joinJoin: '┼', + }; + } + if (name === 'norc') { + return { + topBody: '─', + topJoin: '┬', + topLeft: '┌', + topRight: '┐', + bottomBody: '─', + bottomJoin: '┴', + bottomLeft: '└', + bottomRight: '┘', + bodyLeft: '│', + bodyRight: '│', + bodyJoin: '│', + joinBody: '─', + joinLeft: '├', + joinRight: '┤', + joinJoin: '┼', + }; + } + if (name === 'ramac') { + return { + topBody: '-', + topJoin: '+', + topLeft: '+', + topRight: '+', + bottomBody: '-', + bottomJoin: '+', + bottomLeft: '+', + bottomRight: '+', + bodyLeft: '|', + bodyRight: '|', + bodyJoin: '|', + joinBody: '-', + joinLeft: '|', + joinRight: '|', + joinJoin: '|', + }; + } + if (name === 'void') { + return { + topBody: '', + topJoin: '', + topLeft: '', + topRight: '', + bottomBody: '', + bottomJoin: '', + bottomLeft: '', + bottomRight: '', + bodyLeft: '', + bodyRight: '', + bodyJoin: '', + joinBody: '', + joinLeft: '', + joinRight: '', + joinJoin: '', + }; + } + throw new Error('Unknown border template "' + name + '".'); }; - -var _default = getBorderCharacters; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/getBorderCharacters.js.flow b/tools/node_modules/eslint/node_modules/table/dist/getBorderCharacters.js.flow deleted file mode 100644 index bc8b0f263a1e07..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/getBorderCharacters.js.flow +++ /dev/null @@ -1,120 +0,0 @@ -/* eslint-disable sort-keys-fix/sort-keys-fix */ - -/** - * @typedef border - * @property {string} topBody - * @property {string} topJoin - * @property {string} topLeft - * @property {string} topRight - * @property {string} bottomBody - * @property {string} bottomJoin - * @property {string} bottomLeft - * @property {string} bottomRight - * @property {string} bodyLeft - * @property {string} bodyRight - * @property {string} bodyJoin - * @property {string} joinBody - * @property {string} joinLeft - * @property {string} joinRight - * @property {string} joinJoin - */ - -/** - * @param {string} name - * @returns {border} - */ -export default (name) => { - if (name === 'honeywell') { - return { - topBody: '═', - topJoin: '╤', - topLeft: '╔', - topRight: '╗', - - bottomBody: '═', - bottomJoin: '╧', - bottomLeft: '╚', - bottomRight: '╝', - - bodyLeft: '║', - bodyRight: '║', - bodyJoin: '│', - - joinBody: '─', - joinLeft: '╟', - joinRight: '╢', - joinJoin: '┼', - }; - } - - if (name === 'norc') { - return { - topBody: '─', - topJoin: '┬', - topLeft: '┌', - topRight: '┐', - - bottomBody: '─', - bottomJoin: '┴', - bottomLeft: '└', - bottomRight: '┘', - - bodyLeft: '│', - bodyRight: '│', - bodyJoin: '│', - - joinBody: '─', - joinLeft: '├', - joinRight: '┤', - joinJoin: '┼', - }; - } - - if (name === 'ramac') { - return { - topBody: '-', - topJoin: '+', - topLeft: '+', - topRight: '+', - - bottomBody: '-', - bottomJoin: '+', - bottomLeft: '+', - bottomRight: '+', - - bodyLeft: '|', - bodyRight: '|', - bodyJoin: '|', - - joinBody: '-', - joinLeft: '|', - joinRight: '|', - joinJoin: '|', - }; - } - - if (name === 'void') { - return { - topBody: '', - topJoin: '', - topLeft: '', - topRight: '', - - bottomBody: '', - bottomJoin: '', - bottomLeft: '', - bottomRight: '', - - bodyLeft: '', - bodyRight: '', - bodyJoin: '', - - joinBody: '', - joinLeft: '', - joinRight: '', - joinJoin: '', - }; - } - - throw new Error('Unknown border template "' + name + '".'); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/index.js b/tools/node_modules/eslint/node_modules/table/dist/index.js index 069dcccb36ff73..6e93edc0317f71 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/index.js +++ b/tools/node_modules/eslint/node_modules/table/dist/index.js @@ -1,31 +1,23 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -Object.defineProperty(exports, "createStream", { - enumerable: true, - get: function () { - return _createStream.default; - } -}); -Object.defineProperty(exports, "getBorderCharacters", { - enumerable: true, - get: function () { - return _getBorderCharacters.default; - } -}); -Object.defineProperty(exports, "table", { - enumerable: true, - get: function () { - return _table.default; - } -}); - -var _createStream = _interopRequireDefault(require("./createStream")); - -var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters")); - -var _table = _interopRequireDefault(require("./table")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } \ No newline at end of file +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __exportStar = (this && this.__exportStar) || function(m, exports) { + for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.getBorderCharacters = exports.createStream = exports.table = void 0; +const createStream_1 = __importDefault(require("./createStream")); +exports.createStream = createStream_1.default; +const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters")); +exports.getBorderCharacters = getBorderCharacters_1.default; +const table_1 = __importDefault(require("./table")); +exports.table = table_1.default; +__exportStar(require("./types/api"), exports); diff --git a/tools/node_modules/eslint/node_modules/table/dist/index.js.flow b/tools/node_modules/eslint/node_modules/table/dist/index.js.flow deleted file mode 100644 index 4a47c502576564..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/index.js.flow +++ /dev/null @@ -1,9 +0,0 @@ -import createStream from './createStream'; -import getBorderCharacters from './getBorderCharacters'; -import table from './table'; - -export { - table, - createStream, - getBorderCharacters, -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/makeConfig.js b/tools/node_modules/eslint/node_modules/table/dist/makeConfig.js index a80d9a06acf1c9..4189a6d21b544e 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/makeConfig.js +++ b/tools/node_modules/eslint/node_modules/table/dist/makeConfig.js @@ -1,91 +1,58 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _lodash = _interopRequireDefault(require("lodash.clonedeep")); - -var _calculateMaximumColumnWidthIndex = _interopRequireDefault(require("./calculateMaximumColumnWidthIndex")); - -var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters")); - -var _validateConfig = _interopRequireDefault(require("./validateConfig")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); +const calculateMaximumColumnWidthIndex_1 = __importDefault(require("./calculateMaximumColumnWidthIndex")); +const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters")); +const validateConfig_1 = __importDefault(require("./validateConfig")); /** * Merges user provided border characters with the default border ("honeywell") characters. - * - * @param {object} border - * @returns {object} */ -const makeBorder = (border = {}) => { - return Object.assign({}, (0, _getBorderCharacters.default)('honeywell'), border); +const makeBorder = (border) => { + return { + ...getBorderCharacters_1.default('honeywell'), + ...border, + }; }; /** * Creates a configuration for every column using default * values for the missing configuration properties. - * - * @param {Array[]} rows - * @param {object} columns - * @param {object} columnDefault - * @returns {object} */ - - -const makeColumns = (rows, columns = {}, columnDefault = {}) => { - const maximumColumnWidthIndex = (0, _calculateMaximumColumnWidthIndex.default)(rows); - - for (let index = 0; index < rows[0].length; index++) { - if (typeof columns[index] === 'undefined') { - columns[index] = {}; - } - - columns[index] = Object.assign({ - alignment: 'left', - paddingLeft: 1, - paddingRight: 1, - truncate: Number.POSITIVE_INFINITY, - width: maximumColumnWidthIndex[index], - wrapWord: false - }, columnDefault, columns[index]); - } - - return columns; +const makeColumns = (rows, columns, columnDefault) => { + const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex_1.default(rows); + return rows[0].map((_cell, index) => { + return { + alignment: 'left', + paddingLeft: 1, + paddingRight: 1, + truncate: Number.POSITIVE_INFINITY, + width: maximumColumnWidthIndex[index], + wrapWord: false, + ...columnDefault, + ...columns === null || columns === void 0 ? void 0 : columns[index], + }; + }); }; /** * Makes a new configuration object out of the userConfig object * using default values for the missing configuration properties. - * - * @param {Array[]} rows - * @param {object} userConfig - * @returns {object} */ - - -const makeConfig = (rows, userConfig = {}) => { - (0, _validateConfig.default)('config.json', userConfig); - const config = (0, _lodash.default)(userConfig); - config.border = makeBorder(config.border); - config.columns = makeColumns(rows, config.columns, config.columnDefault); - - if (!config.drawHorizontalLine) { - /** - * @returns {boolean} - */ - config.drawHorizontalLine = () => { - return true; +exports.default = (rows, userConfig = {}) => { + var _a, _b, _c; + validateConfig_1.default('config.json', userConfig); + const config = lodash_clonedeep_1.default(userConfig); + return { + ...config, + border: makeBorder(config.border), + columns: makeColumns(rows, config.columns, config.columnDefault), + drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => { + return true; + }), + drawVerticalLine: (_b = config.drawVerticalLine) !== null && _b !== void 0 ? _b : (() => { + return true; + }), + singleLine: (_c = config.singleLine) !== null && _c !== void 0 ? _c : false, }; - } - - if (config.singleLine === undefined) { - config.singleLine = false; - } - - return config; }; - -var _default = makeConfig; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/makeConfig.js.flow b/tools/node_modules/eslint/node_modules/table/dist/makeConfig.js.flow deleted file mode 100644 index 3fcbc79c555f0b..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/makeConfig.js.flow +++ /dev/null @@ -1,76 +0,0 @@ -import cloneDeep from 'lodash.clonedeep'; -import calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex'; -import getBorderCharacters from './getBorderCharacters'; -import validateConfig from './validateConfig'; - -/** - * Merges user provided border characters with the default border ("honeywell") characters. - * - * @param {object} border - * @returns {object} - */ -const makeBorder = (border = {}) => { - return Object.assign({}, getBorderCharacters('honeywell'), border); -}; - -/** - * Creates a configuration for every column using default - * values for the missing configuration properties. - * - * @param {Array[]} rows - * @param {object} columns - * @param {object} columnDefault - * @returns {object} - */ -const makeColumns = (rows, columns = {}, columnDefault = {}) => { - const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows); - - for (let index = 0; index < rows[0].length; index++) { - if (typeof columns[index] === 'undefined') { - columns[index] = {}; - } - - columns[index] = Object.assign({ - alignment: 'left', - paddingLeft: 1, - paddingRight: 1, - truncate: Number.POSITIVE_INFINITY, - width: maximumColumnWidthIndex[index], - wrapWord: false, - }, columnDefault, columns[index]); - } - - return columns; -}; - -/** - * Makes a new configuration object out of the userConfig object - * using default values for the missing configuration properties. - * - * @param {Array[]} rows - * @param {object} userConfig - * @returns {object} - */ -export default (rows, userConfig = {}) => { - validateConfig('config.json', userConfig); - - const config = cloneDeep(userConfig); - - config.border = makeBorder(config.border); - config.columns = makeColumns(rows, config.columns, config.columnDefault); - - if (!config.drawHorizontalLine) { - /** - * @returns {boolean} - */ - config.drawHorizontalLine = () => { - return true; - }; - } - - if (config.singleLine === undefined) { - config.singleLine = false; - } - - return config; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/makeStreamConfig.js b/tools/node_modules/eslint/node_modules/table/dist/makeStreamConfig.js index 6ca9733dd358e2..92f577adbff1aa 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/makeStreamConfig.js +++ b/tools/node_modules/eslint/node_modules/table/dist/makeStreamConfig.js @@ -1,97 +1,59 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _lodash = _interopRequireDefault(require("lodash.clonedeep")); - -var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters")); - -var _validateConfig = _interopRequireDefault(require("./validateConfig")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const lodash_clonedeep_1 = __importDefault(require("lodash.clonedeep")); +const getBorderCharacters_1 = __importDefault(require("./getBorderCharacters")); +const validateConfig_1 = __importDefault(require("./validateConfig")); /** * Merges user provided border characters with the default border ("honeywell") characters. * - * @param {object} border - * @returns {object} */ -const makeBorder = (border = {}) => { - return Object.assign({}, (0, _getBorderCharacters.default)('honeywell'), border); +const makeBorder = (border) => { + return { + ...getBorderCharacters_1.default('honeywell'), + ...border, + }; }; /** * Creates a configuration for every column using default * values for the missing configuration properties. - * - * @param {number} columnCount - * @param {object} columns - * @param {object} columnDefault - * @returns {object} */ - - -const makeColumns = (columnCount, columns = {}, columnDefault = {}) => { - for (let index = 0; index < columnCount; index++) { - if (typeof columns[index] === 'undefined') { - columns[index] = {}; - } - - columns[index] = Object.assign({ - alignment: 'left', - paddingLeft: 1, - paddingRight: 1, - truncate: Number.POSITIVE_INFINITY, - wrapWord: false - }, columnDefault, columns[index]); - } - - return columns; +const makeColumns = (columnCount, columns = {}, columnDefault) => { + return Array.from({ length: columnCount }).map((_, index) => { + return { + alignment: 'left', + paddingLeft: 1, + paddingRight: 1, + truncate: Number.POSITIVE_INFINITY, + wrapWord: false, + ...columnDefault, + ...columns[index], + }; + }); }; -/** - * @typedef {object} columnConfig - * @property {string} alignment - * @property {number} width - * @property {number} truncate - * @property {number} paddingLeft - * @property {number} paddingRight - */ - -/** - * @typedef {object} streamConfig - * @property {columnConfig} columnDefault - * @property {object} border - * @property {columnConfig[]} - * @property {number} columnCount Number of columns in the table (required). - */ - /** * Makes a new configuration object out of the userConfig object * using default values for the missing configuration properties. - * - * @param {streamConfig} userConfig - * @returns {object} */ - - -const makeStreamConfig = (userConfig = {}) => { - (0, _validateConfig.default)('streamConfig.json', userConfig); - const config = (0, _lodash.default)(userConfig); - - if (!config.columnDefault || !config.columnDefault.width) { - throw new Error('Must provide config.columnDefault.width when creating a stream.'); - } - - if (!config.columnCount) { - throw new Error('Must provide config.columnCount.'); - } - - config.border = makeBorder(config.border); - config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault); - return config; +exports.default = (userConfig) => { + var _a; + validateConfig_1.default('streamConfig.json', userConfig); + const config = lodash_clonedeep_1.default(userConfig); + if (!config.columnDefault || !config.columnDefault.width) { + throw new Error('Must provide config.columnDefault.width when creating a stream.'); + } + if (!config.columnCount) { + throw new Error('Must provide config.columnCount.'); + } + return { + ...config, + border: makeBorder(config.border), + columnCount: config.columnCount, + columns: makeColumns(config.columnCount, config.columns, config.columnDefault), + drawVerticalLine: (_a = config.drawVerticalLine) !== null && _a !== void 0 ? _a : (() => { + return true; + }), + }; }; - -var _default = makeStreamConfig; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/makeStreamConfig.js.flow b/tools/node_modules/eslint/node_modules/table/dist/makeStreamConfig.js.flow deleted file mode 100644 index 8536bf5b37a0c1..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/makeStreamConfig.js.flow +++ /dev/null @@ -1,83 +0,0 @@ -import cloneDeep from 'lodash.clonedeep'; -import getBorderCharacters from './getBorderCharacters'; -import validateConfig from './validateConfig'; - -/** - * Merges user provided border characters with the default border ("honeywell") characters. - * - * @param {object} border - * @returns {object} - */ -const makeBorder = (border = {}) => { - return Object.assign({}, getBorderCharacters('honeywell'), border); -}; - -/** - * Creates a configuration for every column using default - * values for the missing configuration properties. - * - * @param {number} columnCount - * @param {object} columns - * @param {object} columnDefault - * @returns {object} - */ -const makeColumns = (columnCount, columns = {}, columnDefault = {}) => { - for (let index = 0; index < columnCount; index++) { - if (typeof columns[index] === 'undefined') { - columns[index] = {}; - } - - columns[index] = Object.assign({ - alignment: 'left', - paddingLeft: 1, - paddingRight: 1, - truncate: Number.POSITIVE_INFINITY, - wrapWord: false, - }, columnDefault, columns[index]); - } - - return columns; -}; - -/** - * @typedef {object} columnConfig - * @property {string} alignment - * @property {number} width - * @property {number} truncate - * @property {number} paddingLeft - * @property {number} paddingRight - */ - -/** - * @typedef {object} streamConfig - * @property {columnConfig} columnDefault - * @property {object} border - * @property {columnConfig[]} - * @property {number} columnCount Number of columns in the table (required). - */ - -/** - * Makes a new configuration object out of the userConfig object - * using default values for the missing configuration properties. - * - * @param {streamConfig} userConfig - * @returns {object} - */ -export default (userConfig = {}) => { - validateConfig('streamConfig.json', userConfig); - - const config = cloneDeep(userConfig); - - if (!config.columnDefault || !config.columnDefault.width) { - throw new Error('Must provide config.columnDefault.width when creating a stream.'); - } - - if (!config.columnCount) { - throw new Error('Must provide config.columnCount.'); - } - - config.border = makeBorder(config.border); - config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault); - - return config; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/mapDataUsingRowHeightIndex.js b/tools/node_modules/eslint/node_modules/table/dist/mapDataUsingRowHeightIndex.js index 1708570759dde0..4b79669cf5081c 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/mapDataUsingRowHeightIndex.js +++ b/tools/node_modules/eslint/node_modules/table/dist/mapDataUsingRowHeightIndex.js @@ -1,41 +1,26 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _lodash = _interopRequireDefault(require("lodash.flatten")); - -var _wrapCell = _interopRequireDefault(require("./wrapCell")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * @param {Array} unmappedRows - * @param {number[]} rowHeightIndex - * @param {object} config - * @returns {Array} - */ -const mapDataUsingRowHeightIndex = (unmappedRows, rowHeightIndex, config) => { - const tableWidth = unmappedRows[0].length; - const mappedRows = unmappedRows.map((cells, index0) => { - const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => { - return new Array(tableWidth).fill(''); - }); // rowHeight - // [{row index within rowSaw; index2}] - // [{cell index within a virtual row; index1}] - - cells.forEach((value, index1) => { - const cellLines = (0, _wrapCell.default)(value, config.columns[index1].width, config.columns[index1].wrapWord); - cellLines.forEach((cellLine, index2) => { - rowHeight[index2][index1] = cellLine; - }); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const lodash_flatten_1 = __importDefault(require("lodash.flatten")); +const wrapCell_1 = __importDefault(require("./wrapCell")); +exports.default = (unmappedRows, rowHeightIndex, config) => { + const tableWidth = unmappedRows[0].length; + const mappedRows = unmappedRows.map((row, index0) => { + const rowHeight = Array.from({ length: rowHeightIndex[index0] }, () => { + return new Array(tableWidth).fill(''); + }); + // rowHeight + // [{row index within rowSaw; index2}] + // [{cell index within a virtual row; index1}] + row.forEach((cell, index1) => { + const cellLines = wrapCell_1.default(cell, config.columns[index1].width, config.columns[index1].wrapWord); + cellLines.forEach((cellLine, index2) => { + rowHeight[index2][index1] = cellLine; + }); + }); + return rowHeight; }); - return rowHeight; - }); - return (0, _lodash.default)(mappedRows); + return lodash_flatten_1.default(mappedRows); }; - -var _default = mapDataUsingRowHeightIndex; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/mapDataUsingRowHeightIndex.js.flow b/tools/node_modules/eslint/node_modules/table/dist/mapDataUsingRowHeightIndex.js.flow deleted file mode 100644 index 5d59b059a0ad00..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/mapDataUsingRowHeightIndex.js.flow +++ /dev/null @@ -1,34 +0,0 @@ -import flatten from 'lodash.flatten'; -import wrapCell from './wrapCell'; - -/** - * @param {Array} unmappedRows - * @param {number[]} rowHeightIndex - * @param {object} config - * @returns {Array} - */ -export default (unmappedRows, rowHeightIndex, config) => { - const tableWidth = unmappedRows[0].length; - - const mappedRows = unmappedRows.map((cells, index0) => { - const rowHeight = Array.from(new Array(rowHeightIndex[index0]), () => { - return new Array(tableWidth).fill(''); - }); - - // rowHeight - // [{row index within rowSaw; index2}] - // [{cell index within a virtual row; index1}] - - cells.forEach((value, index1) => { - const cellLines = wrapCell(value, config.columns[index1].width, config.columns[index1].wrapWord); - - cellLines.forEach((cellLine, index2) => { - rowHeight[index2][index1] = cellLine; - }); - }); - - return rowHeight; - }); - - return flatten(mappedRows); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/padTableData.js b/tools/node_modules/eslint/node_modules/table/dist/padTableData.js index 4b7fd4dfeca503..e539f3d7a08629 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/padTableData.js +++ b/tools/node_modules/eslint/node_modules/table/dist/padTableData.js @@ -1,23 +1,10 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -/** - * @param {table~row[]} rows - * @param {object} config - * @returns {table~row[]} - */ -const padTableData = (rows, config) => { - return rows.map(cells => { - return cells.map((value, index1) => { - const column = config.columns[index1]; - return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = (rows, config) => { + return rows.map((cells) => { + return cells.map((value, index1) => { + const column = config.columns[index1]; + return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight); + }); }); - }); }; - -var _default = padTableData; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/padTableData.js.flow b/tools/node_modules/eslint/node_modules/table/dist/padTableData.js.flow deleted file mode 100644 index a4e6b142c1839f..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/padTableData.js.flow +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @param {table~row[]} rows - * @param {object} config - * @returns {table~row[]} - */ -export default (rows, config) => { - return rows.map((cells) => { - return cells.map((value, index1) => { - const column = config.columns[index1]; - - return ' '.repeat(column.paddingLeft) + value + ' '.repeat(column.paddingRight); - }); - }); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/schemas/config.json b/tools/node_modules/eslint/node_modules/table/dist/schemas/config.json deleted file mode 100644 index 10fc74ab93cfc1..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/schemas/config.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "$id": "config.json", - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "border": { - "$ref": "shared.json#/definitions/borders" - }, - "columns": { - "$ref": "shared.json#/definitions/columns" - }, - "columnDefault": { - "$ref": "shared.json#/definitions/column" - }, - "drawHorizontalLine": { - "typeof": "function" - }, - "singleLine": { - "typeof": "boolean" - } - }, - "additionalProperties": false -} diff --git a/tools/node_modules/eslint/node_modules/table/dist/schemas/shared.json b/tools/node_modules/eslint/node_modules/table/dist/schemas/shared.json deleted file mode 100644 index 7d03f9269455a5..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/schemas/shared.json +++ /dev/null @@ -1,98 +0,0 @@ -{ - "$id": "shared.json", - "$schema": "http://json-schema.org/draft-07/schema#", - "definitions": { - "columns": { - "type": "object", - "patternProperties": { - "^[0-9]+$": { - "$ref": "#/definitions/column" - } - }, - "additionalProperties": false - }, - "column": { - "type": "object", - "properties": { - "alignment": { - "type": "string", - "enum": [ - "left", - "right", - "center" - ] - }, - "width": { - "type": "number" - }, - "wrapWord": { - "type": "boolean" - }, - "truncate": { - "type": "number" - }, - "paddingLeft": { - "type": "number" - }, - "paddingRight": { - "type": "number" - } - }, - "additionalProperties": false - }, - "borders": { - "type": "object", - "properties": { - "topBody": { - "$ref": "#/definitions/border" - }, - "topJoin": { - "$ref": "#/definitions/border" - }, - "topLeft": { - "$ref": "#/definitions/border" - }, - "topRight": { - "$ref": "#/definitions/border" - }, - "bottomBody": { - "$ref": "#/definitions/border" - }, - "bottomJoin": { - "$ref": "#/definitions/border" - }, - "bottomLeft": { - "$ref": "#/definitions/border" - }, - "bottomRight": { - "$ref": "#/definitions/border" - }, - "bodyLeft": { - "$ref": "#/definitions/border" - }, - "bodyRight": { - "$ref": "#/definitions/border" - }, - "bodyJoin": { - "$ref": "#/definitions/border" - }, - "joinBody": { - "$ref": "#/definitions/border" - }, - "joinLeft": { - "$ref": "#/definitions/border" - }, - "joinRight": { - "$ref": "#/definitions/border" - }, - "joinJoin": { - "$ref": "#/definitions/border" - } - }, - "additionalProperties": false - }, - "border": { - "type": "string" - } - } -} diff --git a/tools/node_modules/eslint/node_modules/table/dist/schemas/streamConfig.json b/tools/node_modules/eslint/node_modules/table/dist/schemas/streamConfig.json deleted file mode 100644 index 24dfa56282541a..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/schemas/streamConfig.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "$id": "streamConfig.json", - "$schema": "http://json-schema.org/draft-07/schema#", - "type": "object", - "properties": { - "border": { - "$ref": "shared.json#/definitions/borders" - }, - "columns": { - "$ref": "shared.json#/definitions/columns" - }, - "columnDefault": { - "$ref": "shared.json#/definitions/column" - }, - "columnCount": { - "type": "number" - } - }, - "additionalProperties": false -} diff --git a/tools/node_modules/eslint/node_modules/table/dist/stringifyTableData.js b/tools/node_modules/eslint/node_modules/table/dist/stringifyTableData.js index 99640e16551ddc..16d88d553c2886 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/stringifyTableData.js +++ b/tools/node_modules/eslint/node_modules/table/dist/stringifyTableData.js @@ -1,21 +1,7 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -/** - * Casts all cell values to a string. - * - * @param {table~row[]} rows - * @returns {table~row[]} - */ -const stringifyTableData = rows => { - return rows.map(cells => { - return cells.map(String); - }); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = (rows) => { + return rows.map((cells) => { + return cells.map(String); + }); }; - -var _default = stringifyTableData; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/stringifyTableData.js.flow b/tools/node_modules/eslint/node_modules/table/dist/stringifyTableData.js.flow deleted file mode 100644 index a4dffac13d9be6..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/stringifyTableData.js.flow +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Casts all cell values to a string. - * - * @param {table~row[]} rows - * @returns {table~row[]} - */ -export default (rows) => { - return rows.map((cells) => { - return cells.map(String); - }); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/table.js b/tools/node_modules/eslint/node_modules/table/dist/table.js index 8c053d81f773b4..94177acc7bd101 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/table.js +++ b/tools/node_modules/eslint/node_modules/table/dist/table.js @@ -1,109 +1,27 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _alignTableData = _interopRequireDefault(require("./alignTableData")); - -var _calculateCellWidthIndex = _interopRequireDefault(require("./calculateCellWidthIndex")); - -var _calculateRowHeightIndex = _interopRequireDefault(require("./calculateRowHeightIndex")); - -var _drawTable = _interopRequireDefault(require("./drawTable")); - -var _makeConfig = _interopRequireDefault(require("./makeConfig")); - -var _mapDataUsingRowHeightIndex = _interopRequireDefault(require("./mapDataUsingRowHeightIndex")); - -var _padTableData = _interopRequireDefault(require("./padTableData")); - -var _stringifyTableData = _interopRequireDefault(require("./stringifyTableData")); - -var _truncateTableData = _interopRequireDefault(require("./truncateTableData")); - -var _validateTableData = _interopRequireDefault(require("./validateTableData")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * @typedef {string} table~cell - */ - -/** - * @typedef {table~cell[]} table~row - */ - -/** - * @typedef {object} table~columns - * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left). - * @property {number} width Column width (default: auto). - * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity). - * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters - * @property {number} paddingLeft Cell content padding width left (default: 1). - * @property {number} paddingRight Cell content padding width right (default: 1). - */ - -/** - * @typedef {object} table~border - * @property {string} topBody - * @property {string} topJoin - * @property {string} topLeft - * @property {string} topRight - * @property {string} bottomBody - * @property {string} bottomJoin - * @property {string} bottomLeft - * @property {string} bottomRight - * @property {string} bodyLeft - * @property {string} bodyRight - * @property {string} bodyJoin - * @property {string} joinBody - * @property {string} joinLeft - * @property {string} joinRight - * @property {string} joinJoin - */ - -/** - * Used to tell whether to draw a horizontal line. - * This callback is called for each non-content line of the table. - * The default behavior is to always return true. - * - * @typedef {Function} drawHorizontalLine - * @param {number} index - * @param {number} size - * @returns {boolean} - */ - -/** - * @typedef {object} table~config - * @property {table~border} border - * @property {table~columns[]} columns Column specific configuration. - * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values. - * @property {table~drawHorizontalLine} drawHorizontalLine - * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn. - */ - -/** - * Generates a text table. - * - * @param {table~row[]} data - * @param {table~config} userConfig - * @returns {string} - */ -const table = (data, userConfig = {}) => { - let rows; - (0, _validateTableData.default)(data); - rows = (0, _stringifyTableData.default)(data); - const config = (0, _makeConfig.default)(rows, userConfig); - rows = (0, _truncateTableData.default)(data, config); - const rowHeightIndex = (0, _calculateRowHeightIndex.default)(rows, config); - rows = (0, _mapDataUsingRowHeightIndex.default)(rows, rowHeightIndex, config); - rows = (0, _alignTableData.default)(rows, config); - rows = (0, _padTableData.default)(rows, config); - const cellWidthIndex = (0, _calculateCellWidthIndex.default)(rows[0]); - return (0, _drawTable.default)(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine); +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const alignTableData_1 = __importDefault(require("./alignTableData")); +const calculateCellWidthIndex_1 = __importDefault(require("./calculateCellWidthIndex")); +const calculateRowHeightIndex_1 = __importDefault(require("./calculateRowHeightIndex")); +const drawTable_1 = __importDefault(require("./drawTable")); +const makeConfig_1 = __importDefault(require("./makeConfig")); +const mapDataUsingRowHeightIndex_1 = __importDefault(require("./mapDataUsingRowHeightIndex")); +const padTableData_1 = __importDefault(require("./padTableData")); +const stringifyTableData_1 = __importDefault(require("./stringifyTableData")); +const truncateTableData_1 = __importDefault(require("./truncateTableData")); +const validateTableData_1 = __importDefault(require("./validateTableData")); +exports.default = (data, userConfig = {}) => { + validateTableData_1.default(data); + let rows = stringifyTableData_1.default(data); + const config = makeConfig_1.default(rows, userConfig); + rows = truncateTableData_1.default(rows, config); + const rowHeightIndex = calculateRowHeightIndex_1.default(rows, config); + rows = mapDataUsingRowHeightIndex_1.default(rows, rowHeightIndex, config); + rows = alignTableData_1.default(rows, config); + rows = padTableData_1.default(rows, config); + const cellWidthIndex = calculateCellWidthIndex_1.default(rows[0]); + return drawTable_1.default(rows, cellWidthIndex, rowHeightIndex, config); }; - -var _default = table; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/table.js.flow b/tools/node_modules/eslint/node_modules/table/dist/table.js.flow deleted file mode 100644 index 6790e8cc550f2c..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/table.js.flow +++ /dev/null @@ -1,96 +0,0 @@ -import alignTableData from './alignTableData'; -import calculateCellWidthIndex from './calculateCellWidthIndex'; -import calculateRowHeightIndex from './calculateRowHeightIndex'; -import drawTable from './drawTable'; -import makeConfig from './makeConfig'; -import mapDataUsingRowHeightIndex from './mapDataUsingRowHeightIndex'; -import padTableData from './padTableData'; -import stringifyTableData from './stringifyTableData'; -import truncateTableData from './truncateTableData'; -import validateTableData from './validateTableData'; - -/** - * @typedef {string} table~cell - */ - -/** - * @typedef {table~cell[]} table~row - */ - -/** - * @typedef {object} table~columns - * @property {string} alignment Cell content alignment (enum: left, center, right) (default: left). - * @property {number} width Column width (default: auto). - * @property {number} truncate Number of characters are which the content will be truncated (default: Infinity). - * @property {boolean} wrapWord When true the text is broken at the nearest space or one of the special characters - * @property {number} paddingLeft Cell content padding width left (default: 1). - * @property {number} paddingRight Cell content padding width right (default: 1). - */ - -/** - * @typedef {object} table~border - * @property {string} topBody - * @property {string} topJoin - * @property {string} topLeft - * @property {string} topRight - * @property {string} bottomBody - * @property {string} bottomJoin - * @property {string} bottomLeft - * @property {string} bottomRight - * @property {string} bodyLeft - * @property {string} bodyRight - * @property {string} bodyJoin - * @property {string} joinBody - * @property {string} joinLeft - * @property {string} joinRight - * @property {string} joinJoin - */ - -/** - * Used to tell whether to draw a horizontal line. - * This callback is called for each non-content line of the table. - * The default behavior is to always return true. - * - * @typedef {Function} drawHorizontalLine - * @param {number} index - * @param {number} size - * @returns {boolean} - */ - -/** - * @typedef {object} table~config - * @property {table~border} border - * @property {table~columns[]} columns Column specific configuration. - * @property {table~columns} columnDefault Default values for all columns. Column specific settings overwrite the default values. - * @property {table~drawHorizontalLine} drawHorizontalLine - * @property {table~singleLine} singleLine Horizontal lines inside the table are not drawn. - */ - -/** - * Generates a text table. - * - * @param {table~row[]} data - * @param {table~config} userConfig - * @returns {string} - */ -export default (data, userConfig = {}) => { - let rows; - - validateTableData(data); - - rows = stringifyTableData(data); - - const config = makeConfig(rows, userConfig); - - rows = truncateTableData(data, config); - - const rowHeightIndex = calculateRowHeightIndex(rows, config); - - rows = mapDataUsingRowHeightIndex(rows, rowHeightIndex, config); - rows = alignTableData(rows, config); - rows = padTableData(rows, config); - - const cellWidthIndex = calculateCellWidthIndex(rows[0]); - - return drawTable(rows, config.border, cellWidthIndex, rowHeightIndex, config.drawHorizontalLine, config.singleLine); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/truncateTableData.js b/tools/node_modules/eslint/node_modules/table/dist/truncateTableData.js index 72f8bfd8d261b1..8d0f7a31a4d669 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/truncateTableData.js +++ b/tools/node_modules/eslint/node_modules/table/dist/truncateTableData.js @@ -1,29 +1,19 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _lodash = _interopRequireDefault(require("lodash.truncate")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const lodash_truncate_1 = __importDefault(require("lodash.truncate")); /** * @todo Make it work with ASCII content. - * @param {table~row[]} rows - * @param {object} config - * @returns {table~row[]} */ -const truncateTableData = (rows, config) => { - return rows.map(cells => { - return cells.map((content, index) => { - return (0, _lodash.default)(content, { - length: config.columns[index].truncate - }); +exports.default = (rows, config) => { + return rows.map((cells) => { + return cells.map((content, index) => { + return lodash_truncate_1.default(content, { + length: config.columns[index].truncate, + omission: '…', + }); + }); }); - }); }; - -var _default = truncateTableData; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/truncateTableData.js.flow b/tools/node_modules/eslint/node_modules/table/dist/truncateTableData.js.flow deleted file mode 100644 index e78b7ec7898682..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/truncateTableData.js.flow +++ /dev/null @@ -1,17 +0,0 @@ -import truncate from 'lodash.truncate'; - -/** - * @todo Make it work with ASCII content. - * @param {table~row[]} rows - * @param {object} config - * @returns {table~row[]} - */ -export default (rows, config) => { - return rows.map((cells) => { - return cells.map((content, index) => { - return truncate(content, { - length: config.columns[index].truncate, - }); - }); - }); -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/types/api.js b/tools/node_modules/eslint/node_modules/table/dist/types/api.js new file mode 100644 index 00000000000000..c8ad2e549bdc68 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/table/dist/types/api.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tools/node_modules/eslint/node_modules/table/dist/types/internal.js b/tools/node_modules/eslint/node_modules/table/dist/types/internal.js new file mode 100644 index 00000000000000..c8ad2e549bdc68 --- /dev/null +++ b/tools/node_modules/eslint/node_modules/table/dist/types/internal.js @@ -0,0 +1,2 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); diff --git a/tools/node_modules/eslint/node_modules/table/dist/validateConfig.js b/tools/node_modules/eslint/node_modules/table/dist/validateConfig.js index b01a94b54aad0a..50d837c00ec7e0 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/validateConfig.js +++ b/tools/node_modules/eslint/node_modules/table/dist/validateConfig.js @@ -1,40 +1,23 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _validators = _interopRequireDefault(require("../dist/validators")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * @param {string} schemaId - * @param {formatData~config} config - * @returns {undefined} - */ -const validateConfig = (schemaId, config = {}) => { - const validate = _validators.default[schemaId]; - - if (!validate(config)) { - const errors = validate.errors.map(error => { - return { - dataPath: error.dataPath, - message: error.message, - params: error.params, - schemaPath: error.schemaPath - }; - }); - /* eslint-disable no-console */ - - console.log('config', config); - console.log('errors', errors); - /* eslint-enable no-console */ - - throw new Error('Invalid config.'); - } +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const validators_1 = __importDefault(require("./generated/validators")); +exports.default = (schemaId, config) => { + const validate = validators_1.default[schemaId]; + if (!validate(config) && validate.errors) { + const errors = validate.errors.map((error) => { + return { + message: error.message, + params: error.params, + schemaPath: error.schemaPath, + }; + }); + /* eslint-disable no-console */ + console.log('config', config); + console.log('errors', errors); + /* eslint-enable no-console */ + throw new Error('Invalid config.'); + } }; - -var _default = validateConfig; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/validateConfig.js.flow b/tools/node_modules/eslint/node_modules/table/dist/validateConfig.js.flow deleted file mode 100644 index 2873880b7577c1..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/validateConfig.js.flow +++ /dev/null @@ -1,27 +0,0 @@ -import validators from '../dist/validators'; - -/** - * @param {string} schemaId - * @param {formatData~config} config - * @returns {undefined} - */ -export default (schemaId, config = {}) => { - const validate = validators[schemaId]; - if (!validate(config)) { - const errors = validate.errors.map((error) => { - return { - dataPath: error.dataPath, - message: error.message, - params: error.params, - schemaPath: error.schemaPath, - }; - }); - - /* eslint-disable no-console */ - console.log('config', config); - console.log('errors', errors); - /* eslint-enable no-console */ - - throw new Error('Invalid config.'); - } -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/validateTableData.js b/tools/node_modules/eslint/node_modules/table/dist/validateTableData.js index d80c2e26612765..3a11457c714660 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/validateTableData.js +++ b/tools/node_modules/eslint/node_modules/table/dist/validateTableData.js @@ -1,54 +1,28 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -/** - * @typedef {string} cell - */ - -/** - * @typedef {cell[]} validateData~column - */ - -/** - * @param {column[]} rows - * @returns {undefined} - */ -const validateTableData = rows => { - if (!Array.isArray(rows)) { - throw new TypeError('Table data must be an array.'); - } - - if (rows.length === 0) { - throw new Error('Table must define at least one row.'); - } - - if (rows[0].length === 0) { - throw new Error('Table must define at least one column.'); - } - - const columnNumber = rows[0].length; - - for (const cells of rows) { - if (!Array.isArray(cells)) { - throw new TypeError('Table row data must be an array.'); +Object.defineProperty(exports, "__esModule", { value: true }); +exports.default = (rows) => { + if (!Array.isArray(rows)) { + throw new TypeError('Table data must be an array.'); } - - if (cells.length !== columnNumber) { - throw new Error('Table must have a consistent number of cells.'); + if (rows.length === 0) { + throw new Error('Table must define at least one row.'); } - - for (const cell of cells) { - // eslint-disable-next-line no-control-regex - if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) { - throw new Error('Table data must not contain control characters.'); - } + if (rows[0].length === 0) { + throw new Error('Table must define at least one column.'); + } + const columnNumber = rows[0].length; + for (const row of rows) { + if (!Array.isArray(row)) { + throw new TypeError('Table row data must be an array.'); + } + if (row.length !== columnNumber) { + throw new Error('Table must have a consistent number of cells.'); + } + for (const cell of row) { + // eslint-disable-next-line no-control-regex + if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) { + throw new Error('Table data must not contain control characters.'); + } + } } - } }; - -var _default = validateTableData; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/validateTableData.js.flow b/tools/node_modules/eslint/node_modules/table/dist/validateTableData.js.flow deleted file mode 100644 index dcc7fc1d139154..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/validateTableData.js.flow +++ /dev/null @@ -1,44 +0,0 @@ -/** - * @typedef {string} cell - */ - -/** - * @typedef {cell[]} validateData~column - */ - -/** - * @param {column[]} rows - * @returns {undefined} - */ -export default (rows) => { - if (!Array.isArray(rows)) { - throw new TypeError('Table data must be an array.'); - } - - if (rows.length === 0) { - throw new Error('Table must define at least one row.'); - } - - if (rows[0].length === 0) { - throw new Error('Table must define at least one column.'); - } - - const columnNumber = rows[0].length; - - for (const cells of rows) { - if (!Array.isArray(cells)) { - throw new TypeError('Table row data must be an array.'); - } - - if (cells.length !== columnNumber) { - throw new Error('Table must have a consistent number of cells.'); - } - - for (const cell of cells) { - // eslint-disable-next-line no-control-regex - if (/[\u0001-\u0006\u0008\u0009\u000B-\u001A]/.test(cell)) { - throw new Error('Table data must not contain control characters.'); - } - } - } -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/wrapCell.js b/tools/node_modules/eslint/node_modules/table/dist/wrapCell.js index 040787ddeb8a67..df64e7568c0756 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/wrapCell.js +++ b/tools/node_modules/eslint/node_modules/table/dist/wrapCell.js @@ -1,47 +1,47 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _wrapString = _interopRequireDefault(require("./wrapString")); - -var _wrapWord = _interopRequireDefault(require("./wrapWord")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const slice_ansi_1 = __importDefault(require("slice-ansi")); +const strip_ansi_1 = __importDefault(require("strip-ansi")); +const wrapString_1 = __importDefault(require("./wrapString")); +const wrapWord_1 = __importDefault(require("./wrapWord")); +const splitAnsi = (input) => { + const lengths = strip_ansi_1.default(input).split('\n').map(({ length }) => { + return length; + }); + const result = []; + let startIndex = 0; + lengths.forEach((length) => { + result.push(length === 0 ? '' : slice_ansi_1.default(input, startIndex, startIndex + length)); + // Plus 1 for the newline character itself + startIndex += length + 1; + }); + return result; +}; /** * Wrap a single cell value into a list of lines * * Always wraps on newlines, for the remainder uses either word or string wrapping * depending on user configuration. * - * @param {string} cellValue - * @param {number} columnWidth - * @param {boolean} useWrapWord - * @returns {Array} */ -const wrapCell = (cellValue, columnWidth, useWrapWord) => { - // First split on literal newlines - const cellLines = cellValue.split('\n'); // Then iterate over the list and word-wrap every remaining line if necessary. - - for (let lineNr = 0; lineNr < cellLines.length;) { - let lineChunks; - - if (useWrapWord) { - lineChunks = (0, _wrapWord.default)(cellLines[lineNr], columnWidth); - } else { - lineChunks = (0, _wrapString.default)(cellLines[lineNr], columnWidth); - } // Replace our original array element with whatever the wrapping returned - - - cellLines.splice(lineNr, 1, ...lineChunks); - lineNr += lineChunks.length; - } - - return cellLines; +exports.default = (cellValue, columnWidth, useWrapWord) => { + // First split on literal newlines + const cellLines = splitAnsi(cellValue); + // Then iterate over the list and word-wrap every remaining line if necessary. + for (let lineNr = 0; lineNr < cellLines.length;) { + let lineChunks; + if (useWrapWord) { + lineChunks = wrapWord_1.default(cellLines[lineNr], columnWidth); + } + else { + lineChunks = wrapString_1.default(cellLines[lineNr], columnWidth); + } + // Replace our original array element with whatever the wrapping returned + cellLines.splice(lineNr, 1, ...lineChunks); + lineNr += lineChunks.length; + } + return cellLines; }; - -var _default = wrapCell; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/wrapCell.js.flow b/tools/node_modules/eslint/node_modules/table/dist/wrapCell.js.flow deleted file mode 100644 index 0c66260e2599f9..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/wrapCell.js.flow +++ /dev/null @@ -1,35 +0,0 @@ -import wrapString from './wrapString'; -import wrapWord from './wrapWord'; - -/** - * Wrap a single cell value into a list of lines - * - * Always wraps on newlines, for the remainder uses either word or string wrapping - * depending on user configuration. - * - * @param {string} cellValue - * @param {number} columnWidth - * @param {boolean} useWrapWord - * @returns {Array} - */ -export default (cellValue, columnWidth, useWrapWord) => { - // First split on literal newlines - const cellLines = cellValue.split('\n'); - - // Then iterate over the list and word-wrap every remaining line if necessary. - for (let lineNr = 0; lineNr < cellLines.length;) { - let lineChunks; - - if (useWrapWord) { - lineChunks = wrapWord(cellLines[lineNr], columnWidth); - } else { - lineChunks = wrapString(cellLines[lineNr], columnWidth); - } - - // Replace our original array element with whatever the wrapping returned - cellLines.splice(lineNr, 1, ...lineChunks); - lineNr += lineChunks.length; - } - - return cellLines; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/wrapString.js b/tools/node_modules/eslint/node_modules/table/dist/wrapString.js index f97f798c450948..d61620857e2e17 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/wrapString.js +++ b/tools/node_modules/eslint/node_modules/table/dist/wrapString.js @@ -1,16 +1,10 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _sliceAnsi = _interopRequireDefault(require("slice-ansi")); - -var _stringWidth = _interopRequireDefault(require("string-width")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const slice_ansi_1 = __importDefault(require("slice-ansi")); +const string_width_1 = __importDefault(require("string-width")); /** * Creates an array of strings split into groups the length of size. * This function works with strings that contain ASCII characters. @@ -18,22 +12,13 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de * wrapText is different from would-be "chunk" implementation * in that whitespace characters that occur on a chunk size limit are trimmed. * - * @param {string} subject - * @param {number} size - * @returns {Array} */ -const wrapString = (subject, size) => { - let subjectSlice; - subjectSlice = subject; - const chunks = []; - - do { - chunks.push((0, _sliceAnsi.default)(subjectSlice, 0, size)); - subjectSlice = (0, _sliceAnsi.default)(subjectSlice, size).trim(); - } while ((0, _stringWidth.default)(subjectSlice)); - - return chunks; +exports.default = (subject, size) => { + let subjectSlice = subject; + const chunks = []; + do { + chunks.push(slice_ansi_1.default(subjectSlice, 0, size)); + subjectSlice = slice_ansi_1.default(subjectSlice, size).trim(); + } while (string_width_1.default(subjectSlice)); + return chunks; }; - -var _default = wrapString; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/wrapString.js.flow b/tools/node_modules/eslint/node_modules/table/dist/wrapString.js.flow deleted file mode 100644 index bbb40721e34f99..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/wrapString.js.flow +++ /dev/null @@ -1,29 +0,0 @@ -import slice from 'slice-ansi'; -import stringWidth from 'string-width'; - -/** - * Creates an array of strings split into groups the length of size. - * This function works with strings that contain ASCII characters. - * - * wrapText is different from would-be "chunk" implementation - * in that whitespace characters that occur on a chunk size limit are trimmed. - * - * @param {string} subject - * @param {number} size - * @returns {Array} - */ -export default (subject, size) => { - let subjectSlice; - - subjectSlice = subject; - - const chunks = []; - - do { - chunks.push(slice(subjectSlice, 0, size)); - - subjectSlice = slice(subjectSlice, size).trim(); - } while (stringWidth(subjectSlice)); - - return chunks; -}; diff --git a/tools/node_modules/eslint/node_modules/table/dist/wrapWord.js b/tools/node_modules/eslint/node_modules/table/dist/wrapWord.js index 52a8095ab5aa7d..bc864ace513b35 100644 --- a/tools/node_modules/eslint/node_modules/table/dist/wrapWord.js +++ b/tools/node_modules/eslint/node_modules/table/dist/wrapWord.js @@ -1,46 +1,39 @@ "use strict"; - -Object.defineProperty(exports, "__esModule", { - value: true -}); -exports.default = void 0; - -var _sliceAnsi = _interopRequireDefault(require("slice-ansi")); - -var _stringWidth = _interopRequireDefault(require("string-width")); - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } - -/** - * @param {string} input - * @param {number} size - * @returns {Array} - */ -const wrapWord = (input, size) => { - let subject; - subject = input; - const chunks = []; // https://regex101.com/r/gY5kZ1/1 - - const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))'); - - do { - let chunk; - chunk = subject.match(re); - - if (chunk) { - chunk = chunk[0]; - subject = (0, _sliceAnsi.default)(subject, (0, _stringWidth.default)(chunk)); - chunk = chunk.trim(); - } else { - chunk = (0, _sliceAnsi.default)(subject, 0, size); - subject = (0, _sliceAnsi.default)(subject, size); - } - - chunks.push(chunk); - } while ((0, _stringWidth.default)(subject)); - - return chunks; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const slice_ansi_1 = __importDefault(require("slice-ansi")); +const strip_ansi_1 = __importDefault(require("strip-ansi")); +const calculateStringLengths = (input, size) => { + let subject = strip_ansi_1.default(input); + const chunks = []; + // https://regex101.com/r/gY5kZ1/1 + const re = new RegExp('(^.{1,' + String(size) + '}(\\s+|$))|(^.{1,' + String(size - 1) + '}(\\\\|/|_|\\.|,|;|-))'); + do { + let chunk; + const match = re.exec(subject); + if (match) { + chunk = match[0]; + subject = subject.slice(chunk.length); + const trimmedLength = chunk.trim().length; + const offset = chunk.length - trimmedLength; + chunks.push([trimmedLength, offset]); + } + else { + chunk = subject.slice(0, size); + subject = subject.slice(size); + chunks.push([chunk.length, 0]); + } + } while (subject.length); + return chunks; +}; +exports.default = (input, size) => { + const result = []; + let startIndex = 0; + calculateStringLengths(input, size).forEach(([length, offset]) => { + result.push(slice_ansi_1.default(input, startIndex, startIndex + length)); + startIndex += length + offset; + }); + return result; }; - -var _default = wrapWord; -exports.default = _default; \ No newline at end of file diff --git a/tools/node_modules/eslint/node_modules/table/dist/wrapWord.js.flow b/tools/node_modules/eslint/node_modules/table/dist/wrapWord.js.flow deleted file mode 100644 index 02a8d45ea4c9bd..00000000000000 --- a/tools/node_modules/eslint/node_modules/table/dist/wrapWord.js.flow +++ /dev/null @@ -1,39 +0,0 @@ -import slice from 'slice-ansi'; -import stringWidth from 'string-width'; - -/** - * @param {string} input - * @param {number} size - * @returns {Array} - */ -export default (input, size) => { - let subject; - - subject = input; - - const chunks = []; - - // https://regex101.com/r/gY5kZ1/1 - const re = new RegExp('(^.{1,' + size + '}(\\s+|$))|(^.{1,' + (size - 1) + '}(\\\\|/|_|\\.|,|;|-))'); - - do { - let chunk; - - chunk = subject.match(re); - - if (chunk) { - chunk = chunk[0]; - - subject = slice(subject, stringWidth(chunk)); - - chunk = chunk.trim(); - } else { - chunk = slice(subject, 0, size); - subject = slice(subject, size); - } - - chunks.push(chunk); - } while (stringWidth(subject)); - - return chunks; -}; diff --git a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/compile/validate/keyword.js b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/compile/validate/keyword.js index 42b2e7a33759b6..47f6176b1109cf 100644 --- a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/compile/validate/keyword.js +++ b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/compile/validate/keyword.js @@ -99,7 +99,7 @@ function validSchemaType(schema, schemaType, allowUndefined = false) { : typeof schema == st || (allowUndefined && typeof schema == "undefined"))); } exports.validSchemaType = validSchemaType; -function validateKeywordUsage({ schema, opts, self }, def, keyword) { +function validateKeywordUsage({ schema, opts, self, errSchemaPath }, def, keyword) { /* istanbul ignore if */ if (Array.isArray(def.keyword) ? !def.keyword.includes(keyword) : def.keyword !== keyword) { throw new Error("ajv implementation error"); @@ -111,7 +111,8 @@ function validateKeywordUsage({ schema, opts, self }, def, keyword) { if (def.validateSchema) { const valid = def.validateSchema(schema[keyword]); if (!valid) { - const msg = "keyword value is invalid: " + self.errorsText(def.validateSchema.errors); + const msg = `keyword "${keyword}" value is invalid at path "${errSchemaPath}": ` + + self.errorsText(def.validateSchema.errors); if (opts.validateSchema === "log") self.logger.error(msg); else diff --git a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/core.js b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/core.js index 9eba9f49d9e1e8..a1aae13883da38 100644 --- a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/core.js +++ b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/core.js @@ -61,7 +61,7 @@ const deprecatedOptions = { const MAX_EXPRESSION = 200; // eslint-disable-next-line complexity function requiredOptions(o) { - var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u; + var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v; const s = o.strict; const _optz = (_a = o.code) === null || _a === void 0 ? void 0 : _a.optimize; const optimize = _optz === true || _optz === undefined ? 1 : _optz || 0; @@ -80,6 +80,7 @@ function requiredOptions(o) { addUsedSchema: (_s = o.addUsedSchema) !== null && _s !== void 0 ? _s : true, validateSchema: (_t = o.validateSchema) !== null && _t !== void 0 ? _t : true, validateFormats: (_u = o.validateFormats) !== null && _u !== void 0 ? _u : true, + unicodeRegExp: (_v = o.unicodeRegExp) !== null && _v !== void 0 ? _v : true, }; } class Ajv { diff --git a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js index 91672bc0846023..09da8547ec735b 100644 --- a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +++ b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js @@ -50,7 +50,7 @@ const def = { definedProp = codegen_1.nil; } if (patProps.length) { - definedProp = codegen_1.or(definedProp, ...patProps.map((p) => codegen_1._ `${code_1.usePattern(gen, p)}.test(${key})`)); + definedProp = codegen_1.or(definedProp, ...patProps.map((p) => codegen_1._ `${code_1.usePattern(cxt, p)}.test(${key})`)); } return codegen_1.not(definedProp); } diff --git a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js index 1f2f9fe71434cf..ff68c82e1061ec 100644 --- a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +++ b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js @@ -45,7 +45,7 @@ const def = { } function validateProperties(pat) { gen.forIn("key", data, (key) => { - gen.if(codegen_1._ `${code_1.usePattern(gen, pat)}.test(${key})`, () => { + gen.if(codegen_1._ `${code_1.usePattern(cxt, pat)}.test(${key})`, () => { cxt.subschema({ keyword: "patternProperties", schemaProp: pat, diff --git a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/code.js b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/code.js index 848a72c88f4c9b..c6f852daf9190f 100644 --- a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/code.js +++ b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/code.js @@ -65,11 +65,12 @@ function callValidateCode({ schemaCode, data, it: { gen, topSchemaRef, schemaPat return context !== codegen_1.nil ? codegen_1._ `${func}.call(${context}, ${args})` : codegen_1._ `${func}(${args})`; } exports.callValidateCode = callValidateCode; -function usePattern(gen, pattern) { +function usePattern({ gen, it: { opts } }, pattern) { + const u = opts.unicodeRegExp ? "u" : ""; return gen.scopeValue("pattern", { key: pattern, - ref: new RegExp(pattern, "u"), - code: codegen_1._ `new RegExp(${pattern}, "u")`, + ref: new RegExp(pattern, u), + code: codegen_1._ `new RegExp(${pattern}, ${u})`, }); } exports.usePattern = usePattern; diff --git a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/validation/pattern.js b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/validation/pattern.js index 7bb1587d98d5b5..b0862db342257f 100644 --- a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/validation/pattern.js +++ b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/dist/vocabularies/validation/pattern.js @@ -13,8 +13,10 @@ const def = { $data: true, error, code(cxt) { - const { gen, data, $data, schema, schemaCode } = cxt; - const regExp = $data ? codegen_1._ `(new RegExp(${schemaCode}, "u"))` : code_1.usePattern(gen, schema); // TODO regexp should be wrapped in try/catch + const { data, $data, schema, schemaCode, it } = cxt; + // TODO regexp should be wrapped in try/catchs + const u = it.opts.unicodeRegExp ? "u" : ""; + const regExp = $data ? codegen_1._ `(new RegExp(${schemaCode}, ${u}))` : code_1.usePattern(cxt, schema); cxt.fail$data(codegen_1._ `!${regExp}.test(${data})`); }, }; diff --git a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/package.json b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/package.json index ec9f333b117190..22f7a782c40b27 100644 --- a/tools/node_modules/eslint/node_modules/table/node_modules/ajv/package.json +++ b/tools/node_modules/eslint/node_modules/table/node_modules/ajv/package.json @@ -1,6 +1,6 @@ { "name": "ajv", - "version": "8.0.5", + "version": "8.1.0", "description": "Another JSON Schema Validator", "main": "dist/ajv.js", "types": "dist/ajv.d.ts", diff --git a/tools/node_modules/eslint/node_modules/table/package.json b/tools/node_modules/eslint/node_modules/table/package.json index c1e2f61bacdcd4..5d331e4b5287bf 100644 --- a/tools/node_modules/eslint/node_modules/table/package.json +++ b/tools/node_modules/eslint/node_modules/table/package.json @@ -6,43 +6,42 @@ }, "dependencies": { "ajv": "^8.0.1", - "is-boolean-object": "^1.1.0", - "is-number-object": "^1.0.4", - "is-string": "^1.0.5", "lodash.clonedeep": "^4.5.0", "lodash.flatten": "^4.4.0", "lodash.truncate": "^4.4.2", "slice-ansi": "^4.0.0", - "string-width": "^4.2.0" + "string-width": "^4.2.0", + "strip-ansi": "^6.0.0" }, "description": "Formats data into a string table.", "devDependencies": { - "@babel/cli": "^7.12.10", - "@babel/core": "^7.12.10", - "@babel/plugin-transform-flow-strip-types": "^7.12.10", - "@babel/preset-env": "^7.12.11", - "@babel/register": "^7.12.10", + "@types/chai": "^4.2.16", + "@types/lodash.clonedeep": "^4.5.6", + "@types/lodash.flatten": "^4.4.6", + "@types/lodash.mapvalues": "^4.6.6", + "@types/lodash.truncate": "^4.4.6", + "@types/mocha": "^8.2.2", + "@types/node": "^14.14.37", + "@types/sinon": "^10.0.0", + "@types/slice-ansi": "^4.0.0", "ajv-cli": "^5.0.0", "ajv-keywords": "^5.0.0", - "babel-plugin-istanbul": "^6.0.0", - "babel-plugin-transform-export-default-name": "^2.1.0", "chai": "^4.2.0", "chalk": "^4.1.0", "coveralls": "^3.1.0", "eslint": "^7.16.0", "eslint-config-canonical": "^25.0.0", - "flow-bin": "^0.141.0", - "flow-copy-source": "^2.0.9", "gitdown": "^3.1.3", "husky": "^4.3.6", "js-beautify": "^1.13.0", "lodash.mapvalues": "^4.6.0", - "lodash.random": "^3.2.0", - "lodash.sample": "^4.2.1", + "mkdirp": "^1.0.4", "mocha": "^8.2.1", "nyc": "^15.1.0", "semantic-release": "^17.3.1", - "sinon": "^9.2.2" + "sinon": "^9.2.2", + "ts-node": "^9.1.1", + "typescript": "4.2.4" }, "engines": { "node": ">=10.0.0" @@ -50,7 +49,7 @@ "husky": { "hooks": { "post-commit": "npm run create-readme && git add README.md && git commit -m 'docs: generate docs' --no-verify", - "pre-commit": "npm run lint && npm run test && npm run build" + "pre-commit": "npm run build && npm run lint && npm run test" } }, "keywords": [ @@ -62,30 +61,35 @@ ], "license": "BSD-3-Clause", "main": "./dist/index.js", + "files": [ + "dist/**/*.js", + "dist/**/*.d.ts" + ], "name": "table", "nyc": { - "include": [ - "src/**/*.js" + "extensions": [ + ".ts" + ], + "exclude": [ + "src/generated/validators.js", + "test/**/*.ts" ], - "instrument": false, "reporter": [ "text-lcov" - ], - "require": [ - "@babel/register" - ], - "sourceMap": false + ] }, "repository": { "type": "git", "url": "https://github.com/gajus/table" }, "scripts": { - "build": "rm -fr ./dist && NODE_ENV=production babel ./src --out-dir ./dist --copy-files && npm run create-validators && flow-copy-source src dist", + "compile": "tsc", + "prebuild": "rm -fr ./dist && mkdirp dist", + "build": "npm run create-validators && npm run compile", "create-readme": "gitdown ./.README/README.md --output-file ./README.md", - "create-validators": "ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > dist/validators.js", - "lint": "npm run build && eslint ./src ./test && flow", - "test": "mocha --require @babel/register" + "create-validators": "rm -fr ./src/generated && mkdirp ./src/generated && ajv compile --all-errors --inline-refs=false -s src/schemas/config -s src/schemas/streamConfig -r src/schemas/shared -c ajv-keywords/dist/keywords/typeof -o | js-beautify > ./src/generated/validators.js", + "lint": "eslint --ignore-path .gitignore ./src ./test", + "test": "npm run create-validators && mocha --require ts-node/register ./test/**/*.ts" }, - "version": "6.0.9" + "version": "6.5.1" } diff --git a/tools/node_modules/eslint/package.json b/tools/node_modules/eslint/package.json index b414ca6eae5671..4f87ef6403bc82 100644 --- a/tools/node_modules/eslint/package.json +++ b/tools/node_modules/eslint/package.json @@ -1,6 +1,6 @@ { "name": "eslint", - "version": "7.24.0", + "version": "7.25.0", "author": "Nicholas C. Zakas ", "description": "An AST-based pattern checker for JavaScript.", "bin": { @@ -27,10 +27,7 @@ "pre-commit": "lint-staged" }, "lint-staged": { - "*.js": [ - "eslint --fix", - "git add" - ], + "*.js": "eslint --fix", "*.md": "markdownlint" }, "files": [ @@ -103,7 +100,7 @@ "eslint-plugin-jsdoc": "^25.4.3", "eslint-plugin-node": "^11.1.0", "eslint-release": "^2.0.0", - "eslump": "^2.0.0", + "eslump": "^3.0.0", "esprima": "^4.0.1", "fs-teardown": "^0.1.0", "glob": "^7.1.6", diff --git a/tools/update-npm.sh b/tools/update-npm.sh index c106570d0b33dd..d58b325b77f713 100755 --- a/tools/update-npm.sh +++ b/tools/update-npm.sh @@ -11,25 +11,25 @@ if [ "$#" -le 0 ]; then exit 1 fi -WORKSPACE="$TMPDIR"update-npm-$NPM_VERSION/ +echo "Making temporary workspace" -if [ -d "$WORKSPACE" ]; then - echo "Cleaning up old workspace" - rm -rf "$WORKSPACE" -fi +WORKSPACE=$(mktemp -d 2> /dev/null || mktemp -d -t 'tmp') -echo "Making temporary workspace" +cleanup () { + EXIT_CODE=$? + [ -d "$WORKSPACE" ] && rm -rf "$WORKSPACE" + exit $EXIT_CODE +} -mkdir -p "$WORKSPACE" +trap cleanup INT TERM EXIT cd "$WORKSPACE" -git clone git@github.com:npm/cli.git +git clone --depth=1 --branch="v$NPM_VERSION" git@github.com:npm/cli.git cd cli echo "Preparing npm release" -git checkout v"$NPM_VERSION" make make release @@ -40,11 +40,7 @@ rm -rf npm/ echo "Copying new npm" -tar zxf "$WORKSPACE"cli/release/npm-"$NPM_VERSION".tgz - -echo "Deleting temporary workspace" - -rm -rf "$WORKSPACE" +tar zxf "$WORKSPACE"/cli/release/npm-"$NPM_VERSION".tgz echo "" echo "All done!" diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp index ccb5984f47d0d8..377e12d1fdcfbd 100644 --- a/tools/v8_gypfiles/v8.gyp +++ b/tools/v8_gypfiles/v8.gyp @@ -1378,6 +1378,9 @@ '<(V8_ROOT)/src/heap/base/worklist.h', ], 'conditions': [ + ['enable_lto=="true"', { + 'cflags_cc': [ '-fno-lto' ], + }], ['clang or OS!="win"', { 'conditions': [ ['_toolset == "host" and host_arch == "x64" or _toolset == "target" and target_arch=="x64"', { diff --git a/vcbuild.bat b/vcbuild.bat index 9e54fabd41681e..47e2f3b8337f06 100644 --- a/vcbuild.bat +++ b/vcbuild.bat @@ -282,7 +282,7 @@ goto msbuild-found :msbuild-not-found echo Failed to find a suitable Visual Studio installation. echo Try to run in a "Developer Command Prompt" or consult -echo https://github.com/nodejs/node/blob/master/BUILDING.md#windows +echo https://github.com/nodejs/node/blob/HEAD/BUILDING.md#windows goto exit :msbuild-found