full site update
This commit is contained in:
8
node_modules/astro/dist/vite-plugin-scanner/index.d.ts
generated
vendored
8
node_modules/astro/dist/vite-plugin-scanner/index.d.ts
generated
vendored
@@ -1,8 +1,10 @@
|
||||
import type { Plugin as VitePlugin } from 'vite';
|
||||
import type { AstroSettings } from '../@types/astro.js';
|
||||
import type { Logger } from '../core/logger/core.js';
|
||||
export interface AstroPluginScannerOptions {
|
||||
import type { AstroSettings, RoutesList } from '../types/astro.js';
|
||||
interface AstroPluginScannerOptions {
|
||||
settings: AstroSettings;
|
||||
logger: Logger;
|
||||
routesList: RoutesList;
|
||||
}
|
||||
export default function astroScannerPlugin({ settings, logger, }: AstroPluginScannerOptions): VitePlugin;
|
||||
export default function astroScannerPlugin({ settings, logger, routesList, }: AstroPluginScannerOptions): VitePlugin;
|
||||
export {};
|
||||
|
70
node_modules/astro/dist/vite-plugin-scanner/index.js
generated
vendored
70
node_modules/astro/dist/vite-plugin-scanner/index.js
generated
vendored
@@ -1,15 +1,16 @@
|
||||
import { extname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { bold } from "kleur/colors";
|
||||
import { normalizePath } from "vite";
|
||||
import { isEndpoint, isPage, isServerLikeOutput } from "../core/util.js";
|
||||
import { rootRelativePath } from "../core/viteUtils.js";
|
||||
import { runHookRouteSetup } from "../integrations/hooks.js";
|
||||
import { getPrerenderDefault } from "../prerender/utils.js";
|
||||
import { scan } from "./scan.js";
|
||||
import { warnMissingAdapter } from "../core/dev/adapter-validation.js";
|
||||
import { getRoutePrerenderOption } from "../core/routing/manifest/prerender.js";
|
||||
import { isEndpoint, isPage } from "../core/util.js";
|
||||
import { normalizePath, rootRelativePath } from "../core/viteUtils.js";
|
||||
import { createDefaultAstroMetadata } from "../vite-plugin-astro/metadata.js";
|
||||
const KNOWN_FILE_EXTENSIONS = [".astro", ".js", ".ts"];
|
||||
function astroScannerPlugin({
|
||||
settings,
|
||||
logger
|
||||
logger,
|
||||
routesList
|
||||
}) {
|
||||
return {
|
||||
name: "astro:scanner",
|
||||
@@ -26,8 +27,14 @@ function astroScannerPlugin({
|
||||
const fileIsPage = isPage(fileURL, settings);
|
||||
const fileIsEndpoint = isEndpoint(fileURL, settings);
|
||||
if (!(fileIsPage || fileIsEndpoint)) return;
|
||||
const pageOptions = await getPageOptions(code, id, fileURL, settings, logger);
|
||||
if (!pageOptions.prerender && isServerLikeOutput(settings.config) && code.includes("getStaticPaths") && // this should only be valid for `.astro`, `.js` and `.ts` files
|
||||
const route = routesList.routes.find((r) => {
|
||||
const filePath = new URL(`./${r.component}`, settings.config.root);
|
||||
return normalizePath(fileURLToPath(filePath)) === filename;
|
||||
});
|
||||
if (!route) {
|
||||
return;
|
||||
}
|
||||
if (!route.prerender && code.includes("getStaticPaths") && // this should only be valid for `.astro`, `.js` and `.ts` files
|
||||
KNOWN_FILE_EXTENSIONS.includes(extname(filename))) {
|
||||
logger.warn(
|
||||
"router",
|
||||
@@ -43,31 +50,38 @@ function astroScannerPlugin({
|
||||
meta: {
|
||||
...meta,
|
||||
astro: {
|
||||
...meta.astro ?? { hydratedComponents: [], clientOnlyComponents: [], scripts: [] },
|
||||
pageOptions
|
||||
...meta.astro ?? createDefaultAstroMetadata(),
|
||||
pageOptions: {
|
||||
prerender: route.prerender
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
},
|
||||
// Handle hot updates to update the prerender option
|
||||
async handleHotUpdate(ctx) {
|
||||
const filename = normalizePath(ctx.file);
|
||||
let fileURL;
|
||||
try {
|
||||
fileURL = new URL(`file://${filename}`);
|
||||
} catch {
|
||||
return;
|
||||
}
|
||||
const fileIsPage = isPage(fileURL, settings);
|
||||
const fileIsEndpoint = isEndpoint(fileURL, settings);
|
||||
if (!(fileIsPage || fileIsEndpoint)) return;
|
||||
const route = routesList.routes.find((r) => {
|
||||
const filePath = new URL(`./${r.component}`, settings.config.root);
|
||||
return normalizePath(fileURLToPath(filePath)) === filename;
|
||||
});
|
||||
if (!route) {
|
||||
return;
|
||||
}
|
||||
await getRoutePrerenderOption(await ctx.read(), route, settings, logger);
|
||||
warnMissingAdapter(logger, settings);
|
||||
}
|
||||
};
|
||||
}
|
||||
async function getPageOptions(code, id, fileURL, settings, logger) {
|
||||
const fileUrlStr = fileURL.toString();
|
||||
const injectedRoute = settings.resolvedInjectedRoutes.find(
|
||||
(route2) => route2.resolvedEntryPoint && fileUrlStr === route2.resolvedEntryPoint.toString()
|
||||
);
|
||||
const pageOptions = injectedRoute?.prerender != null ? { prerender: injectedRoute.prerender } : await scan(code, id, settings);
|
||||
const route = {
|
||||
component: rootRelativePath(settings.config.root, fileURL, false),
|
||||
prerender: pageOptions.prerender
|
||||
};
|
||||
await runHookRouteSetup({ route, settings, logger });
|
||||
pageOptions.prerender = route.prerender;
|
||||
if (typeof pageOptions.prerender === "undefined") {
|
||||
pageOptions.prerender = getPrerenderDefault(settings.config);
|
||||
}
|
||||
return pageOptions;
|
||||
}
|
||||
export {
|
||||
astroScannerPlugin as default
|
||||
};
|
||||
|
3
node_modules/astro/dist/vite-plugin-scanner/scan.d.ts
generated
vendored
3
node_modules/astro/dist/vite-plugin-scanner/scan.d.ts
generated
vendored
@@ -1,3 +0,0 @@
|
||||
import type { AstroSettings } from '../@types/astro.js';
|
||||
import type { PageOptions } from '../vite-plugin-astro/types.js';
|
||||
export declare function scan(code: string, id: string, settings?: AstroSettings): Promise<PageOptions>;
|
58
node_modules/astro/dist/vite-plugin-scanner/scan.js
generated
vendored
58
node_modules/astro/dist/vite-plugin-scanner/scan.js
generated
vendored
@@ -1,58 +0,0 @@
|
||||
import * as eslexer from "es-module-lexer";
|
||||
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
||||
const BOOLEAN_EXPORTS = /* @__PURE__ */ new Set(["prerender"]);
|
||||
function includesExport(code) {
|
||||
for (const name of BOOLEAN_EXPORTS) {
|
||||
if (code.includes(name)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
function isQuoted(value) {
|
||||
return (value[0] === '"' || value[0] === "'") && value[value.length - 1] === value[0];
|
||||
}
|
||||
function isTruthy(value) {
|
||||
if (isQuoted(value)) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
return value === "true" || value === "1";
|
||||
}
|
||||
function isFalsy(value) {
|
||||
if (isQuoted(value)) {
|
||||
value = value.slice(1, -1);
|
||||
}
|
||||
return value === "false" || value === "0";
|
||||
}
|
||||
let didInit = false;
|
||||
async function scan(code, id, settings) {
|
||||
if (!includesExport(code)) return {};
|
||||
if (!didInit) {
|
||||
await eslexer.init;
|
||||
didInit = true;
|
||||
}
|
||||
const [, exports] = eslexer.parse(code, id);
|
||||
let pageOptions = {};
|
||||
for (const _export of exports) {
|
||||
const { n: name, le: endOfLocalName } = _export;
|
||||
if (BOOLEAN_EXPORTS.has(name)) {
|
||||
const prefix = code.slice(0, endOfLocalName).split("export").pop().trim().replace("prerender", "").trim();
|
||||
const suffix = code.slice(endOfLocalName).trim().replace(/=/, "").trim().split(/[;\n\r]/)[0].trim();
|
||||
if (prefix !== "const" || !(isTruthy(suffix) || isFalsy(suffix))) {
|
||||
throw new AstroError({
|
||||
...AstroErrorData.InvalidPrerenderExport,
|
||||
message: AstroErrorData.InvalidPrerenderExport.message(
|
||||
prefix,
|
||||
suffix,
|
||||
settings?.config.output === "hybrid"
|
||||
),
|
||||
location: { file: id }
|
||||
});
|
||||
} else {
|
||||
pageOptions[name] = isTruthy(suffix);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pageOptions;
|
||||
}
|
||||
export {
|
||||
scan
|
||||
};
|
Reference in New Issue
Block a user