Skip to content

Commit 548db88

Browse files
src: add -f alias for --experimental-config-file
1 parent 2071c44 commit 548db88

9 files changed

Lines changed: 77 additions & 9 deletions

File tree

doc/api/cli.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,7 +1045,7 @@ added:
10451045
10461046
Enable experimental import support for `.node` addons.
10471047

1048-
### `--experimental-config-file=path`, `--experimental-config-file`
1048+
### `-f`, `--experimental-config-file=path`, `--experimental-config-file`
10491049

10501050
<!-- YAML
10511051
added:
@@ -1058,8 +1058,11 @@ added:
10581058
If present, Node.js will look for a configuration file at the specified path.
10591059
If the path is not specified, Node.js will look for a `node.config.json` file
10601060
in the current working directory.
1061-
To specify a custom path, use the `--experimental-config-file=path` form.
1062-
The space-separated `--experimental-config-file path` form is not supported.
1061+
The short alias `-f` is equivalent to `--experimental-config-file`.
1062+
To specify a custom path, use the `-f=path` or
1063+
`--experimental-config-file=path` form.
1064+
The space-separated `-f path` and `--experimental-config-file path` forms are
1065+
not supported for specifying a config file path.
10631066
The alias `--experimental-default-config-file` is equivalent to
10641067
`--experimental-config-file` without an argument.
10651068
Node.js will read the configuration file and apply the settings. The

doc/api/test.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ test runner functionality:
751751
* `--test` - Prevented to avoid recursive test execution
752752
* `--experimental-test-coverage` - Managed by the test runner
753753
* `--watch` - Watch mode is handled at the parent level
754-
* `--experimental-default-config-file` - Config file loading is handled by the parent
754+
* `-f`, `--experimental-default-config-file` - Config file loading is handled by the parent
755755
* `--test-reporter` - Reporting is managed by the parent process
756756
* `--test-reporter-destination` - Output destinations are controlled by the parent
757757
* `--experimental-config-file` - Config file paths are managed by the parent
@@ -4535,7 +4535,7 @@ test.describe('my suite', (suite) => {
45354535
[`suite()`]: #suitename-options-fn
45364536
[`test()`]: #testname-options-fn
45374537
[code coverage]: #collecting-code-coverage
4538-
[configuration files]: cli.md#--experimental-config-filepath---experimental-config-file
4538+
[configuration files]: cli.md#-f---experimental-config-filepath---experimental-config-file
45394539
[describe options]: #describename-options-fn
45404540
[it options]: #testname-options-fn
45414541
[module customization hooks]: module.md#customization-hooks

doc/node.1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,12 +623,16 @@ It is possible to run code containing inline types unless the
623623
.It Fl -experimental-addon-modules
624624
Enable experimental import support for \fB.node\fR addons.
625625
.
626-
.It Fl -experimental-config-file= Ns Ar config , Fl -experimental-config-file , Fl -experimental-default-config-file
626+
.It Fl f , Fl -experimental-config-file= Ns Ar config , Fl -experimental-config-file , Fl -experimental-default-config-file
627627
If present, Node.js will look for a configuration file at the specified path.
628628
If the path is not specified, Node.js will look for a \fBnode.config.json\fR file
629629
in the current working directory.
630-
To specify a custom path, use the \fB--experimental-config-file=\fR\fBpath\fR form.
631-
The space-separated \fB--experimental-config-file path\fR form is not supported.
630+
The short alias \fB-f\fR is equivalent to \fB--experimental-config-file\fR.
631+
To specify a custom path, use the \fB-f=\fR\fBpath\fR or
632+
\fB--experimental-config-file=\fR\fBpath\fR form.
633+
The space-separated \fB-f path\fR and
634+
\fB--experimental-config-file path\fR forms are not supported for specifying a
635+
config file path.
632636
Node.js will read the configuration file and apply the settings. The
633637
configuration file should be a JSON file with the following structure. \fBvX.Y.Z\fR
634638
in the \fB$schema\fR must be replaced with the version of Node.js you are using.

src/node_config_file.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace node {
77
constexpr std::string_view kConfigFileFlag = "--experimental-config-file";
88
constexpr std::string_view kDefaultConfigFileFlag =
99
"--experimental-default-config-file";
10+
constexpr std::string_view kConfigFileShortFlag = "-f";
1011
constexpr std::string_view kDefaultConfigFileName = "node.config.json";
1112

1213
inline bool HasEqualsPrefix(std::string_view arg, std::string_view flag) {
@@ -27,13 +28,26 @@ std::optional<std::string_view> ConfigReader::GetDataFromArgs(
2728
arg = std::string(kConfigFileFlag) + "=" +
2829
std::string(kDefaultConfigFileName);
2930
result = kDefaultConfigFileName;
31+
} else if (arg == kConfigFileShortFlag) {
32+
// -f
33+
arg = std::string(kConfigFileFlag) + "=" +
34+
std::string(kDefaultConfigFileName);
35+
result = kDefaultConfigFileName;
3036
} else if (HasEqualsPrefix(arg, kConfigFileFlag)) {
3137
// --experimental-config-file=path
3238
std::string_view path =
3339
std::string_view(arg).substr(kConfigFileFlag.size() + 1);
3440
if (!path.empty()) {
3541
result = path;
3642
}
43+
} else if (HasEqualsPrefix(arg, kConfigFileShortFlag)) {
44+
// -f=path
45+
std::string path =
46+
std::string(arg).substr(kConfigFileShortFlag.size() + 1);
47+
arg = std::string(kConfigFileFlag) + "=" + std::string(path);
48+
if (!path.empty()) {
49+
result = std::string_view(arg).substr(kConfigFileFlag.size() + 1);
50+
}
3751
} else if (arg == kDefaultConfigFileFlag) {
3852
// --experimental-default-config-file
3953
arg = std::string(kConfigFileFlag) + "=" +

src/node_options.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -903,6 +903,7 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {
903903
"set config file path",
904904
&EnvironmentOptions::experimental_config_file_path,
905905
kDisallowedInEnvvar);
906+
AddAlias("-f", "--experimental-config-file");
906907
AddAlias("--experimental-default-config-file", "--experimental-config-file");
907908
AddOption("--test",
908909
"launch test runner on startup",

test/parallel/test-cli-node-options-docs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ for (const [, envVar, config] of nodeOptionsCC.matchAll(addOptionRE)) {
121121
}
122122

123123
// add alias handling
124+
manPagesOptions.delete('-f');
124125
manPagesOptions.delete('-trace-events-enabled');
125126
manPagesOptions.delete('-experimental-default-config-file');
126127

test/parallel/test-config-file.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,25 @@ test('should use node.config.json when --experimental-config-file has no argumen
358358
assert.strictEqual(result.code, 0);
359359
});
360360

361+
test('should use node.config.json when -f has no argument',
362+
onlyIfNodeOptionsSupport, async () => {
363+
const result = await spawnPromisified(process.execPath, [
364+
'--no-warnings',
365+
'-f',
366+
'-p', 'http.maxHeaderSize',
367+
], {
368+
cwd: fixtures.path('rc/default'),
369+
});
370+
assert.strictEqual(result.stderr, '');
371+
assert.strictEqual(result.stdout, '10\n');
372+
assert.strictEqual(result.code, 0);
373+
});
374+
361375
test('should not treat the script path as a config file argument',
362376
onlyIfNodeOptionsSupport, async () => {
363377
const result = await spawnPromisified(process.execPath, [
364378
'--no-warnings',
365-
'--experimental-config-file',
379+
'-f',
366380
fixtures.path('printA.js'),
367381
], {
368382
cwd: fixtures.path('rc/default'),
@@ -390,6 +404,18 @@ test('should treat a space-separated config file path as the script',
390404
assert.strictEqual(result.code, 1);
391405
});
392406

407+
test('should work with -f=path',
408+
onlyIfNodeOptionsSupport, async () => {
409+
const result = await spawnPromisified(process.execPath, [
410+
'--no-warnings',
411+
`-f=${fixtures.path('rc/default/node.config.json')}`,
412+
'-p', 'http.maxHeaderSize',
413+
]);
414+
assert.strictEqual(result.stderr, '');
415+
assert.strictEqual(result.stdout, '10\n');
416+
assert.strictEqual(result.code, 0);
417+
});
418+
393419
test('should error when --experimental-config-file= has empty argument',
394420
onlyIfNodeOptionsSupport, async () => {
395421
const result = await spawnPromisified(process.execPath, [
@@ -403,6 +429,19 @@ test('should error when --experimental-config-file= has empty argument',
403429
assert.strictEqual(result.code, 9);
404430
});
405431

432+
test('should error when -f= has empty argument',
433+
onlyIfNodeOptionsSupport, async () => {
434+
const result = await spawnPromisified(process.execPath, [
435+
'--no-warnings',
436+
'-f=',
437+
'-p', 'http.maxHeaderSize',
438+
], {
439+
cwd: fixtures.path('rc/default'),
440+
});
441+
assert.match(result.stderr, /--experimental-config-file= requires an argument/);
442+
assert.strictEqual(result.code, 9);
443+
});
444+
406445
test('should error when --experimental-default-config-file has an explicit argument',
407446
onlyIfNodeOptionsSupport, async () => {
408447
const result = await spawnPromisified(process.execPath, [

test/parallel/test-runner-cli.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ for (const isolation of ['none', 'process']) {
434434
// Should not propagate config file options to sub tests in isolation process.
435435
const fixturePath = join(testFixtures, 'options-propagation');
436436
const configFlagVariants = [
437+
['-f'],
438+
['-f=node.config.json'],
437439
['--experimental-config-file=node.config.json'],
438440
['--experimental-config-file'],
439441
['--experimental-default-config-file'],

test/parallel/test-runner-flag-propagation.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ const runner = path.join(fixtureDir, 'runner.mjs');
1515
describe('test runner flag propagation', () => {
1616
describe('via command line', () => {
1717
const flagPropagationTests = [
18+
['-f', '', '', '--experimental-config-file',
19+
'should not propagate -f to child tests'],
20+
['-f=node.config.json', '', '', '--experimental-config-file',
21+
'should not propagate -f=node.config.json to child tests'],
1822
['--experimental-config-file=node.config.json', '', '', '--experimental-config-file',
1923
'should not propagate --experimental-config-file to child tests'],
2024
['--experimental-default-config-file', '', '', '--experimental-config-file',

0 commit comments

Comments
 (0)