Skip to content

Commit ccd02e8

Browse files
authored
fix(man-page): keep the last environment variable when its section ends the input (#1202)
Signed-off-by: kgeminicdev <kurtgeminicb@gmail.com>
1 parent 2d16eba commit ccd02e8

3 files changed

Lines changed: 67 additions & 2 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@node-core/doc-kit': patch
3+
---
4+
5+
The man page no longer drops the last environment variable when that section ends the input.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import assert from 'node:assert/strict';
2+
import { describe, it } from 'node:test';
3+
4+
import { setConfig } from '@doc-kit/core/utils/configuration/index.mjs';
5+
import { u } from 'unist-builder';
6+
7+
import { generate } from '../generate.mjs';
8+
9+
const config = await setConfig({ target: ['man-page'] });
10+
config['man-page'].output = undefined;
11+
12+
const entry = (depth, slug, text, description = '') => {
13+
const heading = u('heading', { depth }, [u('text', text)]);
14+
15+
return {
16+
heading: { depth, data: { slug, text } },
17+
content: u('root', [heading, u('paragraph', [u('text', description)])]),
18+
};
19+
};
20+
21+
describe('man-page generate', () => {
22+
it('keeps the last environment variable when the section ends the input', async () => {
23+
const input = [
24+
entry(1, 'command-line-api', 'Command-line API'),
25+
entry(2, 'environment-variables', 'Environment variables', 'Intro.'),
26+
entry(2, 'options', 'Options'),
27+
entry(3, '--foo', '`--foo`', 'Foo option.'),
28+
entry(2, 'environment-variables-1', 'Environment variables'),
29+
entry(3, 'node_onevalue', '`NODE_ONE=value`', 'First var.'),
30+
entry(3, 'node_twovalue', '`NODE_TWO=value`', 'Second var.'),
31+
entry(3, 'node_threevalue', '`NODE_THREE=value`', 'Third var.'),
32+
];
33+
34+
const output = await generate(input);
35+
36+
assert.match(output, /\.It Ev NODE_ONE Ar value\nFirst var\./);
37+
assert.match(output, /\.It Ev NODE_TWO Ar value\nSecond var\./);
38+
assert.match(output, /\.It Ev NODE_THREE Ar value\nThird var\./);
39+
});
40+
41+
it('stops the environment variables at the next section', async () => {
42+
const input = [
43+
entry(2, 'options', 'Options'),
44+
entry(3, '--foo', '`--foo`', 'Foo option.'),
45+
entry(2, 'environment-variables-1', 'Environment variables'),
46+
entry(3, 'node_onevalue', '`NODE_ONE=value`', 'First var.'),
47+
entry(2, 'useful-v8-options', 'Useful V8 options'),
48+
entry(3, '--max-old-space-size', '`--max-old-space-size=SIZE`', 'Heap.'),
49+
];
50+
51+
const output = await generate(input);
52+
53+
assert.match(output, /\.It Ev NODE_ONE Ar value\nFirst var\./);
54+
assert.doesNotMatch(output, /max-old-space-size/);
55+
});
56+
});

‎packages/node/src/man-page/generate.mjs‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ export async function generate(input) {
4343
({ heading }) => heading.data.slug === config.envVarsHeaderSlug
4444
);
4545

46-
// The first header that is <3 in depth after environmentStart
47-
const environmentEnd = input.findIndex(
46+
// The first header that is <3 in depth after environmentStart,
47+
// or the end of the input when the section is the last one
48+
const nextSectionStart = input.findIndex(
4849
({ heading }, index) => heading.depth < 3 && index > environmentStart
4950
);
5051

52+
const environmentEnd =
53+
nextSectionStart === -1 ? input.length : nextSectionStart;
54+
5155
const output = {
5256
// Extract the CLI options.
5357
options: extractMandoc(

0 commit comments

Comments
 (0)