astro 6.1.3 → 6.1.5

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.
Files changed (50) hide show
  1. package/dist/assets/consts.d.ts +2 -0
  2. package/dist/assets/consts.js +4 -0
  3. package/dist/assets/utils/index.d.ts +1 -1
  4. package/dist/assets/utils/index.js +1 -9
  5. package/dist/assets/utils/vendor/image-size/utils/bit-reader.d.ts +2 -2
  6. package/dist/assets/utils/vendor/image-size/utils/bit-reader.js +5 -3
  7. package/dist/assets/vite-plugin-assets.js +33 -3
  8. package/dist/cli/add/index.js +38 -55
  9. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  10. package/dist/cli/preferences/index.js +1 -1
  11. package/dist/content/content-layer.js +3 -3
  12. package/dist/content/loaders/errors.d.ts +2 -2
  13. package/dist/content/loaders/errors.js +3 -0
  14. package/dist/content/runtime.js +1 -1
  15. package/dist/core/app/base.js +1 -1
  16. package/dist/core/base-pipeline.d.ts +22 -35
  17. package/dist/core/base-pipeline.js +41 -8
  18. package/dist/core/build/generate.js +9 -1
  19. package/dist/core/build/pipeline.d.ts +3 -7
  20. package/dist/core/build/pipeline.js +30 -28
  21. package/dist/core/config/schemas/refined-validators.d.ts +44 -0
  22. package/dist/core/config/schemas/refined-validators.js +168 -0
  23. package/dist/core/config/schemas/refined.js +28 -141
  24. package/dist/core/constants.js +1 -1
  25. package/dist/core/cookies/cookies.js +1 -0
  26. package/dist/core/dev/dev.js +1 -1
  27. package/dist/core/dev/restart.js +63 -68
  28. package/dist/core/messages/runtime.js +1 -1
  29. package/dist/core/render-context.d.ts +2 -2
  30. package/dist/core/render-context.js +20 -0
  31. package/dist/core/routing/create-manifest.js +12 -4
  32. package/dist/core/routing/default.d.ts +2 -3
  33. package/dist/env/validators.d.ts +1 -1
  34. package/dist/integrations/features-validation.d.ts +3 -1
  35. package/dist/integrations/features-validation.js +2 -0
  36. package/dist/preferences/dlv.d.ts +1 -0
  37. package/dist/preferences/dlv.js +9 -0
  38. package/dist/preferences/index.js +1 -1
  39. package/dist/preferences/store.js +3 -2
  40. package/dist/runtime/server/render/component.js +6 -6
  41. package/dist/runtime/server/transition.d.ts +2 -2
  42. package/dist/runtime/server/transition.js +4 -2
  43. package/dist/transitions/swap-functions.js +1 -1
  44. package/dist/vite-plugin-app/pipeline.d.ts +4 -13
  45. package/dist/vite-plugin-app/pipeline.js +27 -12
  46. package/dist/vite-plugin-astro-server/base.d.ts +52 -0
  47. package/dist/vite-plugin-astro-server/base.js +66 -36
  48. package/dist/vite-plugin-astro-server/trailing-slash.d.ts +34 -0
  49. package/dist/vite-plugin-astro-server/trailing-slash.js +24 -11
  50. package/package.json +3 -5
@@ -3,26 +3,18 @@ import * as vite from "vite";
3
3
  import { globalContentLayer } from "../../content/instance.js";
4
4
  import { attachContentServerListeners } from "../../content/server-listeners.js";
5
5
  import { eventCliSession, telemetry } from "../../events/index.js";
6
+ import { runHookConfigDone, runHookConfigSetup } from "../../integrations/hooks.js";
6
7
  import { SETTINGS_FILE } from "../../preferences/constants.js";
8
+ import { getPrerenderDefault } from "../../prerender/utils.js";
7
9
  import { createSettings, resolveConfig } from "../config/index.js";
8
- import { createNodeLogger } from "../logger/node.js";
10
+ import { createVite } from "../create-vite.js";
9
11
  import { collectErrorMetadata } from "../errors/dev/utils.js";
10
12
  import { isAstroConfigZodError } from "../errors/errors.js";
11
13
  import { createSafeError } from "../errors/index.js";
14
+ import { createNodeLogger } from "../logger/node.js";
12
15
  import { formatErrorMessage, warnIfCspWithShiki } from "../messages/runtime.js";
13
- import { createContainer, startContainer } from "./container.js";
14
- async function createRestartedContainer(container, settings) {
15
- const { logger, fs, inlineConfig } = container;
16
- const newContainer = await createContainer({
17
- isRestart: true,
18
- logger,
19
- settings,
20
- inlineConfig,
21
- fs
22
- });
23
- await startContainer(newContainer);
24
- return newContainer;
25
- }
16
+ import { createRoutesList } from "../routing/create-manifest.js";
17
+ import { createContainer } from "./container.js";
26
18
  const configRE = /.*astro.config.(?:mjs|mts|cjs|cts|js|ts)$/;
27
19
  function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, changedFile) {
28
20
  if (restartInFlight) return false;
@@ -47,25 +39,41 @@ function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, cha
47
39
  }
48
40
  return shouldRestart;
49
41
  }
50
- async function restartContainer(container) {
51
- const { logger, close, settings: existingSettings } = container;
42
+ async function restartContainerInPlace(container) {
43
+ const { logger, settings: existingSettings, inlineConfig, fs } = container;
52
44
  container.restartInFlight = true;
53
45
  try {
54
- const { astroConfig } = await resolveConfig(container.inlineConfig, "dev", container.fs);
55
- if (astroConfig.security.csp) {
56
- logger.warn(
57
- "config",
58
- "Astro's Content Security Policy (CSP) does not work in development mode. To verify your CSP implementation, build the project and run the preview server."
59
- );
60
- }
46
+ const { astroConfig } = await resolveConfig(inlineConfig, "dev", fs);
61
47
  warnIfCspWithShiki(astroConfig, logger);
62
- const settings = await createSettings(
48
+ let settings = await createSettings(
63
49
  astroConfig,
64
- container.inlineConfig.logLevel,
50
+ inlineConfig.logLevel,
65
51
  fileURLToPath(existingSettings.config.root)
66
52
  );
67
- await close();
68
- return await createRestartedContainer(container, settings);
53
+ settings = await runHookConfigSetup({ settings, command: "dev", logger, isRestart: true });
54
+ if (!settings.adapter?.adapterFeatures?.buildOutput) {
55
+ settings.buildOutput = getPrerenderDefault(settings.config) ? "static" : "server";
56
+ }
57
+ await runHookConfigDone({ settings, logger, command: "dev" });
58
+ const mode = inlineConfig?.mode ?? "development";
59
+ const {
60
+ server: { host, headers, allowedHosts }
61
+ } = settings.config;
62
+ const rendererClientEntries = settings.renderers.map((r) => r.clientEntrypoint).filter(Boolean);
63
+ const routesList = await createRoutesList({ settings, fsMod: fs }, logger, { dev: true });
64
+ const address = container.viteServer.httpServer?.address();
65
+ const port = address !== null && typeof address === "object" ? address.port : void 0;
66
+ const newViteConfig = await createVite(
67
+ {
68
+ server: { host, headers, allowedHosts, port },
69
+ optimizeDeps: { include: rendererClientEntries }
70
+ },
71
+ { settings, logger, mode, command: "dev", fs, sync: false, routesList }
72
+ );
73
+ container.viteServer.config = await vite.resolveConfig(newViteConfig, "serve");
74
+ await container.viteServer.restart();
75
+ container.settings = settings;
76
+ return settings;
69
77
  } catch (_err) {
70
78
  const error = createSafeError(_err);
71
79
  if (!isAstroConfigZodError(_err)) {
@@ -74,16 +82,14 @@ async function restartContainer(container) {
74
82
  formatErrorMessage(collectErrorMetadata(error), logger.level() === "debug") + "\n"
75
83
  );
76
84
  }
77
- container.viteServer.environments.client.hot.send({
85
+ container.viteServer.environments?.client?.hot?.send({
78
86
  type: "error",
79
- err: {
80
- message: error.message,
81
- stack: error.stack || ""
82
- }
87
+ err: { message: error.message, stack: error.stack || "" }
83
88
  });
84
- container.restartInFlight = false;
85
89
  logger.error(null, "Continuing with previous valid configuration\n");
86
90
  return error;
91
+ } finally {
92
+ container.restartInFlight = false;
87
93
  }
88
94
  }
89
95
  async function createContainerWithAutomaticRestart({
@@ -92,12 +98,6 @@ async function createContainerWithAutomaticRestart({
92
98
  }) {
93
99
  const logger = createNodeLogger(inlineConfig ?? {});
94
100
  const { userConfig, astroConfig } = await resolveConfig(inlineConfig ?? {}, "dev", fs);
95
- if (astroConfig.security.csp) {
96
- logger.warn(
97
- "config",
98
- "Astro's Content Security Policy (CSP) does not work in development mode. To verify your CSP implementation, build the project and run the preview server."
99
- );
100
- }
101
101
  warnIfCspWithShiki(astroConfig, logger);
102
102
  telemetry.record(eventCliSession("dev", userConfig));
103
103
  const settings = await createSettings(
@@ -119,7 +119,6 @@ async function createContainerWithAutomaticRestart({
119
119
  container: initialContainer,
120
120
  bindCLIShortcuts() {
121
121
  const customShortcuts = [
122
- // Disable default Vite shortcuts that don't work well with Astro
123
122
  { key: "r", description: "" },
124
123
  { key: "u", description: "" },
125
124
  { key: "c", description: "" }
@@ -139,42 +138,38 @@ async function createContainerWithAutomaticRestart({
139
138
  return restartComplete;
140
139
  }
141
140
  };
142
- async function handleServerRestart(logMsg = "", server) {
143
- logger.info(null, (logMsg + " Restarting...").trim());
144
- const container = restart.container;
145
- const result = await restartContainer(container);
146
- if (result instanceof Error) {
147
- resolveRestart(result);
148
- } else {
149
- restart.container = result;
150
- setupContainer();
151
- await attachContentServerListeners(restart.container);
152
- if (server) {
153
- server.resolvedUrls = result.viteServer.resolvedUrls;
154
- }
155
- resolveRestart(null);
156
- }
157
- restartComplete = new Promise((resolve) => {
158
- resolveRestart = resolve;
159
- });
160
- }
161
141
  function handleChangeRestart(logMsg) {
162
142
  return async function(changedFile) {
163
143
  if (shouldRestartContainer(restart.container, changedFile)) {
164
- handleServerRestart(logMsg);
144
+ logger.info(null, (logMsg + " Restarting...").trim());
145
+ const result = await restartContainerInPlace(restart.container);
146
+ if (result instanceof Error) {
147
+ resolveRestart(result);
148
+ } else {
149
+ setupContainer();
150
+ await attachContentServerListeners(restart.container);
151
+ resolveRestart(null);
152
+ }
153
+ restartComplete = new Promise((resolve) => {
154
+ resolveRestart = resolve;
155
+ });
165
156
  }
166
157
  };
167
158
  }
159
+ let changeHandler;
160
+ let unlinkHandler;
161
+ let addHandler;
168
162
  function setupContainer() {
169
163
  const watcher = restart.container.viteServer.watcher;
170
- watcher.on("change", handleChangeRestart("Configuration file updated."));
171
- watcher.on("unlink", handleChangeRestart("Configuration file removed."));
172
- watcher.on("add", handleChangeRestart("Configuration file added."));
173
- restart.container.viteServer.restart = async () => {
174
- if (!restart.container.restartInFlight) {
175
- await handleServerRestart("", restart.container.viteServer);
176
- }
177
- };
164
+ if (changeHandler) watcher.off("change", changeHandler);
165
+ if (unlinkHandler) watcher.off("unlink", unlinkHandler);
166
+ if (addHandler) watcher.off("add", addHandler);
167
+ changeHandler = handleChangeRestart("Configuration file updated.");
168
+ unlinkHandler = handleChangeRestart("Configuration file removed.");
169
+ addHandler = handleChangeRestart("Configuration file added.");
170
+ watcher.on("change", changeHandler);
171
+ watcher.on("unlink", unlinkHandler);
172
+ watcher.on("add", addHandler);
178
173
  }
179
174
  setupContainer();
180
175
  return restart;
@@ -276,7 +276,7 @@ function printHelp({
276
276
  message.push(
277
277
  linebreak(),
278
278
  ` ${bgGreen(black(` ${commandName} `))} ${green(
279
- `v${"6.1.3"}`
279
+ `v${"6.1.5"}`
280
280
  )} ${headline}`
281
281
  );
282
282
  }
@@ -1,6 +1,6 @@
1
1
  import type { ActionAPIContext } from '../actions/runtime/types.js';
2
2
  import type { ComponentInstance } from '../types/astro.js';
3
- import type { MiddlewareHandler, Props } from '../types/public/common.js';
3
+ import type { MiddlewareHandler, Params, Props } from '../types/public/common.js';
4
4
  import type { APIContext, AstroGlobal } from '../types/public/context.js';
5
5
  import type { RouteData, SSRResult } from '../types/public/internal.js';
6
6
  import type { ServerIslandMappings, SSRActions } from './app/types.js';
@@ -26,7 +26,7 @@ export declare class RenderContext {
26
26
  status: number;
27
27
  clientAddress: string | undefined;
28
28
  protected cookies: AstroCookies;
29
- params: import("../types/public/common.js").Params;
29
+ params: Params;
30
30
  protected url: URL;
31
31
  props: Props;
32
32
  partial: undefined | boolean;
@@ -38,6 +38,26 @@ import { AstroSession } from "./session/runtime.js";
38
38
  import { collapseDuplicateSlashes } from "@astrojs/internal-helpers/path";
39
39
  import { validateAndDecodePathname } from "./util/pathname.js";
40
40
  class RenderContext {
41
+ pipeline;
42
+ locals;
43
+ middleware;
44
+ actions;
45
+ serverIslands;
46
+ // It must be a DECODED pathname
47
+ pathname;
48
+ request;
49
+ routeData;
50
+ status;
51
+ clientAddress;
52
+ cookies;
53
+ params;
54
+ url;
55
+ props;
56
+ partial;
57
+ shouldInjectCspMetaTags;
58
+ session;
59
+ cache;
60
+ skipMiddleware;
41
61
  constructor(pipeline, locals, middleware, actions, serverIslands, pathname, request, routeData, status, clientAddress, cookies = new AstroCookies(request), params = getParams(routeData, pathname), url = RenderContext.#createNormalizedUrl(request.url), props = {}, partial = void 0, shouldInjectCspMetaTags = pipeline.manifest.shouldInjectCspMetaTags, session = void 0, cache, skipMiddleware = false) {
42
62
  this.pipeline = pipeline;
43
63
  this.locals = locals;
@@ -158,7 +158,11 @@ function createFileBasedRoutes({ settings, cwd, fsMod }, logger) {
158
158
  } else {
159
159
  const component = item.file;
160
160
  const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
161
- const trailingSlash = trailingSlashForPath(pathname, settings.config);
161
+ const trailingSlash = trailingSlashForPath(
162
+ pathname,
163
+ settings.config,
164
+ item.isPage ? "page" : "endpoint"
165
+ );
162
166
  const pattern = getPattern(segments, settings.config.base, trailingSlash);
163
167
  const route = joinSegments(segments);
164
168
  routes.push({
@@ -273,7 +277,11 @@ function createRoutesFromEntriesByDir(entriesByDir, settings, logger, pagesDirRe
273
277
  } else {
274
278
  const component = item.file;
275
279
  const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
276
- const trailingSlash = trailingSlashForPath(pathname, settings.config);
280
+ const trailingSlash = trailingSlashForPath(
281
+ pathname,
282
+ settings.config,
283
+ item.isPage ? "page" : "endpoint"
284
+ );
277
285
  const pattern = getPattern(segments, settings.config.base, trailingSlash);
278
286
  const route = joinSegments(segments);
279
287
  routes.push({
@@ -312,7 +320,7 @@ function groupEntriesByDir(entries) {
312
320
  }
313
321
  return entriesByDir;
314
322
  }
315
- const trailingSlashForPath = (pathname, config) => pathname && hasFileExtension(pathname) ? "never" : config.trailingSlash;
323
+ const trailingSlashForPath = (pathname, config, type) => type === "endpoint" && pathname && hasFileExtension(pathname) ? "never" : config.trailingSlash;
316
324
  function createInjectedRoutes({ settings, cwd }) {
317
325
  const { config } = settings;
318
326
  const prerender = getPrerenderDefault(config);
@@ -326,7 +334,7 @@ function createInjectedRoutes({ settings, cwd }) {
326
334
  });
327
335
  const type = resolved.endsWith(".astro") ? "page" : "endpoint";
328
336
  const pathname = segments.every((segment) => segment.length === 1 && !segment[0].dynamic) ? `/${segments.map((segment) => segment[0].content).join("/")}` : null;
329
- const trailingSlash = trailingSlashForPath(pathname, config);
337
+ const trailingSlash = trailingSlashForPath(pathname, config, type);
330
338
  const pattern = getPattern(segments, settings.config.base, trailingSlash);
331
339
  const params = segments.flat().filter((p) => p.dynamic).map((p) => p.content);
332
340
  const route = joinSegments(segments);
@@ -1,11 +1,10 @@
1
1
  import type { ComponentInstance } from '../../types/astro.js';
2
2
  import type { SSRManifest } from '../app/types.js';
3
- type DefaultRouteParams = {
3
+ export interface DefaultRouteParams {
4
4
  instance: ComponentInstance;
5
5
  matchesComponent(filePath: URL): boolean;
6
6
  route: string;
7
7
  component: string;
8
- };
8
+ }
9
9
  export declare const DEFAULT_COMPONENTS: string[];
10
10
  export declare function createDefaultRoutes(manifest: SSRManifest): DefaultRouteParams[];
11
- export {};
@@ -1,6 +1,6 @@
1
1
  import type { AstroConfig } from '../types/public/index.js';
2
2
  import type { EnvFieldType } from './schema.js';
3
- export type ValidationResultValue = EnvFieldType['default'];
3
+ type ValidationResultValue = EnvFieldType['default'];
4
4
  export type ValidationResultErrors = ['missing'] | ['type'] | Array<string>;
5
5
  interface ValidationResultValid {
6
6
  ok: true;
@@ -1,6 +1,6 @@
1
1
  import type { Logger } from '../core/logger/core.js';
2
2
  import type { AstroSettings } from '../types/astro.js';
3
- import type { AstroAdapterFeatureMap } from '../types/public/integrations.js';
3
+ import type { AdapterSupport, AdapterSupportsKind, AstroAdapterFeatureMap } from '../types/public/integrations.js';
4
4
  export declare const AdapterFeatureStability: {
5
5
  readonly STABLE: "stable";
6
6
  readonly DEPRECATED: "deprecated";
@@ -19,5 +19,7 @@ type ValidationResult = {
19
19
  *
20
20
  */
21
21
  export declare function validateSupportedFeatures(adapterName: string, featureMap: AstroAdapterFeatureMap, settings: AstroSettings, logger: Logger): ValidationResult;
22
+ export declare function unwrapSupportKind(supportKind?: AdapterSupport): AdapterSupportsKind | undefined;
23
+ export declare function getSupportMessage(supportKind: AdapterSupport): string | undefined;
22
24
  export declare function getAdapterStaticRecommendation(adapterName: string): string | undefined;
23
25
  export {};
@@ -132,5 +132,7 @@ function getAdapterStaticRecommendation(adapterName) {
132
132
  export {
133
133
  AdapterFeatureStability,
134
134
  getAdapterStaticRecommendation,
135
+ getSupportMessage,
136
+ unwrapSupportKind,
135
137
  validateSupportedFeatures
136
138
  };
@@ -0,0 +1 @@
1
+ export default function dlv(obj: Record<string, unknown>, key: string): any;
@@ -0,0 +1,9 @@
1
+ function dlv(obj, key) {
2
+ for (const k of key.split(".")) {
3
+ obj = obj?.[k];
4
+ }
5
+ return obj;
6
+ }
7
+ export {
8
+ dlv as default
9
+ };
@@ -2,8 +2,8 @@ import os from "node:os";
2
2
  import path from "node:path";
3
3
  import process from "node:process";
4
4
  import { fileURLToPath } from "node:url";
5
- import dget from "dlv";
6
5
  import { DEFAULT_PREFERENCES } from "./defaults.js";
6
+ import dget from "./dlv.js";
7
7
  import { PreferenceStore } from "./store.js";
8
8
  function isValidKey(key) {
9
9
  return dget(DEFAULT_PREFERENCES, key) !== void 0;
@@ -1,14 +1,15 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
- import dget from "dlv";
4
3
  import { dset } from "dset";
5
4
  import { SETTINGS_FILE } from "./constants.js";
5
+ import dget from "./dlv.js";
6
6
  class PreferenceStore {
7
+ dir;
8
+ file;
7
9
  constructor(dir, filename = SETTINGS_FILE) {
8
10
  this.dir = dir;
9
11
  this.file = path.join(this.dir, filename);
10
12
  }
11
- file;
12
13
  _store;
13
14
  get store() {
14
15
  if (this._store) return this._store;
@@ -18,7 +18,7 @@ import { componentIsHTMLElement, renderHTMLElement } from "./dom.js";
18
18
  import { maybeRenderHead } from "./head.js";
19
19
  import { createRenderInstruction } from "./instruction.js";
20
20
  import { containsServerDirective, ServerIslandComponent } from "./server-islands.js";
21
- import { renderSlots, renderSlotToString } from "./slot.js";
21
+ import { renderSlot, renderSlots, renderSlotToString } from "./slot.js";
22
22
  import { formatList, internalSpreadAttributes, renderElement, voidElementNames } from "./util.js";
23
23
  const needsHeadRenderingSymbol = /* @__PURE__ */ Symbol.for("astro.needsHeadRendering");
24
24
  const rendererAliases = /* @__PURE__ */ new Map([["solid", "solid-js"]]);
@@ -331,12 +331,12 @@ function sanitizeElementName(tag) {
331
331
  if (!unsafe.test(tag)) return tag;
332
332
  return tag.trim().split(unsafe)[0].trim();
333
333
  }
334
- async function renderFragmentComponent(result, slots = {}) {
335
- const children = await renderSlotToString(result, slots?.default);
334
+ function renderFragmentComponent(result, slots = {}) {
335
+ const slot = slots?.default;
336
336
  return {
337
337
  render(destination) {
338
- if (children == null) return;
339
- destination.write(children);
338
+ if (slot == null) return;
339
+ return renderSlot(result, slot).render(destination);
340
340
  }
341
341
  };
342
342
  }
@@ -370,7 +370,7 @@ function renderComponent(result, displayName, Component, props, slots = {}) {
370
370
  });
371
371
  }
372
372
  if (isFragmentComponent(Component)) {
373
- return renderFragmentComponent(result, slots).catch(handleCancellation);
373
+ return renderFragmentComponent(result, slots);
374
374
  }
375
375
  props = normalizeProps(props);
376
376
  if (isHTMLComponent(Component)) {
@@ -9,10 +9,10 @@ export declare function createAnimationScope(transitionName: string, animations:
9
9
  styles: string;
10
10
  };
11
11
  export declare class ViewTransitionStyleSheet {
12
- private scope;
13
- private name;
14
12
  private modern;
15
13
  private fallback;
14
+ private scope;
15
+ private name;
16
16
  constructor(scope: string, name: string);
17
17
  toString(): string;
18
18
  private layer;
@@ -68,12 +68,14 @@ function createAnimationScope(transitionName, animations) {
68
68
  return { scope, styles: sheet.toString().replaceAll('"', "") };
69
69
  }
70
70
  class ViewTransitionStyleSheet {
71
+ modern = [];
72
+ fallback = [];
73
+ scope;
74
+ name;
71
75
  constructor(scope, name) {
72
76
  this.scope = scope;
73
77
  this.name = name;
74
78
  }
75
- modern = [];
76
- fallback = [];
77
79
  toString() {
78
80
  const { scope, name } = this;
79
81
  const [modern, fallback] = [this.modern, this.fallback].map((rules) => rules.join(""));
@@ -118,7 +118,7 @@ const persistedHeadElement = (el, newDoc) => {
118
118
  }
119
119
  if (import.meta.env.DEV && el.tagName === "STYLE") {
120
120
  const viteDevId = el.getAttribute("data-vite-dev-id");
121
- if (viteDevId) {
121
+ if (/\?vue&type=style&.*lang.css$/.test(viteDevId || "")) {
122
122
  return newDoc.head.querySelector(`style[data-vite-dev-id="${viteDevId}"]`);
123
123
  }
124
124
  }
@@ -1,26 +1,17 @@
1
1
  import { type HeadElements, Pipeline, type TryRewriteResult } from '../core/base-pipeline.js';
2
- import type { Logger } from '../core/logger/core.js';
3
2
  import type { ModuleLoader } from '../core/module-loader/index.js';
4
3
  import type { AstroSettings, ComponentInstance, RoutesList } from '../types/astro.js';
5
- import type { RewritePayload, RouteData, SSRLoadedRenderer, SSRManifest } from '../types/public/index.js';
4
+ import type { RewritePayload, RouteData, SSRLoadedRenderer } from '../types/public/index.js';
6
5
  /**
7
6
  * This Pipeline is used when the Vite SSR environment is runnable.
8
7
  */
9
8
  export declare class RunnablePipeline extends Pipeline {
10
- readonly loader: ModuleLoader;
11
- readonly logger: Logger;
12
- readonly manifest: SSRManifest;
13
- readonly settings: AstroSettings;
14
- readonly getDebugInfo: () => Promise<string>;
15
- readonly defaultRoutes: {
16
- instance: ComponentInstance;
17
- matchesComponent(filePath: URL): boolean;
18
- route: string;
19
- component: string;
20
- }[];
21
9
  getName(): string;
22
10
  renderers: SSRLoadedRenderer[];
23
11
  routesList: RoutesList | undefined;
12
+ readonly loader: ModuleLoader;
13
+ readonly settings: AstroSettings;
14
+ readonly getDebugInfo: () => Promise<string>;
24
15
  private constructor();
25
16
  static create(manifestData: RoutesList, { loader, logger, manifest, settings, getDebugInfo, }: Pick<RunnablePipeline, 'loader' | 'logger' | 'manifest' | 'settings' | 'getDebugInfo'>): RunnablePipeline;
26
17
  headElements(routeData: RouteData): Promise<HeadElements>;
@@ -5,7 +5,6 @@ import { enhanceViteSSRError } from "../core/errors/dev/index.js";
5
5
  import { AggregateError, CSSError, MarkdownError } from "../core/errors/index.js";
6
6
  import { RedirectComponentInstance } from "../core/redirects/index.js";
7
7
  import { loadRenderer } from "../core/render/index.js";
8
- import { createDefaultRoutes } from "../core/routing/default.js";
9
8
  import { routeIsRedirect } from "../core/routing/helpers.js";
10
9
  import { findRouteToRewrite } from "../core/routing/rewrite.js";
11
10
  import { isPage } from "../core/util.js";
@@ -16,17 +15,6 @@ import { newNodePool } from "../runtime/server/render/queue/pool.js";
16
15
  import { HTMLStringCache } from "../runtime/server/html-string-cache.js";
17
16
  import { queueRenderingEnabled } from "../core/app/manifest.js";
18
17
  class RunnablePipeline extends Pipeline {
19
- constructor(loader, logger, manifest, settings, getDebugInfo, defaultRoutes = createDefaultRoutes(manifest)) {
20
- const resolve = createResolve(loader, manifest.rootDir);
21
- const streaming = true;
22
- super(logger, manifest, "development", [], resolve, streaming);
23
- this.loader = loader;
24
- this.logger = logger;
25
- this.manifest = manifest;
26
- this.settings = settings;
27
- this.getDebugInfo = getDebugInfo;
28
- this.defaultRoutes = defaultRoutes;
29
- }
30
18
  getName() {
31
19
  return "RunnablePipeline";
32
20
  }
@@ -34,6 +22,33 @@ class RunnablePipeline extends Pipeline {
34
22
  // so it needs to be mutable here unlike in other environments
35
23
  renderers = new Array();
36
24
  routesList;
25
+ loader;
26
+ settings;
27
+ getDebugInfo;
28
+ constructor(loader, logger, manifest, settings, getDebugInfo, defaultRoutes) {
29
+ const resolve = createResolve(loader, manifest.rootDir);
30
+ const streaming = true;
31
+ super(
32
+ logger,
33
+ manifest,
34
+ "development",
35
+ [],
36
+ resolve,
37
+ streaming,
38
+ void 0,
39
+ void 0,
40
+ void 0,
41
+ void 0,
42
+ void 0,
43
+ void 0,
44
+ void 0,
45
+ void 0,
46
+ defaultRoutes
47
+ );
48
+ this.loader = loader;
49
+ this.settings = settings;
50
+ this.getDebugInfo = getDebugInfo;
51
+ }
37
52
  static create(manifestData, {
38
53
  loader,
39
54
  logger,
@@ -1,4 +1,56 @@
1
1
  import type * as vite from 'vite';
2
2
  import type { Logger } from '../core/logger/core.js';
3
3
  import type { AstroSettings } from '../types/astro.js';
4
+ /**
5
+ * Outcome of the base-URL evaluation for a dev-server request.
6
+ *
7
+ * - **`rewrite`** — The request URL starts with the configured `base` path.
8
+ * Strip the base prefix so downstream handlers see a root-relative URL
9
+ * (e.g. `/docs/about` → `/about` when `base: '/docs'`).
10
+ * - **`not-found-subpath`** — The user navigated to `/` or `/index.html` but
11
+ * the project has a non-root `base`. Respond with a 404 explaining that the
12
+ * site lives under the base path, so the developer knows to update the URL.
13
+ * - **`not-found`** — The URL doesn't start with the base and the browser
14
+ * expects HTML (`Accept: text/html`). Respond with a generic 404 page.
15
+ * - **`check-public`** — The URL doesn't match the base and the browser is
16
+ * requesting a non-HTML asset (image, script, font, etc.). The middleware
17
+ * must do an async `fs.stat` to decide whether the file exists in
18
+ * `publicDir` (and show a helpful base-path hint) or just pass through.
19
+ * This variant cannot be resolved purely.
20
+ */
21
+ export type BaseRewriteDecision = {
22
+ action: 'rewrite';
23
+ newUrl: string;
24
+ } | {
25
+ action: 'not-found-subpath';
26
+ pathname: string;
27
+ devRoot: string;
28
+ } | {
29
+ action: 'not-found';
30
+ pathname: string;
31
+ } | {
32
+ action: 'check-public';
33
+ };
34
+ /**
35
+ * Computes the `devRoot` path used to match and strip the base prefix.
36
+ *
37
+ * The `devRoot` is the pathname portion of the base URL (resolved against the
38
+ * `site` if present, otherwise against `http://localhost`). For example:
39
+ * - `base: '/docs'`, no site → `/docs`
40
+ * - `base: '/docs'`, `site: 'https://example.com'` → `/docs`
41
+ * - `base: '/'` → `/`
42
+ */
43
+ export declare function resolveDevRoot(base: string, site?: string): {
44
+ devRoot: string;
45
+ devRootReplacement: string;
46
+ };
47
+ /**
48
+ * Pure decision function for base-URL dev-server rewriting.
49
+ *
50
+ * Evaluates whether the incoming `url` starts with the project's `base` path
51
+ * and returns the action the middleware should take. The async `fs.stat` branch
52
+ * (checking `publicDir`) is represented as `check-public` and must be handled
53
+ * by the caller.
54
+ */
55
+ export declare function evaluateBaseRewrite(url: string, pathname: string, acceptHeader: string | undefined, devRoot: string, devRootReplacement: string): BaseRewriteDecision;
4
56
  export declare function baseMiddleware(settings: AstroSettings, logger: Logger): vite.Connect.NextHandleFunction;