Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
Use small HTTP dependency (#110)
Browse files Browse the repository at this point in the history
Replace request with teeny-request. Improve startup time by 400 ms.

request is a large module because it has so many options and features. That
requires both extra bandwidth and space, and also extra time to load and
parse the module every time codecov is run.

Uploading the reports only uses a minimal subset of request's features.
request can easily be switched out with a much more lightweight dependency.
  • Loading branch information
fhinkel authored and eddiemoore committed Sep 11, 2018
1 parent 500f308 commit 023d204
Show file tree
Hide file tree
Showing 3 changed files with 970 additions and 1,205 deletions.
22 changes: 13 additions & 9 deletions lib/codecov.js
@@ -1,6 +1,6 @@
var fs = require('fs')
var path = require('path')
var request = require('request')
var request = require('teeny-request').teenyRequest
var urlgrey = require('urlgrey')
var jsYaml = require('js-yaml')
var walk = require('ignore-walk')
Expand Down Expand Up @@ -146,11 +146,12 @@ var sendToCodecovV2 = function(
on_failure
) {
// Direct to Codecov
request.post(
request(
{
url: urlgrey(codecov_endpoint + '/upload/v2')
uri: urlgrey(codecov_endpoint + '/upload/v2')
.query(query)
.toString(),
method: 'POST',
body: upload_body,
headers: {
'Content-Type': 'text/plain',
Expand Down Expand Up @@ -180,11 +181,12 @@ var sendToCodecovV3 = function(
on_failure
) {
// Direct to S3
request.post(
request(
{
url: urlgrey(codecov_endpoint + '/upload/v4')
uri: urlgrey(codecov_endpoint + '/upload/v4')
.query(query)
.toString(),
method: 'POST',
body: '',
headers: {
'Content-Type': 'text/plain',
Expand All @@ -202,9 +204,10 @@ var sendToCodecovV3 = function(
)
} else {
var codecov_report_url = result.split('\n')[0]
request.put(
request(
{
url: result.split('\n')[1],
uri: result.split('\n')[1],
method: 'PUT',
body: upload_body,
headers: {
'Content-Type': 'text/plain',
Expand Down Expand Up @@ -299,8 +302,9 @@ var upload = function(args, on_success, on_failure) {

var yamlToken
try {
var loadedYamlFile = jsYaml.safeLoad(fs.readFileSync(query.yaml, 'utf8'))
yamlToken = loadedYamlFile && loadedYamlFile.codecov && loadedYamlFile.codecov.token
var loadedYamlFile = jsYaml.safeLoad(fs.readFileSync(query.yaml, 'utf8'))
yamlToken =
loadedYamlFile && loadedYamlFile.codecov && loadedYamlFile.codecov.token
} catch (e) {
// silently fail
}
Expand Down

0 comments on commit 023d204

Please sign in to comment.