process: move setup of process warnings into node.js
To clarify the side effects and conditions of the warning setup during bootstrap. PR-URL: https://github.com/nodejs/node/pull/25263 Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Minwoo Jung <minwoo@nodesource.com>
This commit is contained in:
parent
d28980c464
commit
0878b6172e
@ -107,7 +107,15 @@ function startup() {
|
|||||||
process.exit = wrapped.exit;
|
process.exit = wrapped.exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
NativeModule.require('internal/process/warning').setup();
|
const {
|
||||||
|
onWarning,
|
||||||
|
emitWarning
|
||||||
|
} = NativeModule.require('internal/process/warning');
|
||||||
|
if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') {
|
||||||
|
process.on('warning', onWarning);
|
||||||
|
}
|
||||||
|
process.emitWarning = emitWarning;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
nextTick,
|
nextTick,
|
||||||
runNextTicks
|
runNextTicks
|
||||||
|
@ -3,8 +3,6 @@
|
|||||||
const prefix = `(${process.release.name}:${process.pid}) `;
|
const prefix = `(${process.release.name}:${process.pid}) `;
|
||||||
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
|
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;
|
||||||
|
|
||||||
exports.setup = setupProcessWarnings;
|
|
||||||
|
|
||||||
// Lazily loaded
|
// Lazily loaded
|
||||||
let fs;
|
let fs;
|
||||||
let fd;
|
let fd;
|
||||||
@ -51,9 +49,7 @@ function doEmitWarning(warning) {
|
|||||||
return () => process.emit('warning', warning);
|
return () => process.emit('warning', warning);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setupProcessWarnings() {
|
function onWarning(warning) {
|
||||||
if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') {
|
|
||||||
process.on('warning', (warning) => {
|
|
||||||
if (!(warning instanceof Error)) return;
|
if (!(warning instanceof Error)) return;
|
||||||
const isDeprecation = warning.name === 'DeprecationWarning';
|
const isDeprecation = warning.name === 'DeprecationWarning';
|
||||||
if (isDeprecation && process.noDeprecation) return;
|
if (isDeprecation && process.noDeprecation) return;
|
||||||
@ -78,13 +74,12 @@ function setupProcessWarnings() {
|
|||||||
return writeToFile(msg);
|
return writeToFile(msg);
|
||||||
}
|
}
|
||||||
writeOut(msg);
|
writeOut(msg);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// process.emitWarning(error)
|
// process.emitWarning(error)
|
||||||
// process.emitWarning(str[, type[, code]][, ctor])
|
// process.emitWarning(str[, type[, code]][, ctor])
|
||||||
// process.emitWarning(str[, options])
|
// process.emitWarning(str[, options])
|
||||||
process.emitWarning = (warning, type, code, ctor, now) => {
|
function emitWarning(warning, type, code, ctor, now) {
|
||||||
let detail;
|
let detail;
|
||||||
if (type !== null && typeof type === 'object' && !Array.isArray(type)) {
|
if (type !== null && typeof type === 'object' && !Array.isArray(type)) {
|
||||||
ctor = type.ctor;
|
ctor = type.ctor;
|
||||||
@ -129,5 +124,9 @@ function setupProcessWarnings() {
|
|||||||
}
|
}
|
||||||
if (now) process.emit('warning', warning);
|
if (now) process.emit('warning', warning);
|
||||||
else process.nextTick(doEmitWarning(warning));
|
else process.nextTick(doEmitWarning(warning));
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
onWarning,
|
||||||
|
emitWarning
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user