Skip to content

Commit

Permalink
style: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Dec 21, 2022
1 parent a076f01 commit 4679953
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
18 changes: 12 additions & 6 deletions src/presets/netlify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ async function writeRedirects(nitro: Nitro) {
const redirectsPath = join(nitro.options.output.publicDir, "_redirects");
let contents = "/* /.netlify/functions/server 200";

const rules = Object.entries(nitro.options.routeRules)
.sort((a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length)
const rules = Object.entries(nitro.options.routeRules).sort(
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
);

// Rewrite static cached paths to builder functions
for (const [key] of rules.filter(
Expand All @@ -96,7 +97,9 @@ async function writeRedirects(nitro: Nitro) {
`${key.replace("/**", "/*")}\t/.netlify/builders/server 200\n` + contents;
}

for (const [key, routeRules] of rules.filter(([_, routeRules]) => routeRules.redirect)) {
for (const [key, routeRules] of rules.filter(
([_, routeRules]) => routeRules.redirect
)) {
// TODO: Remove map when netlify support 307/308
let code = routeRules.redirect.statusCode;
code = { 307: 302, 308: 301 }[code] || code;
Expand Down Expand Up @@ -126,10 +129,13 @@ async function writeHeaders(nitro: Nitro) {
const headersPath = join(nitro.options.output.publicDir, "_headers");
let contents = "";

const rules = Object.entries(nitro.options.routeRules)
.sort((a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length)
const rules = Object.entries(nitro.options.routeRules).sort(
(a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length
);

for (const [path, routeRules] of rules.filter(([_, routeRules]) => routeRules.headers)) {
for (const [path, routeRules] of rules.filter(
([_, routeRules]) => routeRules.headers
)) {
const headers = [
path.replace("/**", "/*"),
...Object.entries({ ...routeRules.headers }).map(
Expand Down
26 changes: 17 additions & 9 deletions src/presets/vercel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ export const vercel = defineNitroPreset({
);

// Write prerender functions
const rules = Object.entries(nitro.options.routeRules)
.filter(([_, value]) => value.cache && (value.cache.swr || value.cache.static))
const rules = Object.entries(nitro.options.routeRules).filter(
([_, value]) => value.cache && (value.cache.swr || value.cache.static)
);

for (const [key, value] of rules) {
if (!value.cache) {
Expand Down Expand Up @@ -120,8 +121,9 @@ export const vercelEdge = defineNitroPreset({
});

function generateBuildConfig(nitro: Nitro) {
const rules = Object.entries(nitro.options.routeRules)
.sort((a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length)
const rules = Object.entries(nitro.options.routeRules).sort(
(a, b) => b[0].split(/\/(?!\*)/).length - a[0].split(/\/(?!\*)/).length
);

return defu(nitro.options.vercel?.config, <VercelBuildConfigV3>{
version: 3,
Expand Down Expand Up @@ -175,11 +177,17 @@ function generateBuildConfig(nitro: Nitro) {
})),
// If we are using a prerender function as a fallback, then we do not need to output
// the below fallback route as well
...(!nitro.options.routeRules['/**']?.cache || !(nitro.options.routeRules['/**'].cache.swr || nitro.options.routeRules['/**']?.cache.static)
? [{
src: "/(.*)",
dest: "/__nitro",
}]
...(!nitro.options.routeRules["/**"]?.cache ||
!(
nitro.options.routeRules["/**"].cache.swr ||
nitro.options.routeRules["/**"]?.cache.static
)
? [
{
src: "/(.*)",
dest: "/__nitro",
},
]
: []),
],
});
Expand Down

0 comments on commit 4679953

Please sign in to comment.