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:
2
node_modules/astro/dist/core/logger/console.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/core/logger/console.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
import { type LogMessage, type LogWritable } from './core.js';
|
||||
export declare const consoleLogDestination: LogWritable<LogMessage>;
|
18
node_modules/astro/dist/core/logger/console.js
generated
vendored
Normal file
18
node_modules/astro/dist/core/logger/console.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
import { getEventPrefix, levels } from "./core.js";
|
||||
const consoleLogDestination = {
|
||||
write(event) {
|
||||
let dest = console.error;
|
||||
if (levels[event.level] < levels["error"]) {
|
||||
dest = console.log;
|
||||
}
|
||||
if (event.label === "SKIP_FORMAT") {
|
||||
dest(event.message);
|
||||
} else {
|
||||
dest(getEventPrefix(event) + " " + event.message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
export {
|
||||
consoleLogDestination
|
||||
};
|
63
node_modules/astro/dist/core/logger/core.d.ts
generated
vendored
Normal file
63
node_modules/astro/dist/core/logger/core.d.ts
generated
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
export interface LogWritable<T> {
|
||||
write: (chunk: T) => boolean;
|
||||
}
|
||||
export type LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
||||
/**
|
||||
* Defined logger labels. Add more as needed, but keep them high-level & reusable,
|
||||
* rather than specific to a single command, function, use, etc. The label will be
|
||||
* shown in the log message to the user, so it should be relevant.
|
||||
*/
|
||||
export type LoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'crypto' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'sync' | 'toolbar' | 'assets' | 'env' | 'update' | 'SKIP_FORMAT';
|
||||
export interface LogOptions {
|
||||
dest: LogWritable<LogMessage>;
|
||||
level: LoggerLevel;
|
||||
}
|
||||
export declare const dateTimeFormat: Intl.DateTimeFormat;
|
||||
export interface LogMessage {
|
||||
label: string | null;
|
||||
level: LoggerLevel;
|
||||
message: string;
|
||||
newLine: boolean;
|
||||
}
|
||||
export declare const levels: Record<LoggerLevel, number>;
|
||||
/** Full logging API */
|
||||
export declare function log(opts: LogOptions, level: LoggerLevel, label: string | null, message: string, newLine?: boolean): void;
|
||||
export declare function isLogLevelEnabled(configuredLogLevel: LoggerLevel, level: LoggerLevel): boolean;
|
||||
/** Emit a user-facing message. Useful for UI and other console messages. */
|
||||
export declare function info(opts: LogOptions, label: string | null, message: string, newLine?: boolean): void;
|
||||
/** Emit a warning message. Useful for high-priority messages that aren't necessarily errors. */
|
||||
export declare function warn(opts: LogOptions, label: string | null, message: string, newLine?: boolean): void;
|
||||
/** Emit a error message, Useful when Astro can't recover from some error. */
|
||||
export declare function error(opts: LogOptions, label: string | null, message: string, newLine?: boolean): void;
|
||||
export declare function debug(...args: any[]): void;
|
||||
/**
|
||||
* Get the prefix for a log message.
|
||||
* This includes the timestamp, log level, and label all properly formatted
|
||||
* with colors. This is shared across different loggers, so it's defined here.
|
||||
*/
|
||||
export declare function getEventPrefix({ level, label }: LogMessage): string;
|
||||
/** Print out a timer message for debug() */
|
||||
export declare function timerMessage(message: string, startTime?: number): string;
|
||||
export declare class Logger {
|
||||
options: LogOptions;
|
||||
constructor(options: LogOptions);
|
||||
info(label: LoggerLabel | null, message: string, newLine?: boolean): void;
|
||||
warn(label: LoggerLabel | null, message: string, newLine?: boolean): void;
|
||||
error(label: LoggerLabel | null, message: string, newLine?: boolean): void;
|
||||
debug(label: LoggerLabel, ...messages: any[]): void;
|
||||
level(): LoggerLevel;
|
||||
forkIntegrationLogger(label: string): AstroIntegrationLogger;
|
||||
}
|
||||
export declare class AstroIntegrationLogger {
|
||||
options: LogOptions;
|
||||
label: string;
|
||||
constructor(logging: LogOptions, label: string);
|
||||
/**
|
||||
* Creates a new logger instance with a new label, but the same log options.
|
||||
*/
|
||||
fork(label: string): AstroIntegrationLogger;
|
||||
info(message: string): void;
|
||||
warn(message: string): void;
|
||||
error(message: string): void;
|
||||
debug(message: string): void;
|
||||
}
|
137
node_modules/astro/dist/core/logger/core.js
generated
vendored
Normal file
137
node_modules/astro/dist/core/logger/core.js
generated
vendored
Normal file
@@ -0,0 +1,137 @@
|
||||
import { blue, bold, dim, red, yellow } from "kleur/colors";
|
||||
const dateTimeFormat = new Intl.DateTimeFormat([], {
|
||||
hour: "2-digit",
|
||||
minute: "2-digit",
|
||||
second: "2-digit",
|
||||
hour12: false
|
||||
});
|
||||
const levels = {
|
||||
debug: 20,
|
||||
info: 30,
|
||||
warn: 40,
|
||||
error: 50,
|
||||
silent: 90
|
||||
};
|
||||
function log(opts, level, label, message, newLine = true) {
|
||||
const logLevel = opts.level;
|
||||
const dest = opts.dest;
|
||||
const event = {
|
||||
label,
|
||||
level,
|
||||
message,
|
||||
newLine
|
||||
};
|
||||
if (!isLogLevelEnabled(logLevel, level)) {
|
||||
return;
|
||||
}
|
||||
dest.write(event);
|
||||
}
|
||||
function isLogLevelEnabled(configuredLogLevel, level) {
|
||||
return levels[configuredLogLevel] <= levels[level];
|
||||
}
|
||||
function info(opts, label, message, newLine = true) {
|
||||
return log(opts, "info", label, message, newLine);
|
||||
}
|
||||
function warn(opts, label, message, newLine = true) {
|
||||
return log(opts, "warn", label, message, newLine);
|
||||
}
|
||||
function error(opts, label, message, newLine = true) {
|
||||
return log(opts, "error", label, message, newLine);
|
||||
}
|
||||
function debug(...args) {
|
||||
if ("_astroGlobalDebug" in globalThis) {
|
||||
globalThis._astroGlobalDebug(...args);
|
||||
}
|
||||
}
|
||||
function getEventPrefix({ level, label }) {
|
||||
const timestamp = `${dateTimeFormat.format(/* @__PURE__ */ new Date())}`;
|
||||
const prefix = [];
|
||||
if (level === "error" || level === "warn") {
|
||||
prefix.push(bold(timestamp));
|
||||
prefix.push(`[${level.toUpperCase()}]`);
|
||||
} else {
|
||||
prefix.push(timestamp);
|
||||
}
|
||||
if (label) {
|
||||
prefix.push(`[${label}]`);
|
||||
}
|
||||
if (level === "error") {
|
||||
return red(prefix.join(" "));
|
||||
}
|
||||
if (level === "warn") {
|
||||
return yellow(prefix.join(" "));
|
||||
}
|
||||
if (prefix.length === 1) {
|
||||
return dim(prefix[0]);
|
||||
}
|
||||
return dim(prefix[0]) + " " + blue(prefix.splice(1).join(" "));
|
||||
}
|
||||
function timerMessage(message, startTime = Date.now()) {
|
||||
let timeDiff = Date.now() - startTime;
|
||||
let timeDisplay = timeDiff < 750 ? `${Math.round(timeDiff)}ms` : `${(timeDiff / 1e3).toFixed(1)}s`;
|
||||
return `${message} ${dim(timeDisplay)}`;
|
||||
}
|
||||
class Logger {
|
||||
options;
|
||||
constructor(options) {
|
||||
this.options = options;
|
||||
}
|
||||
info(label, message, newLine = true) {
|
||||
info(this.options, label, message, newLine);
|
||||
}
|
||||
warn(label, message, newLine = true) {
|
||||
warn(this.options, label, message, newLine);
|
||||
}
|
||||
error(label, message, newLine = true) {
|
||||
error(this.options, label, message, newLine);
|
||||
}
|
||||
debug(label, ...messages) {
|
||||
debug(label, ...messages);
|
||||
}
|
||||
level() {
|
||||
return this.options.level;
|
||||
}
|
||||
forkIntegrationLogger(label) {
|
||||
return new AstroIntegrationLogger(this.options, label);
|
||||
}
|
||||
}
|
||||
class AstroIntegrationLogger {
|
||||
options;
|
||||
label;
|
||||
constructor(logging, label) {
|
||||
this.options = logging;
|
||||
this.label = label;
|
||||
}
|
||||
/**
|
||||
* Creates a new logger instance with a new label, but the same log options.
|
||||
*/
|
||||
fork(label) {
|
||||
return new AstroIntegrationLogger(this.options, label);
|
||||
}
|
||||
info(message) {
|
||||
info(this.options, this.label, message);
|
||||
}
|
||||
warn(message) {
|
||||
warn(this.options, this.label, message);
|
||||
}
|
||||
error(message) {
|
||||
error(this.options, this.label, message);
|
||||
}
|
||||
debug(message) {
|
||||
debug(this.label, message);
|
||||
}
|
||||
}
|
||||
export {
|
||||
AstroIntegrationLogger,
|
||||
Logger,
|
||||
dateTimeFormat,
|
||||
debug,
|
||||
error,
|
||||
getEventPrefix,
|
||||
info,
|
||||
isLogLevelEnabled,
|
||||
levels,
|
||||
log,
|
||||
timerMessage,
|
||||
warn
|
||||
};
|
3
node_modules/astro/dist/core/logger/node.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/core/logger/node.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import { type LogMessage, type LogWritable } from './core.js';
|
||||
export declare const nodeLogDestination: LogWritable<LogMessage>;
|
||||
export declare function enableVerboseLogging(): void;
|
36
node_modules/astro/dist/core/logger/node.js
generated
vendored
Normal file
36
node_modules/astro/dist/core/logger/node.js
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import debugPackage from "debug";
|
||||
import { getEventPrefix, levels } from "./core.js";
|
||||
const nodeLogDestination = {
|
||||
write(event) {
|
||||
let dest = process.stderr;
|
||||
if (levels[event.level] < levels["error"]) {
|
||||
dest = process.stdout;
|
||||
}
|
||||
let trailingLine = event.newLine ? "\n" : "";
|
||||
if (event.label === "SKIP_FORMAT") {
|
||||
dest.write(event.message + trailingLine);
|
||||
} else {
|
||||
dest.write(getEventPrefix(event) + " " + event.message + trailingLine);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
const debuggers = {};
|
||||
function debug(type, ...messages) {
|
||||
const namespace = `astro:${type}`;
|
||||
debuggers[namespace] = debuggers[namespace] || debugPackage(namespace);
|
||||
return debuggers[namespace](...messages);
|
||||
}
|
||||
globalThis._astroGlobalDebug = debug;
|
||||
function enableVerboseLogging() {
|
||||
debugPackage.enable("astro:*,vite:*");
|
||||
debug("cli", '--verbose flag enabled! Enabling: DEBUG="astro:*,vite:*"');
|
||||
debug(
|
||||
"cli",
|
||||
'Tip: Set the DEBUG env variable directly for more control. Example: "DEBUG=astro:*,vite:* astro build".'
|
||||
);
|
||||
}
|
||||
export {
|
||||
enableVerboseLogging,
|
||||
nodeLogDestination
|
||||
};
|
3
node_modules/astro/dist/core/logger/vite.d.ts
generated
vendored
Normal file
3
node_modules/astro/dist/core/logger/vite.d.ts
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
import type { LogLevel, Logger as ViteLogger } from 'vite';
|
||||
import { type Logger as AstroLogger } from './core.js';
|
||||
export declare function createViteLogger(astroLogger: AstroLogger, viteLogLevel?: LogLevel): ViteLogger;
|
74
node_modules/astro/dist/core/logger/vite.js
generated
vendored
Normal file
74
node_modules/astro/dist/core/logger/vite.js
generated
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { stripVTControlCharacters } from "node:util";
|
||||
import { isAstroError } from "../errors/errors.js";
|
||||
import { serverShortcuts as formatServerShortcuts } from "../messages.js";
|
||||
import { isLogLevelEnabled } from "./core.js";
|
||||
const PKG_PREFIX = fileURLToPath(new URL("../../../", import.meta.url));
|
||||
const E2E_PREFIX = fileURLToPath(new URL("../../../e2e", import.meta.url));
|
||||
function isAstroSrcFile(id) {
|
||||
return id?.startsWith(PKG_PREFIX) && !id.startsWith(E2E_PREFIX);
|
||||
}
|
||||
const vitePageReloadMsg = /page reload (.*)/;
|
||||
const viteHmrUpdateMsg = /hmr update (.*)/;
|
||||
const viteBuildMsg = /vite.*building.*for production/;
|
||||
const viteShortcutTitleMsg = /^\s*Shortcuts\s*$/;
|
||||
const viteShortcutHelpMsg = /press (.+?) to (.+)$/s;
|
||||
function createViteLogger(astroLogger, viteLogLevel = "info") {
|
||||
const warnedMessages = /* @__PURE__ */ new Set();
|
||||
const loggedErrors = /* @__PURE__ */ new WeakSet();
|
||||
const logger = {
|
||||
hasWarned: false,
|
||||
info(msg) {
|
||||
if (!isLogLevelEnabled(viteLogLevel, "info")) return;
|
||||
const stripped = stripVTControlCharacters(msg);
|
||||
let m;
|
||||
if (m = vitePageReloadMsg.exec(stripped)) {
|
||||
if (isAstroSrcFile(m[1])) return;
|
||||
astroLogger.info("watch", m[1]);
|
||||
} else if (m = viteHmrUpdateMsg.exec(stripped)) {
|
||||
if (isAstroSrcFile(m[1])) return;
|
||||
astroLogger.info("watch", m[1]);
|
||||
} else if (viteBuildMsg.test(stripped) || viteShortcutTitleMsg.test(stripped)) {
|
||||
} else if (viteShortcutHelpMsg.test(stripped)) {
|
||||
const [, key, label] = viteShortcutHelpMsg.exec(stripped);
|
||||
astroLogger.info("SKIP_FORMAT", formatServerShortcuts({ key, label }));
|
||||
} else {
|
||||
astroLogger.info("vite", msg);
|
||||
}
|
||||
},
|
||||
warn(msg) {
|
||||
if (!isLogLevelEnabled(viteLogLevel, "warn")) return;
|
||||
logger.hasWarned = true;
|
||||
astroLogger.warn("vite", msg);
|
||||
},
|
||||
warnOnce(msg) {
|
||||
if (!isLogLevelEnabled(viteLogLevel, "warn")) return;
|
||||
if (warnedMessages.has(msg)) return;
|
||||
logger.hasWarned = true;
|
||||
astroLogger.warn("vite", msg);
|
||||
warnedMessages.add(msg);
|
||||
},
|
||||
error(msg, opts) {
|
||||
if (!isLogLevelEnabled(viteLogLevel, "error")) return;
|
||||
logger.hasWarned = true;
|
||||
const err = opts?.error;
|
||||
if (err) loggedErrors.add(err);
|
||||
if (err && isAstroError(err)) return;
|
||||
if (msg.includes("Error when evaluating SSR module") || msg.includes("Pre-transform error:")) {
|
||||
astroLogger.debug("vite", msg);
|
||||
return;
|
||||
}
|
||||
astroLogger.error("vite", msg);
|
||||
},
|
||||
// Don't allow clear screen
|
||||
clearScreen: () => {
|
||||
},
|
||||
hasErrorLogged(error) {
|
||||
return loggedErrors.has(error);
|
||||
}
|
||||
};
|
||||
return logger;
|
||||
}
|
||||
export {
|
||||
createViteLogger
|
||||
};
|
Reference in New Issue
Block a user