Skip to content

Commit

Permalink
fix: normalize backslashes
Browse files Browse the repository at this point in the history
The next semver-major of minimatch does not allow backslashes.  We'll
normalize it here so that change doesn't break anyone currently relying
on that behavior.
  • Loading branch information
wraithgar committed Feb 17, 2022
1 parent e441074 commit 777e4d3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function pkgPathmame (opts) {

// make sure glob pattern only matches folders
function getGlobPattern (pattern) {
pattern = pattern.replace(/\\/g, '/')
return pattern.endsWith('/')
? pattern
: `${pattern}/`
Expand Down
6 changes: 6 additions & 0 deletions tap-snapshots/test/test.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/test.js TAP backslashes are normalized > matches with backslashes 1`] = `
Map {
"a" => "{CWD}/test/tap-testdir-test-backslashes-are-normalized/packages/a",
}
`

exports[`test/test.js TAP double negate patterns > should include doubly-negated items into resulting map 1`] = `
Map {
"a" => "{CWD}/test/tap-testdir-test-double-negate-patterns/packages/a",
Expand Down
22 changes: 22 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,3 +771,25 @@ test('try to declare node_modules', t => {
'should not include declared packages within node_modules'
)
})

test('backslashes are normalized', t => {
const cwd = t.testdir({
packages: {
a: {
'package.json': '{ "name": "a" }',
},
},
})

return t.resolveMatchSnapshot(
mapWorkspaces({
cwd,
pkg: {
workspaces: [
'packages\\*',
],
},
}),
'matches with backslashes'
)
})

0 comments on commit 777e4d3

Please sign in to comment.