Skip to content

Commit

Permalink
Return '.' instead of '' when matching cwd
Browse files Browse the repository at this point in the history
Fix: #519
  • Loading branch information
isaacs committed Apr 11, 2023
1 parent 93efe71 commit d6e8645
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ export abstract class GlobUtil<O extends GlobWalkerOpts = GlobWalkerOpts> {
this.opts.dotRelative && !rel.startsWith('..' + this.#sep)
? '.' + this.#sep
: ''
this.matchEmit(!rel && mark ? '.' + mark : pre + rel + mark)
this.matchEmit(!rel ? '.' + mark : pre + rel + mark)
}
}

Expand Down
2 changes: 1 addition & 1 deletion test/custom-fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const cwd = t.testdir({
})

t.same(
new Set(['a', 'b', 'c', '']),
new Set(['a', 'b', 'c', '.']),
new Set(
globSync('**', {
fs: {
Expand Down
4 changes: 3 additions & 1 deletion test/custom-ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ t.test('ignore files with long names', async t => {
const syncRes = globSync('**', { cwd, ignore })
const asyncRes = await glob('**', { cwd, ignore })
const expect = j(
globSync('**', { cwd }).filter(p => basename(p).length === 1)
globSync('**', { cwd }).filter(p => {
return basename(p).length === 1 && basename(p) !== '.'
})
)
t.same(j(syncRes), expect)
t.same(j(asyncRes), expect)
Expand Down
18 changes: 9 additions & 9 deletions test/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const cases: Case[] = [
'**',
['c/**', 'bc/**', 'symlink/**', 'abcdef/**'],
j([
'',
'.',
'abcfed',
'abcfed/g',
'abcfed/g/h',
Expand All @@ -80,7 +80,7 @@ const cases: Case[] = [
'**',
['b'],
j([
'',
'.',
'abcdef',
'abcdef/g',
'abcdef/g/h',
Expand Down Expand Up @@ -112,7 +112,7 @@ const cases: Case[] = [
'**',
['b', 'c'],
j([
'',
'.',
'abcdef',
'abcdef/g',
'abcdef/g/h',
Expand Down Expand Up @@ -143,7 +143,7 @@ const cases: Case[] = [
'**',
['b**'],
j([
'',
'.',
'abcdef',
'abcdef/g',
'abcdef/g/h',
Expand Down Expand Up @@ -174,7 +174,7 @@ const cases: Case[] = [
'**',
['b/**'],
j([
'',
'.',
'abcdef',
'abcdef/g',
'abcdef/g/h',
Expand Down Expand Up @@ -204,7 +204,7 @@ const cases: Case[] = [
'**',
['b**/**'],
j([
'',
'.',
'abcdef',
'abcdef/g',
'abcdef/g/h',
Expand All @@ -231,7 +231,7 @@ const cases: Case[] = [
'**',
['ab**ef/**'],
j([
'',
'.',
'abcfed',
'abcfed/g',
'abcfed/g/h',
Expand Down Expand Up @@ -261,7 +261,7 @@ const cases: Case[] = [
'**',
['abc{def,fed}/**'],
j([
'',
'.',
'b',
'b/c',
'b/c/d',
Expand All @@ -288,7 +288,7 @@ const cases: Case[] = [
'**',
['abc{def,fed}/*'],
j([
'',
'.',
'abcdef',
'abcdef/g/h',
'abcfed',
Expand Down
2 changes: 1 addition & 1 deletion test/mark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ for (const mark of [true, false]) {
if (mark) {
t.equal(res, './')
} else {
t.equal(res, '')
t.equal(res, '.')
}
t.equal(syncRes, res, 'sync should match async')
})
Expand Down
10 changes: 5 additions & 5 deletions test/max-depth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ t.test('set maxDepth', async t => {
const expect = j(
noMaxDepth
.filter(p => p.depth() <= startDepth + maxDepth)
.map(p => p.relative())
.map(p => p.relative() || '.')
)

const ssync = j(syncRes.map(p => p.relative()))
const sasync = j(asyncRes.map(p => p.relative()))
const ssync = j(syncRes.map(p => p.relative() || '.'))
const sasync = j(asyncRes.map(p => p.relative() || '.'))
t.same(ssync, expect, 'got all results sync')
t.same(sasync, expect, 'got all results async')
for (const p of syncRes) {
Expand Down Expand Up @@ -87,12 +87,12 @@ t.test('set maxDepth', async t => {

t.same(
await glob(pattern, { cwd, maxDepth: 0, follow: true }),
[''],
['.'],
'async maxDepth 0'
)
t.same(
globSync(pattern, { cwd, maxDepth: 0, follow: true }),
[''],
['.'],
'async maxDepth 0'
)

Expand Down
2 changes: 1 addition & 1 deletion test/slash-cwd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { glob } from '../'
import type { GlobOptions } from '../src/index.js'

const pattern = '../{*.md,test}/'
const expect = ['']
const expect = ['.']
const cwd = __dirname
const opt: GlobOptions = { cwd }
process.chdir(__dirname + '/..')
Expand Down
2 changes: 1 addition & 1 deletion test/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { glob, globSync } from '../dist/cjs'
const cwd = resolve(__dirname, 'fixtures/a')
const j = (a: string[]) => a.map(a => a.split('/').join(sep))
const expect = j([
'',
'.',
'z',
'x',
'cb',
Expand Down

0 comments on commit d6e8645

Please sign in to comment.