Skip to content

Commit

Permalink
punycode: limit deprecation warning
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
cjihrig authored Jan 18, 2025
1 parent 6f946c9 commit 840f952
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
19 changes: 12 additions & 7 deletions lib/punycode.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
'use strict';

process.emitWarning(
'The `punycode` module is deprecated. Please use a userland ' +
'alternative instead.',
'DeprecationWarning',
'DEP0040',
);
const {
isInsideNodeModules,
} = internalBinding('util');

if (!isInsideNodeModules(100, true)) {
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
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/errors/core_line_numbers.snapshot
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
node:punycode:49
node:punycode:54
throw new RangeError(errors[type]);
^

RangeError: Invalid input
at error (node:punycode:49:8)
at Object.decode (node:punycode:242:5)
at error (node:punycode:54:8)
at Object.decode (node:punycode:247:5)
at Object.<anonymous> (*core_line_numbers.js:13:10)

Node.js *

0 comments on commit 840f952

Please sign in to comment.