Skip to content

Commit 6dbea61

Browse files
authored
Merge pull request #65 from seamapi/feat-prettier
2 parents a393f15 + 2398c56 commit 6dbea61

35 files changed

Lines changed: 180 additions & 139 deletions

.github/workflows/npm-lint.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: NPM Format Check
2+
on: ["pull_request"]
3+
jobs:
4+
npm_test:
5+
if: "!contains(github.event.head_commit.message, 'skip ci')"
6+
name: Run NPM Test
7+
runs-on: ubuntu-latest
8+
timeout-minutes: 30
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v1
12+
- name: Setup Node.js
13+
uses: actions/setup-node@v1
14+
with:
15+
node-version: 18
16+
- name: Run NPM Install
17+
run: yarn install
18+
- name: Check formatting
19+
run: npm run format:check

.prettierrc.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"semi": false,
3+
"singleQuote": true,
4+
"jsxSingleQuote": true,
5+
"endOfLine": "lf"
6+
}

ava.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ module.exports = {
22
files: ["tests/**/*.test.ts"],
33
extensions: ["ts"],
44
timeout: "2m",
5-
require: ["esbuild-runner/register"]
5+
require: ["esbuild-runner/register"],
66
}

bin.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env node
22

33
require("esbuild-runner/register")
4-
require("./lib/cli.js").default().catch(error => {
5-
console.error(error)
6-
process.exit(1)
7-
})
4+
require("./lib/cli.js")
5+
.default()
6+
.catch((error) => {
7+
console.error(error)
8+
process.exit(1)
9+
})

lib/build.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const build = async ({
2121
skipBuild = false,
2222
nextless = false,
2323
onlyApiFiles = false,
24-
skipNextBuild = false
24+
skipNextBuild = false,
2525
}) => {
2626
if (skipNextBuild) {
2727
console.log("Deprecated. Use --skip-build and/or --nextless instead")
@@ -33,14 +33,14 @@ const build = async ({
3333
(await findUp(
3434
async (directory) => {
3535
const hasNext = await findUp.exists(
36-
path.join(directory, "node_modules/next")
36+
path.join(directory, "node_modules/next"),
3737
)
3838
return hasNext && directory
3939
},
4040
{
4141
type: "directory",
4242
cwd: dir,
43-
}
43+
},
4444
)) || dir
4545
logv({ packageDirWithNext })
4646

@@ -49,7 +49,7 @@ const build = async ({
4949
require.resolve(`${packageDirWithNext}/node_modules/next`)
5050
} catch (e) {
5151
throw new Error(
52-
`Couldn't find next module, it might not be installed in your project. I checked the path: "${dir}/node_modules/next"`
52+
`Couldn't find next module, it might not be installed in your project. I checked the path: "${dir}/node_modules/next"`,
5353
)
5454
}
5555
}

lib/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ async function main() {
4949
skipBuild: argv["skip-build"],
5050
nextless: argv["nextless"],
5151
onlyApiFiles: argv["only-api-files"],
52-
skipNextBuild: argv["skip-next-build"]
52+
skipNextBuild: argv["skip-next-build"],
5353
})
5454
break
5555
}

nsm/get-server-fixture.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ async function getServerFixture(t: ExecutionContext, options: Options = {}) {
3434

3535
const customAxios = axios.create({
3636
baseURL: serverURL,
37-
...options.axiosConfig
37+
...options.axiosConfig,
3838
})
3939

4040
customAxios.interceptors.response.use(
4141
(res) => res,
4242
(err) =>
4343
err instanceof AxiosError
4444
? Promise.reject(new SimpleAxiosError(err))
45-
: Promise.reject(err)
45+
: Promise.reject(err),
4646
)
4747

4848
return {

nsm/index.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ function resolveDynamicRoute(pathname: string, pages: string[]) {
5757

5858
type Middleware = (next: NextApiHandler) => NextApiHandler
5959

60-
export const runServer = async ({ port, middlewares = [] }: {port: number, middlewares?: Middleware[]}) => {
60+
export const runServer = async ({
61+
port,
62+
middlewares = [],
63+
}: {
64+
port: number
65+
middlewares?: Middleware[]
66+
}) => {
6167
debug(`starting server on port ${port}`)
6268

6369
const routeMatcher = getRouteMatcher(routes)
@@ -74,7 +80,7 @@ export const runServer = async ({ port, middlewares = [] }: {port: number, middl
7480
...(nextConfig as any).rewrites,
7581
},
7682
query,
77-
(s) => resolveDynamicRoute(s, Object.keys(routes))
83+
(s) => resolveDynamicRoute(s, Object.keys(routes)),
7884
)
7985
debug(`resolved request to "${resolveResult.parsedAs.pathname}"`)
8086

@@ -93,7 +99,7 @@ export const runServer = async ({ port, middlewares = [] }: {port: number, middl
9399
}
94100

95101
const wrappedServerFunc = (wrappers as any)(
96-
...[...middlewares, serverFunc?.default || serverFunc]
102+
...[...middlewares, serverFunc?.default || serverFunc],
97103
)
98104

99105
wrappedServerFunc.config = serverFunc.config || {}
@@ -104,12 +110,12 @@ export const runServer = async ({ port, middlewares = [] }: {port: number, middl
104110
{ ...query, ...match },
105111
wrappedServerFunc,
106112
{},
107-
false
113+
false,
108114
)
109115
})
110116

111117
await new Promise<void>((resolve, reject) => {
112-
server.once('error', (err) => {
118+
server.once("error", (err) => {
113119
if (err) reject(err)
114120
})
115121
server.listen(port, () => {

nsm/nextjs-middleware/api-utils.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function apiResolver(
4545
apiContext: __ApiPreviewProps,
4646
propagateError: boolean,
4747
dev?: boolean,
48-
page?: string
48+
page?: string,
4949
): Promise<void> {
5050
const apiReq = req as NextApiRequest
5151
const apiRes = res as NextApiResponse
@@ -76,7 +76,7 @@ export async function apiResolver(
7676
apiReq,
7777
config.api && config.api.bodyParser && config.api.bodyParser.sizeLimit
7878
? config.api.bodyParser.sizeLimit
79-
: "1mb"
79+
: "1mb",
8080
)
8181
}
8282

@@ -94,7 +94,7 @@ export async function apiResolver(
9494

9595
if (contentLength >= 4 * 1024 * 1024) {
9696
console.warn(
97-
`API response for ${req.url} exceeds 4MB. This will cause the request to fail in a future version. https://nextjs.org/docs/messages/api-routes-body-size-limit`
97+
`API response for ${req.url} exceeds 4MB. This will cause the request to fail in a future version. https://nextjs.org/docs/messages/api-routes-body-size-limit`,
9898
)
9999
}
100100

@@ -127,7 +127,7 @@ export async function apiResolver(
127127
!wasPiped
128128
) {
129129
console.warn(
130-
`API resolved without sending a response for ${req.url}, this may result in stalled requests.`
130+
`API resolved without sending a response for ${req.url}, this may result in stalled requests.`,
131131
)
132132
}
133133
} catch (err) {
@@ -156,7 +156,7 @@ export async function apiResolver(
156156
*/
157157
export async function parseBody(
158158
req: IncomingMessage,
159-
limit: string | number
159+
limit: string | number,
160160
): Promise<any> {
161161
let contentType
162162
try {
@@ -234,7 +234,7 @@ export function getCookieParser(headers: {
234234
*/
235235
export function sendStatusCode(
236236
res: NextApiResponse,
237-
statusCode: number
237+
statusCode: number,
238238
): NextApiResponse<any> {
239239
res.statusCode = statusCode
240240
return res
@@ -249,15 +249,15 @@ export function sendStatusCode(
249249
export function redirect(
250250
res: NextApiResponse,
251251
statusOrUrl: string | number,
252-
url?: string
252+
url?: string,
253253
): NextApiResponse<any> {
254254
if (typeof statusOrUrl === "string") {
255255
url = statusOrUrl
256256
statusOrUrl = 307
257257
}
258258
if (typeof statusOrUrl !== "number" || typeof url !== "string") {
259259
throw new Error(
260-
`Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`
260+
`Invalid redirect arguments. Please use a single argument URL, e.g. res.redirect('/destination') or use a status code and URL, e.g. res.redirect(307, '/destination').`,
261261
)
262262
}
263263
res.writeHead(statusOrUrl, { Location: url })
@@ -275,7 +275,7 @@ export function redirect(
275275
export function sendData(
276276
req: NextApiRequest,
277277
res: NextApiResponse,
278-
body: any
278+
body: any,
279279
): void {
280280
if (body === null || body === undefined) {
281281
res.end()
@@ -291,7 +291,7 @@ export function sendData(
291291
if (process.env.NODE_ENV === "development" && body) {
292292
console.warn(
293293
`A body was attempted to be set with a 204 statusCode for ${req.url}, this is invalid and the body was ignored.\n` +
294-
`See more info here https://nextjs.org/docs/messages/invalid-api-status-body`
294+
`See more info here https://nextjs.org/docs/messages/invalid-api-status-body`,
295295
)
296296
}
297297
res.end()
@@ -354,7 +354,7 @@ const SYMBOL_CLEARED_COOKIES = Symbol(COOKIE_NAME_PRERENDER_BYPASS)
354354
export function tryGetPreviewData(
355355
req: IncomingMessage,
356356
res: ServerResponse,
357-
options: __ApiPreviewProps
357+
options: __ApiPreviewProps,
358358
): any {
359359
// Read cached preview data if present
360360
if (SYMBOL_PREVIEW_DATA in req) {
@@ -437,7 +437,7 @@ function setPreviewData<T>(
437437
data: object | string, // TODO: strict runtime type checking
438438
options: {
439439
maxAge?: number
440-
} & __ApiPreviewProps
440+
} & __ApiPreviewProps,
441441
): NextApiResponse<T> {
442442
if (isNotValidData(options.previewModeId!)) {
443443
throw new Error("invariant: invalid previewModeId")
@@ -567,7 +567,7 @@ export class ApiError extends Error {
567567
export function sendError(
568568
res: NextApiResponse,
569569
statusCode: number,
570-
message: string
570+
message: string,
571571
): void {
572572
res.statusCode = statusCode
573573
res.statusMessage = message
@@ -587,7 +587,7 @@ interface LazyProps {
587587
export function setLazyProp<T>(
588588
{ req }: LazyProps,
589589
prop: string,
590-
getter: () => T
590+
getter: () => T,
591591
): void {
592592
const opts = { configurable: true, enumerable: true }
593593
const optsReset = { ...opts, writable: true }

nsm/nextjs-middleware/normalize-locale-path.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface PathLocale {
1616
*/
1717
export function normalizeLocalePath(
1818
pathname: string,
19-
locales?: string[]
19+
locales?: string[],
2020
): PathLocale {
2121
let detectedLocale: string | undefined
2222
// first item will be empty string from splitting at first char

0 commit comments

Comments
 (0)