astro 1.7.1 → 1.8.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 (37) hide show
  1. package/README.md +1 -1
  2. package/components/Shiki.js +1 -1
  3. package/dist/@types/astro.d.ts +40 -5
  4. package/dist/cli/index.js +8 -0
  5. package/dist/cli/sync/index.d.ts +8 -0
  6. package/dist/cli/sync/index.js +25 -0
  7. package/dist/content/index.d.ts +2 -0
  8. package/dist/content/index.js +6 -1
  9. package/dist/content/types-generator.d.ts +2 -3
  10. package/dist/content/types-generator.js +6 -4
  11. package/dist/content/vite-plugin-content-server.js +1 -2
  12. package/dist/core/build/generate.js +4 -1
  13. package/dist/core/build/static-build.js +3 -1
  14. package/dist/core/build/vite-plugin-pages.js +2 -2
  15. package/dist/core/build/vite-plugin-ssr.js +4 -1
  16. package/dist/core/constants.js +1 -1
  17. package/dist/core/create-vite.js +1 -1
  18. package/dist/core/dev/container.js +1 -1
  19. package/dist/core/dev/dev.js +1 -1
  20. package/dist/core/errors/errors-data.d.ts +30 -5
  21. package/dist/core/errors/errors-data.js +11 -1
  22. package/dist/core/errors/utils.d.ts +10 -2
  23. package/dist/core/messages.js +2 -2
  24. package/dist/core/render/dev/environment.js +4 -1
  25. package/dist/core/render/environment.js +4 -1
  26. package/dist/core/render/route-cache.d.ts +1 -1
  27. package/dist/runtime/server/index.d.ts +1 -1
  28. package/dist/vite-plugin-astro/compile.js +6 -1
  29. package/dist/vite-plugin-astro-postprocess/index.js +28 -34
  30. package/dist/vite-plugin-config-alias/index.d.ts +1 -1
  31. package/dist/vite-plugin-env/index.js +2 -2
  32. package/dist/vite-plugin-head-propagation/index.d.ts +1 -1
  33. package/dist/vite-plugin-head-propagation/index.js +2 -0
  34. package/dist/vite-plugin-jsx/index.js +6 -1
  35. package/dist/vite-plugin-markdown/index.js +5 -2
  36. package/dist/vite-plugin-markdown-legacy/index.js +7 -4
  37. package/package.json +4 -3
package/README.md CHANGED
@@ -26,7 +26,7 @@ Looking for quick examples? [Open a starter project](https://astro.new/) right i
26
26
 
27
27
  ## Documentation
28
28
 
29
- Visit our [offical documentation](https://docs.astro.build/).
29
+ Visit our [official documentation](https://docs.astro.build/).
30
30
 
31
31
  ## Support
32
32
 
@@ -2,7 +2,7 @@ import { getHighlighter as getShikiHighlighter } from 'shiki';
2
2
  import { themes } from './shiki-themes.js';
3
3
  import { languages } from './shiki-languages.js';
4
4
 
5
- // Caches Promise<Highligher> for reuse when the same theme and langs are provided
5
+ // Caches Promise<Highlighter> for reuse when the same theme and langs are provided
6
6
  const _resolvedHighlighters = new Map();
7
7
 
8
8
  /** @type {Promise<any>} */
@@ -1,7 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ /// <reference types="node" />
3
4
  import type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, RemarkRehype, ShikiConfig } from '@astrojs/markdown-remark';
4
5
  import type * as babel from '@babel/core';
6
+ import type { OutgoingHttpHeaders } from 'http';
5
7
  import type { AddressInfo } from 'net';
6
8
  import type { TsConfigJson } from 'tsconfig-resolver';
7
9
  import type * as vite from 'vite';
@@ -287,6 +289,15 @@ declare type ServerConfig = {
287
289
  * If the given port is already in use, Astro will automatically try the next available port.
288
290
  */
289
291
  port?: number;
292
+ /**
293
+ * @name server.headers
294
+ * @typeraw {OutgoingHttpHeaders}
295
+ * @default `{}`
296
+ * @version 1.7.0
297
+ * @description
298
+ * Set custom HTTP response headers to be sent in `astro dev` and `astro preview`.
299
+ */
300
+ headers?: OutgoingHttpHeaders;
290
301
  };
291
302
  export interface ViteUserConfig extends vite.UserConfig {
292
303
  ssr?: vite.SSROptions;
@@ -618,6 +629,15 @@ export interface AstroUserConfig {
618
629
  * }
619
630
  * ```
620
631
  */
632
+ /**
633
+ * @docs
634
+ * @name server.headers
635
+ * @typeraw {OutgoingHttpHeaders}
636
+ * @default `{}`
637
+ * @version 1.7.0
638
+ * @description
639
+ * Set custom HTTP response headers to be sent in `astro dev` and `astro preview`.
640
+ */
621
641
  server?: ServerConfig | ((options: {
622
642
  command: 'dev' | 'preview';
623
643
  }) => ServerConfig);
@@ -763,7 +783,7 @@ export interface AstroUserConfig {
763
783
  *
764
784
  * Extend Astro with custom integrations. Integrations are your one-stop-shop for adding framework support (like Solid.js), new features (like sitemaps), and new libraries (like Partytown and Turbolinks).
765
785
  *
766
- * Read our [Integrations Guide](/en/guides/integrations-guide/) for help getting started with Astro Integrations.
786
+ * Read our [Integrations Guide](https://docs.astro.build/en/guides/integrations-guide/) for help getting started with Astro Integrations.
767
787
  *
768
788
  * ```js
769
789
  * import react from '@astrojs/react';
@@ -826,9 +846,9 @@ export interface AstroUserConfig {
826
846
  * @version 1.0.0-rc.1
827
847
  * @description
828
848
  * Enable Astro's pre-v1.0 support for components and JSX expressions in `.md` (and alternative extensions for markdown files like ".markdown") Markdown files.
829
- * In Astro `1.0.0-rc`, this original behavior was removed as the default, in favor of our new [MDX integration](/en/guides/integrations-guide/mdx/).
849
+ * In Astro `1.0.0-rc`, this original behavior was removed as the default, in favor of our new [MDX integration](https://docs.astro.build/en/guides/integrations-guide/mdx/).
830
850
  *
831
- * To enable this behavior, set `legacy.astroFlavoredMarkdown` to `true` in your [`astro.config.mjs` configuration file](/en/guides/configuring-astro/#the-astro-config-file).
851
+ * To enable this behavior, set `legacy.astroFlavoredMarkdown` to `true` in your [`astro.config.mjs` configuration file](https://docs.astro.build/en/guides/configuring-astro/#the-astro-config-file).
832
852
  *
833
853
  * ```js
834
854
  * {
@@ -851,8 +871,23 @@ export interface AstroUserConfig {
851
871
  */
852
872
  experimental?: {
853
873
  /**
854
- * @hidden
874
+ * @docs
875
+ * @name experimental.errorOverlay
876
+ * @type {boolean}
877
+ * @default `false`
878
+ * @version 1.7.0
879
+ * @description
855
880
  * Turn on experimental support for the new error overlay component.
881
+ *
882
+ * To enable this feature, set `experimental.errorOverlay` to `true` in your Astro config:
883
+ *
884
+ * ```js
885
+ * {
886
+ * experimental: {
887
+ * errorOverlay: true,
888
+ * },
889
+ * }
890
+ * ```
856
891
  */
857
892
  errorOverlay?: boolean;
858
893
  /**
@@ -882,7 +917,7 @@ export interface AstroUserConfig {
882
917
  * @default `false`
883
918
  * @version 1.7.0
884
919
  * @description
885
- * Enable experimental support for [Content Collections](/en/guides/content-collections). This makes the `src/content/` directory a reserved directory for Astro to manage, and introduces the `astro:content` module for querying this content.
920
+ * Enable experimental support for [Content Collections](https://docs.astro.build/en/guides/content-collections/). This makes the `src/content/` directory a reserved directory for Astro to manage, and introduces the `astro:content` module for querying this content.
886
921
  *
887
922
  * To enable this feature, set `experimental.contentCollections` to `true` in your Astro config:
888
923
  *
package/dist/cli/index.js CHANGED
@@ -31,6 +31,7 @@ function printAstroHelp() {
31
31
  ["dev", "Start the development server."],
32
32
  ["docs", "Open documentation in your web browser."],
33
33
  ["preview", "Preview your build locally."],
34
+ ["sync", "Generate content collection types."],
34
35
  ["telemetry", "Configure telemetry settings."]
35
36
  ],
36
37
  "Global Flags": [
@@ -54,6 +55,8 @@ function resolveCommand(flags) {
54
55
  const cmd = flags._[2];
55
56
  if (cmd === "add")
56
57
  return "add";
58
+ if (cmd === "sync")
59
+ return "sync";
57
60
  if (cmd === "telemetry")
58
61
  return "telemetry";
59
62
  if (flags.version)
@@ -153,6 +156,11 @@ async function runCommand(cmd, flags) {
153
156
  const ret = await check(settings);
154
157
  return process.exit(ret);
155
158
  }
159
+ case "sync": {
160
+ const { sync } = await import("./sync/index.js");
161
+ const ret = await sync(settings, { logging, fs });
162
+ return process.exit(ret);
163
+ }
156
164
  case "preview": {
157
165
  const { default: preview } = await import("../core/preview/index.js");
158
166
  const server = await preview(settings, { logging, telemetry });
@@ -0,0 +1,8 @@
1
+ /// <reference types="node" />
2
+ import type fsMod from 'node:fs';
3
+ import type { AstroSettings } from '../../@types/astro';
4
+ import { LogOptions } from '../../core/logger/core.js';
5
+ export declare function sync(settings: AstroSettings, { logging, fs }: {
6
+ logging: LogOptions;
7
+ fs: typeof fsMod;
8
+ }): Promise<0 | 1>;
@@ -0,0 +1,25 @@
1
+ import { dim } from "kleur/colors";
2
+ import { performance } from "node:perf_hooks";
3
+ import { contentObservable, createContentTypesGenerator } from "../../content/index.js";
4
+ import { getTimeStat } from "../../core/build/util.js";
5
+ import { AstroError, AstroErrorData } from "../../core/errors/index.js";
6
+ import { info } from "../../core/logger/core.js";
7
+ async function sync(settings, { logging, fs }) {
8
+ const timerStart = performance.now();
9
+ try {
10
+ const contentTypesGenerator = await createContentTypesGenerator({
11
+ contentConfigObserver: contentObservable({ status: "loading" }),
12
+ logging,
13
+ fs,
14
+ settings
15
+ });
16
+ await contentTypesGenerator.init();
17
+ } catch (e) {
18
+ throw new AstroError(AstroErrorData.GenerateContentTypesError);
19
+ }
20
+ info(logging, "content", `Types generated ${dim(getTimeStat(timerStart, performance.now()))}`);
21
+ return 0;
22
+ }
23
+ export {
24
+ sync
25
+ };
@@ -1,3 +1,5 @@
1
+ export { createContentTypesGenerator } from './types-generator.js';
2
+ export { contentObservable, getContentPaths } from './utils.js';
1
3
  export { astroBundleDelayedAssetPlugin, astroDelayedAssetPlugin, } from './vite-plugin-content-assets.js';
2
4
  export { astroContentServerPlugin } from './vite-plugin-content-server.js';
3
5
  export { astroContentVirtualModPlugin } from './vite-plugin-content-virtual-mod.js';
@@ -1,3 +1,5 @@
1
+ import { createContentTypesGenerator } from "./types-generator.js";
2
+ import { contentObservable, getContentPaths } from "./utils.js";
1
3
  import {
2
4
  astroBundleDelayedAssetPlugin,
3
5
  astroDelayedAssetPlugin
@@ -8,5 +10,8 @@ export {
8
10
  astroBundleDelayedAssetPlugin,
9
11
  astroContentServerPlugin,
10
12
  astroContentVirtualModPlugin,
11
- astroDelayedAssetPlugin
13
+ astroDelayedAssetPlugin,
14
+ contentObservable,
15
+ createContentTypesGenerator,
16
+ getContentPaths
12
17
  };
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import fsMod from 'node:fs';
2
+ import type fsMod from 'node:fs';
3
3
  import type { AstroSettings } from '../@types/astro.js';
4
4
  import { LogOptions } from '../core/logger/core.js';
5
5
  import { ContentObservable, ContentPaths } from './utils.js';
@@ -18,13 +18,12 @@ export declare type GenerateContentTypes = {
18
18
  queueEvent(event: RawContentEvent): void;
19
19
  };
20
20
  declare type CreateContentGeneratorParams = {
21
- contentPaths: ContentPaths;
22
21
  contentConfigObserver: ContentObservable;
23
22
  logging: LogOptions;
24
23
  settings: AstroSettings;
25
24
  fs: typeof fsMod;
26
25
  };
27
- export declare function createContentTypesGenerator({ contentPaths, contentConfigObserver, fs, logging, settings, }: CreateContentGeneratorParams): Promise<GenerateContentTypes>;
26
+ export declare function createContentTypesGenerator({ contentConfigObserver, fs, logging, settings, }: CreateContentGeneratorParams): Promise<GenerateContentTypes>;
28
27
  export declare function getEntryInfo({ entry, contentDir, }: Pick<ContentPaths, 'contentDir'> & {
29
28
  entry: URL;
30
29
  }): EntryInfo | Error;
@@ -1,26 +1,28 @@
1
1
  import glob from "fast-glob";
2
2
  import { cyan } from "kleur/colors";
3
- import fsMod from "node:fs";
4
3
  import * as path from "node:path";
5
4
  import { fileURLToPath, pathToFileURL } from "node:url";
6
5
  import { normalizePath } from "vite";
7
6
  import { info, warn } from "../core/logger/core.js";
8
7
  import { appendForwardSlash, isRelativePath } from "../core/path.js";
9
8
  import { contentFileExts, CONTENT_TYPES_FILE } from "./consts.js";
10
- import { loadContentConfig } from "./utils.js";
9
+ import {
10
+ getContentPaths,
11
+ loadContentConfig
12
+ } from "./utils.js";
11
13
  class UnsupportedFileTypeError extends Error {
12
14
  }
13
15
  async function createContentTypesGenerator({
14
- contentPaths,
15
16
  contentConfigObserver,
16
17
  fs,
17
18
  logging,
18
19
  settings
19
20
  }) {
20
21
  const contentTypes = {};
22
+ const contentPaths = getContentPaths({ srcDir: settings.config.srcDir });
21
23
  let events = [];
22
24
  let debounceTimeout;
23
- const contentTypesBase = await fsMod.promises.readFile(
25
+ const contentTypesBase = await fs.promises.readFile(
24
26
  new URL(CONTENT_TYPES_FILE, contentPaths.generatedInputDir),
25
27
  "utf-8"
26
28
  );
@@ -43,8 +43,7 @@ function astroContentServerPlugin({
43
43
  fs,
44
44
  settings,
45
45
  logging,
46
- contentConfigObserver,
47
- contentPaths
46
+ contentConfigObserver
48
47
  });
49
48
  await contentGenerator.init();
50
49
  info(logging, "content", "Types generated");
@@ -3,6 +3,7 @@ import * as colors from "kleur/colors";
3
3
  import { bgGreen, black, cyan, dim, green, magenta } from "kleur/colors";
4
4
  import npath from "path";
5
5
  import { fileURLToPath } from "url";
6
+ import { getContentPaths } from "../../content/index.js";
6
7
  import { hasPrerenderedPages } from "../../core/build/internal.js";
7
8
  import {
8
9
  prependForwardSlash,
@@ -237,7 +238,9 @@ async function generatePath(pathname, opts, gopts) {
237
238
  logging,
238
239
  markdown: {
239
240
  ...settings.config.markdown,
240
- isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
241
+ isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown,
242
+ isExperimentalContentCollections: settings.config.experimental.contentCollections,
243
+ contentDir: getContentPaths(settings.config).contentDir
241
244
  },
242
245
  mode: opts.mode,
243
246
  renderers,
@@ -293,7 +293,9 @@ async function cleanServerOutput(opts) {
293
293
  await Promise.all(
294
294
  Array.from(directories).map(async (filename) => {
295
295
  const url = new URL(filename, out);
296
- const dir = await glob(fileURLToPath(url), { absolute: true });
296
+ const dir = await glob(fileURLToPath(url));
297
+ if (filename === "chunks")
298
+ return;
297
299
  if (!dir.length) {
298
300
  await fs.promises.rm(url, { recursive: true, force: true });
299
301
  }
@@ -21,8 +21,8 @@ function vitePluginPages(opts, internals) {
21
21
  let i = 0;
22
22
  for (const pageData of eachPageData(internals)) {
23
23
  const variable = `_page${i}`;
24
- imports.push(`import * as ${variable} from '${pageData.moduleSpecifier}';`);
25
- importMap += `['${pageData.component}', ${variable}],`;
24
+ imports.push(`import * as ${variable} from ${JSON.stringify(pageData.moduleSpecifier)};`);
25
+ importMap += `[${JSON.stringify(pageData.component)}, ${variable}],`;
26
26
  i++;
27
27
  }
28
28
  i = 0;
@@ -1,6 +1,7 @@
1
1
  import glob from "fast-glob";
2
2
  import * as fs from "fs";
3
3
  import { fileURLToPath } from "url";
4
+ import { getContentPaths } from "../../content/index.js";
4
5
  import { runHookBuildSsr } from "../../integrations/index.js";
5
6
  import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
6
7
  import { pagesVirtualModuleId } from "../app/index.js";
@@ -168,7 +169,9 @@ function buildManifest(opts, internals, staticFiles) {
168
169
  base: settings.config.base,
169
170
  markdown: {
170
171
  ...settings.config.markdown,
171
- isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
172
+ isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown,
173
+ isExperimentalContentCollections: settings.config.experimental.contentCollections,
174
+ contentDir: getContentPaths(settings.config).contentDir
172
175
  },
173
176
  pageMap: null,
174
177
  renderers: [],
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "1.7.1";
1
+ const ASTRO_VERSION = "1.8.0";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -93,7 +93,7 @@ async function createVite(commandConfig, { settings, logging, mode, fs = nodeFs
93
93
  root: fileURLToPath(settings.config.root),
94
94
  envPrefix: "PUBLIC_",
95
95
  define: {
96
- "import.meta.env.SITE": settings.config.site ? `'${settings.config.site}'` : "undefined"
96
+ "import.meta.env.SITE": settings.config.site ? JSON.stringify(settings.config.site) : "undefined"
97
97
  },
98
98
  server: {
99
99
  hmr: process.env.NODE_ENV === "test" || process.env.NODE_ENV === "production" ? false : void 0,
@@ -40,7 +40,7 @@ async function createContainer(params = {}) {
40
40
  include: rendererClientEntries
41
41
  },
42
42
  define: {
43
- "import.meta.env.BASE_URL": settings.config.base ? `'${settings.config.base}'` : "undefined"
43
+ "import.meta.env.BASE_URL": settings.config.base ? JSON.stringify(settings.config.base) : "undefined"
44
44
  }
45
45
  },
46
46
  { settings, logging, mode: "dev", fs }
@@ -30,7 +30,7 @@ async function dev(settings, options) {
30
30
  isRestart: options.isRestart
31
31
  })
32
32
  );
33
- const currentVersion = "1.7.1";
33
+ const currentVersion = "1.8.0";
34
34
  if (currentVersion.includes("-")) {
35
35
  warn(options.logging, null, msg.prerelease({ currentVersion }));
36
36
  }
@@ -147,7 +147,7 @@ export declare const AstroErrorData: {
147
147
  * - [`client:only`](https://docs.astro.build/en/reference/directives-reference/#clientonly)
148
148
  * @description
149
149
  *
150
- * `client:only` components are not ran on the server, as such Astro does not know (and cannot guess) which renderer to use and require a hint. Like such:
150
+ * `client:only` components are not run on the server, as such Astro does not know (and cannot guess) which renderer to use and require a hint. Like such:
151
151
  *
152
152
  * ```astro
153
153
  * <SomeReactComponent client:only="react" />
@@ -319,7 +319,7 @@ export declare const AstroErrorData: {
319
319
  * - [Server-side Rendering](https://docs.astro.build/en/guides/server-side-rendering/)
320
320
  * - [Adding an Adapter](https://docs.astro.build/en/guides/server-side-rendering/#adding-an-adapter)
321
321
  * @description
322
- * To use server-side rendering, an adapter needs to be installed so Astro knows how to generate the proper output for your targetted deployment platform.
322
+ * To use server-side rendering, an adapter needs to be installed so Astro knows how to generate the proper output for your targeted deployment platform.
323
323
  */
324
324
  readonly NoAdapterInstalled: {
325
325
  readonly title: "Cannot use Server-side Rendering without an adapter.";
@@ -340,8 +340,11 @@ export declare const AstroErrorData: {
340
340
  };
341
341
  /**
342
342
  * @docs
343
+ * @message
344
+ * **Example error messages:**<br/>
345
+ * InvalidPrerenderExport: A `prerender` export has been detected, but its value cannot be statically analyzed.
343
346
  * @description
344
- * A `prerender` export was detected, but the value was not statically analyzable. Values computed at runtime are not supported, so `export const prerender` can only be set to `true` or `false`. Variables are not supported.
347
+ * The `prerender` feature only supports a subset of valid JavaScript be sure to use exactly `export const prerender = true` so that our compiler can detect this directive at build time. Variables, `let`, and `var` declarations are not supported.
345
348
  */
346
349
  readonly InvalidPrerenderExport: {
347
350
  readonly title: "Invalid prerender export.";
@@ -438,13 +441,13 @@ export declare const AstroErrorData: {
438
441
  * A Markdown document's frontmatter in `src/content/` does not match its collection schema.
439
442
  * Make sure that all required fields are present, and that all fields are of the correct type.
440
443
  * You can check against the collection schema in your `src/content/config.*` file.
441
- * See the [Content collections documentation](https://docs.astro.build/en/guides/content-collections) for more information.
444
+ * See the [Content collections documentation](https://docs.astro.build/en/guides/content-collections/) for more information.
442
445
  */
443
446
  readonly MarkdownContentSchemaValidationError: {
444
447
  readonly title: "Content collection frontmatter invalid.";
445
448
  readonly code: 6002;
446
449
  readonly message: (collection: string, entryId: string, error: ZodError) => string;
447
- readonly hint: "See https://docs.astro.build/en/guides/content-collections for more information on content schemas.";
450
+ readonly hint: "See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.";
448
451
  };
449
452
  readonly UnknownConfigError: {
450
453
  readonly title: "Unknown configuration error.";
@@ -476,6 +479,28 @@ export declare const AstroErrorData: {
476
479
  readonly message: (legacyConfigKey: string) => string;
477
480
  readonly hint: "Please update your configuration to the new format.\nSee https://astro.build/config for more information.";
478
481
  };
482
+ /**
483
+ * @docs
484
+ * @kind heading
485
+ * @name CLI Errors
486
+ */
487
+ readonly UnknownCLIError: {
488
+ readonly title: "Unknown CLI Error.";
489
+ readonly code: 8000;
490
+ };
491
+ /**
492
+ * @docs
493
+ * @description
494
+ * `astro sync` command failed to generate content collection types.
495
+ * @see
496
+ * - [Content collections documentation](https://docs.astro.build/en/guides/content-collections/)
497
+ */
498
+ readonly GenerateContentTypesError: {
499
+ readonly title: "Failed to generate content types.";
500
+ readonly code: 8001;
501
+ readonly message: "`astro sync` command failed to generate content collection types.";
502
+ readonly hint: "Check your `src/content/config.*` file for typos.";
503
+ };
479
504
  readonly UnknownError: {
480
505
  readonly title: "Unknown Error.";
481
506
  readonly code: 99999;
@@ -173,7 +173,7 @@ Expected \`true\` value but got \`${suffix}\`.`;
173
173
  ...error.errors.map((zodError) => zodError.message)
174
174
  ].join("\n");
175
175
  },
176
- hint: "See https://docs.astro.build/en/guides/content-collections for more information on content schemas."
176
+ hint: "See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas."
177
177
  },
178
178
  UnknownConfigError: {
179
179
  title: "Unknown configuration error.",
@@ -190,6 +190,16 @@ Expected \`true\` value but got \`${suffix}\`.`;
190
190
  message: (legacyConfigKey) => `Legacy configuration detected: \`${legacyConfigKey}\`.`,
191
191
  hint: "Please update your configuration to the new format.\nSee https://astro.build/config for more information."
192
192
  },
193
+ UnknownCLIError: {
194
+ title: "Unknown CLI Error.",
195
+ code: 8e3
196
+ },
197
+ GenerateContentTypesError: {
198
+ title: "Failed to generate content types.",
199
+ code: 8001,
200
+ message: "`astro sync` command failed to generate content collection types.",
201
+ hint: "Check your `src/content/config.*` file for typos."
202
+ },
193
203
  UnknownError: {
194
204
  title: "Unknown Error.",
195
205
  code: 99999
@@ -3,7 +3,7 @@ import { AstroErrorCodes } from './errors-data.js';
3
3
  /**
4
4
  * Get the line and character based on the offset
5
5
  * @param offset The index of the position
6
- * @param text The text for which the position should be retrived
6
+ * @param text The text for which the position should be retrieved
7
7
  */
8
8
  export declare function positionAt(offset: number, text: string): {
9
9
  line: number;
@@ -138,7 +138,7 @@ export declare function getErrorDataByCode(code: AstroErrorCodes | DiagnosticCod
138
138
  readonly title: "Content collection frontmatter invalid.";
139
139
  readonly code: 6002;
140
140
  readonly message: (collection: string, entryId: string, error: import("zod").ZodError<any>) => string;
141
- readonly hint: "See https://docs.astro.build/en/guides/content-collections for more information on content schemas.";
141
+ readonly hint: "See https://docs.astro.build/en/guides/content-collections/ for more information on content schemas.";
142
142
  } | {
143
143
  readonly title: "Unknown configuration error.";
144
144
  readonly code: 7000;
@@ -151,6 +151,14 @@ export declare function getErrorDataByCode(code: AstroErrorCodes | DiagnosticCod
151
151
  readonly code: 7002;
152
152
  readonly message: (legacyConfigKey: string) => string;
153
153
  readonly hint: "Please update your configuration to the new format.\nSee https://astro.build/config for more information.";
154
+ } | {
155
+ readonly title: "Unknown CLI Error.";
156
+ readonly code: 8000;
157
+ } | {
158
+ readonly title: "Failed to generate content types.";
159
+ readonly code: 8001;
160
+ readonly message: "`astro sync` command failed to generate content collection types.";
161
+ readonly hint: "Check your `src/content/config.*` file for typos.";
154
162
  } | {
155
163
  readonly title: "Unknown Error.";
156
164
  readonly code: 99999;
@@ -49,7 +49,7 @@ function serverStart({
49
49
  site,
50
50
  isRestart = false
51
51
  }) {
52
- const version = "1.7.1";
52
+ const version = "1.8.0";
53
53
  const rootPath = site ? site.pathname : "/";
54
54
  const localPrefix = `${dim("\u2503")} Local `;
55
55
  const networkPrefix = `${dim("\u2503")} Network `;
@@ -272,7 +272,7 @@ function printHelp({
272
272
  message.push(
273
273
  linebreak(),
274
274
  ` ${bgGreen(black(` ${commandName} `))} ${green(
275
- `v${"1.7.1"}`
275
+ `v${"1.8.0"}`
276
276
  )} ${headline}`
277
277
  );
278
278
  }
@@ -1,3 +1,4 @@
1
+ import { getContentPaths } from "../../../content/index.js";
1
2
  import { createEnvironment } from "../index.js";
2
3
  import { RouteCache } from "../route-cache.js";
3
4
  import { createResolve } from "./resolve.js";
@@ -9,7 +10,9 @@ function createDevelopmentEnvironment(settings, logging, loader) {
9
10
  logging,
10
11
  markdown: {
11
12
  ...settings.config.markdown,
12
- isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown
13
+ isAstroFlavoredMd: settings.config.legacy.astroFlavoredMarkdown,
14
+ isExperimentalContentCollections: settings.config.experimental.contentCollections,
15
+ contentDir: getContentPaths(settings.config).contentDir
13
16
  },
14
17
  mode,
15
18
  renderers: [],
@@ -6,7 +6,10 @@ function createBasicEnvironment(options) {
6
6
  const mode = options.mode ?? "development";
7
7
  return createEnvironment({
8
8
  ...options,
9
- markdown: options.markdown ?? {},
9
+ markdown: {
10
+ ...options.markdown ?? {},
11
+ contentDir: new URL("file:///src/content/")
12
+ },
10
13
  mode,
11
14
  renderers: options.renderers ?? [],
12
15
  resolve: options.resolve ?? ((s) => Promise.resolve(s)),
@@ -12,7 +12,7 @@ export interface RouteCacheEntry {
12
12
  staticPaths: GetStaticPathsResultKeyed;
13
13
  }
14
14
  /**
15
- * Manange the route cache, responsible for caching data related to each route,
15
+ * Manage the route cache, responsible for caching data related to each route,
16
16
  * including the result of calling getStaticPath() so that it can be reused across
17
17
  * responses during dev and only ever called once during build.
18
18
  */
@@ -6,7 +6,7 @@ export { renderJSX } from './jsx.js';
6
6
  export { addAttribute, createHeadAndContent, defineScriptVars, Fragment, maybeRenderHead, renderAstroTemplateResult as renderAstroComponent, renderComponent, renderComponentToIterable, Renderer as Renderer, renderHead, renderHTMLElement, renderPage, renderSlot, renderStyleElement, renderTemplate as render, renderTemplate, renderToString, renderUniqueStylesheet, stringifyChunk, voidElementNames, } from './render/index.js';
7
7
  export type { AstroComponentFactory, AstroComponentInstance, AstroComponentSlots, AstroComponentSlotsWithValues, RenderInstruction, } from './render/index.js';
8
8
  export declare function mergeSlots(...slotted: unknown[]): Record<string, () => any>;
9
- /** @internal Assosciate JSX components with a specific renderer (see /src/vite-plugin-jsx/tag.ts) */
9
+ /** @internal Associate JSX components with a specific renderer (see /src/vite-plugin-jsx/tag.ts) */
10
10
  export declare function __astro_tag_component__(Component: unknown, rendererName: string): void;
11
11
  export declare function spreadAttributes(values: Record<any, any>, _name?: string, { class: scopedClassName }?: {
12
12
  class?: string;
@@ -15,7 +15,12 @@ async function cachedFullCompilation({
15
15
  esbuildResult = await transformWithEsbuild(transformResult.code, rawId, {
16
16
  loader: "ts",
17
17
  target: "esnext",
18
- sourcemap: "external"
18
+ sourcemap: "external",
19
+ tsconfigRaw: {
20
+ compilerOptions: {
21
+ importsNotUsedAsValues: "remove"
22
+ }
23
+ }
19
24
  });
20
25
  } catch (err) {
21
26
  await enhanceCompileError({
@@ -1,5 +1,6 @@
1
- import { parse as babelParser } from "@babel/parser";
2
- import { parse, print, types, visit } from "recast";
1
+ import { parse } from "acorn";
2
+ import { walk } from "estree-walker";
3
+ import MagicString from "magic-string";
3
4
  import { isMarkdownFile } from "../core/util.js";
4
5
  const ASTRO_GLOB_REGEX = /Astro2?\s*\.\s*glob\s*\(/;
5
6
  function astro(_opts) {
@@ -12,43 +13,36 @@ function astro(_opts) {
12
13
  if (!ASTRO_GLOB_REGEX.test(code)) {
13
14
  return null;
14
15
  }
16
+ let s;
15
17
  const ast = parse(code, {
16
- parser: { parse: babelParser }
18
+ ecmaVersion: "latest",
19
+ sourceType: "module"
17
20
  });
18
- visit(ast, {
19
- visitCallExpression: function(path) {
20
- if (!types.namedTypes.MemberExpression.check(path.node.callee) || !types.namedTypes.Identifier.check(path.node.callee.property) || !(path.node.callee.property.name === "glob") || !types.namedTypes.Identifier.check(path.node.callee.object) || !(path.node.callee.object.name === "Astro" || path.node.callee.object.name === "Astro2")) {
21
- this.traverse(path);
22
- return;
23
- }
24
- const argsPath = path.get("arguments", 0);
25
- const args = argsPath.value;
26
- argsPath.replace(
27
- {
28
- type: "CallExpression",
29
- callee: {
30
- type: "MemberExpression",
31
- object: {
32
- type: "MetaProperty",
33
- meta: { type: "Identifier", name: "import" },
34
- property: { type: "Identifier", name: "meta" }
35
- },
36
- property: { type: "Identifier", name: "glob" },
37
- computed: false
38
- },
39
- arguments: [args]
40
- },
41
- {
42
- type: "ArrowFunctionExpression",
43
- body: args,
44
- params: []
21
+ walk(ast, {
22
+ enter(node) {
23
+ if (node.type === "CallExpression" && node.callee.type === "MemberExpression" && node.callee.property.name === "glob" && (node.callee.object.name === "Astro" || node.callee.object.name === "Astro2") && node.arguments.length) {
24
+ const firstArgStart = node.arguments[0].start;
25
+ const firstArgEnd = node.arguments[0].end;
26
+ const lastArgEnd = node.arguments[node.arguments.length - 1].end;
27
+ let firstArg = code.slice(firstArgStart, firstArgEnd);
28
+ if (firstArg.startsWith("`") && firstArg.endsWith("`") && !firstArg.includes("${")) {
29
+ firstArg = JSON.stringify(firstArg.slice(1, -1));
45
30
  }
46
- );
47
- return false;
31
+ s ?? (s = new MagicString(code));
32
+ s.overwrite(
33
+ firstArgStart,
34
+ lastArgEnd,
35
+ `import.meta.glob(${firstArg}), () => ${firstArg}`
36
+ );
37
+ }
48
38
  }
49
39
  });
50
- const result = print(ast);
51
- return { code: result.code, map: result.map };
40
+ if (s) {
41
+ return {
42
+ code: s.toString(),
43
+ map: s.generateMap()
44
+ };
45
+ }
52
46
  }
53
47
  };
54
48
  }
@@ -5,7 +5,7 @@ export declare interface Alias {
5
5
  find: RegExp;
6
6
  replacement: string;
7
7
  }
8
- /** Returns a Vite plugin used to alias pathes from tsconfig.json and jsconfig.json. */
8
+ /** Returns a Vite plugin used to alias paths from tsconfig.json and jsconfig.json. */
9
9
  export default function configAliasVitePlugin({ settings, }: {
10
10
  settings: AstroSettings;
11
11
  }): vite.PluginOption;
@@ -21,9 +21,9 @@ function getPrivateEnv(viteConfig, astroConfig) {
21
21
  }
22
22
  }
23
23
  }
24
- privateEnv.SITE = astroConfig.site ? `'${astroConfig.site}'` : "undefined";
24
+ privateEnv.SITE = astroConfig.site ? JSON.stringify(astroConfig.site) : "undefined";
25
25
  privateEnv.SSR = JSON.stringify(true);
26
- privateEnv.BASE_URL = astroConfig.base ? `'${astroConfig.base}'` : "undefined";
26
+ privateEnv.BASE_URL = astroConfig.base ? JSON.stringify(astroConfig.base) : "undefined";
27
27
  return privateEnv;
28
28
  }
29
29
  function getReferencedPrivateKeys(source, privateEnv) {
@@ -4,7 +4,7 @@ import * as vite from 'vite';
4
4
  * If any component is marked as doing head injection, walk up the tree
5
5
  * and mark parent Astro components as having head injection in the tree.
6
6
  * This is used at runtime to determine if we should wait for head content
7
- * to be be populated before rendering the entire tree.
7
+ * to be populated before rendering the entire tree.
8
8
  */
9
9
  export default function configHeadPropagationVitePlugin({ settings, }: {
10
10
  settings: AstroSettings;
@@ -9,6 +9,8 @@ function configHeadPropagationVitePlugin({
9
9
  if (parent.id) {
10
10
  if (seen.has(parent.id)) {
11
11
  continue;
12
+ } else {
13
+ seen.add(parent.id);
12
14
  }
13
15
  const info = getInfo(parent.id);
14
16
  if (info == null ? void 0 : info.meta.astro) {
@@ -104,7 +104,12 @@ function jsx({ settings, logging }) {
104
104
  const { code: jsxCode2 } = await transformWithEsbuild(code, id, {
105
105
  loader: getEsbuildLoader(id),
106
106
  jsx: "preserve",
107
- sourcemap: "inline"
107
+ sourcemap: "inline",
108
+ tsconfigRaw: {
109
+ compilerOptions: {
110
+ importsNotUsedAsValues: "remove"
111
+ }
112
+ }
108
113
  });
109
114
  return transformJSX({
110
115
  code: jsxCode2,
@@ -3,6 +3,7 @@ import fs from "fs";
3
3
  import matter from "gray-matter";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { normalizePath } from "vite";
6
+ import { getContentPaths } from "../content/index.js";
6
7
  import { AstroErrorData, MarkdownError } from "../core/errors/index.js";
7
8
  import { warn } from "../core/logger/core.js";
8
9
  import { isMarkdownFile } from "../core/util.js";
@@ -50,7 +51,9 @@ function markdown({ settings, logging }) {
50
51
  const renderResult = await renderMarkdown(raw.content, {
51
52
  ...settings.config.markdown,
52
53
  fileURL: new URL(`file://${fileId}`),
53
- isAstroFlavoredMd: false
54
+ isAstroFlavoredMd: false,
55
+ isExperimentalContentCollections: settings.config.experimental.contentCollections,
56
+ contentDir: getContentPaths(settings.config).contentDir
54
57
  });
55
58
  const html = renderResult.code;
56
59
  const { headings } = renderResult.metadata;
@@ -68,7 +71,7 @@ function markdown({ settings, logging }) {
68
71
  );
69
72
  }
70
73
  const code = escapeViteEnvReferences(`
71
- import { Fragment, jsx as h } from '${astroJsxRuntimeModulePath}';
74
+ import { Fragment, jsx as h } from ${JSON.stringify(astroJsxRuntimeModulePath)};
72
75
  ${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
73
76
 
74
77
  const html = ${JSON.stringify(html)};
@@ -3,6 +3,7 @@ import fs from "fs";
3
3
  import matter from "gray-matter";
4
4
  import { fileURLToPath } from "url";
5
5
  import { transformWithEsbuild } from "vite";
6
+ import { getContentPaths } from "../content/index.js";
6
7
  import { pagesVirtualModuleId } from "../core/app/index.js";
7
8
  import { cachedCompilation } from "../core/compile/index.js";
8
9
  import { AstroErrorData, MarkdownError } from "../core/errors/index.js";
@@ -115,7 +116,9 @@ function markdown({ settings }) {
115
116
  let renderResult = await renderMarkdown(markdownContent, {
116
117
  ...renderOpts,
117
118
  fileURL: fileUrl,
118
- isAstroFlavoredMd: true
119
+ isAstroFlavoredMd: true,
120
+ isExperimentalContentCollections: settings.config.experimental.contentCollections,
121
+ contentDir: getContentPaths(settings.config).contentDir
119
122
  });
120
123
  let { code: astroResult, metadata } = renderResult;
121
124
  const { layout = "", components = "", setup = "", ...content } = frontmatter;
@@ -124,8 +127,8 @@ function markdown({ settings }) {
124
127
  content.file = filename;
125
128
  const prelude = `---
126
129
  import Slugger from 'github-slugger';
127
- ${layout ? `import Layout from '${layout}';` : ""}
128
- ${components ? `import * from '${components}';` : ""}
130
+ ${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
131
+ ${components ? `import * from ${JSON.stringify(components)};` : ""}
129
132
  ${setup}
130
133
 
131
134
  const slugger = new Slugger();
@@ -142,7 +145,7 @@ Object.defineProperty($$content.astro, 'headers', {
142
145
  }
143
146
  });
144
147
  ---`;
145
- const imports = `${layout ? `import Layout from '${layout}';` : ""}
148
+ const imports = `${layout ? `import Layout from ${JSON.stringify(layout)};` : ""}
146
149
  ${setup}`.trim();
147
150
  if (/\bLayout\b/.test(imports)) {
148
151
  astroResult = `${prelude}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro",
3
- "version": "1.7.1",
3
+ "version": "1.8.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",
@@ -97,7 +97,7 @@
97
97
  "dependencies": {
98
98
  "@astrojs/compiler": "^0.31.0",
99
99
  "@astrojs/language-server": "^0.28.3",
100
- "@astrojs/markdown-remark": "^1.1.3",
100
+ "@astrojs/markdown-remark": "^1.2.0",
101
101
  "@astrojs/telemetry": "^1.0.1",
102
102
  "@astrojs/webapi": "^1.1.1",
103
103
  "@babel/core": "^7.18.2",
@@ -111,6 +111,7 @@
111
111
  "@types/babel__core": "^7.1.19",
112
112
  "@types/html-escaper": "^3.0.0",
113
113
  "@types/yargs-parser": "^21.0.0",
114
+ "acorn": "^8.8.1",
114
115
  "boxen": "^6.2.1",
115
116
  "ci-info": "^3.3.1",
116
117
  "common-ancestor-path": "^1.0.1",
@@ -120,6 +121,7 @@
120
121
  "devalue": "^4.2.0",
121
122
  "diff": "^5.1.0",
122
123
  "es-module-lexer": "^1.1.0",
124
+ "estree-walker": "^3.0.1",
123
125
  "execa": "^6.1.0",
124
126
  "fast-glob": "^3.2.11",
125
127
  "github-slugger": "^1.4.0",
@@ -179,7 +181,6 @@
179
181
  "@types/rimraf": "^3.0.2",
180
182
  "@types/send": "^0.17.1",
181
183
  "@types/unist": "^2.0.6",
182
- "ast-types": "^0.14.2",
183
184
  "astro-scripts": "0.0.9",
184
185
  "chai": "^4.3.6",
185
186
  "cheerio": "^1.0.0-rc.11",