Skip to content

Commit 21362cc

Browse files
cjihrigaduh95
authored andcommitted
punycode: limit deprecation warning
DEP0040 is an extremely annoying warning. Most of the people seeing it cannot do anything about it. This commit updates the warning logic to only emit outside of node_modules. This is similar to other warnings such as the Buffer() constructor warning. Ideally, this should be backported to Node 22. Refs: #47202 PR-URL: #56632 Reviewed-By: Jordan Harband <[email protected]> Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Joyee Cheung <[email protected]>
1 parent 56b2148 commit 21362cc

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

lib/punycode.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
'use strict';
2-
3-
process.emitWarning(
4-
'The `punycode` module is deprecated. Please use a userland ' +
5-
'alternative instead.',
6-
'DeprecationWarning',
7-
'DEP0040',
8-
);
2+
const {
3+
isInsideNodeModules,
4+
} = internalBinding('util');
5+
6+
if (!isInsideNodeModules(100, true)) {
7+
process.emitWarning(
8+
'The `punycode` module is deprecated. Please use a userland ' +
9+
'alternative instead.',
10+
'DeprecationWarning',
11+
'DEP0040',
12+
);
13+
}
914

1015
/** Highest positive signed 32-bit float value */
1116
const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
node:punycode:49
1+
node:punycode:54
22
throw new RangeError(errors[type]);
33
^
44

55
RangeError: Invalid input
6-
at error (node:punycode:49:8)
7-
at Object.decode (node:punycode:242:5)
6+
at error (node:punycode:54:8)
7+
at Object.decode (node:punycode:247:5)
88
at Object.<anonymous> (*core_line_numbers.js:13:10)
99

1010
Node.js *

0 commit comments

Comments
 (0)