From 4d3d2b15c9c8e2db5df635db73594b2f2c52911e Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 22 Jul 2021 23:56:51 -0500 Subject: [PATCH] fix: used named export in request module --- src/develop.js | 2 +- src/featured.js | 2 +- src/init.js | 1 - src/install.js | 2 +- src/package-converter.js | 2 +- src/publish.js | 2 +- src/request.js | 82 ++++++++++++++++++++-------------------- src/search.js | 2 +- src/star.js | 2 +- src/stars.js | 2 +- src/theme-converter.js | 2 +- src/uninstall.js | 2 +- src/unpublish.js | 2 +- src/unstar.js | 2 +- src/upgrade.js | 2 +- src/view.js | 2 +- 16 files changed, 54 insertions(+), 57 deletions(-) diff --git a/src/develop.js b/src/develop.js index 34377b3..f5eabe4 100644 --- a/src/develop.js +++ b/src/develop.js @@ -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() { diff --git a/src/featured.js b/src/featured.js index 14ee737..83fcf0a 100644 --- a/src/featured.js +++ b/src/featured.js @@ -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 { diff --git a/src/init.js b/src/init.js index f9f75fc..92bdf3d 100644 --- a/src/init.js +++ b/src/init.js @@ -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" diff --git a/src/install.js b/src/install.js index 2ab26ec..c6915d5 100644 --- a/src/install.js +++ b/src/install.js @@ -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 { diff --git a/src/package-converter.js b/src/package-converter.js index b004ace..4a1a796 100644 --- a/src/package-converter.js +++ b/src/package-converter.js @@ -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 { diff --git a/src/publish.js b/src/publish.js index da20ca3..0ac2dee 100644 --- a/src/publish.js +++ b/src/publish.js @@ -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() { diff --git a/src/request.js b/src/request.js index a061c3d..2310a1e 100644 --- a/src/request.js +++ b/src/request.js @@ -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) } diff --git a/src/search.js b/src/search.js index 9ef658b..431df80 100644 --- a/src/search.js +++ b/src/search.js @@ -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" diff --git a/src/star.js b/src/star.js index a92461a..a0487ff 100644 --- a/src/star.js +++ b/src/star.js @@ -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) { diff --git a/src/stars.js b/src/stars.js index 4730d46..9afc69d 100644 --- a/src/stars.js +++ b/src/stars.js @@ -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 { diff --git a/src/theme-converter.js b/src/theme-converter.js index 0194484..4c8f9d6 100644 --- a/src/theme-converter.js +++ b/src/theme-converter.js @@ -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 diff --git a/src/uninstall.js b/src/uninstall.js index cb74d76..b58a364 100644 --- a/src/uninstall.js +++ b/src/uninstall.js @@ -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) { diff --git a/src/unpublish.js b/src/unpublish.js index 8fbfa56..b9c4758 100644 --- a/src/unpublish.js +++ b/src/unpublish.js @@ -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) { diff --git a/src/unstar.js b/src/unstar.js index f17ca7f..e3280f2 100644 --- a/src/unstar.js +++ b/src/unstar.js @@ -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) { diff --git a/src/upgrade.js b/src/upgrade.js index b949b4c..9d6f0bc 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -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" diff --git a/src/view.js b/src/view.js index 698f18c..019dd38 100644 --- a/src/view.js +++ b/src/view.js @@ -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 {