Skip to content

Commit

Permalink
fix(deps): update dependency got to v11 (#1248)
Browse files Browse the repository at this point in the history
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [got](https://togithub.com/sindresorhus/got) | dependencies | major | [`^10.0.0` -> `^11.0.0`](https://renovatebot.com/diffs/npm/got/10.7.0/11.0.0) |

---

### Release Notes

<details>
<summary>sindresorhus/got</summary>

### [`v11.0.0`](https://togithub.com/sindresorhus/got/releases/v11.0.0)

[Compare Source](https://togithub.com/sindresorhus/got/compare/v10.7.0...v11.0.0)

Introducing Got 11! 🎉 The last major version was in December last year. ❄️ Since then, a huge amount of bugs has been fixed. There are also many new features, for example, **HTTP2 support** is finally live! 🌐

_If you find Got useful, you might want to [sponsor the Got maintainers](https://togithub.com/sindresorhus/got?sponsor=1)._

* * *

#### Breaking changes

##### Removed support for `electron.net`

Due to the inconsistencies between the Electron's `net` module and the Node.js `http` module, we have decided to officially drop support for it. Therefore, the `useElectronNet` option has been removed.

You'll still be able to use Got in the Electron main process and in the renderer process through the `electron.remote` module or if you use Node.js shims.

##### The Pagination API is now stable

We haven't seen any bugs yet, so please give it a try!
If you want to leave some feedback, you can do it [here](https://togithub.com/sindresorhus/got/issues/1052). Any suggestion is greatly appreciated!

```diff
 {
-    _pagination: {...}
+    pagination: {...}
 }
```

##### API

-   The `options.encoding` behavior has been reverted back to the Got 9 behavior.
    In other words, the options is only meant for the Got promise API.
    To set the encoding for streams, simply call `stream.setEncoding(encoding)`.

```diff
-got.stream('https://sindresorhus.com', {encoding: 'base64'});
+got.stream('https://sindresorhus.com').setEncoding('base64');

// Promises stay untouched
await got('https://sindresorhus.com', {encoding: 'base64'});
```

-   The error name `GotError` has been renamed to `RequestError` for better readability and to comply with the documentation.

```diff
-const {GotError} = require('got');
+const {RequestError} = require('got');
```

-   The `agent` option now accepts **only an object** with `http`, `https` and `http2` properties.
    While the `http` and `https` properties accept native `http(s).Agent` instances, the `http2` property must be an instance of [`http2wrapper.Agent`](https://togithub.com/szmarczak/http2-wrapper#new-http2agentoptions) or be undefined.

```diff
{
-    agent: new https.Agent({keepAlive: true})
}

{
+    agent: {
+        http: new http.Agent({keepAlive: true}),
+        https: new https.Agent({keepAlive: true}),
+        http2: new http2wrapper.Agent()
+    }
}
```

-   The `dnsCache` option is now set to a default instance of [`CacheableLookup`](https://togithub.com/szmarczak/cacheable-lookup). It cannot be a `Map`-like instance anymore. The underlying [`cacheable-lookup`](https://togithub.com/szmarczak/cacheable-lookup) package has received many improvements, for example, it has received `hosts` file support! Additionally, the `cacheAdapter` option has been renamed to `cache`. Note that it's no longer passed to [Keyv](https://togithub.com/lukechilds/keyv), so you need to pass a Keyv instance it if you want to save the data for later.

```diff
{
-    dnsCache: new CacheableLookup({
-        cacheAdapter: new Map()
-    })
}

{
+    dnsCache: new CacheableLookup({
+        cache: new Keyv({
+            cacheAdapter: new Map()
+        })
+    })
}

// Default:

{
    dnsCache: new CacheableLookup()
}
```

-   Errors thrown in `init` hooks will be converted to instances of `RequestError`. `RequestError`s provide much more useful information, for example, you can access the Got options (through `error.options`), which is very useful when debugging.

```js
const got = require('got');

(async () => {
    try {
        await got('https://sindresorhus.com', {
            hooks: {
                init: [
                    options => {
                        if (!options.context) {
                            throw new Error('You need to pass a `context` option');
                        }
                    }
                ]
            }
        });
    } catch (error) {
        console.log(`Request failed: ${error.message}`);
        console.log('Here are the options:', error.options);
    }
})();
```

-   The options passed in an `init` hook may not have a `url` property. To modify the request URL you should use a `beforeRequest` hook instead.

```diff
{
    hooks: {
-        init: [
+        beforeRequest: [
            options => {
                options.url = 'https://sindresorhus.com';
            }
        ]
    }
}
```

Note that this example shows a simple use case. In more complicated algorithms, you need to split the `init` hook into another `init` hook and a `beforeRequest` hook.

-   The `error.request` property is no longer a `ClientRequest` instance. Instead, it gives a Got stream, which provides a set of useful properties.

```js
const got = require('got');

(async () => {
    try {
        await got('https://sindresorhus.com/notfound');
    } catch (error) {
        console.log(`Request failed: ${error.message}`);
        console.log('Download progress:', error.request.downloadProgress);
    }
})();
```

##### Renamed TypeScript types

Some of the TypeScript types have been renamed to improve the readability:

<table>
<tr>
    <td>Old type</td>
    <td>New type</td>
</tr>
<tr>
    <td><code>ResponseObject</code></td>
    <td><code>Response</code></td>
</tr>
<tr>
    <td><code>Defaults</code></td>
    <td><code>InstanceDefaults</code></td>
</tr>
<tr>
    <td><code>DefaultOptions</code></td>
    <td><code>Defaults</code></td>
</tr>
<tr>
    <td><code>DefaultRetryOptions</code></td>
    <td><code>RequiredRetryOptions</code></td>
</tr>
<tr>
    <td><code>GotOptions</code></td>
    <td><code>Options</code></td>
</tr>
<tr>
    <td><code>GotRequestMethod</code></td>
    <td><code>GotRequestFunction</code></td>
</tr>
</table>
#### Enhancements

HTTP2 support is here! Excited? Yay! Unfortunately, it's off by default to make the migration smoother. Many Got users have set up their own Agents and we didn't want to break them. But fear no more, it will come enabled by default in Got 12.

```js
const got = require('got');

(async () => {
    const response = await got('https://nghttp2.org/httpbin/anything', {http2: true});
    console.log(response.socket.alpnProtocol);
    //=> 'h2'
})();
```

1.  The `merge` function is slow ([#&#8203;1016](https://togithub.com/sindresorhus/got/issues/1016))
2.  Use `error.code` instead of `error.message` to compare errors ([#&#8203;981](https://togithub.com/sindresorhus/got/issues/981))
3.  Pass error thrown in the `init` hook to `beforeError` hook ([#&#8203;929](https://togithub.com/sindresorhus/got/issues/929))
4.  Errors have undefined body when using streams ([#&#8203;1138](https://togithub.com/sindresorhus/got/issues/1138))
5.  Spaces should be normalized as `+` in query strings ([#&#8203;1113](https://togithub.com/sindresorhus/got/issues/1113))
6.  Modify response headers while using `got.stream(...)` ([#&#8203;1129](https://togithub.com/sindresorhus/got/issues/1129))
7.  Make `error.request` a Got stream ([`af0b147`](https://togithub.com/sindresorhus/got/commit/af0b1472abf48a6c5491dcb36a1d8863c5227fb3)).

#### Known bugs

1.  When some errors occur, the `timings` may indicate that the request was successful although it failed.
2.  When some errors occur, the `downloadProgress` object may show incorrect data.

#### Bug fixes

1.  Requests to UNIX sockets are missing query strings ([#&#8203;1036](https://togithub.com/sindresorhus/got/issues/1036))
2.  `beforeRequest` hooks aren't called on redirects ([#&#8203;994](https://togithub.com/sindresorhus/got/issues/994))
3.  Errors are swallowed when using `stream.pipeline(got.stream(...), ...)` ([#&#8203;1026](https://togithub.com/sindresorhus/got/issues/1026))
4.  Cannot use the `cache` along with the `body` option ([#&#8203;1021](https://togithub.com/sindresorhus/got/issues/1021))
5.  Got doesn't throw on leading slashes ([#&#8203;1057](https://togithub.com/sindresorhus/got/issues/1057))
6.  Got throws when passing already frozen options ([#&#8203;1050](https://togithub.com/sindresorhus/got/issues/1050))
7.  Cannot type Got options properly due to missing types ([#&#8203;954](https://togithub.com/sindresorhus/got/issues/954))
8.  `got.mergeOptions(...)` doesn't merge `URLSearchParams` instances ([#&#8203;1011](https://togithub.com/sindresorhus/got/issues/1011))
9.  The `authorization` header is leaking ([#&#8203;1090](https://togithub.com/sindresorhus/got/issues/1090))
10. Pagination should ignore the `resolveBodyOnly` option ([#&#8203;1140](https://togithub.com/sindresorhus/got/issues/1140))
11. Cannot reuse user-provided options ([#&#8203;1118](https://togithub.com/sindresorhus/got/issues/1118))
12. Broken with Node.js ≥ 13.10.0 ([#&#8203;1107](https://togithub.com/sindresorhus/got/issues/1107))
13. Cache is not decompressed ([#&#8203;1158](https://togithub.com/sindresorhus/got/issues/1158))
14. `beforeRetry` hooks are missing `options.context` ([#&#8203;1141](https://togithub.com/sindresorhus/got/issues/1141))
15. `promise.json()` doesn't throw `ParseError` ([#&#8203;1069](https://togithub.com/sindresorhus/got/issues/1069))
16. Not compatible with `tough-cookie@4.0.0` ([#&#8203;1131](https://togithub.com/sindresorhus/got/issues/1131))
17. Shortcuts give body from the failed request on token renewal ([#&#8203;1120](https://togithub.com/sindresorhus/got/issues/1120))
18. No effect when replacing the `cache` option in a Got instance ([#&#8203;1098](https://togithub.com/sindresorhus/got/issues/1098))
19. Memory leak when using `cache` ([#&#8203;1128](https://togithub.com/sindresorhus/got/issues/1128))
20. Got doesn't throw on aborted requests by the server ([#&#8203;1096](https://togithub.com/sindresorhus/got/issues/1096))

#### All changes

</details>

---

### Renovate configuration

:date: **Schedule**: "after 9am and before 3pm" (UTC).

:vertical_traffic_light: **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

:recycle: **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

:no_bell: **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [WhiteSource Renovate](https://renovate.whitesourcesoftware.com). View repository job log [here](https://app.renovatebot.com/dashboard#googleapis/cloud-trace-nodejs).
  • Loading branch information
renovate-bot authored Apr 20, 2020
1 parent 511b21c commit 03ff0f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"dependencies": {
"@google-cloud/trace-agent": "^4.2.5",
"express": "^4.16.4",
"got": "^10.0.0"
"got": "^11.0.0"
},
"devDependencies": {
"execa": "^4.0.0",
Expand Down

0 comments on commit 03ff0f4

Please sign in to comment.