Skip to content

Commit

Permalink
fix: allow for workspace patterns to start with ./ (#145)
Browse files Browse the repository at this point in the history
Closes #144
  • Loading branch information
wraithgar authored Apr 10, 2024
1 parent 8fa5cd9 commit e2a803b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ function appendNegatedPatterns (allPatterns) {
pattern = pattern.slice(excl[0].length)
}

// strip off any / from the start of the pattern. /foo => foo
pattern = pattern.replace(/^\/+/, '')
// strip off any / or ./ from the start of the pattern. /foo => foo
pattern = pattern.replace(/^\.?\/+/, '')

// an odd number of ! means a negated pattern. !!foo ==> foo
const negate = excl && excl[0].length % 2 === 1
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 @@ -156,6 +156,12 @@ Map {
}
`

exports[`test/test.js TAP workspaces config using relative path globs > should return a valid map 1`] = `
Map {
"a" => "{CWD}/test/tap-testdir-test-workspaces-config-using-relative-path-globs/packages/a",
}
`

exports[`test/test.js TAP workspaces config using simplistic glob > should return a valid map 1`] = `
Map {
"a" => "{CWD}/test/tap-testdir-test-workspaces-config-using-simplistic-glob/packages/a",
Expand Down
28 changes: 28 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@ test('workspaces config using simplistic glob', t => {
)
})

test('workspaces config using relative path globs', t => {
const cwd = t.testdir({
packages: {
a: {
'package.json': '{ "name": "a" }',
},
b: {
'package.json': '{ "name": "b" }',
},
},
})

return t.resolveMatchSnapshot(
mapWorkspaces({
cwd,
pkg: {
workspaces: {
packages: [
'./packages/*',
'!./packages/b',
],
},
},
}),
'should return a valid map'
)
})

test('duplicated workspaces config', t => {
const cwd = t.testdir({
packages: {
Expand Down

0 comments on commit e2a803b

Please # to comment.