From a59d260e004884b4e8987ba7aaac060c394c1092 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Thu, 29 Jun 2023 14:04:27 -0700 Subject: [PATCH] feat: retry staple up to 3 times (#144) --- package.json | 4 +++- src/helpers.ts | 2 +- src/index.ts | 8 ++++++-- src/legacy.ts | 2 +- src/notarytool.ts | 2 +- src/spawn.ts | 2 +- src/staple.ts | 2 +- tsconfig.json | 2 +- yarn.lock | 12 ++++++++++++ 9 files changed, 27 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index efcda21..9f6d4ca 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@types/fs-extra": "^9.0.1", "@types/jest": "^29.0.0", "@types/node": "^13.7.7", + "@types/promise-retry": "^1.1.3", "jest": "^29.0.0", "prettier": "^1.18.2", "ts-jest": "^29.0.0", @@ -39,6 +40,7 @@ }, "dependencies": { "debug": "^4.1.1", - "fs-extra": "^9.0.1" + "fs-extra": "^9.0.1", + "promise-retry": "^2.0.1" } } diff --git a/src/helpers.ts b/src/helpers.ts index 51e2300..3745707 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -1,4 +1,4 @@ -import * as debug from 'debug'; +import debug from 'debug'; import * as fs from 'fs-extra'; import * as os from 'os'; import * as path from 'path'; diff --git a/src/index.ts b/src/index.ts index b87051a..4932b23 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,6 @@ -import * as debug from 'debug'; +import debug from 'debug'; +import retry from 'promise-retry'; + import { delay } from './helpers'; import { startLegacyNotarize, waitForLegacyNotarize } from './legacy'; import { isNotaryToolAvailable, notarizeAndWaitForNotaryTool } from './notarytool'; @@ -48,5 +50,7 @@ export async function notarize({ appPath, ...otherOptions }: NotarizeOptions) { } as NotaryToolStartOptions); } - await stapleApp({ appPath }); + await retry(() => stapleApp({ appPath }), { + retries: 3, + }); } diff --git a/src/legacy.ts b/src/legacy.ts index 7ce897f..c9ce044 100644 --- a/src/legacy.ts +++ b/src/legacy.ts @@ -1,4 +1,4 @@ -import * as debug from 'debug'; +import debug from 'debug'; import * as path from 'path'; import { spawn } from './spawn'; diff --git a/src/notarytool.ts b/src/notarytool.ts index 8f19e3c..44ec60e 100644 --- a/src/notarytool.ts +++ b/src/notarytool.ts @@ -1,4 +1,4 @@ -import * as debug from 'debug'; +import debug from 'debug'; import * as path from 'path'; import { spawn } from './spawn'; diff --git a/src/spawn.ts b/src/spawn.ts index 0e91f24..9a2ebec 100644 --- a/src/spawn.ts +++ b/src/spawn.ts @@ -1,5 +1,5 @@ import { spawn as cpSpawn, SpawnOptions } from 'child_process'; -import * as debug from 'debug'; +import debug from 'debug'; import { isSecret } from './helpers'; const d = debug('electron-notarize:spawn'); diff --git a/src/staple.ts b/src/staple.ts index aab3b6b..037fba8 100644 --- a/src/staple.ts +++ b/src/staple.ts @@ -1,4 +1,4 @@ -import * as debug from 'debug'; +import debug from 'debug'; import * as path from 'path'; import { spawn } from './spawn'; diff --git a/tsconfig.json b/tsconfig.json index c1c7e1e..9460018 100755 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,10 +10,10 @@ "noUnusedLocals": true, "noImplicitThis": true, "noImplicitAny": true, - "noImplicitUseStrict": true, "declaration": true, "skipDefaultLibCheck": true, "skipLibCheck": true, + "esModuleInterop": true }, "include": [ "src/**/*" diff --git a/yarn.lock b/yarn.lock index 7004c85..5e7db1f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -924,6 +924,18 @@ resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.1.tgz#dfd20e2dc35f027cdd6c1908e80a5ddc7499670e" integrity sha512-ri0UmynRRvZiiUJdiz38MmIblKK+oH30MztdBVR95dv/Ubw6neWSb8u1XpRb72L4qsZOhz+L+z9JD40SJmfWow== +"@types/promise-retry@^1.1.3": + version "1.1.3" + resolved "https://registry.yarnpkg.com/@types/promise-retry/-/promise-retry-1.1.3.tgz#baab427419da9088a1d2f21bf56249c21b3dd43c" + integrity sha512-LxIlEpEX6frE3co3vCO2EUJfHIta1IOmhDlcAsR4GMMv9hev1iTI9VwberVGkePJAuLZs5rMucrV8CziCfuJMw== + dependencies: + "@types/retry" "*" + +"@types/retry@*": + version "0.12.2" + resolved "https://registry.yarnpkg.com/@types/retry/-/retry-0.12.2.tgz#ed279a64fa438bb69f2480eda44937912bb7480a" + integrity sha512-XISRgDJ2Tc5q4TRqvgJtzsRkFYNJzZrhTdtMoGVBttwzzQJkPnS3WWTFc7kuDRoPtPakl+T+OfdEUjYJj7Jbow== + "@types/stack-utils@^2.0.0": version "2.0.1" resolved "https://registry.yarnpkg.com/@types/stack-utils/-/stack-utils-2.0.1.tgz#20f18294f797f2209b5f65c8e3b5c8e8261d127c"