Skip to content

Commit

Permalink
Replace request-promise with node-fetch (MetaMask#7899)
Browse files Browse the repository at this point in the history
`node-fetch` is a smaller and simpler project than `request-promise`,
and we already have it as a transitive dependency.

`request-promise` was also incorrectly listed as a production
dependency. `node-fetch` has been added as a `devDependency` to replace
it, as it was only used in one CI script.
  • Loading branch information
Gudahtt authored and yqrashawn committed Feb 10, 2020
1 parent 0def1c5 commit d562366
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
40 changes: 29 additions & 11 deletions development/metamaskbot-build-announce.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
const { promises: fs } = require('fs')
const path = require('path')
const request = require('request-promise')
const fetch = require('node-fetch')
const VERSION = require('../dist/chrome/manifest.json').version // eslint-disable-line import/no-unresolved

start().catch(console.error)
Expand Down Expand Up @@ -78,7 +78,11 @@ async function start () {

const benchmarkResults = {}
for (const platform of platforms) {
const benchmarkPath = path.resolve(__dirname, '..', path.join('test-artifacts', platform, 'benchmark', 'pageload.json'))
const benchmarkPath = path.resolve(
__dirname,
'..',
path.join('test-artifacts', platform, 'benchmark', 'pageload.json')
)
try {
const data = await fs.readFile(benchmarkPath, 'utf8')
const benchmark = JSON.parse(data)
Expand All @@ -87,7 +91,9 @@ async function start () {
if (error.code === 'ENOENT') {
console.log(`No benchmark data found for ${platform}; skipping`)
} else {
console.error(`Error encountered processing benchmark data for '${platform}': '${error}'`)
console.error(
`Error encountered processing benchmark data for '${platform}': '${error}'`
)
}
}
}
Expand All @@ -98,8 +104,12 @@ async function start () {
commentBody = artifactsBody
} else {
try {
const chromePageLoad = Math.round(parseFloat(benchmarkResults.chrome.notification.average.load))
const chromePageLoadMarginOfError = Math.round(parseFloat(benchmarkResults.chrome.notification.marginOfError.load))
const chromePageLoad = Math.round(
parseFloat(benchmarkResults.chrome.notification.average.load)
)
const chromePageLoadMarginOfError = Math.round(
parseFloat(benchmarkResults.chrome.notification.marginOfError.load)
)
const benchmarkSummary = `Page Load Metrics (${chromePageLoad} ± ${chromePageLoadMarginOfError} ms)`

const allPlatforms = new Set()
Expand Down Expand Up @@ -133,14 +143,21 @@ async function start () {
for (const metric of allMetrics) {
let metricData = `<td>${metric}</td>`
for (const measure of allMeasures) {
metricData += `<td align="right">${Math.round(parseFloat(benchmarkResults[platform][page][measure][metric]))}</td>`
metricData += `<td align="right">${Math.round(
parseFloat(benchmarkResults[platform][page][measure][metric])
)}</td>`
}
metricRows.push(metricData)
}
metricRows[0] = `<td rowspan="${allMetrics.size}">${capitalizeFirstLetter(page)}</td>${metricRows[0]}`
metricRows[0] = `<td rowspan="${
allMetrics.size
}">${capitalizeFirstLetter(page)}</td>${metricRows[0]}`
pageRows.push(...metricRows)
}
pageRows[0] = `<td rowspan="${allPages.size * allMetrics.size}">${capitalizeFirstLetter(platform)}</td>${pageRows[0]}`
pageRows[0] = `<td rowspan="${allPages.size *
allMetrics.size}">${capitalizeFirstLetter(platform)}</td>${
pageRows[0]
}`
for (const row of pageRows) {
tableRows.push(`<tr>${row}</tr>`)
}
Expand All @@ -150,7 +167,9 @@ async function start () {
for (const measure of allMeasures) {
benchmarkTableHeaders.push(`${capitalizeFirstLetter(measure)} (ms)`)
}
const benchmarkTableHeader = `<thead><tr>${benchmarkTableHeaders.map(header => `<th>${header}</th>`).join('')}</tr></thead>`
const benchmarkTableHeader = `<thead><tr>${benchmarkTableHeaders
.map(header => `<th>${header}</th>`)
.join('')}</tr></thead>`
const benchmarkTableBody = `<tbody>${tableRows.join('')}</tbody>`
const benchmarkTable = `<table>${benchmarkTableHeader}${benchmarkTableBody}</table>`
const benchmarkBody = `<details><summary>${benchmarkSummary}</summary>${benchmarkTable}</details>`
Expand All @@ -166,9 +185,8 @@ async function start () {
console.log(`Announcement:\n${commentBody}`)
console.log(`Posting to: ${POST_COMMENT_URI}`)

await request({
await fetch(POST_COMMENT_URI, {
method: 'POST',
uri: POST_COMMENT_URI,
body: JSON_PAYLOAD,
headers: {
'User-Agent': 'confluxbot',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
"redux": "^3.0.5",
"redux-logger": "^3.0.6",
"redux-thunk": "^2.2.0",
"request-promise": "^4.2.1",
"reselect": "^3.0.1",
"rpc-cap": "^1.0.1",
"safe-event-emitter": "^1.0.1",
Expand Down Expand Up @@ -292,6 +291,7 @@
"mocha-jsdom": "^1.1.0",
"mocha-sinon": "^2.0.0",
"nock": "^9.0.14",
"node-fetch": "^2.6.0",
"node-sass": "^4.12.0",
"nodemon": "^2.0.2",
"nyc": "^13.0.0",
Expand Down
10 changes: 0 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24690,16 +24690,6 @@ request-promise-native@^1.0.3:
stealthy-require "^1.1.0"
tough-cookie ">=2.3.3"

request-promise@^4.2.1:
version "4.2.2"
resolved "https://registry.yarnpkg.com/request-promise/-/request-promise-4.2.2.tgz#d1ea46d654a6ee4f8ee6a4fea1018c22911904b4"
integrity sha1-0epG1lSm7k+O5qT+oQGMIpEZBLQ=
dependencies:
bluebird "^3.5.0"
request-promise-core "1.1.1"
stealthy-require "^1.1.0"
tough-cookie ">=2.3.3"

request@^2.45.0, request@^2.81.0, request@^2.83.0:
version "2.87.0"
resolved "https://registry.yarnpkg.com/request/-/request-2.87.0.tgz#32f00235cd08d482b4d0d68db93a829c0ed5756e"
Expand Down

0 comments on commit d562366

Please sign in to comment.