astro 2.6.6 → 2.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/README.md +3 -6
  2. package/dist/@types/astro.d.ts +30 -15
  3. package/dist/assets/utils/emitAsset.js +1 -2
  4. package/dist/content/utils.d.ts +1 -2
  5. package/dist/content/utils.js +3 -4
  6. package/dist/content/vite-plugin-content-imports.js +0 -1
  7. package/dist/content/vite-plugin-content-virtual-mod.d.ts +1 -1
  8. package/dist/content/vite-plugin-content-virtual-mod.js +7 -1
  9. package/dist/core/add/babel.d.ts +8 -2
  10. package/dist/core/app/index.d.ts +3 -4
  11. package/dist/core/app/index.js +21 -14
  12. package/dist/core/app/node.d.ts +1 -1
  13. package/dist/core/app/node.js +9 -5
  14. package/dist/core/app/types.d.ts +5 -5
  15. package/dist/core/build/generate.js +9 -12
  16. package/dist/core/build/index.js +1 -8
  17. package/dist/core/build/internal.d.ts +3 -1
  18. package/dist/core/build/internal.js +5 -6
  19. package/dist/core/build/plugins/index.js +2 -1
  20. package/dist/core/build/plugins/plugin-middleware.js +15 -0
  21. package/dist/core/build/plugins/plugin-pages.d.ts +1 -2
  22. package/dist/core/build/plugins/plugin-pages.js +6 -9
  23. package/dist/core/build/plugins/plugin-ssr.d.ts +13 -2
  24. package/dist/core/build/plugins/plugin-ssr.js +220 -73
  25. package/dist/core/build/plugins/util.d.ts +15 -0
  26. package/dist/core/build/plugins/util.js +17 -1
  27. package/dist/core/build/static-build.d.ts +33 -0
  28. package/dist/core/build/static-build.js +57 -26
  29. package/dist/core/build/types.d.ts +5 -3
  30. package/dist/core/compile/compile.js +0 -5
  31. package/dist/core/compile/style.js +0 -1
  32. package/dist/core/config/schema.d.ts +12 -0
  33. package/dist/core/config/schema.js +6 -3
  34. package/dist/core/config/settings.js +1 -1
  35. package/dist/core/constants.js +1 -1
  36. package/dist/core/dev/dev.js +1 -1
  37. package/dist/core/endpoint/dev/index.js +1 -1
  38. package/dist/core/endpoint/index.d.ts +2 -2
  39. package/dist/core/endpoint/index.js +3 -3
  40. package/dist/core/errors/dev/vite.js +1 -9
  41. package/dist/core/errors/errors-data.d.ts +29 -70
  42. package/dist/core/errors/errors-data.js +20 -75
  43. package/dist/core/errors/errors.d.ts +1 -9
  44. package/dist/core/errors/errors.js +8 -9
  45. package/dist/core/errors/index.d.ts +1 -1
  46. package/dist/core/errors/utils.d.ts +2 -3
  47. package/dist/core/errors/utils.js +3 -3
  48. package/dist/core/messages.js +2 -2
  49. package/dist/core/module-loader/loader.d.ts +4 -0
  50. package/dist/core/redirects/component.js +1 -4
  51. package/dist/core/render/context.d.ts +1 -0
  52. package/dist/core/render/context.js +17 -1
  53. package/dist/core/render/core.d.ts +3 -3
  54. package/dist/core/render/core.js +3 -4
  55. package/dist/core/render/dev/index.js +18 -8
  56. package/dist/core/render/dev/vite.js +25 -19
  57. package/dist/core/render/ssr-element.js +3 -4
  58. package/dist/core/request.d.ts +2 -1
  59. package/dist/core/request.js +3 -2
  60. package/dist/core/routing/manifest/create.js +3 -4
  61. package/dist/core/util.d.ts +1 -0
  62. package/dist/core/util.js +5 -4
  63. package/dist/events/error.d.ts +0 -1
  64. package/dist/events/error.js +1 -5
  65. package/dist/integrations/index.d.ts +6 -7
  66. package/dist/integrations/index.js +8 -11
  67. package/dist/jsx/babel.js +3 -3
  68. package/dist/vite-plugin-astro/compile.js +2 -0
  69. package/dist/vite-plugin-astro-server/route.js +4 -1
  70. package/dist/vite-plugin-jsx/index.js +2 -0
  71. package/dist/vite-plugin-load-fallback/index.js +2 -2
  72. package/dist/vite-plugin-markdown/content-entry-type.d.ts +0 -5
  73. package/dist/vite-plugin-markdown/content-entry-type.js +1 -26
  74. package/dist/vite-plugin-markdown/index.js +0 -2
  75. package/package.json +39 -40
  76. package/dist/content/template/types.d.js +0 -0
  77. package/dist/content/template/virtual-mod.d.mts +0 -7
  78. /package/{src/content/template/virtual-mod.mjs → content-module.template.mjs} +0 -0
  79. /package/{src/content/template/types.d.ts → content-types.template.d.ts} +0 -0
@@ -1,5 +1,5 @@
1
1
  import type { default as vite, InlineConfig } from 'vite';
2
- import type { AstroConfig, AstroMiddlewareInstance, AstroSettings, BuildConfig, ComponentInstance, ManifestData, RouteData, RuntimeMode, SSRLoadedRenderer } from '../../@types/astro';
2
+ import type { AstroConfig, AstroSettings, ComponentInstance, ManifestData, MiddlewareHandler, RouteData, RuntimeMode, SSRLoadedRenderer } from '../../@types/astro';
3
3
  import type { LogOptions } from '../logger/core';
4
4
  import type { RouteCache } from '../render/route-cache';
5
5
  export type ComponentPath = string;
@@ -33,7 +33,6 @@ export type AllPagesData = Record<ComponentPath, PageBuildData>;
33
33
  export interface StaticBuildOptions {
34
34
  allPages: AllPagesData;
35
35
  settings: AstroSettings;
36
- buildConfig: BuildConfig;
37
36
  logging: LogOptions;
38
37
  manifest: ManifestData;
39
38
  mode: RuntimeMode;
@@ -46,7 +45,10 @@ export interface StaticBuildOptions {
46
45
  type ImportComponentInstance = () => Promise<ComponentInstance>;
47
46
  export interface SinglePageBuiltModule {
48
47
  page: ImportComponentInstance;
49
- middleware: AstroMiddlewareInstance<unknown>;
48
+ /**
49
+ * The `onRequest` hook exported by the middleware
50
+ */
51
+ onRequest?: MiddlewareHandler<unknown>;
50
52
  renderers: SSRLoadedRenderer[];
51
53
  }
52
54
  export type ViteBuildReturn = Awaited<ReturnType<typeof vite.build>>;
@@ -55,7 +55,6 @@ function handleCompileResultErrors(result, cssTransformErrors) {
55
55
  const compilerError = result.diagnostics.find((diag) => diag.severity === 1);
56
56
  if (compilerError) {
57
57
  throw new CompilerError({
58
- code: compilerError.code,
59
58
  message: compilerError.text,
60
59
  location: {
61
60
  line: compilerError.location.line,
@@ -70,15 +69,11 @@ function handleCompileResultErrors(result, cssTransformErrors) {
70
69
  break;
71
70
  case 1: {
72
71
  const error = cssTransformErrors[0];
73
- if (!error.errorCode) {
74
- error.errorCode = AstroErrorData.UnknownCSSError.code;
75
- }
76
72
  throw cssTransformErrors[0];
77
73
  }
78
74
  default: {
79
75
  throw new AggregateError({
80
76
  ...cssTransformErrors[0],
81
- code: cssTransformErrors[0].errorCode,
82
77
  errors: cssTransformErrors
83
78
  });
84
79
  }
@@ -69,7 +69,6 @@ function enhanceCSSError(err, filename) {
69
69
  const errorPosition = positionAt(styleTagBeginning, fileContent);
70
70
  errorPosition.line += 1;
71
71
  return new CSSError({
72
- code: AstroErrorData.UnknownCSSError.code,
73
72
  message: err.message,
74
73
  location: {
75
74
  file: filename,
@@ -48,6 +48,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
48
48
  serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
49
49
  redirects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
50
50
  inlineStylesheets: z.ZodDefault<z.ZodOptional<z.ZodEnum<["always", "auto", "never"]>>>;
51
+ split: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
51
52
  }, "strip", z.ZodTypeAny, {
52
53
  assetsPrefix?: string | undefined;
53
54
  server: URL;
@@ -57,6 +58,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
57
58
  serverEntry: string;
58
59
  redirects: boolean;
59
60
  inlineStylesheets: "never" | "always" | "auto";
61
+ split: boolean;
60
62
  }, {
61
63
  server?: string | undefined;
62
64
  format?: "file" | "directory" | undefined;
@@ -66,6 +68,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
66
68
  serverEntry?: string | undefined;
67
69
  redirects?: boolean | undefined;
68
70
  inlineStylesheets?: "never" | "always" | "auto" | undefined;
71
+ split?: boolean | undefined;
69
72
  }>>>;
70
73
  server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
71
74
  open: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
@@ -213,6 +216,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
213
216
  serverEntry: string;
214
217
  redirects: boolean;
215
218
  inlineStylesheets: "never" | "always" | "auto";
219
+ split: boolean;
216
220
  };
217
221
  image: {
218
222
  service: {
@@ -268,6 +272,7 @@ export declare const AstroConfigSchema: z.ZodObject<{
268
272
  serverEntry?: string | undefined;
269
273
  redirects?: boolean | undefined;
270
274
  inlineStylesheets?: "never" | "always" | "auto" | undefined;
275
+ split?: boolean | undefined;
271
276
  } | undefined;
272
277
  image?: {
273
278
  service: {
@@ -429,6 +434,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
429
434
  serverEntry: z.ZodDefault<z.ZodOptional<z.ZodString>>;
430
435
  redirects: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
431
436
  inlineStylesheets: z.ZodDefault<z.ZodOptional<z.ZodEnum<["always", "auto", "never"]>>>;
437
+ split: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
432
438
  }, "strip", z.ZodTypeAny, {
433
439
  assetsPrefix?: string | undefined;
434
440
  server: URL;
@@ -438,6 +444,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
438
444
  serverEntry: string;
439
445
  redirects: boolean;
440
446
  inlineStylesheets: "never" | "always" | "auto";
447
+ split: boolean;
441
448
  }, {
442
449
  server?: string | undefined;
443
450
  format?: "file" | "directory" | undefined;
@@ -447,6 +454,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
447
454
  serverEntry?: string | undefined;
448
455
  redirects?: boolean | undefined;
449
456
  inlineStylesheets?: "never" | "always" | "auto" | undefined;
457
+ split?: boolean | undefined;
450
458
  }>>>;
451
459
  server: z.ZodEffects<z.ZodDefault<z.ZodOptional<z.ZodObject<{
452
460
  host: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>>;
@@ -510,6 +518,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
510
518
  serverEntry: string;
511
519
  redirects: boolean;
512
520
  inlineStylesheets: "never" | "always" | "auto";
521
+ split: boolean;
513
522
  };
514
523
  image: {
515
524
  service: {
@@ -565,6 +574,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
565
574
  serverEntry?: string | undefined;
566
575
  redirects?: boolean | undefined;
567
576
  inlineStylesheets?: "never" | "always" | "auto" | undefined;
577
+ split?: boolean | undefined;
568
578
  } | undefined;
569
579
  image?: {
570
580
  service: {
@@ -629,6 +639,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
629
639
  serverEntry: string;
630
640
  redirects: boolean;
631
641
  inlineStylesheets: "never" | "always" | "auto";
642
+ split: boolean;
632
643
  };
633
644
  image: {
634
645
  service: {
@@ -684,6 +695,7 @@ export declare function createRelativeSchema(cmd: string, fileProtocolRoot: URL)
684
695
  serverEntry?: string | undefined;
685
696
  redirects?: boolean | undefined;
686
697
  inlineStylesheets?: "never" | "always" | "auto" | undefined;
698
+ split?: boolean | undefined;
687
699
  } | undefined;
688
700
  image?: {
689
701
  service: {
@@ -17,7 +17,8 @@ const ASTRO_CONFIG_DEFAULTS = {
17
17
  assets: "_astro",
18
18
  serverEntry: "entry.mjs",
19
19
  redirects: true,
20
- inlineStylesheets: "never"
20
+ inlineStylesheets: "never",
21
+ split: false
21
22
  },
22
23
  compressHTML: false,
23
24
  server: {
@@ -66,7 +67,8 @@ const AstroConfigSchema = z.object({
66
67
  assetsPrefix: z.string().optional(),
67
68
  serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
68
69
  redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
69
- inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets)
70
+ inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
71
+ split: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.split)
70
72
  }).optional().default({}),
71
73
  server: z.preprocess(
72
74
  // preprocess
@@ -160,7 +162,8 @@ function createRelativeSchema(cmd, fileProtocolRoot) {
160
162
  assetsPrefix: z.string().optional(),
161
163
  serverEntry: z.string().optional().default(ASTRO_CONFIG_DEFAULTS.build.serverEntry),
162
164
  redirects: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.redirects),
163
- inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets)
165
+ inlineStylesheets: z.enum(["always", "auto", "never"]).optional().default(ASTRO_CONFIG_DEFAULTS.build.inlineStylesheets),
166
+ split: z.boolean().optional().default(ASTRO_CONFIG_DEFAULTS.build.split)
164
167
  }).optional().default({}),
165
168
  server: z.preprocess(
166
169
  // preprocess
@@ -19,7 +19,7 @@ function createBaseSettings(config) {
19
19
  tsConfig: void 0,
20
20
  tsConfigPath: void 0,
21
21
  adapter: void 0,
22
- injectedRoutes: config.experimental.assets && isServerLikeOutput(config) ? [{ pattern: "/_image", entryPoint: "astro/assets/image-endpoint" }] : [],
22
+ injectedRoutes: config.experimental.assets && isServerLikeOutput(config) ? [{ pattern: "/_image", entryPoint: "astro/assets/image-endpoint", prerender: false }] : [],
23
23
  pageExtensions: [".astro", ".html", ...SUPPORTED_MARKDOWN_FILE_EXTENSIONS],
24
24
  contentEntryTypes: [markdownContentEntryType],
25
25
  dataEntryTypes: [
@@ -1,4 +1,4 @@
1
- const ASTRO_VERSION = "2.6.6";
1
+ const ASTRO_VERSION = "2.7.1";
2
2
  const SUPPORTED_MARKDOWN_FILE_EXTENSIONS = [
3
3
  ".markdown",
4
4
  ".mdown",
@@ -53,7 +53,7 @@ async function dev(settings, options) {
53
53
  isRestart: options.isRestart
54
54
  })
55
55
  );
56
- const currentVersion = "2.6.6";
56
+ const currentVersion = "2.7.1";
57
57
  if (currentVersion.includes("-")) {
58
58
  warn(options.logging, null, msg.prerelease({ currentVersion }));
59
59
  }
@@ -15,7 +15,7 @@ async function call(options, logging) {
15
15
  env,
16
16
  mod: endpointHandler
17
17
  });
18
- return await callEndpoint(endpointHandler, env, ctx, logging, middleware);
18
+ return await callEndpoint(endpointHandler, env, ctx, logging, middleware == null ? void 0 : middleware.onRequest);
19
19
  }
20
20
  export {
21
21
  call
@@ -1,5 +1,5 @@
1
1
  /// <reference types="node" />
2
- import type { APIContext, AstroConfig, AstroMiddlewareInstance, EndpointHandler, EndpointOutput, Params } from '../../@types/astro';
2
+ import type { APIContext, AstroConfig, EndpointHandler, EndpointOutput, MiddlewareHandler, Params } from '../../@types/astro';
3
3
  import type { Environment, RenderContext } from '../render/index';
4
4
  import { AstroCookies } from '../cookies/index.js';
5
5
  import { type LogOptions } from '../logger/core.js';
@@ -19,6 +19,6 @@ export declare function createAPIContext({ request, params, site, props, adapter
19
19
  props: Record<string, any>;
20
20
  adapterName?: string;
21
21
  }): APIContext;
22
- export declare function callEndpoint<MiddlewareResult = Response | EndpointOutput>(mod: EndpointHandler, env: Environment, ctx: RenderContext, logging: LogOptions, middleware?: AstroMiddlewareInstance<MiddlewareResult> | undefined): Promise<EndpointCallResult>;
22
+ export declare function callEndpoint<MiddlewareResult = Response | EndpointOutput>(mod: EndpointHandler, env: Environment, ctx: RenderContext, logging: LogOptions, onRequest?: MiddlewareHandler<MiddlewareResult> | undefined): Promise<EndpointCallResult>;
23
23
  export declare function throwIfRedirectNotAllowed(response: Response, config: AstroConfig): void;
24
24
  export {};
@@ -45,6 +45,7 @@ function createAPIContext({
45
45
  }
46
46
  };
47
47
  Object.defineProperty(context, "locals", {
48
+ enumerable: true,
48
49
  get() {
49
50
  return Reflect.get(request, clientLocalsSymbol);
50
51
  },
@@ -58,7 +59,7 @@ function createAPIContext({
58
59
  });
59
60
  return context;
60
61
  }
61
- async function callEndpoint(mod, env, ctx, logging, middleware) {
62
+ async function callEndpoint(mod, env, ctx, logging, onRequest) {
62
63
  var _a;
63
64
  const context = createAPIContext({
64
65
  request: ctx.request,
@@ -68,8 +69,7 @@ async function callEndpoint(mod, env, ctx, logging, middleware) {
68
69
  adapterName: env.adapterName
69
70
  });
70
71
  let response;
71
- if (middleware && middleware.onRequest) {
72
- const onRequest = middleware.onRequest;
72
+ if (onRequest) {
73
73
  response = await callMiddleware(
74
74
  env.logging,
75
75
  onRequest,
@@ -29,7 +29,6 @@ function enhanceViteSSRError({
29
29
  safeError.name = "FailedToLoadModuleSSR";
30
30
  safeError.message = AstroErrorData.FailedToLoadModuleSSR.message(importName);
31
31
  safeError.hint = AstroErrorData.FailedToLoadModuleSSR.hint;
32
- safeError.code = AstroErrorData.FailedToLoadModuleSSR.code;
33
32
  const line = lns.findIndex((ln) => ln.includes(importName));
34
33
  if (line !== -1) {
35
34
  const column = (_b = lns[line]) == null ? void 0 : _b.indexOf(importName);
@@ -55,7 +54,6 @@ function enhanceViteSSRError({
55
54
  safeError.message = AstroErrorData.InvalidGlob.message(globPattern);
56
55
  safeError.name = "InvalidGlob";
57
56
  safeError.hint = AstroErrorData.InvalidGlob.hint;
58
- safeError.code = AstroErrorData.InvalidGlob.code;
59
57
  safeError.title = AstroErrorData.InvalidGlob.title;
60
58
  const line = lns.findIndex((ln) => ln.includes(globPattern));
61
59
  if (line !== -1) {
@@ -81,13 +79,7 @@ async function getViteErrorPayload(err) {
81
79
  }
82
80
  const message = renderErrorMarkdown(err.message.trim(), "html");
83
81
  const hint = err.hint ? renderErrorMarkdown(err.hint.trim(), "html") : void 0;
84
- const hasDocs = err.type && err.name && [
85
- "AstroError",
86
- "AggregateError",
87
- /* 'CompilerError' ,*/
88
- "CSSError",
89
- "MarkdownError"
90
- ] || ["FailedToLoadModuleSSR", "InvalidGlob"].includes(err.name);
82
+ const hasDocs = err.name in AstroErrorData;
91
83
  const docslink = hasDocs ? `https://docs.astro.build/en/reference/errors/${getKebabErrorName(err.name)}/` : void 0;
92
84
  const highlighter = await getHighlighter({ theme: "css-variables" });
93
85
  let highlighterLang = (_b = (_a = err.loc) == null ? void 0 : _a.file) == null ? void 0 : _b.split(".").pop();