astro 3.1.2 → 3.1.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.
@@ -219,13 +219,13 @@ const { fallback = 'animate' } = Astro.props as Props;
219
219
  for (const s2 of newDocument.scripts) {
220
220
  if (
221
221
  // Inline
222
- (s1.textContent && s1.textContent === s2.textContent) ||
222
+ (!s1.src && s1.textContent === s2.textContent) ||
223
223
  // External
224
- (s1.type === s2.type && s1.src === s2.src)
224
+ (s1.src && s1.type === s2.type && s1.src === s2.src)
225
225
  ) {
226
- s2.remove();
227
- } else {
228
- s1.remove();
226
+ // the old script is in the new document: we mark it as executed to prevent re-execution
227
+ s2.dataset.astroExec = '';
228
+ break;
229
229
  }
230
230
  }
231
231
  }
@@ -70,7 +70,7 @@ export const getEntryBySlug = createGetEntryBySlug({
70
70
  });
71
71
 
72
72
  export const getDataEntryById = createGetDataEntryById({
73
- dataCollectionToEntryMap,
73
+ getEntryImport: createGlobLookup(dataCollectionToEntryMap),
74
74
  });
75
75
 
76
76
  export const getEntry = createGetEntry({
@@ -1,5 +1,4 @@
1
1
  import type { MarkdownHeading } from '@astrojs/markdown-remark';
2
- import type { AstroIntegration } from '../@types/astro.js';
3
2
  import { type AstroComponentFactory } from '../runtime/server/index.js';
4
3
  import type { ContentLookupMap } from './utils.js';
5
4
  type LazyImport = () => Promise<any>;
@@ -14,7 +13,7 @@ export declare function createGetCollection({ contentCollectionToEntryMap, dataC
14
13
  contentCollectionToEntryMap: CollectionToEntryMap;
15
14
  dataCollectionToEntryMap: CollectionToEntryMap;
16
15
  getRenderEntryImport: GetEntryImport;
17
- }): (collection: string, filter?: ((entry: any) => unknown) | undefined) => Promise<any[] | AstroIntegration>;
16
+ }): (collection: string, filter?: ((entry: any) => unknown) | undefined) => Promise<any[] | undefined>;
18
17
  export declare function createGetEntryBySlug({ getEntryImport, getRenderEntryImport, }: {
19
18
  getEntryImport: GetEntryImport;
20
19
  getRenderEntryImport: GetEntryImport;
@@ -26,8 +25,8 @@ export declare function createGetEntryBySlug({ getEntryImport, getRenderEntryImp
26
25
  data: any;
27
26
  render(): Promise<RenderResult>;
28
27
  } | undefined>;
29
- export declare function createGetDataEntryById({ dataCollectionToEntryMap, }: {
30
- dataCollectionToEntryMap: CollectionToEntryMap;
28
+ export declare function createGetDataEntryById({ getEntryImport }: {
29
+ getEntryImport: GetEntryImport;
31
30
  }): (collection: string, id: string) => Promise<{
32
31
  id: any;
33
32
  collection: any;
@@ -39,7 +39,10 @@ function createGetCollection({
39
39
  } else if (collection in dataCollectionToEntryMap) {
40
40
  type = "data";
41
41
  } else {
42
- return warnOfEmptyCollection(collection);
42
+ console.warn(
43
+ `The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`
44
+ );
45
+ return;
43
46
  }
44
47
  const lazyImports = Object.values(
45
48
  type === "content" ? contentCollectionToEntryMap[collection] : dataCollectionToEntryMap[collection]
@@ -105,14 +108,9 @@ function createGetEntryBySlug({
105
108
  };
106
109
  };
107
110
  }
108
- function createGetDataEntryById({
109
- dataCollectionToEntryMap
110
- }) {
111
+ function createGetDataEntryById({ getEntryImport }) {
111
112
  return async function getDataEntryById(collection, id) {
112
- const lazyImport = dataCollectionToEntryMap[collection]?.[
113
- /*TODO: filePathToIdMap*/
114
- id + ".json"
115
- ];
113
+ const lazyImport = await getEntryImport(collection, id);
116
114
  if (!lazyImport)
117
115
  throw new Error(`Entry ${collection} \u2192 ${id} was not found.`);
118
116
  const entry = await lazyImport();
@@ -286,18 +284,6 @@ function createReference({ lookupMap }) {
286
284
  function isPropagatedAssetsModule(module) {
287
285
  return typeof module === "object" && module != null && "__astroPropagation" in module;
288
286
  }
289
- function warnOfEmptyCollection(collection) {
290
- return {
291
- name: "astro-collection",
292
- hooks: {
293
- "astro:server:start": ({ logger }) => {
294
- logger.warn(
295
- `The collection **${collection}** does not exist or is empty. Ensure a collection directory with this name exists.`
296
- );
297
- }
298
- }
299
- };
300
- }
301
287
  export {
302
288
  createCollectionToGlobResultMap,
303
289
  createGetCollection,
@@ -418,7 +418,9 @@ async function generatePath(pathname, gopts, pipeline) {
418
418
  if (!pipeline.getConfig().build.redirects) {
419
419
  return;
420
420
  }
421
- const location = getRedirectLocationOrThrow(response.headers);
421
+ const locationSite = getRedirectLocationOrThrow(response.headers);
422
+ const siteURL = pipeline.getConfig().site;
423
+ const location = siteURL ? new URL(locationSite, siteURL) : locationSite;
422
424
  const fromPath = new URL(renderContext.request.url).pathname;
423
425
  const delay = response.status === 302 ? 2 : 0;
424
426
  body = `<!doctype html>
@@ -433,7 +435,7 @@ async function generatePath(pathname, gopts, pipeline) {
433
435
  body = body.replaceAll("\n", "");
434
436
  }
435
437
  if (pageData.route.type !== "redirect") {
436
- pageData.route.redirect = location;
438
+ pageData.route.redirect = location.toString();
437
439
  }
438
440
  } else {
439
441
  if (!response.body)
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "3.1.2";
1
+ const ASTRO_VERSION = "3.1.4";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -20,7 +20,7 @@ async function dev(inlineConfig) {
20
20
  base: restart.container.settings.config.base
21
21
  })
22
22
  );
23
- const currentVersion = "3.1.2";
23
+ const currentVersion = "3.1.4";
24
24
  if (currentVersion.includes("-")) {
25
25
  logger.warn(null, msg.prerelease({ currentVersion }));
26
26
  }
@@ -1042,6 +1042,7 @@ export declare const ContentSchemaContainsSlugError: {
1042
1042
  /**
1043
1043
  * @docs
1044
1044
  * @message A collection queried via `getCollection()` does not exist.
1045
+ * @deprecated Collections that do not exist no longer result in an error. A warning is omitted instead.
1045
1046
  * @description
1046
1047
  * When querying a collection, ensure a collection directory with the requested name exists under `src/content/`.
1047
1048
  */
@@ -50,7 +50,7 @@ function serverStart({
50
50
  base,
51
51
  isRestart = false
52
52
  }) {
53
- const version = "3.1.2";
53
+ const version = "3.1.4";
54
54
  const localPrefix = `${dim("\u2503")} Local `;
55
55
  const networkPrefix = `${dim("\u2503")} Network `;
56
56
  const emptyPrefix = " ".repeat(11);
@@ -235,7 +235,7 @@ function printHelp({
235
235
  message.push(
236
236
  linebreak(),
237
237
  ` ${bgGreen(black(` ${commandName} `))} ${green(
238
- `v${"3.1.2"}`
238
+ `v${"3.1.4"}`
239
239
  )} ${headline}`
240
240
  );
241
241
  }
@@ -81,14 +81,14 @@ function validateAssetsFeature(assets, adapterName, config, logger) {
81
81
  isSquooshCompatible = false
82
82
  } = assets;
83
83
  if (config?.image?.service?.entrypoint === SHARP_SERVICE && !isSharpCompatible) {
84
- logger.error(
84
+ logger.warn(
85
85
  "astro",
86
86
  `The currently selected adapter \`${adapterName}\` is not compatible with the image service "Sharp".`
87
87
  );
88
88
  return false;
89
89
  }
90
90
  if (config?.image?.service?.entrypoint === SQUOOSH_SERVICE && !isSquooshCompatible) {
91
- logger.error(
91
+ logger.warn(
92
92
  "astro",
93
93
  `The currently selected adapter \`${adapterName}\` is not compatible with the image service "Squoosh".`
94
94
  );
@@ -152,7 +152,7 @@ async function runHookConfigDone({
152
152
  logger
153
153
  );
154
154
  for (const [featureName, supported] of Object.entries(validationResult)) {
155
- if (!supported) {
155
+ if (!supported && featureName !== "assets") {
156
156
  logger.error(
157
157
  "astro",
158
158
  `The adapter ${adapter.name} doesn't support the feature ${featureName}. Your project won't be built. You should not use it.`
@@ -160,9 +160,9 @@ async function runHookConfigDone({
160
160
  }
161
161
  }
162
162
  if (!validationResult.assets) {
163
- logger.info(
163
+ logger.warn(
164
164
  "astro",
165
- `The selected adapter ${adapter.name} does not support Sharp or Squoosh for image processing. To ensure your project is still able to build, image processing has been disabled.`
165
+ `The selected adapter ${adapter.name} does not support image optimization. To allow your project to build with the original, unoptimized images, the image service has been automatically switched to the 'noop' option. See https://docs.astro.build/en/reference/configuration-reference/#imageservice`
166
166
  );
167
167
  settings.config.image.service = {
168
168
  entrypoint: "astro/assets/services/noop",
@@ -1,5 +1,5 @@
1
1
  import islandScript from "./astro-island.prebuilt.js";
2
- const ISLAND_STYLES = `<style style="display:none">astro-island,astro-slot,astro-static-slot{display:contents}</style>`;
2
+ const ISLAND_STYLES = `<style>astro-island,astro-slot,astro-static-slot{display:contents}</style>`;
3
3
  function determineIfNeedsHydrationScript(result) {
4
4
  if (result._metadata.hasHydrationScript) {
5
5
  return false;
@@ -24,12 +24,12 @@ function getDirectiveScriptText(result, directive) {
24
24
  function getPrescripts(result, type, directive) {
25
25
  switch (type) {
26
26
  case "both":
27
- return `${ISLAND_STYLES}<script style="display:none">${getDirectiveScriptText(
27
+ return `${ISLAND_STYLES}<script>${getDirectiveScriptText(
28
28
  result,
29
29
  directive
30
30
  )};${islandScript}</script>`;
31
31
  case "directive":
32
- return `<script style="display:none">${getDirectiveScriptText(result, directive)}</script>`;
32
+ return `<script>${getDirectiveScriptText(result, directive)}</script>`;
33
33
  }
34
34
  return "";
35
35
  }
@@ -23,9 +23,30 @@ function configHeadVitePlugin() {
23
23
  }
24
24
  return {
25
25
  name: "astro:head-metadata",
26
+ enforce: "pre",
27
+ apply: "serve",
26
28
  configureServer(_server) {
27
29
  server = _server;
28
30
  },
31
+ resolveId(source, importer) {
32
+ if (importer) {
33
+ return this.resolve(source, importer, { skipSelf: true }).then((result) => {
34
+ if (result) {
35
+ let info = this.getModuleInfo(result.id);
36
+ const astro = info && getAstroMetadata(info);
37
+ if (astro) {
38
+ if (astro.propagation === "self" || astro.propagation === "in-tree") {
39
+ propagateMetadata.call(this, importer, "propagation", "in-tree");
40
+ }
41
+ if (astro.containsHead) {
42
+ propagateMetadata.call(this, importer, "containsHead", true);
43
+ }
44
+ }
45
+ }
46
+ return result;
47
+ });
48
+ }
49
+ },
29
50
  transform(source, id) {
30
51
  if (!server) {
31
52
  return;
@@ -91,11 +91,11 @@ function markdown({ settings, logger }) {
91
91
 
92
92
  ${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
93
93
  import { getImage } from "astro:assets";
94
- ${imagePaths.map((entry) => `import Astro__${entry.safeName} from ${JSON.stringify(entry.raw)};`)}
94
+ ${imagePaths.map((entry) => `import Astro__${entry.safeName} from ${JSON.stringify(entry.raw)};`).join("\n")}
95
95
 
96
96
  const images = async function() {
97
97
  return {
98
- ${imagePaths.map((entry) => `"${entry.raw}": await getImage({src: Astro__${entry.safeName}})`).join("\n")}
98
+ ${imagePaths.map((entry) => `"${entry.raw}": await getImage({src: Astro__${entry.safeName}})`).join(",\n")}
99
99
  }
100
100
  }
101
101
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "3.1.2",
3
+ "version": "3.1.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",