src: remove internalBinding('config').warningFile
Instead use `require('internal/options')` lazily. Also refactor the call site a bit so that the option is queried only once since it's synchronous anyway. PR-URL: https://github.com/nodejs/node/pull/24959 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
7ee61fb3e5
commit
e989269865
@ -1,11 +1,18 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const config = internalBinding('config');
|
|
||||||
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;
|
exports.setup = setupProcessWarnings;
|
||||||
|
|
||||||
|
let options;
|
||||||
|
function lazyOption(name) {
|
||||||
|
if (!options) {
|
||||||
|
options = require('internal/options');
|
||||||
|
}
|
||||||
|
return options.getOptionValue(name);
|
||||||
|
}
|
||||||
|
|
||||||
var cachedFd;
|
var cachedFd;
|
||||||
var acquiringFd = false;
|
var acquiringFd = false;
|
||||||
function nop() {}
|
function nop() {}
|
||||||
@ -49,11 +56,11 @@ function onAcquired(message) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function acquireFd(cb) {
|
function acquireFd(warningFile, cb) {
|
||||||
if (cachedFd === undefined && !acquiringFd) {
|
if (cachedFd === undefined && !acquiringFd) {
|
||||||
acquiringFd = true;
|
acquiringFd = true;
|
||||||
if (fs === null) fs = require('fs');
|
if (fs === null) fs = require('fs');
|
||||||
fs.open(config.warningFile, 'a', onOpen(cb));
|
fs.open(warningFile, 'a', onOpen(cb));
|
||||||
} else if (cachedFd !== undefined && !acquiringFd) {
|
} else if (cachedFd !== undefined && !acquiringFd) {
|
||||||
cb(null, cachedFd);
|
cb(null, cachedFd);
|
||||||
} else {
|
} else {
|
||||||
@ -62,8 +69,9 @@ function acquireFd(cb) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function output(message) {
|
function output(message) {
|
||||||
if (typeof config.warningFile === 'string') {
|
const warningFile = lazyOption('--redirect-warnings');
|
||||||
acquireFd(onAcquired(message));
|
if (warningFile) {
|
||||||
|
acquireFd(warningFile, onAcquired(message));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
writeOut(message);
|
writeOut(message);
|
||||||
|
@ -90,11 +90,6 @@ static void Initialize(Local<Object> target,
|
|||||||
"bits",
|
"bits",
|
||||||
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
|
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
|
||||||
|
|
||||||
const std::string& warning_file = env->options()->redirect_warnings;
|
|
||||||
if (!warning_file.empty()) {
|
|
||||||
READONLY_STRING_PROPERTY(target, "warningFile", warning_file);
|
|
||||||
}
|
|
||||||
|
|
||||||
Local<Object> debug_options_obj = Object::New(isolate);
|
Local<Object> debug_options_obj = Object::New(isolate);
|
||||||
READONLY_PROPERTY(target, "debugOptions", debug_options_obj);
|
READONLY_PROPERTY(target, "debugOptions", debug_options_obj);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user