mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
fs: move DEP0187 to End-of-Life
Passing an invalid argument type to fs.existsSync() now throws ERR_INVALID_ARG_TYPE instead of returning false. Other invalid paths, such as strings containing null bytes or non-file: URLs, continue to return false. This has been a runtime deprecation since v24.0.0. Refs: https://github.com/nodejs/node/pull/55753 Refs: https://github.com/nodejs/node/pull/55892 Assisted-by: Claude Signed-off-by: James M Snell <jasnell@gmail.com> PR-URL: https://github.com/nodejs/node/pull/67494 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day> Reviewed-By: LiviaMedeiros <livia@cirno.name> Reviewed-By: Richard Lau <richard.lau@ibm.com>
This commit is contained in:
1 parent
f8dd0aae2f
commit
d77ed7854e
4 files changed
+21
-16
No files matched your search
@@ -4207,6 +4207,9 @@ npx codemod@latest @nodejs/repl-classes-with-new
|
||||
|
||||
<!-- YAML
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/67494
|
||||
description: End-of-Life.
|
||||
- version: v24.0.0
|
||||
pr-url: https://github.com/nodejs/node/pull/55753
|
||||
description: Runtime deprecation.
|
||||
@@ -4218,10 +4221,10 @@ changes:
|
||||
description: Documentation-only.
|
||||
-->
|
||||
|
||||
Type: Runtime
|
||||
Type: End-of-Life
|
||||
|
||||
Passing non-supported argument types is deprecated and, instead of returning `false`,
|
||||
will throw an error in a future version.
|
||||
Passing non-supported argument types to `fs.existsSync()` throws an
|
||||
`ERR_INVALID_ARG_TYPE` error instead of returning `false`.
|
||||
|
||||
### DEP0188: `process.features.ipv6` and `process.features.uv`
|
||||
|
||||
|
||||
+6
-1
@@ -6299,6 +6299,10 @@ behavior is similar to `cp dir1/ dir2/`.
|
||||
<!-- YAML
|
||||
added: v0.1.21
|
||||
changes:
|
||||
- version: REPLACEME
|
||||
pr-url: https://github.com/nodejs/node/pull/67494
|
||||
description: Passing an invalid argument type now throws an
|
||||
`ERR_INVALID_ARG_TYPE` error instead of returning `false`.
|
||||
- version: v7.6.0
|
||||
pr-url: https://github.com/nodejs/node/pull/10739
|
||||
description: The `path` parameter can be a WHATWG `URL` object using
|
||||
@@ -6308,7 +6312,8 @@ changes:
|
||||
* `path` {string|Buffer|URL}
|
||||
* Returns: {boolean}
|
||||
|
||||
Returns `true` if the path exists, `false` otherwise.
|
||||
Returns `true` if the path exists, `false` otherwise. Throws an
|
||||
`ERR_INVALID_ARG_TYPE` error if `path` is not a string, {Buffer}, or {URL}.
|
||||
|
||||
For detailed information, see the documentation of the asynchronous version of
|
||||
this API: [`fs.exists()`][].
|
||||
|
||||
@@ -310,11 +310,11 @@ ObjectDefineProperty(exists, kCustomPromisifiedSymbol, {
|
||||
},
|
||||
});
|
||||
|
||||
let showExistsDeprecation = true;
|
||||
/**
|
||||
* Synchronously tests whether or not the given path exists.
|
||||
* @param {string | Buffer | URL} path
|
||||
* @returns {boolean}
|
||||
* @throws {ERR_INVALID_ARG_TYPE} If `path` is not a string, Buffer, or URL.
|
||||
*/
|
||||
function existsSync(path) {
|
||||
const h = vfsState.handlers;
|
||||
@@ -325,12 +325,7 @@ function existsSync(path) {
|
||||
try {
|
||||
path = getValidatedPath(path);
|
||||
} catch (err) {
|
||||
if (showExistsDeprecation && err?.code === 'ERR_INVALID_ARG_TYPE') {
|
||||
process.emitWarning(
|
||||
'Passing invalid argument types to fs.existsSync is deprecated', 'DeprecationWarning', 'DEP0187',
|
||||
);
|
||||
showExistsDeprecation = false;
|
||||
}
|
||||
if (err?.code === 'ERR_INVALID_ARG_TYPE') throw err;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,11 @@ fs.exists({}, common.mustCall(function(y) {
|
||||
assert(fs.existsSync(f));
|
||||
assert(!fs.existsSync(`${f}-NO`));
|
||||
|
||||
// fs.existsSync() never throws
|
||||
const msg = 'Passing invalid argument types to fs.existsSync is deprecated';
|
||||
common.expectWarning('DeprecationWarning', msg, 'DEP0187');
|
||||
assert(!fs.existsSync());
|
||||
assert(!fs.existsSync({}));
|
||||
// fs.existsSync() throws on invalid argument types
|
||||
assert.throws(() => fs.existsSync(), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => fs.existsSync({}), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
assert.throws(() => fs.existsSync(123), { code: 'ERR_INVALID_ARG_TYPE' });
|
||||
|
||||
// Other invalid paths still return false instead of throwing
|
||||
assert(!fs.existsSync(new URL('https://foo')));
|
||||
assert(!fs.existsSync('foo\u0000bar'));
|
||||
Reference in new issue
Block a user