-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: fix "
fs.rmSync
is not a function" for old node.js versions
add simplest polyfill for `fs.rmSync(path, {recursive: true})`
- Loading branch information
1 parent
9541460
commit 0dd5a26
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
/** recursively delete files, symlinks (without following them) and dirs */ | ||
module.exports = function rmRecSync (pth) { | ||
pth = path.normalize(pth) | ||
|
||
rm(pth) | ||
|
||
function rm (pth) { | ||
const pathStat = fs.statSync(pth) | ||
// trick with lstat is used to avoid following symlinks (especially junctions on windows) | ||
if (pathStat.isDirectory() && !fs.lstatSync(pth).isSymbolicLink()) { | ||
fs.readdirSync(pth).forEach((nextPath) => rm(path.join(pth, nextPath))) | ||
fs.rmdirSync(pth) | ||
} else { | ||
fs.unlinkSync(pth) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters