|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +constcommon=require('../common'); |
| 4 | + |
| 5 | +constassert=require('assert'); |
| 6 | +constfs=require('fs'); |
| 7 | +constpath=require('path'); |
| 8 | + |
| 9 | +constrootDir=path.resolve(__dirname,'..','..'); |
| 10 | +constcliMd=path.join(rootDir,'doc','api','cli.md'); |
| 11 | +constcliText=fs.readFileSync(cliMd,{encoding: 'utf8'}); |
| 12 | + |
| 13 | +constparseSection=(text,startMarker,endMarker)=>{ |
| 14 | +constregExp=newRegExp(`${startMarker}\r?\n([^]*)\r?\n${endMarker}`); |
| 15 | +constmatch=text.match(regExp); |
| 16 | +assert(match, |
| 17 | +`Unable to locate text between '${startMarker}' and '${endMarker}'.`); |
| 18 | +returnmatch[1].split(/\r?\n/); |
| 19 | +}; |
| 20 | + |
| 21 | +constnodeOptionsLines=parseSection(cliText, |
| 22 | +'<!-- node-options-node start -->', |
| 23 | +'<!-- node-options-node end -->'); |
| 24 | +constv8OptionsLines=parseSection(cliText, |
| 25 | +'<!-- node-options-v8 start -->', |
| 26 | +'<!-- node-options-v8 end -->'); |
| 27 | +// Check the options are documented in alphabetical order. |
| 28 | +assert.deepStrictEqual(nodeOptionsLines,[...nodeOptionsLines].sort()); |
| 29 | +assert.deepStrictEqual(v8OptionsLines,[...v8OptionsLines].sort()); |
| 30 | + |
| 31 | +constdocumented=newSet(); |
| 32 | +for(constlineof[...nodeOptionsLines, ...v8OptionsLines]){ |
| 33 | +for(constmatchofline.matchAll(/`(-[^`]+)`/g)){ |
| 34 | +constoption=match[1]; |
| 35 | +assert(!documented.has(option), |
| 36 | +`Option '${option}' was documented more than once as an `+ |
| 37 | +`allowed option for NODE_OPTIONS in ${cliMd}.`); |
| 38 | +documented.add(option); |
| 39 | +} |
| 40 | +} |
| 41 | + |
| 42 | +// Filter out options that are conditionally present. |
| 43 | +constconditionalOpts=[ |
| 44 | +{include: common.hasCrypto, |
| 45 | +filter: (opt)=>{ |
| 46 | +return['--openssl-config','--tls-cipher-list','--use-bundled-ca', |
| 47 | +'--use-openssl-ca'].includes(opt); |
| 48 | +}}, |
| 49 | +{include: common.hasFipsCrypto, |
| 50 | +filter: (opt)=>opt.includes('-fips')}, |
| 51 | +{include: common.hasIntl, |
| 52 | +filter: (opt)=>opt==='--icu-data-dir'}, |
| 53 | +{include: process.features.inspector, |
| 54 | +filter: (opt)=>opt.startsWith('--inspect')||opt==='--debug-port'}, |
| 55 | +{include: process.config.variables.node_report, |
| 56 | +filter: (opt)=>opt.includes('-report')}, |
| 57 | +]; |
| 58 | +documented.forEach((opt)=>{ |
| 59 | +conditionalOpts.forEach(({ include, filter })=>{ |
| 60 | +if(!include&&filter(opt)){ |
| 61 | +documented.delete(opt); |
| 62 | +} |
| 63 | +}); |
| 64 | +}); |
| 65 | + |
| 66 | +constdifference=(setA,setB)=>{ |
| 67 | +returnnewSet([...setA].filter((x)=>!setB.has(x))); |
| 68 | +}; |
| 69 | + |
| 70 | +constoverdocumented=difference(documented, |
| 71 | +process.allowedNodeEnvironmentFlags); |
| 72 | +assert.strictEqual(overdocumented.size,0, |
| 73 | +'The following options are documented as allowed in '+ |
| 74 | +`NODE_OPTIONS in ${cliMd}: `+ |
| 75 | +`${[...overdocumented].join(' ')} `+ |
| 76 | +'but are not in process.allowedNodeEnvironmentFlags'); |
| 77 | +constundocumented=difference(process.allowedNodeEnvironmentFlags, |
| 78 | +documented); |
| 79 | +// Remove intentionally undocumented options. |
| 80 | +assert(undocumented.delete('--debug-arraybuffer-allocations')); |
| 81 | +assert(undocumented.delete('--experimental-worker')); |
| 82 | +assert.strictEqual(undocumented.size,0, |
| 83 | +'The following options are not documented as allowed in '+ |
| 84 | +`NODE_OPTIONS in ${cliMd}: ${[...undocumented].join(' ')}`); |
0 commit comments