chore: added standards-compliant Promise.any implementation
Signed-off-by: planeiii <planeiii@thousandeyes.com>
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
"express": "^4.17.1",
|
||||
"express-promise-router": "^4.1.0",
|
||||
"jenkins": "^0.28.1",
|
||||
"promise-any-polyfill": "^1.0.1",
|
||||
"winston": "^3.2.1",
|
||||
"yn": "^4.0.0"
|
||||
},
|
||||
|
||||
@@ -30,27 +30,11 @@ import {
|
||||
import { jenkinsExecutePermission } from '@backstage/plugin-jenkins-common';
|
||||
import { NotAllowedError } from '@backstage/errors';
|
||||
|
||||
// polyfill Promise.any for Node v14
|
||||
const anyPromise = (any => {
|
||||
if (any) {
|
||||
// bind is required by tsc
|
||||
return any.bind(Promise);
|
||||
}
|
||||
|
||||
// reverse promise resolution (rejects become resolves and visa versa)
|
||||
const reverse = (promise: Promise<JenkinsProject>): Promise<JenkinsProject> =>
|
||||
new Promise<JenkinsProject>((resolve, reject) =>
|
||||
Promise.resolve(promise).then(reject, resolve),
|
||||
);
|
||||
|
||||
return (
|
||||
iterable: Iterable<Promise<JenkinsProject>>,
|
||||
): Promise<JenkinsProject> =>
|
||||
Promise.all([...iterable].map(reverse)).then(
|
||||
results => reverse(Promise.resolve(results[0])),
|
||||
reverse,
|
||||
);
|
||||
})(Promise.any);
|
||||
if (!Promise.any) {
|
||||
(async () => {
|
||||
await import('promise-any-polyfill');
|
||||
})();
|
||||
}
|
||||
|
||||
export class JenkinsApiImpl {
|
||||
private static readonly lastBuildTreeSpec = `lastBuild[
|
||||
@@ -99,7 +83,7 @@ export class JenkinsApiImpl {
|
||||
if (branches) {
|
||||
// Assume jenkinsInfo.jobFullName is a folder which contains one job per branch.
|
||||
// TODO: extract a strategy interface for this
|
||||
const job = await anyPromise(
|
||||
const job = await Promise.any(
|
||||
branches.map(branch =>
|
||||
client.job.get({
|
||||
name: `${jenkinsInfo.jobFullName}/${branch}`,
|
||||
|
||||
@@ -20902,6 +20902,11 @@ promise-all-reject-late@^1.0.0:
|
||||
resolved "https://registry.npmjs.org/promise-all-reject-late/-/promise-all-reject-late-1.0.1.tgz#f8ebf13483e5ca91ad809ccc2fcf25f26f8643c2"
|
||||
integrity sha512-vuf0Lf0lOxyQREH7GDIOUMLS7kz+gs8i6B+Yi8dC68a2sychGrHTJYghMBD6k7eUcH0H5P73EckCA48xijWqXw==
|
||||
|
||||
promise-any-polyfill@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://artifactory.thousandeyes.com/artifactory/api/npm/npm/promise-any-polyfill/-/promise-any-polyfill-1.0.1.tgz#563872dd0abd370bfa8039e63980469b4b8b0d53"
|
||||
integrity sha1-Vjhy3Qq9Nwv6gDnmOYBGm0uLDVM=
|
||||
|
||||
promise-call-limit@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.npmjs.org/promise-call-limit/-/promise-call-limit-1.0.1.tgz#4bdee03aeb85674385ca934da7114e9bcd3c6e24"
|
||||
|
||||
Reference in New Issue
Block a user