astro 4.13.3 → 4.14.0

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 (107) hide show
  1. package/components/Code.astro +9 -0
  2. package/dist/@types/astro.d.ts +251 -2
  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/actions/runtime/virtual/server.js +9 -3
  7. package/dist/actions/runtime/virtual/shared.js +25 -3
  8. package/dist/assets/utils/resolveImports.d.ts +9 -0
  9. package/dist/assets/utils/resolveImports.js +22 -0
  10. package/dist/cli/add/index.d.ts +2 -2
  11. package/dist/cli/add/index.js +2 -2
  12. package/dist/cli/build/index.d.ts +2 -2
  13. package/dist/cli/build/index.js +5 -1
  14. package/dist/cli/check/index.d.ts +2 -2
  15. package/dist/cli/check/index.js +5 -2
  16. package/dist/cli/db/index.d.ts +4 -3
  17. package/dist/cli/db/index.js +10 -3
  18. package/dist/cli/dev/index.d.ts +2 -2
  19. package/dist/cli/dev/index.js +1 -0
  20. package/dist/cli/docs/index.d.ts +2 -2
  21. package/dist/cli/flags.d.ts +3 -1
  22. package/dist/cli/flags.js +2 -1
  23. package/dist/cli/index.d.ts +1 -1
  24. package/dist/cli/index.js +26 -13
  25. package/dist/cli/info/index.d.ts +2 -2
  26. package/dist/cli/preferences/index.d.ts +2 -2
  27. package/dist/cli/preferences/index.js +1 -1
  28. package/dist/cli/preview/index.d.ts +2 -2
  29. package/dist/cli/sync/index.d.ts +2 -2
  30. package/dist/cli/sync/index.js +5 -2
  31. package/dist/cli/telemetry/index.d.ts +2 -2
  32. package/dist/container/index.js +3 -1
  33. package/dist/content/consts.d.ts +16 -2
  34. package/dist/content/consts.js +32 -2
  35. package/dist/content/content-layer.d.ts +40 -0
  36. package/dist/content/content-layer.js +253 -0
  37. package/dist/content/data-store.d.ts +114 -0
  38. package/dist/content/data-store.js +323 -0
  39. package/dist/content/loaders/file.d.ts +7 -0
  40. package/dist/content/loaders/file.js +72 -0
  41. package/dist/content/loaders/glob.d.ts +25 -0
  42. package/dist/content/loaders/glob.js +218 -0
  43. package/dist/content/loaders/index.d.ts +3 -0
  44. package/dist/content/loaders/index.js +7 -0
  45. package/dist/content/loaders/types.d.ts +36 -0
  46. package/dist/content/loaders/types.js +0 -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 +125 -35
  50. package/dist/content/utils.d.ts +306 -2
  51. package/dist/content/utils.js +93 -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/app/common.js +4 -1
  55. package/dist/core/app/index.js +5 -3
  56. package/dist/core/app/types.d.ts +3 -1
  57. package/dist/core/build/generate.js +4 -2
  58. package/dist/core/build/index.js +17 -8
  59. package/dist/core/build/plugins/plugin-manifest.js +5 -2
  60. package/dist/core/build/plugins/plugin-ssr.js +35 -3
  61. package/dist/core/build/static-build.js +2 -0
  62. package/dist/core/build/types.d.ts +1 -0
  63. package/dist/core/config/config.d.ts +2 -5
  64. package/dist/core/config/config.js +0 -12
  65. package/dist/core/config/index.d.ts +1 -1
  66. package/dist/core/config/index.js +0 -2
  67. package/dist/core/config/schema.d.ts +34 -0
  68. package/dist/core/config/schema.js +6 -2
  69. package/dist/core/config/settings.js +5 -3
  70. package/dist/core/constants.js +1 -1
  71. package/dist/core/create-vite.js +1 -1
  72. package/dist/core/dev/container.js +2 -1
  73. package/dist/core/dev/dev.js +34 -2
  74. package/dist/core/dev/restart.js +25 -10
  75. package/dist/core/encryption.d.ts +24 -0
  76. package/dist/core/encryption.js +64 -0
  77. package/dist/core/errors/errors-data.d.ts +21 -0
  78. package/dist/core/errors/errors-data.js +13 -0
  79. package/dist/core/index.js +1 -1
  80. package/dist/core/messages.js +2 -2
  81. package/dist/core/render-context.js +1 -0
  82. package/dist/core/server-islands/endpoint.js +5 -1
  83. package/dist/core/sync/constants.d.ts +1 -0
  84. package/dist/core/sync/constants.js +4 -0
  85. package/dist/core/sync/index.d.ts +12 -4
  86. package/dist/core/sync/index.js +56 -25
  87. package/dist/core/sync/write-files.d.ts +4 -0
  88. package/dist/core/sync/write-files.js +69 -0
  89. package/dist/core/util.js +1 -1
  90. package/dist/env/sync.js +6 -4
  91. package/dist/integrations/hooks.d.ts +7 -1
  92. package/dist/integrations/hooks.js +54 -0
  93. package/dist/preferences/index.d.ts +1 -1
  94. package/dist/preferences/index.js +2 -2
  95. package/dist/runtime/server/render/server-islands.js +9 -5
  96. package/dist/vite-plugin-astro-server/plugin.js +2 -0
  97. package/dist/vite-plugin-env/index.d.ts +3 -1
  98. package/dist/vite-plugin-env/index.js +11 -1
  99. package/dist/vite-plugin-markdown/content-entry-type.js +25 -2
  100. package/dist/vite-plugin-scanner/index.js +15 -5
  101. package/dist/vite-plugin-scanner/scan.js +1 -1
  102. package/package.json +15 -9
  103. package/templates/content/module.mjs +6 -1
  104. package/templates/content/types.d.ts +18 -5
  105. package/types/content.d.ts +34 -1
  106. package/dist/core/sync/setup-env-ts.d.ts +0 -8
  107. package/dist/core/sync/setup-env-ts.js +0 -79
package/dist/core/util.js CHANGED
@@ -101,7 +101,7 @@ function isPage(file, settings) {
101
101
  function isEndpoint(file, settings) {
102
102
  if (!isInPagesDir(file, settings.config)) return false;
103
103
  if (!isPublicRoute(file, settings.config)) return false;
104
- return !endsWithPageExt(file, settings);
104
+ return !endsWithPageExt(file, settings) && !file.toString().includes("?astro");
105
105
  }
106
106
  function isServerLikeOutput(config) {
107
107
  return config.output === "server" || config.output === "hybrid";
package/dist/env/sync.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import fsMod from "node:fs";
2
- import { ENV_TYPES_FILE, TYPES_TEMPLATE_URL } from "./constants.js";
2
+ import { TYPES_TEMPLATE_URL } from "./constants.js";
3
3
  import { getEnvFieldType } from "./validators.js";
4
4
  function syncAstroEnv(settings, fs = fsMod) {
5
5
  if (!settings.config.experimental.env) {
@@ -18,9 +18,11 @@ function syncAstroEnv(settings, fs = fsMod) {
18
18
  }
19
19
  }
20
20
  const template = fs.readFileSync(TYPES_TEMPLATE_URL, "utf-8");
21
- const dts = template.replace("// @@CLIENT@@", client).replace("// @@SERVER@@", server);
22
- fs.mkdirSync(settings.dotAstroDir, { recursive: true });
23
- fs.writeFileSync(new URL(ENV_TYPES_FILE, settings.dotAstroDir), dts, "utf-8");
21
+ const content = template.replace("// @@CLIENT@@", client).replace("// @@SERVER@@", server);
22
+ settings.injectedTypes.push({
23
+ filename: "astro/env.d.ts",
24
+ content
25
+ });
24
26
  }
25
27
  export {
26
28
  syncAstroEnv
@@ -1,7 +1,7 @@
1
1
  import fsMod from 'node:fs';
2
2
  import type { AddressInfo } from 'node:net';
3
3
  import type { InlineConfig, ViteDevServer } from 'vite';
4
- import type { AstroAdapter, AstroConfig, AstroSettings, RouteData } from '../@types/astro.js';
4
+ import type { AstroAdapter, AstroConfig, AstroSettings, RouteData, RouteOptions } from '../@types/astro.js';
5
5
  import type { SerializedSSRManifest } from '../core/app/types.js';
6
6
  import type { PageBuildData } from '../core/build/types.js';
7
7
  import type { Logger } from '../core/logger/core.js';
@@ -33,6 +33,7 @@ export declare function getToolbarServerCommunicationHelpers(server: ViteDevServ
33
33
  state: boolean;
34
34
  }) => void) => void;
35
35
  };
36
+ export declare function normalizeInjectedTypeFilename(filename: string, integrationName: string): string;
36
37
  export declare function runHookConfigSetup({ settings, command, logger, isRestart, fs, }: {
37
38
  settings: AstroSettings;
38
39
  command: 'dev' | 'build' | 'preview';
@@ -89,5 +90,10 @@ type RunHookBuildDone = {
89
90
  cacheManifest: boolean;
90
91
  };
91
92
  export declare function runHookBuildDone({ config, pages, routes, logging, cacheManifest, }: RunHookBuildDone): Promise<void>;
93
+ export declare function runHookRouteSetup({ route, settings, logger, }: {
94
+ route: RouteOptions;
95
+ settings: AstroSettings;
96
+ logger: Logger;
97
+ }): Promise<void>;
92
98
  export declare function isFunctionPerRouteEnabled(adapter: AstroAdapter | undefined): boolean;
93
99
  export {};
@@ -70,6 +70,15 @@ function getToolbarServerCommunicationHelpers(server) {
70
70
  }
71
71
  };
72
72
  }
73
+ const SAFE_CHARS_RE = /[^\w.-]/g;
74
+ function normalizeInjectedTypeFilename(filename, integrationName) {
75
+ if (!filename.endsWith(".d.ts")) {
76
+ throw new Error(
77
+ `Integration ${bold(integrationName)} is injecting a type that does not end with "${bold(".d.ts")}"`
78
+ );
79
+ }
80
+ return `./integrations/${integrationName.replace(SAFE_CHARS_RE, "_")}/${filename.replace(SAFE_CHARS_RE, "_")}`;
81
+ }
73
82
  async function runHookConfigSetup({
74
83
  settings,
75
84
  command,
@@ -242,6 +251,17 @@ async function runHookConfigDone({
242
251
  }
243
252
  settings.adapter = adapter;
244
253
  },
254
+ injectTypes(injectedType) {
255
+ const normalizedFilename = normalizeInjectedTypeFilename(
256
+ injectedType.filename,
257
+ integration.name
258
+ );
259
+ settings.injectedTypes.push({
260
+ filename: normalizedFilename,
261
+ content: injectedType.content
262
+ });
263
+ return new URL(normalizedFilename, settings.config.root);
264
+ },
245
265
  logger: getLogger(integration, logger)
246
266
  }),
247
267
  logger
@@ -419,6 +439,38 @@ async function runHookBuildDone({
419
439
  }
420
440
  }
421
441
  }
442
+ async function runHookRouteSetup({
443
+ route,
444
+ settings,
445
+ logger
446
+ }) {
447
+ const prerenderChangeLogs = [];
448
+ for (const integration of settings.config.integrations) {
449
+ if (integration?.hooks?.["astro:route:setup"]) {
450
+ const originalRoute = { ...route };
451
+ const integrationLogger = getLogger(integration, logger);
452
+ await withTakingALongTimeMsg({
453
+ name: integration.name,
454
+ hookName: "astro:route:setup",
455
+ hookResult: integration.hooks["astro:route:setup"]({
456
+ route,
457
+ logger: integrationLogger
458
+ }),
459
+ logger
460
+ });
461
+ if (route.prerender !== originalRoute.prerender) {
462
+ prerenderChangeLogs.push({ integrationName: integration.name, value: route.prerender });
463
+ }
464
+ }
465
+ }
466
+ if (prerenderChangeLogs.length > 1) {
467
+ logger.debug(
468
+ "router",
469
+ `The ${route.component} route's prerender option has been changed multiple times by integrations:
470
+ ` + prerenderChangeLogs.map((log) => `- ${log.integrationName}: ${log.value}`).join("\n")
471
+ );
472
+ }
473
+ }
422
474
  function isFunctionPerRouteEnabled(adapter) {
423
475
  if (adapter?.adapterFeatures?.functionPerRoute === true) {
424
476
  return true;
@@ -429,6 +481,7 @@ function isFunctionPerRouteEnabled(adapter) {
429
481
  export {
430
482
  getToolbarServerCommunicationHelpers,
431
483
  isFunctionPerRouteEnabled,
484
+ normalizeInjectedTypeFilename,
432
485
  runHookBuildDone,
433
486
  runHookBuildGenerated,
434
487
  runHookBuildSetup,
@@ -436,6 +489,7 @@ export {
436
489
  runHookBuildStart,
437
490
  runHookConfigDone,
438
491
  runHookConfigSetup,
492
+ runHookRouteSetup,
439
493
  runHookServerDone,
440
494
  runHookServerSetup,
441
495
  runHookServerStart
@@ -32,5 +32,5 @@ export interface AstroPreferences {
32
32
  }
33
33
  export declare function isValidKey(key: string): key is PreferenceKey;
34
34
  export declare function coerce(key: string, value: unknown): any;
35
- export default function createPreferences(config: AstroConfig): AstroPreferences;
35
+ export default function createPreferences(config: AstroConfig, dotAstroDir: URL): AstroPreferences;
36
36
  export {};
@@ -25,9 +25,9 @@ function coerce(key, value) {
25
25
  }
26
26
  return value;
27
27
  }
28
- function createPreferences(config) {
28
+ function createPreferences(config, dotAstroDir) {
29
29
  const global = new PreferenceStore(getGlobalPreferenceDir());
30
- const project = new PreferenceStore(fileURLToPath(new URL("./.astro/", config.root)));
30
+ const project = new PreferenceStore(fileURLToPath(dotAstroDir));
31
31
  const stores = { global, project };
32
32
  return {
33
33
  async get(key, { location } = {}) {
@@ -1,3 +1,4 @@
1
+ import { encryptString } from "../../../core/encryption.js";
1
2
  import { renderChild } from "./any.js";
2
3
  import { renderSlotToString } from "./slot.js";
3
4
  const internalProps = /* @__PURE__ */ new Set([
@@ -21,9 +22,9 @@ function renderServerIsland(result, _displayName, props, slots) {
21
22
  if (!componentId) {
22
23
  throw new Error(`Could not find server component name`);
23
24
  }
24
- for (const key of Object.keys(props)) {
25
- if (internalProps.has(key)) {
26
- delete props[key];
25
+ for (const key2 of Object.keys(props)) {
26
+ if (internalProps.has(key2)) {
27
+ delete props[key2];
27
28
  }
28
29
  }
29
30
  destination.write("<!--server-island-start-->");
@@ -36,15 +37,18 @@ function renderServerIsland(result, _displayName, props, slots) {
36
37
  await renderChild(destination, slots.fallback(result));
37
38
  }
38
39
  }
40
+ const key = await result.key;
41
+ const propsEncrypted = await encryptString(key, JSON.stringify(props));
39
42
  const hostId = crypto.randomUUID();
40
- const serverIslandUrl = `${result.base}_server-islands/${componentId}${result.trailingSlash === "always" ? "/" : ""}`;
43
+ const slash = result.base.endsWith("/") ? "" : "/";
44
+ const serverIslandUrl = `${result.base}${slash}_server-islands/${componentId}${result.trailingSlash === "always" ? "/" : ""}`;
41
45
  destination.write(`<script async type="module" data-island-id="${hostId}">
42
46
  let componentId = ${safeJsonStringify(componentId)};
43
47
  let componentExport = ${safeJsonStringify(componentExport)};
44
48
  let script = document.querySelector('script[data-island-id="${hostId}"]');
45
49
  let data = {
46
50
  componentExport,
47
- props: ${safeJsonStringify(props)},
51
+ encryptedProps: ${safeJsonStringify(propsEncrypted)},
48
52
  slots: ${safeJsonStringify(renderedSlots)},
49
53
  };
50
54
 
@@ -1,5 +1,6 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import { IncomingMessage } from "node:http";
3
+ import { createKey } from "../core/encryption.js";
3
4
  import { getViteErrorPayload } from "../core/errors/dev/index.js";
4
5
  import { AstroError, AstroErrorData } from "../core/errors/index.js";
5
6
  import { patchOverlay } from "../core/errors/overlay.js";
@@ -117,6 +118,7 @@ function createDevelopmentManifest(settings) {
117
118
  i18n: i18nManifest,
118
119
  checkOrigin: settings.config.security?.checkOrigin ?? false,
119
120
  experimentalEnvGetSecretEnabled: false,
121
+ key: createKey(),
120
122
  middleware(_, next) {
121
123
  return next();
122
124
  }
@@ -1,7 +1,9 @@
1
1
  import type * as vite from 'vite';
2
2
  import type { AstroSettings } from '../@types/astro.js';
3
+ import type { Logger } from '../core/logger/core.js';
3
4
  interface EnvPluginOptions {
4
5
  settings: AstroSettings;
6
+ logger: Logger;
5
7
  }
6
- export default function envVitePlugin({ settings }: EnvPluginOptions): vite.Plugin;
8
+ export default function envVitePlugin({ settings, logger }: EnvPluginOptions): vite.Plugin;
7
9
  export {};
@@ -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
  };
@@ -35,7 +35,7 @@ async function scan(code, id, settings) {
35
35
  const { n: name, le: endOfLocalName } = _export;
36
36
  if (BOOLEAN_EXPORTS.has(name)) {
37
37
  const prefix = code.slice(0, endOfLocalName).split("export").pop().trim().replace("prerender", "").trim();
38
- const suffix = code.slice(endOfLocalName).trim().replace(/=/, "").trim().split(/[;\n]/)[0];
38
+ const suffix = code.slice(endOfLocalName).trim().replace(/=/, "").trim().split(/[;\n\r]/)[0].trim();
39
39
  if (prefix !== "const" || !(isTruthy(suffix) || isFalsy(suffix))) {
40
40
  throw new AstroError({
41
41
  ...AstroErrorData.InvalidPrerenderExport,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "4.13.3",
3
+ "version": "4.14.0",
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",
@@ -107,13 +108,15 @@
107
108
  "vendor"
108
109
  ],
109
110
  "dependencies": {
110
- "@astrojs/compiler": "^2.10.1",
111
+ "@astrojs/compiler": "^2.10.2",
111
112
  "@babel/core": "^7.25.2",
112
113
  "@babel/generator": "^7.25.0",
113
114
  "@babel/parser": "^7.25.3",
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",
119
+ "@oslojs/encoding": "^0.4.1",
117
120
  "@types/babel__core": "^7.20.5",
118
121
  "@types/cookie": "^0.6.0",
119
122
  "acorn": "^8.12.1",
@@ -144,7 +147,9 @@
144
147
  "js-yaml": "^4.1.0",
145
148
  "kleur": "^4.1.5",
146
149
  "magic-string": "^0.30.11",
150
+ "micromatch": "^4.0.7",
147
151
  "mrmime": "^2.0.0",
152
+ "neotraverse": "^0.6.9",
148
153
  "ora": "^8.0.1",
149
154
  "p-limit": "^6.1.0",
150
155
  "p-queue": "^8.0.1",
@@ -159,12 +164,13 @@
159
164
  "tsconfck": "^3.1.1",
160
165
  "unist-util-visit": "^5.0.0",
161
166
  "vfile": "^6.0.2",
162
- "vite": "^5.3.5",
167
+ "vite": "^5.4.0",
163
168
  "vitefu": "^0.2.5",
164
169
  "which-pm": "^3.0.0",
165
- "yargs-parser": "^21.1.1",
170
+ "xxhash-wasm": "^1.0.2",
166
171
  "zod": "^3.23.8",
167
172
  "zod-to-json-schema": "^3.23.2",
173
+ "zod-to-ts": "^1.2.0",
168
174
  "@astrojs/internal-helpers": "0.4.1",
169
175
  "@astrojs/markdown-remark": "5.2.0",
170
176
  "@astrojs/telemetry": "3.1.0"
@@ -173,8 +179,8 @@
173
179
  "sharp": "^0.33.3"
174
180
  },
175
181
  "devDependencies": {
176
- "@astrojs/check": "^0.9.1",
177
- "@playwright/test": "^1.45.3",
182
+ "@astrojs/check": "^0.9.2",
183
+ "@playwright/test": "^1.46.0",
178
184
  "@types/aria-query": "^5.0.4",
179
185
  "@types/babel__generator": "^7.6.8",
180
186
  "@types/babel__traverse": "^7.20.6",
@@ -188,10 +194,10 @@
188
194
  "@types/html-escaper": "^3.0.2",
189
195
  "@types/http-cache-semantics": "^4.0.4",
190
196
  "@types/js-yaml": "^4.0.9",
197
+ "@types/micromatch": "^4.0.9",
191
198
  "@types/prompts": "^2.4.9",
192
199
  "@types/semver": "^7.5.8",
193
- "@types/yargs-parser": "^21.0.3",
194
- "cheerio": "1.0.0-rc.12",
200
+ "cheerio": "1.0.0",
195
201
  "eol": "^0.9.1",
196
202
  "expect-type": "^0.19.0",
197
203
  "mdast-util-mdx": "^3.0.0",
@@ -205,7 +211,7 @@
205
211
  "remark-code-titles": "^0.1.2",
206
212
  "rollup": "^4.20.0",
207
213
  "sass": "^1.77.8",
208
- "undici": "^6.19.5",
214
+ "undici": "^6.19.7",
209
215
  "unified": "^11.0.5",
210
216
  "astro-scripts": "0.0.14"
211
217
  },
@@ -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>;