astro 4.13.4 → 4.14.1

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 (98) hide show
  1. package/components/Code.astro +9 -0
  2. package/dist/@types/astro.d.ts +249 -1
  3. package/dist/actions/consts.d.ts +1 -1
  4. package/dist/actions/consts.js +1 -1
  5. package/dist/actions/index.js +12 -21
  6. package/dist/assets/endpoint/node.js +1 -1
  7. package/dist/assets/utils/resolveImports.d.ts +9 -0
  8. package/dist/assets/utils/resolveImports.js +22 -0
  9. package/dist/cli/add/index.d.ts +2 -2
  10. package/dist/cli/add/index.js +2 -2
  11. package/dist/cli/build/index.d.ts +2 -2
  12. package/dist/cli/build/index.js +5 -1
  13. package/dist/cli/check/index.d.ts +2 -2
  14. package/dist/cli/check/index.js +5 -2
  15. package/dist/cli/db/index.d.ts +4 -3
  16. package/dist/cli/db/index.js +10 -3
  17. package/dist/cli/dev/index.d.ts +2 -2
  18. package/dist/cli/dev/index.js +1 -0
  19. package/dist/cli/docs/index.d.ts +2 -2
  20. package/dist/cli/flags.d.ts +3 -1
  21. package/dist/cli/flags.js +2 -1
  22. package/dist/cli/index.d.ts +1 -1
  23. package/dist/cli/index.js +26 -13
  24. package/dist/cli/info/index.d.ts +2 -2
  25. package/dist/cli/preferences/index.d.ts +2 -2
  26. package/dist/cli/preferences/index.js +1 -1
  27. package/dist/cli/preview/index.d.ts +2 -2
  28. package/dist/cli/sync/index.d.ts +2 -2
  29. package/dist/cli/sync/index.js +5 -2
  30. package/dist/cli/telemetry/index.d.ts +2 -2
  31. package/dist/content/consts.d.ts +16 -2
  32. package/dist/content/consts.js +32 -2
  33. package/dist/content/content-layer.d.ts +40 -0
  34. package/dist/content/content-layer.js +253 -0
  35. package/dist/content/data-store.d.ts +54 -0
  36. package/dist/content/data-store.js +72 -0
  37. package/dist/content/loaders/file.d.ts +7 -0
  38. package/dist/content/loaders/file.js +72 -0
  39. package/dist/content/loaders/glob.d.ts +25 -0
  40. package/dist/content/loaders/glob.js +218 -0
  41. package/dist/content/loaders/index.d.ts +3 -0
  42. package/dist/content/loaders/index.js +7 -0
  43. package/dist/content/loaders/types.d.ts +36 -0
  44. package/dist/content/loaders/types.js +0 -0
  45. package/dist/content/mutable-data-store.d.ts +77 -0
  46. package/dist/content/mutable-data-store.js +269 -0
  47. package/dist/content/runtime.d.ts +46 -8
  48. package/dist/content/runtime.js +225 -31
  49. package/dist/content/types-generator.js +123 -35
  50. package/dist/content/utils.d.ts +307 -2
  51. package/dist/content/utils.js +101 -7
  52. package/dist/content/vite-plugin-content-assets.js +9 -1
  53. package/dist/content/vite-plugin-content-virtual-mod.js +94 -2
  54. package/dist/core/build/index.js +14 -7
  55. package/dist/core/build/plugins/plugin-ssr.js +32 -4
  56. package/dist/core/config/config.d.ts +2 -5
  57. package/dist/core/config/config.js +0 -12
  58. package/dist/core/config/index.d.ts +1 -1
  59. package/dist/core/config/index.js +0 -2
  60. package/dist/core/config/schema.d.ts +34 -0
  61. package/dist/core/config/schema.js +6 -2
  62. package/dist/core/config/settings.js +5 -3
  63. package/dist/core/constants.js +1 -1
  64. package/dist/core/create-vite.js +1 -1
  65. package/dist/core/dev/container.js +2 -1
  66. package/dist/core/dev/dev.js +33 -3
  67. package/dist/core/dev/restart.js +25 -10
  68. package/dist/core/errors/errors-data.d.ts +21 -0
  69. package/dist/core/errors/errors-data.js +13 -0
  70. package/dist/core/index.js +1 -1
  71. package/dist/core/logger/vite.js +1 -1
  72. package/dist/core/messages.js +2 -2
  73. package/dist/core/preview/static-preview-server.js +1 -1
  74. package/dist/core/routing/manifest/create.js +1 -1
  75. package/dist/core/sync/constants.d.ts +1 -0
  76. package/dist/core/sync/constants.js +4 -0
  77. package/dist/core/sync/index.d.ts +12 -4
  78. package/dist/core/sync/index.js +54 -24
  79. package/dist/core/sync/write-files.d.ts +4 -0
  80. package/dist/core/sync/write-files.js +69 -0
  81. package/dist/core/util.js +1 -1
  82. package/dist/env/sync.js +6 -4
  83. package/dist/integrations/hooks.d.ts +7 -1
  84. package/dist/integrations/hooks.js +54 -0
  85. package/dist/preferences/index.d.ts +1 -1
  86. package/dist/preferences/index.js +2 -2
  87. package/dist/runtime/server/render/server-islands.js +6 -4
  88. package/dist/vite-plugin-astro-server/response.js +1 -1
  89. package/dist/vite-plugin-env/index.d.ts +3 -1
  90. package/dist/vite-plugin-env/index.js +11 -1
  91. package/dist/vite-plugin-markdown/content-entry-type.js +25 -2
  92. package/dist/vite-plugin-scanner/index.js +15 -5
  93. package/package.json +10 -5
  94. package/templates/content/module.mjs +6 -1
  95. package/templates/content/types.d.ts +18 -5
  96. package/types/content.d.ts +34 -1
  97. package/dist/core/sync/setup-env-ts.d.ts +0 -8
  98. package/dist/core/sync/setup-env-ts.js +0 -79
@@ -1,5 +1,6 @@
1
1
  import { fileURLToPath } from "node:url";
2
2
  import { transform } from "esbuild";
3
+ import { bold } from "kleur/colors";
3
4
  import MagicString from "magic-string";
4
5
  import { loadEnv } from "vite";
5
6
  const importMetaEnvOnlyRe = /\bimport\.meta\.env\b(?!\.)/;
@@ -71,7 +72,7 @@ async function replaceDefine(code, id, define, config) {
71
72
  map: result.map || null
72
73
  };
73
74
  }
74
- function envVitePlugin({ settings }) {
75
+ function envVitePlugin({ settings, logger }) {
75
76
  let privateEnv;
76
77
  let defaultDefines;
77
78
  let isDev;
@@ -114,13 +115,22 @@ function envVitePlugin({ settings }) {
114
115
  devImportMetaEnvPrepend += "});";
115
116
  }
116
117
  s.prepend(devImportMetaEnvPrepend);
118
+ let exportConstPrerenderStr;
117
119
  s.replace(exportConstPrerenderRe, (m, key) => {
120
+ exportConstPrerenderStr = m;
118
121
  if (privateEnv[key] != null) {
119
122
  return `export const prerender = ${privateEnv[key]}`;
120
123
  } else {
121
124
  return m;
122
125
  }
123
126
  });
127
+ if (exportConstPrerenderStr) {
128
+ logger.warn(
129
+ "router",
130
+ `Exporting dynamic values from prerender is deprecated. Please use an integration with the "astro:route:setup" hook to update the route's \`prerender\` option instead. This allows for better treeshaking and bundling configuration in the future. See https://docs.astro.build/en/reference/integrations-reference/#astroroutesetup for a migration example.
131
+ Found \`${bold(exportConstPrerenderStr)}\` in ${bold(id)}.`
132
+ );
133
+ }
124
134
  return {
125
135
  code: s.toString(),
126
136
  map: s.generateMap({ hires: "boundary" })
@@ -1,4 +1,5 @@
1
- import { fileURLToPath } from "node:url";
1
+ import { fileURLToPath, pathToFileURL } from "node:url";
2
+ import { createMarkdownProcessor } from "@astrojs/markdown-remark";
2
3
  import { safeParseFrontmatter } from "../content/utils.js";
3
4
  const markdownContentEntryType = {
4
5
  extensions: [".md"],
@@ -12,7 +13,29 @@ const markdownContentEntryType = {
12
13
  };
13
14
  },
14
15
  // We need to handle propagation for Markdown because they support layouts which will bring in styles.
15
- handlePropagation: true
16
+ handlePropagation: true,
17
+ async getRenderFunction(settings) {
18
+ const processor = await createMarkdownProcessor(settings.config.markdown);
19
+ return async function renderToString(entry) {
20
+ if (!entry.body) {
21
+ return {
22
+ html: ""
23
+ };
24
+ }
25
+ const result = await processor.render(entry.body, {
26
+ frontmatter: entry.data,
27
+ // @ts-expect-error Internal API
28
+ fileURL: entry.filePath ? pathToFileURL(entry.filePath) : void 0
29
+ });
30
+ return {
31
+ html: result.code,
32
+ metadata: {
33
+ ...result.metadata,
34
+ imagePaths: Array.from(result.metadata.imagePaths)
35
+ }
36
+ };
37
+ };
38
+ }
16
39
  };
17
40
  export {
18
41
  markdownContentEntryType
@@ -4,6 +4,7 @@ import { normalizePath } from "vite";
4
4
  import {} from "../core/logger/core.js";
5
5
  import { isEndpoint, isPage, isServerLikeOutput } from "../core/util.js";
6
6
  import { rootRelativePath } from "../core/viteUtils.js";
7
+ import { runHookRouteSetup } from "../integrations/hooks.js";
7
8
  import { getPrerenderDefault } from "../prerender/utils.js";
8
9
  import { scan } from "./scan.js";
9
10
  const KNOWN_FILE_EXTENSIONS = [".astro", ".js", ".ts"];
@@ -26,11 +27,7 @@ function astroScannerPlugin({
26
27
  const fileIsPage = isPage(fileURL, settings);
27
28
  const fileIsEndpoint = isEndpoint(fileURL, settings);
28
29
  if (!(fileIsPage || fileIsEndpoint)) return;
29
- const defaultPrerender = getPrerenderDefault(settings.config);
30
- const pageOptions = await scan(code, id, settings);
31
- if (typeof pageOptions.prerender === "undefined") {
32
- pageOptions.prerender = defaultPrerender;
33
- }
30
+ const pageOptions = await getPageOptions(code, id, fileURL, settings, logger);
34
31
  if (!pageOptions.prerender && isServerLikeOutput(settings.config) && code.includes("getStaticPaths") && // this should only be valid for `.astro`, `.js` and `.ts` files
35
32
  KNOWN_FILE_EXTENSIONS.includes(extname(filename))) {
36
33
  logger.warn(
@@ -55,6 +52,19 @@ function astroScannerPlugin({
55
52
  }
56
53
  };
57
54
  }
55
+ async function getPageOptions(code, id, fileURL, settings, logger) {
56
+ const pageOptions = await scan(code, id, settings);
57
+ const route = {
58
+ component: rootRelativePath(settings.config.root, fileURL, false),
59
+ prerender: pageOptions.prerender
60
+ };
61
+ await runHookRouteSetup({ route, settings, logger });
62
+ pageOptions.prerender = route.prerender;
63
+ if (typeof pageOptions.prerender === "undefined") {
64
+ pageOptions.prerender = getPrerenderDefault(settings.config);
65
+ }
66
+ return pageOptions;
67
+ }
58
68
  export {
59
69
  astroScannerPlugin as default
60
70
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.13.4",
3
+ "version": "4.14.1",
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",
@@ -68,6 +68,7 @@
68
68
  "./assets/services/sharp": "./dist/assets/services/sharp.js",
69
69
  "./assets/services/squoosh": "./dist/assets/services/squoosh.js",
70
70
  "./assets/services/noop": "./dist/assets/services/noop.js",
71
+ "./loaders": "./dist/content/loaders/index.js",
71
72
  "./content/runtime": "./dist/content/runtime.js",
72
73
  "./content/runtime-assets": "./dist/content/runtime-assets.js",
73
74
  "./debug": "./components/Debug.astro",
@@ -114,6 +115,7 @@
114
115
  "@babel/plugin-transform-react-jsx": "^7.25.2",
115
116
  "@babel/traverse": "^7.25.3",
116
117
  "@babel/types": "^7.25.2",
118
+ "@rollup/pluginutils": "^5.1.0",
117
119
  "@oslojs/encoding": "^0.4.1",
118
120
  "@types/babel__core": "^7.20.5",
119
121
  "@types/cookie": "^0.6.0",
@@ -145,7 +147,9 @@
145
147
  "js-yaml": "^4.1.0",
146
148
  "kleur": "^4.1.5",
147
149
  "magic-string": "^0.30.11",
150
+ "micromatch": "^4.0.7",
148
151
  "mrmime": "^2.0.0",
152
+ "neotraverse": "^0.6.9",
149
153
  "ora": "^8.0.1",
150
154
  "p-limit": "^6.1.0",
151
155
  "p-queue": "^8.0.1",
@@ -163,12 +167,13 @@
163
167
  "vite": "^5.4.0",
164
168
  "vitefu": "^0.2.5",
165
169
  "which-pm": "^3.0.0",
166
- "yargs-parser": "^21.1.1",
170
+ "xxhash-wasm": "^1.0.2",
167
171
  "zod": "^3.23.8",
168
172
  "zod-to-json-schema": "^3.23.2",
169
- "@astrojs/markdown-remark": "5.2.0",
173
+ "zod-to-ts": "^1.2.0",
170
174
  "@astrojs/internal-helpers": "0.4.1",
171
- "@astrojs/telemetry": "3.1.0"
175
+ "@astrojs/telemetry": "3.1.0",
176
+ "@astrojs/markdown-remark": "5.2.0"
172
177
  },
173
178
  "optionalDependencies": {
174
179
  "sharp": "^0.33.3"
@@ -189,9 +194,9 @@
189
194
  "@types/html-escaper": "^3.0.2",
190
195
  "@types/http-cache-semantics": "^4.0.4",
191
196
  "@types/js-yaml": "^4.0.9",
197
+ "@types/micromatch": "^4.0.9",
192
198
  "@types/prompts": "^2.4.9",
193
199
  "@types/semver": "^7.5.8",
194
- "@types/yargs-parser": "^21.0.3",
195
200
  "cheerio": "1.0.0",
196
201
  "eol": "^0.9.1",
197
202
  "expect-type": "^0.19.0",
@@ -9,7 +9,7 @@ import {
9
9
  createReference,
10
10
  } from 'astro/content/runtime';
11
11
 
12
- export { defineCollection } from 'astro/content/runtime';
12
+ export { defineCollection, renderEntry as render } from 'astro/content/runtime';
13
13
  export { z } from 'astro/zod';
14
14
 
15
15
  const contentDir = '@@CONTENT_DIR@@';
@@ -33,6 +33,8 @@ const collectionToEntryMap = createCollectionToGlobResultMap({
33
33
  let lookupMap = {};
34
34
  /* @@LOOKUP_MAP_ASSIGNMENT@@ */
35
35
 
36
+ const collectionNames = new Set(Object.keys(lookupMap));
37
+
36
38
  function createGlobLookup(glob) {
37
39
  return async (collection, lookupId) => {
38
40
  const filePath = lookupMap[collection]?.entries[lookupId];
@@ -59,15 +61,18 @@ export const getCollection = createGetCollection({
59
61
  export const getEntryBySlug = createGetEntryBySlug({
60
62
  getEntryImport: createGlobLookup(contentCollectionToEntryMap),
61
63
  getRenderEntryImport: createGlobLookup(collectionToRenderEntryMap),
64
+ collectionNames,
62
65
  });
63
66
 
64
67
  export const getDataEntryById = createGetDataEntryById({
65
68
  getEntryImport: createGlobLookup(dataCollectionToEntryMap),
69
+ collectionNames,
66
70
  });
67
71
 
68
72
  export const getEntry = createGetEntry({
69
73
  getEntryImport: createGlobLookup(collectionToEntryMap),
70
74
  getRenderEntryImport: createGlobLookup(collectionToRenderEntryMap),
75
+ collectionNames,
71
76
  });
72
77
 
73
78
  export const getEntries = createGetEntries(getEntry);
@@ -1,10 +1,19 @@
1
1
  declare module 'astro:content' {
2
+ interface RenderResult {
3
+ Content: import('astro/runtime/server/index.js').AstroComponentFactory;
4
+ headings: import('astro').MarkdownHeading[];
5
+ remarkPluginFrontmatter: Record<string, any>;
6
+ }
2
7
  interface Render {
3
- '.md': Promise<{
4
- Content: import('astro').MarkdownInstance<{}>['Content'];
5
- headings: import('astro').MarkdownHeading[];
6
- remarkPluginFrontmatter: Record<string, any>;
7
- }>;
8
+ '.md': Promise<RenderResult>;
9
+ }
10
+
11
+ export interface RenderedContent {
12
+ html: string;
13
+ metadata?: {
14
+ imagePaths: Array<string>;
15
+ [key: string]: unknown;
16
+ };
8
17
  }
9
18
  }
10
19
 
@@ -100,6 +109,10 @@ declare module 'astro:content' {
100
109
  }[],
101
110
  ): Promise<CollectionEntry<C>[]>;
102
111
 
112
+ export function render<C extends keyof AnyEntryMap>(
113
+ entry: AnyEntryMap[C][string],
114
+ ): Promise<RenderResult>;
115
+
103
116
  export function reference<C extends keyof AnyEntryMap>(
104
117
  collection: C,
105
118
  ): import('astro/zod').ZodEffects<
@@ -20,6 +20,31 @@ declare module 'astro:content' {
20
20
  >;
21
21
  }>;
22
22
 
23
+ export interface DataEntry {
24
+ id: string;
25
+ data: Record<string, unknown>;
26
+ filePath?: string;
27
+ body?: string;
28
+ }
29
+
30
+ export interface DataStore {
31
+ get: (key: string) => DataEntry;
32
+ entries: () => Array<[id: string, DataEntry]>;
33
+ set: (key: string, data: Record<string, unknown>, body?: string, filePath?: string) => void;
34
+ values: () => Array<DataEntry>;
35
+ keys: () => Array<string>;
36
+ delete: (key: string) => void;
37
+ clear: () => void;
38
+ has: (key: string) => boolean;
39
+ }
40
+
41
+ export interface MetaStore {
42
+ get: (key: string) => string | undefined;
43
+ set: (key: string, value: string) => void;
44
+ delete: (key: string) => void;
45
+ has: (key: string) => boolean;
46
+ }
47
+
23
48
  type BaseSchemaWithoutEffects =
24
49
  | import('astro/zod').AnyZodObject
25
50
  | import('astro/zod').ZodUnion<[BaseSchemaWithoutEffects, ...BaseSchemaWithoutEffects[]]>
@@ -32,6 +57,12 @@ declare module 'astro:content' {
32
57
 
33
58
  export type SchemaContext = { image: ImageFunction };
34
59
 
60
+ type ContentLayerConfig<S extends BaseSchema, TData extends { id: string } = { id: string }> = {
61
+ type?: 'content_layer';
62
+ schema?: S | ((context: SchemaContext) => S);
63
+ loader: import('astro/loaders').Loader | (() => Array<TData> | Promise<Array<TData>>);
64
+ };
65
+
35
66
  type DataCollectionConfig<S extends BaseSchema> = {
36
67
  type: 'data';
37
68
  schema?: S | ((context: SchemaContext) => S);
@@ -40,11 +71,13 @@ declare module 'astro:content' {
40
71
  type ContentCollectionConfig<S extends BaseSchema> = {
41
72
  type?: 'content';
42
73
  schema?: S | ((context: SchemaContext) => S);
74
+ loader?: never;
43
75
  };
44
76
 
45
77
  export type CollectionConfig<S extends BaseSchema> =
46
78
  | ContentCollectionConfig<S>
47
- | DataCollectionConfig<S>;
79
+ | DataCollectionConfig<S>
80
+ | ContentLayerConfig<S>;
48
81
 
49
82
  export function defineCollection<S extends BaseSchema>(
50
83
  input: CollectionConfig<S>,
@@ -1,8 +0,0 @@
1
- import type fsMod from 'node:fs';
2
- import type { AstroSettings } from '../../@types/astro.js';
3
- import { type Logger } from '../logger/core.js';
4
- export declare function setUpEnvTs({ settings, logger, fs, }: {
5
- settings: AstroSettings;
6
- logger: Logger;
7
- fs: typeof fsMod;
8
- }): Promise<void>;
@@ -1,79 +0,0 @@
1
- import path from "node:path";
2
- import { fileURLToPath } from "node:url";
3
- import { bold } from "kleur/colors";
4
- import { normalizePath } from "vite";
5
- import { ACTIONS_TYPES_FILE } from "../../actions/consts.js";
6
- import { CONTENT_TYPES_FILE } from "../../content/consts.js";
7
- import { ENV_TYPES_FILE } from "../../env/constants.js";
8
- import {} from "../logger/core.js";
9
- function getDotAstroTypeReference({
10
- settings,
11
- filename
12
- }) {
13
- const relativePath = normalizePath(
14
- path.relative(
15
- fileURLToPath(settings.config.srcDir),
16
- fileURLToPath(new URL(filename, settings.dotAstroDir))
17
- )
18
- );
19
- return `/// <reference path=${JSON.stringify(relativePath)} />`;
20
- }
21
- async function setUpEnvTs({
22
- settings,
23
- logger,
24
- fs
25
- }) {
26
- const envTsPath = new URL("env.d.ts", settings.config.srcDir);
27
- const envTsPathRelativetoRoot = normalizePath(
28
- path.relative(fileURLToPath(settings.config.root), fileURLToPath(envTsPath))
29
- );
30
- const injectedTypes = [
31
- {
32
- filename: CONTENT_TYPES_FILE,
33
- meetsCondition: () => fs.existsSync(new URL(CONTENT_TYPES_FILE, settings.dotAstroDir))
34
- },
35
- {
36
- filename: ACTIONS_TYPES_FILE,
37
- meetsCondition: () => fs.existsSync(new URL(ACTIONS_TYPES_FILE, settings.dotAstroDir))
38
- }
39
- ];
40
- if (settings.config.experimental.env) {
41
- injectedTypes.push({
42
- filename: ENV_TYPES_FILE
43
- });
44
- }
45
- if (fs.existsSync(envTsPath)) {
46
- const initialEnvContents = await fs.promises.readFile(envTsPath, "utf-8");
47
- let typesEnvContents = initialEnvContents;
48
- for (const injectedType of injectedTypes) {
49
- if (!injectedType.meetsCondition || await injectedType.meetsCondition?.()) {
50
- const expectedTypeReference = getDotAstroTypeReference({
51
- settings,
52
- filename: injectedType.filename
53
- });
54
- if (!typesEnvContents.includes(expectedTypeReference)) {
55
- typesEnvContents = `${expectedTypeReference}
56
- ${typesEnvContents}`;
57
- }
58
- }
59
- }
60
- if (initialEnvContents !== typesEnvContents) {
61
- logger.info("types", `Updated ${bold(envTsPathRelativetoRoot)} type declarations.`);
62
- await fs.promises.writeFile(envTsPath, typesEnvContents, "utf-8");
63
- }
64
- } else {
65
- let referenceDefs = [];
66
- referenceDefs.push('/// <reference types="astro/client" />');
67
- for (const injectedType of injectedTypes) {
68
- if (!injectedType.meetsCondition || await injectedType.meetsCondition?.()) {
69
- referenceDefs.push(getDotAstroTypeReference({ settings, filename: injectedType.filename }));
70
- }
71
- }
72
- await fs.promises.mkdir(settings.config.srcDir, { recursive: true });
73
- await fs.promises.writeFile(envTsPath, referenceDefs.join("\n"), "utf-8");
74
- logger.info("types", `Added ${bold(envTsPathRelativetoRoot)} type declarations`);
75
- }
76
- }
77
- export {
78
- setUpEnvTs
79
- };