| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cee0154 commit d49c89e
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,6 +8,7 @@ constexpr std::string_view kConfigFileFlag = "--experimental-config-file"; | |||
| 8 | 8 | constexpr std::string_view kDefaultConfigFileFlag = | |
| 9 | 9 | "--experimental-default-config-file"; | |
| 10 | 10 | constexpr std::string_view kDefaultConfigFileName = "node.config.json"; | |
| 11 | + constexpr std::string_view kSchemaField = "$schema"; | ||
| 11 | 12 | ||
| 12 | 13 | inline bool HasEqualsPrefix(std::string_view arg, std::string_view flag) { | |
| 13 | 14 | return arg.size() > flag.size() && arg.starts_with(flag) && | |
@@ -290,10 +291,14 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) { | |||
| 290 | 291 | return ParseResult::InvalidContent; | |
| 291 | 292 | } | |
| 292 | 293 | ||
| 294 | + if (namespace_name == kSchemaField) { | ||
| 295 | + continue; | ||
| 296 | + } | ||
| 297 | + | ||
| 293 | 298 | // Check if this field is a valid namespace | |
| 294 | 299 | if (!valid_namespaces.contains(namespace_name)) { | |
| 295 | - // If not, skip it | ||
| 296 | - continue; | ||
| 300 | + FPrintF(stderr, "Unknown namespace %s\n", namespace_name); | ||
| 301 | + return ParseResult::InvalidContent; | ||
| 297 | 302 | } | |
| 298 | 303 | ||
| 299 | 304 | // List of implicit namespace flags | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + { | ||
| 2 | + "$schema": "https://nodejs.org/dist/vX.Y.Z/docs/node-config-schema.json", | ||
| 3 | + "nodeOptions": { | ||
| 4 | + "max-http-header-size": 10 | ||
| 5 | + } | ||
| 6 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -517,14 +517,26 @@ describe('namespace-scoped options', () => { | |||
| 517 | 517 | assert.strictEqual(result.code, 9); | |
| 518 | 518 | }); | |
| 519 | 519 | ||
| 520 | - it('should not throw an error when a namespace is not recognised', async () => { | ||
| 520 | + it('should throw an error when a namespace is not recognised', async () => { | ||
| 521 | 521 | const result = await spawnPromisified(process.execPath, [ | |
| 522 | 522 | '--no-warnings', | |
| 523 | 523 | `--experimental-config-file=${fixtures.path('rc/unknown-namespace.json')}`, | |
| 524 | 524 | '-p', '"Hello, World!"', | |
| 525 | 525 | ]); | |
| 526 | + assert.match(result.stderr, /Unknown namespace an-invalid-namespace/); | ||
| 527 | + assert.match(result.stderr, /unknown-namespace\.json: invalid content/); | ||
| 528 | + assert.strictEqual(result.stdout, ''); | ||
| 529 | + assert.strictEqual(result.code, 9); | ||
| 530 | + }); | ||
| 531 | + | ||
| 532 | + it('should allow the $schema field', async () => { | ||
| 533 | + const result = await spawnPromisified(process.execPath, [ | ||
| 534 | + '--no-warnings', | ||
| 535 | + `--experimental-config-file=${fixtures.path('rc/schema.json')}`, | ||
| 536 | + '-p', 'http.maxHeaderSize', | ||
| 537 | + ]); | ||
| 526 | 538 | assert.strictEqual(result.stderr, ''); | |
| 527 | - assert.strictEqual(result.stdout, 'Hello, World!\n'); | ||
| 539 | + assert.strictEqual(result.stdout, '10\n'); | ||
| 528 | 540 | assert.strictEqual(result.code, 0); | |
| 529 | 541 | }); | |
| 530 | 542 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments