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

16
node_modules/astro/dist/core/compile/compile.d.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import type { TransformResult } from '@astrojs/compiler';
import type { ResolvedConfig } from 'vite';
import type { AstroPreferences } from '../../preferences/index.js';
import type { AstroConfig } from '../../types/public/config.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
View File

@@ -0,0 +1,101 @@
import { fileURLToPath } from "node:url";
import { transform } from "@astrojs/compiler";
import { AggregateError, CompilerError } from "../errors/errors.js";
import { AstroErrorData } from "../errors/index.js";
import { normalizePath, 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: remove in Astro v7
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: true,
preprocessStyle: createStylePreprocessor({
filename,
viteConfig,
astroConfig,
cssPartialCompileResults,
cssTransformErrors
}),
experimentalScriptOrder: astroConfig.experimental.preserveScriptOrder ?? false,
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
View File

@@ -0,0 +1,2 @@
export type { CompileProps, CompileResult } from './compile.js';
export { compile } from './compile.js';

4
node_modules/astro/dist/core/compile/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
import { compile } from "./compile.js";
export {
compile
};

12
node_modules/astro/dist/core/compile/style.d.ts generated vendored Normal file
View File

@@ -0,0 +1,12 @@
import type { TransformOptions } from '@astrojs/compiler';
import { type ResolvedConfig } from 'vite';
import type { AstroConfig } from '../../types/public/config.js';
import type { CompileCssResult } from './types.js';
export type PartialCompileCssResult = Pick<CompileCssResult, 'isGlobal' | 'dependencies'>;
export declare function createStylePreprocessor({ filename, viteConfig, astroConfig, cssPartialCompileResults, cssTransformErrors, }: {
filename: string;
viteConfig: ResolvedConfig;
astroConfig: AstroConfig;
cssPartialCompileResults: Partial<CompileCssResult>[];
cssTransformErrors: Error[];
}): TransformOptions['preprocessStyle'];

118
node_modules/astro/dist/core/compile/style.js generated vendored Normal file
View File

@@ -0,0 +1,118 @@
import fs from "node:fs";
import { preprocessCSS } from "vite";
import { AstroErrorData, CSSError, positionAt } from "../errors/index.js";
import { normalizePath } from "../viteUtils.js";
function rewriteCssUrls(css, base) {
if (!base || base === "/") {
return css;
}
const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base;
if (!normalizedBase.startsWith("/")) {
return css;
}
const cssUrlRE = (
// eslint-disable-next-line regexp/no-unused-capturing-group
/(?<!@import\s+)(?<=^|[^\w\-\u0080-\uffff])url\((\s*('[^']+'|"[^"]+")\s*|(?:\\.|[^'")\\])+)\)/g
);
return css.replace(cssUrlRE, (match, rawUrl) => {
let url = rawUrl.trim();
let quote = "";
if (url.startsWith("'") && url.endsWith("'") || url.startsWith('"') && url.endsWith('"')) {
quote = url[0];
url = url.slice(1, -1);
}
url = url.trim();
const isRootRelative = url.startsWith("/") && !url.startsWith("//");
const isExternal = url.startsWith("data:") || url.startsWith("http:") || url.startsWith("https:");
const alreadyHasBase = url.startsWith(normalizedBase + "/");
if (isRootRelative && !isExternal && !alreadyHasBase) {
return `url(${quote}${normalizedBase}${url}${quote})`;
}
return match;
});
}
function createStylePreprocessor({
filename,
viteConfig,
astroConfig,
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);
const rewrittenCode = rewriteCssUrls(result.code, astroConfig.base);
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: rewrittenCode, 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
View 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
View File