@@ -3,7 +3,6 @@ import assert from 'node:assert';
33import { createReadStream , readFileSync } from 'node:fs' ;
44import { createInterface } from 'node:readline' ;
55import { resolve , join } from 'node:path' ;
6- import { EOL } from 'node:os' ;
76
87// This test checks that all the CLI flags defined in the public CLI documentation (doc/api/cli.md)
98// are also documented in the manpage file (doc/node.1)
@@ -18,48 +17,6 @@ const cliMdContentsStream = createReadStream(cliMdPath);
1817const manPagePath = join ( rootDir , 'doc' , 'node.1' ) ;
1918const manPageContents = readFileSync ( manPagePath , { encoding : 'utf8' } ) ;
2019
21- // TODO(dario-piotrowicz): add the missing flags to the node.1 and remove this set
22- // (refs: https://github.com/nodejs/node/issues/58895)
23- const knownFlagsMissingFromManPage = new Set ( [
24- 'build-snapshot' ,
25- 'build-snapshot-config' ,
26- 'disable-sigusr1' ,
27- 'disable-warning' ,
28- 'dns-result-order' ,
29- 'enable-network-family-autoselection' ,
30- 'env-file-if-exists' ,
31- 'env-file' ,
32- 'experimental-network-inspection' ,
33- 'experimental-print-required-tla' ,
34- 'experimental-require-module' ,
35- 'experimental-sea-config' ,
36- 'experimental-worker-inspection' ,
37- 'expose-gc' ,
38- 'force-node-api-uncaught-exceptions-policy' ,
39- 'import' ,
40- 'network-family-autoselection-attempt-timeout' ,
41- 'no-async-context-frame' ,
42- 'no-experimental-detect-module' ,
43- 'no-experimental-global-navigator' ,
44- 'no-experimental-require-module' ,
45- 'no-network-family-autoselection' ,
46- 'openssl-legacy-provider' ,
47- 'openssl-shared-config' ,
48- 'report-dir' ,
49- 'report-directory' ,
50- 'report-exclude-env' ,
51- 'report-exclude-network' ,
52- 'run' ,
53- 'snapshot-blob' ,
54- 'trace-env' ,
55- 'trace-env-js-stack' ,
56- 'trace-env-native-stack' ,
57- 'trace-require-module' ,
58- 'use-system-ca' ,
59- 'watch-preserve-output' ,
60- ] ) ;
61-
62- const optionsEncountered = { dash : 0 , dashDash : 0 , named : 0 } ;
6320let insideOptionsSection = false ;
6421
6522const rl = createInterface ( {
@@ -84,54 +41,21 @@ for await (const line of rl) {
8441 }
8542
8643 if ( insideOptionsSection && isOptionLineRegex . test ( line ) ) {
87- if ( line === '### `-`' ) {
88- if ( ! manPageContents . includes ( `${ EOL } .It Sy -${ EOL } ` ) ) {
89- throw new Error ( `The \`-\` flag is missing in the \`doc/node.1\` file` ) ;
90- }
91- optionsEncountered . dash ++ ;
92- continue ;
93- }
94-
95- if ( line === '### `--`' ) {
96- if ( ! manPageContents . includes ( `${ EOL } .It Fl -${ EOL } ` ) ) {
97- throw new Error ( `The \`--\` flag is missing in the \`doc/node.1\` file` ) ;
98- }
99- optionsEncountered . dashDash ++ ;
100- continue ;
101- }
102-
10344 const flagNames = extractFlagNames ( line ) ;
45+ const flagMatcher = new RegExp ( `^\\.It ${ flagNames . map ( ( f ) => `Fl ${ f } .*` ) . join ( ', ' ) } $` , 'm' ) ;
10446
105- optionsEncountered . named += flagNames . length ;
106-
107- const manLine = `.It ${ flagNames
108- . map ( ( flag ) => `Fl ${ flag . length > 1 ? '-' : '' } ${ flag } ` )
109- . join ( ' , ' ) } `;
110-
111- if (
112- // Note: we don't check the full line (note the EOL only at the beginning) because
113- // options can have arguments and we do want to ignore those
114- ! manPageContents . includes ( `${ EOL } ${ manLine } ` ) &&
115- ! flagNames . every ( ( flag ) => knownFlagsMissingFromManPage . has ( flag ) ) ) {
47+ if ( ! manPageContents . match ( flagMatcher ) ) {
11648 assert . fail (
11749 `The following flag${
11850 flagNames . length === 1 ? '' : 's'
11951 } (present in \`doc/api/cli.md\`) ${ flagNames . length === 1 ? 'is' : 'are' } missing in the \`doc/node.1\` file: ${
120- flagNames . map ( ( flag ) => `"${ flag } "` ) . join ( ', ' )
52+ flagNames . map ( ( flag ) => `"- ${ flag } "` ) . join ( ', ' )
12153 } `
12254 ) ;
12355 }
12456 }
12557}
12658
127- assert . strictEqual ( optionsEncountered . dash , 1 ) ;
128-
129- assert . strictEqual ( optionsEncountered . dashDash , 1 ) ;
130-
131- assert ( optionsEncountered . named > 0 ,
132- 'Unexpectedly not even a single cli flag/option was detected when scanning the `doc/cli.md` file'
133- ) ;
134-
13559/**
13660 * Function that given a string containing backtick enclosed cli flags
13761 * separated by `, ` returns the name of flags present in the string
@@ -145,11 +69,8 @@ function extractFlagNames(str) {
14569 return [ ] ;
14670 }
14771 return match . map ( ( flag ) => {
148- // Remove the backticks from the flag
149- flag = flag . slice ( 1 , - 1 ) ;
150-
151- // Remove the dash or dashes
152- flag = flag . replace ( / ^ - - ? / , '' ) ;
72+ // Remove the backticks, and leading dash from the flag
73+ flag = flag . slice ( 2 , - 1 ) ;
15374
15475 // If the flag contains parameters make sure to remove those
15576 const nameDelimiters = [ '=' , ' ' , '[' ] ;
0 commit comments