Initial commit

This commit is contained in:
Alejandro Martinez
2026-02-12 02:04:10 +01:00
commit f09af719cf
13433 changed files with 2193445 additions and 0 deletions

14
node_modules/astro/dist/vite-plugin-astro/compile.d.ts generated vendored Normal file
View File

@@ -0,0 +1,14 @@
import { type ESBuildTransformResult } from 'vite';
import { type CompileProps, type CompileResult } from '../core/compile/index.js';
import type { Logger } from '../core/logger/core.js';
import type { CompileMetadata } from './types.js';
interface CompileAstroOption {
compileProps: CompileProps;
astroFileToCompileMetadata: Map<string, CompileMetadata>;
logger: Logger;
}
export interface CompileAstroResult extends Omit<CompileResult, 'map'> {
map: ESBuildTransformResult['map'];
}
export declare function compileAstro({ compileProps, astroFileToCompileMetadata, logger, }: CompileAstroOption): Promise<CompileAstroResult>;
export {};

95
node_modules/astro/dist/vite-plugin-astro/compile.js generated vendored Normal file
View File

@@ -0,0 +1,95 @@
import { transformWithEsbuild } from "vite";
import { compile } from "../core/compile/index.js";
import { getFileInfo } from "../vite-plugin-utils/index.js";
import { frontmatterRE } from "./utils.js";
async function compileAstro({
compileProps,
astroFileToCompileMetadata,
logger
}) {
let transformResult;
let esbuildResult;
try {
transformResult = await compile(compileProps);
esbuildResult = await transformWithEsbuild(transformResult.code, compileProps.filename, {
...compileProps.viteConfig.esbuild,
loader: "ts",
sourcemap: "external",
tsconfigRaw: {
compilerOptions: {
// Ensure client:only imports are treeshaken
verbatimModuleSyntax: false,
importsNotUsedAsValues: "remove"
}
}
});
} catch (err) {
await enhanceCompileError({
err,
id: compileProps.filename,
source: compileProps.source,
config: compileProps.astroConfig,
logger
});
throw err;
}
const { fileId: file, fileUrl: url } = getFileInfo(
compileProps.filename,
compileProps.astroConfig
);
let SUFFIX = "";
SUFFIX += `
const $$file = ${JSON.stringify(file)};
const $$url = ${JSON.stringify(
url
)};export { $$file as file, $$url as url };
`;
if (!compileProps.viteConfig.isProduction) {
let i = 0;
while (i < transformResult.scripts.length) {
SUFFIX += `import "${compileProps.filename}?astro&type=script&index=${i}&lang.ts";`;
i++;
}
}
astroFileToCompileMetadata.set(compileProps.filename, {
originalCode: compileProps.source,
css: transformResult.css,
scripts: transformResult.scripts
});
return {
...transformResult,
code: esbuildResult.code + SUFFIX,
map: esbuildResult.map
};
}
async function enhanceCompileError({
err,
id,
source
}) {
const lineText = err.loc?.lineText;
const scannedFrontmatter = frontmatterRE.exec(source);
if (scannedFrontmatter) {
const frontmatter = scannedFrontmatter[1].replace(/\breturn\b/g, "throw");
if (lineText && !frontmatter.includes(lineText)) throw err;
try {
await transformWithEsbuild(frontmatter, id, {
loader: "ts",
target: "esnext",
sourcemap: false
});
} catch (frontmatterErr) {
if (frontmatterErr?.message) {
frontmatterErr.message = frontmatterErr.message.replace(
"end of file",
"end of frontmatter"
);
}
throw frontmatterErr;
}
}
throw err;
}
export {
compileAstro
};

10
node_modules/astro/dist/vite-plugin-astro/hmr.d.ts generated vendored Normal file
View File

@@ -0,0 +1,10 @@
import type { HmrContext } from 'vite';
import type { Logger } from '../core/logger/core.js';
import type { CompileMetadata } from './types.js';
interface HandleHotUpdateOptions {
logger: Logger;
astroFileToCompileMetadata: Map<string, CompileMetadata>;
}
export declare function handleHotUpdate(ctx: HmrContext, { logger, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
export declare function isStyleOnlyChanged(oldCode: string, newCode: string): boolean;
export {};

60
node_modules/astro/dist/vite-plugin-astro/hmr.js generated vendored Normal file
View File

@@ -0,0 +1,60 @@
import { parseAstroRequest } from "./query.js";
import { frontmatterRE } from "./utils.js";
async function handleHotUpdate(ctx, { logger, astroFileToCompileMetadata }) {
for (const [astroFile, compileData] of astroFileToCompileMetadata) {
const isUpdatedFileCssDep = compileData.css.some((css) => css.dependencies?.includes(ctx.file));
if (isUpdatedFileCssDep) {
astroFileToCompileMetadata.delete(astroFile);
}
}
const oldCode = astroFileToCompileMetadata.get(ctx.file)?.originalCode;
if (oldCode == null) return;
const newCode = await ctx.read();
if (isStyleOnlyChanged(oldCode, newCode)) {
logger.debug("watch", "style-only change");
astroFileToCompileMetadata.delete(ctx.file);
return ctx.modules.filter((mod) => {
if (!mod.id) {
return false;
}
const { query } = parseAstroRequest(mod.id);
return query.astro && query.type === "style" && !query.inline;
});
}
}
const scriptRE = /<script(?:\s.*?)?>.*?<\/script>/gs;
const styleRE = /<style(?:\s.*?)?>.*?<\/style>/gs;
function isStyleOnlyChanged(oldCode, newCode) {
if (oldCode === newCode) return false;
let oldFrontmatter = "";
let newFrontmatter = "";
oldCode = oldCode.replace(frontmatterRE, (m) => (oldFrontmatter = m, ""));
newCode = newCode.replace(frontmatterRE, (m) => (newFrontmatter = m, ""));
if (oldFrontmatter !== newFrontmatter) return false;
const oldScripts = [];
const newScripts = [];
oldCode = oldCode.replace(scriptRE, (m) => (oldScripts.push(m), ""));
newCode = newCode.replace(scriptRE, (m) => (newScripts.push(m), ""));
if (!isArrayEqual(oldScripts, newScripts)) return false;
const oldStyles = [];
const newStyles = [];
oldCode = oldCode.replace(styleRE, (m) => (oldStyles.push(m), ""));
newCode = newCode.replace(styleRE, (m) => (newStyles.push(m), ""));
if (oldCode !== newCode) return false;
return oldStyles.length === newStyles.length && !isArrayEqual(oldStyles, newStyles);
}
function isArrayEqual(a, b) {
if (a.length !== b.length) {
return false;
}
for (let i = 0; i < a.length; i++) {
if (a[i] !== b[i]) {
return false;
}
}
return true;
}
export {
handleHotUpdate,
isStyleOnlyChanged
};

12
node_modules/astro/dist/vite-plugin-astro/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import type * as vite from 'vite';
import type { Logger } from '../core/logger/core.js';
import type { AstroSettings } from '../types/astro.js';
import type { PluginMetadata as AstroPluginMetadata } from './types.js';
export { getAstroMetadata } from './metadata.js';
export type { AstroPluginMetadata };
interface AstroPluginOptions {
settings: AstroSettings;
logger: Logger;
}
/** Transform .astro files for Vite */
export default function astro({ settings, logger }: AstroPluginOptions): vite.Plugin[];

238
node_modules/astro/dist/vite-plugin-astro/index.js generated vendored Normal file
View File

@@ -0,0 +1,238 @@
import { defaultClientConditions, defaultServerConditions, normalizePath } from "vite";
import { hasSpecialQueries, normalizeFilename } from "../vite-plugin-utils/index.js";
import { compileAstro } from "./compile.js";
import { handleHotUpdate } from "./hmr.js";
import { parseAstroRequest } from "./query.js";
import { loadId } from "./utils.js";
import { getAstroMetadata } from "./metadata.js";
const astroFileToCompileMetadataWeakMap = /* @__PURE__ */ new WeakMap();
function astro({ settings, logger }) {
const { config } = settings;
let server;
let compile;
let astroFileToCompileMetadata = /* @__PURE__ */ new Map();
const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
const isBrowserPath = (path) => path.startsWith(srcRootWeb) && srcRootWeb !== "/";
const notAstroComponent = (component) => !component.resolvedPath.endsWith(".astro");
const prePlugin = {
name: "astro:build",
enforce: "pre",
// run transforms before other plugins can
async configEnvironment(name, viteConfig, opts) {
viteConfig.resolve ??= {};
if (viteConfig.resolve.conditions == null) {
if (viteConfig.consumer === "client" || name === "client" || opts.isSsrTargetWebworker) {
viteConfig.resolve.conditions = [...defaultClientConditions];
} else {
viteConfig.resolve.conditions = [...defaultServerConditions];
}
}
viteConfig.resolve.conditions.push("astro");
},
configResolved(viteConfig) {
compile = (code, filename) => {
return compileAstro({
compileProps: {
astroConfig: config,
viteConfig,
preferences: settings.preferences,
filename,
source: code
},
astroFileToCompileMetadata,
logger
});
};
},
configureServer(_server) {
server = _server;
server.watcher.on("unlink", (filename) => {
astroFileToCompileMetadata.delete(filename);
});
},
buildStart() {
astroFileToCompileMetadata = /* @__PURE__ */ new Map();
if (astroFileToCompileMetadataWeakMap.has(config)) {
astroFileToCompileMetadata = astroFileToCompileMetadataWeakMap.get(config);
} else {
astroFileToCompileMetadataWeakMap.set(config, astroFileToCompileMetadata);
}
},
async load(id, opts) {
const parsedId = parseAstroRequest(id);
const query = parsedId.query;
if (!query.astro) {
return null;
}
const filename = normalizePath(normalizeFilename(parsedId.filename, config.root));
let compileMetadata = astroFileToCompileMetadata.get(filename);
if (!compileMetadata) {
if (server) {
const code = await loadId(server.pluginContainer, filename);
if (code != null) await compile(code, filename);
}
compileMetadata = astroFileToCompileMetadata.get(filename);
}
if (!compileMetadata) {
throw new Error(
`No cached compile metadata found for "${id}". The main Astro module "${filename}" should have compiled and filled the metadata first, before its virtual modules can be requested.`
);
}
switch (query.type) {
case "style": {
if (typeof query.index === "undefined") {
throw new Error(`Requests for Astro CSS must include an index.`);
}
const result = compileMetadata.css[query.index];
if (!result) {
throw new Error(`No Astro CSS at index ${query.index}`);
}
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
return {
code: result.code,
// `vite.cssScopeTo` is a Vite feature that allows this CSS to be treeshaken
// if the Astro component's default export is not used
meta: result.isGlobal ? void 0 : {
vite: {
cssScopeTo: [filename, "default"]
}
}
};
}
case "script": {
if (typeof query.index === "undefined") {
throw new Error(`Requests for scripts must include an index`);
}
if (opts?.ssr) {
return {
code: `/* client script, empty in SSR: ${id} */`
};
}
const script = compileMetadata.scripts[query.index];
if (!script) {
throw new Error(`No script at index ${query.index}`);
}
if (script.type === "external") {
const src = script.src;
if (src.startsWith("/") && !isBrowserPath(src)) {
const publicDir = config.publicDir.pathname.replace(/\/$/, "").split("/").pop() + "/";
throw new Error(
`
<script src="${src}"> references an asset in the "${publicDir}" directory. Please add the "is:inline" directive to keep this asset from being bundled.
File: ${id}`
);
}
}
const result = {
code: "",
meta: {
vite: {
lang: "ts"
}
}
};
switch (script.type) {
case "inline": {
const { code, map } = script;
result.code = appendSourceMap(code, map);
break;
}
case "external": {
const { src } = script;
result.code = `import "${src}"`;
break;
}
}
return result;
}
case "custom":
case "template":
case void 0:
default:
return null;
}
},
async transform(source, id, options) {
if (hasSpecialQueries(id)) return;
const parsedId = parseAstroRequest(id);
if (!parsedId.filename.endsWith(".astro") || parsedId.query.astro) {
if (this.environment.name === "client") {
const astroFilename = normalizePath(normalizeFilename(parsedId.filename, config.root));
const compileMetadata = astroFileToCompileMetadata.get(astroFilename);
if (compileMetadata && parsedId.query.type === "style" && parsedId.query.index != null) {
const result = compileMetadata.css[parsedId.query.index];
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
}
}
return;
}
const filename = normalizePath(parsedId.filename);
if (!options?.ssr && // Workaround to allow tests run with Vitest in a “client” environment to still render
// Astro components. See https://github.com/withastro/astro/issues/14883
// TODO: In a future major we should remove this and require people test Astro rendering in
// an SSR test environment, which more closely matches the real-world Vite environment.
!process.env.VITEST) {
return {
code: `export default import.meta.env.DEV
? () => {
throw new Error(
'Astro components cannot be used in the browser.\\nTried to render "${filename}".'
);
}
: {};`,
meta: { vite: { lang: "ts" } }
};
}
const transformResult = await compile(source, filename);
const astroMetadata = {
// Remove Astro components that have been mistakenly given client directives
// We'll warn the user about this later, but for now we'll prevent them from breaking the build
clientOnlyComponents: transformResult.clientOnlyComponents.filter(notAstroComponent),
hydratedComponents: transformResult.hydratedComponents.filter(notAstroComponent),
serverComponents: transformResult.serverComponents,
scripts: transformResult.scripts,
containsHead: transformResult.containsHead,
propagation: transformResult.propagation ? "self" : "none",
pageOptions: {}
};
return {
code: transformResult.code,
map: transformResult.map,
meta: {
astro: astroMetadata,
vite: {
// Setting this vite metadata to `ts` causes Vite to resolve .js
// extensions to .ts files.
lang: "ts"
}
}
};
},
async handleHotUpdate(ctx) {
return handleHotUpdate(ctx, { logger, astroFileToCompileMetadata });
}
};
const normalPlugin = {
name: "astro:build:normal",
resolveId(id) {
const parsedId = parseAstroRequest(id);
if (parsedId.query.astro) {
return id;
}
}
};
return [prePlugin, normalPlugin];
}
function appendSourceMap(content, map) {
if (!map) return content;
return `${content}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(
map
).toString("base64")}`;
}
export {
astro as default,
getAstroMetadata
};

View File

@@ -0,0 +1,4 @@
import type { ModuleInfo } from '../core/module-loader/index.js';
import type { PluginMetadata } from './types.js';
export declare function getAstroMetadata(modInfo: ModuleInfo): PluginMetadata['astro'] | undefined;
export declare function createDefaultAstroMetadata(): PluginMetadata['astro'];

21
node_modules/astro/dist/vite-plugin-astro/metadata.js generated vendored Normal file
View File

@@ -0,0 +1,21 @@
function getAstroMetadata(modInfo) {
if (modInfo.meta?.astro) {
return modInfo.meta.astro;
}
return void 0;
}
function createDefaultAstroMetadata() {
return {
hydratedComponents: [],
clientOnlyComponents: [],
serverComponents: [],
scripts: [],
propagation: "none",
containsHead: false,
pageOptions: {}
};
}
export {
createDefaultAstroMetadata,
getAstroMetadata
};

15
node_modules/astro/dist/vite-plugin-astro/query.d.ts generated vendored Normal file
View File

@@ -0,0 +1,15 @@
interface AstroQuery {
astro?: boolean;
src?: boolean;
type?: 'script' | 'template' | 'style' | 'custom';
index?: number;
lang?: string;
raw?: boolean;
inline?: boolean;
}
interface ParsedRequestResult {
filename: string;
query: AstroQuery;
}
export declare function parseAstroRequest(id: string): ParsedRequestResult;
export {};

26
node_modules/astro/dist/vite-plugin-astro/query.js generated vendored Normal file
View File

@@ -0,0 +1,26 @@
function parseAstroRequest(id) {
const [filename, rawQuery] = id.split(`?`, 2);
const query = Object.fromEntries(new URLSearchParams(rawQuery).entries());
if (query.astro != null) {
query.astro = true;
}
if (query.src != null) {
query.src = true;
}
if (query.index != null) {
query.index = Number(query.index);
}
if (query.raw != null) {
query.raw = true;
}
if (query.inline != null) {
query.inline = true;
}
return {
filename,
query
};
}
export {
parseAstroRequest
};

26
node_modules/astro/dist/vite-plugin-astro/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,26 @@
import type { HoistedScript, TransformResult } from '@astrojs/compiler';
import type { CompileCssResult } from '../core/compile/types.js';
import type { PropagationHint } from '../types/public/internal.js';
interface PageOptions {
prerender?: boolean;
}
export interface PluginMetadata {
astro: {
hydratedComponents: TransformResult['hydratedComponents'];
clientOnlyComponents: TransformResult['clientOnlyComponents'];
serverComponents: TransformResult['serverComponents'];
scripts: TransformResult['scripts'];
containsHead: TransformResult['containsHead'];
propagation: PropagationHint;
pageOptions: PageOptions;
};
}
export interface CompileMetadata {
/** Used for HMR to compare code changes */
originalCode: string;
/** For Astro CSS virtual module */
css: CompileCssResult[];
/** For Astro scripts virtual module */
scripts: HoistedScript[];
}
export {};

0
node_modules/astro/dist/vite-plugin-astro/types.js generated vendored Normal file
View File

3
node_modules/astro/dist/vite-plugin-astro/utils.d.ts generated vendored Normal file
View File

@@ -0,0 +1,3 @@
import type { PluginContainer } from 'vite';
export declare const frontmatterRE: RegExp;
export declare function loadId(pluginContainer: PluginContainer, id: string): Promise<string | undefined>;

20
node_modules/astro/dist/vite-plugin-astro/utils.js generated vendored Normal file
View File

@@ -0,0 +1,20 @@
import fs from "node:fs/promises";
const frontmatterRE = /^---(.*?)^---/ms;
async function loadId(pluginContainer, id) {
const result = await pluginContainer.load(id, { ssr: true });
if (result) {
if (typeof result === "string") {
return result;
} else {
return result.code;
}
}
try {
return await fs.readFile(id, "utf-8");
} catch {
}
}
export {
frontmatterRE,
loadId
};