Skip to content

Commit

Permalink
fix: add async-retry dependency and update package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
typicode committed Dec 26, 2023
1 parent 69324e3 commit 2794d40
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
63 changes: 63 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@commitlint/config-conventional": "^17.7.0",
"@commitlint/prompt-cli": "^17.7.2",
"@sindresorhus/tsconfig": "^5.0.0",
"@types/async-retry": "^1.4.8",
"@types/node": "^20.8.3",
"@typicode/eslint-config": "^1.2.0",
"del-cli": "^5.1.0",
Expand All @@ -57,5 +58,8 @@
},
"engines": {
"node": ">=18"
},
"dependencies": {
"async-retry": "^1.3.3"
}
}
11 changes: 10 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { rename, writeFile } from 'node:fs/promises'
import { basename, dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'

import retry from 'async-retry'

// Returns a temporary file
// Example: for /some/file will return /some/.file.tmp
function getTempFilename(file: PathLike): string {
Expand Down Expand Up @@ -46,7 +48,14 @@ export class Writer {
try {
// Atomic write
await writeFile(this.#tempFilename, data, 'utf-8')
await rename(this.#tempFilename, this.#filename)
await retry(
async () => {
await rename(this.#tempFilename, this.#filename)
},
{
minTimeout: 100,
},
)

// Call resolve
this.#prev?.[0]()
Expand Down

0 comments on commit 2794d40

Please sign in to comment.