Description
What version of Bun is running?
1.2.17+282dda62c
What platform is your computer?
Microsoft Windows NT 10.0.26100.0 x64
What steps can reproduce the bug?
I want to remove all node_modules in a given directory. My code looks like this:
import { $ } from 'bun'
import { basename, dirname, join } from 'node:path'
const www3 = "D:\\litebox\\www3"
for await (let package_json of $`git ls-files -- '*package.json'`.cwd(www3).lines()) {
if (basename(package_json) !== 'package.json') {
continue
}
const dir = join(www3, dirname(package_json))
await $`rm -rf node_modules`.cwd(dir)
)
}
When the node_modules subfolder exists in the first directory, the whole content is removed, not just the node_modules folder.
For the other folders i did not observe any wrong behavior.
Luckily, there is a workaround: Instead of rm -rf node_modules
, i use rm -rf ./node_modules
With this little change, everything works as expected and only the node_modules folders are removed.
What is the expected behavior?
Remove only the passed directory and nothing else, no matter if prefixed with ./
or not, and in which async context rm is called.
What do you see instead?
The whole parent folder is cleared.
Additional information
These are directories that are processed in my environment:
D:\litebox\www3\client\api\node_modules
D:\litebox\www3\client\licenses\node_modules
D:\litebox\www3\client\node_modules
D:\litebox\www3\node_modules
D:\litebox\www3\server-bun\node_modules
D:\litebox\www3\tests\docker\node_modules
D:\litebox\www3\tests\npm-api\node_modules
D:\litebox\www3\tests\playwright\node_modules
Only the client/api folder is affected.