astro 4.4.2 → 4.4.4

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.
@@ -212,7 +212,7 @@ export interface AstroGlobal<Props extends Record<string, any> = Record<string,
212
212
  * <Fragment set:html={html} />
213
213
  * ```
214
214
  *
215
- * A second parameters can be used to pass arguments to a slotted callback
215
+ * A second parameter can be used to pass arguments to a slotted callback
216
216
  *
217
217
  * Example usage:
218
218
  * ```astro
@@ -2459,6 +2459,7 @@ export interface PreviewServerParams {
2459
2459
  port: number;
2460
2460
  base: string;
2461
2461
  logger: AstroIntegrationLogger;
2462
+ headers?: OutgoingHttpHeaders;
2462
2463
  }
2463
2464
  export type CreatePreviewServer = (params: PreviewServerParams) => PreviewServer | Promise<PreviewServer>;
2464
2465
  export interface PreviewModule {
package/dist/cli/index.js CHANGED
@@ -12,6 +12,7 @@ async function printAstroHelp() {
12
12
  ["add", "Add an integration."],
13
13
  ["build", "Build your project and write it to disk."],
14
14
  ["check", "Check your project for errors."],
15
+ ["db", "Manage your Astro database."],
15
16
  ["dev", "Start the development server."],
16
17
  ["docs", "Open documentation in your web browser."],
17
18
  ["info", "List info about your current Astro setup."],
@@ -52,7 +53,11 @@ function resolveCommand(flags) {
52
53
  "check",
53
54
  "docs",
54
55
  "db",
55
- "info"
56
+ "info",
57
+ "login",
58
+ "loutout",
59
+ "link",
60
+ "init"
56
61
  ]);
57
62
  if (supportedCommands.has(cmd)) {
58
63
  return cmd;
@@ -108,7 +113,11 @@ async function runCommand(cmd, flags) {
108
113
  await add(packages, { flags });
109
114
  return;
110
115
  }
111
- case "db": {
116
+ case "db":
117
+ case "login":
118
+ case "logout":
119
+ case "link":
120
+ case "init": {
112
121
  const { db } = await import("./db/index.js");
113
122
  await db({ flags });
114
123
  return;
@@ -6,11 +6,22 @@ import prompts from "prompts";
6
6
  import resolvePackage from "resolve";
7
7
  import whichPm from "which-pm";
8
8
  import {} from "../core/logger/core.js";
9
+ import { createRequire } from "node:module";
10
+ import { sep } from "node:path";
11
+ const require2 = createRequire(import.meta.url);
9
12
  async function getPackage(packageName, logger, options, otherDeps = []) {
10
- let packageImport;
11
13
  try {
14
+ if (packageName === "@astrojs/db") {
15
+ const packageJsonLoc = require2.resolve(packageName + "/package.json", {
16
+ paths: [options.cwd ?? process.cwd()]
17
+ });
18
+ const packageLoc = packageJsonLoc.replace(`package.json`, "dist/index.js");
19
+ const packageImport2 = await import(packageLoc);
20
+ return packageImport2;
21
+ }
12
22
  await tryResolve(packageName, options.cwd ?? process.cwd());
13
- packageImport = await import(packageName);
23
+ const packageImport = await import(packageName);
24
+ return packageImport;
14
25
  } catch (e) {
15
26
  logger.info(
16
27
  null,
@@ -18,12 +29,12 @@ async function getPackage(packageName, logger, options, otherDeps = []) {
18
29
  );
19
30
  const result = await installPackage([packageName, ...otherDeps], options, logger);
20
31
  if (result) {
21
- packageImport = await import(packageName);
32
+ const packageImport = await import(packageName);
33
+ return packageImport;
22
34
  } else {
23
35
  return void 0;
24
36
  }
25
37
  }
26
- return packageImport;
27
38
  }
28
39
  function tryResolve(packageName, cwd) {
29
40
  return new Promise((resolve, reject) => {
@@ -8,12 +8,13 @@ interface AstroContentVirtualModPluginParams {
8
8
  fs: typeof nodeFs;
9
9
  }
10
10
  export declare function astroContentVirtualModPlugin({ settings, fs, }: AstroContentVirtualModPluginParams): Plugin;
11
- export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV, IS_SERVER, }: {
11
+ export declare function generateContentEntryFile({ settings, lookupMap, IS_DEV, IS_SERVER, isClient, }: {
12
12
  settings: AstroSettings;
13
13
  fs: typeof nodeFs;
14
14
  lookupMap: ContentLookupMap;
15
15
  IS_DEV: boolean;
16
16
  IS_SERVER: boolean;
17
+ isClient: boolean;
17
18
  }): Promise<string>;
18
19
  /**
19
20
  * Generate a map from a collection + slug to the local file path.
@@ -51,13 +51,21 @@ function astroContentVirtualModPlugin({
51
51
  }
52
52
  }
53
53
  },
54
- async load(id) {
54
+ async load(id, args) {
55
55
  if (id === RESOLVED_VIRTUAL_MODULE_ID) {
56
56
  const lookupMap = await generateLookupMap({
57
57
  settings,
58
58
  fs
59
59
  });
60
- const code = await generateContentEntryFile({ settings, fs, lookupMap, IS_DEV, IS_SERVER });
60
+ const isClient = !args?.ssr;
61
+ const code = await generateContentEntryFile({
62
+ settings,
63
+ fs,
64
+ lookupMap,
65
+ IS_DEV,
66
+ IS_SERVER,
67
+ isClient
68
+ });
61
69
  return {
62
70
  code,
63
71
  meta: {
@@ -89,7 +97,8 @@ async function generateContentEntryFile({
89
97
  settings,
90
98
  lookupMap,
91
99
  IS_DEV,
92
- IS_SERVER
100
+ IS_SERVER,
101
+ isClient
93
102
  }) {
94
103
  const contentPaths = getContentPaths(settings.config);
95
104
  const relContentDir = rootRelativePath(settings.config.root, contentPaths.contentDir);
@@ -122,7 +131,8 @@ async function generateContentEntryFile({
122
131
  dataEntryGlobResult = getStringifiedCollectionFromLookup("data", relContentDir, lookupMap);
123
132
  renderEntryGlobResult = getStringifiedCollectionFromLookup("render", relContentDir, lookupMap);
124
133
  }
125
- const virtualModContents = nodeFs.readFileSync(contentPaths.virtualModTemplate, "utf-8").replace("@@CONTENT_DIR@@", relContentDir).replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult).replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult).replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult).replace("/* @@LOOKUP_MAP_ASSIGNMENT@@ */", `lookupMap = ${JSON.stringify(lookupMap)};`);
134
+ let virtualModContents = nodeFs.readFileSync(contentPaths.virtualModTemplate, "utf-8").replace("@@CONTENT_DIR@@", relContentDir).replace("'@@CONTENT_ENTRY_GLOB_PATH@@'", contentEntryGlobResult).replace("'@@DATA_ENTRY_GLOB_PATH@@'", dataEntryGlobResult).replace("'@@RENDER_ENTRY_GLOB_PATH@@'", renderEntryGlobResult).replace("/* @@LOOKUP_MAP_ASSIGNMENT@@ */", `lookupMap = ${JSON.stringify(lookupMap)};`) + (isClient ? `
135
+ console.warn('astro:content is only supported running server-side. Using it in the browser will lead to bloated bundles and slow down page load. In the future it will not be supported.');` : "");
126
136
  return virtualModContents;
127
137
  }
128
138
  function getStringifiedCollectionFromLookup(wantedType, relContentDir, lookupMap) {
@@ -120,7 +120,8 @@ export default {}`
120
120
  fs: fsMod,
121
121
  lookupMap,
122
122
  IS_DEV: false,
123
- IS_SERVER: false
123
+ IS_SERVER: false,
124
+ isClient: false
124
125
  });
125
126
  this.emitFile({
126
127
  type: "prebuilt-chunk",
@@ -237,6 +237,7 @@ ${bgGreen(black(" building client (vite) "))}`);
237
237
  ...viteConfig.build,
238
238
  emptyOutDir: false,
239
239
  outDir: fileURLToPath(out),
240
+ copyPublicDir: ssr,
240
241
  rollupOptions: {
241
242
  ...viteConfig.build?.rollupOptions,
242
243
  input: Array.from(input),
@@ -9,8 +9,14 @@ export interface CompileProps {
9
9
  filename: string;
10
10
  source: string;
11
11
  }
12
- export interface CompileResult extends TransformResult {
13
- cssDeps: Set<string>;
14
- source: string;
12
+ export interface CompileCssResult {
13
+ code: string;
14
+ /**
15
+ * The dependencies of the transformed CSS (Normalized paths)
16
+ */
17
+ dependencies?: string[];
18
+ }
19
+ export interface CompileResult extends Omit<TransformResult, 'css'> {
20
+ css: CompileCssResult[];
15
21
  }
16
22
  export declare function compile({ astroConfig, viteConfig, preferences, filename, source, }: CompileProps): Promise<CompileResult>;
@@ -12,7 +12,7 @@ async function compile({
12
12
  filename,
13
13
  source
14
14
  }) {
15
- const cssDeps = /* @__PURE__ */ new Set();
15
+ const cssDeps = [];
16
16
  const cssTransformErrors = [];
17
17
  let transformResult;
18
18
  try {
@@ -50,8 +50,10 @@ async function compile({
50
50
  handleCompileResultErrors(transformResult, cssTransformErrors);
51
51
  return {
52
52
  ...transformResult,
53
- cssDeps,
54
- source
53
+ css: transformResult.css.map((code, i) => ({
54
+ code,
55
+ dependencies: cssDeps[i]
56
+ }))
55
57
  };
56
58
  }
57
59
  function handleCompileResultErrors(result, cssTransformErrors) {
@@ -1,8 +1,9 @@
1
1
  import type { TransformOptions } from '@astrojs/compiler';
2
2
  import { type ResolvedConfig } from 'vite';
3
+ import type { CompileCssResult } from './compile.js';
3
4
  export declare function createStylePreprocessor({ filename, viteConfig, cssDeps, cssTransformErrors, }: {
4
5
  filename: string;
5
6
  viteConfig: ResolvedConfig;
6
- cssDeps: Set<string>;
7
+ cssDeps: CompileCssResult['dependencies'][];
7
8
  cssTransformErrors: Error[];
8
9
  }): TransformOptions['preprocessStyle'];
@@ -1,5 +1,5 @@
1
1
  import fs from "node:fs";
2
- import { preprocessCSS } from "vite";
2
+ import { normalizePath, preprocessCSS } from "vite";
3
3
  import { AstroErrorData, CSSError, positionAt } from "../errors/index.js";
4
4
  function createStylePreprocessor({
5
5
  filename,
@@ -7,14 +7,16 @@ function createStylePreprocessor({
7
7
  cssDeps,
8
8
  cssTransformErrors
9
9
  }) {
10
+ let processedStylesCount = 0;
10
11
  return async (content, attrs) => {
12
+ const index = processedStylesCount++;
11
13
  const lang = `.${attrs?.lang || "css"}`.toLowerCase();
12
- const id = `${filename}?astro&type=style&lang${lang}`;
14
+ const id = `${filename}?astro&type=style&index=${index}&lang${lang}`;
13
15
  try {
14
16
  const result = await preprocessCSS(content, id, viteConfig);
15
- result.deps?.forEach((dep) => {
16
- cssDeps.add(dep);
17
- });
17
+ if (result.deps) {
18
+ cssDeps[index] = [...result.deps].map((dep) => normalizePath(dep));
19
+ }
18
20
  let map;
19
21
  if (result.map) {
20
22
  if (typeof result.map === "string") {
@@ -7,7 +7,7 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
7
7
  if (value == null) {
8
8
  continue;
9
9
  }
10
- const existing = merged[key];
10
+ let existing = merged[key];
11
11
  if (existing == null) {
12
12
  merged[key] = value;
13
13
  continue;
@@ -26,6 +26,11 @@ function mergeConfigRecursively(defaults, overrides, rootPath) {
26
26
  continue;
27
27
  }
28
28
  }
29
+ if (key === "data" && rootPath === "db") {
30
+ if (!Array.isArray(existing) && !Array.isArray(value)) {
31
+ existing = [existing];
32
+ }
33
+ }
29
34
  if (Array.isArray(existing) || Array.isArray(value)) {
30
35
  merged[key] = [...arraify(existing ?? []), ...arraify(value ?? [])];
31
36
  continue;
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.4.2";
1
+ const ASTRO_VERSION = "4.4.4";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const ROUTE_TYPE_HEADER = "X-Astro-Route-Type";
4
4
  const REROUTABLE_STATUS_CODES = [404, 500];
@@ -1,5 +1,6 @@
1
1
  import nodeFs from "node:fs";
2
2
  import { fileURLToPath } from "node:url";
3
+ import glob from "fast-glob";
3
4
  import * as vite from "vite";
4
5
  import { crawlFrameworkPkgs } from "vitefu";
5
6
  import astroAssetsPlugin from "../assets/vite-plugin-assets.js";
@@ -74,6 +75,7 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
74
75
  }
75
76
  }
76
77
  });
78
+ const srcDirPattern = glob.convertPathToPattern(fileURLToPath(settings.config.srcDir));
77
79
  const commonConfig = {
78
80
  // Tell Vite not to combine config from vite.config.js with our provided inline config
79
81
  configFile: false,
@@ -84,7 +86,17 @@ async function createVite(commandConfig, { settings, logger, mode, command, fs =
84
86
  customLogger: createViteLogger(logger, settings.config.vite.logLevel),
85
87
  appType: "custom",
86
88
  optimizeDeps: {
87
- entries: ["src/**/*"],
89
+ // Scan all files within `srcDir` except for known server-code (e.g endpoints)
90
+ entries: [
91
+ `${srcDirPattern}!(pages)/**/*`,
92
+ // All files except for pages
93
+ `${srcDirPattern}pages/**/!(*.js|*.mjs|*.ts|*.mts)`,
94
+ // All pages except for endpoints
95
+ `${srcDirPattern}pages/**/_*.{js,mjs,ts,mts}`,
96
+ // Remaining JS/TS files prefixed with `_` (not endpoints)
97
+ `${srcDirPattern}pages/**/_*/**/*.{js,mjs,ts,mts}`
98
+ // Remaining JS/TS files within directories prefixed with `_` (not endpoints)
99
+ ],
88
100
  exclude: ["astro", "node-fetch"]
89
101
  },
90
102
  plugins: [
@@ -23,7 +23,7 @@ async function dev(inlineConfig) {
23
23
  base: restart.container.settings.config.base
24
24
  })
25
25
  );
26
- const currentVersion = "4.4.2";
26
+ const currentVersion = "4.4.4";
27
27
  if (currentVersion.includes("-")) {
28
28
  logger.warn("SKIP_FORMAT", msg.prerelease({ currentVersion }));
29
29
  }
@@ -36,7 +36,7 @@ function serverStart({
36
36
  host,
37
37
  base
38
38
  }) {
39
- const version = "4.4.2";
39
+ const version = "4.4.4";
40
40
  const localPrefix = `${dim("\u2503")} Local `;
41
41
  const networkPrefix = `${dim("\u2503")} Network `;
42
42
  const emptyPrefix = " ".repeat(11);
@@ -261,7 +261,7 @@ function printHelp({
261
261
  message.push(
262
262
  linebreak(),
263
263
  ` ${bgGreen(black(` ${commandName} `))} ${green(
264
- `v${"4.4.2"}`
264
+ `v${"4.4.4"}`
265
265
  )} ${headline}`
266
266
  );
267
267
  }
@@ -58,7 +58,8 @@ async function preview(inlineConfig) {
58
58
  host: getResolvedHostForHttpServer(settings.config.server.host),
59
59
  port: settings.config.server.port,
60
60
  base: settings.config.base,
61
- logger: new AstroIntegrationLogger(logger.options, settings.adapter.name)
61
+ logger: new AstroIntegrationLogger(logger.options, settings.adapter.name),
62
+ headers: settings.config.server.headers
62
63
  });
63
64
  return server;
64
65
  }
@@ -43,6 +43,9 @@ function reEncode(s) {
43
43
  return reEncodeInValidStart[result.codePointAt(0) ?? 0] ? "_" + result : result;
44
44
  }
45
45
  function renderTransition(result, hash, animationName, transitionName) {
46
+ if (typeof (transitionName ?? "") !== "string") {
47
+ throw new Error(`Invalid transition name {${transitionName}}`);
48
+ }
46
49
  if (!animationName)
47
50
  animationName = "fade";
48
51
  const scope = createTransitionScope(result, hash);
@@ -5,6 +5,13 @@ const resolvedVirtualClientModuleId = "\0" + virtualClientModuleId;
5
5
  function astroTransitions({ settings }) {
6
6
  return {
7
7
  name: "astro:transitions",
8
+ config() {
9
+ return {
10
+ optimizeDeps: {
11
+ include: ["astro > cssesc"]
12
+ }
13
+ };
14
+ },
8
15
  async resolveId(id) {
9
16
  if (id === virtualModuleId) {
10
17
  return resolvedVirtualModuleId;
@@ -1,12 +1,9 @@
1
1
  import type { HmrContext } from 'vite';
2
2
  import type { Logger } from '../core/logger/core.js';
3
- import type { CompileAstroResult } from './compile.js';
4
3
  import type { CompileMetadata } from './types.js';
5
4
  export interface HandleHotUpdateOptions {
6
5
  logger: Logger;
7
- compile: (code: string, filename: string) => Promise<CompileAstroResult>;
8
- astroFileToCssAstroDeps: Map<string, Set<string>>;
9
6
  astroFileToCompileMetadata: Map<string, CompileMetadata>;
10
7
  }
11
- export declare function handleHotUpdate(ctx: HmrContext, { logger, compile, astroFileToCssAstroDeps, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
8
+ export declare function handleHotUpdate(ctx: HmrContext, { logger, astroFileToCompileMetadata }: HandleHotUpdateOptions): Promise<import("vite").ModuleNode[] | undefined>;
12
9
  export declare function isStyleOnlyChanged(oldCode: string, newCode: string): boolean;
@@ -1,26 +1,20 @@
1
- import path from "node:path";
2
- import { appendForwardSlash } from "@astrojs/internal-helpers/path";
3
1
  import { frontmatterRE } from "./utils.js";
4
- async function handleHotUpdate(ctx, { logger, compile, astroFileToCssAstroDeps, astroFileToCompileMetadata }) {
2
+ async function handleHotUpdate(ctx, { logger, astroFileToCompileMetadata }) {
3
+ for (const [astroFile, compileData] of astroFileToCompileMetadata) {
4
+ const isUpdatedFileCssDep = compileData.css.some((css) => css.dependencies?.includes(ctx.file));
5
+ if (isUpdatedFileCssDep) {
6
+ astroFileToCompileMetadata.delete(astroFile);
7
+ }
8
+ }
5
9
  const oldCode = astroFileToCompileMetadata.get(ctx.file)?.originalCode;
10
+ if (oldCode == null)
11
+ return;
6
12
  const newCode = await ctx.read();
7
- if (oldCode && isStyleOnlyChanged(oldCode, newCode)) {
13
+ if (isStyleOnlyChanged(oldCode, newCode)) {
8
14
  logger.debug("watch", "style-only change");
9
- await compile(newCode, ctx.file);
15
+ astroFileToCompileMetadata.delete(ctx.file);
10
16
  return ctx.modules.filter((mod) => mod.id?.includes("astro&type=style"));
11
17
  }
12
- for (const [astroFile, cssAstroDeps] of astroFileToCssAstroDeps) {
13
- if (cssAstroDeps.has(ctx.file)) {
14
- logger.info("watch", getShortName(ctx.file, ctx.server.config.root));
15
- const parentModules = ctx.server.moduleGraph.getModulesByFile(astroFile);
16
- if (parentModules) {
17
- for (const mod of parentModules) {
18
- ctx.server.moduleGraph.invalidateModule(mod);
19
- }
20
- }
21
- ctx.server.hot.send({ type: "full-reload", path: "*" });
22
- }
23
- }
24
18
  }
25
19
  const scriptRE = /<script(?:\s.*?)?>.*?<\/script>/gs;
26
20
  const styleRE = /<style(?:\s.*?)?>.*?<\/style>/gs;
@@ -58,9 +52,6 @@ function isArrayEqual(a, b) {
58
52
  }
59
53
  return true;
60
54
  }
61
- function getShortName(file, root) {
62
- return file.startsWith(appendForwardSlash(root)) ? path.posix.relative(root, file) : file;
63
- }
64
55
  export {
65
56
  handleHotUpdate,
66
57
  isStyleOnlyChanged
@@ -3,13 +3,13 @@ import { normalizeFilename } from "../vite-plugin-utils/index.js";
3
3
  import { compileAstro } from "./compile.js";
4
4
  import { handleHotUpdate } from "./hmr.js";
5
5
  import { parseAstroRequest } from "./query.js";
6
+ import { loadId } from "./utils.js";
6
7
  import { getAstroMetadata } from "./metadata.js";
7
8
  const astroFileToCompileMetadataWeakMap = /* @__PURE__ */ new WeakMap();
8
9
  function astro({ settings, logger }) {
9
10
  const { config } = settings;
10
11
  let server;
11
12
  let compile;
12
- let astroFileToCssAstroDeps = /* @__PURE__ */ new Map();
13
13
  let astroFileToCompileMetadata = /* @__PURE__ */ new Map();
14
14
  const srcRootWeb = config.srcDir.pathname.slice(config.root.pathname.length - 1);
15
15
  const isBrowserPath = (path) => path.startsWith(srcRootWeb) && srcRootWeb !== "/";
@@ -39,7 +39,6 @@ function astro({ settings, logger }) {
39
39
  });
40
40
  },
41
41
  buildStart() {
42
- astroFileToCssAstroDeps = /* @__PURE__ */ new Map();
43
42
  astroFileToCompileMetadata = /* @__PURE__ */ new Map();
44
43
  if (astroFileToCompileMetadataWeakMap.has(config)) {
45
44
  astroFileToCompileMetadata = astroFileToCompileMetadataWeakMap.get(config);
@@ -54,7 +53,13 @@ function astro({ settings, logger }) {
54
53
  return null;
55
54
  }
56
55
  const filename = normalizePath(normalizeFilename(parsedId.filename, config.root));
57
- const compileMetadata = astroFileToCompileMetadata.get(filename);
56
+ let compileMetadata = astroFileToCompileMetadata.get(filename);
57
+ if (!compileMetadata && server) {
58
+ const code = await loadId(server.pluginContainer, filename);
59
+ if (code != null)
60
+ await compile(code, filename);
61
+ compileMetadata = astroFileToCompileMetadata.get(filename);
62
+ }
58
63
  if (!compileMetadata) {
59
64
  throw new Error(
60
65
  `No cached compile metadata found for "${id}". The main Astro module "${filename}" should have compiled and filled the metadata first, before its virtual modules can be requested.`
@@ -65,11 +70,12 @@ function astro({ settings, logger }) {
65
70
  if (typeof query.index === "undefined") {
66
71
  throw new Error(`Requests for Astro CSS must include an index.`);
67
72
  }
68
- const code = compileMetadata.css[query.index];
69
- if (!code) {
73
+ const result = compileMetadata.css[query.index];
74
+ if (!result) {
70
75
  throw new Error(`No Astro CSS at index ${query.index}`);
71
76
  }
72
- return { code };
77
+ result.dependencies?.forEach((dep) => this.addWatchFile(dep));
78
+ return { code: result.code };
73
79
  }
74
80
  case "script": {
75
81
  if (typeof query.index === "undefined") {
@@ -130,25 +136,6 @@ File: ${id}`
130
136
  }
131
137
  const filename = normalizePath(parsedId.filename);
132
138
  const transformResult = await compile(source, filename);
133
- const astroDeps = /* @__PURE__ */ new Set();
134
- for (const dep of transformResult.cssDeps) {
135
- if (dep.endsWith(".astro")) {
136
- astroDeps.add(dep);
137
- }
138
- this.addWatchFile(dep);
139
- }
140
- astroFileToCssAstroDeps.set(id, astroDeps);
141
- if (server) {
142
- const mods = server.moduleGraph.getModulesByFile(filename);
143
- if (mods) {
144
- const seen = new Set(mods);
145
- for (const mod of mods) {
146
- if (mod.url.includes("?astro")) {
147
- server.moduleGraph.invalidateModule(mod, seen);
148
- }
149
- }
150
- }
151
- }
152
139
  const astroMetadata = {
153
140
  clientOnlyComponents: transformResult.clientOnlyComponents,
154
141
  hydratedComponents: transformResult.hydratedComponents,
@@ -171,14 +158,7 @@ File: ${id}`
171
158
  };
172
159
  },
173
160
  async handleHotUpdate(ctx) {
174
- if (!ctx.file.endsWith(".astro"))
175
- return;
176
- return handleHotUpdate(ctx, {
177
- logger,
178
- compile,
179
- astroFileToCssAstroDeps,
180
- astroFileToCompileMetadata
181
- });
161
+ return handleHotUpdate(ctx, { logger, astroFileToCompileMetadata });
182
162
  }
183
163
  };
184
164
  const normalPlugin = {
@@ -1,5 +1,6 @@
1
1
  import type { HoistedScript, TransformResult } from '@astrojs/compiler';
2
2
  import type { PropagationHint } from '../@types/astro.js';
3
+ import type { CompileCssResult } from '../core/compile/compile.js';
3
4
  export interface PageOptions {
4
5
  prerender?: boolean;
5
6
  }
@@ -17,7 +18,7 @@ export interface CompileMetadata {
17
18
  /** Used for HMR to compare code changes */
18
19
  originalCode: string;
19
20
  /** For Astro CSS virtual module */
20
- css: string[];
21
+ css: CompileCssResult[];
21
22
  /** For Astro hoisted scripts virtual module */
22
23
  scripts: HoistedScript[];
23
24
  }
@@ -1 +1,3 @@
1
+ import type { PluginContainer } from 'vite';
1
2
  export declare const frontmatterRE: RegExp;
3
+ export declare function loadId(pluginContainer: PluginContainer, id: string): Promise<string | undefined>;
@@ -1,4 +1,20 @@
1
+ import fs from "node:fs/promises";
1
2
  const frontmatterRE = /^---(.*?)^---/ms;
3
+ async function loadId(pluginContainer, id) {
4
+ const result = await pluginContainer.load(id, { ssr: true });
5
+ if (result) {
6
+ if (typeof result === "string") {
7
+ return result;
8
+ } else {
9
+ return result.code;
10
+ }
11
+ }
12
+ try {
13
+ return await fs.readFile(id, "utf-8");
14
+ } catch {
15
+ }
16
+ }
2
17
  export {
3
- frontmatterRE
18
+ frontmatterRE,
19
+ loadId
4
20
  };
@@ -61,8 +61,7 @@ async function writeWebResponse(res, webResponse) {
61
61
  } else {
62
62
  const reader = body.getReader();
63
63
  res.on("close", () => {
64
- reader.cancel().catch((error) => {
65
- console.error("An unexpected error occurred in the middle of the stream.", error);
64
+ reader.cancel().catch(() => {
66
65
  });
67
66
  });
68
67
  while (true) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.4.2",
3
+ "version": "4.4.4",
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",