Skip to content

Commit d6e8645

Browse files
committed
Return '.' instead of '' when matching cwd
Fix: #519
1 parent 93efe71 commit d6e8645

File tree

8 files changed

+22
-20
lines changed

8 files changed

+22
-20
lines changed

src/walker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ export abstract class GlobUtil<O extends GlobWalkerOpts = GlobWalkerOpts> {
214214
this.opts.dotRelative && !rel.startsWith('..' + this.#sep)
215215
? '.' + this.#sep
216216
: ''
217-
this.matchEmit(!rel && mark ? '.' + mark : pre + rel + mark)
217+
this.matchEmit(!rel ? '.' + mark : pre + rel + mark)
218218
}
219219
}
220220

test/custom-fs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const cwd = t.testdir({
1616
})
1717

1818
t.same(
19-
new Set(['a', 'b', 'c', '']),
19+
new Set(['a', 'b', 'c', '.']),
2020
new Set(
2121
globSync('**', {
2222
fs: {

test/custom-ignore.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ t.test('ignore files with long names', async t => {
1616
const syncRes = globSync('**', { cwd, ignore })
1717
const asyncRes = await glob('**', { cwd, ignore })
1818
const expect = j(
19-
globSync('**', { cwd }).filter(p => basename(p).length === 1)
19+
globSync('**', { cwd }).filter(p => {
20+
return basename(p).length === 1 && basename(p) !== '.'
21+
})
2022
)
2123
t.same(j(syncRes), expect)
2224
t.same(j(asyncRes), expect)

test/ignore.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const cases: Case[] = [
5858
'**',
5959
['c/**', 'bc/**', 'symlink/**', 'abcdef/**'],
6060
j([
61-
'',
61+
'.',
6262
'abcfed',
6363
'abcfed/g',
6464
'abcfed/g/h',
@@ -80,7 +80,7 @@ const cases: Case[] = [
8080
'**',
8181
['b'],
8282
j([
83-
'',
83+
'.',
8484
'abcdef',
8585
'abcdef/g',
8686
'abcdef/g/h',
@@ -112,7 +112,7 @@ const cases: Case[] = [
112112
'**',
113113
['b', 'c'],
114114
j([
115-
'',
115+
'.',
116116
'abcdef',
117117
'abcdef/g',
118118
'abcdef/g/h',
@@ -143,7 +143,7 @@ const cases: Case[] = [
143143
'**',
144144
['b**'],
145145
j([
146-
'',
146+
'.',
147147
'abcdef',
148148
'abcdef/g',
149149
'abcdef/g/h',
@@ -174,7 +174,7 @@ const cases: Case[] = [
174174
'**',
175175
['b/**'],
176176
j([
177-
'',
177+
'.',
178178
'abcdef',
179179
'abcdef/g',
180180
'abcdef/g/h',
@@ -204,7 +204,7 @@ const cases: Case[] = [
204204
'**',
205205
['b**/**'],
206206
j([
207-
'',
207+
'.',
208208
'abcdef',
209209
'abcdef/g',
210210
'abcdef/g/h',
@@ -231,7 +231,7 @@ const cases: Case[] = [
231231
'**',
232232
['ab**ef/**'],
233233
j([
234-
'',
234+
'.',
235235
'abcfed',
236236
'abcfed/g',
237237
'abcfed/g/h',
@@ -261,7 +261,7 @@ const cases: Case[] = [
261261
'**',
262262
['abc{def,fed}/**'],
263263
j([
264-
'',
264+
'.',
265265
'b',
266266
'b/c',
267267
'b/c/d',
@@ -288,7 +288,7 @@ const cases: Case[] = [
288288
'**',
289289
['abc{def,fed}/*'],
290290
j([
291-
'',
291+
'.',
292292
'abcdef',
293293
'abcdef/g/h',
294294
'abcfed',

test/mark.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ for (const mark of [true, false]) {
173173
if (mark) {
174174
t.equal(res, './')
175175
} else {
176-
t.equal(res, '')
176+
t.equal(res, '.')
177177
}
178178
t.equal(syncRes, res, 'sync should match async')
179179
})

test/max-depth.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ t.test('set maxDepth', async t => {
3131
const expect = j(
3232
noMaxDepth
3333
.filter(p => p.depth() <= startDepth + maxDepth)
34-
.map(p => p.relative())
34+
.map(p => p.relative() || '.')
3535
)
3636

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

8888
t.same(
8989
await glob(pattern, { cwd, maxDepth: 0, follow: true }),
90-
[''],
90+
['.'],
9191
'async maxDepth 0'
9292
)
9393
t.same(
9494
globSync(pattern, { cwd, maxDepth: 0, follow: true }),
95-
[''],
95+
['.'],
9696
'async maxDepth 0'
9797
)
9898

test/slash-cwd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { glob } from '../'
55
import type { GlobOptions } from '../src/index.js'
66

77
const pattern = '../{*.md,test}/'
8-
const expect = ['']
8+
const expect = ['.']
99
const cwd = __dirname
1010
const opt: GlobOptions = { cwd }
1111
process.chdir(__dirname + '/..')

test/stream.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { glob, globSync } from '../dist/cjs'
1111
const cwd = resolve(__dirname, 'fixtures/a')
1212
const j = (a: string[]) => a.map(a => a.split('/').join(sep))
1313
const expect = j([
14-
'',
14+
'.',
1515
'z',
1616
'x',
1717
'cb',

0 commit comments

Comments
 (0)