1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 09:57:02 +01:00
metamask-extension/development/lib/retry.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

/**
Fix 'yarn setup' on M1 Macs (#11887) There are a few issues encountered when running `yarn setup` on new Apple Silicon (aka M1, aka arm64) Macs: * The script halts when attempting to run the install step for the `chromedriver` package with the message "Only Mac 64 bits supported". This is somewhat misleading as it seems to indicate that chromedriver can only be installed on a 64-bit Mac. However, what I think is happening is that the installation script for `chromedriver` is not able to detect that an arm64 CPU *is* a 64-bit CPU. After looking through the `chromedriver` repo, it appears that 87.0.1 is the first version that adds a proper check ([1]). Note that upgrading chromedriver caused the Chrome-specific tests to fail intermittently on CI. I was not able to 100% work out the reason for this, but ensuring that X (which provides a way for Chrome to run in a GUI setting from the command line) is available seems to fix these issues. * The script also halts when attempting to run the install step for the `electron` package. This happens because for the version of `electron` we are using (9.4.2), there is no available binary for arm64. It appears that Electron 11.x was the first version to support arm64 Macs ([2]). This is a bit trickier to resolve because we don't explicitly rely on `electron` — that's brought in by `react-devtools`. The first version of `react-devtools` that relies on `electron` 11.x is 4.11.0 ([3]). [1]: https://github.com/giggio/node-chromedriver/commit/469dd0a6ee23540bfa832b5f09b4cbde3e152010 [2]: https://www.electronjs.org/blog/apple-silicon [3]: https://github.com/facebook/react/blob/main/packages/react-devtools/CHANGELOG.md#4110-april-9-2021
2021-09-01 18:40:40 +02:00
* Re-runs the given function until it returns a resolved promise or the number
* of retries is exceeded, whichever comes first (with an optional delay in
* between retries).
*
* @param {object} args - A set of arguments and options.
Fix 'yarn setup' on M1 Macs (#11887) There are a few issues encountered when running `yarn setup` on new Apple Silicon (aka M1, aka arm64) Macs: * The script halts when attempting to run the install step for the `chromedriver` package with the message "Only Mac 64 bits supported". This is somewhat misleading as it seems to indicate that chromedriver can only be installed on a 64-bit Mac. However, what I think is happening is that the installation script for `chromedriver` is not able to detect that an arm64 CPU *is* a 64-bit CPU. After looking through the `chromedriver` repo, it appears that 87.0.1 is the first version that adds a proper check ([1]). Note that upgrading chromedriver caused the Chrome-specific tests to fail intermittently on CI. I was not able to 100% work out the reason for this, but ensuring that X (which provides a way for Chrome to run in a GUI setting from the command line) is available seems to fix these issues. * The script also halts when attempting to run the install step for the `electron` package. This happens because for the version of `electron` we are using (9.4.2), there is no available binary for arm64. It appears that Electron 11.x was the first version to support arm64 Macs ([2]). This is a bit trickier to resolve because we don't explicitly rely on `electron` — that's brought in by `react-devtools`. The first version of `react-devtools` that relies on `electron` 11.x is 4.11.0 ([3]). [1]: https://github.com/giggio/node-chromedriver/commit/469dd0a6ee23540bfa832b5f09b4cbde3e152010 [2]: https://www.electronjs.org/blog/apple-silicon [3]: https://github.com/facebook/react/blob/main/packages/react-devtools/CHANGELOG.md#4110-april-9-2021
2021-09-01 18:40:40 +02:00
* @param {number} args.retries - The maximum number of times to re-run the
* function on failure.
* @param {number} args.delay - The amount of time (in milliseconds) to wait in
* between retries. (Default: 0)
* @param {string} args.rejectionMessage - The message for the rejected promise
* this function will return in the event of failure. (Default: "Retry limit
* reached")
* @param {string} args.retryUntilFailure - Retries until the function fails.
* @param {Function} functionToRetry - The function that is run and tested for
Fix 'yarn setup' on M1 Macs (#11887) There are a few issues encountered when running `yarn setup` on new Apple Silicon (aka M1, aka arm64) Macs: * The script halts when attempting to run the install step for the `chromedriver` package with the message "Only Mac 64 bits supported". This is somewhat misleading as it seems to indicate that chromedriver can only be installed on a 64-bit Mac. However, what I think is happening is that the installation script for `chromedriver` is not able to detect that an arm64 CPU *is* a 64-bit CPU. After looking through the `chromedriver` repo, it appears that 87.0.1 is the first version that adds a proper check ([1]). Note that upgrading chromedriver caused the Chrome-specific tests to fail intermittently on CI. I was not able to 100% work out the reason for this, but ensuring that X (which provides a way for Chrome to run in a GUI setting from the command line) is available seems to fix these issues. * The script also halts when attempting to run the install step for the `electron` package. This happens because for the version of `electron` we are using (9.4.2), there is no available binary for arm64. It appears that Electron 11.x was the first version to support arm64 Macs ([2]). This is a bit trickier to resolve because we don't explicitly rely on `electron` — that's brought in by `react-devtools`. The first version of `react-devtools` that relies on `electron` 11.x is 4.11.0 ([3]). [1]: https://github.com/giggio/node-chromedriver/commit/469dd0a6ee23540bfa832b5f09b4cbde3e152010 [2]: https://www.electronjs.org/blog/apple-silicon [3]: https://github.com/facebook/react/blob/main/packages/react-devtools/CHANGELOG.md#4110-april-9-2021
2021-09-01 18:40:40 +02:00
* failure.
* @returns {Promise<null | Error>} a promise that either resolves to null if
* the function is successful or is rejected with rejectionMessage otherwise.
*/
Fix 'yarn setup' on M1 Macs (#11887) There are a few issues encountered when running `yarn setup` on new Apple Silicon (aka M1, aka arm64) Macs: * The script halts when attempting to run the install step for the `chromedriver` package with the message "Only Mac 64 bits supported". This is somewhat misleading as it seems to indicate that chromedriver can only be installed on a 64-bit Mac. However, what I think is happening is that the installation script for `chromedriver` is not able to detect that an arm64 CPU *is* a 64-bit CPU. After looking through the `chromedriver` repo, it appears that 87.0.1 is the first version that adds a proper check ([1]). Note that upgrading chromedriver caused the Chrome-specific tests to fail intermittently on CI. I was not able to 100% work out the reason for this, but ensuring that X (which provides a way for Chrome to run in a GUI setting from the command line) is available seems to fix these issues. * The script also halts when attempting to run the install step for the `electron` package. This happens because for the version of `electron` we are using (9.4.2), there is no available binary for arm64. It appears that Electron 11.x was the first version to support arm64 Macs ([2]). This is a bit trickier to resolve because we don't explicitly rely on `electron` — that's brought in by `react-devtools`. The first version of `react-devtools` that relies on `electron` 11.x is 4.11.0 ([3]). [1]: https://github.com/giggio/node-chromedriver/commit/469dd0a6ee23540bfa832b5f09b4cbde3e152010 [2]: https://www.electronjs.org/blog/apple-silicon [3]: https://github.com/facebook/react/blob/main/packages/react-devtools/CHANGELOG.md#4110-april-9-2021
2021-09-01 18:40:40 +02:00
async function retry(
{
retries,
delay = 0,
rejectionMessage = 'Retry limit reached',
retryUntilFailure = false,
},
Fix 'yarn setup' on M1 Macs (#11887) There are a few issues encountered when running `yarn setup` on new Apple Silicon (aka M1, aka arm64) Macs: * The script halts when attempting to run the install step for the `chromedriver` package with the message "Only Mac 64 bits supported". This is somewhat misleading as it seems to indicate that chromedriver can only be installed on a 64-bit Mac. However, what I think is happening is that the installation script for `chromedriver` is not able to detect that an arm64 CPU *is* a 64-bit CPU. After looking through the `chromedriver` repo, it appears that 87.0.1 is the first version that adds a proper check ([1]). Note that upgrading chromedriver caused the Chrome-specific tests to fail intermittently on CI. I was not able to 100% work out the reason for this, but ensuring that X (which provides a way for Chrome to run in a GUI setting from the command line) is available seems to fix these issues. * The script also halts when attempting to run the install step for the `electron` package. This happens because for the version of `electron` we are using (9.4.2), there is no available binary for arm64. It appears that Electron 11.x was the first version to support arm64 Macs ([2]). This is a bit trickier to resolve because we don't explicitly rely on `electron` — that's brought in by `react-devtools`. The first version of `react-devtools` that relies on `electron` 11.x is 4.11.0 ([3]). [1]: https://github.com/giggio/node-chromedriver/commit/469dd0a6ee23540bfa832b5f09b4cbde3e152010 [2]: https://www.electronjs.org/blog/apple-silicon [3]: https://github.com/facebook/react/blob/main/packages/react-devtools/CHANGELOG.md#4110-april-9-2021
2021-09-01 18:40:40 +02:00
functionToRetry,
) {
let attempts = 0;
while (attempts <= retries) {
Fix 'yarn setup' on M1 Macs (#11887) There are a few issues encountered when running `yarn setup` on new Apple Silicon (aka M1, aka arm64) Macs: * The script halts when attempting to run the install step for the `chromedriver` package with the message "Only Mac 64 bits supported". This is somewhat misleading as it seems to indicate that chromedriver can only be installed on a 64-bit Mac. However, what I think is happening is that the installation script for `chromedriver` is not able to detect that an arm64 CPU *is* a 64-bit CPU. After looking through the `chromedriver` repo, it appears that 87.0.1 is the first version that adds a proper check ([1]). Note that upgrading chromedriver caused the Chrome-specific tests to fail intermittently on CI. I was not able to 100% work out the reason for this, but ensuring that X (which provides a way for Chrome to run in a GUI setting from the command line) is available seems to fix these issues. * The script also halts when attempting to run the install step for the `electron` package. This happens because for the version of `electron` we are using (9.4.2), there is no available binary for arm64. It appears that Electron 11.x was the first version to support arm64 Macs ([2]). This is a bit trickier to resolve because we don't explicitly rely on `electron` — that's brought in by `react-devtools`. The first version of `react-devtools` that relies on `electron` 11.x is 4.11.0 ([3]). [1]: https://github.com/giggio/node-chromedriver/commit/469dd0a6ee23540bfa832b5f09b4cbde3e152010 [2]: https://www.electronjs.org/blog/apple-silicon [3]: https://github.com/facebook/react/blob/main/packages/react-devtools/CHANGELOG.md#4110-april-9-2021
2021-09-01 18:40:40 +02:00
if (attempts > 0 && delay > 0) {
await new Promise((resolve) => setTimeout(resolve, delay));
}
try {
await functionToRetry();
if (!retryUntilFailure) {
return;
}
} catch (error) {
console.error(error);
if (retryUntilFailure) {
return;
}
} finally {
attempts += 1;
}
}
Fix 'yarn setup' on M1 Macs (#11887) There are a few issues encountered when running `yarn setup` on new Apple Silicon (aka M1, aka arm64) Macs: * The script halts when attempting to run the install step for the `chromedriver` package with the message "Only Mac 64 bits supported". This is somewhat misleading as it seems to indicate that chromedriver can only be installed on a 64-bit Mac. However, what I think is happening is that the installation script for `chromedriver` is not able to detect that an arm64 CPU *is* a 64-bit CPU. After looking through the `chromedriver` repo, it appears that 87.0.1 is the first version that adds a proper check ([1]). Note that upgrading chromedriver caused the Chrome-specific tests to fail intermittently on CI. I was not able to 100% work out the reason for this, but ensuring that X (which provides a way for Chrome to run in a GUI setting from the command line) is available seems to fix these issues. * The script also halts when attempting to run the install step for the `electron` package. This happens because for the version of `electron` we are using (9.4.2), there is no available binary for arm64. It appears that Electron 11.x was the first version to support arm64 Macs ([2]). This is a bit trickier to resolve because we don't explicitly rely on `electron` — that's brought in by `react-devtools`. The first version of `react-devtools` that relies on `electron` 11.x is 4.11.0 ([3]). [1]: https://github.com/giggio/node-chromedriver/commit/469dd0a6ee23540bfa832b5f09b4cbde3e152010 [2]: https://www.electronjs.org/blog/apple-silicon [3]: https://github.com/facebook/react/blob/main/packages/react-devtools/CHANGELOG.md#4110-april-9-2021
2021-09-01 18:40:40 +02:00
throw new Error(rejectionMessage);
}
module.exports = { retry };