Skip to content

Commit 0a0b416

Browse files
H4adUlisesGascon
authored andcommitted
lib: avoid memory allocation on nodeprecation flag
PR-URL: #50231 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent fffc495 commit 0a0b416

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

lib/internal/modules/esm/resolve.js

+9
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ const emittedPackageWarnings = new SafeSet();
7575
* @param {string} base - The URL of the module that imported the package.
7676
*/
7777
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
78+
if (process.noDeprecation) {
79+
return;
80+
}
7881
const pjsonPath = fileURLToPath(pjsonUrl);
7982
if (emittedPackageWarnings.has(pjsonPath + '|' + match)) { return; }
8083
emittedPackageWarnings.add(pjsonPath + '|' + match);
@@ -101,6 +104,9 @@ const doubleSlashRegEx = /[/\\][/\\]/;
101104
* @param {boolean} isTarget - Whether the target is a module.
102105
*/
103106
function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, internal, base, isTarget) {
107+
if (process.noDeprecation) {
108+
return;
109+
}
104110
const pjsonPath = fileURLToPath(pjsonUrl);
105111
const double = RegExpPrototypeExec(doubleSlashRegEx, isTarget ? target : request) !== null;
106112
process.emitWarning(
@@ -123,6 +129,9 @@ function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, interna
123129
* @param {string} [main] - The "main" field from the package.json file.
124130
*/
125131
function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) {
132+
if (process.noDeprecation) {
133+
return;
134+
}
126135
const format = defaultGetFormatWithoutErrors(url);
127136
if (format !== 'module') { return; }
128137
const path = fileURLToPath(url);

lib/internal/process/warning.js

+5
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,11 @@ function onWarning(warning) {
127127
// process.emitWarning(str[, type[, code]][, ctor])
128128
// process.emitWarning(str[, options])
129129
function emitWarning(warning, type, code, ctor) {
130+
// Fast path to avoid memory allocation,
131+
// this doesn't eliminate the other if a few lines below
132+
if (process.noDeprecation && type === 'DeprecationWarning') {
133+
return;
134+
}
130135
let detail;
131136
if (type !== null && typeof type === 'object' && !ArrayIsArray(type)) {
132137
ctor = type.ctor;

0 commit comments

Comments
 (0)