feat: scaffold Astro + Tailwind project

This commit is contained in:
TerryM
2026-05-12 16:16:03 +08:00
parent 906eb5c763
commit 03d3800c6c
12097 changed files with 1266600 additions and 0 deletions

25
node_modules/astro/dist/core/compile/compile-rs.d.ts generated vendored Normal file
View File

@@ -0,0 +1,25 @@
import type { ResolvedConfig } from 'vite';
import type { AstroConfig } from '../../types/public/config.js';
import type { CompileCssResult } from './types.js';
export interface CompileProps {
astroConfig: AstroConfig;
viteConfig: ResolvedConfig;
toolbarEnabled: boolean;
filename: string;
source: string;
}
export interface CompileResult {
code: string;
map: string;
scope: string;
css: CompileCssResult[];
scripts: any[];
hydratedComponents: any[];
clientOnlyComponents: any[];
serverComponents: any[];
containsHead: boolean;
propagation: boolean;
styleError: string[];
diagnostics: any[];
}
export declare function compile({ astroConfig, viteConfig, toolbarEnabled, filename, source, }: CompileProps): Promise<CompileResult>;

111
node_modules/astro/dist/core/compile/compile-rs.js generated vendored Normal file
View File

@@ -0,0 +1,111 @@
import { fileURLToPath } from "node:url";
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,
toolbarEnabled,
filename,
source
}) {
let preprocessStyles;
let transform;
try {
({ preprocessStyles, transform } = await import("@astrojs/compiler-rs"));
} catch (err) {
throw new Error(
`Failed to load @astrojs/compiler-rs. Make sure it is installed and up to date. Original error: ${err}`
);
}
const cssPartialCompileResults = [];
const cssTransformErrors = [];
let transformResult;
try {
const preprocessedStyles = await preprocessStyles(
source,
createStylePreprocessor({
filename,
viteConfig,
astroConfig,
cssPartialCompileResults,
cssTransformErrors
})
);
transformResult = 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 && toolbarEnabled,
preprocessedStyles,
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(filename, transformResult, cssTransformErrors);
return {
...transformResult,
css: transformResult.css.map((code, i) => ({
...cssPartialCompileResults[i],
code
}))
};
}
function handleCompileResultErrors(filename, result, cssTransformErrors) {
const compilerError = result.diagnostics.find((diag) => diag.severity === "error");
if (compilerError) {
throw new CompilerError({
name: "CompilerError",
message: compilerError.text,
location: {
line: compilerError.labels[0].line,
column: compilerError.labels[0].column,
file: filename
},
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
};

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

@@ -0,0 +1,15 @@
import type { TransformResult } from '@astrojs/compiler';
import type { ResolvedConfig } from 'vite';
import type { AstroConfig } from '../../types/public/config.js';
import type { CompileCssResult } from './types.js';
export interface CompileProps {
astroConfig: AstroConfig;
viteConfig: ResolvedConfig;
toolbarEnabled: boolean;
filename: string;
source: string;
}
export interface CompileResult extends Omit<TransformResult, 'css'> {
css: CompileCssResult[];
}
export declare function compile({ astroConfig, viteConfig, toolbarEnabled, filename, source, }: CompileProps): Promise<CompileResult>;

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

@@ -0,0 +1,99 @@
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,
toolbarEnabled,
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 && toolbarEnabled,
preprocessStyle: createStylePreprocessor({
filename,
viteConfig,
astroConfig,
cssPartialCompileResults,
cssTransformErrors
}),
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
};

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

@@ -0,0 +1,20 @@
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'>;
interface PreprocessorResult {
code: string;
map?: string;
}
interface PreprocessorError {
error: string;
}
export type PreprocessStyleFn = (content: string, attrs: Record<string, string>) => Promise<PreprocessorResult | PreprocessorError>;
export declare function createStylePreprocessor({ filename, viteConfig, astroConfig, cssPartialCompileResults, cssTransformErrors, }: {
filename: string;
viteConfig: ResolvedConfig;
astroConfig: AstroConfig;
cssPartialCompileResults: Partial<CompileCssResult>[];
cssTransformErrors: Error[];
}): PreprocessStyleFn;
export {};

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

@@ -0,0 +1,137 @@
import fs from "node:fs";
import { createRequire } from "node:module";
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 withNestingExcluded(viteConfig) {
let Features;
try {
const requireFromRoot = createRequire(viteConfig.root + "/");
Features = requireFromRoot("lightningcss").Features;
} catch {
return void 0;
}
const lcss = viteConfig.css?.lightningcss ?? {};
const prevExclude = lcss.exclude ?? 0;
return {
...viteConfig,
css: { ...viteConfig.css, lightningcss: { ...lcss, exclude: prevExclude | Features.Nesting } }
};
}
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 effectiveViteConfig = viteConfig.css?.transformer === "lightningcss" ? withNestingExcluded(viteConfig) ?? viteConfig : viteConfig;
const result = await preprocessCSS(content, id, effectiveViteConfig);
const rewrittenCode = rewriteCssUrls(result.code, astroConfig.base);
cssPartialCompileResults[index] = {
// Use `in` operator to handle both Go compiler (boolean `true`) and
// Rust compiler (empty string `""`) representations of boolean attributes.
isGlobal: "is:global" in attrs,
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