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:
16
node_modules/astro/dist/preferences/defaults.d.ts
generated
vendored
Normal file
16
node_modules/astro/dist/preferences/defaults.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
export declare const DEFAULT_PREFERENCES: {
|
||||
devToolbar: {
|
||||
/** Specifies whether the user has the Dev Overlay enabled */
|
||||
enabled: boolean;
|
||||
};
|
||||
checkUpdates: {
|
||||
/** Specifies whether the user has the update check enabled */
|
||||
enabled: boolean;
|
||||
};
|
||||
_variables: {
|
||||
/** Time since last update check */
|
||||
lastUpdateCheck: number;
|
||||
};
|
||||
};
|
||||
export type Preferences = typeof DEFAULT_PREFERENCES;
|
||||
export type PublicPreferences = Omit<Preferences, '_variables'>;
|
18
node_modules/astro/dist/preferences/defaults.js
generated
vendored
Normal file
18
node_modules/astro/dist/preferences/defaults.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
const DEFAULT_PREFERENCES = {
|
||||
devToolbar: {
|
||||
/** Specifies whether the user has the Dev Overlay enabled */
|
||||
enabled: true
|
||||
},
|
||||
checkUpdates: {
|
||||
/** Specifies whether the user has the update check enabled */
|
||||
enabled: true
|
||||
},
|
||||
// Temporary variables that shouldn't be exposed to the users in the CLI, but are still useful to store in preferences
|
||||
_variables: {
|
||||
/** Time since last update check */
|
||||
lastUpdateCheck: 0
|
||||
}
|
||||
};
|
||||
export {
|
||||
DEFAULT_PREFERENCES
|
||||
};
|
36
node_modules/astro/dist/preferences/index.d.ts
generated
vendored
Normal file
36
node_modules/astro/dist/preferences/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { AstroConfig } from '../@types/astro.js';
|
||||
import { type Preferences, type PublicPreferences } from './defaults.js';
|
||||
type DotKeys<T> = T extends object ? {
|
||||
[K in keyof T]: `${Exclude<K, symbol>}${DotKeys<T[K]> extends never ? '' : `.${DotKeys<T[K]>}`}`;
|
||||
}[keyof T] : never;
|
||||
export type GetDotKey<T extends Record<string | number, any>, K extends string> = K extends `${infer U}.${infer Rest}` ? GetDotKey<T[U], Rest> : T[K];
|
||||
export type PreferenceLocation = 'global' | 'project';
|
||||
export interface PreferenceOptions {
|
||||
location?: PreferenceLocation;
|
||||
/**
|
||||
* If `true`, the server will be reloaded after setting the preference.
|
||||
* If `false`, the server will not be reloaded after setting the preference.
|
||||
*
|
||||
* Defaults to `true`.
|
||||
*/
|
||||
reloadServer?: boolean;
|
||||
}
|
||||
type DeepPartial<T> = T extends object ? {
|
||||
[P in keyof T]?: DeepPartial<T[P]>;
|
||||
} : T;
|
||||
export type PreferenceKey = DotKeys<Preferences>;
|
||||
export interface PreferenceList extends Record<PreferenceLocation, DeepPartial<PublicPreferences>> {
|
||||
fromAstroConfig: DeepPartial<Preferences>;
|
||||
defaults: PublicPreferences;
|
||||
}
|
||||
export interface AstroPreferences {
|
||||
get<Key extends PreferenceKey>(key: Key, opts?: PreferenceOptions): Promise<GetDotKey<Preferences, Key>>;
|
||||
set<Key extends PreferenceKey>(key: Key, value: GetDotKey<Preferences, Key>, opts?: PreferenceOptions): Promise<void>;
|
||||
getAll(): Promise<PublicPreferences>;
|
||||
list(opts?: PreferenceOptions): Promise<PreferenceList>;
|
||||
ignoreNextPreferenceReload: boolean;
|
||||
}
|
||||
export declare function isValidKey(key: string): key is PreferenceKey;
|
||||
export declare function coerce(key: string, value: unknown): any;
|
||||
export default function createPreferences(config: AstroConfig, dotAstroDir: URL): AstroPreferences;
|
||||
export {};
|
95
node_modules/astro/dist/preferences/index.js
generated
vendored
Normal file
95
node_modules/astro/dist/preferences/index.js
generated
vendored
Normal file
@@ -0,0 +1,95 @@
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import process from "node:process";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import dget from "dlv";
|
||||
import { DEFAULT_PREFERENCES } from "./defaults.js";
|
||||
import { PreferenceStore } from "./store.js";
|
||||
function isValidKey(key) {
|
||||
return dget(DEFAULT_PREFERENCES, key) !== void 0;
|
||||
}
|
||||
function coerce(key, value) {
|
||||
const type = typeof dget(DEFAULT_PREFERENCES, key);
|
||||
switch (type) {
|
||||
case "string":
|
||||
return value;
|
||||
case "number":
|
||||
return Number(value);
|
||||
case "boolean": {
|
||||
if (value === "true" || value === 1) return true;
|
||||
if (value === "false" || value === 0) return false;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new Error(`Incorrect value for ${key}`);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
function createPreferences(config, dotAstroDir) {
|
||||
const global = new PreferenceStore(getGlobalPreferenceDir());
|
||||
const project = new PreferenceStore(fileURLToPath(dotAstroDir));
|
||||
const stores = { global, project };
|
||||
return {
|
||||
async get(key, { location } = {}) {
|
||||
if (!location) return project.get(key) ?? global.get(key) ?? dget(DEFAULT_PREFERENCES, key);
|
||||
return stores[location].get(key);
|
||||
},
|
||||
async set(key, value, { location = "project", reloadServer = true } = {}) {
|
||||
stores[location].set(key, value);
|
||||
if (!reloadServer) {
|
||||
this.ignoreNextPreferenceReload = true;
|
||||
}
|
||||
},
|
||||
async getAll() {
|
||||
const allPrefs = Object.assign(
|
||||
{},
|
||||
DEFAULT_PREFERENCES,
|
||||
stores["global"].getAll(),
|
||||
stores["project"].getAll()
|
||||
);
|
||||
const { _variables, ...prefs } = allPrefs;
|
||||
return prefs;
|
||||
},
|
||||
async list() {
|
||||
const { _variables, ...defaultPrefs } = DEFAULT_PREFERENCES;
|
||||
return {
|
||||
global: stores["global"].getAll(),
|
||||
project: stores["project"].getAll(),
|
||||
fromAstroConfig: mapFrom(DEFAULT_PREFERENCES, config),
|
||||
defaults: defaultPrefs
|
||||
};
|
||||
function mapFrom(defaults, astroConfig) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(defaults).map(([key, _]) => [key, astroConfig[key]])
|
||||
);
|
||||
}
|
||||
},
|
||||
ignoreNextPreferenceReload: false
|
||||
};
|
||||
}
|
||||
function getGlobalPreferenceDir() {
|
||||
const name = "astro";
|
||||
const homedir = os.homedir();
|
||||
const macos = () => path.join(homedir, "Library", "Preferences", name);
|
||||
const win = () => {
|
||||
const { APPDATA = path.join(homedir, "AppData", "Roaming") } = process.env;
|
||||
return path.join(APPDATA, name, "Config");
|
||||
};
|
||||
const linux = () => {
|
||||
const { XDG_CONFIG_HOME = path.join(homedir, ".config") } = process.env;
|
||||
return path.join(XDG_CONFIG_HOME, name);
|
||||
};
|
||||
switch (process.platform) {
|
||||
case "darwin":
|
||||
return macos();
|
||||
case "win32":
|
||||
return win();
|
||||
default:
|
||||
return linux();
|
||||
}
|
||||
}
|
||||
export {
|
||||
coerce,
|
||||
createPreferences as default,
|
||||
isValidKey
|
||||
};
|
15
node_modules/astro/dist/preferences/store.d.ts
generated
vendored
Normal file
15
node_modules/astro/dist/preferences/store.d.ts
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
export declare class PreferenceStore {
|
||||
private dir;
|
||||
private file;
|
||||
constructor(dir: string, filename?: string);
|
||||
private _store?;
|
||||
private get store();
|
||||
private set store(value);
|
||||
write(): void;
|
||||
clear(): void;
|
||||
delete(key: string): boolean;
|
||||
get(key: string): any;
|
||||
has(key: string): boolean;
|
||||
set(key: string, value: any): void;
|
||||
getAll(): Record<string, any>;
|
||||
}
|
61
node_modules/astro/dist/preferences/store.js
generated
vendored
Normal file
61
node_modules/astro/dist/preferences/store.js
generated
vendored
Normal file
@@ -0,0 +1,61 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import dget from "dlv";
|
||||
import { dset } from "dset";
|
||||
class PreferenceStore {
|
||||
constructor(dir, filename = "settings.json") {
|
||||
this.dir = dir;
|
||||
this.file = path.join(this.dir, filename);
|
||||
}
|
||||
file;
|
||||
_store;
|
||||
get store() {
|
||||
if (this._store) return this._store;
|
||||
if (fs.existsSync(this.file)) {
|
||||
try {
|
||||
this._store = JSON.parse(fs.readFileSync(this.file).toString());
|
||||
} catch {
|
||||
}
|
||||
}
|
||||
if (!this._store) {
|
||||
this._store = {};
|
||||
this.write();
|
||||
}
|
||||
return this._store;
|
||||
}
|
||||
set store(value) {
|
||||
this._store = value;
|
||||
this.write();
|
||||
}
|
||||
write() {
|
||||
if (!this._store || Object.keys(this._store).length === 0) return;
|
||||
fs.mkdirSync(this.dir, { recursive: true });
|
||||
fs.writeFileSync(this.file, JSON.stringify(this.store, null, " "));
|
||||
}
|
||||
clear() {
|
||||
this.store = {};
|
||||
fs.rmSync(this.file, { recursive: true });
|
||||
}
|
||||
delete(key) {
|
||||
dset(this.store, key, void 0);
|
||||
this.write();
|
||||
return true;
|
||||
}
|
||||
get(key) {
|
||||
return dget(this.store, key);
|
||||
}
|
||||
has(key) {
|
||||
return typeof this.get(key) !== "undefined";
|
||||
}
|
||||
set(key, value) {
|
||||
if (this.get(key) === value) return;
|
||||
dset(this.store, key, value);
|
||||
this.write();
|
||||
}
|
||||
getAll() {
|
||||
return this.store;
|
||||
}
|
||||
}
|
||||
export {
|
||||
PreferenceStore
|
||||
};
|
Reference in New Issue
Block a user