Skip to content

Commit c65e264

Browse files
authored
revert: revert #245 (#247)
This reverts commit 281a09c aka #245 so we can re-publish it as a breaking change.
1 parent c1595bc commit c65e264

File tree

162 files changed

+1443
-334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+1443
-334
lines changed

.github/workflows/ci.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
node-version:
16-
- lts/-1
17-
- lts/*
18-
- latest
16+
- 18
17+
- 20
1918

2019
steps:
2120
- uses: actions/checkout@v4

.vscode/settings.json

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
{
2-
"editor.defaultFormatter": "esbenp.prettier-vscode",
32
"editor.codeActionsOnSave": {
43
"source.fixAll": "explicit"
54
},
6-
"editor.formatOnSave": true,
5+
"editor.defaultFormatter": "esbenp.prettier-vscode",
76

87
// controlled by the .editorconfig at root since we can't map vscode settings directly to files
98
// https://github.com/microsoft/vscode/issues/35350
10-
"files.insertFinalNewline": false,
11-
12-
"search.exclude": {
13-
"coverage": true
14-
}
9+
"files.insertFinalNewline": false
1510
}

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ console.log(
109109
}),
110110
);
111111

112-
// generate Node.js: Axios output
113-
console.log(snippet.convert('node', 'axios'));
112+
// generate Node.js: Unirest output
113+
console.log(snippet.convert('node', 'unirest'));
114114
```
115115

116116
### addTarget(target)

integrations/node.Dockerfile

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ WORKDIR /src
1313
ADD package.json /src/
1414

1515
# https://www.npmjs.com/package/axios
16-
RUN npm install axios && \
16+
# https://www.npmjs.com/package/request
17+
# Installing node-fetch@2 because as of 3.0 is't now an ESM-only package.
18+
# https://www.npmjs.com/package/node-fetch
19+
RUN npm install axios request node-fetch@2 && \
1720
npm install
1821

1922
ADD . /src

package.json

+2
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,14 @@
5353
"ocaml",
5454
"php",
5555
"python",
56+
"request",
5657
"requests",
5758
"ruby",
5859
"shell",
5960
"snippet",
6061
"swift",
6162
"swift",
63+
"unirest",
6264
"xhr",
6365
"xmlhttprequest"
6466
],

src/fixtures/customTarget.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import type { Target } from '../targets/index.js';
22

3-
import { axios } from '../targets/node/axios/client.js';
3+
import { request } from '../targets/node/request/client.js';
44

55
export const customTarget = {
66
info: {
7-
key: 'node-variant',
8-
title: 'Node Variant',
7+
key: 'js-variant',
8+
title: 'JavaScript Variant',
99
extname: '.js',
10-
default: 'axios',
10+
default: 'request',
1111
},
1212
clientsById: {
13-
axios,
13+
request,
1414
},
1515
} as unknown as Target;

src/helpers/__snapshots__/utils.test.ts.snap

+23-7
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ exports[`availableTargets > returns all available targets 1`] = `
150150
"title": "jQuery",
151151
},
152152
],
153-
"default": "fetch",
153+
"default": "xhr",
154154
"key": "javascript",
155155
"title": "JavaScript",
156156
},
@@ -192,23 +192,39 @@ exports[`availableTargets > returns all available targets 1`] = `
192192
"link": "http://nodejs.org/api/http.html#http_http_request_options_callback",
193193
"title": "HTTP",
194194
},
195+
{
196+
"description": "Simplified HTTP request client",
197+
"extname": ".cjs",
198+
"installation": "npm install request --save",
199+
"key": "request",
200+
"link": "https://github.com/request/request",
201+
"title": "Request",
202+
},
203+
{
204+
"description": "Lightweight HTTP Request Client Library",
205+
"extname": ".cjs",
206+
"key": "unirest",
207+
"link": "http://unirest.io/nodejs.html",
208+
"title": "Unirest",
209+
},
195210
{
196211
"description": "Promise based HTTP client for the browser and node.js",
197-
"extname": ".js",
212+
"extname": ".cjs",
198213
"installation": "npm install axios --save",
199214
"key": "axios",
200215
"link": "https://github.com/axios/axios",
201216
"title": "Axios",
202217
},
203218
{
204-
"description": "Perform asynchronous HTTP requests with the Fetch API",
205-
"extname": ".js",
219+
"description": "Simplified HTTP node-fetch client",
220+
"extname": ".cjs",
221+
"installation": "npm install node-fetch@2 --save",
206222
"key": "fetch",
207-
"link": "https://nodejs.org/docs/latest/api/globals.html#fetch",
208-
"title": "fetch",
223+
"link": "https://github.com/bitinn/node-fetch",
224+
"title": "Fetch",
209225
},
210226
],
211-
"default": "fetch",
227+
"default": "native",
212228
"key": "node",
213229
"title": "Node.js",
214230
},

src/helpers/utils.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('extname', () => {
2222
expect(extname('c', 'libcurl')).toBe('.c');
2323
expect(extname('clojure', 'clj_http')).toBe('.clj');
2424
expect(extname('javascript', 'axios')).toBe('.js');
25-
expect(extname('node', 'axios')).toBe('.js');
25+
expect(extname('node', 'axios')).toBe('.cjs');
2626
});
2727

2828
it('returns empty string if the extension is not found', () => {

src/integration.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const ENVIRONMENT_CONFIG = {
2121
c: ['libcurl'],
2222
csharp: ['httpclient', 'restsharp'],
2323
go: ['native'],
24-
node: ['axios', 'fetch'],
24+
node: ['axios', 'fetch', 'native', 'request'],
2525
php: ['curl', 'guzzle'],
2626
python: ['requests'],
2727
shell: ['curl'],
@@ -30,7 +30,7 @@ const ENVIRONMENT_CONFIG = {
3030
// When running tests locally, or within a CI environment, we shold limit the targets that
3131
// we're testing so as to not require a mess of dependency requirements that would be better
3232
// served within a container.
33-
node: ['fetch'],
33+
node: ['native'],
3434
php: ['curl'],
3535
python: ['requests'],
3636
shell: ['curl'],

src/targets/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const targetFilter: TargetId[] = [
3131
/** useful for debuggin, only run a particular set of targets */
3232
const clientFilter: ClientId[] = [
3333
// put your clientId here:
34-
// 'axios',
34+
// 'unirest',
3535
];
3636

3737
/** useful for debuggin, only run a particular set of fixtures */

src/targets/javascript/axios/client.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ export const axios: Client = {
9999

100100
push('axios');
101101
push('.request(options)', 1);
102-
push('.then(res => console.log(res.data))', 1);
103-
push('.catch(err => console.error(err));', 1);
102+
push('.then(function (response) {', 1);
103+
push('console.log(response.data);', 2);
104+
push('})', 1);
105+
push('.catch(function (error) {', 1);
106+
push('console.error(error);', 2);
107+
push('});', 1);
104108

105109
return join();
106110
},

src/targets/javascript/axios/fixtures/application-form-encoded.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ const options = {
1313

1414
axios
1515
.request(options)
16-
.then(res => console.log(res.data))
17-
.catch(err => console.error(err));
16+
.then(function (response) {
17+
console.log(response.data);
18+
})
19+
.catch(function (error) {
20+
console.error(error);
21+
});

src/targets/javascript/axios/fixtures/application-json.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,9 @@ const options = {
1616

1717
axios
1818
.request(options)
19-
.then(res => console.log(res.data))
20-
.catch(err => console.error(err));
19+
.then(function (response) {
20+
console.log(response.data);
21+
})
22+
.catch(function (error) {
23+
console.error(error);
24+
});

src/targets/javascript/axios/fixtures/cookies.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ const options = {
88

99
axios
1010
.request(options)
11-
.then(res => console.log(res.data))
12-
.catch(err => console.error(err));
11+
.then(function (response) {
12+
console.log(response.data);
13+
})
14+
.catch(function (error) {
15+
console.error(error);
16+
});

src/targets/javascript/axios/fixtures/custom-method.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ const options = {method: 'PROPFIND', url: 'https://httpbin.org/anything'};
44

55
axios
66
.request(options)
7-
.then(res => console.log(res.data))
8-
.catch(err => console.error(err));
7+
.then(function (response) {
8+
console.log(response.data);
9+
})
10+
.catch(function (error) {
11+
console.error(error);
12+
});

src/targets/javascript/axios/fixtures/full.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ const options = {
1717

1818
axios
1919
.request(options)
20-
.then(res => console.log(res.data))
21-
.catch(err => console.error(err));
20+
.then(function (response) {
21+
console.log(response.data);
22+
})
23+
.catch(function (error) {
24+
console.error(error);
25+
});

src/targets/javascript/axios/fixtures/headers.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ const options = {
1313

1414
axios
1515
.request(options)
16-
.then(res => console.log(res.data))
17-
.catch(err => console.error(err));
16+
.then(function (response) {
17+
console.log(response.data);
18+
})
19+
.catch(function (error) {
20+
console.error(error);
21+
});

src/targets/javascript/axios/fixtures/http-insecure.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,9 @@ const options = {method: 'GET', url: 'http://httpbin.org/anything'};
44

55
axios
66
.request(options)
7-
.then(res => console.log(res.data))
8-
.catch(err => console.error(err));
7+
.then(function (response) {
8+
console.log(response.data);
9+
})
10+
.catch(function (error) {
11+
console.error(error);
12+
});

src/targets/javascript/axios/fixtures/jsonObj-multiline.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ const options = {
99

1010
axios
1111
.request(options)
12-
.then(res => console.log(res.data))
13-
.catch(err => console.error(err));
12+
.then(function (response) {
13+
console.log(response.data);
14+
})
15+
.catch(function (error) {
16+
console.error(error);
17+
});

src/targets/javascript/axios/fixtures/jsonObj-null-value.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,9 @@ const options = {
99

1010
axios
1111
.request(options)
12-
.then(res => console.log(res.data))
13-
.catch(err => console.error(err));
12+
.then(function (response) {
13+
console.log(response.data);
14+
})
15+
.catch(function (error) {
16+
console.error(error);
17+
});

src/targets/javascript/axios/fixtures/multipart-data.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,9 @@ const options = {
1313

1414
axios
1515
.request(options)
16-
.then(res => console.log(res.data))
17-
.catch(err => console.error(err));
16+
.then(function (response) {
17+
console.log(response.data);
18+
})
19+
.catch(function (error) {
20+
console.error(error);
21+
});

src/targets/javascript/axios/fixtures/multipart-file.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ const options = {
1212

1313
axios
1414
.request(options)
15-
.then(res => console.log(res.data))
16-
.catch(err => console.error(err));
15+
.then(function (response) {
16+
console.log(response.data);
17+
})
18+
.catch(function (error) {
19+
console.error(error);
20+
});

src/targets/javascript/axios/fixtures/multipart-form-data-no-params.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ const options = {
88

99
axios
1010
.request(options)
11-
.then(res => console.log(res.data))
12-
.catch(err => console.error(err));
11+
.then(function (response) {
12+
console.log(response.data);
13+
})
14+
.catch(function (error) {
15+
console.error(error);
16+
});

src/targets/javascript/axios/fixtures/multipart-form-data.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ const options = {
1212

1313
axios
1414
.request(options)
15-
.then(res => console.log(res.data))
16-
.catch(err => console.error(err));
15+
.then(function (response) {
16+
console.log(response.data);
17+
})
18+
.catch(function (error) {
19+
console.error(error);
20+
});

src/targets/javascript/axios/fixtures/nested.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@ const options = {
88

99
axios
1010
.request(options)
11-
.then(res => console.log(res.data))
12-
.catch(err => console.error(err));
11+
.then(function (response) {
12+
console.log(response.data);
13+
})
14+
.catch(function (error) {
15+
console.error(error);
16+
});

0 commit comments

Comments
 (0)