diff --git a/misc/admin/lib/cmds/bump-versions.js b/misc/admin/lib/cmds/bump-versions.js index 2dc82bab8..289a7260d 100644 --- a/misc/admin/lib/cmds/bump-versions.js +++ b/misc/admin/lib/cmds/bump-versions.js @@ -56,7 +56,7 @@ const utils_1 = require("../utils"); latestVersions[pLocal.name] = version; // Write out the _version.ts if (!pLocal._ethers_nobuild) { - const code = "export const version = " + JSON.stringify(dirname + "/" + pLocal.version) + ";\n"; + const code = "export const version = " + JSON.stringify(dirname + "/" + version) + ";\n"; fs_1.default.writeFileSync(path_1.resolve(path_1.getPackagePath(dirname), "src.ts/_version.ts"), code); } } diff --git a/misc/admin/lib/cmds/publish.js b/misc/admin/lib/cmds/publish.js index d7cb890a4..50eae6ed9 100644 --- a/misc/admin/lib/cmds/publish.js +++ b/misc/admin/lib/cmds/publish.js @@ -176,14 +176,13 @@ exports.invalidate = invalidate; ]; for (let i = 0; i < fileInfos.length; i++) { const { filename, key } = fileInfos[i]; - const status = yield putObject(s3, { + yield putObject(s3, { ACL: "public-read", Body: fs_1.default.readFileSync(path_1.resolve(filename)), Bucket: bucketName, ContentType: "application/javascript; charset=utf-8", Key: (originRoot + key) }); - console.log(status); console.log(`${log_1.colorify.bold("Uploaded:")} https://cdn.ethers.io/lib/${key}`); } } diff --git a/misc/admin/lib/geturl.js b/misc/admin/lib/geturl.js index 5a19233c4..802c22671 100644 --- a/misc/admin/lib/geturl.js +++ b/misc/admin/lib/geturl.js @@ -60,7 +60,13 @@ function nonnull(value) { } return value; } -function getUrl(href, options) { +function staller(duration) { + return new Promise((resolve) => { + const timer = setTimeout(resolve, duration); + timer.unref(); + }); +} +function _getUrl(href, options) { return __awaiter(this, void 0, void 0, function* () { if (options == null) { options = {}; @@ -100,4 +106,23 @@ function getUrl(href, options) { return response; }); } +function getUrl(href, options) { + return __awaiter(this, void 0, void 0, function* () { + let error = null; + for (let i = 0; i < 3; i++) { + try { + const result = yield Promise.race([ + _getUrl(href, options), + staller(30000).then((result) => { throw new Error("timeout"); }) + ]); + return result; + } + catch (e) { + error = e; + } + yield staller(1000); + } + throw error; + }); +} exports.getUrl = getUrl; diff --git a/misc/admin/src.ts/cmds/bump-versions.ts b/misc/admin/src.ts/cmds/bump-versions.ts index 8d10d1c28..78091877a 100644 --- a/misc/admin/src.ts/cmds/bump-versions.ts +++ b/misc/admin/src.ts/cmds/bump-versions.ts @@ -50,7 +50,7 @@ import { loadJson, repeat, saveJson } from "../utils"; // Write out the _version.ts if (!pLocal._ethers_nobuild) { - const code = "export const version = " + JSON.stringify(dirname + "/" + pLocal.version) + ";\n"; + const code = "export const version = " + JSON.stringify(dirname + "/" + version) + ";\n"; fs.writeFileSync(resolve(getPackagePath(dirname), "src.ts/_version.ts"), code); } } diff --git a/misc/admin/src.ts/cmds/publish.ts b/misc/admin/src.ts/cmds/publish.ts index 895ea66ab..0e6a1d440 100644 --- a/misc/admin/src.ts/cmds/publish.ts +++ b/misc/admin/src.ts/cmds/publish.ts @@ -184,15 +184,13 @@ export function invalidate(cloudfront: AWS.CloudFront, distributionId: string): for (let i = 0; i < fileInfos.length; i++) { const { filename, key } = fileInfos[i]; - const status = await putObject(s3, { + await putObject(s3, { ACL: "public-read", Body: fs.readFileSync(resolve(filename)), Bucket: bucketName, ContentType: "application/javascript; charset=utf-8", Key: (originRoot + key) }); - console.log(status); - console.log(`${ colorify.bold("Uploaded:") } https://cdn.ethers.io/lib/${ key }`); } } diff --git a/misc/admin/src.ts/geturl.ts b/misc/admin/src.ts/geturl.ts index 05e8c04e0..993d9b37e 100644 --- a/misc/admin/src.ts/geturl.ts +++ b/misc/admin/src.ts/geturl.ts @@ -68,7 +68,14 @@ function nonnull(value: string): string { return value; } -export async function getUrl(href: string, options?: Options): Promise { +function staller(duration: number): Promise { + return new Promise((resolve) => { + const timer = setTimeout(resolve, duration); + timer.unref(); + }); +} + +async function _getUrl(href: string, options?: Options): Promise { if (options == null) { options = { }; } // @TODO: Once we drop support for node 8, we can pass the href @@ -112,3 +119,19 @@ export async function getUrl(href: string, options?: Options): Promise { + let error: Error = null; + for (let i = 0; i < 3; i++) { + try { + const result = await Promise.race([ + _getUrl(href, options), + staller(30000).then((result) => { throw new Error("timeout") }) + ]); + return result; + } catch (e) { + error = e; + } + await staller(1000); + } + throw error; +}