Skip to content

Bug: globSync does not match node fs behavior on relative file names #1242

@snoozbuster

Description

@snoozbuster

Node version: 24.14.0
Memfs version: 4.56.10

If the pattern given to memfs's globSync function is a relative path to a file in the current working directory, the file is not returned. This differs from node's built-in globSync function, which does return the file in the current directory.

Steps to reproduce:

> const fs = require('fs')
undefined
> const memfs = require('memfs')
undefined
> memfs.writeFileSync('/tsconfig.json', '{}')
undefined
> memfs.vol.toJSON()
{ '/tsconfig.json': '{}' }
> memfs.globSync('./tsconfig.json', { cwd: '/' }) // should find the file, but doesn't
[]
> fs.globSync('./tsconfig.json', { cwd: '.' }) // this file exists in my cwd on my system
[ 'tsconfig.json' ]

I stepped into the code to debug a little bit, and the issue seems to stem from the regex that this code produces including the ./ part of the pattern, but the actual file names passed in that are generated via relativePath do not include the leading ./ in the filenames (probably rightly so). Additionally, I see a test for absolute patterns but no tests for relative patterns which include the cwd explicitly as the first part of the path.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions