Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in fetch #18

Merged
merged 1 commit into from Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
127 changes: 0 additions & 127 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Expand Up @@ -17,7 +17,6 @@
"cheerio": "^1.0.0-rc.3",
"lodash-es": "^4.17.21",
"markdown-it": "^13.0.1",
"node-fetch": "^3.2.9",
"parse-github-url": "^1.0.2"
},
"devDependencies": {
Expand Down
16 changes: 14 additions & 2 deletions src/fetch/proposals.ts
@@ -1,12 +1,24 @@
import { Endpoints } from '@octokit/types';
import _ from 'lodash-es';
import fetch from 'node-fetch';
import parseGithubURL from 'parse-github-url';
import { github } from './github.js';
import { readAllProposals } from './proposal-markdown.js';
import { getTC39Repos } from './repos.js';
import { BundleProposals } from '../types/bundle.js';

const fetchWithRetry = async (url: RequestInfo, init: RequestInit, retryCount = 3) => {
for (let i = 0; i < retryCount; i++) {
try {
return await fetch(url, init);
} catch (error) {
if (i === retryCount - 1) throw error;
}
// exponential backoff: 100ms, 400ms, 900ms
await new Promise((resolve) => setTimeout(resolve, (i + 1) ** 2 * 100));
}
throw new Error('Unreachable');
};

export async function getProposals() {
const repos = await getTC39Repos();
const records: BundleProposals = [];
Expand Down Expand Up @@ -36,7 +48,7 @@ export async function getProposals() {
? `https://tc39.es/${data.name}/`
: `https://${data?.owner?.login}.github.io/${data?.name}/`;

const response = await fetch(specURL, { redirect: 'manual' });
const response = await fetchWithRetry(specURL, { redirect: 'manual' });

// This is the default spec text at https://github.com/tc39/template-for-proposals/blob/HEAD/spec.emu
if (response.status !== 200) spec = undefined;
Expand Down