Skip to content

Commit

Permalink
revert: revert #245 (#247)
Browse files Browse the repository at this point in the history
This reverts commit 281a09c aka #245 so
we can re-publish it as a breaking change.
  • Loading branch information
kanadgupta authored Sep 23, 2024
1 parent c1595bc commit c65e264
Show file tree
Hide file tree
Showing 162 changed files with 1,443 additions and 334 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ jobs:
strategy:
matrix:
node-version:
- lts/-1
- lts/*
- latest
- 18
- 20

steps:
- uses: actions/checkout@v4
Expand Down
9 changes: 2 additions & 7 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit"
},
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",

// controlled by the .editorconfig at root since we can't map vscode settings directly to files
// https://github.com/microsoft/vscode/issues/35350
"files.insertFinalNewline": false,

"search.exclude": {
"coverage": true
}
"files.insertFinalNewline": false
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ console.log(
}),
);

// generate Node.js: Axios output
console.log(snippet.convert('node', 'axios'));
// generate Node.js: Unirest output
console.log(snippet.convert('node', 'unirest'));
```

### addTarget(target)
Expand Down
5 changes: 4 additions & 1 deletion integrations/node.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ WORKDIR /src
ADD package.json /src/

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

ADD . /src
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@
"ocaml",
"php",
"python",
"request",
"requests",
"ruby",
"shell",
"snippet",
"swift",
"swift",
"unirest",
"xhr",
"xmlhttprequest"
],
Expand Down
10 changes: 5 additions & 5 deletions src/fixtures/customTarget.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { Target } from '../targets/index.js';

import { axios } from '../targets/node/axios/client.js';
import { request } from '../targets/node/request/client.js';

export const customTarget = {
info: {
key: 'node-variant',
title: 'Node Variant',
key: 'js-variant',
title: 'JavaScript Variant',
extname: '.js',
default: 'axios',
default: 'request',
},
clientsById: {
axios,
request,
},
} as unknown as Target;
30 changes: 23 additions & 7 deletions src/helpers/__snapshots__/utils.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ exports[`availableTargets > returns all available targets 1`] = `
"title": "jQuery",
},
],
"default": "fetch",
"default": "xhr",
"key": "javascript",
"title": "JavaScript",
},
Expand Down Expand Up @@ -192,23 +192,39 @@ exports[`availableTargets > returns all available targets 1`] = `
"link": "http://nodejs.org/api/http.html#http_http_request_options_callback",
"title": "HTTP",
},
{
"description": "Simplified HTTP request client",
"extname": ".cjs",
"installation": "npm install request --save",
"key": "request",
"link": "https://github.com/request/request",
"title": "Request",
},
{
"description": "Lightweight HTTP Request Client Library",
"extname": ".cjs",
"key": "unirest",
"link": "http://unirest.io/nodejs.html",
"title": "Unirest",
},
{
"description": "Promise based HTTP client for the browser and node.js",
"extname": ".js",
"extname": ".cjs",
"installation": "npm install axios --save",
"key": "axios",
"link": "https://github.com/axios/axios",
"title": "Axios",
},
{
"description": "Perform asynchronous HTTP requests with the Fetch API",
"extname": ".js",
"description": "Simplified HTTP node-fetch client",
"extname": ".cjs",
"installation": "npm install node-fetch@2 --save",
"key": "fetch",
"link": "https://nodejs.org/docs/latest/api/globals.html#fetch",
"title": "fetch",
"link": "https://github.com/bitinn/node-fetch",
"title": "Fetch",
},
],
"default": "fetch",
"default": "native",
"key": "node",
"title": "Node.js",
},
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('extname', () => {
expect(extname('c', 'libcurl')).toBe('.c');
expect(extname('clojure', 'clj_http')).toBe('.clj');
expect(extname('javascript', 'axios')).toBe('.js');
expect(extname('node', 'axios')).toBe('.js');
expect(extname('node', 'axios')).toBe('.cjs');
});

it('returns empty string if the extension is not found', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const ENVIRONMENT_CONFIG = {
c: ['libcurl'],
csharp: ['httpclient', 'restsharp'],
go: ['native'],
node: ['axios', 'fetch'],
node: ['axios', 'fetch', 'native', 'request'],
php: ['curl', 'guzzle'],
python: ['requests'],
shell: ['curl'],
Expand All @@ -30,7 +30,7 @@ const ENVIRONMENT_CONFIG = {
// When running tests locally, or within a CI environment, we shold limit the targets that
// we're testing so as to not require a mess of dependency requirements that would be better
// served within a container.
node: ['fetch'],
node: ['native'],
php: ['curl'],
python: ['requests'],
shell: ['curl'],
Expand Down
2 changes: 1 addition & 1 deletion src/targets/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const targetFilter: TargetId[] = [
/** useful for debuggin, only run a particular set of targets */
const clientFilter: ClientId[] = [
// put your clientId here:
// 'axios',
// 'unirest',
];

/** useful for debuggin, only run a particular set of fixtures */
Expand Down
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ export const axios: Client = {

push('axios');
push('.request(options)', 1);
push('.then(res => console.log(res.data))', 1);
push('.catch(err => console.error(err));', 1);
push('.then(function (response) {', 1);
push('console.log(response.data);', 2);
push('})', 1);
push('.catch(function (error) {', 1);
push('console.error(error);', 2);
push('});', 1);

return join();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/application-json.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/cookies.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/custom-method.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ const options = {method: 'PROPFIND', url: 'https://httpbin.org/anything'};

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/headers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/http-insecure.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ const options = {method: 'GET', url: 'http://httpbin.org/anything'};

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/jsonObj-multiline.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/jsonObj-null-value.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/multipart-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/multipart-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/multipart-form-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
8 changes: 6 additions & 2 deletions src/targets/javascript/axios/fixtures/nested.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ const options = {

axios
.request(options)
.then(res => console.log(res.data))
.catch(err => console.error(err));
.then(function (response) {
console.log(response.data);
})
.catch(function (error) {
console.error(error);
});
Loading

0 comments on commit c65e264

Please sign in to comment.