-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: make directory removal work on node 12.9
For alpine releases we are stuck with node 12.9 where recursive directory removal does not work. We are reluctant to make major changes to release tooling as we work towards deprecating this tool, so this commit is adding a rimraf workaround which will catch cases when `fs.rmdirSync` throws.
- Loading branch information
1 parent
7aca4b7
commit afd41e7
Showing
5 changed files
with
33 additions
and
3 deletions.
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
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,12 @@ | ||
import * as rmrf from 'rimraf'; | ||
import * as fs from 'fs'; | ||
|
||
export async function deleteDirectory(dir: string): Promise<void> { | ||
try { | ||
fs.rmdirSync(dir, { recursive: true, maxRetries: 3 }); | ||
} catch (e) { | ||
await new Promise<void>((resolve, reject) => | ||
rmrf(dir, (err) => (err ? reject(err) : resolve())), | ||
); | ||
} | ||
} |
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
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
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,15 @@ | ||
import { promises as fs } from 'fs'; | ||
import * as os from 'os'; | ||
import * as path from 'path'; | ||
import { deleteDirectory } from '../../src/lib/delete-directory'; | ||
|
||
test('directory is deleted with contents', async () => { | ||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'deletion-test-')); | ||
await fs.writeFile(path.join(dir, 'root.txt'), ''); | ||
|
||
await deleteDirectory(dir); | ||
|
||
console.log(dir); | ||
|
||
await expect(fs.stat(dir)).rejects.toThrowError('no such file or directory'); | ||
}); |