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:
5
node_modules/astro/dist/vite-plugin-mdx/index.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/vite-plugin-mdx/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import { type Plugin } from 'vite';
|
||||
/**
|
||||
* @deprecated This plugin is no longer used. Remove in Astro 5.0
|
||||
*/
|
||||
export default function mdxVitePlugin(): Plugin;
|
40
node_modules/astro/dist/vite-plugin-mdx/index.js
generated
vendored
Normal file
40
node_modules/astro/dist/vite-plugin-mdx/index.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { transformWithEsbuild } from "vite";
|
||||
import { CONTENT_FLAG, PROPAGATED_ASSET_FLAG } from "../content/index.js";
|
||||
import { astroEntryPrefix } from "../core/build/plugins/plugin-component-entry.js";
|
||||
import { removeQueryString } from "../core/path.js";
|
||||
import { transformJSX } from "./transform-jsx.js";
|
||||
const SPECIAL_QUERY_REGEX = new RegExp(
|
||||
`[?&](?:worker|sharedworker|raw|url|${CONTENT_FLAG}|${PROPAGATED_ASSET_FLAG})\\b`
|
||||
);
|
||||
function mdxVitePlugin() {
|
||||
return {
|
||||
name: "astro:jsx",
|
||||
enforce: "pre",
|
||||
// run transforms before other plugins
|
||||
async transform(code, id, opts) {
|
||||
if (SPECIAL_QUERY_REGEX.test(id) || id.startsWith(astroEntryPrefix)) {
|
||||
return null;
|
||||
}
|
||||
id = removeQueryString(id);
|
||||
if (!id.endsWith(".mdx")) {
|
||||
return null;
|
||||
}
|
||||
const { code: jsxCode } = await transformWithEsbuild(code, id, {
|
||||
loader: "jsx",
|
||||
jsx: "preserve",
|
||||
sourcemap: "inline",
|
||||
tsconfigRaw: {
|
||||
compilerOptions: {
|
||||
// Ensure client:only imports are treeshaken
|
||||
verbatimModuleSyntax: false,
|
||||
importsNotUsedAsValues: "remove"
|
||||
}
|
||||
}
|
||||
});
|
||||
return await transformJSX(jsxCode, id, opts?.ssr);
|
||||
}
|
||||
};
|
||||
}
|
||||
export {
|
||||
mdxVitePlugin as default
|
||||
};
|
12
node_modules/astro/dist/vite-plugin-mdx/tag.d.ts
generated
vendored
Normal file
12
node_modules/astro/dist/vite-plugin-mdx/tag.d.ts
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
import type { PluginObj } from '@babel/core';
|
||||
/**
|
||||
* This plugin handles every file that runs through our JSX plugin.
|
||||
* Since we statically match every JSX file to an Astro renderer based on import scanning,
|
||||
* it would be helpful to embed some of that metadata at runtime.
|
||||
*
|
||||
* This plugin crawls each export in the file and "tags" each export with a given `rendererName`.
|
||||
* This allows us to automatically match a component to a renderer and skip the usual `check()` calls.
|
||||
*
|
||||
* @deprecated This plugin is no longer used. Remove in Astro 5.0
|
||||
*/
|
||||
export declare const tagExportsPlugin: PluginObj;
|
100
node_modules/astro/dist/vite-plugin-mdx/tag.js
generated
vendored
Normal file
100
node_modules/astro/dist/vite-plugin-mdx/tag.js
generated
vendored
Normal file
@@ -0,0 +1,100 @@
|
||||
import * as t from "@babel/types";
|
||||
import astroJsxRenderer from "../jsx/renderer.js";
|
||||
const rendererName = astroJsxRenderer.name;
|
||||
const tagExportsPlugin = {
|
||||
visitor: {
|
||||
Program: {
|
||||
// Inject `import { __astro_tag_component__ } from 'astro/runtime/server/index.js'`
|
||||
enter(path) {
|
||||
path.node.body.splice(
|
||||
0,
|
||||
0,
|
||||
t.importDeclaration(
|
||||
[
|
||||
t.importSpecifier(
|
||||
t.identifier("__astro_tag_component__"),
|
||||
t.identifier("__astro_tag_component__")
|
||||
)
|
||||
],
|
||||
t.stringLiteral("astro/runtime/server/index.js")
|
||||
)
|
||||
);
|
||||
},
|
||||
// For each export we found, inject `__astro_tag_component__(exportName, rendererName)`
|
||||
exit(path, state) {
|
||||
const exportedIds = state.get("astro:tags");
|
||||
if (exportedIds) {
|
||||
for (const id of exportedIds) {
|
||||
path.node.body.push(
|
||||
t.expressionStatement(
|
||||
t.callExpression(t.identifier("__astro_tag_component__"), [
|
||||
t.identifier(id),
|
||||
t.stringLiteral(rendererName)
|
||||
])
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
ExportDeclaration: {
|
||||
/**
|
||||
* For default anonymous function export, we need to give them a unique name
|
||||
* @param path
|
||||
* @returns
|
||||
*/
|
||||
enter(path) {
|
||||
const node = path.node;
|
||||
if (!t.isExportDefaultDeclaration(node)) return;
|
||||
if (t.isArrowFunctionExpression(node.declaration) || t.isCallExpression(node.declaration)) {
|
||||
const varName = t.isArrowFunctionExpression(node.declaration) ? "_arrow_function" : "_hoc_function";
|
||||
const uidIdentifier = path.scope.generateUidIdentifier(varName);
|
||||
path.insertBefore(
|
||||
t.variableDeclaration("const", [t.variableDeclarator(uidIdentifier, node.declaration)])
|
||||
);
|
||||
node.declaration = uidIdentifier;
|
||||
} else if (t.isFunctionDeclaration(node.declaration) && !node.declaration.id?.name) {
|
||||
const uidIdentifier = path.scope.generateUidIdentifier("_function");
|
||||
node.declaration.id = uidIdentifier;
|
||||
}
|
||||
},
|
||||
exit(path, state) {
|
||||
const node = path.node;
|
||||
if (node.exportKind === "type") return;
|
||||
if (t.isExportAllDeclaration(node)) return;
|
||||
const addTag = (id) => {
|
||||
const tags = state.get("astro:tags") ?? [];
|
||||
state.set("astro:tags", [...tags, id]);
|
||||
};
|
||||
if (t.isExportNamedDeclaration(node) || t.isExportDefaultDeclaration(node)) {
|
||||
if (t.isIdentifier(node.declaration)) {
|
||||
addTag(node.declaration.name);
|
||||
} else if (t.isFunctionDeclaration(node.declaration) && node.declaration.id?.name) {
|
||||
addTag(node.declaration.id.name);
|
||||
} else if (t.isVariableDeclaration(node.declaration)) {
|
||||
node.declaration.declarations?.forEach((declaration) => {
|
||||
if (t.isArrowFunctionExpression(declaration.init) && t.isIdentifier(declaration.id)) {
|
||||
addTag(declaration.id.name);
|
||||
}
|
||||
});
|
||||
} else if (t.isObjectExpression(node.declaration)) {
|
||||
node.declaration.properties?.forEach((property) => {
|
||||
if (t.isProperty(property) && t.isIdentifier(property.key)) {
|
||||
addTag(property.key.name);
|
||||
}
|
||||
});
|
||||
} else if (t.isExportNamedDeclaration(node) && !node.source) {
|
||||
node.specifiers.forEach((specifier) => {
|
||||
if (t.isExportSpecifier(specifier) && t.isIdentifier(specifier.exported)) {
|
||||
addTag(specifier.local.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
export {
|
||||
tagExportsPlugin
|
||||
};
|
5
node_modules/astro/dist/vite-plugin-mdx/transform-jsx.d.ts
generated
vendored
Normal file
5
node_modules/astro/dist/vite-plugin-mdx/transform-jsx.d.ts
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
import type { TransformResult } from 'rollup';
|
||||
/**
|
||||
* @deprecated This function is no longer used. Remove in Astro 5.0
|
||||
*/
|
||||
export declare function transformJSX(code: string, id: string, ssr?: boolean): Promise<TransformResult>;
|
49
node_modules/astro/dist/vite-plugin-mdx/transform-jsx.js
generated
vendored
Normal file
49
node_modules/astro/dist/vite-plugin-mdx/transform-jsx.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import babel from "@babel/core";
|
||||
import { jsxTransformOptions } from "../jsx/transform-options.js";
|
||||
import { tagExportsPlugin } from "./tag.js";
|
||||
async function transformJSX(code, id, ssr) {
|
||||
const options = await getJsxTransformOptions();
|
||||
const plugins = ssr ? [...options.plugins ?? [], tagExportsPlugin] : options.plugins;
|
||||
const result = await babel.transformAsync(code, {
|
||||
presets: options.presets,
|
||||
plugins,
|
||||
cwd: process.cwd(),
|
||||
filename: id,
|
||||
ast: false,
|
||||
compact: false,
|
||||
sourceMaps: true,
|
||||
configFile: false,
|
||||
babelrc: false,
|
||||
browserslistConfigFile: false,
|
||||
inputSourceMap: options.inputSourceMap
|
||||
});
|
||||
if (!result) return null;
|
||||
const { astro } = result.metadata;
|
||||
return {
|
||||
code: result.code || "",
|
||||
map: result.map,
|
||||
meta: {
|
||||
astro,
|
||||
vite: {
|
||||
// Setting this vite metadata to `ts` causes Vite to resolve .js
|
||||
// extensions to .ts files.
|
||||
lang: "ts"
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
let cachedJsxTransformOptions;
|
||||
async function getJsxTransformOptions() {
|
||||
if (cachedJsxTransformOptions) {
|
||||
return cachedJsxTransformOptions;
|
||||
}
|
||||
const options = jsxTransformOptions();
|
||||
cachedJsxTransformOptions = options;
|
||||
options.then((resolvedOptions) => {
|
||||
cachedJsxTransformOptions = resolvedOptions;
|
||||
});
|
||||
return options;
|
||||
}
|
||||
export {
|
||||
transformJSX
|
||||
};
|
Reference in New Issue
Block a user