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

Replace node-fetch and axios with native fetch #3123

Merged
merged 3 commits into from
May 24, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .changeset/moody-wombats-glow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 2 additions & 3 deletions packages/community-meta/scripts/generateRichMeetupData.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { join } = require("path")
const { writeFileSync } = require("fs")
const { meetups } = require("./meetups")
// const xml2js = require("xml2js")
// const nodeFetch = require("node-fetch").default
// const icalToolkit = require("ical-utils")
const { format } = require("prettier")
// const moment = require("moment")
Expand All @@ -31,7 +30,7 @@ const go = async () => {
// const meetupID = meetupURL.split('/').pop()
// process.stdout.write(meetupID)

// const icalResponse = await nodeFetch(`https://www.meetup.com/${meetupID}/events/ical/`)
// const icalResponse = await fetch(`https://www.meetup.com/${meetupID}/events/ical/`)
// const icalText = await icalResponse.text()
// const ical = await icalToolkit.parseToJSON(icalText)

Expand All @@ -53,7 +52,7 @@ const go = async () => {
// let richDescription = '<p>' + upcomingEvent.description + '</p>'

// // Best to not assume meetup.com's long term health, and it's rss
// const rssResponse = await nodeFetch(`https://www.meetup.com/${meetupID}/events/rss/`)
// const rssResponse = await fetch(`https://www.meetup.com/${meetupID}/events/rss/`)
// const rssText = await rssResponse.text()
// const rss = await xml2js.parseStringPromise(rssText)

Expand Down
1 change: 0 additions & 1 deletion packages/playground/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"jest": "^29.5.0",
"monaco-editor": "^0.32.1",
"monaco-typescript": "^3.7.0",
"node-fetch": "^2.7.0",
"typescript": "*"
}
}
3 changes: 1 addition & 2 deletions packages/playground/scripts/getListOfPluginsFromNPM.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,12 @@ if (!process.env.CI) {
process.exit(0)
}

const nodeFetch = require("node-fetch").default
const { writeFileSync } = require("fs")
const { join } = require("path")
const { format } = require("prettier")

const get = async url => {
const packageJSON = await nodeFetch(url)
const packageJSON = await fetch(url)
const contents = await packageJSON.json()
return contents
}
Expand Down
2 changes: 0 additions & 2 deletions packages/sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,10 @@
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.7",
"@types/jest": "^29.5.12",
"axios": "^0.21.4",
"dts-cli": "^2.0.5",
"jest": "^29.5.0",
"monaco-editor": "^0.32.1",
"monaco-typescript": "^3.7.0",
"node-fetch": "^2.7.0",
"ts-jest": "^29.0.5",
"typescript": "*"
}
Expand Down
2 changes: 0 additions & 2 deletions packages/sandbox/script/downloadReleases.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
// Run via: pnpm run --filter=typescript-sandbox bootstrap

// Ensure the versions dropdown is up to date
const axios = require("axios").default
const { writeFileSync } = require("fs")
const { join } = require("path")
const { format } = require("prettier")
const fetch = require("node-fetch").default

const go = async () => {
const response = await fetch("https://typescript.azureedge.net/indexes/releases.json")
Expand Down
1 change: 0 additions & 1 deletion packages/tsconfig-reference/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
},
"devDependencies": {
"@types/json-schema": "^7.0.15",
"node-fetch": "^2.7.0",
"ts-node": "*",
"typescript": "*",
"xml-js": "^1.6.11"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

// https://json.schemastore.org/tsconfig.json

import nodeFetch from "node-fetch";
import { writeFileSync, existsSync, mkdirSync } from "fs";
import { join } from "path";

const getFileAndStoreLocally = async (url, path, editFunc) => {
const editingFunc = editFunc ? editFunc : (text) => text;
const packageJSON = await nodeFetch(url);
const packageJSON = await fetch(url);
const contents = await packageJSON.text();
writeFileSync(new URL(path, import.meta.url), editingFunc(contents), "utf8");
};
Expand Down
3 changes: 0 additions & 3 deletions packages/typescriptlang-org/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"dependencies": {
"@babel/core": "^7.24.5",
"@formatjs/intl-relativetimeformat": "^4.5.15",
"@types/node-fetch": "^2.5.3",
"@types/react-helmet": "^5.0.15",
"@typescript/playground": "workspace:*",
"@typescript/sandbox": "workspace:*",
Expand Down Expand Up @@ -66,12 +65,10 @@
"@types/jest": "^29.5.12",
"@types/react": "^18.3.2",
"@types/react-dom": "^18.3.0",
"axios": "^0.21.4",
"gatsby-plugin-typegen": "^3.1.0",
"gatsby-plugin-typescript": "^5.6.0",
"jest": "^29.5.0",
"monaco-editor": "^0.32.1",
"node-fetch": "^2.7.0",
"node-polyfill-webpack-plugin": "^3.0.0",
"semver": "^7.6.2",
"ts-jest": "^29.0.5",
Expand Down
3 changes: 1 addition & 2 deletions packages/typescriptlang-org/scripts/createLighthouseJSON.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const nodeFetch = require("node-fetch").default
const { writeFileSync } = require("fs")
const { join } = require("path")
const parser = require("xml-js")
Expand All @@ -9,7 +8,7 @@ const prRoot =
const go = async () => {
const sitemap = `${prRoot}/sitemap.xml`
try {
const packageJSON = await nodeFetch(sitemap)
const packageJSON = await fetch(sitemap)

const contents = await packageJSON.text()
const sitemapJSON = JSON.parse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

// Ensure Playground assets are up to date

const nodeFetch = require("node-fetch").default
const { writeFileSync, readFileSync } = require("fs")
const { join } = require("path")

const getFileAndStoreLocally = async (url, path) => {
const packageJSON = await nodeFetch(url)
const packageJSON = await fetch(url)
const contents = await packageJSON.text()
writeFileSync(join(__dirname, "..", path), contents, "utf8")
}
Expand Down
3 changes: 1 addition & 2 deletions packages/typescriptlang-org/scripts/downloadSearchAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

// Ensure Algolia info is up to date

const nodeFetch = require("node-fetch").default
const { writeFileSync } = require("fs")
const { join } = require("path")

const getFileAndStoreLocally = async (url, path, editFunc) => {
const editingFunc = editFunc ? editFunc : text => text
const packageJSON = await nodeFetch(url)
const packageJSON = await fetch(url)
const contents = await packageJSON.text()
writeFileSync(join(__dirname, "..", path), editingFunc(contents), "utf8")
}
Expand Down
19 changes: 8 additions & 11 deletions packages/typescriptlang-org/scripts/getTypeScriptNPMVersions.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

// pnpm run --filter=typescriptlang-org update-versions

const nodeFetch = require("node-fetch").default
const { writeFileSync, existsSync } = require("fs")
const { join, dirname } = require("path")
const semver = require("semver")
const axios = require("axios").default
const { format } = require("prettier")

const get = async url => {
const packageJSON = await nodeFetch(url)
const packageJSON = await fetch(url)
const contents = await packageJSON.text()
return contents
}
Expand All @@ -30,7 +28,6 @@ const getLatestVSExtensions = async latest => {
`https://marketplace.visualstudio.com/search?term=typescript%20${semver.major(latest)}.${semver.minor(latest)}&target=VS&category=All%20categories&vsVersion=&sortBy=Relevance`,
"User-Agent":
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.1.1 Safari/605.1.15",
"Content-Length": "1082",
Connection: "keep-alive",
"X-TFS-Session": "e16c1b5b-850f-42ee-ab7c-519c79f6e356",
"X-Requested-With": "XMLHttpRequest",
Expand All @@ -40,19 +37,19 @@ const getLatestVSExtensions = async latest => {
const query = name =>
`{"assetTypes":["Microsoft.VisualStudio.Services.Icons.Default","Microsoft.VisualStudio.Services.Icons.Branding","Microsoft.VisualStudio.Services.Icons.Small"],"filters":[{"criteria":[{"filterType":8,"value":"Microsoft.VisualStudio.Ide"},{"filterType":10,"value":"${name}"},{"filterType":12,"value":"37888"}],"direction":2,"pageSize":54,"pageNumber":1,"sortBy":0,"sortOrder":0,"pagingToken":null}],"flags":870}`

const extensionSearchResults = await axios({
url:
"https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery",
const extensionSearchResults = await fetch("https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery", {
method: "POST",
headers: headers,
data: query(`typescript ${semver.major(latest)}.${semver.minor(latest)}`),
headers,
body: query(`typescript ${semver.major(latest)}.${semver.minor(latest)}`),
})

if (!extensionSearchResults.data || !extensionSearchResults.data.results) {
const data = await extensionSearchResults.json()

if (!data || !data.results) {
throw new Error("Got a bad response from VS marketplace")
}

const extensions = extensionSearchResults.data.results[0].extensions
const extensions = data.results[0].extensions
const officialExtensions = extensions.filter(
e => e.publisher.publisherId === "4f0355d2-4a53-4ab1-a8ea-507f4a333a6f"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@
APP_INSIGHTS_ID="X" APP_INSIGHTS_API_KEY="Y" node packages/typescriptlang-org/scripts/makeMarkdownForAppInsights.js
*/

const nodeFetch = require("node-fetch").default
const querystring = require("querystring")

const APP_INSIGHTS_ID = process.env.APP_INSIGHTS_ID;
const APP_INSIGHTS_API_KEY = process.env.APP_INSIGHTS_API_KEY;

// Get these from: https://ms.portal.azure.com/#@microsoft.onmicrosoft.com/resource/subscriptions/57bfeeed-c34a-4ffd-a06b-ccff27ac91b8/resourceGroups/typescriptlang-org/providers/microsoft.insights/components/TypeScriptLang-Prod-Ai/apiKeys
if (!process.env.APP_INSIGHTS_ID)
if (!APP_INSIGHTS_ID)
throw new Error("No App Insights ID at process.env.APP_INSIGHTS_ID")

if (!process.env.APP_INSIGHTS_API_KEY)
if (!APP_INSIGHTS_API_KEY)
throw new Error("No App Insights ID at process.env.APP_INSIGHTS_API_KEY")

const getJSON = async (query, params) => {
const headers = {
"x-api-key": process.env.APP_INSIGHTS_API_KEY,
"x-api-key": APP_INSIGHTS_API_KEY,
}

const queryParams = querystring.stringify(params)
const root = `https://api.applicationinsights.io/v1/apps/${process.env.APP_INSIGHTS_ID}`
const root = `https://api.applicationinsights.io/v1/apps/${APP_INSIGHTS_ID}`
const href = `${root}${query}?${queryParams}`
const response = await nodeFetch(href, { headers })
const response = await fetch(href, { headers })

if (!response.ok) {
console.error("Error in API call to app insights")
Expand Down
Loading