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/core/compile/compile.d.ts
generated
vendored
Normal file
16
node_modules/astro/dist/core/compile/compile.d.ts
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import type { TransformResult } from '@astrojs/compiler';
|
||||
import type { ResolvedConfig } from 'vite';
|
||||
import type { AstroConfig } from '../../@types/astro.js';
|
||||
import type { AstroPreferences } from '../../preferences/index.js';
|
||||
import type { CompileCssResult } from './types.js';
|
||||
export interface CompileProps {
|
||||
astroConfig: AstroConfig;
|
||||
viteConfig: ResolvedConfig;
|
||||
preferences: AstroPreferences;
|
||||
filename: string;
|
||||
source: string;
|
||||
}
|
||||
export interface CompileResult extends Omit<TransformResult, 'css'> {
|
||||
css: CompileCssResult[];
|
||||
}
|
||||
export declare function compile({ astroConfig, viteConfig, preferences, filename, source, }: CompileProps): Promise<CompileResult>;
|
101
node_modules/astro/dist/core/compile/compile.js
generated
vendored
Normal file
101
node_modules/astro/dist/core/compile/compile.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { transform } from "@astrojs/compiler";
|
||||
import { normalizePath } from "vite";
|
||||
import { AggregateError, CompilerError } from "../errors/errors.js";
|
||||
import { AstroErrorData } from "../errors/index.js";
|
||||
import { resolvePath } from "../viteUtils.js";
|
||||
import { createStylePreprocessor } from "./style.js";
|
||||
async function compile({
|
||||
astroConfig,
|
||||
viteConfig,
|
||||
preferences,
|
||||
filename,
|
||||
source
|
||||
}) {
|
||||
const cssPartialCompileResults = [];
|
||||
const cssTransformErrors = [];
|
||||
let transformResult;
|
||||
try {
|
||||
transformResult = await transform(source, {
|
||||
compact: astroConfig.compressHTML,
|
||||
filename,
|
||||
normalizedFilename: normalizeFilename(filename, astroConfig.root),
|
||||
sourcemap: "both",
|
||||
internalURL: "astro/compiler-runtime",
|
||||
// TODO: this is no longer necessary for `Astro.site`
|
||||
// but it somehow allows working around caching issues in content collections for some tests
|
||||
astroGlobalArgs: JSON.stringify(astroConfig.site),
|
||||
scopedStyleStrategy: astroConfig.scopedStyleStrategy,
|
||||
resultScopedSlot: true,
|
||||
transitionsAnimationURL: "astro/components/viewtransitions.css",
|
||||
annotateSourceFile: viteConfig.command === "serve" && astroConfig.devToolbar && astroConfig.devToolbar.enabled && await preferences.get("devToolbar.enabled"),
|
||||
renderScript: astroConfig.experimental.directRenderScript,
|
||||
preprocessStyle: createStylePreprocessor({
|
||||
filename,
|
||||
viteConfig,
|
||||
cssPartialCompileResults,
|
||||
cssTransformErrors
|
||||
}),
|
||||
async resolvePath(specifier) {
|
||||
return resolvePath(specifier, filename);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
throw new CompilerError({
|
||||
...AstroErrorData.UnknownCompilerError,
|
||||
message: err.message ?? "Unknown compiler error",
|
||||
stack: err.stack,
|
||||
location: {
|
||||
file: filename
|
||||
}
|
||||
});
|
||||
}
|
||||
handleCompileResultErrors(transformResult, cssTransformErrors);
|
||||
return {
|
||||
...transformResult,
|
||||
css: transformResult.css.map((code, i) => ({
|
||||
...cssPartialCompileResults[i],
|
||||
code
|
||||
}))
|
||||
};
|
||||
}
|
||||
function handleCompileResultErrors(result, cssTransformErrors) {
|
||||
const compilerError = result.diagnostics.find((diag) => diag.severity === 1);
|
||||
if (compilerError) {
|
||||
throw new CompilerError({
|
||||
name: "CompilerError",
|
||||
message: compilerError.text,
|
||||
location: {
|
||||
line: compilerError.location.line,
|
||||
column: compilerError.location.column,
|
||||
file: compilerError.location.file
|
||||
},
|
||||
hint: compilerError.hint
|
||||
});
|
||||
}
|
||||
switch (cssTransformErrors.length) {
|
||||
case 0:
|
||||
break;
|
||||
case 1: {
|
||||
throw cssTransformErrors[0];
|
||||
}
|
||||
default: {
|
||||
throw new AggregateError({
|
||||
...cssTransformErrors[0],
|
||||
errors: cssTransformErrors
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
function normalizeFilename(filename, root) {
|
||||
const normalizedFilename = normalizePath(filename);
|
||||
const normalizedRoot = normalizePath(fileURLToPath(root));
|
||||
if (normalizedFilename.startsWith(normalizedRoot)) {
|
||||
return normalizedFilename.slice(normalizedRoot.length - 1);
|
||||
} else {
|
||||
return normalizedFilename;
|
||||
}
|
||||
}
|
||||
export {
|
||||
compile
|
||||
};
|
2
node_modules/astro/dist/core/compile/index.d.ts
generated
vendored
Normal file
2
node_modules/astro/dist/core/compile/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
export { compile } from './compile.js';
|
||||
export type { CompileProps, CompileResult } from './compile.js';
|
4
node_modules/astro/dist/core/compile/index.js
generated
vendored
Normal file
4
node_modules/astro/dist/core/compile/index.js
generated
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
import { compile } from "./compile.js";
|
||||
export {
|
||||
compile
|
||||
};
|
10
node_modules/astro/dist/core/compile/style.d.ts
generated
vendored
Normal file
10
node_modules/astro/dist/core/compile/style.d.ts
generated
vendored
Normal file
@@ -0,0 +1,10 @@
|
||||
import type { TransformOptions } from '@astrojs/compiler';
|
||||
import { type ResolvedConfig } from 'vite';
|
||||
import type { CompileCssResult } from './types.js';
|
||||
export type PartialCompileCssResult = Pick<CompileCssResult, 'isGlobal' | 'dependencies'>;
|
||||
export declare function createStylePreprocessor({ filename, viteConfig, cssPartialCompileResults, cssTransformErrors, }: {
|
||||
filename: string;
|
||||
viteConfig: ResolvedConfig;
|
||||
cssPartialCompileResults: Partial<CompileCssResult>[];
|
||||
cssTransformErrors: Error[];
|
||||
}): TransformOptions['preprocessStyle'];
|
86
node_modules/astro/dist/core/compile/style.js
generated
vendored
Normal file
86
node_modules/astro/dist/core/compile/style.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
import fs from "node:fs";
|
||||
import { normalizePath, preprocessCSS } from "vite";
|
||||
import { AstroErrorData, CSSError, positionAt } from "../errors/index.js";
|
||||
function createStylePreprocessor({
|
||||
filename,
|
||||
viteConfig,
|
||||
cssPartialCompileResults,
|
||||
cssTransformErrors
|
||||
}) {
|
||||
let processedStylesCount = 0;
|
||||
return async (content, attrs) => {
|
||||
const index = processedStylesCount++;
|
||||
const lang = `.${attrs?.lang || "css"}`.toLowerCase();
|
||||
const id = `${filename}?astro&type=style&index=${index}&lang${lang}`;
|
||||
try {
|
||||
const result = await preprocessCSS(content, id, viteConfig);
|
||||
cssPartialCompileResults[index] = {
|
||||
isGlobal: !!attrs["is:global"],
|
||||
dependencies: result.deps ? [...result.deps].map((dep) => normalizePath(dep)) : []
|
||||
};
|
||||
let map;
|
||||
if (result.map) {
|
||||
if (typeof result.map === "string") {
|
||||
map = result.map;
|
||||
} else if (result.map.mappings) {
|
||||
map = result.map.toString();
|
||||
}
|
||||
}
|
||||
return { code: result.code, map };
|
||||
} catch (err) {
|
||||
try {
|
||||
err = enhanceCSSError(err, filename, content);
|
||||
} catch {
|
||||
}
|
||||
cssTransformErrors.push(err);
|
||||
return { error: err + "" };
|
||||
}
|
||||
};
|
||||
}
|
||||
function enhanceCSSError(err, filename, cssContent) {
|
||||
const fileContent = fs.readFileSync(filename).toString();
|
||||
const styleTagBeginning = fileContent.indexOf(cssContent);
|
||||
if (err.name === "CssSyntaxError") {
|
||||
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
||||
return new CSSError({
|
||||
...AstroErrorData.CSSSyntaxError,
|
||||
message: err.reason,
|
||||
location: {
|
||||
file: filename,
|
||||
line: errorLine,
|
||||
column: err.column
|
||||
},
|
||||
stack: err.stack
|
||||
});
|
||||
}
|
||||
if (err.line && err.column) {
|
||||
const errorLine = positionAt(styleTagBeginning, fileContent).line + (err.line ?? 0);
|
||||
return new CSSError({
|
||||
...AstroErrorData.UnknownCSSError,
|
||||
message: err.message,
|
||||
location: {
|
||||
file: filename,
|
||||
line: errorLine,
|
||||
column: err.column
|
||||
},
|
||||
frame: err.frame,
|
||||
stack: err.stack
|
||||
});
|
||||
}
|
||||
const errorPosition = positionAt(styleTagBeginning, fileContent);
|
||||
errorPosition.line += 1;
|
||||
return new CSSError({
|
||||
name: "CSSError",
|
||||
message: err.message,
|
||||
location: {
|
||||
file: filename,
|
||||
line: errorPosition.line,
|
||||
column: 0
|
||||
},
|
||||
frame: err.frame,
|
||||
stack: err.stack
|
||||
});
|
||||
}
|
||||
export {
|
||||
createStylePreprocessor
|
||||
};
|
11
node_modules/astro/dist/core/compile/types.d.ts
generated
vendored
Normal file
11
node_modules/astro/dist/core/compile/types.d.ts
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
export interface CompileCssResult {
|
||||
code: string;
|
||||
/**
|
||||
* Whether this is `<style is:global>`
|
||||
*/
|
||||
isGlobal: boolean;
|
||||
/**
|
||||
* The dependencies of the transformed CSS (Normalized/forward-slash-only absolute paths)
|
||||
*/
|
||||
dependencies: string[];
|
||||
}
|
0
node_modules/astro/dist/core/compile/types.js
generated
vendored
Normal file
0
node_modules/astro/dist/core/compile/types.js
generated
vendored
Normal file
Reference in New Issue
Block a user