full site update

This commit is contained in:
2025-07-24 18:46:24 +02:00
parent bfe2b90d8d
commit 37a6e0ab31
6912 changed files with 540482 additions and 361712 deletions

View File

@@ -12,8 +12,8 @@ async function compileAstro({
try {
transformResult = await compile(compileProps);
esbuildResult = await transformWithEsbuild(transformResult.code, compileProps.filename, {
...compileProps.viteConfig.esbuild,
loader: "ts",
target: "esnext",
sourcemap: "external",
tsconfigRaw: {
compilerOptions: {

View File

@@ -1,9 +1,10 @@
import type { HmrContext } from 'vite';
import type { Logger } from '../core/logger/core.js';
import type { CompileMetadata } from './types.js';
export interface HandleHotUpdateOptions {
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 {};

View File

@@ -1,9 +1,9 @@
import type * as vite from 'vite';
import type { AstroSettings } from '../@types/astro.js';
import type { Logger } from '../core/logger/core.js';
import type { PluginCssMetadata as AstroPluginCssMetadata, PluginMetadata as AstroPluginMetadata } from './types.js';
import type { AstroSettings } from '../types/astro.js';
import type { PluginMetadata as AstroPluginMetadata } from './types.js';
export { getAstroMetadata } from './metadata.js';
export type { AstroPluginMetadata, AstroPluginCssMetadata };
export type { AstroPluginMetadata };
interface AstroPluginOptions {
settings: AstroSettings;
logger: Logger;

View File

@@ -1,4 +1,4 @@
import { normalizePath } from "vite";
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";
@@ -13,10 +13,22 @@ function astro({ settings, logger }) {
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({
@@ -58,11 +70,6 @@ function astro({ settings, logger }) {
if (server) {
const code = await loadId(server.pluginContainer, filename);
if (code != null) await compile(code, filename);
} else if (config.experimental.contentCollectionCache) {
await this.load({
id: filename,
resolveDependencies: false
});
}
compileMetadata = astroFileToCompileMetadata.get(filename);
}
@@ -83,32 +90,30 @@ function astro({ settings, logger }) {
result.dependencies?.forEach((dep) => this.addWatchFile(dep));
return {
code: result.code,
// This metadata is used by `cssScopeToPlugin` to remove this module from the bundle
// if the `filename` default export (the Astro component) is unused.
// `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 : {
astroCss: {
cssScopeTo: {
[filename]: ["default"]
}
vite: {
cssScopeTo: [filename, "default"]
}
}
};
}
case "script": {
if (typeof query.index === "undefined") {
throw new Error(`Requests for hoisted scripts must include an index`);
throw new Error(`Requests for scripts must include an index`);
}
if (opts?.ssr) {
return {
code: `/* client hoisted script, empty in SSR: ${id} */`
code: `/* client script, empty in SSR: ${id} */`
};
}
const hoistedScript = compileMetadata.scripts[query.index];
if (!hoistedScript) {
throw new Error(`No hoisted script at index ${query.index}`);
const script = compileMetadata.scripts[query.index];
if (!script) {
throw new Error(`No script at index ${query.index}`);
}
if (hoistedScript.type === "external") {
const src = hoistedScript.src;
if (script.type === "external") {
const src = script.src;
if (src.startsWith("/") && !isBrowserPath(src)) {
const publicDir = config.publicDir.pathname.replace(/\/$/, "").split("/").pop() + "/";
throw new Error(
@@ -128,14 +133,14 @@ File: ${id}`
}
}
};
switch (hoistedScript.type) {
switch (script.type) {
case "inline": {
const { code, map } = hoistedScript;
const { code, map } = script;
result.code = appendSourceMap(code, map);
break;
}
case "external": {
const { src } = hoistedScript;
const { src } = script;
result.code = `import "${src}"`;
break;
}
@@ -153,13 +158,23 @@ File: ${id}`
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);
const transformResult = await compile(source, filename);
const astroMetadata = {
clientOnlyComponents: transformResult.clientOnlyComponents,
hydratedComponents: transformResult.hydratedComponents,
// 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,

View File

@@ -1,4 +1,4 @@
export interface AstroQuery {
interface AstroQuery {
astro?: boolean;
src?: boolean;
type?: 'script' | 'template' | 'style' | 'custom';
@@ -6,8 +6,9 @@ export interface AstroQuery {
lang?: string;
raw?: boolean;
}
export interface ParsedRequestResult {
interface ParsedRequestResult {
filename: string;
query: AstroQuery;
}
export declare function parseAstroRequest(id: string): ParsedRequestResult;
export {};

View File

@@ -1,7 +1,7 @@
import type { HoistedScript, TransformResult } from '@astrojs/compiler';
import type { PropagationHint } from '../@types/astro.js';
import type { CompileCssResult } from '../core/compile/types.js';
export interface PageOptions {
import type { PropagationHint } from '../types/public/internal.js';
interface PageOptions {
prerender?: boolean;
}
export interface PluginMetadata {
@@ -15,31 +15,12 @@ export interface PluginMetadata {
pageOptions: PageOptions;
};
}
export interface PluginCssMetadata {
astroCss: {
/**
* For Astro CSS virtual modules, it can scope to the main Astro module's default export
* so that if those exports are treeshaken away, the CSS module will also be treeshaken.
*
* Example config if the CSS id is `/src/Foo.astro?astro&type=style&lang.css`:
* ```js
* cssScopeTo: {
* '/src/Foo.astro': ['default']
* }
* ```
*
* The above is the only config we use today, but we're exposing as a `Record` to follow the
* upstream Vite implementation: https://github.com/vitejs/vite/pull/16058. When/If that lands,
* we can also remove our custom implementation.
*/
cssScopeTo: Record<string, string[]>;
};
}
export interface CompileMetadata {
/** Used for HMR to compare code changes */
originalCode: string;
/** For Astro CSS virtual module */
css: CompileCssResult[];
/** For Astro hoisted scripts virtual module */
/** For Astro scripts virtual module */
scripts: HoistedScript[];
}
export {};