Skip to content

Commit 281a09c

Browse files
authored
feat: modernizing our JS and Node snippet targets (#245)
## 🧰 Changes #### JS * [x] 🏄 `fetch` * Is now the default target. 🆕 * Renamed `response` to `res`. * [x] 🏄 `jquery` * Renamed `response` to `res`. * Moved response handling to arrow functions. #### Node * [x] 🏄 `axios` * Moved the `axios` import from `require` to `import`. * No longer importing `URLSearchParams` from `node:url` as its global now. * Renamed `response` to `res` and `error` to `err`. * Moved response handling to arrow functions. * [x] 🏄 `fetch` * Has moved from `node-fetch` to native `fetch`. * Is now the default target. 🆕 * Dropped an `error: `output header from logged errors because it's already using `console.error()`.. * [x] 🔪 `request` * It's been deprecated for a couple years now. * [x] 🔪 `unirest` * Hasn't been updated in six years, was a bespoke HTTP client from the Mashape/Kong folks and never reached an adoption level worth us supporting on all customer sites.
1 parent cb55858 commit 281a09c

File tree

162 files changed

+334
-1443
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

+334
-1443
lines changed

.github/workflows/ci.yml

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

1920
steps:
2021
- uses: actions/checkout@v4

.vscode/settings.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
{
2+
"editor.defaultFormatter": "esbenp.prettier-vscode",
23
"editor.codeActionsOnSave": {
34
"source.fixAll": "explicit"
45
},
5-
"editor.defaultFormatter": "esbenp.prettier-vscode",
6+
"editor.formatOnSave": true,
67

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

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ console.log(
109109
}),
110110
);
111111

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

116116
### addTarget(target)

integrations/node.Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ WORKDIR /src
1313
ADD package.json /src/
1414

1515
# https://www.npmjs.com/package/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 && \
16+
RUN npm install axios && \
2017
npm install
2118

2219
ADD . /src

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,12 @@
5353
"ocaml",
5454
"php",
5555
"python",
56-
"request",
5756
"requests",
5857
"ruby",
5958
"shell",
6059
"snippet",
6160
"swift",
6261
"swift",
63-
"unirest",
6462
"xhr",
6563
"xmlhttprequest"
6664
],

src/fixtures/customTarget.ts

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

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

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

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

Lines changed: 7 additions & 23 deletions
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": "xhr",
153+
"default": "fetch",
154154
"key": "javascript",
155155
"title": "JavaScript",
156156
},
@@ -192,39 +192,23 @@ 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-
},
210195
{
211196
"description": "Promise based HTTP client for the browser and node.js",
212-
"extname": ".cjs",
197+
"extname": ".js",
213198
"installation": "npm install axios --save",
214199
"key": "axios",
215200
"link": "https://github.com/axios/axios",
216201
"title": "Axios",
217202
},
218203
{
219-
"description": "Simplified HTTP node-fetch client",
220-
"extname": ".cjs",
221-
"installation": "npm install node-fetch@2 --save",
204+
"description": "Perform asynchronous HTTP requests with the Fetch API",
205+
"extname": ".js",
222206
"key": "fetch",
223-
"link": "https://github.com/bitinn/node-fetch",
224-
"title": "Fetch",
207+
"link": "https://nodejs.org/docs/latest/api/globals.html#fetch",
208+
"title": "fetch",
225209
},
226210
],
227-
"default": "native",
211+
"default": "fetch",
228212
"key": "node",
229213
"title": "Node.js",
230214
},

src/helpers/utils.test.ts

Lines changed: 1 addition & 1 deletion
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('.cjs');
25+
expect(extname('node', 'axios')).toBe('.js');
2626
});
2727

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

src/integration.test.ts

Lines changed: 2 additions & 2 deletions
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', 'native', 'request'],
24+
node: ['axios', 'fetch'],
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: ['native'],
33+
node: ['fetch'],
3434
php: ['curl'],
3535
python: ['requests'],
3636
shell: ['curl'],

src/targets/index.test.ts

Lines changed: 1 addition & 1 deletion
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-
// 'unirest',
34+
// 'axios',
3535
];
3636

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

0 commit comments

Comments
 (0)