Skip to content

Commit c3d2819

Browse files
docs: npm help json/global command on windows (#7496)
On Windows, `npm help json` and `npm help global` attempt to display `npm-json.html` and `npm-global.html` files which leads to an error because these files have not been generated. This pull request duplicates the `package-json.md` and `folders.md` files in order to generate these files and make the above-mentioned commands functional. Closes: #7374 Co-authored-by: Luke Karrys <luke@lukekarrys.com>
1 parent 6d456bb commit c3d2819

File tree

1 file changed

+29
-19
lines changed

1 file changed

+29
-19
lines changed

docs/lib/build.js

+29-19
Original file line numberDiff line numberDiff line change
@@ -93,35 +93,45 @@ const run = async ({ content, template, nav, man, html, md }) => {
9393
: []),
9494
])
9595

96+
const aliases = [
97+
fullName === 'configuring-npm/package-json' && 'configuring-npm/npm-json',
98+
fullName === 'configuring-npm/folders' && 'configuring-npm/npm-global',
99+
].filter(Boolean)
100+
96101
if (data.section) {
97-
const manSrc = applyTransforms(transformedSrc, [
102+
const manSource = applyTransforms(transformedSrc, [
98103
transform.helpLinks,
99104
transform.man,
100105
])
101-
const manPaths = [
102-
name,
103-
fullName === 'configuring-npm/package-json' && 'npm-json',
104-
fullName === 'configuring-npm/folders' && 'npm-global',
105-
].filter(Boolean).map(p => applyTransforms(p, [transform.manPath]))
106-
107-
acc.man.push(...manPaths.map((manPath) => ({
108-
path: manPath,
109-
fullPath: join(man, manPath),
110-
src: manSrc,
111-
})))
106+
// Man page aliases are only the basename since the man pages have no hierarchy
107+
acc.man.push(...[name, ...aliases.map(a => basename(a))]
108+
.map((p) => applyTransforms(p, [transform.manPath]))
109+
.map((manPath) => ({
110+
path: manPath,
111+
fullPath: join(man, manPath),
112+
src: manSource,
113+
}))
114+
)
112115
}
113116

114-
acc.html.push({
115-
path: `${fullName}.html`,
116-
fullPath: join(html, `${fullName}.html`),
117-
src: applyTransforms(transformedSrc, [transform.html]),
118-
})
119-
117+
// html docs are used for npm help on Windows
118+
const htmlSource = applyTransforms(transformedSrc, [transform.html])
119+
acc.html.push(...[fullName, ...aliases].map((htmlPath) => ({
120+
path: `${htmlPath}.html`,
121+
fullPath: join(html, `${htmlPath}.html`),
122+
src: htmlSource,
123+
})))
124+
125+
// Markdown pages don't get aliases here. These are used to build the website so any redirects
126+
// for these pages are applied in npm/documentation. Not ideal but there are also many more
127+
// redirects that we would never apply to man or html docs pages
128+
const mdSource = applyTransforms(transformedSrc, [transform.md])
120129
acc.md.push({
121130
path: childPath,
122131
fullPath: join(md, childPath),
123-
src: applyTransforms(transformedSrc, [transform.md]),
132+
src: mdSource,
124133
})
134+
125135
return acc
126136
}, { man: [], html: [], md: [] })
127137

0 commit comments

Comments
 (0)