Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: avoid memory allocation on no-deprecation flag #50231

Merged
merged 3 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/internal/modules/esm/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ const emittedPackageWarnings = new SafeSet();
* @param {string} base - The URL of the module that imported the package.
*/
function emitTrailingSlashPatternDeprecation(match, pjsonUrl, base) {
if (process.noDeprecation) {
return;
}
const pjsonPath = fileURLToPath(pjsonUrl);
if (emittedPackageWarnings.has(pjsonPath + '|' + match)) { return; }
emittedPackageWarnings.add(pjsonPath + '|' + match);
Expand All @@ -101,6 +104,9 @@ const doubleSlashRegEx = /[/\\][/\\]/;
* @param {boolean} isTarget - Whether the target is a module.
*/
function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, internal, base, isTarget) {
if (process.noDeprecation) {
return;
}
const pjsonPath = fileURLToPath(pjsonUrl);
const double = RegExpPrototypeExec(doubleSlashRegEx, isTarget ? target : request) !== null;
process.emitWarning(
Expand All @@ -123,6 +129,9 @@ function emitInvalidSegmentDeprecation(target, request, match, pjsonUrl, interna
* @param {string} [main] - The "main" field from the package.json file.
*/
function emitLegacyIndexDeprecation(url, packageJSONUrl, base, main) {
if (process.noDeprecation) {
return;
}
const format = defaultGetFormatWithoutErrors(url);
if (format !== 'module') { return; }
const path = fileURLToPath(url);
Expand Down
5 changes: 5 additions & 0 deletions lib/internal/process/warning.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ function onWarning(warning) {
// process.emitWarning(str[, type[, code]][, ctor])
// process.emitWarning(str[, options])
function emitWarning(warning, type, code, ctor) {
// Fast path to avoid memory allocation,
// this doesn't eliminate the other if a few lines below
if (type === 'DeprecationWarning' && process.noDeprecation) {
H4ad marked this conversation as resolved.
Show resolved Hide resolved
return;
}
let detail;
if (type !== null && typeof type === 'object' && !ArrayIsArray(type)) {
ctor = type.ctor;
Expand Down