Skip to content

Commit 9ea2603

Browse files
lukekarrysruyadorno
authored andcommitted
fix: normalize win32 paths before globbing
1 parent 0f2da5d commit 9ea2603

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

lib/commands/help-search.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const glob = promisify(require('glob'))
66
const readFile = promisify(fs.readFile)
77
const BaseCommand = require('../base-command.js')
88

9+
const globify = pattern => pattern.split('\\').join('/')
10+
911
class HelpSearch extends BaseCommand {
1012
static description = 'Search npm help documentation'
1113
static name = 'help-search'
@@ -19,7 +21,7 @@ class HelpSearch extends BaseCommand {
1921
}
2022

2123
const docPath = path.resolve(__dirname, '..', '..', 'docs/content')
22-
const files = await glob(`${docPath}/*/*.md`)
24+
const files = await glob(`${globify(docPath)}/*/*.md`)
2325
const data = await this.readFiles(files)
2426
const results = await this.searchFiles(args, data, files)
2527
const formatted = this.formatResults(args, results)

lib/commands/help.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const { promisify } = require('util')
55
const glob = promisify(require('glob'))
66
const localeCompare = require('@isaacs/string-locale-compare')('en')
77

8+
const globify = pattern => pattern.split('\\').join('/')
89
const BaseCommand = require('../base-command.js')
910

1011
// Strips out the number from foo.7 or foo.7. or foo.7.tgz
@@ -26,7 +27,7 @@ class Help extends BaseCommand {
2627
return []
2728
}
2829
const g = path.resolve(__dirname, '../../man/man[0-9]/*.[0-9]')
29-
const files = await glob(g)
30+
const files = await glob(globify(g))
3031

3132
return Object.keys(files.reduce(function (acc, file) {
3233
file = path.basename(file).replace(/\.[0-9]+$/, '')
@@ -61,7 +62,7 @@ class Help extends BaseCommand {
6162
const manroot = path.resolve(__dirname, '..', '..', 'man')
6263
// find either section.n or npm-section.n
6364
const f = `${manroot}/${manSearch}/?(npm-)${section}.[0-9]*`
64-
let mans = await glob(f)
65+
let mans = await glob(globify(f))
6566
mans = mans.sort((a, b) => {
6667
// Prefer the page with an npm prefix, if there's only one.
6768
const aHasPrefix = manNpmPrefixRegex.test(a)

lib/utils/log-file.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const fs = require('@npmcli/fs')
99
const log = require('./log-shim')
1010

1111
const padZero = (n, length) => n.toString().padStart(length.toString().length, '0')
12+
const globify = pattern => pattern.split('\\').join('/')
1213

1314
const _logHandler = Symbol('logHandler')
1415
const _formatLogItem = Symbol('formatLogItem')
@@ -225,7 +226,7 @@ class LogFiles {
225226
)
226227

227228
// Always ignore the currently written files
228-
const files = await glob(logGlob, { ignore: this.#files })
229+
const files = await glob(globify(logGlob), { ignore: this.#files.map(globify) })
229230
const toDelete = files.length - this.#logsMax
230231

231232
if (toDelete <= 0) {
@@ -236,7 +237,7 @@ class LogFiles {
236237

237238
for (const file of files.slice(0, toDelete)) {
238239
try {
239-
await rimraf(file)
240+
await rimraf(file, { glob: false })
240241
} catch (e) {
241242
log.silly('logfile', 'error removing log file', file, e)
242243
}

0 commit comments

Comments
 (0)