astro 4.4.14 → 4.5.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 (98) hide show
  1. package/components/Code.astro +15 -12
  2. package/dist/@types/astro.d.ts +95 -18
  3. package/dist/assets/utils/getAssetsPrefix.d.ts +2 -0
  4. package/dist/assets/utils/getAssetsPrefix.js +14 -0
  5. package/dist/assets/vite-plugin-assets.js +10 -3
  6. package/dist/cli/add/index.js +76 -28
  7. package/dist/cli/install-package.js +2 -2
  8. package/dist/content/types-generator.js +56 -7
  9. package/dist/content/vite-plugin-content-assets.js +11 -3
  10. package/dist/core/app/common.js +2 -0
  11. package/dist/core/app/index.js +10 -2
  12. package/dist/core/app/types.d.ts +7 -2
  13. package/dist/core/base-pipeline.d.ts +2 -1
  14. package/dist/core/base-pipeline.js +2 -1
  15. package/dist/core/build/generate.js +1 -0
  16. package/dist/core/build/internal.d.ts +6 -0
  17. package/dist/core/build/internal.js +1 -0
  18. package/dist/core/build/plugins/index.js +6 -1
  19. package/dist/core/build/plugins/plugin-analyzer.js +10 -98
  20. package/dist/core/build/plugins/plugin-css.js +27 -1
  21. package/dist/core/build/plugins/plugin-manifest.js +5 -2
  22. package/dist/core/build/plugins/plugin-scripts.d.ts +8 -0
  23. package/dist/core/build/plugins/plugin-scripts.js +34 -0
  24. package/dist/core/compile/compile.d.ts +1 -7
  25. package/dist/core/compile/compile.js +5 -4
  26. package/dist/core/compile/style.d.ts +4 -3
  27. package/dist/core/compile/style.js +5 -4
  28. package/dist/core/compile/types.d.ts +11 -0
  29. package/dist/core/config/schema.d.ts +177 -113
  30. package/dist/core/config/schema.js +42 -9
  31. package/dist/core/config/vite-load.js +1 -0
  32. package/dist/core/constants.d.ts +1 -0
  33. package/dist/core/constants.js +3 -1
  34. package/dist/core/create-vite.js +5 -3
  35. package/dist/core/dev/dev.js +1 -1
  36. package/dist/core/errors/dev/vite.js +1 -1
  37. package/dist/core/messages.js +2 -2
  38. package/dist/core/render/params-and-props.js +2 -1
  39. package/dist/core/render/ssr-element.d.ts +8 -8
  40. package/dist/core/render/ssr-element.js +4 -2
  41. package/dist/core/render-context.js +3 -1
  42. package/dist/core/routing/astro-designed-error-pages.d.ts +2 -0
  43. package/dist/core/routing/astro-designed-error-pages.js +21 -0
  44. package/dist/runtime/client/dev-toolbar/apps/audit/index.d.ts +8 -15
  45. package/dist/runtime/client/dev-toolbar/apps/audit/index.js +130 -249
  46. package/dist/runtime/client/dev-toolbar/apps/audit/{a11y.js → rules/a11y.js} +4 -2
  47. package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.d.ts +35 -0
  48. package/dist/runtime/client/dev-toolbar/apps/audit/rules/index.js +40 -0
  49. package/dist/runtime/client/dev-toolbar/apps/audit/{perf.js → rules/perf.js} +2 -2
  50. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-item.d.ts +7 -0
  51. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-item.js +137 -0
  52. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.d.ts +23 -0
  53. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-list-window.js +384 -0
  54. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.d.ts +6 -0
  55. package/dist/runtime/client/dev-toolbar/apps/audit/ui/audit-ui.js +126 -0
  56. package/dist/runtime/client/dev-toolbar/apps/utils/window.d.ts +1 -1
  57. package/dist/runtime/client/dev-toolbar/apps/utils/window.js +3 -1
  58. package/dist/runtime/client/dev-toolbar/entrypoint.js +43 -15
  59. package/dist/runtime/client/dev-toolbar/settings.d.ts +3 -1
  60. package/dist/runtime/client/dev-toolbar/settings.js +8 -2
  61. package/dist/runtime/client/dev-toolbar/toolbar.d.ts +1 -0
  62. package/dist/runtime/client/dev-toolbar/toolbar.js +10 -8
  63. package/dist/runtime/client/dev-toolbar/ui-library/badge.d.ts +14 -4
  64. package/dist/runtime/client/dev-toolbar/ui-library/badge.js +72 -33
  65. package/dist/runtime/client/dev-toolbar/ui-library/button.d.ts +14 -4
  66. package/dist/runtime/client/dev-toolbar/ui-library/button.js +100 -47
  67. package/dist/runtime/client/dev-toolbar/ui-library/card.d.ts +9 -0
  68. package/dist/runtime/client/dev-toolbar/ui-library/card.js +57 -2
  69. package/dist/runtime/client/dev-toolbar/ui-library/highlight.d.ts +9 -0
  70. package/dist/runtime/client/dev-toolbar/ui-library/highlight.js +54 -2
  71. package/dist/runtime/client/dev-toolbar/ui-library/icons.d.ts +4 -0
  72. package/dist/runtime/client/dev-toolbar/ui-library/icons.js +5 -1
  73. package/dist/runtime/client/dev-toolbar/ui-library/toggle.d.ts +9 -0
  74. package/dist/runtime/client/dev-toolbar/ui-library/toggle.js +64 -5
  75. package/dist/runtime/compiler/index.d.ts +1 -1
  76. package/dist/runtime/compiler/index.js +2 -0
  77. package/dist/runtime/server/hydration.js +3 -2
  78. package/dist/runtime/server/index.d.ts +1 -1
  79. package/dist/runtime/server/index.js +2 -0
  80. package/dist/runtime/server/render/astro/factory.d.ts +1 -1
  81. package/dist/runtime/server/render/component.js +4 -5
  82. package/dist/runtime/server/render/index.d.ts +1 -0
  83. package/dist/runtime/server/render/index.js +2 -0
  84. package/dist/runtime/server/render/script.d.ts +6 -0
  85. package/dist/runtime/server/render/script.js +15 -0
  86. package/dist/transitions/router.js +12 -3
  87. package/dist/vite-plugin-astro/index.d.ts +2 -2
  88. package/dist/vite-plugin-astro/index.js +12 -1
  89. package/dist/vite-plugin-astro/types.d.ts +21 -1
  90. package/dist/vite-plugin-astro-server/pipeline.js +6 -2
  91. package/dist/vite-plugin-astro-server/plugin.js +6 -2
  92. package/dist/vite-plugin-astro-server/response.d.ts +6 -0
  93. package/dist/vite-plugin-astro-server/response.js +13 -0
  94. package/dist/vite-plugin-astro-server/route.js +18 -2
  95. package/package.json +8 -9
  96. package/tsconfigs/base.json +3 -1
  97. /package/dist/runtime/client/dev-toolbar/apps/audit/{a11y.d.ts → rules/a11y.d.ts} +0 -0
  98. /package/dist/runtime/client/dev-toolbar/apps/audit/{perf.d.ts → rules/perf.d.ts} +0 -0
@@ -6,34 +6,35 @@ import type {
6
6
  SpecialLanguage,
7
7
  ThemeRegistration,
8
8
  ThemeRegistrationRaw,
9
- } from 'shikiji';
10
- import { bundledLanguages } from 'shikiji/langs';
9
+ } from 'shiki';
10
+ import { bundledLanguages } from 'shiki/langs';
11
11
  import { getCachedHighlighter } from '../dist/core/shiki.js';
12
+ import type { HTMLAttributes } from '../types';
12
13
 
13
- interface Props {
14
+ interface Props extends Omit<HTMLAttributes<'pre'>, 'lang'> {
14
15
  /** The code to highlight. Required. */
15
16
  code: string;
16
17
  /**
17
18
  * The language of your code.
18
- * Supports all languages listed here: https://github.com/shikijs/shiki/blob/main/docs/languages.md#all-languages
19
- * Instructions for loading a custom language: https://github.com/shikijs/shiki/blob/main/docs/languages.md#supporting-your-own-languages-with-shiki
19
+ * Supports all languages listed here: https://shiki.style/languages
20
+ * Instructions for loading a custom language: https://shiki.style/guide/load-lang
20
21
  *
21
22
  * @default "plaintext"
22
23
  */
23
24
  lang?: BuiltinLanguage | SpecialLanguage | LanguageRegistration;
24
25
  /**
25
26
  * The styling theme.
26
- * Supports all themes listed here: https://github.com/shikijs/shiki/blob/main/docs/themes.md#all-themes
27
- * Instructions for loading a custom theme: https://github.com/shikijs/shiki/blob/main/docs/themes.md#loading-theme
27
+ * Supports all themes listed here: https://shiki.style/themes
28
+ * Instructions for loading a custom theme: https://shiki.style/guide/load-theme
28
29
  *
29
30
  * @default "github-dark"
30
31
  */
31
32
  theme?: ThemePresets | ThemeRegistration | ThemeRegistrationRaw;
32
33
  /**
33
34
  * Multiple themes to style with -- alternative to "theme" option.
34
- * Supports all themes found above; see https://github.com/antfu/shikiji#lightdark-dual-themes for more information.
35
+ * Supports all themes found above; see https://shiki.style/guide/dual-themes for more information.
35
36
  */
36
- experimentalThemes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
37
+ themes?: Record<string, ThemePresets | ThemeRegistration | ThemeRegistrationRaw>;
37
38
  /**
38
39
  * Enable word wrapping.
39
40
  * - true: enabled.
@@ -55,12 +56,13 @@ const {
55
56
  code,
56
57
  lang = 'plaintext',
57
58
  theme = 'github-dark',
58
- experimentalThemes = {},
59
+ themes = {},
59
60
  wrap = false,
60
61
  inline = false,
62
+ ...rest
61
63
  } = Astro.props;
62
64
 
63
- // shiki -> shikiji compat
65
+ // shiki 1.0 compat
64
66
  if (typeof lang === 'object') {
65
67
  // `id` renamed to `name` (always override)
66
68
  if ((lang as any).id) {
@@ -81,12 +83,13 @@ const highlighter = await getCachedHighlighter({
81
83
  : lang,
82
84
  ],
83
85
  theme,
84
- experimentalThemes,
86
+ themes,
85
87
  wrap,
86
88
  });
87
89
 
88
90
  const html = highlighter.highlight(code, typeof lang === 'string' ? lang : lang.name, {
89
91
  inline,
92
+ attributes: rest,
90
93
  });
91
94
  ---
92
95
 
@@ -7,7 +7,7 @@ import type * as babel from '@babel/core';
7
7
  import type * as rollup from 'rollup';
8
8
  import type * as vite from 'vite';
9
9
  import type { RemotePattern } from '../assets/utils/remotePattern.js';
10
- import type { SerializedSSRManifest } from '../core/app/types.js';
10
+ import type { AssetsPrefix, SerializedSSRManifest } from '../core/app/types.js';
11
11
  import type { PageBuildData } from '../core/build/types.js';
12
12
  import type { AstroConfigType } from '../core/config/index.js';
13
13
  import type { AstroTimer } from '../core/config/timer.js';
@@ -27,7 +27,7 @@ export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, Rehype
27
27
  export type { ExternalImageService, ImageService, LocalImageService, } from '../assets/services/service.js';
28
28
  export type { GetImageResult, ImageInputFormat, ImageMetadata, ImageOutputFormat, ImageQuality, ImageQualityPreset, ImageTransform, UnresolvedImageTransform, } from '../assets/types.js';
29
29
  export type { RemotePattern } from '../assets/utils/remotePattern.js';
30
- export type { SSRManifest } from '../core/app/types.js';
30
+ export type { SSRManifest, AssetsPrefix } from '../core/app/types.js';
31
31
  export type { AstroCookieGetOptions, AstroCookieSetOptions, AstroCookies, } from '../core/cookies/index.js';
32
32
  export interface AstroBuiltinProps {
33
33
  'client:load'?: boolean;
@@ -779,17 +779,17 @@ export interface AstroUserConfig {
779
779
  /**
780
780
  * @docs
781
781
  * @name build.assetsPrefix
782
- * @type {string}
782
+ * @type {string | Record<string, string>}
783
783
  * @default `undefined`
784
784
  * @version 2.2.0
785
785
  * @description
786
786
  * Specifies the prefix for Astro-generated asset links. This can be used if assets are served from a different domain than the current site.
787
787
  *
788
- * For example, if this is set to `https://cdn.example.com`, assets will be fetched from `https://cdn.example.com/_astro/...` (regardless of the `base` option).
789
- * You would need to upload the files in `./dist/_astro/` to `https://cdn.example.com/_astro/` to serve the assets.
790
- * The process varies depending on how the third-party domain is hosted.
788
+ * This requires uploading the assets in your local `./dist/_astro` folder to a corresponding `/_astro/` folder on the remote domain.
791
789
  * To rename the `_astro` path, specify a new directory in `build.assets`.
792
790
  *
791
+ * To fetch all assets uploaded to the same domain (e.g. `https://cdn.example.com/_astro/...`), set `assetsPrefix` to the root domain as a string (regardless of your `base` configuration):
792
+ *
793
793
  * ```js
794
794
  * {
795
795
  * build: {
@@ -797,8 +797,27 @@ export interface AstroUserConfig {
797
797
  * }
798
798
  * }
799
799
  * ```
800
+ *
801
+ * **Added in:** `astro@4.5.0`
802
+ *
803
+ * You can also pass an object to `assetsPrefix` to specify a different domain for each file type.
804
+ * In this case, a `fallback` property is required and will be used by default for any other files.
805
+ *
806
+ * ```js
807
+ * {
808
+ * build: {
809
+ * assetsPrefix: {
810
+ * 'js': 'https://js.cdn.example.com',
811
+ * 'mjs': 'https://js.cdn.example.com',
812
+ * 'css': 'https://css.cdn.example.com',
813
+ * 'fallback': 'https://cdn.example.com'
814
+ * }
815
+ * }
816
+ * }
817
+ * ```
818
+ *
800
819
  */
801
- assetsPrefix?: string;
820
+ assetsPrefix?: AssetsPrefix;
802
821
  /**
803
822
  * @docs
804
823
  * @name build.serverEntry
@@ -1177,7 +1196,7 @@ export interface AstroUserConfig {
1177
1196
  * @default `shiki`
1178
1197
  * @description
1179
1198
  * Which syntax highlighter to use, if any.
1180
- * - `shiki` - use the [Shiki](https://github.com/shikijs/shiki) highlighter
1199
+ * - `shiki` - use the [Shiki](https://shiki.style) highlighter
1181
1200
  * - `prism` - use the [Prism](https://prismjs.com/) highlighter
1182
1201
  * - `false` - do not apply syntax highlighting.
1183
1202
  *
@@ -1478,25 +1497,30 @@ export interface AstroUserConfig {
1478
1497
  experimental?: {
1479
1498
  /**
1480
1499
  * @docs
1481
- * @name experimental.optimizeHoistedScript
1500
+ * @name experimental.directRenderScript
1482
1501
  * @type {boolean}
1483
1502
  * @default `false`
1484
- * @version 2.10.4
1503
+ * @version 4.5.0
1485
1504
  * @description
1486
- * Prevents unused components' scripts from being included in a page unexpectedly.
1487
- * The optimization is best-effort and may inversely miss including the used scripts. Make sure to double-check your built pages
1488
- * before publishing.
1489
- * Enable hoisted script analysis optimization by adding the experimental flag:
1505
+ * Enables a more reliable strategy to prevent scripts from being executed in pages where they are not used.
1506
+ *
1507
+ * Scripts will directly render as declared in Astro files (including existing features like TypeScript, importing `node_modules`,
1508
+ * and deduplicating scripts). You can also now conditionally render scripts in your Astro file.
1509
+
1510
+ * However, this means scripts are no longer hoisted to the `<head>` and multiple scripts on a page are no longer bundled together.
1511
+ * If you enable this option, you should check that all your `<script>` tags behave as expected.
1512
+ *
1513
+ * This option will be enabled by default in Astro 5.0.
1490
1514
  *
1491
1515
  * ```js
1492
1516
  * {
1493
- * experimental: {
1494
- * optimizeHoistedScript: true,
1495
- * },
1517
+ * experimental: {
1518
+ * directRenderScript: true,
1519
+ * },
1496
1520
  * }
1497
1521
  * ```
1498
1522
  */
1499
- optimizeHoistedScript?: boolean;
1523
+ directRenderScript?: boolean;
1500
1524
  /**
1501
1525
  * @docs
1502
1526
  * @name experimental.contentCollectionCache
@@ -1515,6 +1539,53 @@ export interface AstroUserConfig {
1515
1539
  * ```
1516
1540
  */
1517
1541
  contentCollectionCache?: boolean;
1542
+ /**
1543
+ * @docs
1544
+ * @name experimental.contentCollectionJsonSchema
1545
+ * @type {boolean}
1546
+ * @default `false`
1547
+ * @version 4.5.0
1548
+ * @description
1549
+ * This feature will auto-generate a JSON schema for content collections of `type: 'data'` which can be used as the `$schema` value for TypeScript-style autocompletion/hints in tools like VSCode.
1550
+ *
1551
+ * To enable this feature, add the experimental flag:
1552
+ *
1553
+ * ```diff
1554
+ * import { defineConfig } from 'astro/config';
1555
+
1556
+ * export default defineConfig({
1557
+ * experimental: {
1558
+ * + contentCollectionJsonSchema: true
1559
+ * }
1560
+ * });
1561
+ * ```
1562
+ *
1563
+ * This experimental implementation requires you to manually reference the schema in each data entry file of the collection:
1564
+ *
1565
+ * ```diff
1566
+ * // src/content/test/entry.json
1567
+ * {
1568
+ * + "$schema": "../../../.astro/collections/test.schema.json",
1569
+ * "test": "test"
1570
+ * }
1571
+ * ```
1572
+ *
1573
+ * Alternatively, you can set this in your [VSCode `json.schemas` settings](https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings):
1574
+ *
1575
+ * ```diff
1576
+ * "json.schemas": [
1577
+ * {
1578
+ * "fileMatch": [
1579
+ * "/src/content/test/**"
1580
+ * ],
1581
+ * "url": "../../../.astro/collections/test.schema.json"
1582
+ * }
1583
+ * ]
1584
+ * ```
1585
+ *
1586
+ * Note that this initial implementation uses a library with [known issues for advanced Zod schemas](https://github.com/StefanTerdell/zod-to-json-schema#known-issues), so you may wish to consult these limitations before enabling the experimental flag.
1587
+ */
1588
+ contentCollectionJsonSchema?: boolean;
1518
1589
  /**
1519
1590
  * @docs
1520
1591
  * @name experimental.clientPrerender
@@ -2411,6 +2482,7 @@ export interface SSRResult {
2411
2482
  scripts: Set<SSRElement>;
2412
2483
  links: Set<SSRElement>;
2413
2484
  componentMetadata: Map<string, SSRComponentMetadata>;
2485
+ inlinedScripts: Map<string, string>;
2414
2486
  createAstro(Astro: AstroGlobalPartial, props: Record<string, any>, slots: Record<string, any> | null): AstroGlobal;
2415
2487
  resolve: (s: string) => Promise<string>;
2416
2488
  response: AstroGlobal['response'];
@@ -2440,6 +2512,11 @@ export interface SSRMetadata {
2440
2512
  * script in the page HTML before the first Solid component.
2441
2513
  */
2442
2514
  rendererSpecificHydrationScripts: Set<string>;
2515
+ /**
2516
+ * Used by `renderScript` to track script ids that have been rendered,
2517
+ * so we only render each once.
2518
+ */
2519
+ renderedScripts: Set<string>;
2443
2520
  hasDirectives: Set<string>;
2444
2521
  hasRenderedHead: boolean;
2445
2522
  headInTree: boolean;
@@ -0,0 +1,2 @@
1
+ import type { AssetsPrefix } from '../../core/app/types.js';
2
+ export declare function getAssetsPrefix(fileExtension: string, assetsPrefix?: AssetsPrefix): string;
@@ -0,0 +1,14 @@
1
+ function getAssetsPrefix(fileExtension, assetsPrefix) {
2
+ if (!assetsPrefix)
3
+ return "";
4
+ if (typeof assetsPrefix === "string")
5
+ return assetsPrefix;
6
+ const dotLessFileExtension = fileExtension.slice(1);
7
+ if (assetsPrefix[dotLessFileExtension]) {
8
+ return assetsPrefix[dotLessFileExtension];
9
+ }
10
+ return assetsPrefix.fallback;
11
+ }
12
+ export {
13
+ getAssetsPrefix
14
+ };
@@ -1,3 +1,4 @@
1
+ import { extname } from "node:path";
1
2
  import MagicString from "magic-string";
2
3
  import { normalizePath } from "vite";
3
4
  import { extendManualChunks } from "../core/build/plugins/util.js";
@@ -11,6 +12,7 @@ import {
11
12
  import { isServerLikeOutput } from "../prerender/utils.js";
12
13
  import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
13
14
  import { emitESMImage } from "./utils/emitAsset.js";
15
+ import { getAssetsPrefix } from "./utils/getAssetsPrefix.js";
14
16
  import { isESMImportedImage } from "./utils/imageKind.js";
15
17
  import { getProxyCode } from "./utils/proxy.js";
16
18
  import { hashTransform, propsToFilename } from "./utils/transformToPath.js";
@@ -73,7 +75,10 @@ function assets({
73
75
  if (!globalThis.astroAsset.staticImages) {
74
76
  globalThis.astroAsset.staticImages = /* @__PURE__ */ new Map();
75
77
  }
76
- const finalOriginalImagePath = (isESMImportedImage(options.src) ? options.src.src : options.src).replace(settings.config.build.assetsPrefix || "", "");
78
+ const ESMImportedImageSrc = isESMImportedImage(options.src) ? options.src.src : options.src;
79
+ const fileExtension = extname(ESMImportedImageSrc);
80
+ const pf = getAssetsPrefix(fileExtension, settings.config.build.assetsPrefix);
81
+ const finalOriginalImagePath = ESMImportedImageSrc.replace(pf, "");
77
82
  const hash = hashTransform(
78
83
  options,
79
84
  settings.config.image.service.entrypoint,
@@ -101,7 +106,7 @@ function assets({
101
106
  });
102
107
  }
103
108
  if (settings.config.build.assetsPrefix) {
104
- return encodeURI(joinPaths(settings.config.build.assetsPrefix, finalFilePath));
109
+ return encodeURI(joinPaths(pf, finalFilePath));
105
110
  } else {
106
111
  return encodeURI(prependForwardSlash(joinPaths(settings.config.base, finalFilePath)));
107
112
  }
@@ -116,7 +121,9 @@ function assets({
116
121
  s = s || (s = new MagicString(code));
117
122
  const [full, hash, postfix = ""] = match;
118
123
  const file = this.getFileName(hash);
119
- const prefix = settings.config.build.assetsPrefix ? appendForwardSlash(settings.config.build.assetsPrefix) : resolvedConfig.base;
124
+ const fileExtension = extname(file);
125
+ const pf = getAssetsPrefix(fileExtension, settings.config.build.assetsPrefix);
126
+ const prefix = pf ? appendForwardSlash(pf) : resolvedConfig.base;
120
127
  const outputFilepath = prefix + normalizePath(file + postfix);
121
128
  s.overwrite(match.index, match.index + full.length, outputFilepath);
122
129
  }
@@ -34,10 +34,11 @@ const ALIASES = /* @__PURE__ */ new Map([
34
34
  ["solid", "solid-js"],
35
35
  ["tailwindcss", "tailwind"]
36
36
  ]);
37
- const ASTRO_CONFIG_STUB = `import { defineConfig } from 'astro/config';
38
-
39
- export default defineConfig({});`;
40
- const TAILWIND_CONFIG_STUB = `/** @type {import('tailwindcss').Config} */
37
+ const STUBS = {
38
+ ASTRO_CONFIG: `import { defineConfig } from 'astro/config';
39
+ // https://astro.build/config
40
+ export default defineConfig({});`,
41
+ TAILWIND_CONFIG: `/** @type {import('tailwindcss').Config} */
41
42
  export default {
42
43
  content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'],
43
44
  theme: {
@@ -45,16 +46,31 @@ export default {
45
46
  },
46
47
  plugins: [],
47
48
  }
48
- `;
49
- const SVELTE_CONFIG_STUB = `import { vitePreprocess } from '@astrojs/svelte';
49
+ `,
50
+ SVELTE_CONFIG: `import { vitePreprocess } from '@astrojs/svelte';
50
51
 
51
52
  export default {
52
53
  preprocess: vitePreprocess(),
53
- };
54
- `;
55
- const LIT_NPMRC_STUB = `# Lit libraries are required to be hoisted due to dependency issues.
54
+ }
55
+ `,
56
+ LIT_NPMRC: `# Lit libraries are required to be hoisted due to dependency issues.
56
57
  public-hoist-pattern[]=*lit*
57
- `;
58
+ `,
59
+ DB_CONFIG: `import { defineDb } from 'astro:db';
60
+
61
+ // https://astro.build/db/config
62
+ export default defineDb({
63
+ tables: {}
64
+ });
65
+ `,
66
+ DB_SEED: `import { db } from 'astro:db';
67
+
68
+ // https://astro.build/db/seed
69
+ export default async function seed() {
70
+ // TODO
71
+ }
72
+ `
73
+ };
58
74
  const OFFICIAL_ADAPTER_TO_IMPORT_MAP = {
59
75
  netlify: "@astrojs/netlify",
60
76
  vercel: "@astrojs/vercel/serverless",
@@ -147,7 +163,7 @@ async function add(names, { flags }) {
147
163
  "./tailwind.config.js"
148
164
  ],
149
165
  defaultConfigFile: "./tailwind.config.mjs",
150
- defaultConfigContent: TAILWIND_CONFIG_STUB
166
+ defaultConfigContent: STUBS.TAILWIND_CONFIG
151
167
  });
152
168
  }
153
169
  if (integrations.find((integration) => integration.id === "svelte")) {
@@ -158,9 +174,38 @@ async function add(names, { flags }) {
158
174
  integrationName: "Svelte",
159
175
  possibleConfigFiles: ["./svelte.config.js", "./svelte.config.cjs", "./svelte.config.mjs"],
160
176
  defaultConfigFile: "./svelte.config.js",
161
- defaultConfigContent: SVELTE_CONFIG_STUB
177
+ defaultConfigContent: STUBS.SVELTE_CONFIG
162
178
  });
163
179
  }
180
+ if (integrations.find((integration) => integration.id === "db")) {
181
+ if (!existsSync(new URL("./db/", root))) {
182
+ logger.info(
183
+ "SKIP_FORMAT",
184
+ `
185
+ ${magenta(
186
+ `Astro will scaffold ${green("./db/config.ts")}${magenta(" and ")}${green(
187
+ "./db/seed.ts"
188
+ )}${magenta(" files.")}`
189
+ )}
190
+ `
191
+ );
192
+ if (await askToContinue({ flags })) {
193
+ await fs.mkdir(new URL("./db", root));
194
+ await Promise.all([
195
+ fs.writeFile(new URL("./db/config.ts", root), STUBS.DB_CONFIG, { encoding: "utf-8" }),
196
+ fs.writeFile(new URL("./db/seed.ts", root), STUBS.DB_SEED, { encoding: "utf-8" })
197
+ ]);
198
+ } else {
199
+ logger.info(
200
+ "SKIP_FORMAT",
201
+ `
202
+ Astro DB requires additional configuration. Please refer to https://astro.build/db/config`
203
+ );
204
+ }
205
+ } else {
206
+ logger.debug("add", `Using existing db configuration`);
207
+ }
208
+ }
164
209
  if (integrations.find((integration) => integration.id === "lit") && (await preferredPM(fileURLToPath(root)))?.name === "pnpm") {
165
210
  await setupIntegrationConfig({
166
211
  root,
@@ -169,14 +214,14 @@ async function add(names, { flags }) {
169
214
  integrationName: "Lit",
170
215
  possibleConfigFiles: ["./.npmrc"],
171
216
  defaultConfigFile: "./.npmrc",
172
- defaultConfigContent: LIT_NPMRC_STUB
217
+ defaultConfigContent: STUBS.LIT_NPMRC
173
218
  });
174
219
  }
175
220
  break;
176
221
  }
177
222
  case 2 /* cancelled */: {
178
223
  logger.info(
179
- null,
224
+ "SKIP_FORMAT",
180
225
  msg.cancelled(
181
226
  `Dependencies ${bold("NOT")} installed.`,
182
227
  `Be sure to install them manually before continuing!`
@@ -201,7 +246,7 @@ async function add(names, { flags }) {
201
246
  } else {
202
247
  logger.info("add", `Unable to locate a config file, generating one for you.`);
203
248
  configURL = new URL("./astro.config.mjs", root);
204
- await fs.writeFile(fileURLToPath(configURL), ASTRO_CONFIG_STUB, { encoding: "utf-8" });
249
+ await fs.writeFile(fileURLToPath(configURL), STUBS.ASTRO_CONFIG, { encoding: "utf-8" });
205
250
  }
206
251
  let ast = null;
207
252
  try {
@@ -224,7 +269,7 @@ async function add(names, { flags }) {
224
269
  await setAdapter(ast, integration, officialExportName);
225
270
  } else {
226
271
  logger.info(
227
- null,
272
+ "SKIP_FORMAT",
228
273
  `
229
274
  ${magenta(
230
275
  `Check our deployment docs for ${bold(
@@ -259,7 +304,10 @@ async function add(names, { flags }) {
259
304
  }
260
305
  switch (configResult) {
261
306
  case 2 /* cancelled */: {
262
- logger.info(null, msg.cancelled(`Your configuration has ${bold("NOT")} been updated.`));
307
+ logger.info(
308
+ "SKIP_FORMAT",
309
+ msg.cancelled(`Your configuration has ${bold("NOT")} been updated.`)
310
+ );
263
311
  break;
264
312
  }
265
313
  case 0 /* none */: {
@@ -271,17 +319,17 @@ async function add(names, { flags }) {
271
319
  (integration) => !deps.includes(integration.packageName)
272
320
  );
273
321
  if (missingDeps.length === 0) {
274
- logger.info(null, msg.success(`Configuration up-to-date.`));
322
+ logger.info("SKIP_FORMAT", msg.success(`Configuration up-to-date.`));
275
323
  break;
276
324
  }
277
325
  }
278
- logger.info(null, msg.success(`Configuration up-to-date.`));
326
+ logger.info("SKIP_FORMAT", msg.success(`Configuration up-to-date.`));
279
327
  break;
280
328
  }
281
329
  default: {
282
330
  const list = integrations.map((integration) => ` - ${integration.packageName}`).join("\n");
283
331
  logger.info(
284
- null,
332
+ "SKIP_FORMAT",
285
333
  msg.success(
286
334
  `Added the following integration${integrations.length === 1 ? "" : "s"} to your project:
287
335
  ${list}`
@@ -296,7 +344,7 @@ ${list}`
296
344
  }
297
345
  case 2 /* cancelled */: {
298
346
  logger.info(
299
- null,
347
+ "SKIP_FORMAT",
300
348
  msg.cancelled(`Your TypeScript configuration has ${bold("NOT")} been updated.`)
301
349
  );
302
350
  break;
@@ -307,7 +355,7 @@ ${list}`
307
355
  );
308
356
  }
309
357
  default:
310
- logger.info(null, msg.success(`Successfully updated TypeScript settings`));
358
+ logger.info("SKIP_FORMAT", msg.success(`Successfully updated TypeScript settings`));
311
359
  }
312
360
  }
313
361
  function isAdapter(integration) {
@@ -488,14 +536,14 @@ ${boxen(diff, {
488
536
  })}
489
537
  `;
490
538
  logger.info(
491
- null,
539
+ "SKIP_FORMAT",
492
540
  `
493
541
  ${magenta("Astro will make the following changes to your config file:")}
494
542
  ${message}`
495
543
  );
496
544
  if (logAdapterInstructions) {
497
545
  logger.info(
498
- null,
546
+ "SKIP_FORMAT",
499
547
  magenta(
500
548
  ` For complete deployment options, visit
501
549
  ${bold(
@@ -597,7 +645,7 @@ ${boxen(coloredOutput, {
597
645
  })}
598
646
  `;
599
647
  logger.info(
600
- null,
648
+ "SKIP_FORMAT",
601
649
  `
602
650
  ${magenta("Astro will run the following command:")}
603
651
  ${dim(
@@ -801,7 +849,7 @@ ${boxen(diff, {
801
849
  })}
802
850
  `;
803
851
  logger.info(
804
- null,
852
+ "SKIP_FORMAT",
805
853
  `
806
854
  ${magenta(`Astro will make the following changes to your ${configFileName}:`)}
807
855
  ${message}`
@@ -810,7 +858,7 @@ ${message}`
810
858
  const hasConflictingIntegrations = integrations.filter((integration) => presets.has(integration)).length > 1 && integrations.filter((integration) => conflictingIntegrations.includes(integration)).length > 0;
811
859
  if (hasConflictingIntegrations) {
812
860
  logger.info(
813
- null,
861
+ "SKIP_FORMAT",
814
862
  red(
815
863
  ` ${bold(
816
864
  "Caution:"
@@ -895,7 +943,7 @@ async function setupIntegrationConfig(opts) {
895
943
  }
896
944
  if (!alreadyConfigured) {
897
945
  logger.info(
898
- null,
946
+ "SKIP_FORMAT",
899
947
  `
900
948
  ${magenta(`Astro will generate a minimal ${bold(opts.defaultConfigFile)} file.`)}
901
949
  `
@@ -25,7 +25,7 @@ async function getPackage(packageName, logger, options, otherDeps = []) {
25
25
  return packageImport;
26
26
  } catch (e) {
27
27
  logger.info(
28
- null,
28
+ "SKIP_FORMAT",
29
29
  `To continue, Astro requires the following dependency to be installed: ${bold(packageName)}.`
30
30
  );
31
31
  const result = await installPackage([packageName, ...otherDeps], options, logger);
@@ -87,7 +87,7 @@ ${boxen(coloredOutput, {
87
87
  })}
88
88
  `;
89
89
  logger.info(
90
- null,
90
+ "SKIP_FORMAT",
91
91
  `
92
92
  ${magenta("Astro will run the following command:")}
93
93
  ${dim(