astro 4.15.2 → 4.15.3

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.
@@ -48,9 +48,9 @@ function getFullImagePath(originalFilePath, env) {
48
48
  return new URL(removeLeadingForwardSlash(originalFilePath), env.serverRoot);
49
49
  }
50
50
  async function generateImagesForPath(originalFilePath, transformsAndPath, env, queue) {
51
- const originalImageData = await loadImage(originalFilePath, env);
51
+ let originalImage;
52
52
  for (const [_, transform] of transformsAndPath.transforms) {
53
- await queue.add(async () => generateImage(originalImageData, transform.finalPath, transform.transform)).catch((e) => {
53
+ await queue.add(async () => generateImage(transform.finalPath, transform.transform)).catch((e) => {
54
54
  throw e;
55
55
  });
56
56
  }
@@ -66,9 +66,9 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env, q
66
66
  } catch {
67
67
  }
68
68
  }
69
- async function generateImage(originalImage, filepath, options) {
69
+ async function generateImage(filepath, options) {
70
70
  const timeStart = performance.now();
71
- const generationData = await generateImageInternal(originalImage, filepath, options);
71
+ const generationData = await generateImageInternal(filepath, options);
72
72
  const timeEnd = performance.now();
73
73
  const timeChange = getTimeStat(timeStart, timeEnd);
74
74
  const timeIncrease = `(+${timeChange})`;
@@ -80,7 +80,7 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env, q
80
80
  );
81
81
  env.count.current++;
82
82
  }
83
- async function generateImageInternal(originalImage, filepath, options) {
83
+ async function generateImageInternal(filepath, options) {
84
84
  const isLocalImage = isESMImportedImage(options.src);
85
85
  const finalFileURL = new URL("." + filepath, env.clientRoot);
86
86
  const cacheFile = basename(filepath) + (isLocalImage ? "" : ".json");
@@ -116,6 +116,9 @@ async function generateImagesForPath(originalFilePath, transformsAndPath, env, q
116
116
  const finalFolderURL = new URL("./", finalFileURL);
117
117
  await fs.promises.mkdir(finalFolderURL, { recursive: true });
118
118
  const originalImagePath = isLocalImage ? options.src.src : options.src;
119
+ if (!originalImage) {
120
+ originalImage = await loadImage(originalFilePath, env);
121
+ }
119
122
  let resultData = {
120
123
  data: void 0,
121
124
  expires: originalImage.expires
@@ -33,6 +33,12 @@ export declare class ContentLayer {
33
33
  export declare function simpleLoader<TData extends {
34
34
  id: string;
35
35
  }>(handler: () => Array<TData> | Promise<Array<TData>>, context: LoaderContext): Promise<void>;
36
+ /**
37
+ * Get the path to the data store file.
38
+ * During development, this is in the `.astro` directory so that the Vite watcher can see it.
39
+ * In production, it's in the cache directory so that it's preserved between builds.
40
+ */
41
+ export declare function getDataStoreFile(settings: AstroSettings, isDev?: boolean): URL;
36
42
  export declare const globalContentLayer: {
37
43
  init: (options: ContentLayerOptions) => ContentLayer;
38
44
  get: () => ContentLayer | null;
@@ -170,7 +170,7 @@ class ContentLayer {
170
170
  if (!existsSync(this.#settings.config.cacheDir)) {
171
171
  await fs.mkdir(this.#settings.config.cacheDir, { recursive: true });
172
172
  }
173
- const cacheFile = new URL(DATA_STORE_FILE, this.#settings.config.cacheDir);
173
+ const cacheFile = getDataStoreFile(this.#settings);
174
174
  await this.#store.writeToDisk(cacheFile);
175
175
  if (!existsSync(this.#settings.dotAstroDir)) {
176
176
  await fs.mkdir(this.#settings.dotAstroDir, { recursive: true });
@@ -224,6 +224,10 @@ async function simpleLoader(handler, context) {
224
224
  context.store.set({ id: raw.id, data: item });
225
225
  }
226
226
  }
227
+ function getDataStoreFile(settings, isDev) {
228
+ isDev ??= process?.env.NODE_ENV === "development";
229
+ return new URL(DATA_STORE_FILE, isDev ? settings.dotAstroDir : settings.config.cacheDir);
230
+ }
227
231
  function contentLayerSingleton() {
228
232
  let instance = null;
229
233
  return {
@@ -242,6 +246,7 @@ function contentLayerSingleton() {
242
246
  const globalContentLayer = contentLayerSingleton();
243
247
  export {
244
248
  ContentLayer,
249
+ getDataStoreFile,
245
250
  globalContentLayer,
246
251
  simpleLoader
247
252
  };
@@ -39,6 +39,9 @@ class DataStore {
39
39
  static async fromModule() {
40
40
  try {
41
41
  const data = await import("astro:data-layer-content");
42
+ if (data.default instanceof Map) {
43
+ return DataStore.fromMap(data.default);
44
+ }
42
45
  const map = devalue.unflatten(data.default);
43
46
  return DataStore.fromMap(map);
44
47
  } catch {
@@ -17,7 +17,6 @@ import {
17
17
  CONTENT_FLAG,
18
18
  CONTENT_RENDER_FLAG,
19
19
  DATA_FLAG,
20
- DATA_STORE_FILE,
21
20
  DATA_STORE_VIRTUAL_ID,
22
21
  MODULES_IMPORTS_FILE,
23
22
  MODULES_MJS_ID,
@@ -26,6 +25,7 @@ import {
26
25
  RESOLVED_VIRTUAL_MODULE_ID,
27
26
  VIRTUAL_MODULE_ID
28
27
  } from "./consts.js";
28
+ import { getDataStoreFile } from "./content-layer.js";
29
29
  import {
30
30
  getContentEntryIdAndSlug,
31
31
  getContentPaths,
@@ -44,12 +44,13 @@ function astroContentVirtualModPlugin({
44
44
  }) {
45
45
  let IS_DEV = false;
46
46
  const IS_SERVER = isServerLikeOutput(settings.config);
47
- const dataStoreFile = new URL(DATA_STORE_FILE, settings.config.cacheDir);
47
+ let dataStoreFile;
48
48
  return {
49
49
  name: "astro-content-virtual-mod-plugin",
50
50
  enforce: "pre",
51
51
  configResolved(config) {
52
52
  IS_DEV = config.mode === "development";
53
+ dataStoreFile = getDataStoreFile(settings, IS_DEV);
53
54
  },
54
55
  async resolveId(id) {
55
56
  if (id === VIRTUAL_MODULE_ID) {
@@ -161,20 +162,25 @@ function astroContentVirtualModPlugin({
161
162
  },
162
163
  configureServer(server) {
163
164
  const dataStorePath = fileURLToPath(dataStoreFile);
164
- if (Array.isArray(server.watcher.options.ignored)) {
165
- server.watcher.options.ignored.push(`!${dataStorePath}`);
166
- }
167
165
  server.watcher.add(dataStorePath);
166
+ function invalidateDataStore() {
167
+ const module = server.moduleGraph.getModuleById(RESOLVED_DATA_STORE_VIRTUAL_ID);
168
+ if (module) {
169
+ server.moduleGraph.invalidateModule(module);
170
+ }
171
+ server.ws.send({
172
+ type: "full-reload",
173
+ path: "*"
174
+ });
175
+ }
176
+ server.watcher.on("add", (addedPath) => {
177
+ if (addedPath === dataStorePath) {
178
+ invalidateDataStore();
179
+ }
180
+ });
168
181
  server.watcher.on("change", (changedPath) => {
169
182
  if (changedPath === dataStorePath) {
170
- const module = server.moduleGraph.getModuleById(RESOLVED_DATA_STORE_VIRTUAL_ID);
171
- if (module) {
172
- server.moduleGraph.invalidateModule(module);
173
- }
174
- server.ws.send({
175
- type: "full-reload",
176
- path: "*"
177
- });
183
+ invalidateDataStore();
178
184
  }
179
185
  });
180
186
  }
@@ -31,6 +31,7 @@ async function build(inlineConfig, options = {}) {
31
31
  const logger = createNodeLogger(inlineConfig);
32
32
  const { userConfig, astroConfig } = await resolveConfig(inlineConfig, "build");
33
33
  telemetry.record(eventCliSession("build", userConfig));
34
+ const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
34
35
  if (inlineConfig.force) {
35
36
  if (astroConfig.experimental.contentCollectionCache) {
36
37
  const contentCacheDir = new URL("./content/", astroConfig.cacheDir);
@@ -40,9 +41,8 @@ async function build(inlineConfig, options = {}) {
40
41
  logger.warn("content", "content cache cleared (force)");
41
42
  }
42
43
  }
43
- await clearContentLayerCache({ astroConfig, logger, fs });
44
+ await clearContentLayerCache({ settings, logger, fs });
44
45
  }
45
- const settings = await createSettings(astroConfig, fileURLToPath(astroConfig.root));
46
46
  const builder = new AstroBuilder(settings, {
47
47
  ...options,
48
48
  logger,
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "4.15.2";
1
+ const ASTRO_VERSION = "4.15.3";
2
2
  const REROUTE_DIRECTIVE_HEADER = "X-Astro-Reroute";
3
3
  const REWRITE_DIRECTIVE_HEADER_KEY = "X-Astro-Rewrite";
4
4
  const REWRITE_DIRECTIVE_HEADER_VALUE = "yes";
@@ -2,8 +2,7 @@ import fs, { existsSync } from "node:fs";
2
2
  import { performance } from "node:perf_hooks";
3
3
  import { green } from "kleur/colors";
4
4
  import { gt, major, minor, patch } from "semver";
5
- import { DATA_STORE_FILE } from "../../content/consts.js";
6
- import { globalContentLayer } from "../../content/content-layer.js";
5
+ import { getDataStoreFile, globalContentLayer } from "../../content/content-layer.js";
7
6
  import { attachContentServerListeners } from "../../content/index.js";
8
7
  import { MutableDataStore } from "../../content/mutable-data-store.js";
9
8
  import { globalContentConfigObserver } from "../../content/utils.js";
@@ -23,7 +22,7 @@ async function dev(inlineConfig) {
23
22
  await telemetry.record([]);
24
23
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
25
24
  const logger = restart.container.logger;
26
- const currentVersion = "4.15.2";
25
+ const currentVersion = "4.15.3";
27
26
  const isPrerelease = currentVersion.includes("-");
28
27
  if (!isPrerelease) {
29
28
  try {
@@ -70,7 +69,7 @@ async function dev(inlineConfig) {
70
69
  await attachContentServerListeners(restart.container);
71
70
  let store;
72
71
  try {
73
- const dataStoreFile = new URL(DATA_STORE_FILE, restart.container.settings.config.cacheDir);
72
+ const dataStoreFile = getDataStoreFile(restart.container.settings);
74
73
  if (existsSync(dataStoreFile)) {
75
74
  store = await MutableDataStore.fromFile(dataStoreFile);
76
75
  }
@@ -7,7 +7,7 @@ export type LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
7
7
  * rather than specific to a single command, function, use, etc. The label will be
8
8
  * shown in the log message to the user, so it should be relevant.
9
9
  */
10
- export type LoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'toolbar' | 'assets' | 'env' | 'update' | 'SKIP_FORMAT';
10
+ export type LoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'sync' | 'toolbar' | 'assets' | 'env' | 'update' | 'SKIP_FORMAT';
11
11
  export interface LogOptions {
12
12
  dest: LogWritable<LogMessage>;
13
13
  level: LoggerLevel;
@@ -38,7 +38,7 @@ function serverStart({
38
38
  host,
39
39
  base
40
40
  }) {
41
- const version = "4.15.2";
41
+ const version = "4.15.3";
42
42
  const localPrefix = `${dim("\u2503")} Local `;
43
43
  const networkPrefix = `${dim("\u2503")} Network `;
44
44
  const emptyPrefix = " ".repeat(11);
@@ -270,7 +270,7 @@ function printHelp({
270
270
  message.push(
271
271
  linebreak(),
272
272
  ` ${bgGreen(black(` ${commandName} `))} ${green(
273
- `v${"4.15.2"}`
273
+ `v${"4.15.3"}`
274
274
  )} ${headline}`
275
275
  );
276
276
  }
@@ -1,5 +1,5 @@
1
1
  import fsMod from 'node:fs';
2
- import type { AstroConfig, AstroInlineConfig, AstroSettings } from '../../@types/astro.js';
2
+ import type { AstroInlineConfig, AstroSettings } from '../../@types/astro.js';
3
3
  import type { Logger } from '../logger/core.js';
4
4
  export type SyncOptions = {
5
5
  logger: Logger;
@@ -16,8 +16,8 @@ export default function sync(inlineConfig: AstroInlineConfig, { fs, telemetry: _
16
16
  /**
17
17
  * Clears the content layer and content collection cache, forcing a full rebuild.
18
18
  */
19
- export declare function clearContentLayerCache({ astroConfig, logger, fs, }: {
20
- astroConfig: AstroConfig;
19
+ export declare function clearContentLayerCache({ settings, logger, fs, }: {
20
+ settings: AstroSettings;
21
21
  logger: Logger;
22
22
  fs?: typeof fsMod;
23
23
  }): Promise<void>;
@@ -3,8 +3,8 @@ import { performance } from "node:perf_hooks";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { dim } from "kleur/colors";
5
5
  import { createServer } from "vite";
6
- import { CONTENT_TYPES_FILE, DATA_STORE_FILE } from "../../content/consts.js";
7
- import { globalContentLayer } from "../../content/content-layer.js";
6
+ import { CONTENT_TYPES_FILE } from "../../content/consts.js";
7
+ import { getDataStoreFile, globalContentLayer } from "../../content/content-layer.js";
8
8
  import { createContentTypesGenerator } from "../../content/index.js";
9
9
  import { MutableDataStore } from "../../content/mutable-data-store.js";
10
10
  import { getContentPaths, globalContentConfigObserver } from "../../content/utils.js";
@@ -41,15 +41,23 @@ async function sync(inlineConfig, { fs, telemetry: _telemetry = false } = {}) {
41
41
  settings,
42
42
  logger
43
43
  });
44
- await runHookConfigDone({ settings, logger });
44
+ try {
45
+ await runHookConfigDone({ settings, logger });
46
+ } catch (err) {
47
+ if (err instanceof Error) {
48
+ const errorMessage = err.toString();
49
+ logger.error("sync", errorMessage);
50
+ }
51
+ throw err;
52
+ }
45
53
  return await syncInternal({ settings, logger, fs, force: inlineConfig.force });
46
54
  }
47
55
  async function clearContentLayerCache({
48
- astroConfig,
56
+ settings,
49
57
  logger,
50
58
  fs = fsMod
51
59
  }) {
52
- const dataStore = new URL(DATA_STORE_FILE, astroConfig.cacheDir);
60
+ const dataStore = getDataStoreFile(settings);
53
61
  if (fs.existsSync(dataStore)) {
54
62
  logger.debug("content", "clearing data store");
55
63
  await fs.promises.rm(dataStore, { force: true });
@@ -64,7 +72,7 @@ async function syncInternal({
64
72
  force
65
73
  }) {
66
74
  if (force) {
67
- await clearContentLayerCache({ astroConfig: settings.config, logger, fs });
75
+ await clearContentLayerCache({ settings, logger, fs });
68
76
  }
69
77
  const timerStart = performance.now();
70
78
  try {
@@ -73,7 +81,7 @@ async function syncInternal({
73
81
  settings.timer.start("Sync content layer");
74
82
  let store;
75
83
  try {
76
- const dataStoreFile = new URL(DATA_STORE_FILE, settings.config.cacheDir);
84
+ const dataStoreFile = getDataStoreFile(settings);
77
85
  if (existsSync(dataStoreFile)) {
78
86
  store = await MutableDataStore.fromFile(dataStoreFile);
79
87
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.15.2",
3
+ "version": "4.15.3",
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",
@@ -164,7 +164,7 @@
164
164
  "unist-util-visit": "^5.0.0",
165
165
  "vfile": "^6.0.3",
166
166
  "vite": "^5.4.2",
167
- "vitefu": "^0.2.5",
167
+ "vitefu": "^1.0.2",
168
168
  "which-pm": "^3.0.0",
169
169
  "xxhash-wasm": "^1.0.2",
170
170
  "yargs-parser": "^21.1.1",
@@ -182,8 +182,6 @@
182
182
  "@astrojs/check": "^0.9.3",
183
183
  "@playwright/test": "^1.46.1",
184
184
  "@types/aria-query": "^5.0.4",
185
- "@types/babel__generator": "^7.6.8",
186
- "@types/babel__traverse": "^7.20.6",
187
185
  "@types/common-ancestor-path": "^1.0.2",
188
186
  "@types/cssesc": "^3.0.2",
189
187
  "@types/debug": "^4.1.12",