Skip to content

Commit 6a758d6

Browse files
Prep for Release: source maps, types, prettier (#301)
* updates library exports * fixes lint configuration so that it actually fails now, as intended * tidy up --------- Co-authored-by: Filipe Freire <[email protected]>
1 parent fbd23b5 commit 6a758d6

File tree

7 files changed

+66
-27
lines changed

7 files changed

+66
-27
lines changed

package.json

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"author": "Kong <[email protected]>",
66
"homepage": "https://github.com/Kong/httpsnippet",
77
"license": "MIT",
8-
"main": "dist/httpsnippet.js",
9-
"types": "dist/httpsnippet.d.ts",
8+
"main": "dist/index.js",
9+
"types": "dist/index.d.ts",
1010
"bin": "bin/httpsnippet",
1111
"keywords": [
1212
"api",
@@ -51,9 +51,13 @@
5151
"clean": "tsc --build tsconfig.build.json --clean",
5252
"prebuild": "npm run clean",
5353
"lint": "npm run lint:prettify && npm run lint:code && npm run lint:markdown",
54-
"lint:prettify": "prettier --write .",
55-
"lint:code": "eslint . --ext ts,d.ts,test.ts --fix",
54+
"lint:prettify": "prettier --check .",
55+
"lint:code": "eslint . --ext ts,d.ts,test.ts",
5656
"lint:markdown": "markdownlint-cli2 \"**/*.md\" \"#**/node_modules\"",
57+
"lint:fix": "npm run lint:prettify:fix && npm run lint:code:fix && npm run lint:markdown:fix",
58+
"lint:prettify:fix": "prettier --write .",
59+
"lint:code:fix": "eslint . --ext ts,d.ts,test.ts --fix",
60+
"lint:markdown:fix": "markdownlint-cli2-fix \"**/*.md\" \"#**/node_modules\"",
5761
"build": "tsc --build tsconfig.build.json",
5862
"build:types": "tsc -d --declarationDir dist/lib --declarationMap --emitDeclarationOnly",
5963
"test": "jest"

src/httpsnippet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ interface Entry {
5353
request: Partial<HarRequest>;
5454
}
5555

56-
interface HarEntry {
56+
export interface HarEntry {
5757
log: {
5858
version: string;
5959
creator: {
@@ -64,7 +64,7 @@ interface HarEntry {
6464
};
6565
}
6666

67-
const isHarEntry = (value: any): value is HarEntry =>
67+
export const isHarEntry = (value: any): value is HarEntry =>
6868
typeof value === 'object' &&
6969
'log' in value &&
7070
typeof value.log === 'object' &&

src/index.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export { CodeBuilder, CodeBuilderOptions, PostProcessor } from './helpers/code-builder';
2+
export { EscapeOptions, escapeString } from './helpers/escape';
3+
export { HARError, validateHarRequest } from './helpers/har-validator';
4+
export { getHeader, getHeaderName } from './helpers/headers';
5+
export { AvailableTarget, availableTargets, extname } from './helpers/utils';
6+
export {
7+
HarEntry,
8+
HarRequest,
9+
HTTPSnippet,
10+
isHarEntry,
11+
Request,
12+
RequestExtras,
13+
} from './httpsnippet';
14+
export {
15+
addTarget,
16+
addTargetClient,
17+
Client,
18+
ClientId,
19+
ClientInfo,
20+
Converter,
21+
Extension,
22+
isClient,
23+
isTarget,
24+
Target,
25+
TargetId,
26+
TargetInfo,
27+
targets,
28+
} from './targets/targets';

src/targets/powershell/common.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
2626
'PATCH',
2727
'POST',
2828
'PUT',
29-
'TRACE'
29+
'TRACE',
3030
];
3131
const methodArg = methods.includes(method.toUpperCase()) ? '-Method' : '-CustomMethod';
3232

@@ -73,7 +73,9 @@ export const generatePowershellConvert = (command: PowershellCommand) => {
7373
commandOptions.push(`-Body '${postData.text}'`);
7474
}
7575

76-
push(`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`);
76+
push(
77+
`$response = ${command} -Uri '${fullUrl}' ${methodArg} ${method} ${commandOptions.join(' ')}`,
78+
);
7779
return join();
7880
};
7981
return convert;

src/targets/ruby/faraday/client.ts

+14-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const faraday: Client = {
99
link: 'https://github.com/lostisland/faraday',
1010
description: 'Faraday HTTP client',
1111
},
12-
convert: ({ uriObj, queryObj, method: rawMethod, fullUrl, postData, allHeaders }, options = {}) => {
12+
convert: ({ uriObj, queryObj, method: rawMethod, postData, allHeaders }) => {
1313
const { push, blank, join } = new CodeBuilder();
1414

1515
// To support custom methods we check for the supported methods
@@ -30,16 +30,16 @@ export const faraday: Client = {
3030
'TRACE',
3131
];
3232

33-
if(!methods.includes(method)) {
34-
push(`# Faraday cannot currently run ${method} requests. Please use another client.`)
33+
if (!methods.includes(method)) {
34+
push(`# Faraday cannot currently run ${method} requests. Please use another client.`);
3535
return join();
3636
}
3737

3838
push("require 'faraday'");
3939
blank();
4040

4141
// Write body to beginning of script
42-
if(postData.mimeType === 'application/x-www-form-urlencoded') {
42+
if (postData.mimeType === 'application/x-www-form-urlencoded') {
4343
if (postData.params) {
4444
push(`data = {`);
4545
postData.params.forEach(param => {
@@ -52,8 +52,12 @@ export const faraday: Client = {
5252

5353
push(`conn = Faraday.new(`);
5454
push(` url: '${uriObj.protocol}//${uriObj.host}',`);
55-
if(allHeaders['content-type'] || allHeaders['Content-Type']) {
56-
push(` headers: {'Content-Type' => '${allHeaders['content-type'] || allHeaders['Content-Type']}'}`);
55+
if (allHeaders['content-type'] || allHeaders['Content-Type']) {
56+
push(
57+
` headers: {'Content-Type' => '${
58+
allHeaders['content-type'] || allHeaders['Content-Type']
59+
}'}`,
60+
);
5761
}
5862
push(`)`);
5963

@@ -63,7 +67,7 @@ export const faraday: Client = {
6367
const headers = Object.keys(allHeaders);
6468
if (headers.length) {
6569
headers.forEach(key => {
66-
if(key.toLowerCase() !== 'content-type') {
70+
if (key.toLowerCase() !== 'content-type') {
6771
push(` req.headers['${key}'] = '${escapeForSingleQuotes(allHeaders[key])}'`);
6872
}
6973
});
@@ -72,9 +76,9 @@ export const faraday: Client = {
7276
Object.keys(queryObj).forEach(name => {
7377
const value = queryObj[name];
7478
if (Array.isArray(value)) {
75-
push(` req.params['${name}'] = ${JSON.stringify(value)}`)
79+
push(` req.params['${name}'] = ${JSON.stringify(value)}`);
7680
} else {
77-
push(` req.params['${name}'] = '${value}'`)
81+
push(` req.params['${name}'] = '${value}'`);
7882
}
7983
});
8084

@@ -98,7 +102,7 @@ export const faraday: Client = {
98102
}
99103

100104
push('end');
101-
blank()
105+
blank();
102106
push('puts response.status');
103107
push('puts response.body');
104108

src/targets/ruby/target.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Target } from '../targets';
2-
import { native } from './native/client';
32
import { faraday } from './faraday/client';
3+
import { native } from './native/client';
44

55
export const ruby: Target = {
66
info: {
@@ -11,6 +11,6 @@ export const ruby: Target = {
1111
},
1212
clientsById: {
1313
native,
14-
faraday
14+
faraday,
1515
},
1616
};

tsconfig.build.json

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
{
22
"compilerOptions": {
3-
"outDir": "dist",
4-
"rootDir": "src",
53
"allowJs": true,
6-
"resolveJsonModule": true,
7-
"strict": true,
8-
"esModuleInterop": true,
4+
"declaration": true,
5+
"declarationMap": true,
96
"downlevelIteration": true,
107
"lib": ["ESNext"],
11-
"declaration": true,
12-
"declarationMap": true
8+
"esModuleInterop": true,
9+
"outDir": "dist",
10+
"resolveJsonModule": true,
11+
"rootDir": "src",
12+
"sourceMap": true,
13+
"strict": true
1314
},
1415
"include": ["src"],
1516
"exclude": ["dist", "**/*.test.ts"]

0 commit comments

Comments
 (0)