| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1025,7 +1025,40 @@ The configuration file supports namespace-specific options: | |||
| 1025 | 1025 | ||
| 1026 | 1026 | * The `nodeOptions` field contains CLI flags that are allowed in [`NODE_OPTIONS`][]. | |
| 1027 | 1027 | ||
| 1028 | - * Namespace fields like `test` contain configuration specific to that subsystem. | ||
| 1028 | + * Namespace fields like `test`, `watch`, and `permission` contain configuration specific to that subsystem. | ||
| 1029 | + | ||
| 1030 | + When a namespace is present in the | ||
| 1031 | + configuration file, Node.js automatically enables the corresponding flag | ||
| 1032 | + (e.g., `--test`, `--watch`, `--permission`). This allows you to configure | ||
| 1033 | + subsystem-specific options without explicitly passing the flag on the command line. | ||
| 1034 | + | ||
| 1035 | + For example: | ||
| 1036 | + | ||
| 1037 | + ```json | ||
| 1038 | + { | ||
| 1039 | + "test": { | ||
| 1040 | + "test-isolation": "process" | ||
| 1041 | + } | ||
| 1042 | + } | ||
| 1043 | + ``` | ||
| 1044 | + | ||
| 1045 | + is equivalent to: | ||
| 1046 | + | ||
| 1047 | + ```bash | ||
| 1048 | + node --test --test-isolation=process | ||
| 1049 | + ``` | ||
| 1050 | + | ||
| 1051 | + To disable the automatic flag while still using namespace options, you can | ||
| 1052 | + explicitly set the flag to `false` within the namespace: | ||
| 1053 | + | ||
| 1054 | + ```json | ||
| 1055 | + { | ||
| 1056 | + "test": { | ||
| 1057 | + "test": false, | ||
| 1058 | + "test-isolation": "process" | ||
| 1059 | + } | ||
| 1060 | + } | ||
| 1061 | + ``` | ||
| 1029 | 1062 | ||
| 1030 | 1063 | No-op flags are not supported. | |
| 1031 | 1064 | Not all V8 flags are currently supported. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -175,10 +175,11 @@ Example `node.config.json`: | |||
| 175 | 175 | } | |
| 176 | 176 | ``` | |
| 177 | 177 | ||
| 178 | - Run with the configuration file: | ||
| 178 | + When the `permission` namespace is present in the configuration file, Node.js | ||
| 179 | + automatically enables the `--permission` flag. Run with: | ||
| 179 | 180 | ||
| 180 | 181 | ```console | |
| 181 | - $ node --permission --experimental-default-config-file app.js | ||
| 182 | + $ node --experimental-default-config-file app.js | ||
| 182 | 183 | ``` | |
| 183 | 184 | ||
| 184 | 185 | #### Using the Permission Model with `npx` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -255,6 +255,9 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) { | |||
| 255 | 255 | available_namespaces.end()); | |
| 256 | 256 | // Create a set to track unique options | |
| 257 | 257 | std::unordered_set<std::string> unique_options; | |
| 258 | + // Namespaces in OPTION_NAMESPACE_LIST | ||
| 259 | + std::unordered_set<std::string> namespaces_with_implicit_flags; | ||
| 260 | + | ||
| 258 | 261 | // Iterate through the main object to find all namespaces | |
| 259 | 262 | for (auto field : main_object) { | |
| 260 | 263 | std::string_view field_name; | |
@@ -281,6 +284,15 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) { | |||
| 281 | 284 | continue; | |
| 282 | 285 | } | |
| 283 | 286 | ||
| 287 | + // List of implicit namespace flags | ||
| 288 | + for (auto ns_enum : options_parser::AllNamespaces()) { | ||
| 289 | + std::string ns_str = options_parser::NamespaceEnumToString(ns_enum); | ||
| 290 | + if (!ns_str.empty() && namespace_name == ns_str) { | ||
| 291 | + namespaces_with_implicit_flags.insert(namespace_name); | ||
| 292 | + break; | ||
| 293 | + } | ||
| 294 | + } | ||
| 295 | + | ||
| 284 | 296 | // Get the namespace object | |
| 285 | 297 | simdjson::ondemand::object namespace_object; | |
| 286 | 298 | auto field_error = field.value().get_object().get(namespace_object); | |
@@ -302,6 +314,17 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) { | |||
| 302 | 314 | } | |
| 303 | 315 | } | |
| 304 | 316 | ||
| 317 | + // Add implicit flags for namespaces (--test, --permission, --watch) | ||
| 318 | + // These flags are automatically enabled when their namespace is present | ||
| 319 | + for (const auto& ns : namespaces_with_implicit_flags) { | ||
| 320 | + std::string flag = "--" + ns; | ||
| 321 | + std::string no_flag = "--no-" + ns; | ||
| 322 | + // We skip if the user has already set the flag or its negation | ||
| 323 | + if (!unique_options.contains(flag) && !unique_options.contains(no_flag)) { | ||
| 324 | + namespace_options_.push_back(flag); | ||
| 325 | + } | ||
| 326 | + } | ||
| 327 | + | ||
| 305 | 328 | return ParseResult::Valid; | |
| 306 | 329 | } | |
| 307 | 330 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | "max-http-header-size": 8192 | |
| 5 | 5 | }, | |
| 6 | 6 | "test": { | |
| 7 | + "test": false, | ||
| 7 | 8 | "test-isolation": "none" | |
| 8 | 9 | } | |
| 9 | 10 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,3 @@ | |||
| 1 | 1 | { | |
| 2 | - "test": {} | ||
| 2 | + "permission": {} | ||
| 3 | 3 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "permission": { | ||
| 3 | + "allow-fs-read": "*" | ||
| 4 | + } | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + { | ||
| 2 | + "test": { | ||
| 3 | + "test": false, | ||
| 4 | + "test-isolation": "none" | ||
| 5 | + } | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,5 @@ | |||
| 1 | + { | ||
| 2 | + "watch": { | ||
| 3 | + "watch-preserve-output": true | ||
| 4 | + } | ||
| 5 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -407,6 +407,7 @@ describe('namespace-scoped options', () => { | |||
| 407 | 407 | '--expose-internals', | |
| 408 | 408 | '--experimental-config-file', | |
| 409 | 409 | fixtures.path('rc/namespaced/node.config.json'), | |
| 410 | + '--no-test', | ||
| 410 | 411 | '-p', 'require("internal/options").getOptionValue("--test-isolation")', | |
| 411 | 412 | ]); | |
| 412 | 413 | assert.strictEqual(result.stderr, ''); | |
@@ -483,6 +484,7 @@ describe('namespace-scoped options', () => { | |||
| 483 | 484 | '--test-isolation', 'process', | |
| 484 | 485 | '--experimental-config-file', | |
| 485 | 486 | fixtures.path('rc/namespaced/node.config.json'), | |
| 487 | + '--no-test', | ||
| 486 | 488 | '-p', 'require("internal/options").getOptionValue("--test-isolation")', | |
| 487 | 489 | ]); | |
| 488 | 490 | assert.strictEqual(result.stderr, ''); | |
@@ -498,6 +500,7 @@ describe('namespace-scoped options', () => { | |||
| 498 | 500 | '--test-coverage-exclude', 'cli-pattern2', | |
| 499 | 501 | '--experimental-config-file', | |
| 500 | 502 | fixtures.path('rc/namespace-with-array.json'), | |
| 503 | + '--no-test', | ||
| 501 | 504 | '-p', 'JSON.stringify(require("internal/options").getOptionValue("--test-coverage-exclude"))', | |
| 502 | 505 | ]); | |
| 503 | 506 | assert.strictEqual(result.stderr, ''); | |
@@ -520,6 +523,7 @@ describe('namespace-scoped options', () => { | |||
| 520 | 523 | '--expose-internals', | |
| 521 | 524 | '--experimental-config-file', | |
| 522 | 525 | fixtures.path('rc/namespace-with-disallowed-envvar.json'), | |
| 526 | + '--no-test', | ||
| 523 | 527 | '-p', 'require("internal/options").getOptionValue("--test-concurrency")', | |
| 524 | 528 | ]); | |
| 525 | 529 | assert.strictEqual(result.stderr, ''); | |
@@ -536,6 +540,7 @@ describe('namespace-scoped options', () => { | |||
| 536 | 540 | '--test-concurrency', '2', | |
| 537 | 541 | '--experimental-config-file', | |
| 538 | 542 | fixtures.path('rc/namespace-with-disallowed-envvar.json'), | |
| 543 | + '--no-test', | ||
| 539 | 544 | '-p', 'require("internal/options").getOptionValue("--test-concurrency")', | |
| 540 | 545 | ]); | |
| 541 | 546 | assert.strictEqual(result.stderr, ''); | |
@@ -554,4 +559,41 @@ describe('namespace-scoped options', () => { | |||
| 554 | 559 | assert.strictEqual(result.stdout, ''); | |
| 555 | 560 | assert.strictEqual(result.code, 9); | |
| 556 | 561 | }); | |
| 562 | + | ||
| 563 | + it('should automatically enable --test flag when test namespace is present', async () => { | ||
| 564 | + const result = await spawnPromisified(process.execPath, [ | ||
| 565 | + '--no-warnings', | ||
| 566 | + '--experimental-config-file', | ||
| 567 | + fixtures.path('rc/namespaced/node.config.json'), | ||
| 568 | + fixtures.path('rc/test.js'), | ||
| 569 | + ]); | ||
| 570 | + assert.strictEqual(result.code, 0); | ||
| 571 | + assert.match(result.stdout, /tests 1/); | ||
| 572 | + }); | ||
| 573 | + | ||
| 574 | + it('should automatically enable --permission flag when permission namespace is present', async () => { | ||
| 575 | + const result = await spawnPromisified(process.execPath, [ | ||
| 576 | + '--no-warnings', | ||
| 577 | + '--expose-internals', | ||
| 578 | + '--experimental-config-file', | ||
| 579 | + fixtures.path('rc/permission-namespace.json'), | ||
| 580 | + '-p', 'require("internal/options").getOptionValue("--permission")', | ||
| 581 | + ]); | ||
| 582 | + assert.strictEqual(result.stderr, ''); | ||
| 583 | + assert.strictEqual(result.stdout, 'true\n'); | ||
| 584 | + assert.strictEqual(result.code, 0); | ||
| 585 | + }); | ||
| 586 | + | ||
| 587 | + it('should respect explicit test: false in test namespace', async () => { | ||
| 588 | + const result = await spawnPromisified(process.execPath, [ | ||
| 589 | + '--no-warnings', | ||
| 590 | + '--expose-internals', | ||
| 591 | + '--experimental-config-file', | ||
| 592 | + fixtures.path('rc/test-namespace-explicit-false.json'), | ||
| 593 | + '-p', 'require("internal/options").getOptionValue("--test")', | ||
| 594 | + ]); | ||
| 595 | + assert.strictEqual(result.stderr, ''); | ||
| 596 | + assert.strictEqual(result.stdout, 'false\n'); | ||
| 597 | + assert.strictEqual(result.code, 0); | ||
| 598 | + }); | ||
| 557 | 599 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments