Refactor routing in App component to enhance navigation and improve error handling by integrating dynamic routes and updating the NotFound route.

This commit is contained in:
becarta
2025-05-23 12:43:00 +02:00
parent f40db0f5c9
commit a544759a3b
11127 changed files with 1647032 additions and 0 deletions

25
node_modules/astro/dist/core/dev/container.d.ts generated vendored Normal file
View File

@@ -0,0 +1,25 @@
import type * as http from 'node:http';
import type { AddressInfo } from 'node:net';
import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js';
import nodeFs from 'node:fs';
import * as vite from 'vite';
import type { Logger } from '../logger/core.js';
export interface Container {
fs: typeof nodeFs;
logger: Logger;
settings: AstroSettings;
viteServer: vite.ViteDevServer;
inlineConfig: AstroInlineConfig;
restartInFlight: boolean;
handle: (req: http.IncomingMessage, res: http.ServerResponse) => void;
close: () => Promise<void>;
}
export interface CreateContainerParams {
logger: Logger;
settings: AstroSettings;
inlineConfig?: AstroInlineConfig;
isRestart?: boolean;
fs?: typeof nodeFs;
}
export declare function createContainer({ isRestart, logger, inlineConfig, settings, fs, }: CreateContainerParams): Promise<Container>;
export declare function startContainer({ settings, viteServer, logger, }: Container): Promise<AddressInfo>;

98
node_modules/astro/dist/core/dev/container.js generated vendored Normal file
View File

@@ -0,0 +1,98 @@
import nodeFs from "node:fs";
import * as vite from "vite";
import { injectImageEndpoint } from "../../assets/endpoint/config.js";
import {
runHookConfigDone,
runHookConfigSetup,
runHookServerDone,
runHookServerStart
} from "../../integrations/hooks.js";
import { createVite } from "../create-vite.js";
import { apply as applyPolyfill } from "../polyfill.js";
import { syncInternal } from "../sync/index.js";
async function createContainer({
isRestart = false,
logger,
inlineConfig,
settings,
fs = nodeFs
}) {
applyPolyfill();
settings = await runHookConfigSetup({
settings,
command: "dev",
logger,
isRestart
});
settings = injectImageEndpoint(settings, "dev");
const {
base,
server: { host, headers, open: serverOpen }
} = settings.config;
const isServerOpenURL = typeof serverOpen == "string" && !isRestart;
const isServerOpenBoolean = serverOpen && !isRestart;
const open = isServerOpenURL ? serverOpen : isServerOpenBoolean ? base : false;
const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
const viteConfig = await createVite(
{
mode: "development",
server: { host, headers, open },
optimizeDeps: {
include: rendererClientEntries
}
},
{ settings, logger, mode: "dev", command: "dev", fs, sync: false }
);
await runHookConfigDone({ settings, logger });
await syncInternal({
settings,
logger,
skip: {
content: true
},
force: inlineConfig?.force
});
const viteServer = await vite.createServer(viteConfig);
const container = {
inlineConfig: inlineConfig ?? {},
fs,
logger,
restartInFlight: false,
settings,
viteServer,
handle(req, res) {
viteServer.middlewares.handle(req, res, Function.prototype);
},
// TODO deprecate and remove
close() {
return closeContainer(container);
}
};
return container;
}
async function closeContainer({ viteServer, settings, logger }) {
await viteServer.close();
await runHookServerDone({
config: settings.config,
logger
});
}
async function startContainer({
settings,
viteServer,
logger
}) {
const { port } = settings.config.server;
await viteServer.listen(port);
const devServerAddressInfo = viteServer.httpServer.address();
await runHookServerStart({
config: settings.config,
address: devServerAddressInfo,
logger
});
return devServerAddressInfo;
}
export {
createContainer,
startContainer
};

17
node_modules/astro/dist/core/dev/dev.d.ts generated vendored Normal file
View File

@@ -0,0 +1,17 @@
import type http from 'node:http';
import type { AddressInfo } from 'node:net';
import type * as vite from 'vite';
import type { AstroInlineConfig } from '../../@types/astro.js';
export interface DevServer {
address: AddressInfo;
handle: (req: http.IncomingMessage, res: http.ServerResponse<http.IncomingMessage>) => void;
watcher: vite.FSWatcher;
stop(): Promise<void>;
}
/**
* Runs Astros development server. This is a local HTTP server that doesnt bundle assets.
* It uses Hot Module Replacement (HMR) to update your browser as you save changes in your editor.
*
* @experimental The JavaScript API is experimental
*/
export default function dev(inlineConfig: AstroInlineConfig): Promise<DevServer>;

112
node_modules/astro/dist/core/dev/dev.js generated vendored Normal file
View File

@@ -0,0 +1,112 @@
import fs, { existsSync } from "node:fs";
import { performance } from "node:perf_hooks";
import { green } from "kleur/colors";
import { gt, major, minor, patch } from "semver";
import { getDataStoreFile, globalContentLayer } from "../../content/content-layer.js";
import { attachContentServerListeners } from "../../content/index.js";
import { MutableDataStore } from "../../content/mutable-data-store.js";
import { globalContentConfigObserver } from "../../content/utils.js";
import { telemetry } from "../../events/index.js";
import * as msg from "../messages.js";
import { ensureProcessNodeEnv } from "../util.js";
import { startContainer } from "./container.js";
import { createContainerWithAutomaticRestart } from "./restart.js";
import {
MAX_PATCH_DISTANCE,
fetchLatestAstroVersion,
shouldCheckForUpdates
} from "./update-check.js";
async function dev(inlineConfig) {
ensureProcessNodeEnv("development");
const devStart = performance.now();
await telemetry.record([]);
const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
const logger = restart.container.logger;
const currentVersion = "4.16.18";
const isPrerelease = currentVersion.includes("-");
if (!isPrerelease) {
try {
shouldCheckForUpdates(restart.container.settings.preferences).then(async (shouldCheck) => {
if (shouldCheck) {
const version = await fetchLatestAstroVersion(restart.container.settings.preferences);
if (gt(version, currentVersion)) {
restart.container.settings.latestAstroVersion = version;
const sameMajor = major(version) === major(currentVersion);
const sameMinor = minor(version) === minor(currentVersion);
const patchDistance = patch(version) - patch(currentVersion);
if (sameMajor && sameMinor && patchDistance < MAX_PATCH_DISTANCE) {
return;
}
logger.warn(
"SKIP_FORMAT",
await msg.newVersionAvailable({
latestVersion: version
})
);
}
}
}).catch(() => {
});
} catch {
}
}
const devServerAddressInfo = await startContainer(restart.container);
logger.info(
"SKIP_FORMAT",
msg.serverStart({
startupTime: performance.now() - devStart,
resolvedUrls: restart.container.viteServer.resolvedUrls || { local: [], network: [] },
host: restart.container.settings.config.server.host,
base: restart.container.settings.config.base
})
);
if (isPrerelease) {
logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
}
if (restart.container.viteServer.config.server?.fs?.strict === false) {
logger.warn("SKIP_FORMAT", msg.fsStrictWarning());
}
await attachContentServerListeners(restart.container);
let store;
try {
const dataStoreFile = getDataStoreFile(restart.container.settings);
if (existsSync(dataStoreFile)) {
store = await MutableDataStore.fromFile(dataStoreFile);
}
} catch (err) {
logger.error("content", err.message);
}
if (!store) {
store = new MutableDataStore();
}
const config = globalContentConfigObserver.get();
if (config.status === "error") {
logger.error("content", config.error.message);
}
if (config.status === "loaded") {
const contentLayer = globalContentLayer.init({
settings: restart.container.settings,
logger,
watcher: restart.container.viteServer.watcher,
store
});
contentLayer.watchContentConfig();
await contentLayer.sync();
}
logger.info(null, green("watching for file changes..."));
return {
address: devServerAddressInfo,
get watcher() {
return restart.container.viteServer.watcher;
},
handle(req, res) {
return restart.container.handle(req, res);
},
async stop() {
await restart.container.close();
}
};
}
export {
dev as default
};

3
node_modules/astro/dist/core/dev/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
export { createContainer, startContainer } from './container.js';
export { default } from './dev.js';
export { createContainerWithAutomaticRestart } from './restart.js';

9
node_modules/astro/dist/core/dev/index.js generated vendored Normal file
View File

@@ -0,0 +1,9 @@
import { createContainer, startContainer } from "./container.js";
import { default as default2 } from "./dev.js";
import { createContainerWithAutomaticRestart } from "./restart.js";
export {
createContainer,
createContainerWithAutomaticRestart,
default2 as default,
startContainer
};

13
node_modules/astro/dist/core/dev/restart.d.ts generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import type nodeFs from 'node:fs';
import type { AstroInlineConfig } from '../../@types/astro.js';
import type { Container } from './container.js';
export interface CreateContainerWithAutomaticRestart {
inlineConfig?: AstroInlineConfig;
fs: typeof nodeFs;
}
interface Restart {
container: Container;
restarted: () => Promise<Error | null>;
}
export declare function createContainerWithAutomaticRestart({ inlineConfig, fs, }: CreateContainerWithAutomaticRestart): Promise<Restart>;
export {};

148
node_modules/astro/dist/core/dev/restart.js generated vendored Normal file
View File

@@ -0,0 +1,148 @@
import { fileURLToPath } from "node:url";
import * as vite from "vite";
import { globalContentLayer } from "../../content/content-layer.js";
import { eventCliSession, telemetry } from "../../events/index.js";
import { createNodeLogger, createSettings, resolveConfig } from "../config/index.js";
import { collectErrorMetadata } from "../errors/dev/utils.js";
import { isAstroConfigZodError } from "../errors/errors.js";
import { createSafeError } from "../errors/index.js";
import { formatErrorMessage } from "../messages.js";
import { createContainer, startContainer } from "./container.js";
async function createRestartedContainer(container, settings) {
const { logger, fs, inlineConfig } = container;
const newContainer = await createContainer({
isRestart: true,
logger,
settings,
inlineConfig,
fs
});
await startContainer(newContainer);
return newContainer;
}
const configRE = /.*astro.config.(?:mjs|mts|cjs|cts|js|ts)$/;
function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, changedFile) {
if (restartInFlight) return false;
let shouldRestart = false;
const normalizedChangedFile = vite.normalizePath(changedFile);
if (inlineConfig.configFile) {
shouldRestart = vite.normalizePath(inlineConfig.configFile) === normalizedChangedFile;
} else {
shouldRestart = configRE.test(normalizedChangedFile);
const settingsPath = vite.normalizePath(
fileURLToPath(new URL("settings.json", settings.dotAstroDir))
);
if (settingsPath.endsWith(normalizedChangedFile)) {
shouldRestart = settings.preferences.ignoreNextPreferenceReload ? false : true;
settings.preferences.ignoreNextPreferenceReload = false;
}
}
if (!shouldRestart && settings.watchFiles.length > 0) {
shouldRestart = settings.watchFiles.some(
(path) => vite.normalizePath(path) === vite.normalizePath(changedFile)
);
}
return shouldRestart;
}
async function restartContainer(container) {
const { logger, close, settings: existingSettings } = container;
container.restartInFlight = true;
try {
const { astroConfig } = await resolveConfig(container.inlineConfig, "dev", container.fs);
const settings = await createSettings(astroConfig, fileURLToPath(existingSettings.config.root));
await close();
return await createRestartedContainer(container, settings);
} catch (_err) {
const error = createSafeError(_err);
if (!isAstroConfigZodError(_err)) {
logger.error(
"config",
formatErrorMessage(collectErrorMetadata(error), logger.level() === "debug") + "\n"
);
}
container.viteServer.hot.send({
type: "error",
err: {
message: error.message,
stack: error.stack || ""
}
});
container.restartInFlight = false;
logger.error(null, "Continuing with previous valid configuration\n");
return error;
}
}
async function createContainerWithAutomaticRestart({
inlineConfig,
fs
}) {
const logger = createNodeLogger(inlineConfig ?? {});
const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "dev", fs);
telemetry.record(eventCliSession("dev", userConfig));
const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
const initialContainer = await createContainer({ settings, logger, inlineConfig, fs });
let resolveRestart;
let restartComplete = new Promise((resolve) => {
resolveRestart = resolve;
});
let restart = {
container: initialContainer,
restarted() {
return restartComplete;
}
};
async function handleServerRestart(logMsg = "") {
logger.info(null, (logMsg + " Restarting...").trim());
const container = restart.container;
const result = await restartContainer(container);
if (result instanceof Error) {
resolveRestart(result);
} else {
restart.container = result;
setupContainer();
resolveRestart(null);
}
restartComplete = new Promise((resolve) => {
resolveRestart = resolve;
});
}
function handleChangeRestart(logMsg) {
return async function(changedFile) {
if (shouldRestartContainer(restart.container, changedFile)) {
handleServerRestart(logMsg);
}
};
}
function setupContainer() {
const watcher = restart.container.viteServer.watcher;
watcher.on("change", handleChangeRestart("Configuration file updated."));
watcher.on("unlink", handleChangeRestart("Configuration file removed."));
watcher.on("add", handleChangeRestart("Configuration file added."));
restart.container.viteServer.restart = async () => {
if (!restart.container.restartInFlight) await handleServerRestart();
};
const customShortcuts = [
// Disable default Vite shortcuts that don't work well with Astro
{ key: "r", description: "" },
{ key: "u", description: "" },
{ key: "c", description: "" }
];
if (restart.container.settings.config.experimental.contentLayer) {
customShortcuts.push({
key: "s",
description: "sync content layer",
action: () => {
globalContentLayer.get()?.sync();
}
});
}
restart.container.viteServer.bindCLIShortcuts({
customShortcuts
});
}
setupContainer();
return restart;
}
export {
createContainerWithAutomaticRestart
};

4
node_modules/astro/dist/core/dev/update-check.d.ts generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import type { AstroPreferences } from '../../preferences/index.js';
export declare const MAX_PATCH_DISTANCE = 5;
export declare function fetchLatestAstroVersion(preferences: AstroPreferences | undefined): Promise<string>;
export declare function shouldCheckForUpdates(preferences: AstroPreferences): Promise<boolean>;

36
node_modules/astro/dist/core/dev/update-check.js generated vendored Normal file
View File

@@ -0,0 +1,36 @@
import ci from "ci-info";
import { fetchPackageJson } from "../../cli/install-package.js";
const MAX_PATCH_DISTANCE = 5;
const CHECK_MS_INTERVAL = 10368e5;
let _latestVersion = void 0;
async function fetchLatestAstroVersion(preferences) {
if (_latestVersion) {
return _latestVersion;
}
const packageJson = await fetchPackageJson(void 0, "astro", "latest");
if (packageJson instanceof Error) {
throw packageJson;
}
const version = packageJson?.version;
if (!version) {
throw new Error("Failed to fetch latest Astro version");
}
if (preferences) {
await preferences.set("_variables.lastUpdateCheck", Date.now(), { reloadServer: false });
}
_latestVersion = version;
return version;
}
async function shouldCheckForUpdates(preferences) {
if (ci.isCI) {
return false;
}
const timeSinceLastCheck = Date.now() - await preferences.get("_variables.lastUpdateCheck");
const hasCheckUpdatesEnabled = await preferences.get("checkUpdates.enabled");
return timeSinceLastCheck > CHECK_MS_INTERVAL && process.env.ASTRO_DISABLE_UPDATE_CHECK !== "true" && hasCheckUpdatesEnabled;
}
export {
MAX_PATCH_DISTANCE,
fetchLatestAstroVersion,
shouldCheckForUpdates
};