Skip to content

Commit

Permalink
fix: used named export in request module
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 23, 2021
1 parent ac34bbe commit 4d3d2b1
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 57 deletions.
2 changes: 1 addition & 1 deletion src/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Command from "./command"
import Install from "./install"
import * as git from "./git"
import Link from "./link"
import request from "./request"
import * as request from "./request"

export default class Develop extends Command {
constructor() {
Expand Down
2 changes: 1 addition & 1 deletion src/featured.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import _ from "underscore-plus"
import yargs from "yargs"
import Command from "./command"
import * as config from "./apm"
import request from "./request"
import * as request from "./request"
import { tree } from "./tree"

export default class Featured extends Command {
Expand Down
1 change: 0 additions & 1 deletion src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
let Init
import path from "path"
import yargs from "yargs"
import Command from "./command"
Expand Down
2 changes: 1 addition & 1 deletion src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as config from "./apm"
import Command from "./command"
import fs from "./fs"
import RebuildModuleCache from "./rebuild-module-cache"
import request from "./request"
import * as request from "./request"
import { isDeprecatedPackage } from "./deprecated-packages"

export default class Install extends Command {
Expand Down
2 changes: 1 addition & 1 deletion src/package-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ScopeSelector } from "first-mate"
import tar from "tar"
import temp from "temp"
import fs from "./fs"
import request from "./request"
import * as request from "./request"

// Convert a TextMate bundle to an Atom package
export default class PackageConverter {
Expand Down
2 changes: 1 addition & 1 deletion src/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import * as config from "./apm"
import Command from "./command"
import Login from "./login"
import * as Packages from "./packages"
import request from "./request"
import * as request from "./request"

export default class Publish extends Command {
constructor() {
Expand Down
82 changes: 40 additions & 42 deletions src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,50 @@ const configureRequest = (requestOptions, callback) =>
return callback()
})

export default {
get(requestOptions, callback) {
return configureRequest(requestOptions, function () {
let retryCount = requestOptions.retries != null ? requestOptions.retries : 0
let requestsMade = 0
var tryRequest = function () {
requestsMade++
return request.get(requestOptions, function (error, response, body) {
if (retryCount > 0 && ["ETIMEDOUT", "ECONNRESET"].includes(error?.code)) {
retryCount--
return tryRequest()
} else {
if (error?.message && requestsMade > 1) {
error.message += ` (${requestsMade} attempts)`
}

return callback(error, response, body)
export function get(requestOptions, callback) {
return configureRequest(requestOptions, function () {
let retryCount = requestOptions.retries != null ? requestOptions.retries : 0
let requestsMade = 0
var tryRequest = function () {
requestsMade++
return request.get(requestOptions, function (error, response, body) {
if (retryCount > 0 && ["ETIMEDOUT", "ECONNRESET"].includes(error?.code)) {
retryCount--
return tryRequest()
} else {
if (error?.message && requestsMade > 1) {
error.message += ` (${requestsMade} attempts)`
}
})
}
return tryRequest()
})
},

del(requestOptions, callback) {
return configureRequest(requestOptions, () => request.del(requestOptions, callback))
},
return callback(error, response, body)
}
})
}
return tryRequest()
})
}

export function del(requestOptions, callback) {
return configureRequest(requestOptions, () => request.del(requestOptions, callback))
}

post(requestOptions, callback) {
return configureRequest(requestOptions, () => request.post(requestOptions, callback))
},
export function post(requestOptions, callback) {
return configureRequest(requestOptions, () => request.post(requestOptions, callback))
}

createReadStream(requestOptions, callback) {
return configureRequest(requestOptions, () => callback(request.get(requestOptions)))
},
export function createReadStream(requestOptions, callback) {
return configureRequest(requestOptions, () => callback(request.get(requestOptions)))
}

getErrorMessage(response, body) {
if (response?.statusCode === 503) {
return "atom.io is temporarily unavailable, please try again later."
} else {
let left
return (left = body?.message != null ? body?.message : body?.error) != null ? left : body
}
},
export function getErrorMessage(response, body) {
if (response?.statusCode === 503) {
return "atom.io is temporarily unavailable, please try again later."
} else {
let left
return (left = body?.message != null ? body?.message : body?.error) != null ? left : body
}
}

debug(debug) {
return (request.debug = debug)
},
export function debug(debug) {
return (request.debug = debug)
}
2 changes: 1 addition & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import _ from "underscore-plus"
import yargs from "yargs"
import Command from "./command"
import * as config from "./apm"
import request from "./request"
import * as request from "./request"
import { tree } from "./tree"
import { isDeprecatedPackage } from "./deprecated-packages"

Expand Down
2 changes: 1 addition & 1 deletion src/star.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Command from "./command"
import fs from "./fs"
import Login from "./login"
import * as Packages from "./packages"
import request from "./request"
import * as request from "./request"

export default class Star extends Command {
parseOptions(argv) {
Expand Down
2 changes: 1 addition & 1 deletion src/stars.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Command from "./command"
import * as config from "./apm"
import Install from "./install"
import Login from "./login"
import request from "./request"
import * as request from "./request"
import { tree } from "./tree"

export default class Stars extends Command {
Expand Down
2 changes: 1 addition & 1 deletion src/theme-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import path from "path"
import url from "url"
import fs from "./fs"
import request from "./request"
import * as request from "./request"
import TextMateTheme from "./text-mate-theme"

// Convert a TextMate theme to an Atom theme
Expand Down
2 changes: 1 addition & 1 deletion src/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import * as auth from "./auth"
import Command from "./command"
import * as config from "./apm"
import fs from "./fs"
import request from "./request"
import * as request from "./request"

export default class Uninstall extends Command {
parseOptions(argv) {
Expand Down
2 changes: 1 addition & 1 deletion src/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import * as auth from "./auth"
import Command from "./command"
import * as config from "./apm"
import fs from "./fs"
import request from "./request"
import * as request from "./request"

export default class Unpublish extends Command {
parseOptions(argv) {
Expand Down
2 changes: 1 addition & 1 deletion src/unstar.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import yargs from "yargs"
import * as config from "./apm"
import Command from "./command"
import Login from "./login"
import request from "./request"
import * as request from "./request"

export default class Unstar extends Command {
parseOptions(argv) {
Expand Down
2 changes: 1 addition & 1 deletion src/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import * as config from "./apm"
import fs from "./fs"
import Install from "./install"
import * as Packages from "./packages"
import request from "./request"
import * as request from "./request"
import { tree } from "./tree"
import * as git from "./git"

Expand Down
2 changes: 1 addition & 1 deletion src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import yargs from "yargs"
import semver from "semver"
import Command from "./command"
import * as config from "./apm"
import request from "./request"
import * as request from "./request"
import { tree } from "./tree"

export default class View extends Command {
Expand Down

0 comments on commit 4d3d2b1

Please sign in to comment.