Skip to content

Commit

Permalink
docs: npm help json/global command on windows (#7496)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
klm-turing and lukekarrys authored May 9, 2024
1 parent 6d456bb commit c3d2819
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions docs/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,35 +93,45 @@ const run = async ({ content, template, nav, man, html, md }) => {
: []),
])

const aliases = [
fullName === 'configuring-npm/package-json' && 'configuring-npm/npm-json',
fullName === 'configuring-npm/folders' && 'configuring-npm/npm-global',
].filter(Boolean)

if (data.section) {
const manSrc = applyTransforms(transformedSrc, [
const manSource = applyTransforms(transformedSrc, [
transform.helpLinks,
transform.man,
])
const manPaths = [
name,
fullName === 'configuring-npm/package-json' && 'npm-json',
fullName === 'configuring-npm/folders' && 'npm-global',
].filter(Boolean).map(p => applyTransforms(p, [transform.manPath]))

acc.man.push(...manPaths.map((manPath) => ({
path: manPath,
fullPath: join(man, manPath),
src: manSrc,
})))
// Man page aliases are only the basename since the man pages have no hierarchy
acc.man.push(...[name, ...aliases.map(a => basename(a))]
.map((p) => applyTransforms(p, [transform.manPath]))
.map((manPath) => ({
path: manPath,
fullPath: join(man, manPath),
src: manSource,
}))
)
}

acc.html.push({
path: `${fullName}.html`,
fullPath: join(html, `${fullName}.html`),
src: applyTransforms(transformedSrc, [transform.html]),
})

// html docs are used for npm help on Windows
const htmlSource = applyTransforms(transformedSrc, [transform.html])
acc.html.push(...[fullName, ...aliases].map((htmlPath) => ({
path: `${htmlPath}.html`,
fullPath: join(html, `${htmlPath}.html`),
src: htmlSource,
})))

// Markdown pages don't get aliases here. These are used to build the website so any redirects
// for these pages are applied in npm/documentation. Not ideal but there are also many more
// redirects that we would never apply to man or html docs pages
const mdSource = applyTransforms(transformedSrc, [transform.md])
acc.md.push({
path: childPath,
fullPath: join(md, childPath),
src: applyTransforms(transformedSrc, [transform.md]),
src: mdSource,
})

return acc
}, { man: [], html: [], md: [] })

Expand Down

0 comments on commit c3d2819

Please sign in to comment.