Skip to content

Commit 5f1f0d6

Browse files
author
JH
committed
refactor(lib): naming and formatting
1 parent 99c8f83 commit 5f1f0d6

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

lib/jest.config.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import type { Config } from "jest";
33
const commonConfig: Config = {
44
roots: ["<rootDir>/src"],
55
transform: {
6-
"^.+\\.tsx?$": "ts-jest"
6+
"^.+\\.tsx?$": "ts-jest",
77
},
8-
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"]
8+
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"],
99
};
1010

1111
const config: Config = {
@@ -14,15 +14,15 @@ const config: Config = {
1414
...commonConfig,
1515
displayName: "server",
1616
testRegex: "/__tests__/server/.*\\.[jt]sx?$",
17-
testEnvironment: "node"
17+
testEnvironment: "node",
1818
},
1919
{
2020
...commonConfig,
2121
displayName: "client",
2222
testRegex: "/__tests__/client/.*\\.[jt]sx?$",
23-
testEnvironment: "jsdom"
24-
}
25-
]
23+
testEnvironment: "jsdom",
24+
},
25+
],
2626
};
2727

2828
export default config;

lib/src/__tests__/server/server.test.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ test("serveFragment with pipeStream option", async () => {
7474
},
7575
flush: (callback) => {
7676
callback(null, "<div>hi there</div>");
77-
}
77+
},
7878
});
7979
input.pipe(transformer);
8080
return transformer;
81-
}
81+
},
8282
})
8383
);
8484

lib/src/server.tsx

+10-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import type { Request, Response } from "express";
2-
import { createHmac, randomBytes } from "node:crypto";
3-
import type { Transform } from "node:stream";
4-
import { Readable } from "node:stream";
2+
import crypto from "crypto";
3+
import type { Transform } from "stream";
4+
import { Readable } from "stream";
55
import type { ComponentType } from "react";
66
import React from "react";
77
import type { PipeableStream } from "react-dom/server";
88
import { renderToPipeableStream } from "react-dom/server";
99

1010
export const path = process.env.REACT_ESI_PATH || "/_fragment";
11-
const secret = process.env.REACT_ESI_SECRET || randomBytes(64).toString("hex");
11+
const secret =
12+
process.env.REACT_ESI_SECRET || crypto.randomBytes(64).toString("hex");
1213

1314
/**
1415
* Signs the ESI URL with a secret key using the HMAC-SHA256 algorithm.
1516
*/
1617
function sign(url: URL) {
17-
const hmac = createHmac("sha256", secret);
18+
const hmac = crypto.createHmac("sha256", secret);
1819
hmac.update(url.pathname + url.search);
1920
return hmac.digest("hex");
2021
}
@@ -53,11 +54,11 @@ interface IServeFragmentOptions {
5354
pipeStream?: (stream: PipeableStream) => InstanceType<typeof Transform>;
5455
}
5556

56-
type resolver<
57+
type Resolver<
5758
TProps =
5859
| Record<string, unknown>
5960
| Promise<unknown>
60-
| Promise<Record<string, unknown>>
61+
| Promise<Record<string, unknown>>,
6162
> = (
6263
fragmentID: string,
6364
props: object,
@@ -72,7 +73,7 @@ type resolver<
7273
export async function serveFragment<TProps>(
7374
req: Request,
7475
res: Response,
75-
resolve: resolver<TProps>,
76+
resolve: Resolver<TProps>,
7677
options: IServeFragmentOptions = {}
7778
) {
7879
const url = new URL(req.url, "http://example.com");
@@ -100,7 +101,7 @@ export async function serveFragment<TProps>(
100101
? await Component.getInitialProps({
101102
props: baseChildProps,
102103
req,
103-
res
104+
res,
104105
})
105106
: baseChildProps;
106107

0 commit comments

Comments
 (0)