Skip to content

Commit cc951b7

Browse files
committed
fixup! fix: npm help json/global command on windows
1 parent a0dcf44 commit cc951b7

File tree

2 files changed

+39
-36
lines changed

2 files changed

+39
-36
lines changed

docs/lib/build.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ const pAll = async (obj) => {
2828
}, {})
2929
}
3030

31-
const run = async (params) => {
32-
const { content, template, nav, man, html, md } = params
31+
const run = async ({ content, template, nav, man, html, md }) => {
3332
await rmAll(man, html, md)
3433
const [contentPaths, navFile, options] = await Promise.all([
3534
readDocs(content),
@@ -92,37 +91,47 @@ const run = async (params) => {
9291
...(fullName === 'using-npm/config'
9392
? [transform.shorthands, transform.config]
9493
: []),
95-
]);
96-
97-
['man', 'html', 'md'].forEach((type) => {
98-
const isMan = type === 'man'
99-
const DUPLICATED_FOLDER_PATH = 'configuring-npm/'
100-
const FOLDER_PREFIX = isMan ? '' : DUPLICATED_FOLDER_PATH
101-
const trs = [transform[type]]
102-
103-
let paths = [
104-
isMan ? name : fullName,
105-
fullName === `${DUPLICATED_FOLDER_PATH}package-json` && `${FOLDER_PREFIX}npm-json`,
106-
fullName === `${DUPLICATED_FOLDER_PATH}folders` && `${FOLDER_PREFIX}npm-global`,
107-
].filter(Boolean)
108-
109-
if (isMan && data.section) {
110-
paths = paths.map(p => applyTransforms(p, [transform.manPath]))
111-
trs.unshift(transform.helpLinks)
112-
const manSrc = applyTransforms(transformedSrc, trs)
113-
acc.man.push(...paths.map((manPath) => ({
94+
])
95+
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+
101+
if (data.section) {
102+
const manSource = applyTransforms(transformedSrc, [
103+
transform.helpLinks,
104+
transform.man,
105+
])
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) => ({
114110
path: manPath,
115111
fullPath: join(man, manPath),
116-
src: manSrc,
117-
})))
118-
} else {
119-
acc[type].push(...paths.map((path) => ({
120-
path: `${path}.${type}`,
121-
fullPath: join(params[type], `${path}.${type}`),
122-
src: applyTransforms(transformedSrc, trs),
123-
})))
124-
}
112+
src: manSource,
113+
}))
114+
)
115+
}
116+
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])
129+
acc.md.push({
130+
path: childPath,
131+
fullPath: join(md, childPath),
132+
src: mdSource,
125133
})
134+
126135
return acc
127136
}, { man: [], html: [], md: [] })
128137

docs/lib/content/nav.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,6 @@
215215
- title: Folders
216216
url: /configuring-npm/folders
217217
description: Folder structures used by npm
218-
- title: Folders
219-
url: /configuring-npm/npm-global
220-
description: Folder structures used by npm
221218
- title: .npmrc
222219
url: /configuring-npm/npmrc
223220
description: The npm config files
@@ -227,9 +224,6 @@
227224
- title: package.json
228225
url: /configuring-npm/package-json
229226
description: Specifics of npm's package.json handling
230-
- title: package.json
231-
url: /configuring-npm/npm-json
232-
description: Specifics of npm's package.json handling
233227
- title: package-lock.json
234228
url: /configuring-npm/package-lock-json
235229
description: A manifestation of the manifest

0 commit comments

Comments
 (0)