Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/biome code style #628

Merged
merged 24 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
b2a8203
chore(lint): restore useArrowFunction fixes for bound functions and i…
maxmorozoff Nov 9, 2024
0ae45fb
chore(lint): remove linter rules from config
maxmorozoff Nov 10, 2024
e4957a2
chore(lint): fix noVar rule and remove from config
maxmorozoff Nov 10, 2024
14072d1
chore(lint): fix noImplicitAnyLet rule and remove from config
maxmorozoff Nov 10, 2024
04efbbe
chore(lint): fix noGlobalIsNan rule and remove from config
maxmorozoff Nov 10, 2024
e53c241
chore(lint): fix noUselessElse rule and remove from config
maxmorozoff Nov 11, 2024
ee6dd5f
chore(lint): fix useNodejsImportProtocol rule and remove from config
maxmorozoff Nov 11, 2024
53c2ad6
chore(lint): fix useTemplate rule and remove from config
maxmorozoff Nov 11, 2024
4128cb6
chore(lint): fix useDefaultParameterLast rule and remove from config
maxmorozoff Nov 11, 2024
97394c1
chore(lint): fix useSingleVarDeclarator rule and remove from config
maxmorozoff Nov 11, 2024
27e89b0
chore(lint): fix noSwitchDeclarations rule and remove from config
maxmorozoff Nov 11, 2024
66201fc
chore(lint): fix useLiteralKeys rule and remove from config
maxmorozoff Nov 11, 2024
50e3eae
chore(lint): fix noUselessSwitchCase rule and remove from config
maxmorozoff Nov 11, 2024
36c6fbe
chore(lint): fix noUselessConstructor rule and remove from config
maxmorozoff Nov 11, 2024
670b65a
chore(lint): fix noUselessTernary rule and remove from config
maxmorozoff Nov 11, 2024
77a8fa0
chore(lint): fix noExtraBooleanCast rule and remove from config
maxmorozoff Nov 11, 2024
acf1e41
chore(lint): fix useOptionalChain rule and remove from config
maxmorozoff Nov 11, 2024
c485e54
chore(lint): fix noUnusedTemplateLiteral rule and remove from config
maxmorozoff Nov 11, 2024
5d58d4d
chore(lint): fix noAccumulatingSpread rule and remove from config
maxmorozoff Nov 11, 2024
dbf96a9
chore(lint): ignore linter warnings
maxmorozoff Nov 11, 2024
67df90b
chore(lint): update linter rules config
maxmorozoff Nov 11, 2024
8751b03
chore(lint): remove <explanation> placeholder in biome-ignore comments
maxmorozoff Nov 12, 2024
ef74bd9
Revert "chore(lint): restore useArrowFunction fixes for bound functio…
maxmorozoff Nov 14, 2024
4df9a87
fixup! chore(lint): ignore linter warnings
maxmorozoff Nov 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .changeset/aggregate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ console.log(`::set-output name=notes::${notes.join("%0A")}`);
console.log(`::set-output name=version::v${version}`);

execSync(`git tag v${version}`);
execSync(`git push origin --tags`);
execSync("git push origin --tags");
56 changes: 14 additions & 42 deletions biome.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -14,49 +14,21 @@
"all": false
},
"suspicious": {
"noExplicitAny": "info",
"noGlobalIsNan": "warn",
"noImplicitAnyLet": "warn",
"noAssignInExpressions": "warn",
"noConfusingVoidType": "warn",
"useNamespaceKeyword": "warn" // safe fix
"noExplicitAny": "off",
"noAssignInExpressions": "off",
"noConfusingVoidType": "off"
},
"style": {
"noUnusedTemplateLiteral": "warn",
"noInferrableTypes": "warn", // safe fix
"noUselessElse": "warn",
"useNodejsImportProtocol": "warn",
"useTemplate": "warn",
"useNumberNamespace": "warn", // safe fix
"noNonNullAssertion": "warn",
"useImportType": "warn",
"noParameterAssign": "warn",
"useDefaultParameterLast": "warn",
"noCommaOperator": "warn",
"useConst": "warn",
"useSingleVarDeclarator": "warn",
"noVar": "warn",
"useShorthandFunctionType": "warn" // safe fix
},
"correctness": {
"noSwitchDeclarations": "warn",
"noUnnecessaryContinue": "warn",
"noInnerDeclarations": "warn"
"noNonNullAssertion": "off",
"noParameterAssign": "info",
"noCommaOperator": "info"
},
"complexity": {
"useLiteralKeys": "warn",
"noForEach": "off",
"noUselessSwitchCase": "warn",
"noUselessConstructor": "warn",
"noBannedTypes": "warn",
"noUselessTernary": "warn",
"useArrowFunction": "warn", // safe fix
"noExtraBooleanCast": "warn",
"useOptionalChain": "warn"
"noBannedTypes": "off"
},
"performance": {
"noDelete": "warn",
"noAccumulatingSpread": "warn"
"noDelete": "off"
}
}
},
Expand All @@ -66,7 +38,7 @@
"linter": {
"rules": {
"suspicious": {
"noRedeclare": "warn"
"noRedeclare": "off"
}
}
}
Expand All @@ -76,15 +48,15 @@
"linter": {
"rules": {
"style": {
"useSelfClosingElements": "warn"
"useSelfClosingElements": "off"
},
"correctness": {
"useJsxKeyInIterable": "warn",
"useExhaustiveDependencies": "warn"
"useJsxKeyInIterable": "off",
"useExhaustiveDependencies": "off"
},
"suspicious": {
"noArrayIndexKey": "warn",
"noRedeclare": "warn"
"noArrayIndexKey": "off",
"noRedeclare": "off"
}
}
}
Expand Down
21 changes: 11 additions & 10 deletions examples/app-pages-router/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,27 @@ export function middleware(request: NextRequest) {
return NextResponse.redirect(u, {
headers: { "set-cookie": "test=success" },
});
} else if (path === "/rewrite") {
}
if (path === "/rewrite") {
const u = new URL("/rewrite-destination", `${protocol}://${host}`);
u.searchParams.set("a", "b");
return NextResponse.rewrite(u);
} else if (path === "/api/middleware") {
}
if (path === "/api/middleware") {
return new NextResponse(JSON.stringify({ hello: "middleware" }), {
status: 200,
headers: {
"content-type": "application/json",
},
});
} else {
const rHeaders = new Headers(request.headers);
const r = NextResponse.next({
request: {
headers: rHeaders,
},
});
return r;
}
const rHeaders = new Headers(request.headers);
const r = NextResponse.next({
request: {
headers: rHeaders,
},
});
return r;
}

export const config = {
Expand Down
4 changes: 2 additions & 2 deletions examples/app-router/app/api/isr/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from "path";
import fs from "fs/promises";
import fs from "node:fs/promises";
import path from "node:path";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";

Expand Down
2 changes: 1 addition & 1 deletion examples/app-router/app/api/sse/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function GET(request: NextRequest) {
await wait(2000);
await writer.write(
`data: ${JSON.stringify({
message: "hello:" + i,
message: `hello:${i}`,
time: new Date().toISOString(),
})}\n\n`,
);
Expand Down
2 changes: 1 addition & 1 deletion examples/app-router/app/search-query/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default async function SearchQuery(props: {
}) {
const propsSearchParams = await props.searchParams;
const mwSearchParams = (await headers()).get("search-params");
const multiValueParams = propsSearchParams["multi"];
const multiValueParams = propsSearchParams.multi;
const multiValueArray = Array.isArray(multiValueParams)
? multiValueParams
: [multiValueParams];
Expand Down
95 changes: 48 additions & 47 deletions examples/app-router/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,66 +11,67 @@ export function middleware(request: NextRequest) {
return NextResponse.redirect(u, {
headers: { "set-cookie": "test=success" },
});
} else if (path === "/rewrite") {
}
if (path === "/rewrite") {
const u = new URL("/rewrite-destination", `${protocol}://${host}`);
return NextResponse.rewrite(u);
} else if (path === "/api/middleware") {
}
if (path === "/api/middleware") {
return new NextResponse(JSON.stringify({ hello: "middleware" }), {
status: 200,
headers: {
"content-type": "application/json",
},
});
} else {
const requestHeaders = new Headers();
// Setting the Request Headers, this should be available in RSC
requestHeaders.set("request-header", "request-header");
requestHeaders.set(
"search-params",
`mw/${request.nextUrl.searchParams.get("searchParams") || ""}`,
);
const responseHeaders = new Headers();
// Response headers should show up in the client's response headers
responseHeaders.set("response-header", "response-header");
}
const requestHeaders = new Headers();
// Setting the Request Headers, this should be available in RSC
requestHeaders.set("request-header", "request-header");
requestHeaders.set(
"search-params",
`mw/${request.nextUrl.searchParams.get("searchParams") || ""}`,
);
const responseHeaders = new Headers();
// Response headers should show up in the client's response headers
responseHeaders.set("response-header", "response-header");

// Set the cache control header with custom swr
// For: isr.test.ts
if (path === "/isr" && !request.headers.get("x-prerender-revalidate")) {
responseHeaders.set(
"cache-control",
"max-age=10, stale-while-revalidate=999",
);
}
// Set the cache control header with custom swr
// For: isr.test.ts
if (path === "/isr" && !request.headers.get("x-prerender-revalidate")) {
responseHeaders.set(
"cache-control",
"max-age=10, stale-while-revalidate=999",
);
}

// It is so that cloudfront doesn't cache the response
if (
path.startsWith("/revalidate-tag") ||
path.startsWith("/revalidate-path")
) {
responseHeaders.set(
"cache-control",
"private, no-cache, no-store, max-age=0, must-revalidate",
);
}
// It is so that cloudfront doesn't cache the response
if (
path.startsWith("/revalidate-tag") ||
path.startsWith("/revalidate-path")
) {
responseHeaders.set(
"cache-control",
"private, no-cache, no-store, max-age=0, must-revalidate",
);
}

const r = NextResponse.next({
headers: responseHeaders,
request: {
headers: requestHeaders,
},
});
const r = NextResponse.next({
headers: responseHeaders,
request: {
headers: requestHeaders,
},
});

// Set cookies in middleware
// For: middleware.cookies.test.ts
r.cookies.set("from", "middleware", {
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
});
r.cookies.set("with", "love", {
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
});
// Set cookies in middleware
// For: middleware.cookies.test.ts
r.cookies.set("from", "middleware", {
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
});
r.cookies.set("with", "love", {
expires: new Date(Date.now() + 1000 * 60 * 60 * 24 * 365),
});

return r;
}
return r;
}

export const config = {
Expand Down
40 changes: 19 additions & 21 deletions examples/sst/stacks/OpenNextReferenceImplementation.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from "node:child_process";

import { readFileSync } from "fs";
import path from "path";
import { readFileSync } from "node:fs";
import path from "node:path";
import type { BehaviorOptions, ICachePolicy } from "aws-cdk-lib/aws-cloudfront";
import {
AllowedMethods,
Expand Down Expand Up @@ -391,26 +391,24 @@ export class OpenNextCdkReferenceImplementation extends Construct {
.filter((b) => b.pattern !== "*")
.reduce(
(acc, behavior) => {
return {
...acc,
[behavior.pattern]: {
origin: behavior.origin
? origins[behavior.origin]
: origins.default,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
cachePolicy:
behavior.origin === "s3"
? this.staticCachePolicy
: this.serverCachePolicy,
originRequestPolicy:
behavior.origin === "s3"
? undefined
: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
functionAssociations: fnAssociations,
},
acc[behavior.pattern] = {
origin: behavior.origin
? origins[behavior.origin]
: origins.default,
viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS,
allowedMethods: AllowedMethods.ALLOW_GET_HEAD_OPTIONS,
cachedMethods: CachedMethods.CACHE_GET_HEAD_OPTIONS,
cachePolicy:
behavior.origin === "s3"
? this.staticCachePolicy
: this.serverCachePolicy,
originRequestPolicy:
behavior.origin === "s3"
? undefined
: OriginRequestPolicy.ALL_VIEWER_EXCEPT_HOST_HEADER,
functionAssociations: fnAssociations,
};
return acc;
},
{} as Record<string, BehaviorOptions>,
),
Expand Down
16 changes: 8 additions & 8 deletions packages/open-next/src/adapters/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ function isFetchCache(
}
// We need to use globalThis client here as this class can be defined at load time in next 12 but client is not available at load time
export default class S3Cache {
constructor(_ctx: CacheHandlerContext) {}

public async get(
key: string,
// fetchCache is for next 13.5 and above, kindHint is for next 14 and above and boolean is for earlier versions
Expand Down Expand Up @@ -233,7 +231,8 @@ export default class S3Cache {
headers: meta?.headers,
},
} as CacheHandlerValue;
} else if (cacheData?.type === "page" || cacheData?.type === "app") {
}
if (cacheData?.type === "page" || cacheData?.type === "app") {
if (globalThis.isNextAfter15 && cacheData?.type === "app") {
return {
lastModified: _lastModified,
Expand All @@ -258,18 +257,18 @@ export default class S3Cache {
headers: meta?.headers,
},
} as CacheHandlerValue;
} else if (cacheData?.type === "redirect") {
}
if (cacheData?.type === "redirect") {
return {
lastModified: _lastModified,
value: {
kind: "REDIRECT",
props: cacheData.props,
},
} as CacheHandlerValue;
} else {
warn("Unknown cache type", cacheData);
return null;
}
warn("Unknown cache type", cacheData);
return null;
} catch (e) {
// We can usually ignore errors here as they are usually due to cache not being found
debug("Failed to get body cache", e);
Expand All @@ -296,7 +295,7 @@ export default class S3Cache {
} else {
switch (data.kind) {
case "ROUTE":
case "APP_ROUTE":
case "APP_ROUTE": {
const { body, status, headers } = data;
await globalThis.incrementalCache.set(
key,
Expand All @@ -315,6 +314,7 @@ export default class S3Cache {
false,
);
break;
}
case "PAGE":
case "PAGES": {
const { html, pageData, status, headers } = data;
Expand Down
2 changes: 1 addition & 1 deletion packages/open-next/src/adapters/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "path";
import path from "node:path";

import { debug } from "../logger";
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/open-next/src/adapters/config/util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from "fs";
import path from "path";
import fs from "node:fs";
import path from "node:path";
import type {
MiddlewareManifest,
NextConfig,
Expand Down
Loading
Loading