🎉 initiate project *astro_rewrite*

This commit is contained in:
sindrekjelsrud 2023-07-19 21:31:30 +02:00
parent ffd4d5e86c
commit 2ba37bfbe3
8658 changed files with 2268794 additions and 2538 deletions

View file

@ -0,0 +1,5 @@
import { type Plugin as VitePlugin } from 'vite';
import type { AstroSettings } from '../@types/astro.js';
export default function astroScannerPlugin({ settings }: {
settings: AstroSettings;
}): VitePlugin;

45
node_modules/astro/dist/vite-plugin-scanner/index.js generated vendored Normal file
View file

@ -0,0 +1,45 @@
import { normalizePath } from "vite";
import { isEndpoint, isPage } from "../core/util.js";
import { getPrerenderDefault } from "../prerender/utils.js";
import { scan } from "./scan.js";
function astroScannerPlugin({ settings }) {
return {
name: "astro:scanner",
enforce: "post",
async transform(code, id, options) {
if (!(options == null ? void 0 : options.ssr))
return;
const filename = normalizePath(id);
let fileURL;
try {
fileURL = new URL(`file://${filename}`);
} catch (e) {
return;
}
const fileIsPage = isPage(fileURL, settings);
const fileIsEndpoint = isEndpoint(fileURL, settings);
if (!(fileIsPage || fileIsEndpoint))
return;
const defaultPrerender = getPrerenderDefault(settings.config);
const pageOptions = await scan(code, id, settings.config.output === "hybrid");
if (typeof pageOptions.prerender === "undefined") {
pageOptions.prerender = defaultPrerender;
}
const { meta = {} } = this.getModuleInfo(id) ?? {};
return {
code,
map: null,
meta: {
...meta,
astro: {
...meta.astro ?? { hydratedComponents: [], clientOnlyComponents: [], scripts: [] },
pageOptions
}
}
};
}
};
}
export {
astroScannerPlugin as default
};

View file

@ -0,0 +1,2 @@
import type { PageOptions } from '../vite-plugin-astro/types.js';
export declare function scan(code: string, id: string, isHybridOutput?: boolean): Promise<PageOptions>;

56
node_modules/astro/dist/vite-plugin-scanner/scan.js generated vendored Normal file
View file

@ -0,0 +1,56 @@
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, isHybridOutput = false) {
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]/)[0];
if (prefix !== "const" || !(isTruthy(suffix) || isFalsy(suffix))) {
throw new AstroError({
...AstroErrorData.InvalidPrerenderExport,
message: AstroErrorData.InvalidPrerenderExport.message(prefix, suffix, isHybridOutput),
location: { file: id }
});
} else {
pageOptions[name] = isTruthy(suffix);
}
}
}
return pageOptions;
}
export {
scan
};