Skip to content

Commit

Permalink
fix: normalize win32 paths before globbing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Apr 21, 2022
1 parent 8d266c6 commit badd195
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/commands/help-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const glob = promisify(require('glob'))
const readFile = promisify(fs.readFile)
const BaseCommand = require('../base-command.js')

const globify = pattern => pattern.split('\\').join('/')

class HelpSearch extends BaseCommand {
static description = 'Search npm help documentation'
static name = 'help-search'
Expand All @@ -19,7 +21,7 @@ class HelpSearch extends BaseCommand {
}

const docPath = path.resolve(__dirname, '..', '..', 'docs/content')
const files = await glob(`${docPath}/*/*.md`)
const files = await glob(`${globify(docPath)}/*/*.md`)
const data = await this.readFiles(files)
const results = await this.searchFiles(args, data, files)
const formatted = this.formatResults(args, results)
Expand Down
5 changes: 3 additions & 2 deletions lib/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { promisify } = require('util')
const glob = promisify(require('glob'))
const localeCompare = require('@isaacs/string-locale-compare')('en')

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

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

return Object.keys(files.reduce(function (acc, file) {
file = path.basename(file).replace(/\.[0-9]+$/, '')
Expand Down Expand Up @@ -61,7 +62,7 @@ class Help extends BaseCommand {
const manroot = path.resolve(__dirname, '..', '..', 'man')
// find either section.n or npm-section.n
const f = `${manroot}/${manSearch}/?(npm-)${section}.[0-9]*`
let mans = await glob(f)
let mans = await glob(globify(f))
mans = mans.sort((a, b) => {
// Prefer the page with an npm prefix, if there's only one.
const aHasPrefix = manNpmPrefixRegex.test(a)
Expand Down
5 changes: 3 additions & 2 deletions lib/utils/log-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const fs = require('@npmcli/fs')
const log = require('./log-shim')

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

const _logHandler = Symbol('logHandler')
const _formatLogItem = Symbol('formatLogItem')
Expand Down Expand Up @@ -225,7 +226,7 @@ class LogFiles {
)

// Always ignore the currently written files
const files = await glob(logGlob, { ignore: this.#files })
const files = await glob(globify(logGlob), { ignore: this.#files })
const toDelete = files.length - this.#logsMax

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

for (const file of files.slice(0, toDelete)) {
try {
await rimraf(file)
await rimraf(file, { glob: false })
} catch (e) {
log.silly('logfile', 'error removing log file', file, e)
}
Expand Down

0 comments on commit badd195

Please sign in to comment.