Skip to content

Commit

Permalink
Upgrade dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 26, 2019
1 parent b82358f commit d968e49
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -57,19 +57,19 @@
"@sindresorhus/tsconfig": "^0.6.0",
"@types/duplexer3": "^0.1.0",
"@types/express": "^4.17.2",
"@types/lolex": "^3.1.1",
"@types/node": "^12.12.8",
"@types/lolex": "^5.1.0",
"@types/node": "^12.12.14",
"@types/proxyquire": "^1.3.28",
"@types/sinon": "^7.0.13",
"@types/tough-cookie": "^2.3.5",
"@typescript-eslint/eslint-plugin": "^2.7.0",
"@typescript-eslint/parser": "^2.7.0",
"@typescript-eslint/eslint-plugin": "^2.9.0",
"@typescript-eslint/parser": "^2.9.0",
"ava": "^2.4.0",
"coveralls": "^3.0.4",
"create-test-server": "^3.0.1",
"del-cli": "^3.0.0",
"delay": "^4.3.0",
"eslint-config-xo-typescript": "^0.21.0",
"eslint-config-xo-typescript": "^0.23.0",
"express": "^4.17.1",
"form-data": "^3.0.0",
"get-port": "^5.0.0",
Expand Down
2 changes: 2 additions & 0 deletions source/create.ts
Expand Up @@ -118,6 +118,7 @@ const create = (defaults: NormalizedDefaults & {_rawHandlers?: HandlerFunction[]
);
};

/* eslint-disable @typescript-eslint/return-await */
try {
return iterateHandlers(normalizeArguments(url, options, defaults));
} catch (error) {
Expand All @@ -128,6 +129,7 @@ const create = (defaults: NormalizedDefaults & {_rawHandlers?: HandlerFunction[]
return Promise.reject(error);
}
}
/* eslint-enable @typescript-eslint/return-await */
};

got.extend = (...instancesOrOptions) => {
Expand Down
2 changes: 1 addition & 1 deletion source/errors.ts
Expand Up @@ -79,7 +79,7 @@ export class HTTPError extends GotError {
declare readonly response: Response;

constructor(response: Response, options: NormalizedOptions) {
super(`Response code ${response.statusCode} (${response.statusMessage})`, {}, options);
super(`Response code ${response.statusCode} (${response.statusMessage ?? ''})`, {}, options);
this.name = 'HTTPError';

Object.defineProperty(this, 'response', {
Expand Down
9 changes: 5 additions & 4 deletions source/normalize-arguments.ts
Expand Up @@ -139,7 +139,7 @@ export const preNormalizeArguments = (options: Options, defaults?: NormalizedOpt
if (is.string(options.method)) {
options.method = options.method.toUpperCase() as Method;
} else {
options.method = defaults?.method || 'GET';
options.method = defaults?.method ?? 'GET';
}

// Better memory management, so we don't have to generate a new object every time
Expand Down Expand Up @@ -224,13 +224,13 @@ export const normalizeArguments = (url: URLOrOptions, options?: Options, default
if (is.urlInstance(url) || is.string(url)) {
options.url = url;

options = mergeOptions((defaults && defaults.options) ?? {}, options);
options = mergeOptions((defaults?.options) ?? {}, options);
} else {
if (Reflect.has(url, 'resolve')) {
throw new Error('The legacy `url.Url` is deprecated. Use `URL` instead.');
}

options = mergeOptions((defaults && defaults.options) ?? {}, url, options);
options = mergeOptions((defaults?.options) ?? {}, url, options);
}

// Normalize URL
Expand Down Expand Up @@ -270,6 +270,7 @@ export const normalizeArguments = (url: URLOrOptions, options?: Options, default
// Make it possible to remove default headers
for (const [key, value] of Object.entries(normalizedOptions.headers)) {
if (is.undefined(value)) {
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete normalizedOptions.headers[key];
} else if (is.null_(value)) {
throw new TypeError('Use `undefined` instead of `null` to delete HTTP headers');
Expand Down Expand Up @@ -405,7 +406,7 @@ export const normalizeRequestArguments = async (options: NormalizedOptions): Pro
}

if (isAgentByProtocol(options.agent)) {
options.agent = options.agent[options.url.protocol.slice(0, -1) as keyof AgentByProtocol] || options.agent;
options.agent = options.agent[options.url.protocol.slice(0, -1) as keyof AgentByProtocol] ?? options.agent;
}

if (options.dnsCache) {
Expand Down
3 changes: 1 addition & 2 deletions source/request-as-event-emitter.ts
Expand Up @@ -68,8 +68,7 @@ export default (options: NormalizedOptions) => {

const typedResponse = response as Response;
const {statusCode} = typedResponse;
// This is intentionally using `||` over `??` so it can also catch empty status message.
typedResponse.statusMessage = typedResponse.statusMessage || http.STATUS_CODES[statusCode];
typedResponse.statusMessage = is.nonEmptyString(typedResponse.statusMessage) ? typedResponse.statusMessage : http.STATUS_CODES[statusCode];
typedResponse.url = options.url.toString();
typedResponse.requestUrl = requestURL;
typedResponse.retryCount = retryCount;
Expand Down
2 changes: 1 addition & 1 deletion source/types/reflect/index.d.ts
@@ -1,5 +1,5 @@
// The type-guarding behaviour is currently not supported as of TypeScript 3.7
// https://github.com/microsoft/TypeScript/issues/30688
declare namespace Reflect {
function has<T extends object, Key extends PropertyKey>(target: T, propertyKey: Key): target is Required<Extract<T, { [Key]: any }>>;
function has<T extends object, Key extends PropertyKey>(target: T, propertyKey: Key): target is Required<Extract<T, {[key: Key]: any}>>;
}
4 changes: 2 additions & 2 deletions source/utils/options-to-url.ts
@@ -1,7 +1,7 @@
function validateSearchParams(searchParams: Record<string, unknown>): asserts searchParams is Record<string, string | number | boolean | null> {
for (const value of Object.values(searchParams)) {
if (typeof value !== 'string' && typeof value !== 'number' && typeof value !== 'boolean' && value !== null) {
throw new TypeError(`The \`searchParams\` value '${value}' must be a string, number, boolean or null`);
throw new TypeError(`The \`searchParams\` value '${String(value)}' must be a string, number, boolean or null`);
}
}
}
Expand Down Expand Up @@ -59,7 +59,7 @@ export default (options: URLOptions): URL => {
throw new TypeError('No URL protocol specified');
}

origin = `${options.protocol}//${options.hostname || options.host}`;
origin = `${options.protocol}//${options.hostname ?? options.host ?? ''}`;
}

const url = new URL(origin);
Expand Down

0 comments on commit d968e49

Please sign in to comment.