feat: init

This commit is contained in:
2026-02-13 22:02:30 +01:00
commit 8f9ff830fb
16711 changed files with 3307340 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
declare const _default: readonly [any, any, any, any];
export default _default;

View File

@@ -0,0 +1,143 @@
import { promises as fsp } from "node:fs";
import { defineNitroPreset } from "nitropack/kit";
import { dirname, join } from "pathe";
import { deprecateSWR, writeHeaders, writeRedirects } from "./utils.mjs";
const netlify = defineNitroPreset(
{
extends: "aws-lambda",
entry: "./runtime/netlify",
output: {
dir: "{{ rootDir }}/.netlify/functions-internal",
publicDir: "{{ rootDir }}/dist"
},
rollupConfig: {
output: {
entryFileNames: "server.mjs"
}
},
hooks: {
"rollup:before": (nitro) => {
deprecateSWR(nitro);
},
async compiled(nitro) {
await writeHeaders(nitro);
await writeRedirects(nitro, "/.netlify/functions/server");
if (nitro.options.netlify) {
const configPath = join(
nitro.options.output.dir,
"../deploy/v1/config.json"
);
await fsp.mkdir(dirname(configPath), { recursive: true });
await fsp.writeFile(
configPath,
JSON.stringify(nitro.options.netlify),
"utf8"
);
}
const functionConfig = {
config: { nodeModuleFormat: "esm" },
version: 1
};
const functionConfigPath = join(
nitro.options.output.serverDir,
"server.json"
);
await fsp.writeFile(functionConfigPath, JSON.stringify(functionConfig));
}
}
},
{
name: "netlify-legacy",
aliases: ["netlify"],
url: import.meta.url
}
);
const netlifyBuilder = defineNitroPreset(
{
extends: "netlify",
entry: "./runtime/netlify-builder",
hooks: {
"rollup:before": (nitro) => {
deprecateSWR(nitro);
}
}
},
{
name: "netlify-builder",
url: import.meta.url
}
);
const netlifyEdge = defineNitroPreset(
{
extends: "base-worker",
entry: "./runtime/netlify-edge",
exportConditions: ["netlify"],
output: {
serverDir: "{{ rootDir }}/.netlify/edge-functions/server",
publicDir: "{{ rootDir }}/dist"
},
rollupConfig: {
output: {
entryFileNames: "server.js",
format: "esm"
}
},
hooks: {
"rollup:before": (nitro) => {
deprecateSWR(nitro);
},
async compiled(nitro) {
await writeHeaders(nitro);
await writeRedirects(nitro);
const manifest = {
version: 1,
functions: [
{
path: "/*",
name: "nitro server handler",
function: "server",
generator: `${nitro.options.framework.name}@${nitro.options.framework.version}`
}
]
};
const manifestPath = join(
nitro.options.rootDir,
".netlify/edge-functions/manifest.json"
);
await fsp.mkdir(dirname(manifestPath), { recursive: true });
await fsp.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
}
}
},
{
name: "netlify-edge",
url: import.meta.url
}
);
const netlifyStatic = defineNitroPreset(
{
extends: "static",
output: {
dir: "{{ rootDir }}/dist",
publicDir: "{{ rootDir }}/dist"
},
commands: {
preview: "npx serve {{ output.dir }}"
},
hooks: {
"rollup:before": (nitro) => {
deprecateSWR(nitro);
},
async compiled(nitro) {
await writeHeaders(nitro);
await writeRedirects(nitro);
}
}
},
{
name: "netlify-static",
url: import.meta.url,
static: true
}
);
export default [netlify, netlifyBuilder, netlifyEdge, netlifyStatic];

View File

@@ -0,0 +1 @@
Object.assign(process.env, Deno.env.toObject());

View File

@@ -0,0 +1,2 @@
import "#nitro-internal-pollyfills";
export declare const handler: (event: any, context: any, callback?: any) => any;

View File

@@ -0,0 +1,41 @@
import "#nitro-internal-pollyfills";
import { lambda } from "./netlify-lambda.mjs";
export const handler = wrapHandler(lambda);
const BUILDER_FUNCTIONS_FLAG = true;
const HTTP_STATUS_METHOD_NOT_ALLOWED = 405;
const METADATA_VERSION = 1;
const augmentResponse = (response) => {
if (!response) {
return response;
}
const metadata = {
version: METADATA_VERSION,
builder_function: BUILDER_FUNCTIONS_FLAG,
ttl: response.ttl || 0
};
return {
...response,
metadata
};
};
function wrapHandler(handler2) {
return (event, context, callback) => {
if (event.httpMethod !== "GET" && event.httpMethod !== "HEAD") {
return Promise.resolve({
body: "Method Not Allowed",
statusCode: HTTP_STATUS_METHOD_NOT_ALLOWED
});
}
const modifiedEvent = {
...event,
multiValueQueryStringParameters: {},
queryStringParameters: {}
};
const wrappedCallback = (error, response) => callback ? callback(error, augmentResponse(response)) : null;
const execution = handler2(modifiedEvent, context, wrappedCallback);
if (typeof execution === "object" && typeof execution.then === "function") {
return execution.then(augmentResponse);
}
return execution;
};
}

View File

@@ -0,0 +1,3 @@
import "#nitro-internal-pollyfills";
import "./_deno-env-polyfill";
export default function netlifyEdge(request: Request, _context: any): Promise<any>;

View File

@@ -0,0 +1,26 @@
import "#nitro-internal-pollyfills";
import "./_deno-env-polyfill";
import { useNitroApp } from "nitropack/runtime";
import { isPublicAssetURL } from "#nitro-internal-virtual/public-assets";
const nitroApp = useNitroApp();
export default async function netlifyEdge(request, _context) {
const url = new URL(request.url);
if (isPublicAssetURL(url.pathname)) {
return;
}
if (!request.headers.has("x-forwarded-proto") && url.protocol === "https:") {
request.headers.set("x-forwarded-proto", "https");
}
let body;
if (request.body) {
body = await request.arrayBuffer();
}
return nitroApp.localFetch(url.pathname + url.search, {
host: url.hostname,
protocol: url.protocol,
headers: request.headers,
method: request.method,
redirect: request.redirect,
body
});
}

View File

@@ -0,0 +1,3 @@
import "#nitro-internal-pollyfills";
import type { HandlerContext, HandlerEvent, HandlerResponse } from "@netlify/functions";
export declare function lambda(event: HandlerEvent, context: HandlerContext): Promise<HandlerResponse>;

View File

@@ -0,0 +1,38 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import {
normalizeCookieHeader,
normalizeLambdaIncomingHeaders,
normalizeLambdaOutgoingBody,
normalizeLambdaOutgoingHeaders
} from "nitropack/runtime/internal";
import { withQuery } from "ufo";
const nitroApp = useNitroApp();
export async function lambda(event, context) {
const query = {
...event.queryStringParameters,
...event.multiValueQueryStringParameters
};
const url = withQuery(event.path, query);
const method = event.httpMethod || "get";
const r = await nitroApp.localCall({
event,
url,
context,
headers: normalizeLambdaIncomingHeaders(event.headers),
method,
query,
body: event.isBase64Encoded ? Buffer.from(event.body || "", "base64") : event.body
});
const cookies = normalizeCookieHeader(String(r.headers["set-cookie"]));
const awsBody = await normalizeLambdaOutgoingBody(r.body, r.headers);
return {
statusCode: r.status,
headers: normalizeLambdaOutgoingHeaders(r.headers, true),
body: awsBody.body,
isBase64Encoded: awsBody.type === "binary",
...cookies.length > 0 && {
multiValueHeaders: { "set-cookie": cookies }
}
};
}

View File

@@ -0,0 +1,3 @@
import "#nitro-internal-pollyfills";
import type { Handler } from "@netlify/functions";
export declare const handler: Handler;

View File

@@ -0,0 +1,21 @@
import "#nitro-internal-pollyfills";
import { getRouteRulesForPath } from "nitropack/runtime/internal";
import { withQuery } from "ufo";
import { lambda } from "./netlify-lambda.mjs";
export const handler = async function handler2(event, context) {
const query = {
...event.queryStringParameters,
...event.multiValueQueryStringParameters
};
const url = withQuery(event.path, query);
const routeRules = getRouteRulesForPath(url);
if (routeRules.isr) {
const builder = await import("@netlify/functions").then(
(r) => r.builder || r.default.builder
);
const ttl = typeof routeRules.isr === "number" ? routeRules.isr : false;
const builderHandler = ttl ? ((event2, context2) => lambda(event2, context2).then((r) => ({ ...r, ttl }))) : lambda;
return builder(builderHandler)(event, context);
}
return lambda(event, context);
};

View File

@@ -0,0 +1,6 @@
import type { Nitro, PublicAssetDir } from "nitropack/types";
export declare function generateCatchAllRedirects(publicAssets: PublicAssetDir[], catchAllPath?: string): string;
export declare function writeRedirects(nitro: Nitro, catchAllPath?: string): Promise<void>;
export declare function writeHeaders(nitro: Nitro): Promise<void>;
export declare function getStaticPaths(publicAssets: PublicAssetDir[]): string[];
export declare function deprecateSWR(nitro: Nitro): void;

View File

@@ -0,0 +1,133 @@
import { existsSync, promises as fsp } from "node:fs";
import { join } from "pathe";
import { joinURL } from "ufo";
import { isTest } from "std-env";
export function generateCatchAllRedirects(publicAssets, catchAllPath) {
if (!catchAllPath) return "";
return [
// e.g.: /static/* /static/:splat 200
// Because of Netlify CDN shadowing
// (https://docs.netlify.com/routing/redirects/rewrites-proxies/#shadowing),
// this config avoids function invocations for all static paths, even 404s.
...getStaticPaths(publicAssets).map(
(path) => `${path} ${path.replace("/*", "/:splat")} 200`
),
`/* ${catchAllPath} 200`
].join("\n");
}
export async function writeRedirects(nitro, catchAllPath) {
const redirectsPath = join(nitro.options.output.publicDir, "_redirects");
const staticFallback = existsSync(
join(nitro.options.output.publicDir, "404.html")
) ? "/* /404.html 404" : "";
let contents = nitro.options.static ? staticFallback : generateCatchAllRedirects(nitro.options.publicAssets, catchAllPath);
const rules = Object.entries(nitro.options.routeRules).sort(
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
);
if (!nitro.options.static) {
for (const [key, value] of rules.filter(
([_, value2]) => value2.isr !== void 0
)) {
contents = value.isr ? `${key.replace("/**", "/*")} /.netlify/builders/server 200
` + contents : `${key.replace("/**", "/*")} /.netlify/functions/server 200
` + contents;
}
}
for (const [key, routeRules] of rules.filter(
([_, routeRules2]) => routeRules2.redirect
)) {
let code = routeRules.redirect.statusCode;
if (code === 307) {
code = 302;
}
if (code === 308) {
code = 301;
}
contents = `${key.replace("/**", "/*")} ${routeRules.redirect.to.replace(
"/**",
"/:splat"
)} ${code}
` + contents;
}
if (existsSync(redirectsPath)) {
const currentRedirects = await fsp.readFile(redirectsPath, "utf8");
if (/^\/\* /m.test(currentRedirects)) {
nitro.logger.info(
"Not adding Nitro fallback to `_redirects` (as an existing fallback was found)."
);
return;
}
nitro.logger.info(
"Adding Nitro fallback to `_redirects` to handle all unmatched routes."
);
contents = currentRedirects + "\n" + contents;
}
await fsp.writeFile(redirectsPath, contents);
}
export async function writeHeaders(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
);
for (const [path, routeRules] of rules.filter(
([_, routeRules2]) => routeRules2.headers
)) {
const headers = [
path.replace("/**", "/*"),
...Object.entries({ ...routeRules.headers }).map(
([header, value]) => ` ${header}: ${value}`
)
].join("\n");
contents += headers + "\n";
}
if (existsSync(headersPath)) {
const currentHeaders = await fsp.readFile(headersPath, "utf8");
if (/^\/\* /m.test(currentHeaders)) {
nitro.logger.info(
"Not adding Nitro fallback to `_headers` (as an existing fallback was found)."
);
return;
}
nitro.logger.info(
"Adding Nitro fallback to `_headers` to handle all unmatched routes."
);
contents = currentHeaders + "\n" + contents;
}
await fsp.writeFile(headersPath, contents);
}
export function getStaticPaths(publicAssets) {
return publicAssets.filter(
(dir) => dir.fallthrough !== true && dir.baseURL && dir.baseURL !== "/"
).map((dir) => joinURL("/", dir.baseURL, "*"));
}
export function deprecateSWR(nitro) {
if (nitro.options.future.nativeSWR) {
return;
}
let hasLegacyOptions = false;
for (const [_key, value] of Object.entries(nitro.options.routeRules)) {
if (_hasProp(value, "isr")) {
continue;
}
if (value.cache === false) {
value.isr = false;
}
if (_hasProp(value, "static")) {
value.isr = !value.static;
hasLegacyOptions = true;
}
if (value?.cache && _hasProp(value.cache, "swr")) {
value.isr = value.cache.swr;
hasLegacyOptions = true;
}
}
if (hasLegacyOptions && !isTest) {
nitro.logger.warn(
"Nitro now uses `isr` option to configure ISR behavior on Netlify. Backwards-compatible support for `static` and `swr` support with Builder Functions will be removed in the future versions. Set `future.nativeSWR: true` nitro config disable this warning."
);
}
}
function _hasProp(obj, prop) {
return obj && typeof obj === "object" && prop in obj;
}

View File

@@ -0,0 +1,3 @@
export type { NetlifyOptions as PresetOptions } from "./types";
declare const _default: readonly [any, any, any, any, any, any, any];
export default _default;

136
node_modules/nitropack/dist/presets/netlify/preset.mjs generated vendored Normal file
View File

@@ -0,0 +1,136 @@
import { promises as fsp } from "node:fs";
import { defineNitroPreset } from "nitropack/kit";
import { dirname, join } from "pathe";
import { unenvDenoPreset } from "../_unenv/preset-deno.mjs";
import netlifyLegacyPresets from "./legacy/preset.mjs";
import {
generateNetlifyFunction,
getGeneratorString,
getStaticPaths,
writeHeaders,
writeRedirects
} from "./utils.mjs";
const netlify = defineNitroPreset(
{
entry: "./runtime/netlify",
output: {
dir: "{{ rootDir }}/.netlify/functions-internal",
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
},
rollupConfig: {
output: {
entryFileNames: "main.mjs"
}
},
hooks: {
async compiled(nitro) {
await writeHeaders(nitro);
await writeRedirects(nitro);
await fsp.writeFile(
join(nitro.options.output.dir, "server", "server.mjs"),
generateNetlifyFunction(nitro)
);
if (nitro.options.netlify) {
const configPath = join(
nitro.options.output.dir,
"../deploy/v1/config.json"
);
await fsp.mkdir(dirname(configPath), { recursive: true });
await fsp.writeFile(
configPath,
JSON.stringify(nitro.options.netlify),
"utf8"
);
}
}
}
},
{
name: "netlify",
stdName: "netlify",
url: import.meta.url,
compatibilityDate: "2024-05-07"
}
);
const netlifyEdge = defineNitroPreset(
{
extends: "base-worker",
entry: "./runtime/netlify-edge",
exportConditions: ["netlify"],
output: {
serverDir: "{{ rootDir }}/.netlify/edge-functions/server",
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
},
rollupConfig: {
output: {
entryFileNames: "server.js",
format: "esm"
}
},
unenv: unenvDenoPreset,
hooks: {
async compiled(nitro) {
await writeHeaders(nitro);
await writeRedirects(nitro);
const manifest = {
version: 1,
functions: [
{
path: "/*",
excludedPath: getStaticPaths(
nitro.options.publicAssets,
nitro.options.baseURL
),
name: "edge server handler",
function: "server",
generator: getGeneratorString(nitro),
cache: "manual"
}
]
};
const manifestPath = join(
nitro.options.rootDir,
".netlify/edge-functions/manifest.json"
);
await fsp.mkdir(dirname(manifestPath), { recursive: true });
await fsp.writeFile(manifestPath, JSON.stringify(manifest, null, 2));
}
}
},
{
name: "netlify-edge",
url: import.meta.url,
compatibilityDate: "2024-05-07"
}
);
const netlifyStatic = defineNitroPreset(
{
extends: "static",
output: {
dir: "{{ rootDir }}/dist",
publicDir: "{{ rootDir }}/dist/{{ baseURL }}"
},
commands: {
preview: "npx serve {{ output.dir }}"
},
hooks: {
async compiled(nitro) {
await writeHeaders(nitro);
await writeRedirects(nitro);
}
}
},
{
name: "netlify-static",
stdName: "netlify",
static: true,
url: import.meta.url,
compatibilityDate: "2024-05-07"
}
);
export default [
...netlifyLegacyPresets,
netlify,
netlifyEdge,
netlifyStatic
];

View File

@@ -0,0 +1,3 @@
import "#nitro-internal-pollyfills";
import type { Context } from "@netlify/edge-functions";
export default function netlifyEdge(request: Request, _context: Context): Promise<any>;

View File

@@ -0,0 +1,25 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import { isPublicAssetURL } from "#nitro-internal-virtual/public-assets";
const nitroApp = useNitroApp();
export default async function netlifyEdge(request, _context) {
const url = new URL(request.url);
if (isPublicAssetURL(url.pathname)) {
return;
}
if (!request.headers.has("x-forwarded-proto") && url.protocol === "https:") {
request.headers.set("x-forwarded-proto", "https");
}
let body;
if (request.body) {
body = await request.arrayBuffer();
}
return nitroApp.localFetch(url.pathname + url.search, {
host: url.hostname,
protocol: url.protocol,
headers: request.headers,
method: request.method,
redirect: request.redirect,
body
});
}

View File

@@ -0,0 +1,3 @@
import "#nitro-internal-pollyfills";
declare const handler: (req: Request) => Promise<Response>;
export default handler;

View File

@@ -0,0 +1,53 @@
import "#nitro-internal-pollyfills";
import { useNitroApp } from "nitropack/runtime";
import {
getRouteRulesForPath,
joinHeaders,
normalizeCookieHeader
} from "nitropack/runtime/internal";
const nitroApp = useNitroApp();
const handler = async (req) => {
const url = new URL(req.url);
const relativeUrl = `${url.pathname}${url.search}`;
const r = await nitroApp.localCall({
url: relativeUrl,
headers: req.headers,
method: req.method,
body: req.body
});
const headers = normalizeResponseHeaders({
...getCacheHeaders(url.pathname),
...r.headers
});
return new Response(r.body, {
status: r.status,
headers
});
};
export default handler;
const ONE_YEAR_IN_SECONDS = 365 * 24 * 60 * 60;
function normalizeResponseHeaders(headers) {
const outgoingHeaders = new Headers();
for (const [name, header] of Object.entries(headers)) {
if (name === "set-cookie") {
for (const cookie of normalizeCookieHeader(header)) {
outgoingHeaders.append("set-cookie", cookie);
}
} else if (header !== void 0) {
outgoingHeaders.set(name, joinHeaders(header));
}
}
return outgoingHeaders;
}
function getCacheHeaders(url) {
const { isr } = getRouteRulesForPath(url);
if (isr) {
const maxAge = typeof isr === "number" ? isr : ONE_YEAR_IN_SECONDS;
const revalidateDirective = typeof isr === "number" ? `stale-while-revalidate=${ONE_YEAR_IN_SECONDS}` : "must-revalidate";
return {
"Cache-Control": "public, max-age=0, must-revalidate",
"Netlify-CDN-Cache-Control": `public, max-age=${maxAge}, ${revalidateDirective}, durable`
};
}
return {};
}

12
node_modules/nitropack/dist/presets/netlify/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
/**
* Netlify options
*/
export interface NetlifyOptions {
images?: {
/**
* Permitted remote image sources. Array of regex strings.
* @see https://docs.netlify.com/image-cdn/overview/#remote-path
*/
remote_images?: string[];
};
}

View File

View File

@@ -0,0 +1,6 @@
import type { Nitro, PublicAssetDir } from "nitropack/types";
export declare function writeRedirects(nitro: Nitro): Promise<void>;
export declare function writeHeaders(nitro: Nitro): Promise<void>;
export declare function getStaticPaths(publicAssets: PublicAssetDir[], baseURL: string): string[];
export declare function generateNetlifyFunction(nitro: Nitro): string;
export declare function getGeneratorString(nitro: Nitro): string;

105
node_modules/nitropack/dist/presets/netlify/utils.mjs generated vendored Normal file
View File

@@ -0,0 +1,105 @@
import { existsSync, promises as fsp } from "node:fs";
import { join } from "pathe";
import { joinURL } from "ufo";
export async function writeRedirects(nitro) {
const redirectsPath = join(nitro.options.output.publicDir, "_redirects");
let contents = "";
if (nitro.options.static) {
const staticFallback = existsSync(
join(nitro.options.output.publicDir, "404.html")
) ? "/* /404.html 404" : "";
contents += staticFallback;
}
const rules = Object.entries(nitro.options.routeRules).sort(
(a, b) => a[0].split(/\/(?!\*)/).length - b[0].split(/\/(?!\*)/).length
);
for (const [key, routeRules] of rules.filter(
([_, routeRules2]) => routeRules2.redirect
)) {
let code = routeRules.redirect.statusCode;
if (code === 307) {
code = 302;
}
if (code === 308) {
code = 301;
}
contents = `${key.replace("/**", "/*")} ${routeRules.redirect.to.replace(
"/**",
"/:splat"
)} ${code}
` + contents;
}
if (existsSync(redirectsPath)) {
const currentRedirects = await fsp.readFile(redirectsPath, "utf8");
if (/^\/\* /m.test(currentRedirects)) {
nitro.logger.info(
"Not adding Nitro fallback to `_redirects` (as an existing fallback was found)."
);
return;
}
nitro.logger.info(
"Adding Nitro fallback to `_redirects` to handle all unmatched routes."
);
contents = currentRedirects + "\n" + contents;
}
await fsp.writeFile(redirectsPath, contents);
}
export async function writeHeaders(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
);
for (const [path, routeRules] of rules.filter(
([_, routeRules2]) => routeRules2.headers
)) {
const headers = [
path.replace("/**", "/*"),
...Object.entries({ ...routeRules.headers }).map(
([header, value]) => ` ${header}: ${value}`
)
].join("\n");
contents += headers + "\n";
}
if (existsSync(headersPath)) {
const currentHeaders = await fsp.readFile(headersPath, "utf8");
if (/^\/\* /m.test(currentHeaders)) {
nitro.logger.info(
"Not adding Nitro fallback to `_headers` (as an existing fallback was found)."
);
return;
}
nitro.logger.info(
"Adding Nitro fallback to `_headers` to handle all unmatched routes."
);
contents = currentHeaders + "\n" + contents;
}
await fsp.writeFile(headersPath, contents);
}
export function getStaticPaths(publicAssets, baseURL) {
return [
"/.netlify/*",
// TODO: should this be also be prefixed with baseURL?
...publicAssets.filter((a) => a.fallthrough !== true && a.baseURL && a.baseURL !== "/").map((a) => joinURL(baseURL, a.baseURL, "*"))
];
}
export function generateNetlifyFunction(nitro) {
return (
/* js */
`
export { default } from "./main.mjs";
export const config = {
name: "server handler",
generator: "${getGeneratorString(nitro)}",
path: "/*",
nodeBundler: "none",
includedFiles: ["**"],
excludedPath: ${JSON.stringify(getStaticPaths(nitro.options.publicAssets, nitro.options.baseURL))},
preferStatic: true,
};
`.trim()
);
}
export function getGeneratorString(nitro) {
return `${nitro.options.framework.name}@${nitro.options.framework.version}`;
}