We currently ignore invalid `main` entries in package.json files.
This does not seem to be very user friendly as it's certainly an
error if the `main` entry is not a valid file name. So instead of
trying to resolve the file otherwise, throw an error immediately to
improve the user experience.
To keep it backwards compatible `index.js` files in the same directory
as the `package.json` will continue to be resolved instead but that
behavior is now deprecated.
PR-URL: https://github.com/nodejs/node/pull/26823
Fixes: https://github.com/nodejs/node/issues/26588
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
There are lots of places that validate for arrayBufferView and we
have multiple functions that do the same thing. Instead, move the
validation into `internal/validators` so all files can use that
instead.
There are more functions throughout the code that do the same but
it takes some more work to fully consolidate all of those.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This renames the parameters for clarity and removes the check for
undefined encoding. That will always default to `utf8`.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The function does not only validate the input but it causes side
effects by adding default options to the input object in case the
option is not set.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This function did not only validate the input but it returned a new
value in case the hostname was valid. This simplifies the function
by always returning the required value, no matter if it is valid or
invalid, so the callee site does not have to check that anymore. On
top the function is renamed to `getHostname` to make clear that the
function does not only validate the input but it also returns a new
value.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The function did not only validate the input so far but it also made
a copy of the input object and returned that copy to the callee
function. That copy was not necessary for all call sites and it was
not obvious that the function did not only validate the input but
that it also returned a copy of it. This makes sure the function does
nothing more than validation and copying is happening in the callee
function when required.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The name indicated only validation while it did much more and it
returned a different value to the callee function. The underscore
was also not necessary as the function is internal one way or the
other.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The function did not only validate the timer but it caused side
effects like a warning and potentially returned a different value
than the input value. Thus the name `validate` did not seem to be
appropriate.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This makes sure the validation functions do not cause any side
effects. Validation functions should ideally only validate the input
without any other effect. Since the input value must be known from
the callee, there is no reason to return the input value.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The function did not only validate the mode but it returns a new
value depending on the input. Thus `validate` did not seem to be an
appropriate name.
PR-URL: https://github.com/nodejs/node/pull/26809
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Edit the "How Can I Help?" section of the Collaborator Guide to keep
sentences simple, short, and direct.
PR-URL: https://github.com/nodejs/node/pull/26895
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Since `process.binding('inspector')` is loaded during bootstrap,
simply set `process.binding('inspector').callAndPauseOnStart`
unconditionally instead of relying on `agent->WillWaitForConnect()`
which depends on runtime states,
PR-URL: https://github.com/nodejs/node/pull/26793
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Instead of relying on the value of the CLI option when
executing bootstrap/loaders.js.
PR-URL: https://github.com/nodejs/node/pull/26759
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
It is possible to require the 'process' module and with the upcoming
support for ES Modules, importing 'process' might be the more favorable
way for developers. This commit adds that option to the documentation.
PR-URL: https://github.com/nodejs/node/pull/26792
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Myles Borins <myles.borins@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Replace `require('util').inspect` and `require('util').format` with
`require('util/internal/inspect').inspect` and
`require('util/internal/inspect').format` in `lib/internal/errors.js`.
PR-URL: https://github.com/nodejs/node/pull/26782
Refs: https://github.com/nodejs/node/issues/26546
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/26821
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This makes sure that the described default behavior for the
`terminal` option is actually always used and not only when running
the REPL as standalone program.
The options code is now logically combined instead of being spread
out in the big REPL constructor.
PR-URL: https://github.com/nodejs/node/pull/26518
Reviewed-By: Lance Ball <lball@redhat.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
The error provided in this function could come from user code. Thus
the error should not be manipulated in any way. The added properties
do not seem to provide any actual value either as can not be part
of the error. The `hostname` is already set on the error and adding
the `host` property with the identical value does not seem right in
this case.
PR-URL: https://github.com/nodejs/node/pull/26751
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Currently, when configured --without-inspector the following warning
will be generated:
../src/node.cc:859:1: warning: unused label 'exit' [-Wunused-label]
exit:
This commit adds a guard to exclude the label when there is no
inspector support.
PR-URL: https://github.com/nodejs/node/pull/26801
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
99 out of a 100 times (conservative estimate!) the negotiated protocol
will be either "h2" or "http/1.1" so reuse an existing JS string for
those instead of creating a new one every time.
PR-URL: https://github.com/nodejs/node/pull/26836
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Use `require('internal/util/inspect').inspect` and
`require('internal/util/debuglog').debuglog` instead of
`require('util').debuglog` and `require('util').inspect`.
PR-URL: https://github.com/nodejs/node/pull/26807
Refs: https://github.com/nodejs/node/issues/26546
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Use `require('internal/util/debuglog').debuglog` and
`require('internal/util').promisify`
instead of `require('util').debuglog` and `require('util').promisify` in
`lib/internal/modules/translators.js`.
PR-URL: https://github.com/nodejs/node/pull/26806
Refs: https://github.com/nodejs/node/issues/26546
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>