astro 2.9.7 → 3.0.0-beta.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 (161) hide show
  1. package/astro.js +2 -2
  2. package/components/ViewTransitions.astro +65 -12
  3. package/dist/@types/astro.d.ts +68 -7
  4. package/dist/@types/astro.js +1 -0
  5. package/dist/assets/generate.js +7 -3
  6. package/dist/assets/image-endpoint.d.ts +1 -1
  7. package/dist/assets/image-endpoint.js +3 -3
  8. package/dist/assets/internal.js +1 -2
  9. package/dist/assets/services/noop.d.ts +3 -0
  10. package/dist/assets/services/noop.js +17 -0
  11. package/dist/assets/services/vendor/squoosh/image_data.js +3 -0
  12. package/dist/assets/services/vendor/squoosh/impl.js +2 -3
  13. package/dist/assets/services/vendor/squoosh/utils/workerPool.js +4 -0
  14. package/dist/assets/vendor/image-size/types/tiff.js +1 -1
  15. package/dist/assets/vendor/queue/queue.d.ts +3 -3
  16. package/dist/assets/vite-plugin-assets.d.ts +1 -1
  17. package/dist/assets/vite-plugin-assets.js +1 -23
  18. package/dist/cli/add/index.js +6 -9
  19. package/dist/cli/build/index.js +1 -1
  20. package/dist/cli/check/index.d.ts +2 -78
  21. package/dist/cli/check/index.js +23 -275
  22. package/dist/cli/dev/index.js +1 -1
  23. package/dist/cli/index.js +7 -13
  24. package/dist/cli/info/index.js +3 -4
  25. package/dist/cli/install-package.d.ts +7 -0
  26. package/dist/cli/install-package.js +102 -0
  27. package/dist/cli/preview/index.js +1 -1
  28. package/dist/cli/sync/index.js +1 -1
  29. package/dist/content/runtime-assets.js +1 -2
  30. package/dist/content/runtime.js +3 -5
  31. package/dist/content/server-listeners.js +1 -2
  32. package/dist/content/types-generator.js +8 -8
  33. package/dist/content/utils.js +3 -4
  34. package/dist/content/vite-plugin-content-assets.js +4 -6
  35. package/dist/content/vite-plugin-content-imports.js +1 -1
  36. package/dist/content/vite-plugin-content-virtual-mod.js +5 -6
  37. package/dist/core/app/index.js +5 -3
  38. package/dist/core/app/node.d.ts +1 -1
  39. package/dist/core/app/node.js +7 -2
  40. package/dist/core/build/css-asset-name.js +2 -4
  41. package/dist/core/build/generate.js +10 -17
  42. package/dist/core/build/graph.js +3 -4
  43. package/dist/core/build/index.js +8 -1
  44. package/dist/core/build/internal.js +2 -2
  45. package/dist/core/build/plugin.js +2 -4
  46. package/dist/core/build/plugins/plugin-analyzer.js +6 -9
  47. package/dist/core/build/plugins/plugin-component-entry.js +2 -4
  48. package/dist/core/build/plugins/plugin-css.js +6 -9
  49. package/dist/core/build/plugins/plugin-hoisted-scripts.js +2 -3
  50. package/dist/core/build/plugins/plugin-internals.js +1 -2
  51. package/dist/core/build/plugins/plugin-pages.js +5 -1
  52. package/dist/core/build/plugins/plugin-ssr.js +12 -8
  53. package/dist/core/build/static-build.js +8 -12
  54. package/dist/core/client-directive/build.js +1 -2
  55. package/dist/core/compile/compile.js +2 -1
  56. package/dist/core/compile/style.js +2 -3
  57. package/dist/core/config/schema.d.ts +8 -0
  58. package/dist/core/config/schema.js +11 -3
  59. package/dist/core/config/settings.js +3 -3
  60. package/dist/core/config/timer.js +5 -6
  61. package/dist/core/constants.js +1 -1
  62. package/dist/core/cookies/cookies.d.ts +5 -5
  63. package/dist/core/cookies/cookies.js +9 -9
  64. package/dist/core/create-vite.js +6 -28
  65. package/dist/core/dev/container.d.ts +0 -1
  66. package/dist/core/dev/container.js +0 -5
  67. package/dist/core/dev/dev.js +2 -3
  68. package/dist/core/dev/index.d.ts +1 -1
  69. package/dist/core/dev/index.js +1 -2
  70. package/dist/core/dev/restart.d.ts +1 -4
  71. package/dist/core/dev/restart.js +15 -19
  72. package/dist/core/endpoint/dev/index.js +1 -1
  73. package/dist/core/endpoint/index.js +3 -4
  74. package/dist/core/errors/dev/utils.js +12 -16
  75. package/dist/core/errors/dev/vite.js +11 -13
  76. package/dist/core/errors/errors-data.d.ts +21 -0
  77. package/dist/core/errors/errors-data.js +21 -0
  78. package/dist/core/errors/errors.js +12 -17
  79. package/dist/core/errors/overlay.js +7 -8
  80. package/dist/core/errors/utils.js +1 -1
  81. package/dist/core/fs/index.js +1 -1
  82. package/dist/core/logger/console.js +1 -1
  83. package/dist/core/logger/core.d.ts +26 -6
  84. package/dist/core/logger/core.js +54 -8
  85. package/dist/core/logger/node.d.ts +4 -4
  86. package/dist/core/logger/node.js +6 -6
  87. package/dist/core/messages.js +4 -5
  88. package/dist/core/module-loader/vite.js +2 -2
  89. package/dist/core/polyfill.js +12 -4
  90. package/dist/core/redirects/helpers.js +3 -3
  91. package/dist/core/render/core.js +1 -4
  92. package/dist/core/render/params-and-props.js +2 -3
  93. package/dist/core/render/result.js +1 -2
  94. package/dist/core/render/route-cache.d.ts +1 -2
  95. package/dist/core/render/route-cache.js +6 -11
  96. package/dist/core/routing/manifest/create.js +2 -6
  97. package/dist/core/routing/params.js +1 -1
  98. package/dist/core/routing/validation.js +7 -8
  99. package/dist/core/sync/index.js +1 -1
  100. package/dist/core/util.js +1 -1
  101. package/dist/events/error.js +1 -1
  102. package/dist/events/session.js +12 -13
  103. package/dist/integrations/astroFeaturesValidation.d.ts +14 -0
  104. package/dist/integrations/astroFeaturesValidation.js +109 -0
  105. package/dist/integrations/index.d.ts +3 -1
  106. package/dist/integrations/index.js +96 -31
  107. package/dist/jsx/babel.js +1 -2
  108. package/dist/prerender/metadata.js +1 -2
  109. package/dist/runtime/client/hmr.js +1 -2
  110. package/dist/runtime/server/astro-component.js +1 -2
  111. package/dist/runtime/server/astro-island.js +53 -55
  112. package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
  113. package/dist/runtime/server/astro-island.prebuilt.js +1 -1
  114. package/dist/runtime/server/endpoint.d.ts +2 -1
  115. package/dist/runtime/server/endpoint.js +21 -27
  116. package/dist/runtime/server/hydration.js +9 -0
  117. package/dist/runtime/server/jsx.js +3 -2
  118. package/dist/runtime/server/render/astro/instance.js +6 -3
  119. package/dist/runtime/server/render/astro/render-template.js +4 -3
  120. package/dist/runtime/server/render/astro/render.js +3 -3
  121. package/dist/runtime/server/render/common.js +1 -1
  122. package/dist/runtime/server/render/component.js +11 -13
  123. package/dist/runtime/server/render/dom.js +1 -1
  124. package/dist/runtime/server/render/page.js +2 -3
  125. package/dist/runtime/server/render/slot.js +2 -1
  126. package/dist/runtime/server/render/util.js +1 -2
  127. package/dist/runtime/server/transition.d.ts +1 -0
  128. package/dist/runtime/server/transition.js +1 -0
  129. package/dist/transitions/vite-plugin-transitions.js +1 -0
  130. package/dist/vite-plugin-astro/compile.js +2 -3
  131. package/dist/vite-plugin-astro/hmr.js +3 -5
  132. package/dist/vite-plugin-astro/index.js +1 -1
  133. package/dist/vite-plugin-astro/metadata.js +1 -2
  134. package/dist/vite-plugin-astro-postprocess/index.js +1 -1
  135. package/dist/vite-plugin-astro-server/base.js +1 -2
  136. package/dist/vite-plugin-astro-server/controller.js +2 -3
  137. package/dist/vite-plugin-astro-server/css.js +1 -1
  138. package/dist/vite-plugin-astro-server/request.js +1 -1
  139. package/dist/vite-plugin-astro-server/route.js +1 -2
  140. package/dist/vite-plugin-astro-server/scripts.js +2 -3
  141. package/dist/vite-plugin-astro-server/vite.js +1 -1
  142. package/dist/vite-plugin-config-alias/index.js +1 -1
  143. package/dist/vite-plugin-env/index.js +2 -2
  144. package/dist/vite-plugin-head/index.js +4 -6
  145. package/dist/vite-plugin-html/index.js +1 -2
  146. package/dist/vite-plugin-html/transform/index.js +1 -1
  147. package/dist/vite-plugin-html/transform/slots.js +5 -6
  148. package/dist/vite-plugin-html/transform/utils.js +1 -2
  149. package/dist/vite-plugin-jsx/import-source.js +1 -2
  150. package/dist/vite-plugin-jsx/index.js +1 -1
  151. package/dist/vite-plugin-jsx/tag.js +4 -6
  152. package/dist/vite-plugin-markdown/index.js +1 -2
  153. package/dist/vite-plugin-scanner/index.js +2 -1
  154. package/dist/vite-plugin-scanner/scan.js +1 -1
  155. package/dist/vite-plugin-scripts/index.js +1 -1
  156. package/dist/vite-plugin-scripts/page-ssr.js +2 -2
  157. package/package.json +13 -22
  158. package/tsconfigs/base.json +8 -6
  159. package/tsconfigs/strict.json +2 -3
  160. package/dist/cli/check/print.d.ts +0 -2
  161. package/dist/cli/check/print.js +0 -95
@@ -1,7 +1,7 @@
1
1
  import glob from "fast-glob";
2
2
  import { join } from "node:path";
3
3
  import { fileURLToPath, pathToFileURL } from "node:url";
4
- import { runHookBuildSsr } from "../../../integrations/index.js";
4
+ import { isFunctionPerRouteEnabled, runHookBuildSsr } from "../../../integrations/index.js";
5
5
  import { isServerLikeOutput } from "../../../prerender/utils.js";
6
6
  import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
7
7
  import { joinPaths, prependForwardSlash } from "../../path.js";
@@ -82,11 +82,13 @@ function vitePluginSSR(internals, adapter, options) {
82
82
  }
83
83
  function pluginSSR(options, internals) {
84
84
  const ssr = isServerLikeOutput(options.settings.config);
85
+ const functionPerRouteEnabled = isFunctionPerRouteEnabled(options.settings.adapter);
85
86
  return {
86
87
  build: "ssr",
87
88
  hooks: {
88
89
  "build:before": () => {
89
- let vitePlugin = ssr && !options.settings.config.build.split ? vitePluginSSR(internals, options.settings.adapter, options) : void 0;
90
+ let vitePlugin = ssr && // TODO: Remove in Astro 4.0
91
+ options.settings.config.build.split === false && functionPerRouteEnabled === false ? vitePluginSSR(internals, options.settings.adapter, options) : void 0;
90
92
  return {
91
93
  enforce: "after-user-plugins",
92
94
  vitePlugin
@@ -96,7 +98,7 @@ function pluginSSR(options, internals) {
96
98
  if (!ssr) {
97
99
  return;
98
100
  }
99
- if (options.settings.config.build.split) {
101
+ if (options.settings.config.build.split || functionPerRouteEnabled) {
100
102
  return;
101
103
  }
102
104
  if (!internals.ssrEntryChunk) {
@@ -120,11 +122,12 @@ function pluginSSR(options, internals) {
120
122
  const SPLIT_MODULE_ID = "@astro-page-split:";
121
123
  const RESOLVED_SPLIT_MODULE_ID = "\0@astro-page-split:";
122
124
  function vitePluginSSRSplit(internals, adapter, options) {
125
+ const functionPerRouteEnabled = isFunctionPerRouteEnabled(options.settings.adapter);
123
126
  return {
124
127
  name: "@astrojs/vite-plugin-astro-ssr-split",
125
128
  enforce: "post",
126
129
  options(opts) {
127
- if (options.settings.config.build.split) {
130
+ if (options.settings.config.build.split || functionPerRouteEnabled) {
128
131
  const inputs = /* @__PURE__ */ new Set();
129
132
  for (const path of Object.keys(options.allPages)) {
130
133
  inputs.add(getVirtualModulePageNameFromPath(SPLIT_MODULE_ID, path));
@@ -182,11 +185,12 @@ function vitePluginSSRSplit(internals, adapter, options) {
182
185
  }
183
186
  function pluginSSRSplit(options, internals) {
184
187
  const ssr = isServerLikeOutput(options.settings.config);
188
+ const functionPerRouteEnabled = isFunctionPerRouteEnabled(options.settings.adapter);
185
189
  return {
186
190
  build: "ssr",
187
191
  hooks: {
188
192
  "build:before": () => {
189
- let vitePlugin = ssr && options.settings.config.build.split ? vitePluginSSRSplit(internals, options.settings.adapter, options) : void 0;
193
+ let vitePlugin = ssr && (options.settings.config.build.split || functionPerRouteEnabled) ? vitePluginSSRSplit(internals, options.settings.adapter, options) : void 0;
190
194
  return {
191
195
  enforce: "after-user-plugins",
192
196
  vitePlugin
@@ -196,7 +200,7 @@ function pluginSSRSplit(options, internals) {
196
200
  if (!ssr) {
197
201
  return;
198
202
  }
199
- if (!options.settings.config.build.split) {
203
+ if (!options.settings.config.build.split && !functionPerRouteEnabled) {
200
204
  return;
201
205
  }
202
206
  if (internals.ssrSplitEntryChunks.size === 0) {
@@ -222,7 +226,7 @@ function generateSSRCode(config, adapter) {
222
226
  const imports = [];
223
227
  const contents = [];
224
228
  let pageMap;
225
- if (config.build.split) {
229
+ if (config.build.split || isFunctionPerRouteEnabled(adapter)) {
226
230
  pageMap = "pageModule";
227
231
  } else {
228
232
  pageMap = "pageMap";
@@ -264,7 +268,7 @@ function injectManifest(manifest, chunk) {
264
268
  });
265
269
  }
266
270
  async function createManifest(buildOpts, internals) {
267
- if (buildOpts.settings.config.build.split) {
271
+ if (buildOpts.settings.config.build.split || isFunctionPerRouteEnabled(buildOpts.settings.adapter)) {
268
272
  if (internals.ssrSplitEntryChunks.size === 0) {
269
273
  throw new Error(`Did not generate an entry chunk for SSR in serverless mode`);
270
274
  }
@@ -30,7 +30,6 @@ import { RESOLVED_SPLIT_MODULE_ID, SSR_VIRTUAL_MODULE_ID } from "./plugins/plugi
30
30
  import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
31
31
  import { getTimeStat } from "./util.js";
32
32
  async function viteBuild(opts) {
33
- var _a, _b, _c;
34
33
  const { allPages, settings } = opts;
35
34
  if (isModeServerWithNoAdapter(opts.settings)) {
36
35
  throw new AstroError(AstroErrorData.NoAdapterInstalled);
@@ -48,7 +47,7 @@ async function viteBuild(opts) {
48
47
  facadeIdToPageDataMap.set(fileURLToPath(astroModuleURL), pageData);
49
48
  }
50
49
  }
51
- if (((_c = (_b = (_a = settings.config) == null ? void 0 : _a.vite) == null ? void 0 : _b.build) == null ? void 0 : _c.emptyOutDir) !== false) {
50
+ if (settings.config?.vite?.build?.emptyOutDir !== false) {
52
51
  emptyDir(settings.config.outDir, new Set(".git"));
53
52
  }
54
53
  const container = createPluginContainer(opts, internals);
@@ -102,7 +101,6 @@ ${bgMagenta(black(" finalizing server assets "))}
102
101
  }
103
102
  }
104
103
  async function ssrBuild(opts, internals, input, container) {
105
- var _a, _b, _c, _d, _e;
106
104
  const { allPages, settings, viteConfig } = opts;
107
105
  const ssr = isServerLikeOutput(settings.config);
108
106
  const out = ssr ? settings.config.build.server : getOutDirWithinCwd(settings.config.outDir);
@@ -116,14 +114,14 @@ async function ssrBuild(opts, internals, input, container) {
116
114
  target: "esnext",
117
115
  // Vite defaults cssMinify to false in SSR by default, but we want to minify it
118
116
  // as the CSS generated are used and served to the client.
119
- cssMinify: ((_a = viteConfig.build) == null ? void 0 : _a.minify) == null ? true : !!((_b = viteConfig.build) == null ? void 0 : _b.minify),
117
+ cssMinify: viteConfig.build?.minify == null ? true : !!viteConfig.build?.minify,
120
118
  ...viteConfig.build,
121
119
  emptyOutDir: false,
122
120
  manifest: false,
123
121
  outDir: fileURLToPath(out),
124
122
  copyPublicDir: !ssr,
125
123
  rollupOptions: {
126
- ...(_c = viteConfig.build) == null ? void 0 : _c.rollupOptions,
124
+ ...viteConfig.build?.rollupOptions,
127
125
  input: [],
128
126
  output: {
129
127
  format: "esm",
@@ -131,16 +129,15 @@ async function ssrBuild(opts, internals, input, container) {
131
129
  // We need to keep these separate
132
130
  chunkFileNames: `chunks/[name].[hash].mjs`,
133
131
  assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
134
- ...(_e = (_d = viteConfig.build) == null ? void 0 : _d.rollupOptions) == null ? void 0 : _e.output,
132
+ ...viteConfig.build?.rollupOptions?.output,
135
133
  entryFileNames(chunkInfo) {
136
- var _a2, _b2;
137
- if ((_a2 = chunkInfo.facadeModuleId) == null ? void 0 : _a2.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
134
+ if (chunkInfo.facadeModuleId?.startsWith(ASTRO_PAGE_RESOLVED_MODULE_ID)) {
138
135
  return makeAstroPageEntryPointFileName(
139
136
  ASTRO_PAGE_RESOLVED_MODULE_ID,
140
137
  chunkInfo.facadeModuleId,
141
138
  routes
142
139
  );
143
- } else if ((_b2 = chunkInfo.facadeModuleId) == null ? void 0 : _b2.startsWith(RESOLVED_SPLIT_MODULE_ID)) {
140
+ } else if (chunkInfo.facadeModuleId?.startsWith(RESOLVED_SPLIT_MODULE_ID)) {
144
141
  return makeSplitEntryPointFileName(chunkInfo.facadeModuleId, routes);
145
142
  } else if (chunkInfo.facadeModuleId === SSR_VIRTUAL_MODULE_ID) {
146
143
  return opts.settings.config.build.serverEntry;
@@ -173,7 +170,6 @@ async function ssrBuild(opts, internals, input, container) {
173
170
  return await vite.build(updatedViteBuildConfig);
174
171
  }
175
172
  async function clientBuild(opts, internals, input, container) {
176
- var _a, _b, _c;
177
173
  const { settings, viteConfig } = opts;
178
174
  const timer = performance.now();
179
175
  const ssr = isServerLikeOutput(settings.config);
@@ -197,14 +193,14 @@ ${bgGreen(black(" building client "))}`);
197
193
  emptyOutDir: false,
198
194
  outDir: fileURLToPath(out),
199
195
  rollupOptions: {
200
- ...(_a = viteConfig.build) == null ? void 0 : _a.rollupOptions,
196
+ ...viteConfig.build?.rollupOptions,
201
197
  input: Array.from(input),
202
198
  output: {
203
199
  format: "esm",
204
200
  entryFileNames: `${settings.config.build.assets}/[name].[hash].js`,
205
201
  chunkFileNames: `${settings.config.build.assets}/[name].[hash].js`,
206
202
  assetFileNames: `${settings.config.build.assets}/[name].[hash][extname]`,
207
- ...(_c = (_b = viteConfig.build) == null ? void 0 : _b.rollupOptions) == null ? void 0 : _c.output
203
+ ...viteConfig.build?.rollupOptions?.output
208
204
  },
209
205
  preserveEntrySignatures: "exports-only"
210
206
  }
@@ -1,6 +1,5 @@
1
1
  import { build } from "esbuild";
2
2
  async function buildClientDirectiveEntrypoint(name, entrypoint) {
3
- var _a;
4
3
  const stringifiedName = JSON.stringify(name);
5
4
  const stringifiedEntrypoint = JSON.stringify(entrypoint);
6
5
  const output = await build({
@@ -18,7 +17,7 @@ window.dispatchEvent(new Event('astro:' + ${stringifiedName}));`,
18
17
  bundle: true,
19
18
  write: false
20
19
  });
21
- const outputFile = (_a = output.outputFiles) == null ? void 0 : _a[0];
20
+ const outputFile = output.outputFiles?.[0];
22
21
  if (!outputFile)
23
22
  return "";
24
23
  return outputFile.text;
@@ -1,7 +1,7 @@
1
1
  import { transform } from "@astrojs/compiler";
2
2
  import { fileURLToPath } from "node:url";
3
3
  import { normalizePath } from "vite";
4
- import { AggregateError, CompilerError } from "../errors/errors.js";
4
+ import { AggregateError, AstroError, CompilerError } from "../errors/errors.js";
5
5
  import { AstroErrorData } from "../errors/index.js";
6
6
  import { resolvePath } from "../util.js";
7
7
  import { createStylePreprocessor } from "./style.js";
@@ -25,6 +25,7 @@ async function compile({
25
25
  scopedStyleStrategy: astroConfig.scopedStyleStrategy,
26
26
  resultScopedSlot: true,
27
27
  experimentalTransitions: astroConfig.experimental.viewTransitions,
28
+ experimentalPersistence: astroConfig.experimental.viewTransitions,
28
29
  transitionsAnimationURL: "astro/components/viewtransitions.css",
29
30
  preprocessStyle: createStylePreprocessor({
30
31
  filename,
@@ -8,12 +8,11 @@ function createStylePreprocessor({
8
8
  cssTransformErrors
9
9
  }) {
10
10
  return async (content, attrs) => {
11
- var _a;
12
- const lang = `.${(attrs == null ? void 0 : attrs.lang) || "css"}`.toLowerCase();
11
+ const lang = `.${attrs?.lang || "css"}`.toLowerCase();
13
12
  const id = `${filename}?astro&type=style&lang${lang}`;
14
13
  try {
15
14
  const result = await preprocessCSS(content, id, viteConfig);
16
- (_a = result.deps) == null ? void 0 : _a.forEach((dep) => {
15
+ result.deps?.forEach((dep) => {
17
16
  cssDeps.add(dep);
18
17
  });
19
18
  let map;
@@ -49,7 +49,15 @@ export declare const AstroConfigSchema: z.ZodObject<{
49
49
  serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
50
50
  redirects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
51
51
  inlineStylesheets: z.ZodDefault<z.ZodOptional<z.ZodEnum<["always", "auto", "never"]>>>;
52
+ /**
53
+ * @deprecated
54
+ * Use the adapter feature instead
55
+ */
52
56
  split: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
57
+ /**
58
+ * @deprecated
59
+ * Use the adapter feature instead
60
+ */
53
61
  excludeMiddleware: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
54
62
  }, "strip", z.ZodTypeAny, {
55
63
  assetsPrefix?: string | undefined;
@@ -23,10 +23,10 @@ const ASTRO_CONFIG_DEFAULTS = {
23
23
  split: false,
24
24
  excludeMiddleware: false
25
25
  },
26
- compressHTML: false,
26
+ compressHTML: true,
27
27
  server: {
28
28
  host: false,
29
- port: 3e3,
29
+ port: 4321,
30
30
  open: false
31
31
  },
32
32
  integrations: [],
@@ -70,7 +70,15 @@ const AstroConfigSchema = z.object({
70
70
  serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
71
71
  redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
72
72
  inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
73
+ /**
74
+ * @deprecated
75
+ * Use the adapter feature instead
76
+ */
73
77
  split: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.split),
78
+ /**
79
+ * @deprecated
80
+ * Use the adapter feature instead
81
+ */
74
82
  excludeMiddleware: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.excludeMiddleware)
75
83
  }).optional().default({}),
76
84
  server: z.preprocess(
@@ -114,7 +122,7 @@ const AstroConfigSchema = z.object({
114
122
  config: z.record(z.any()).default({})
115
123
  })
116
124
  }).default({
117
- service: { entrypoint: "astro/assets/services/squoosh", config: {} }
125
+ service: { entrypoint: "astro/assets/services/sharp", config: {} }
118
126
  }),
119
127
  markdown: z.object({
120
128
  drafts: z.boolean().default(false),
@@ -93,12 +93,12 @@ function createBaseSettings(config) {
93
93
  function createSettings(config, cwd) {
94
94
  const tsconfig = loadTSConfig(cwd);
95
95
  const settings = createBaseSettings(config);
96
- const watchFiles = (tsconfig == null ? void 0 : tsconfig.exists) ? [tsconfig.path, ...tsconfig.extendedPaths] : [];
96
+ const watchFiles = tsconfig?.exists ? [tsconfig.path, ...tsconfig.extendedPaths] : [];
97
97
  if (cwd) {
98
98
  watchFiles.push(fileURLToPath(new URL("./package.json", pathToFileURL(cwd))));
99
99
  }
100
- settings.tsConfig = tsconfig == null ? void 0 : tsconfig.config;
101
- settings.tsConfigPath = tsconfig == null ? void 0 : tsconfig.path;
100
+ settings.tsConfig = tsconfig?.config;
101
+ settings.tsConfigPath = tsconfig?.path;
102
102
  settings.watchFiles = watchFiles;
103
103
  return settings;
104
104
  }
@@ -1,18 +1,18 @@
1
1
  import fs from "node:fs";
2
2
  class AstroTimer {
3
+ enabled;
4
+ ongoingTimers = /* @__PURE__ */ new Map();
5
+ stats = {};
3
6
  constructor() {
4
- this.ongoingTimers = /* @__PURE__ */ new Map();
5
- this.stats = {};
6
7
  this.enabled = !!process.env.ASTRO_TIMER_PATH;
7
8
  }
8
9
  /**
9
10
  * Start a timer for a scope with a given name.
10
11
  */
11
12
  start(name) {
12
- var _a;
13
13
  if (!this.enabled)
14
14
  return;
15
- (_a = globalThis.gc) == null ? void 0 : _a.call(globalThis);
15
+ globalThis.gc?.();
16
16
  this.ongoingTimers.set(name, {
17
17
  startTime: performance.now(),
18
18
  startHeap: process.memoryUsage().heapUsed
@@ -22,13 +22,12 @@ class AstroTimer {
22
22
  * End a timer for a scope with a given name.
23
23
  */
24
24
  end(name) {
25
- var _a;
26
25
  if (!this.enabled)
27
26
  return;
28
27
  const stat = this.ongoingTimers.get(name);
29
28
  if (!stat)
30
29
  return;
31
- (_a = globalThis.gc) == null ? void 0 : _a.call(globalThis);
30
+ globalThis.gc?.();
32
31
  const endHeap = process.memoryUsage().heapUsed;
33
32
  this.stats[name] = {
34
33
  elapsedTime: performance.now() - stat.startTime,
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.9.7";
1
+ const ASTRO_VERSION = "3.0.0-beta.0";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -9,20 +9,20 @@ interface AstroCookieSetOptions {
9
9
  }
10
10
  type AstroCookieDeleteOptions = Pick<AstroCookieSetOptions, 'domain' | 'path'>;
11
11
  interface AstroCookieInterface {
12
- value: string | undefined;
12
+ value: string;
13
13
  json(): Record<string, any>;
14
14
  number(): number;
15
15
  boolean(): boolean;
16
16
  }
17
17
  interface AstroCookiesInterface {
18
- get(key: string): AstroCookieInterface;
18
+ get(key: string): AstroCookieInterface | undefined;
19
19
  has(key: string): boolean;
20
20
  set(key: string, value: string | number | boolean | Record<string, any>, options?: AstroCookieSetOptions): void;
21
21
  delete(key: string, options?: AstroCookieDeleteOptions): void;
22
22
  }
23
23
  declare class AstroCookie implements AstroCookieInterface {
24
- value: string | undefined;
25
- constructor(value: string | undefined);
24
+ value: string;
25
+ constructor(value: string);
26
26
  json(): any;
27
27
  number(): number;
28
28
  boolean(): boolean;
@@ -44,7 +44,7 @@ declare class AstroCookies implements AstroCookiesInterface {
44
44
  * @param key The cookie to get.
45
45
  * @returns An object containing the cookie value as well as convenience methods for converting its value.
46
46
  */
47
- get(key: string): AstroCookie;
47
+ get(key: string): AstroCookie | undefined;
48
48
  /**
49
49
  * Astro.cookies.has(key) returns a boolean indicating whether this cookie is either
50
50
  * part of the initial request or set via Astro.cookies.set(key)
@@ -43,10 +43,10 @@ class AstroCookies {
43
43
  const serializeOptions = {
44
44
  expires: DELETED_EXPIRATION
45
45
  };
46
- if (options == null ? void 0 : options.domain) {
46
+ if (options?.domain) {
47
47
  serializeOptions.domain = options.domain;
48
48
  }
49
- if (options == null ? void 0 : options.path) {
49
+ if (options?.path) {
50
50
  serializeOptions.path = options.path;
51
51
  }
52
52
  this.#ensureOutgoingMap().set(key, [
@@ -63,18 +63,19 @@ class AstroCookies {
63
63
  * @returns An object containing the cookie value as well as convenience methods for converting its value.
64
64
  */
65
65
  get(key) {
66
- var _a;
67
- if ((_a = this.#outgoing) == null ? void 0 : _a.has(key)) {
66
+ if (this.#outgoing?.has(key)) {
68
67
  let [serializedValue, , isSetValue] = this.#outgoing.get(key);
69
68
  if (isSetValue) {
70
69
  return new AstroCookie(serializedValue);
71
70
  } else {
72
- return new AstroCookie(void 0);
71
+ return void 0;
73
72
  }
74
73
  }
75
74
  const values = this.#ensureParsed();
76
- const value = values[key];
77
- return new AstroCookie(value);
75
+ if (key in values) {
76
+ const value = values[key];
77
+ return new AstroCookie(value);
78
+ }
78
79
  }
79
80
  /**
80
81
  * Astro.cookies.has(key) returns a boolean indicating whether this cookie is either
@@ -83,8 +84,7 @@ class AstroCookies {
83
84
  * @returns
84
85
  */
85
86
  has(key) {
86
- var _a;
87
- if ((_a = this.#outgoing) == null ? void 0 : _a.has(key)) {
87
+ if (this.#outgoing?.has(key)) {
88
88
  let [, , isSetValue] = this.#outgoing.get(key);
89
89
  return isSetValue;
90
90
  }
@@ -46,20 +46,18 @@ const ONLY_DEV_EXTERNAL = [
46
46
  "string-width"
47
47
  ];
48
48
  async function createVite(commandConfig, { settings, logging, mode, command, fs = nodeFs }) {
49
- var _a, _b;
50
49
  const astroPkgsConfig = await crawlFrameworkPkgs({
51
50
  root: fileURLToPath(settings.config.root),
52
51
  isBuild: mode === "build",
53
52
  viteUserConfig: settings.config.vite,
54
53
  isFrameworkPkgByJson(pkgJson) {
55
- var _a2, _b2, _c, _d, _e;
56
- if (((_a2 = pkgJson == null ? void 0 : pkgJson.astro) == null ? void 0 : _a2.external) === true) {
54
+ if (pkgJson?.astro?.external === true) {
57
55
  return false;
58
56
  }
59
57
  return (
60
58
  // Attempt: package relies on `astro`. ✅ Definitely an Astro package
61
- ((_b2 = pkgJson.peerDependencies) == null ? void 0 : _b2.astro) || ((_c = pkgJson.dependencies) == null ? void 0 : _c.astro) || // Attempt: package is tagged with `astro` or `astro-component`. ✅ Likely a community package
62
- ((_d = pkgJson.keywords) == null ? void 0 : _d.includes("astro")) || ((_e = pkgJson.keywords) == null ? void 0 : _e.includes("astro-component")) || // Attempt: package is named `astro-something` or `@scope/astro-something`. ✅ Likely a community package
59
+ pkgJson.peerDependencies?.astro || pkgJson.dependencies?.astro || // Attempt: package is tagged with `astro` or `astro-component`. ✅ Likely a community package
60
+ pkgJson.keywords?.includes("astro") || pkgJson.keywords?.includes("astro-component") || // Attempt: package is named `astro-something` or `@scope/astro-something`. ✅ Likely a community package
63
61
  /^(@[^\/]+\/)?astro\-/.test(pkgJson.name)
64
62
  );
65
63
  },
@@ -111,7 +109,7 @@ async function createVite(commandConfig, { settings, logging, mode, command, fs
111
109
  ],
112
110
  publicDir: fileURLToPath(settings.config.publicDir),
113
111
  root: fileURLToPath(settings.config.root),
114
- envPrefix: ((_a = settings.config.vite) == null ? void 0 : _a.envPrefix) ?? "PUBLIC_",
112
+ envPrefix: settings.config.vite?.envPrefix ?? "PUBLIC_",
115
113
  define: {
116
114
  "import.meta.env.SITE": settings.config.site ? JSON.stringify(settings.config.site) : "undefined"
117
115
  },
@@ -161,7 +159,7 @@ async function createVite(commandConfig, { settings, logging, mode, command, fs
161
159
  };
162
160
  }
163
161
  let result = commonConfig;
164
- if (command && ((_b = settings.config.vite) == null ? void 0 : _b.plugins)) {
162
+ if (command && settings.config.vite?.plugins) {
165
163
  let { plugins, ...rest } = settings.config.vite;
166
164
  const applyToFilter = command === "build" ? "serve" : "build";
167
165
  const applyArgs = [
@@ -169,7 +167,7 @@ async function createVite(commandConfig, { settings, logging, mode, command, fs
169
167
  { command: command === "dev" ? "serve" : command, mode }
170
168
  ];
171
169
  plugins = plugins.flat(Infinity).filter((p) => {
172
- if (!p || (p == null ? void 0 : p.apply) === applyToFilter) {
170
+ if (!p || p?.apply === applyToFilter) {
173
171
  return false;
174
172
  }
175
173
  if (typeof p.apply === "function") {
@@ -182,29 +180,9 @@ async function createVite(commandConfig, { settings, logging, mode, command, fs
182
180
  result = vite.mergeConfig(result, settings.config.vite || {});
183
181
  }
184
182
  result = vite.mergeConfig(result, commandConfig);
185
- if (result.plugins) {
186
- sortPlugins(result.plugins);
187
- }
188
183
  result.customLogger = vite.createLogger(result.logLevel ?? "warn");
189
184
  return result;
190
185
  }
191
- function isVitePlugin(plugin) {
192
- return Boolean(plugin == null ? void 0 : plugin.hasOwnProperty("name"));
193
- }
194
- function findPluginIndexByName(pluginOptions, name) {
195
- return pluginOptions.findIndex(function(pluginOption) {
196
- return isVitePlugin(pluginOption) && pluginOption.name === name;
197
- });
198
- }
199
- function sortPlugins(pluginOptions) {
200
- const mdxPluginIndex = findPluginIndexByName(pluginOptions, "@mdx-js/rollup");
201
- if (mdxPluginIndex === -1)
202
- return;
203
- const jsxPluginIndex = findPluginIndexByName(pluginOptions, "astro:jsx");
204
- const mdxPlugin = pluginOptions[mdxPluginIndex];
205
- pluginOptions.splice(mdxPluginIndex, 1);
206
- pluginOptions.splice(jsxPluginIndex, 0, mdxPlugin);
207
- }
208
186
  const COMMON_DEPENDENCIES_NOT_ASTRO = [
209
187
  "autoprefixer",
210
188
  "react",
@@ -26,4 +26,3 @@ export interface CreateContainerParams {
26
26
  }
27
27
  export declare function createContainer({ isRestart, logging, inlineConfig, settings, fs, }: CreateContainerParams): Promise<Container>;
28
28
  export declare function startContainer({ settings, viteServer, logging, }: Container): Promise<AddressInfo>;
29
- export declare function isStarted(container: Container): boolean;
@@ -79,12 +79,7 @@ async function startContainer({
79
79
  });
80
80
  return devServerAddressInfo;
81
81
  }
82
- function isStarted(container) {
83
- var _a;
84
- return !!((_a = container.viteServer.httpServer) == null ? void 0 : _a.listening);
85
- }
86
82
  export {
87
83
  createContainer,
88
- isStarted,
89
84
  startContainer
90
85
  };
@@ -7,7 +7,6 @@ import * as msg from "../messages.js";
7
7
  import { startContainer } from "./container.js";
8
8
  import { createContainerWithAutomaticRestart } from "./restart.js";
9
9
  async function dev(inlineConfig) {
10
- var _a, _b;
11
10
  const devStart = performance.now();
12
11
  await telemetry.record([]);
13
12
  const restart = await createContainerWithAutomaticRestart({ inlineConfig, fs });
@@ -23,11 +22,11 @@ async function dev(inlineConfig) {
23
22
  base: restart.container.settings.config.base
24
23
  })
25
24
  );
26
- const currentVersion = "2.9.7";
25
+ const currentVersion = "3.0.0-beta.0";
27
26
  if (currentVersion.includes("-")) {
28
27
  warn(logging, null, msg.prerelease({ currentVersion }));
29
28
  }
30
- if (((_b = (_a = restart.container.viteServer.config.server) == null ? void 0 : _a.fs) == null ? void 0 : _b.strict) === false) {
29
+ if (restart.container.viteServer.config.server?.fs?.strict === false) {
31
30
  warn(logging, null, msg.fsStrictWarning());
32
31
  }
33
32
  await attachContentServerListeners(restart.container);
@@ -1,3 +1,3 @@
1
- export { createContainer, isStarted, startContainer } from './container.js';
1
+ export { createContainer, startContainer } from './container.js';
2
2
  export { default } from './dev.js';
3
3
  export { createContainerWithAutomaticRestart } from './restart.js';
@@ -1,10 +1,9 @@
1
- import { createContainer, isStarted, startContainer } from "./container.js";
1
+ import { createContainer, startContainer } from "./container.js";
2
2
  import { default as default2 } from "./dev.js";
3
3
  import { createContainerWithAutomaticRestart } from "./restart.js";
4
4
  export {
5
5
  createContainer,
6
6
  createContainerWithAutomaticRestart,
7
7
  default2 as default,
8
- isStarted,
9
8
  startContainer
10
9
  };
@@ -3,10 +3,7 @@ import nodeFs from 'node:fs';
3
3
  import type { AstroInlineConfig } from '../../@types/astro';
4
4
  import type { Container } from './container';
5
5
  export declare function shouldRestartContainer({ settings, inlineConfig, restartInFlight }: Container, changedFile: string): boolean;
6
- export declare function restartContainer(container: Container): Promise<{
7
- container: Container;
8
- error: Error | null;
9
- }>;
6
+ export declare function restartContainer(container: Container): Promise<Container | Error>;
10
7
  export interface CreateContainerWithAutomaticRestart {
11
8
  inlineConfig?: AstroInlineConfig;
12
9
  fs: typeof nodeFs;
@@ -1,3 +1,4 @@
1
+ import nodeFs from "node:fs";
1
2
  import { fileURLToPath } from "node:url";
2
3
  import * as vite from "vite";
3
4
  import { eventCliSession, telemetry } from "../../events/index.js";
@@ -7,8 +8,8 @@ import { isAstroConfigZodError } from "../errors/errors.js";
7
8
  import { createSafeError } from "../errors/index.js";
8
9
  import { info, error as logError } from "../logger/core.js";
9
10
  import { formatErrorMessage } from "../messages.js";
10
- import { createContainer, isStarted, startContainer } from "./container.js";
11
- async function createRestartedContainer(container, settings, needsStart) {
11
+ import { createContainer, startContainer } from "./container.js";
12
+ async function createRestartedContainer(container, settings) {
12
13
  const { logging, fs, inlineConfig } = container;
13
14
  const newContainer = await createContainer({
14
15
  isRestart: true,
@@ -17,9 +18,7 @@ async function createRestartedContainer(container, settings, needsStart) {
17
18
  inlineConfig,
18
19
  fs
19
20
  });
20
- if (needsStart) {
21
- await startContainer(newContainer);
22
- }
21
+ await startContainer(newContainer);
23
22
  return newContainer;
24
23
  }
25
24
  function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, changedFile) {
@@ -43,15 +42,11 @@ function shouldRestartContainer({ settings, inlineConfig, restartInFlight }, cha
43
42
  async function restartContainer(container) {
44
43
  const { logging, close, settings: existingSettings } = container;
45
44
  container.restartInFlight = true;
46
- const needsStart = isStarted(container);
47
45
  try {
48
46
  const { astroConfig } = await resolveConfig(container.inlineConfig, "dev", container.fs);
49
47
  const settings = createSettings(astroConfig, fileURLToPath(existingSettings.config.root));
50
48
  await close();
51
- return {
52
- container: await createRestartedContainer(container, settings, needsStart),
53
- error: null
54
- };
49
+ return await createRestartedContainer(container, settings);
55
50
  } catch (_err) {
56
51
  const error = createSafeError(_err);
57
52
  if (!isAstroConfigZodError(_err)) {
@@ -64,12 +59,9 @@ async function restartContainer(container) {
64
59
  stack: error.stack || ""
65
60
  }
66
61
  });
67
- await close();
62
+ container.restartInFlight = false;
68
63
  info(logging, "astro", "Continuing with previous valid configuration\n");
69
- return {
70
- container: await createRestartedContainer(container, existingSettings, needsStart),
71
- error
72
- };
64
+ return error;
73
65
  }
74
66
  }
75
67
  async function createContainerWithAutomaticRestart({
@@ -94,10 +86,14 @@ async function createContainerWithAutomaticRestart({
94
86
  async function handleServerRestart(logMsg) {
95
87
  info(logging, "astro", logMsg + "\n");
96
88
  const container = restart.container;
97
- const { container: newContainer, error } = await restartContainer(container);
98
- restart.container = newContainer;
99
- addWatches();
100
- resolveRestart(error);
89
+ const result = await restartContainer(container);
90
+ if (result instanceof Error) {
91
+ resolveRestart(result);
92
+ } else {
93
+ restart.container = result;
94
+ addWatches();
95
+ resolveRestart(null);
96
+ }
101
97
  restartComplete = new Promise((resolve) => {
102
98
  resolveRestart = resolve;
103
99
  });