From 2794d409974ab3ddfb32d106e5c3f6ec3080d4c6 Mon Sep 17 00:00:00 2001 From: typicode Date: Tue, 26 Dec 2023 05:48:23 +0100 Subject: [PATCH] fix: add async-retry dependency and update package.json --- package-lock.json | 63 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 +++ src/index.ts | 11 ++++++++- 3 files changed, 77 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index aed12c6..07ffc9d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,11 +8,15 @@ "name": "steno", "version": "4.0.0", "license": "MIT", + "dependencies": { + "async-retry": "^1.3.3" + }, "devDependencies": { "@commitlint/cli": "^17.7.2", "@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", @@ -1045,6 +1049,15 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, + "node_modules/@types/async-retry": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.8.tgz", + "integrity": "sha512-Qup/B5PWLe86yI5I3av6ePGaeQrIHNKCwbsQotD6aHQ6YkHsMUxVZkZsmx/Ry3VZQ6uysHwTjQ7666+k6UjVJA==", + "dev": true, + "dependencies": { + "@types/retry": "*" + } + }, "node_modules/@types/json-schema": { "version": "7.0.13", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.13.tgz", @@ -1069,6 +1082,12 @@ "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==", "dev": true }, + "node_modules/@types/retry": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.5.tgz", + "integrity": "sha512-3xSjTp3v03X/lSQLkczaN9UIEwJMoMCA1+Nb5HfbJEQWogdeQIyVtTvxPXDQjZ5zws8rFQfVfRdz03ARihPJgw==", + "dev": true + }, "node_modules/@types/semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", @@ -1413,6 +1432,14 @@ "node": ">=0.10.0" } }, + "node_modules/async-retry": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/async-retry/-/async-retry-1.3.3.tgz", + "integrity": "sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==", + "dependencies": { + "retry": "0.13.1" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -4386,6 +4413,14 @@ "node": ">=4" } }, + "node_modules/retry": { + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz", + "integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==", + "engines": { + "node": ">= 4" + } + }, "node_modules/reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", @@ -5709,6 +5744,15 @@ "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", "dev": true }, + "@types/async-retry": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/@types/async-retry/-/async-retry-1.4.8.tgz", + "integrity": "sha512-Qup/B5PWLe86yI5I3av6ePGaeQrIHNKCwbsQotD6aHQ6YkHsMUxVZkZsmx/Ry3VZQ6uysHwTjQ7666+k6UjVJA==", + "dev": true, + "requires": { + "@types/retry": "*" + } + }, "@types/json-schema": { "version": "7.0.13", "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.13.tgz", @@ -5733,6 +5777,12 @@ "integrity": "sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==", "dev": true }, + "@types/retry": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.5.tgz", + "integrity": "sha512-3xSjTp3v03X/lSQLkczaN9UIEwJMoMCA1+Nb5HfbJEQWogdeQIyVtTvxPXDQjZ5zws8rFQfVfRdz03ARihPJgw==", + "dev": true + }, "@types/semver": { "version": "7.5.3", "resolved": "https://registry.npmjs.org/@types/semver/-/semver-7.5.3.tgz", @@ -5946,6 +5996,14 @@ "integrity": "sha512-3CYzex9M9FGQjCGMGyi6/31c8GJbgb0qGyrx5HWxPd0aCwh4cB2YjMb2Xf9UuoogrMrlO9cTqnB5rI5GHZTcUA==", "dev": true }, + "async-retry": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/async-retry/-/async-retry-1.3.3.tgz", + "integrity": "sha512-wfr/jstw9xNi/0teMHrRW7dsz3Lt5ARhYNZ2ewpadnhaIp5mbALhOAP+EAdsC7t4Z6wqsDVv9+W6gm1Dk9mEyw==", + "requires": { + "retry": "0.13.1" + } + }, "balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -8098,6 +8156,11 @@ } } }, + "retry": { + "version": "0.13.1", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz", + "integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==" + }, "reusify": { "version": "1.0.4", "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", diff --git a/package.json b/package.json index 811c774..c3e7b2b 100644 --- a/package.json +++ b/package.json @@ -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", @@ -57,5 +58,8 @@ }, "engines": { "node": ">=18" + }, + "dependencies": { + "async-retry": "^1.3.3" } } diff --git a/src/index.ts b/src/index.ts index b2f7e69..ae2e7ce 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 { @@ -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]()