Skip to content

Generated patterns in Windows are incompatible with micromatch #17

Closed
@yhatt

Description

@yhatt

dir-glob is using path.join() so it will use \\ as join separator in Windows. It would not compatible with micromatch that reserves backslashes for escaping glob characters.
https://github.com/micromatch/micromatch/#backslashes

It means that the generated glob pattern may not work correctly in Windows environment.

const dirGlob = require('dir-glob')
const micromatch = require('micromatch')

const patterns = dirGlob.sync(['lib'])

console.log(patterns)
console.log(micromatch(['lib/index.js'], patterns))
# POSIX environment
$ node ./test.js
[ 'lib/**' ]
[ 'lib/index.js' ]

# Windows
$ node ./test.js
[ 'lib\\**' ]
[]

I think we should always use slashes to join path by using path.posix.join(), or provide a option to choose how to join.

It came from working in the upgrade of fast-glob in globby's PR: sindresorhus/globby#126 (review)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions