Skip to content

Commit

Permalink
Merge branch 'master' into patch-2
Browse files Browse the repository at this point in the history
  • Loading branch information
titanism committed Apr 23, 2024
2 parents a5c39b2 + ea633d7 commit 450f7b2
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 48 deletions.
32 changes: 10 additions & 22 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@ jobs:
strategy:
matrix:
include:
- node-version: 10.x
test-on-old-node: 1
- node-version: 12.x
test-on-old-node: 1
# test-on-brower: 1
- node-version: 14.x
- node-version: 16.x
- node-version: 18.x
Expand All @@ -29,25 +24,18 @@ jobs:
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Cache node modules
uses: actions/cache@v3
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
- name: Install Dependencies On Old Node ${{ matrix.node-version }}
if: ${{ matrix.test-on-old-node == '1' }}
run: node ci/remove-deps-4-old-node.js && yarn install --ignore-scripts
- name: Install Dependencies On Node ${{ matrix.node-version }}
if: ${{ matrix.test-on-old-node != '1' }}
run: yarn install
# - name: Cache node modules
# uses: actions/cache@v3
# env:
# cache-name: cache-node-modules
# with:
# # npm cache files are stored in `~/.npm` on Linux/macOS
# path: ~/.npm
# key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/yarn.lock') }}
- name: Install dependencies
run: npm install
- name: Build
run: npm run build
- name: Build On Old Node
if: ${{ matrix.test-on-old-node == '1' }}
run: npm run build:test
- name: Test On Node ${{ matrix.node-version }}
env:
BROWSER: ${{ matrix.test-on-brower }}
Expand Down
2 changes: 1 addition & 1 deletion .lib.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": [
["@babel/env", {
"targets": {
"node": "6.4.0",
"node": "14.18.0",
"browsers": [ "defaults, not ie 11" ]
}
}]
Expand Down
2 changes: 1 addition & 1 deletion .test.babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"presets": [
["@babel/env", {
"targets": {
"node": "6.4.0",
"node": "14.18.0",
"browsers": [ "defaults, not ie 11" ]
}
}]
Expand Down
9 changes: 0 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,9 @@ node_js:
- '18'
- '16'
- '14'
- '12'
after_success: npm run coverage

env:
global:
- SAUCE_USERNAME='shtylman-superagent'
- SAUCE_ACCESS_KEY='39a45464-cb1d-4b8d-aa1f-83c7c04fa673'

matrix:
include:
- node_js: "10"
env: BROWSER=1
include:
- node_js: "12"
env: HTTP2_TEST=1
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Browser-ready versions of this module are available via [jsdelivr][], [unpkg][],
This is the solution for you if you're just using `<script>` tags everywhere!

```html
<script src="https://polyfill.io/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
<script src="https://cdn.jsdelivr.net/npm/superagent"></script>
<!-- if you wish to use unpkg.com instead: -->
<!-- <script src="https://unpkg.com/superagent"></script> -->
Expand Down Expand Up @@ -112,7 +112,7 @@ If you are using [browserify][], [webpack][], [rollup][], or another bundler, th

## Supported Platforms

* Node: v6.x+
* Node: v14.18.0+
* Browsers (see [.browserslistrc](.browserslistrc)):

```sh
Expand Down Expand Up @@ -155,10 +155,10 @@ If you are using [browserify][], [webpack][], [rollup][], or another bundler, th

### Required Browser Features

We recommend using <https://polyfill.io> (specifically with the bundle mentioned in [VanillaJS](#vanillajs) above):
We recommend using <https://cdnjs.cloudflare.com/polyfill/> (specifically with the bundle mentioned in [VanillaJS](#vanillajs) above):

```html
<script src="https://polyfill.io/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
```

* WeakRef is not supported in Opera 85, iOS Safari 12.2-12.5
Expand Down Expand Up @@ -202,6 +202,7 @@ Existing plugins:
* [superagent-declare](https://github.com/damoclark/superagent-declare) - A simple [declarative](https://en.wikipedia.org/wiki/Declarative_programming) API for SuperAgent
* [superagent-node-http-timings](https://github.com/webuniverseio/superagent-node-http-timings) - measure http timings in node.js
* [superagent-cheerio](https://github.com/mmmmmrob/superagent-cheerio) - add [cheerio](https://www.npmjs.com/package/cheerio) to your response content automatically. Adds `res.$` for HTML and XML response bodies.
* [@certible/superagent-aws-sign](https://github.com/certible/superagent-aws-sign) - Sign AWS endpoint requests, it uses the aws4 to authenticate the SuperAgent requests

Please prefix your plugin with `superagent-*` so that it can easily be found by others.

Expand Down
4 changes: 2 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -868,10 +868,10 @@ Libraries like [co](https://github.com/tj/co) or a web framework like [koa](http

Note that SuperAgent expects the global `Promise` object to be present. You'll need to use v7 and a polyfill to use promises in Internet Explorer or Node.js 0.10.

We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using <https://polyfill.io>:
We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using <https://cdnjs.cloudflare.com/polyfill/>:

```html
<script src="https://polyfill.io/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
<script src="https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=WeakRef,BigInt"></script>
```

## Browser and node versions
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,8 @@ <h2 id="promise-and-generator-support">Promise and Generator support</h2>
const res = yield req;
</code></pre>
<p>Note that SuperAgent expects the global <code>Promise</code> object to be present. You&#39;ll need to use v7 and a polyfill to use promises in Internet Explorer or Node.js 0.10.</p>
<p>We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using <a href="https://polyfill.io">https://polyfill.io</a>:</p>
<pre><code class="language-html">&lt;script src=&quot;https://polyfill.io/v3/polyfill.min.js?features=WeakRef,BigInt&quot;&gt;&lt;/script&gt;
<p>We have dropped support in v8 for IE. You must add a polyfill for WeakRef and BigInt if you wish to support Opera 85, iOS Safari 12.2-12.5, for example using <a href="https://cdnjs.cloudflare.com/polyfill/">https://cdnjs.cloudflare.com/polyfill/</a>:</p>
<pre><code class="language-html">&lt;script src=&quot;https://cdnjs.cloudflare.com/polyfill/v3/polyfill.min.js?features=WeakRef,BigInt&quot;&gt;&lt;/script&gt;
</code></pre>
<h2 id="browser-and-node-versions">Browser and node versions</h2>
<p>SuperAgent has two implementations: one for web browsers (using XHR) and one for Node.JS (using core http module). By default Browserify and WebPack will pick the browser version.</p>
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "superagent",
"description": "elegant & feature rich browser / node HTTP with a fluent API",
"version": "8.1.2",
"version": "9.0.0",
"author": "TJ Holowaychuk <tj@vision-media.ca>",
"browser": {
"./src/node/index.js": "./src/client.js",
Expand All @@ -24,7 +24,7 @@
"debug": "^4.3.4",
"fast-safe-stringify": "^2.1.1",
"form-data": "^4.0.0",
"formidable": "^2.1.2",
"formidable": "^3.5.1",
"methods": "^1.1.2",
"mime": "2.6.0",
"qs": "^6.11.0",
Expand All @@ -38,8 +38,8 @@
"@babel/runtime": "^7.20.13",
"@commitlint/cli": "17",
"@commitlint/config-conventional": "17",
"Base64": "^1.1.0",
"babelify": "^10.0.0",
"Base64": "^1.1.0",
"basic-auth-connect": "^1.0.0",
"body-parser": "^1.20.1",
"browserify": "^17.0.0",
Expand Down Expand Up @@ -69,7 +69,7 @@
"zuul": "^3.12.0"
},
"engines": {
"node": ">=6.4.0 <13 || >=14"
"node": ">=14.18.0"
},
"files": [
"dist/*.js",
Expand Down
30 changes: 27 additions & 3 deletions src/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ Request.prototype._pipeContinue = function (stream, options) {
res.pipe(stream, options);
res.once('end', () => this.emit('end'));
}

});
return stream;
};
Expand Down Expand Up @@ -1093,7 +1092,7 @@ Request.prototype._end = function () {
parser = exports.parse.image; // It's actually a generic Buffer
buffer = true;
} else if (multipart) {
const form = formidable();
const form = formidable.formidable();
parser = form.parse.bind(form);
buffer = true;
} else if (isBinary(mime)) {
Expand Down Expand Up @@ -1125,7 +1124,7 @@ Request.prototype._end = function () {
let parserHandlesEnd = false;
if (buffer) {
// Protectiona against zip bombs and other nuisance
let responseBytesLeft = this._maxResponseSize || 200_000_000;
let responseBytesLeft = this._maxResponseSize || 200000000;
res.on('data', (buf) => {
responseBytesLeft -= buf.byteLength || buf.length > 0 ? buf.length : 0;
if (responseBytesLeft < 0) {
Expand Down Expand Up @@ -1162,6 +1161,31 @@ Request.prototype._end = function () {
}

if (parserHandlesEnd) {
if (multipart) {
// formidable v3 always returns an array with the value in it
// so we need to flatten it
if (object) {
for (const key in object) {
const value = object[key];
if (Array.isArray(value) && value.length === 1) {
object[key] = value[0];
} else {
object[key] = value;
}
}
}

if (files) {
for (const key in files) {
const value = files[key];
if (Array.isArray(value) && value.length === 1) {
files[key] = value[0];
} else {
files[key] = value;
}
}
}
}
this.emit('end');
this.callback(null, this._emitResponse(object, files));
}
Expand Down

0 comments on commit 450f7b2

Please sign in to comment.