chore: add `format` script (#1334)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
* add format * yarn format:fix * fix linter
authored by watany · committed by GitHub · parent 4a990cf · Browse files · 11 files·+93 added−75 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
11 files+93 added−75 removed
- tests:+6 added−5 removed
- other:+87 added−70 removed
Provenance
- Commit
954c06e- Tree
fb48b4a- Author
watany <76135106+watany-dev@users.noreply.github.com>- Committer
GitHub <noreply@github.com>- Parent
4a990cf
11 files changed+93 added−75 removed
modified:.github/workflows/ci.yml+1 added
13 unmodified lines14151617181920212292 unmodified lines13 unmodified lines - uses: actions/setup-node@v3 with: node-version: 18.x - run: yarn install --frozen-lockfile - run: npm run format - run: npm run lint - run: npm run build - run: npm test
92 unmodified linesmodified:runtime_tests/lambda-edge/index.test.ts+1 added-1 removed
1088 unmodified lines1089 ],1090 }1091 1092 let called = false1093- await handler(event, {}, (_err, result) => {1093+ await handler(event, {}, (_, result) => {1094 called = true1095 })1096 1097 expect(called).toBe(true)2 unmodified linesmodified:src/adapter/aws-lambda/custom-context.ts+64 added-64 removed
1234567456789101191011121314151617181920212223242526271516171819202122232425262728293031323132333435363738394041424344454647484934353637383940414243444546474849505152535455565758596061545556575859606162636465666768697065666768697071727374757677787980818283727374757677787980818283// @denoify-ignore
interface ClientCert { clientCertPem: string; subjectDN: string; issuerDN: string; serialNumber: string; clientCertPem: string subjectDN: string issuerDN: string serialNumber: string validity: { notBefore: string; notAfter: string; }; notBefore: string notAfter: string }}
interface Identity { accessKey?: string; accountId?: string; caller?: string; cognitoAuthenticationProvider?: string; cognitoAuthenticationType?: string; cognitoIdentityId?: string; cognitoIdentityPoolId?: string; principalOrgId?: string; sourceIp: string; user?: string; userAgent: string; userArn?: string; clientCert?: ClientCert; accessKey?: string accountId?: string caller?: string cognitoAuthenticationProvider?: string cognitoAuthenticationType?: string cognitoIdentityId?: string cognitoIdentityPoolId?: string principalOrgId?: string sourceIp: string user?: string userAgent: string userArn?: string clientCert?: ClientCert}
export interface ApiGatewayRequestContext { accountId: string; apiId: string; accountId: string apiId: string authorizer: { claims?: unknown; scopes?: unknown; }; domainName: string; domainPrefix: string; extendedRequestId: string; httpMethod: string; identity: Identity; path: string; protocol: string; requestId: string; requestTime: string; requestTimeEpoch: number; resourceId?: string; resourcePath: string; stage: string; claims?: unknown scopes?: unknown } domainName: string domainPrefix: string extendedRequestId: string httpMethod: string identity: Identity path: string protocol: string requestId: string requestTime: string requestTimeEpoch: number resourceId?: string resourcePath: string stage: string}
interface Authorizer { iam?: { accessKey: string; accountId: string; callerId: string; cognitoIdentity: null; principalOrgId: null; userArn: string; userId: string; }; accessKey: string accountId: string callerId: string cognitoIdentity: null principalOrgId: null userArn: string userId: string }}
export interface LambdaFunctionUrlRequestContext { accountId: string; apiId: string; authentication: null; authorizer: Authorizer; domainName: string; domainPrefix: string; accountId: string apiId: string authentication: null authorizer: Authorizer domainName: string domainPrefix: string http: { method: string; path: string; protocol: string; sourceIp: string; userAgent: string; }; requestId: string; routeKey: string; stage: string; time: string; timeEpoch: number;}No newline at end of file method: string path: string protocol: string sourceIp: string userAgent: string } requestId: string routeKey: string stage: string time: string timeEpoch: number}modified:src/adapter/aws-lambda/index.ts-1 removed
1 // @denoify-ignore2 export { handle } from './handler'3 export type { ApiGatewayRequestContext, LambdaFunctionUrlRequestContext } from './custom-context'4-modified:src/adapter/lambda-edge/handler.ts+2 added-1 removed
143 unmodified lines144 v.forEach((header) => headers.set(k, header.value))145 })146 147 const requestBody = event.Records[0].cf.request.body148+ const body =148- const body = requestBody?.encoding === 'base64' && requestBody?.data149+ requestBody?.encoding === 'base64' && requestBody?.data150 ? Buffer.from(requestBody.data, 'base64')151 : requestBody?.data152 153 return new Request(url, {11 unmodified linesmodified:src/adapter/lambda-edge/index.ts+7 added-1 removed
1 // @denoify-ignore2 export { handle } from './handler'3-export type { Callback, CloudFrontConfig, CloudFrontRequest, CloudFrontResponse, CloudFrontEdgeEvent } from './handler'3+export type {4+ Callback,5+ CloudFrontConfig,6+ CloudFrontRequest,7+ CloudFrontResponse,8+ CloudFrontEdgeEvent,9+} from './handler'modified:src/client/client.ts+4 added-1 removed
105 unmodified lines106 }107 }108 109 // eslint-disable-next-line @typescript-eslint/no-explicit-any110-export const hc = <T extends Hono<any, any, any>>(baseUrl: string, options?: ClientRequestOptions) =>110+export const hc = <T extends Hono<any, any, any>>(111+ baseUrl: string,112+ options?: ClientRequestOptions113+) =>114 createProxy(async (opts) => {115 const parts = [...opts.path]116 117 let method = ''17 unmodified linesmodified:src/middleware/compress/index.test.ts+2 added-3 removed
1 import { Hono } from '../../hono'2 import { compress } from '.'3 4 describe('Parse Compress Middleware', () => {5-5 const app = new Hono()6 7 app.use('*', compress())8 app.get('/hello', async (ctx) => {9 unmodified lines18 expect(res).not.toBeNull()19 expect(res.status).toBe(200)20 expect(res.headers.get('Content-Encoding')).toEqual('gzip')21 })23- 22+23 it('deflate', async () => {24 const req = new Request('http://localhost/hello', {25 method: 'GET',26 headers: new Headers({ 'Accept-Encoding': 'deflate' }),2 unmodified lines29 expect(res).not.toBeNull()30 expect(res.status).toBe(200)31 expect(res.headers.get('Content-Encoding')).toEqual('deflate')32 })34- 33+34 it('gzip or deflate', async () => {35 const req = new Request('http://localhost/hello', {36 method: 'GET',37 headers: new Headers({ 'Accept-Encoding': 'gzip, deflate' }),17 unmodified linesmodified:src/middleware/etag/index.test.ts+3 added-1 removed
134 unmodified lines135 expect(res.headers.get('ETag')).toBe('"4e32298b1cb4edc595237405e5b696e105c2399a"')136 })137 138 it('Should not override ETag headers from upstream', async () => {139- app.get('/etag/predefined', (c) => c.text('This response has an ETag', 200, { ETag: '"f-0194-d"'}))139+ app.get('/etag/predefined', (c) =>140+ c.text('This response has an ETag', 200, { ETag: '"f-0194-d"' })141+ )142 143 const res = await app.request('http://localhost/etag/predefined')144 expect(res.headers.get('ETag')).toBe('"f-0194-d"')145 })1 unmodified linemodified:src/middleware/etag/index.ts+7 added-2 removed
1 import type { MiddlewareHandler } from '../../types'2 import { sha1 } from '../../utils/crypto'3 4 type ETagOptions = {5- retainedHeaders?: string[],5+ retainedHeaders?: string[]6 weak?: boolean7 }8 9 /**2 unmodified lines12 * > would have been sent in an equivalent 200 OK response: Cache-Control,13 * > Content-Location, Date, ETag, Expires, and Vary.14 */15 const RETAINED_304_HEADERS = [16- 'cache-control', 'content-location', 'date', 'etag', 'expires', 'vary'16+ 'cache-control',17+ 'content-location',18+ 'date',19+ 'etag',20+ 'expires',21+ 'vary',22 ]23 24 function etagMatches(etag: string, ifNoneMatch: string | null) {25 return ifNoneMatch != null && ifNoneMatch.split(/,\s*/).indexOf(etag) > -138 unmodified linesmodified:package.json+2 added
20 unmodified lines21 "test:lambda-edge": "env NAME=Node jest --config ./runtime_tests/lambda-edge/jest.config.js",22 "test:all": "yarn test && yarn test:deno && yarn test:bun && yarn test:fastly && yarn test:lagon && yarn test:node && yarn test:wrangler && yarn test:lambda && yarn test:lambda-edge",23 "lint": "eslint --ext js,ts src runtime_tests .eslintrc.cjs",24 "lint:fix": "eslint --ext js,ts src runtime_tests .eslintrc.cjs --fix",25+ "format": "prettier --check 'src/**/*.{js,ts}' 'runtime_tests/**/*.{js,ts}'",26+ "format:fix": "prettier --write 'src/**/*.{js,ts}' 'runtime_tests/**/*.{js,ts}'",27 "denoify": "rimraf deno_dist && denoify && rimraf 'deno_dist/**/*.test.ts'",28 "copy:package.cjs.json": "cp ./package.cjs.json ./dist/cjs/package.json && cp ./package.cjs.json ./dist/types/package.json ",29 "build": "rimraf dist && tsx ./build.ts && yarn copy:package.cjs.json",30 "postbuild": "publint",384 unmodified lines