astro 6.1.10 → 6.2.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 (127) hide show
  1. package/client.d.ts +1 -0
  2. package/dist/actions/runtime/types.d.ts +1 -1
  3. package/dist/assets/fonts/constants.d.ts +2 -0
  4. package/dist/assets/fonts/constants.js +4 -0
  5. package/dist/assets/fonts/core/create-get-font-file-url.d.ts +2 -0
  6. package/dist/assets/fonts/core/create-get-font-file-url.js +23 -0
  7. package/dist/assets/fonts/core/font-file-middleware.d.ts +21 -0
  8. package/dist/assets/fonts/core/font-file-middleware.js +59 -0
  9. package/dist/assets/fonts/definitions.d.ts +13 -0
  10. package/dist/assets/fonts/infra/build-url-resolver.d.ts +1 -0
  11. package/dist/assets/fonts/infra/build-url-resolver.js +7 -1
  12. package/dist/assets/fonts/infra/dev-url-resolver.d.ts +1 -0
  13. package/dist/assets/fonts/infra/dev-url-resolver.js +7 -1
  14. package/dist/assets/fonts/infra/remote-runtime-font-file-url-resolver.d.ts +19 -0
  15. package/dist/assets/fonts/infra/remote-runtime-font-file-url-resolver.js +27 -0
  16. package/dist/assets/fonts/infra/ssr-runtime-font-file-url-resolver.d.ts +12 -0
  17. package/dist/assets/fonts/infra/ssr-runtime-font-file-url-resolver.js +25 -0
  18. package/dist/assets/fonts/runtime.d.ts +1 -0
  19. package/dist/assets/fonts/runtime.js +4 -0
  20. package/dist/assets/fonts/vite-plugin-fonts.js +88 -49
  21. package/dist/assets/index.d.ts +1 -1
  22. package/dist/assets/index.js +3 -2
  23. package/dist/assets/svg/config.d.ts +5 -0
  24. package/dist/assets/svg/config.js +8 -0
  25. package/dist/assets/svg/svgo.d.ts +4 -0
  26. package/dist/assets/svg/svgo.js +10 -0
  27. package/dist/assets/svg/types.d.ts +4 -0
  28. package/dist/assets/svg/types.js +0 -0
  29. package/dist/assets/svg/utils.d.ts +3 -0
  30. package/dist/assets/{utils/svg.js → svg/utils.js} +11 -14
  31. package/dist/assets/vite-plugin-assets.js +8 -4
  32. package/dist/cli/flags.js +19 -9
  33. package/dist/cli/help/index.js +2 -1
  34. package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
  35. package/dist/cli/preferences/index.js +3 -2
  36. package/dist/config/entrypoint.d.ts +2 -0
  37. package/dist/config/entrypoint.js +4 -0
  38. package/dist/config/index.js +9 -7
  39. package/dist/container/index.js +4 -7
  40. package/dist/content/content-layer.js +3 -3
  41. package/dist/core/app/base.d.ts +18 -4
  42. package/dist/core/app/base.js +29 -12
  43. package/dist/core/app/dev/app.d.ts +0 -1
  44. package/dist/core/app/dev/app.js +0 -2
  45. package/dist/core/app/entrypoints/index.d.ts +1 -1
  46. package/dist/core/app/entrypoints/index.js +1 -1
  47. package/dist/core/app/entrypoints/virtual/dev.js +1 -1
  48. package/dist/core/app/pipeline.js +2 -2
  49. package/dist/core/app/types.d.ts +10 -3
  50. package/dist/core/base-pipeline.d.ts +9 -2
  51. package/dist/core/base-pipeline.js +17 -0
  52. package/dist/core/build/app.js +2 -1
  53. package/dist/core/build/index.js +13 -2
  54. package/dist/core/build/internal.d.ts +1 -0
  55. package/dist/core/build/internal.js +1 -0
  56. package/dist/core/build/pipeline.js +1 -1
  57. package/dist/core/build/plugins/plugin-manifest.js +6 -1
  58. package/dist/core/cache/types.d.ts +2 -0
  59. package/dist/core/config/schemas/base.d.ts +12 -4
  60. package/dist/core/config/schemas/base.js +11 -4
  61. package/dist/core/config/schemas/relative.d.ts +27 -6
  62. package/dist/core/config/schemas/relative.js +1 -1
  63. package/dist/core/config/settings.js +2 -1
  64. package/dist/core/config/vite-load.js +4 -17
  65. package/dist/core/constants.js +1 -1
  66. package/dist/core/createMinimalViteDevServer.d.ts +8 -0
  67. package/dist/core/createMinimalViteDevServer.js +15 -0
  68. package/dist/core/dev/dev.js +1 -1
  69. package/dist/core/dev/restart.js +2 -2
  70. package/dist/core/errors/errors-data.d.ts +48 -2
  71. package/dist/core/errors/errors-data.js +26 -2
  72. package/dist/core/logger/config.d.ts +6 -0
  73. package/dist/core/logger/config.js +0 -0
  74. package/dist/core/logger/core.d.ts +33 -13
  75. package/dist/core/logger/core.js +50 -5
  76. package/dist/core/logger/handlers.d.ts +60 -0
  77. package/dist/core/logger/handlers.js +81 -0
  78. package/dist/core/logger/impls/compose.d.ts +2 -0
  79. package/dist/core/logger/impls/compose.js +26 -0
  80. package/dist/core/logger/impls/console.d.ts +9 -0
  81. package/dist/core/logger/impls/console.js +38 -0
  82. package/dist/core/logger/impls/json.d.ts +15 -0
  83. package/dist/core/logger/impls/json.js +42 -0
  84. package/dist/core/logger/impls/node.d.ts +7 -0
  85. package/dist/core/logger/impls/node.js +40 -0
  86. package/dist/core/logger/load.d.ts +11 -0
  87. package/dist/core/logger/load.js +88 -0
  88. package/dist/core/logger/node.d.ts +0 -5
  89. package/dist/core/logger/node.js +1 -39
  90. package/dist/core/logger/public.d.ts +17 -0
  91. package/dist/core/logger/public.js +7 -0
  92. package/dist/core/messages/runtime.js +1 -1
  93. package/dist/core/middleware/index.js +2 -1
  94. package/dist/core/preview/index.js +4 -3
  95. package/dist/core/render-context.js +35 -1
  96. package/dist/core/sync/index.js +2 -2
  97. package/dist/core/wait-until.d.ts +1 -0
  98. package/dist/core/wait-until.js +0 -0
  99. package/dist/manifest/serialized.js +6 -1
  100. package/dist/runtime/compiler/index.d.ts +1 -1
  101. package/dist/runtime/compiler/index.js +4 -0
  102. package/dist/runtime/server/astro-global.js +3 -0
  103. package/dist/runtime/server/index.d.ts +1 -0
  104. package/dist/runtime/server/index.js +3 -0
  105. package/dist/runtime/server/render/common.js +16 -0
  106. package/dist/runtime/server/render/instruction.d.ts +7 -1
  107. package/dist/runtime/server/render/template-depth.d.ts +13 -0
  108. package/dist/runtime/server/render/template-depth.js +11 -0
  109. package/dist/types/astro.d.ts +2 -0
  110. package/dist/types/public/common.d.ts +1 -0
  111. package/dist/types/public/config.d.ts +54 -42
  112. package/dist/types/public/context.d.ts +17 -0
  113. package/dist/types/public/index.d.ts +1 -0
  114. package/dist/types/public/internal.d.ts +7 -1
  115. package/dist/types/public/preview.d.ts +5 -0
  116. package/dist/vite-plugin-app/app.d.ts +0 -1
  117. package/dist/vite-plugin-app/app.js +0 -2
  118. package/dist/vite-plugin-app/createAstroServerApp.d.ts +1 -1
  119. package/dist/vite-plugin-app/createAstroServerApp.js +2 -6
  120. package/dist/vite-plugin-load-fallback/index.d.ts +1 -1
  121. package/dist/vite-plugin-load-fallback/index.js +2 -5
  122. package/package.json +12 -7
  123. package/dist/assets/utils/svg.d.ts +0 -3
  124. package/dist/core/app/logging.d.ts +0 -3
  125. package/dist/core/app/logging.js +0 -11
  126. package/dist/core/logger/console.d.ts +0 -2
  127. package/dist/core/logger/console.js +0 -21
@@ -1,12 +1,19 @@
1
- export interface AstroLoggerDestination<T> {
2
- write: (chunk: T) => boolean;
1
+ export interface AstroLoggerDestination<T = unknown> {
2
+ /**
3
+ * It receives a message and writes it into a destination
4
+ */
5
+ write: (chunk: T) => void;
6
+ /**
7
+ * It dumps logs without closing the connection to the destination.
8
+ * Method that can be used by specialized loggers.
9
+ */
10
+ flush?: () => Promise<void> | void;
11
+ /**
12
+ * It dumps logs and closes the connection to the destination.
13
+ * Method that can be used by specialized loggers.
14
+ */
15
+ close?: () => Promise<void> | void;
3
16
  }
4
- /**
5
- * How the log should be formatted
6
- * - 'default': how Astro usually format the logs
7
- * - 'json': logs are formatted in JSON format
8
- */
9
- export type AstroLoggerFormat = 'default' | 'json';
10
17
  /**
11
18
  * The level of logging. Priority is the following:
12
19
  * 1. debug
@@ -21,15 +28,19 @@ export type AstroLoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
21
28
  * rather than specific to a single command, function, use, etc. The label will be
22
29
  * shown in the log message to the user, so it should be relevant.
23
30
  */
24
- type AstroLoggerLabel = 'add' | 'build' | 'check' | 'config' | 'content' | 'crypto' | 'deprecated' | 'markdown' | 'router' | 'types' | 'vite' | 'watch' | 'middleware' | 'preferences' | 'redirects' | 'sync' | 'session' | 'toolbar' | 'assets' | 'env' | 'update' | 'adapter' | 'islands' | 'cache' | 'csp' | 'SKIP_FORMAT';
31
+ declare const AstroLoggerLabels: readonly ["add", "build", "check", "config", "content", "crypto", "deprecated", "markdown", "router", "types", "vite", "watch", "middleware", "preferences", "redirects", "sync", "session", "toolbar", "assets", "env", "update", "adapter", "islands", "cache", "csp", "SKIP_FORMAT"];
32
+ type AstroLoggerLabel = (typeof AstroLoggerLabels)[number];
25
33
  export interface AstroLogOptions {
26
- destination: AstroLoggerDestination<AstroLogMessage>;
34
+ destination: AstroLoggerDestination<AstroLoggerMessage>;
27
35
  level: AstroLoggerLevel;
28
- _format?: AstroLoggerFormat;
36
+ /**
37
+ * Optional configuration for the logger destination
38
+ */
39
+ config?: Record<string, any> | undefined;
29
40
  }
30
41
  /** @lintignore */
31
42
  export declare const dateTimeFormat: Intl.DateTimeFormat;
32
- export interface AstroLogMessage {
43
+ export interface AstroLoggerMessage {
33
44
  /**
34
45
  * Label associated to the message. Used by Astro for pretty logging
35
46
  */
@@ -55,7 +66,7 @@ export declare function debug(...args: any[]): void;
55
66
  * This includes the timestamp, log level, and label all properly formatted
56
67
  * with colors. This is shared across different loggers, so it's defined here.
57
68
  */
58
- export declare function getEventPrefix({ level, label }: AstroLogMessage): string;
69
+ export declare function getEventPrefix({ level, label }: AstroLoggerMessage): string;
59
70
  /** Print out a timer message for debug() */
60
71
  export declare function timerMessage(message: string, startTime?: number): string;
61
72
  export declare class AstroLogger {
@@ -67,6 +78,15 @@ export declare class AstroLogger {
67
78
  debug(label: AstroLoggerLabel, ...messages: any[]): void;
68
79
  level(): AstroLoggerLevel;
69
80
  forkIntegrationLogger(label: string): AstroIntegrationLogger;
81
+ setDestination(destination: AstroLoggerDestination<AstroLoggerMessage>): void;
82
+ /**
83
+ * It calls the `close` function of the provided destination, if it exists.
84
+ */
85
+ close(): void;
86
+ /**
87
+ * It calls the `flush` function of the provided destinatin, if it exists.
88
+ */
89
+ flush(): void;
70
90
  }
71
91
  export declare class AstroIntegrationLogger {
72
92
  options: AstroLogOptions;
@@ -1,4 +1,34 @@
1
1
  import colors from "piccolore";
2
+ const AstroLoggerLabels = [
3
+ "add",
4
+ "build",
5
+ "check",
6
+ "config",
7
+ "content",
8
+ "crypto",
9
+ "deprecated",
10
+ "markdown",
11
+ "router",
12
+ "types",
13
+ "vite",
14
+ "watch",
15
+ "middleware",
16
+ "preferences",
17
+ "redirects",
18
+ "sync",
19
+ "session",
20
+ "toolbar",
21
+ "assets",
22
+ "env",
23
+ "update",
24
+ "adapter",
25
+ "islands",
26
+ "cache",
27
+ "csp",
28
+ // SKIP_FORMAT: A special label that tells the logger not to apply any formatting.
29
+ // Useful for messages that are already formatted, like the server start message.
30
+ "SKIP_FORMAT"
31
+ ];
2
32
  const dateTimeFormat = new Intl.DateTimeFormat([], {
3
33
  hour: "2-digit",
4
34
  minute: "2-digit",
@@ -19,8 +49,7 @@ function log(opts, level, label, message, newLine = true) {
19
49
  label,
20
50
  level,
21
51
  message,
22
- newLine,
23
- _format: opts._format
52
+ newLine
24
53
  };
25
54
  if (!isLogLevelEnabled(logLevel, level)) {
26
55
  return;
@@ -75,9 +104,6 @@ function timerMessage(message, startTime = Date.now()) {
75
104
  class AstroLogger {
76
105
  options;
77
106
  constructor(options) {
78
- if (!options._format) {
79
- options._format = "default";
80
- }
81
107
  this.options = options;
82
108
  }
83
109
  info(label, message, newLine = true) {
@@ -98,6 +124,25 @@ class AstroLogger {
98
124
  forkIntegrationLogger(label) {
99
125
  return new AstroIntegrationLogger(this.options, label);
100
126
  }
127
+ setDestination(destination) {
128
+ this.options.destination = destination;
129
+ }
130
+ /**
131
+ * It calls the `close` function of the provided destination, if it exists.
132
+ */
133
+ close() {
134
+ if (this.options.destination.close) {
135
+ this.options.destination.close();
136
+ }
137
+ }
138
+ /**
139
+ * It calls the `flush` function of the provided destinatin, if it exists.
140
+ */
141
+ flush() {
142
+ if (this.options.destination.flush) {
143
+ this.options.destination.flush();
144
+ }
145
+ }
101
146
  }
102
147
  class AstroIntegrationLogger {
103
148
  options;
@@ -0,0 +1,60 @@
1
+ import type { LoggerHandlerConfig } from './config.js';
2
+ import type { JsonHandlerConfig } from './impls/json.js';
3
+ import type { NodeHandlerConfig } from './impls/node.js';
4
+ import type { ConsoleHandlerConfig } from './impls/console.js';
5
+ export declare const logHandlers: {
6
+ /**
7
+ * It uses the built-in Astro JSON logger.
8
+ * @example
9
+ * ```js
10
+ * export default defineConfig({
11
+ * experimental: {
12
+ * logger: logHandlers.json({ pretty: true })
13
+ * }
14
+ * })
15
+ * ```
16
+ */
17
+ json(config?: JsonHandlerConfig): LoggerHandlerConfig;
18
+ /**
19
+ * It uses the built-in Astro Node.js logger.
20
+ *
21
+ * @example
22
+ * ```js
23
+ * export default defineConfig({
24
+ * experimental: {
25
+ * logger: logHandlers.node({ pretty: true })
26
+ * }
27
+ * })
28
+ * ```
29
+ */
30
+ node(config?: NodeHandlerConfig): LoggerHandlerConfig;
31
+ /**
32
+ * It uses the built-in Astro console logger.
33
+ *
34
+ * @example
35
+ * ```js
36
+ * export default defineConfig({
37
+ * experimental: {
38
+ * logger: logHandlers.console({ pretty: true })
39
+ * }
40
+ * })
41
+ * ```
42
+ */
43
+ console(config?: ConsoleHandlerConfig): LoggerHandlerConfig;
44
+ /**
45
+ * It allows composing different loggers
46
+ *
47
+ * @example
48
+ * ```js
49
+ * export default defineConfig({
50
+ * experimental: {
51
+ * logger: logHandlers.compose(
52
+ * logHandlers.console(),
53
+ * logHandlers.json(),
54
+ * )
55
+ * }
56
+ * })
57
+ * ```
58
+ */
59
+ compose(...loggers: LoggerHandlerConfig[]): LoggerHandlerConfig;
60
+ };
@@ -0,0 +1,81 @@
1
+ const logHandlers = {
2
+ /**
3
+ * It uses the built-in Astro JSON logger.
4
+ * @example
5
+ * ```js
6
+ * export default defineConfig({
7
+ * experimental: {
8
+ * logger: logHandlers.json({ pretty: true })
9
+ * }
10
+ * })
11
+ * ```
12
+ */
13
+ json(config) {
14
+ return {
15
+ entrypoint: "astro/logger/json",
16
+ config
17
+ };
18
+ },
19
+ /**
20
+ * It uses the built-in Astro Node.js logger.
21
+ *
22
+ * @example
23
+ * ```js
24
+ * export default defineConfig({
25
+ * experimental: {
26
+ * logger: logHandlers.node({ pretty: true })
27
+ * }
28
+ * })
29
+ * ```
30
+ */
31
+ node(config) {
32
+ return {
33
+ entrypoint: "astro/logger/node",
34
+ config
35
+ };
36
+ },
37
+ /**
38
+ * It uses the built-in Astro console logger.
39
+ *
40
+ * @example
41
+ * ```js
42
+ * export default defineConfig({
43
+ * experimental: {
44
+ * logger: logHandlers.console({ pretty: true })
45
+ * }
46
+ * })
47
+ * ```
48
+ */
49
+ console(config) {
50
+ return {
51
+ entrypoint: "astro/logger/console",
52
+ config
53
+ };
54
+ },
55
+ /**
56
+ * It allows composing different loggers
57
+ *
58
+ * @example
59
+ * ```js
60
+ * export default defineConfig({
61
+ * experimental: {
62
+ * logger: logHandlers.compose(
63
+ * logHandlers.console(),
64
+ * logHandlers.json(),
65
+ * )
66
+ * }
67
+ * })
68
+ * ```
69
+ */
70
+ compose(...loggers) {
71
+ return {
72
+ entrypoint: "astro/logger/compose",
73
+ config: {
74
+ loggers
75
+ }
76
+ };
77
+ }
78
+ };
79
+ export {
80
+ logHandlers
81
+ };
@@ -0,0 +1,2 @@
1
+ import type { AstroLoggerDestination } from '../core.js';
2
+ export default function compose(destinations: AstroLoggerDestination[]): AstroLoggerDestination;
@@ -0,0 +1,26 @@
1
+ function compose(destinations) {
2
+ return {
3
+ write(chunk) {
4
+ for (const logger of destinations) {
5
+ logger.write(chunk);
6
+ }
7
+ },
8
+ flush() {
9
+ for (const logger of destinations) {
10
+ if (logger.flush) {
11
+ logger.flush();
12
+ }
13
+ }
14
+ },
15
+ close() {
16
+ for (const logger of destinations) {
17
+ if (logger.close) {
18
+ logger.close();
19
+ }
20
+ }
21
+ }
22
+ };
23
+ }
24
+ export {
25
+ compose as default
26
+ };
@@ -0,0 +1,9 @@
1
+ import { type AstroLoggerMessage, type AstroLoggerDestination, type AstroLoggerLevel, AstroLogger } from '../core.js';
2
+ import type { NodeHandlerConfig } from './node.js';
3
+ export type ConsoleHandlerConfig = {
4
+ level?: AstroLoggerLevel;
5
+ };
6
+ export declare function createConsoleLogger({ level }: {
7
+ level: AstroLoggerLevel;
8
+ }): AstroLogger;
9
+ export default function (options?: NodeHandlerConfig): AstroLoggerDestination<AstroLoggerMessage>;
@@ -0,0 +1,38 @@
1
+ import {
2
+ getEventPrefix,
3
+ levels,
4
+ AstroLogger
5
+ } from "../core.js";
6
+ import { matchesLevel } from "../public.js";
7
+ function consoleLogDestination(config = {}) {
8
+ const { level = "info" } = config;
9
+ return {
10
+ write(event) {
11
+ let dest = console.error;
12
+ if (levels[event.level] < levels["error"]) {
13
+ dest = console.info;
14
+ }
15
+ if (!matchesLevel(event.level, level)) {
16
+ return;
17
+ }
18
+ if (event.label === "SKIP_FORMAT") {
19
+ dest(event.message);
20
+ } else {
21
+ dest(getEventPrefix(event) + " " + event.message);
22
+ }
23
+ }
24
+ };
25
+ }
26
+ function createConsoleLogger({ level }) {
27
+ return new AstroLogger({
28
+ level,
29
+ destination: consoleLogDestination()
30
+ });
31
+ }
32
+ function console_default(options) {
33
+ return consoleLogDestination(options);
34
+ }
35
+ export {
36
+ createConsoleLogger,
37
+ console_default as default
38
+ };
@@ -0,0 +1,15 @@
1
+ import { AstroLogger, type AstroLoggerDestination, type AstroLoggerLevel, type AstroLoggerMessage } from '../core.js';
2
+ import type { AstroInlineConfig } from '../../../types/public/index.js';
3
+ export type JsonHandlerConfig = {
4
+ /**
5
+ * Whether the JSON line should format on multiple lines
6
+ */
7
+ pretty?: boolean;
8
+ /**
9
+ * The level of logs that should be printed by the logger.
10
+ */
11
+ level?: AstroLoggerLevel;
12
+ };
13
+ export declare const SGR_REGEX: RegExp;
14
+ export default function jsonLoggerDestination(config?: JsonHandlerConfig): AstroLoggerDestination<AstroLoggerMessage>;
15
+ export declare function createJsonLoggerFromFlags(config: AstroInlineConfig): AstroLogger;
@@ -0,0 +1,42 @@
1
+ import {
2
+ AstroLogger,
3
+ levels
4
+ } from "../core.js";
5
+ import { matchesLevel } from "../public.js";
6
+ const SGR_REGEX = new RegExp(`${String.fromCharCode(27)}\\[[0-9;]*m`, "g");
7
+ function jsonLoggerDestination(config = {}) {
8
+ const { pretty = false, level = "info" } = config;
9
+ return {
10
+ write(event) {
11
+ let dest = process.stderr;
12
+ if (levels[event.level] < levels["error"]) {
13
+ dest = process.stdout;
14
+ }
15
+ if (!matchesLevel(event.level, level)) {
16
+ return;
17
+ }
18
+ let trailingLine = event.newLine ? "\n" : "";
19
+ const message = event.message.replace(SGR_REGEX, "");
20
+ if (pretty) {
21
+ dest.write(
22
+ JSON.stringify({ message, label: event.label, level: event.level }, null, 2) + trailingLine
23
+ );
24
+ } else {
25
+ dest.write(
26
+ JSON.stringify({ message, label: event.label, level: event.level }) + trailingLine
27
+ );
28
+ }
29
+ }
30
+ };
31
+ }
32
+ function createJsonLoggerFromFlags(config) {
33
+ return new AstroLogger({
34
+ destination: jsonLoggerDestination({ pretty: false }),
35
+ level: config.logLevel ?? "info"
36
+ });
37
+ }
38
+ export {
39
+ SGR_REGEX,
40
+ createJsonLoggerFromFlags,
41
+ jsonLoggerDestination as default
42
+ };
@@ -0,0 +1,7 @@
1
+ import { AstroLogger, type AstroLoggerDestination, type AstroLoggerLevel, type AstroLoggerMessage } from '../core.js';
2
+ import type { AstroInlineConfig } from '../../../types/public/index.js';
3
+ export type NodeHandlerConfig = {
4
+ level?: AstroLoggerLevel;
5
+ };
6
+ export default function (options?: NodeHandlerConfig): AstroLoggerDestination<AstroLoggerMessage>;
7
+ export declare function createNodeLoggerFromFlags(inlineConfig: AstroInlineConfig): AstroLogger;
@@ -0,0 +1,40 @@
1
+ import {
2
+ AstroLogger,
3
+ getEventPrefix,
4
+ levels
5
+ } from "../core.js";
6
+ import { matchesLevel } from "../public.js";
7
+ function nodeLogDestination(config = {}) {
8
+ const { level = "info" } = config;
9
+ return {
10
+ write(event) {
11
+ let dest = process.stderr;
12
+ if (levels[event.level] < levels["error"]) {
13
+ dest = process.stdout;
14
+ }
15
+ if (!matchesLevel(event.level, level)) {
16
+ return;
17
+ }
18
+ let trailingLine = event.newLine ? "\n" : "";
19
+ if (event.label === "SKIP_FORMAT") {
20
+ dest.write(event.message + trailingLine);
21
+ } else {
22
+ dest.write(getEventPrefix(event) + " " + event.message + trailingLine);
23
+ }
24
+ }
25
+ };
26
+ }
27
+ function node_default(options) {
28
+ return nodeLogDestination(options);
29
+ }
30
+ function createNodeLoggerFromFlags(inlineConfig) {
31
+ if (inlineConfig.logger) return inlineConfig.logger;
32
+ return new AstroLogger({
33
+ destination: nodeLogDestination(),
34
+ level: inlineConfig.logLevel ?? "info"
35
+ });
36
+ }
37
+ export {
38
+ createNodeLoggerFromFlags,
39
+ node_default as default
40
+ };
@@ -0,0 +1,11 @@
1
+ import { AstroLogger, type AstroLoggerLevel } from './core.js';
2
+ import type { LoggerHandlerConfig } from './config.js';
3
+ import type { AstroConfig, AstroInlineConfig } from '../../types/public/index.js';
4
+ export declare function loadLogger(config: LoggerHandlerConfig, level?: AstroLoggerLevel): Promise<AstroLogger>;
5
+ /**
6
+ * It attempts to load a logger from the entrypoint.
7
+ * If not provided, it creates a new logger instance on the fly.
8
+ * @param astroConfig
9
+ * @param inlineAstroConfig
10
+ */
11
+ export declare function loadOrCreateNodeLogger(astroConfig: AstroConfig, inlineAstroConfig: AstroInlineConfig): Promise<AstroLogger>;
@@ -0,0 +1,88 @@
1
+ import { AstroLogger } from "./core.js";
2
+ import { AstroError } from "../errors/index.js";
3
+ import { UnableToLoadLogger } from "../errors/errors-data.js";
4
+ import { default as nodeLoggerCreator, createNodeLoggerFromFlags } from "./impls/node.js";
5
+ import { default as consoleLoggerCreator } from "./impls/console.js";
6
+ import { default as jsonLoggerCreator } from "./impls/json.js";
7
+ import { default as composeLoggerCreator } from "./impls/compose.js";
8
+ async function loadLogger(config, level = "info") {
9
+ let cause = void 0;
10
+ try {
11
+ switch (config.entrypoint) {
12
+ case "astro/logger/node": {
13
+ return new AstroLogger({
14
+ destination: nodeLoggerCreator(config.config),
15
+ level
16
+ });
17
+ }
18
+ case "astro/logger/console": {
19
+ return new AstroLogger({
20
+ destination: consoleLoggerCreator(config.config),
21
+ level
22
+ });
23
+ }
24
+ case "astro/logger/json": {
25
+ return new AstroLogger({
26
+ destination: jsonLoggerCreator(config.config),
27
+ level
28
+ });
29
+ }
30
+ case "astro/logger/compose": {
31
+ let destinations = [];
32
+ if (config.config?.loggers) {
33
+ const loggers = config.config?.loggers;
34
+ destinations = await Promise.all(
35
+ loggers.map(async (loggerConfig) => {
36
+ const logger = await import(
37
+ /* @vite-ignore */
38
+ loggerConfig.entrypoint
39
+ );
40
+ return logger.default(loggerConfig.config);
41
+ })
42
+ );
43
+ }
44
+ return new AstroLogger({
45
+ destination: composeLoggerCreator(destinations),
46
+ level
47
+ });
48
+ }
49
+ default: {
50
+ const nodeLogger = await import(
51
+ /* @vite-ignore */
52
+ config.entrypoint
53
+ );
54
+ return new AstroLogger({
55
+ destination: nodeLogger.default(config.config),
56
+ level
57
+ });
58
+ }
59
+ }
60
+ } catch (e) {
61
+ if (e instanceof Error) {
62
+ cause = e;
63
+ }
64
+ }
65
+ const error = new AstroError({
66
+ ...UnableToLoadLogger,
67
+ message: UnableToLoadLogger.message(config.entrypoint)
68
+ });
69
+ if (cause) {
70
+ error.cause = cause;
71
+ }
72
+ throw error;
73
+ }
74
+ async function loadOrCreateNodeLogger(astroConfig, inlineAstroConfig) {
75
+ try {
76
+ if (astroConfig.experimental.logger) {
77
+ return await loadLogger(astroConfig.experimental.logger, inlineAstroConfig.logLevel);
78
+ } else {
79
+ return createNodeLoggerFromFlags(inlineAstroConfig);
80
+ }
81
+ } catch {
82
+ return createNodeLoggerFromFlags(inlineAstroConfig);
83
+ }
84
+ }
85
+ export {
86
+ loadLogger,
87
+ loadOrCreateNodeLogger
88
+ };
@@ -1,6 +1 @@
1
- import type { AstroInlineConfig } from '../../types/public/config.js';
2
- import { AstroLogger } from './core.js';
3
- import { type AstroLogMessage, type AstroLoggerDestination } from './core.js';
4
- export declare const nodeLogDestination: AstroLoggerDestination<AstroLogMessage>;
5
1
  export declare function enableVerboseLogging(): void;
6
- export declare function createNodeLogger(inlineConfig: AstroInlineConfig): AstroLogger;
@@ -1,33 +1,4 @@
1
1
  import { createDebug, enable as obugEnable } from "obug";
2
- import { AstroLogger } from "./core.js";
3
- import {
4
- getEventPrefix,
5
- levels
6
- } from "./core.js";
7
- const nodeLogDestination = {
8
- write(event) {
9
- let dest = process.stderr;
10
- if (levels[event.level] < levels["error"]) {
11
- dest = process.stdout;
12
- }
13
- let format = event._format ?? "default";
14
- let trailingLine = event.newLine ? "\n" : "";
15
- switch (format) {
16
- case "json": {
17
- dest.write(JSON.stringify({ message: event.message, label: event.label }) + trailingLine);
18
- return true;
19
- }
20
- case "default": {
21
- if (event.label === "SKIP_FORMAT") {
22
- dest.write(event.message + trailingLine);
23
- } else {
24
- dest.write(getEventPrefix(event) + " " + event.message + trailingLine);
25
- }
26
- return true;
27
- }
28
- }
29
- }
30
- };
31
2
  const debuggers = {};
32
3
  function debug(type, ...messages) {
33
4
  const namespace = `astro:${type}`;
@@ -43,15 +14,6 @@ function enableVerboseLogging() {
43
14
  'Tip: Set the DEBUG env variable directly for more control. Example: "DEBUG=astro:*,vite:* astro build".'
44
15
  );
45
16
  }
46
- function createNodeLogger(inlineConfig) {
47
- if (inlineConfig.logger) return inlineConfig.logger;
48
- return new AstroLogger({
49
- destination: nodeLogDestination,
50
- level: inlineConfig.logLevel ?? "info"
51
- });
52
- }
53
17
  export {
54
- createNodeLogger,
55
- enableVerboseLogging,
56
- nodeLogDestination
18
+ enableVerboseLogging
57
19
  };
@@ -0,0 +1,17 @@
1
+ import { type AstroLoggerLevel } from './core.js';
2
+ /**
3
+ * Returns `true` if `messageLevel` has a level equals or higher than `configuredLevel`. As a golden rule,
4
+ * the first argument should be level of the incoming message, and the second argument should be the
5
+ * configured level of the logger.
6
+ *
7
+ * @param messageLevel The level of the incoming message
8
+ * @param configuredLevel The level the logger is configured with
9
+ *
10
+ * @example
11
+ *
12
+ * ```js
13
+ * matchesLevel('error', 'info') // true, because 'error' has higher priority than 'info'
14
+ * matchesLevel('info', 'error') // false, because 'info' has lower priority than 'error'
15
+ * ```
16
+ */
17
+ export declare function matchesLevel(messageLevel: AstroLoggerLevel, configuredLevel: AstroLoggerLevel): boolean;
@@ -0,0 +1,7 @@
1
+ import { levels } from "./core.js";
2
+ function matchesLevel(messageLevel, configuredLevel) {
3
+ return levels[messageLevel] >= levels[configuredLevel];
4
+ }
5
+ export {
6
+ matchesLevel
7
+ };
@@ -276,7 +276,7 @@ function printHelp({
276
276
  message.push(
277
277
  linebreak(),
278
278
  ` ${bgGreen(black(` ${commandName} `))} ${green(
279
- `v${"6.1.10"}`
279
+ `v${"6.2.0"}`
280
280
  )} ${headline}`
281
281
  );
282
282
  }