astro 7.0.6 → 7.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  class BuildTimeAstroVersionProvider {
2
2
  // Injected during the build through esbuild define
3
- version = "7.0.6";
3
+ version = "7.0.7";
4
4
  }
5
5
  export {
6
6
  BuildTimeAstroVersionProvider
@@ -197,7 +197,7 @@ ${contentConfig.error.message}`
197
197
  logger.info("Content config changed");
198
198
  shouldClear = true;
199
199
  }
200
- if (previousAstroVersion && previousAstroVersion !== "7.0.6") {
200
+ if (previousAstroVersion && previousAstroVersion !== "7.0.7") {
201
201
  logger.info("Astro version changed");
202
202
  shouldClear = true;
203
203
  }
@@ -205,8 +205,8 @@ ${contentConfig.error.message}`
205
205
  logger.info("Clearing content store");
206
206
  this.#store.clearAll();
207
207
  }
208
- if ("7.0.6") {
209
- this.#store.metaStore().set("astro-version", "7.0.6");
208
+ if ("7.0.7") {
209
+ this.#store.metaStore().set("astro-version", "7.0.7");
210
210
  }
211
211
  if (currentConfigDigest) {
212
212
  this.#store.metaStore().set("content-config-digest", currentConfigDigest);
@@ -3,8 +3,12 @@ import { type Plugin } from 'vite';
3
3
  import type { BuildInternals } from '../core/build/internal.js';
4
4
  import type { ExtractedChunk } from '../core/build/static-build.js';
5
5
  import type { AstroSettings } from '../types/astro.js';
6
- export declare function astroContentAssetPropagationPlugin({ settings, }: {
6
+ export declare function astroContentAssetPropagationPlugin({ settings, cssContentCache, }: {
7
7
  settings: AstroSettings;
8
+ /** Shared cache of CSS content populated by the dev-css plugin's transform hook.
9
+ * Used to retrieve already-processed CSS for CSS modules without re-importing
10
+ * via `?inline`, which would produce different scoped-name hashes with Lightning CSS. */
11
+ cssContentCache?: Map<string, string>;
8
12
  }): Plugin;
9
13
  /**
10
14
  * Post-build hook that injects propagated styles into content collection chunks.
@@ -19,7 +19,8 @@ import { joinPaths, prependForwardSlash, slash } from "@astrojs/internal-helpers
19
19
  import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../core/constants.js";
20
20
  import { isAstroServerEnvironment } from "../environments.js";
21
21
  function astroContentAssetPropagationPlugin({
22
- settings
22
+ settings,
23
+ cssContentCache
23
24
  }) {
24
25
  let environment = void 0;
25
26
  return {
@@ -84,7 +85,7 @@ function astroContentAssetPropagationPlugin({
84
85
  styles,
85
86
  urls,
86
87
  crawledFiles: styleCrawledFiles
87
- } = await getStylesForURL(basePath, environment);
88
+ } = await getStylesForURL(basePath, environment, cssContentCache);
88
89
  for (const file of styleCrawledFiles) {
89
90
  if (!file.includes("node_modules")) {
90
91
  this.addWatchFile(file);
@@ -113,7 +114,7 @@ function astroContentAssetPropagationPlugin({
113
114
  };
114
115
  }
115
116
  const INLINE_QUERY_REGEX = /(?:\?|&)inline(?:$|&)/;
116
- async function getStylesForURL(filePath, environment) {
117
+ async function getStylesForURL(filePath, environment, cssContentCache) {
117
118
  const importedCssUrls = /* @__PURE__ */ new Set();
118
119
  const importedStylesMap = /* @__PURE__ */ new Map();
119
120
  const crawledFiles = /* @__PURE__ */ new Set();
@@ -125,6 +126,8 @@ async function getStylesForURL(filePath, environment) {
125
126
  let css = "";
126
127
  if (typeof importedModule.ssrModule?.default === "string") {
127
128
  css = importedModule.ssrModule.default;
129
+ } else if (importedModule.id && cssContentCache?.has(importedModule.id)) {
130
+ css = cssContentCache.get(importedModule.id);
128
131
  } else {
129
132
  let modId = importedModule.url;
130
133
  if (!INLINE_QUERY_REGEX.test(importedModule.url)) {
@@ -1,6 +1,16 @@
1
- import type { Plugin as VitePlugin } from 'vite';
1
+ import type { BuildOptions, Plugin as VitePlugin, Rollup } from 'vite';
2
2
  import type { BuildInternals } from '../internal.js';
3
+ type GetModuleInfo = (moduleId: string) => Rollup.ModuleInfo | null;
4
+ export type ScriptChunkInfo = Pick<Rollup.OutputChunk, 'code' | 'facadeModuleId' | 'fileName' | 'imports' | 'dynamicImports' | 'moduleIds'>;
5
+ export declare function chunkHasDynamicImports(output: Pick<ScriptChunkInfo, 'dynamicImports' | 'moduleIds'>, getModuleInfo: GetModuleInfo): boolean;
6
+ export declare function shouldInlineScriptChunk(output: ScriptChunkInfo, { discoveredScripts, importedIds, assetInlineLimit, getModuleInfo, }: {
7
+ discoveredScripts: Set<string>;
8
+ importedIds: Set<string>;
9
+ assetInlineLimit: NonNullable<BuildOptions['assetsInlineLimit']>;
10
+ getModuleInfo: GetModuleInfo;
11
+ }): boolean;
3
12
  /**
4
13
  * Inline scripts from Astro files directly into the HTML.
5
14
  */
6
15
  export declare function pluginScripts(internals: BuildInternals): VitePlugin;
16
+ export {};
@@ -1,5 +1,18 @@
1
1
  import { shouldInlineAsset } from "./util.js";
2
2
  import { ASTRO_VITE_ENVIRONMENT_NAMES } from "../../constants.js";
3
+ function chunkHasDynamicImports(output, getModuleInfo) {
4
+ return output.dynamicImports.length > 0 || output.moduleIds.some((id) => (getModuleInfo(id)?.dynamicallyImportedIds.length ?? 0) > 0);
5
+ }
6
+ function shouldInlineScriptChunk(output, {
7
+ discoveredScripts,
8
+ importedIds,
9
+ assetInlineLimit,
10
+ getModuleInfo
11
+ }) {
12
+ const facadeModuleId = output.facadeModuleId;
13
+ if (facadeModuleId === null) return false;
14
+ return discoveredScripts.has(facadeModuleId) && !importedIds.has(output.fileName) && output.imports.length === 0 && !chunkHasDynamicImports(output, getModuleInfo) && shouldInlineAsset(output.code, output.fileName, assetInlineLimit);
15
+ }
3
16
  function pluginScripts(internals) {
4
17
  let assetInlineLimit;
5
18
  return {
@@ -20,8 +33,14 @@ function pluginScripts(internals) {
20
33
  }
21
34
  }
22
35
  }
36
+ const getModuleInfo = this.getModuleInfo.bind(this);
23
37
  for (const output of outputs) {
24
- if (output.type === "chunk" && output.facadeModuleId && internals.discoveredScripts.has(output.facadeModuleId) && !importedIds.has(output.fileName) && output.imports.length === 0 && output.dynamicImports.length === 0 && shouldInlineAsset(output.code, output.fileName, assetInlineLimit)) {
38
+ if (output.type === "chunk" && shouldInlineScriptChunk(output, {
39
+ discoveredScripts: internals.discoveredScripts,
40
+ importedIds,
41
+ assetInlineLimit,
42
+ getModuleInfo
43
+ })) {
25
44
  internals.inlinedScripts.set(output.facadeModuleId, output.code.trim());
26
45
  delete bundle[output.fileName];
27
46
  }
@@ -30,5 +49,7 @@ function pluginScripts(internals) {
30
49
  };
31
50
  }
32
51
  export {
33
- pluginScripts
52
+ chunkHasDynamicImports,
53
+ pluginScripts,
54
+ shouldInlineScriptChunk
34
55
  };
@@ -21,6 +21,11 @@ export declare function cssOrder(a: OrderInfo, b: OrderInfo): 1 | -1;
21
21
  /**
22
22
  * Merges inline CSS into as few stylesheets as possible,
23
23
  * preserving ordering when there are non-inlined in between.
24
+ *
25
+ * CSS chunks containing `@import` are never merged with other chunks.
26
+ * Per CSS spec, `@import` rules must appear at the top of a stylesheet
27
+ * or browsers silently ignore them. Keeping these chunks as separate
28
+ * `<style>` tags ensures the `@import` stays at the top of its own stylesheet.
24
29
  */
25
30
  export declare function mergeInlineCss(acc: Array<StylesheetAsset>, current: StylesheetAsset): Array<StylesheetAsset>;
26
31
  export {};
@@ -31,9 +31,13 @@ function mergeInlineCss(acc, current) {
31
31
  const lastWasInline = lastAdded?.type === "inline";
32
32
  const currentIsInline = current?.type === "inline";
33
33
  if (lastWasInline && currentIsInline) {
34
- const merged = { type: "inline", content: lastAdded.content + current.content };
35
- acc[acc.length - 1] = merged;
36
- return acc;
34
+ const currentHasImport = current.content.includes("@import");
35
+ const lastHasImport = lastAdded.content.includes("@import");
36
+ if (!currentHasImport && !lastHasImport) {
37
+ const merged = { type: "inline", content: lastAdded.content + current.content };
38
+ acc[acc.length - 1] = merged;
39
+ return acc;
40
+ }
37
41
  }
38
42
  acc.push(current);
39
43
  return acc;
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "7.0.6";
1
+ const ASTRO_VERSION = "7.0.7";
2
2
  const ASTRO_GENERATOR = `Astro v${ASTRO_VERSION}`;
3
3
  const ASTRO_ERROR_HEADER = "X-Astro-Error";
4
4
  const DEFAULT_404_COMPONENT = "astro-default-404.astro";
@@ -108,6 +108,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
108
108
  config: settings.config
109
109
  });
110
110
  const serverIslandsState = new ServerIslandsState();
111
+ const cssContentCache = /* @__PURE__ */ new Map();
111
112
  validateEnvPrefixAgainstSchema(settings.config);
112
113
  const commonConfig = {
113
114
  // Tell Vite not to combine config from vite.config.js with our provided inline config
@@ -156,7 +157,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
156
157
  vitePluginFetchable({ settings }),
157
158
  command === "dev" && vitePluginAstroServer({ settings, logger }),
158
159
  command === "dev" && vitePluginAstroServerClient(),
159
- astroDevCssPlugin({ routesList, command }),
160
+ astroDevCssPlugin({ routesList, command, cssContentCache }),
160
161
  importMetaEnv({ envLoader }),
161
162
  astroEnv({ settings, sync, envLoader }),
162
163
  vitePluginAdapterConfig(settings),
@@ -167,7 +168,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
167
168
  astroHeadPlugin(),
168
169
  astroContentVirtualModPlugin({ fs, settings }),
169
170
  astroContentImportPlugin({ fs, settings, logger }),
170
- astroContentAssetPropagationPlugin({ settings }),
171
+ astroContentAssetPropagationPlugin({ settings, cssContentCache }),
171
172
  vitePluginMiddleware({ settings }),
172
173
  astroAssetsPlugin({ fs, settings, sync, logger }),
173
174
  astroPrefetch({ settings }),
@@ -26,7 +26,7 @@ async function dev(inlineConfig) {
26
26
  await telemetry.record([]);
27
27
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
28
28
  const logger = restart.container.logger;
29
- const currentVersion = "7.0.6";
29
+ const currentVersion = "7.0.7";
30
30
  const isPrerelease = currentVersion.includes("-");
31
31
  if (!isPrerelease) {
32
32
  try {
@@ -269,7 +269,7 @@ function printHelp({
269
269
  message.push(
270
270
  linebreak(),
271
271
  ` ${bgGreen(black(` ${commandName} `))} ${green(
272
- `v${"7.0.6"}`
272
+ `v${"7.0.7"}`
273
273
  )} ${headline}`
274
274
  );
275
275
  }
@@ -44,9 +44,14 @@ async function getProps(opts) {
44
44
  }
45
45
  function getParams(route, pathname) {
46
46
  if (!route.params.length) return {};
47
- const path = pathname.endsWith(".html") && route.type === "page" && !routeHasHtmlExtension(route) ? pathname.slice(0, -5) : pathname;
47
+ const hasHtmlSuffix = pathname.endsWith(".html") && !routeHasHtmlExtension(route);
48
+ const path = hasHtmlSuffix && route.type === "page" ? pathname.slice(0, -".html".length) : pathname;
48
49
  const allPatterns = [route, ...route.fallbackRoutes].map((r) => r.pattern);
49
- const paramsMatch = allPatterns.map((pattern) => pattern.exec(path)).find((x) => x);
50
+ let paramsMatch = allPatterns.map((pattern) => pattern.exec(path)).find((x) => x);
51
+ if (!paramsMatch && hasHtmlSuffix && route.type !== "page") {
52
+ const strippedPath = pathname.endsWith("/index.html") ? pathname.slice(0, -"/index.html".length) || "/" : pathname.slice(0, -".html".length);
53
+ paramsMatch = allPatterns.map((pattern) => pattern.exec(strippedPath)).find((x) => x);
54
+ }
50
55
  if (!paramsMatch) return {};
51
56
  const params = {};
52
57
  route.params.forEach((key, i) => {
@@ -167,27 +167,31 @@ class AstroServerApp extends BaseApp {
167
167
  } else {
168
168
  socket.on("close", onSocketClose);
169
169
  }
170
- const request = createRequest({
171
- url,
172
- headers: incomingRequest.headers,
173
- method: incomingRequest.method,
174
- body,
175
- logger: self.logger,
176
- isPrerendered: matchedRoute.routeData.prerender,
177
- routePattern: matchedRoute.routeData.component,
178
- init: { signal: abortController.signal }
179
- });
180
- const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
181
- for (const [name, value] of Object.entries(self.settings.config.server.headers ?? {})) {
182
- if (value) incomingResponse.setHeader(name, value);
170
+ try {
171
+ const request = createRequest({
172
+ url,
173
+ headers: incomingRequest.headers,
174
+ method: incomingRequest.method,
175
+ body,
176
+ logger: self.logger,
177
+ isPrerendered: matchedRoute.routeData.prerender,
178
+ routePattern: matchedRoute.routeData.component,
179
+ init: { signal: abortController.signal }
180
+ });
181
+ const locals = Reflect.get(incomingRequest, clientLocalsSymbol);
182
+ for (const [name, value] of Object.entries(self.settings.config.server.headers ?? {})) {
183
+ if (value) incomingResponse.setHeader(name, value);
184
+ }
185
+ const clientAddress = incomingRequest.socket.remoteAddress;
186
+ const response = await self.render(request, {
187
+ locals,
188
+ routeData: matchedRoute.routeData,
189
+ clientAddress
190
+ });
191
+ await writeSSRResult(request, response, incomingResponse);
192
+ } finally {
193
+ socket.off("close", onSocketClose);
183
194
  }
184
- const clientAddress = incomingRequest.socket.remoteAddress;
185
- const response = await self.render(request, {
186
- locals,
187
- routeData: matchedRoute.routeData,
188
- clientAddress
189
- });
190
- await writeSSRResult(request, response, incomingResponse);
191
195
  },
192
196
  onError(_err) {
193
197
  const error = createSafeError(_err);
@@ -3,6 +3,11 @@ import type { RoutesList } from '../types/astro.js';
3
3
  interface AstroVitePluginOptions {
4
4
  routesList: RoutesList;
5
5
  command: 'dev' | 'build';
6
+ /** Shared cache of CSS content by module ID. Populated by the transform hook and
7
+ * consumed by the content asset propagation plugin to avoid re-processing CSS
8
+ * modules with `?inline` (which can produce different scoped-name hashes with
9
+ * Lightning CSS). */
10
+ cssContentCache: Map<string, string>;
6
11
  }
7
12
  /**
8
13
  * This plugin tracks the CSS that should be applied by route.
@@ -14,5 +19,5 @@ interface AstroVitePluginOptions {
14
19
  *
15
20
  * @param routesList
16
21
  */
17
- export declare function astroDevCssPlugin({ routesList, command }: AstroVitePluginOptions): Plugin[];
22
+ export declare function astroDevCssPlugin({ routesList, command, cssContentCache, }: AstroVitePluginOptions): Plugin[];
18
23
  export {};
@@ -60,9 +60,12 @@ function* collectCSSWithOrder(id, mod, seen = /* @__PURE__ */ new Set()) {
60
60
  }
61
61
  }
62
62
  }
63
- function astroDevCssPlugin({ routesList, command }) {
63
+ function astroDevCssPlugin({
64
+ routesList,
65
+ command,
66
+ cssContentCache
67
+ }) {
64
68
  let server;
65
- const cssContentCache = /* @__PURE__ */ new Map();
66
69
  function getCurrentEnvironment(pluginEnv) {
67
70
  return pluginEnv ?? server?.environments[ASTRO_VITE_ENVIRONMENT_NAMES.ssr];
68
71
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "7.0.6",
3
+ "version": "7.0.7",
4
4
  "description": "Astro is a modern site builder with web best practices, performance, and DX front-of-mind.",
5
5
  "type": "module",
6
6
  "author": "withastro",
@@ -146,9 +146,9 @@
146
146
  "xxhash-wasm": "^1.1.0",
147
147
  "yargs-parser": "^22.0.0",
148
148
  "zod": "^4.3.6",
149
- "@astrojs/internal-helpers": "0.10.1",
150
149
  "@astrojs/markdown-satteri": "0.3.3",
151
- "@astrojs/telemetry": "3.3.2"
150
+ "@astrojs/internal-helpers": "0.10.1",
151
+ "@astrojs/telemetry": "3.3.3"
152
152
  },
153
153
  "optionalDependencies": {
154
154
  "sharp": "^0.34.0 || ^0.35.0"
@@ -186,8 +186,8 @@
186
186
  "typescript": "^6.0.3",
187
187
  "undici": "^7.22.0",
188
188
  "vitest": "^4.1.0",
189
- "@astrojs/check": "0.9.9",
190
189
  "@astrojs/markdown-remark": "7.2.1",
190
+ "@astrojs/check": "0.9.9",
191
191
  "astro-scripts": "0.0.14"
192
192
  },
193
193
  "engines": {