Skip to content

Commit ef89c2f

Browse files
geeksilva97aduh95
authored andcommitted
src,test: fix config file parsing for flags defaulted to true
PR-URL: #59110 Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
1 parent 1a44265 commit ef89c2f

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/node_config_file.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ ParseResult ConfigReader::ProcessOptionValue(
5555
if (result) {
5656
// If the value is true, we need to set the flag
5757
output->push_back(option_name);
58+
} else {
59+
// Ensure negation is made putting the "--no-" prefix
60+
output->push_back("--no-" +
61+
option_name.substr(2, option_name.size() - 2));
5862
}
5963

6064
break;

test/fixtures/rc/warnings-false.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"nodeOptions": {
3+
"warnings": false
4+
}
5+
}

test/parallel/test-config-file.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,17 @@ test('should parse boolean flag', async () => {
6060
strictEqual(result.code, 0);
6161
});
6262

63+
test('should parse boolean flag defaulted to true', async () => {
64+
const result = await spawnPromisified(process.execPath, [
65+
'--experimental-config-file',
66+
fixtures.path('rc/warnings-false.json'),
67+
'-p', 'process.emitWarning("A warning")',
68+
]);
69+
strictEqual(result.stderr, '');
70+
strictEqual(result.stdout, 'undefined\n');
71+
strictEqual(result.code, 0);
72+
});
73+
6374
test('should throw an error when a flag is declared twice', async () => {
6475
const result = await spawnPromisified(process.execPath, [
6576
'--no-warnings',

0 commit comments

Comments
 (0)