astro 6.1.10 → 6.2.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.
- package/client.d.ts +1 -0
- package/dist/actions/runtime/types.d.ts +1 -1
- package/dist/assets/fonts/constants.d.ts +2 -0
- package/dist/assets/fonts/constants.js +4 -0
- package/dist/assets/fonts/core/create-get-font-file-url.d.ts +2 -0
- package/dist/assets/fonts/core/create-get-font-file-url.js +23 -0
- package/dist/assets/fonts/core/font-file-middleware.d.ts +21 -0
- package/dist/assets/fonts/core/font-file-middleware.js +59 -0
- package/dist/assets/fonts/definitions.d.ts +13 -0
- package/dist/assets/fonts/infra/build-url-resolver.d.ts +1 -0
- package/dist/assets/fonts/infra/build-url-resolver.js +7 -1
- package/dist/assets/fonts/infra/dev-url-resolver.d.ts +1 -0
- package/dist/assets/fonts/infra/dev-url-resolver.js +7 -1
- package/dist/assets/fonts/infra/remote-runtime-font-file-url-resolver.d.ts +19 -0
- package/dist/assets/fonts/infra/remote-runtime-font-file-url-resolver.js +27 -0
- package/dist/assets/fonts/infra/ssr-runtime-font-file-url-resolver.d.ts +12 -0
- package/dist/assets/fonts/infra/ssr-runtime-font-file-url-resolver.js +25 -0
- package/dist/assets/fonts/runtime.d.ts +1 -0
- package/dist/assets/fonts/runtime.js +4 -0
- package/dist/assets/fonts/vite-plugin-fonts.js +88 -49
- package/dist/assets/index.d.ts +1 -1
- package/dist/assets/index.js +3 -2
- package/dist/assets/svg/config.d.ts +5 -0
- package/dist/assets/svg/config.js +8 -0
- package/dist/assets/svg/svgo.d.ts +4 -0
- package/dist/assets/svg/svgo.js +10 -0
- package/dist/assets/svg/types.d.ts +4 -0
- package/dist/assets/svg/types.js +0 -0
- package/dist/assets/svg/utils.d.ts +3 -0
- package/dist/assets/{utils/svg.js → svg/utils.js} +11 -14
- package/dist/assets/vite-plugin-assets.js +8 -4
- package/dist/cli/flags.js +19 -9
- package/dist/cli/help/index.js +2 -1
- package/dist/cli/infra/build-time-astro-version-provider.js +1 -1
- package/dist/cli/preferences/index.js +3 -2
- package/dist/config/entrypoint.d.ts +2 -0
- package/dist/config/entrypoint.js +4 -0
- package/dist/config/index.js +9 -7
- package/dist/container/index.js +4 -7
- package/dist/content/content-layer.js +3 -3
- package/dist/core/app/base.d.ts +18 -4
- package/dist/core/app/base.js +29 -12
- package/dist/core/app/dev/app.d.ts +0 -1
- package/dist/core/app/dev/app.js +0 -2
- package/dist/core/app/entrypoints/index.d.ts +1 -1
- package/dist/core/app/entrypoints/index.js +1 -1
- package/dist/core/app/entrypoints/virtual/dev.js +1 -1
- package/dist/core/app/pipeline.js +2 -2
- package/dist/core/app/types.d.ts +10 -3
- package/dist/core/base-pipeline.d.ts +9 -2
- package/dist/core/base-pipeline.js +17 -0
- package/dist/core/build/app.js +2 -1
- package/dist/core/build/index.js +13 -2
- package/dist/core/build/internal.d.ts +1 -0
- package/dist/core/build/internal.js +1 -0
- package/dist/core/build/pipeline.js +1 -1
- package/dist/core/build/plugins/plugin-manifest.js +6 -1
- package/dist/core/cache/types.d.ts +2 -0
- package/dist/core/config/schemas/base.d.ts +16 -8
- package/dist/core/config/schemas/base.js +17 -10
- package/dist/core/config/schemas/relative.d.ts +31 -13
- package/dist/core/config/schemas/relative.js +3 -4
- package/dist/core/config/settings.js +2 -1
- package/dist/core/config/vite-load.js +4 -17
- package/dist/core/constants.js +1 -1
- package/dist/core/createMinimalViteDevServer.d.ts +8 -0
- package/dist/core/createMinimalViteDevServer.js +15 -0
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/dev/restart.js +2 -2
- package/dist/core/errors/errors-data.d.ts +48 -2
- package/dist/core/errors/errors-data.js +26 -2
- package/dist/core/errors/zod-error-map.js +27 -0
- package/dist/core/logger/config.d.ts +6 -0
- package/dist/core/logger/config.js +0 -0
- package/dist/core/logger/core.d.ts +33 -13
- package/dist/core/logger/core.js +50 -5
- package/dist/core/logger/handlers.d.ts +60 -0
- package/dist/core/logger/handlers.js +81 -0
- package/dist/core/logger/impls/compose.d.ts +2 -0
- package/dist/core/logger/impls/compose.js +26 -0
- package/dist/core/logger/impls/console.d.ts +9 -0
- package/dist/core/logger/impls/console.js +38 -0
- package/dist/core/logger/impls/json.d.ts +15 -0
- package/dist/core/logger/impls/json.js +42 -0
- package/dist/core/logger/impls/node.d.ts +7 -0
- package/dist/core/logger/impls/node.js +40 -0
- package/dist/core/logger/load.d.ts +11 -0
- package/dist/core/logger/load.js +88 -0
- package/dist/core/logger/node.d.ts +0 -5
- package/dist/core/logger/node.js +1 -39
- package/dist/core/logger/public.d.ts +17 -0
- package/dist/core/logger/public.js +7 -0
- package/dist/core/messages/runtime.js +1 -1
- package/dist/core/middleware/index.js +2 -1
- package/dist/core/preview/index.js +4 -3
- package/dist/core/render-context.js +35 -1
- package/dist/core/sync/index.js +2 -2
- package/dist/core/wait-until.d.ts +1 -0
- package/dist/core/wait-until.js +0 -0
- package/dist/manifest/serialized.js +6 -1
- package/dist/runtime/compiler/index.d.ts +1 -1
- package/dist/runtime/compiler/index.js +4 -0
- package/dist/runtime/server/astro-global.js +3 -0
- package/dist/runtime/server/index.d.ts +1 -0
- package/dist/runtime/server/index.js +3 -0
- package/dist/runtime/server/render/common.js +16 -0
- package/dist/runtime/server/render/instruction.d.ts +7 -1
- package/dist/runtime/server/render/template-depth.d.ts +13 -0
- package/dist/runtime/server/render/template-depth.js +11 -0
- package/dist/types/astro.d.ts +2 -0
- package/dist/types/public/common.d.ts +1 -0
- package/dist/types/public/config.d.ts +54 -42
- package/dist/types/public/context.d.ts +17 -0
- package/dist/types/public/index.d.ts +1 -0
- package/dist/types/public/internal.d.ts +7 -1
- package/dist/types/public/preview.d.ts +5 -0
- package/dist/vite-plugin-app/app.d.ts +0 -1
- package/dist/vite-plugin-app/app.js +0 -2
- package/dist/vite-plugin-app/createAstroServerApp.d.ts +1 -1
- package/dist/vite-plugin-app/createAstroServerApp.js +2 -6
- package/dist/vite-plugin-load-fallback/index.d.ts +1 -1
- package/dist/vite-plugin-load-fallback/index.js +2 -5
- package/package.json +8 -3
- package/dist/assets/utils/svg.d.ts +0 -3
- package/dist/core/app/logging.d.ts +0 -3
- package/dist/core/app/logging.js +0 -11
- package/dist/core/logger/console.d.ts +0 -2
- package/dist/core/logger/console.js +0 -21
|
@@ -539,12 +539,12 @@ export declare const UnsupportedImageConversion: {
|
|
|
539
539
|
};
|
|
540
540
|
/**
|
|
541
541
|
* @docs
|
|
542
|
-
* @message An error occurred while optimizing the SVG file with
|
|
542
|
+
* @message An error occurred while optimizing the SVG file with the optimizer.
|
|
543
543
|
*/
|
|
544
544
|
export declare const CannotOptimizeSvg: {
|
|
545
545
|
name: string;
|
|
546
546
|
title: string;
|
|
547
|
-
message: (path: string) => string;
|
|
547
|
+
message: (path: string, name: string) => string;
|
|
548
548
|
hint: string;
|
|
549
549
|
};
|
|
550
550
|
/**
|
|
@@ -1314,6 +1314,29 @@ export declare const FontFamilyNotFound: {
|
|
|
1314
1314
|
message: (family: string) => string;
|
|
1315
1315
|
hint: string;
|
|
1316
1316
|
};
|
|
1317
|
+
/**
|
|
1318
|
+
* @docs
|
|
1319
|
+
* @description
|
|
1320
|
+
* Font file URL not found
|
|
1321
|
+
* @message
|
|
1322
|
+
* The URL passed to the `experimental_getFontFileURL()` function is invalid.
|
|
1323
|
+
*/
|
|
1324
|
+
export declare const FontFileUrlNotFound: {
|
|
1325
|
+
name: string;
|
|
1326
|
+
title: string;
|
|
1327
|
+
message: (url: string) => string;
|
|
1328
|
+
hint: string;
|
|
1329
|
+
};
|
|
1330
|
+
/**
|
|
1331
|
+
* @docs
|
|
1332
|
+
* @description
|
|
1333
|
+
* `experimental_getFontFileURL()` requires the request URL with on-demand rendering.
|
|
1334
|
+
*/
|
|
1335
|
+
export declare const MissingGetFontFileRequestUrl: {
|
|
1336
|
+
name: string;
|
|
1337
|
+
title: string;
|
|
1338
|
+
hint: string;
|
|
1339
|
+
};
|
|
1317
1340
|
/**
|
|
1318
1341
|
* @docs
|
|
1319
1342
|
* @description
|
|
@@ -1326,6 +1349,29 @@ export declare const UnavailableAstroGlobal: {
|
|
|
1326
1349
|
title: string;
|
|
1327
1350
|
message: (name: string) => string;
|
|
1328
1351
|
};
|
|
1352
|
+
/**
|
|
1353
|
+
* @docs
|
|
1354
|
+
* @description
|
|
1355
|
+
* Unable to load the logger.
|
|
1356
|
+
* @message
|
|
1357
|
+
* Couldn't load the logger at the given path.
|
|
1358
|
+
*/
|
|
1359
|
+
export declare const UnableToLoadLogger: {
|
|
1360
|
+
name: string;
|
|
1361
|
+
title: string;
|
|
1362
|
+
message: (path: string) => string;
|
|
1363
|
+
};
|
|
1364
|
+
/**
|
|
1365
|
+
* @docs
|
|
1366
|
+
* @description
|
|
1367
|
+
* The configuration of the logger is not serializable.
|
|
1368
|
+
* @message
|
|
1369
|
+
* The configuration of the logger is not serializable.
|
|
1370
|
+
*/
|
|
1371
|
+
export declare const LoggerConfigurationNotSerializable: {
|
|
1372
|
+
name: string;
|
|
1373
|
+
title: string;
|
|
1374
|
+
};
|
|
1329
1375
|
/**
|
|
1330
1376
|
* @docs
|
|
1331
1377
|
* @kind heading
|
|
@@ -197,8 +197,8 @@ const UnsupportedImageConversion = {
|
|
|
197
197
|
const CannotOptimizeSvg = {
|
|
198
198
|
name: "CannotOptimizeSvg",
|
|
199
199
|
title: "Cannot optimize SVG",
|
|
200
|
-
message: (path) => `An error occurred while optimizing SVG file "${path}" with
|
|
201
|
-
hint: "Review the included
|
|
200
|
+
message: (path, name) => `An error occurred while optimizing SVG file "${path}" with the "${name}" optimizer.`,
|
|
201
|
+
hint: "Review the included error message provided for guidance."
|
|
202
202
|
};
|
|
203
203
|
const PrerenderDynamicEndpointPathCollide = {
|
|
204
204
|
name: "PrerenderDynamicEndpointPathCollide",
|
|
@@ -496,11 +496,31 @@ const FontFamilyNotFound = {
|
|
|
496
496
|
message: (family) => `No data was found for the \`"${family}"\` family passed to the \`<Font>\` component.`,
|
|
497
497
|
hint: "This is often caused by a typo. Check that the `<Font />` component is using a `cssVariable` specified in your config."
|
|
498
498
|
};
|
|
499
|
+
const FontFileUrlNotFound = {
|
|
500
|
+
name: "FontFileUrlNotFound",
|
|
501
|
+
title: "Font file URL not found",
|
|
502
|
+
message: (url) => `The \`"${url}"\` URL passed to the \`experimental_getFontFileURL()\` function is invalid.`,
|
|
503
|
+
hint: "Make sure you pass a valid URL, obtained via the `fontData` object."
|
|
504
|
+
};
|
|
505
|
+
const MissingGetFontFileRequestUrl = {
|
|
506
|
+
name: "MissingGetFontFileRequestUrl",
|
|
507
|
+
title: "`experimental_getFontFileURL()` requires the request URL with on-demand rendering.",
|
|
508
|
+
hint: "Pass the request URL as the 2nd argument, for example `Astro.url`."
|
|
509
|
+
};
|
|
499
510
|
const UnavailableAstroGlobal = {
|
|
500
511
|
name: "UnavailableAstroGlobal",
|
|
501
512
|
title: "Unavailable Astro global in getStaticPaths()",
|
|
502
513
|
message: (name) => `The Astro global is not available in this scope. Please remove "Astro.${name}" from your getStaticPaths() function.`
|
|
503
514
|
};
|
|
515
|
+
const UnableToLoadLogger = {
|
|
516
|
+
name: "UnableToLoadLogger",
|
|
517
|
+
title: "Unable to load the logger.",
|
|
518
|
+
message: (path) => `Couldn't load the logger at given path "${path}".`
|
|
519
|
+
};
|
|
520
|
+
const LoggerConfigurationNotSerializable = {
|
|
521
|
+
name: "LoggerConfigurationNotSerializable",
|
|
522
|
+
title: "The configuration of the logger is not serializable"
|
|
523
|
+
};
|
|
504
524
|
const UnknownCSSError = {
|
|
505
525
|
name: "UnknownCSSError",
|
|
506
526
|
title: "Unknown CSS Error."
|
|
@@ -820,6 +840,7 @@ export {
|
|
|
820
840
|
FileGlobNotSupported,
|
|
821
841
|
FileParserNotFound,
|
|
822
842
|
FontFamilyNotFound,
|
|
843
|
+
FontFileUrlNotFound,
|
|
823
844
|
ForbiddenRewrite,
|
|
824
845
|
GenerateContentTypesError,
|
|
825
846
|
GetEntryDeprecationError,
|
|
@@ -850,11 +871,13 @@ export {
|
|
|
850
871
|
LocalImageUsedWrongly,
|
|
851
872
|
LocalsNotAnObject,
|
|
852
873
|
LocalsReassigned,
|
|
874
|
+
LoggerConfigurationNotSerializable,
|
|
853
875
|
MarkdownFrontmatterParseError,
|
|
854
876
|
MdxIntegrationMissingError,
|
|
855
877
|
MiddlewareCantBeLoaded,
|
|
856
878
|
MiddlewareNoDataOrNextCalled,
|
|
857
879
|
MiddlewareNotAResponse,
|
|
880
|
+
MissingGetFontFileRequestUrl,
|
|
858
881
|
MissingImageDimension,
|
|
859
882
|
MissingIndexForInternationalization,
|
|
860
883
|
MissingLocale,
|
|
@@ -887,6 +910,7 @@ export {
|
|
|
887
910
|
SessionStorageInitError,
|
|
888
911
|
SessionStorageSaveError,
|
|
889
912
|
StaticClientAddressNotAvailable,
|
|
913
|
+
UnableToLoadLogger,
|
|
890
914
|
UnavailableAstroGlobal,
|
|
891
915
|
UnhandledRejection,
|
|
892
916
|
UnknownCLIError,
|
|
@@ -24,6 +24,17 @@ const errorMap = (issue) => {
|
|
|
24
24
|
`> ${getTypeOrLiteralMsg(error)}`
|
|
25
25
|
) : `> ${prefix(key, getTypeOrLiteralMsg(error))}`
|
|
26
26
|
);
|
|
27
|
+
if (details.length === 0) {
|
|
28
|
+
if ("discriminator" in issue && issue.discriminator && "options" in issue) {
|
|
29
|
+
const options = issue.options;
|
|
30
|
+
if (Array.isArray(options)) {
|
|
31
|
+
details.push(
|
|
32
|
+
`> Expected \`${issue.discriminator}\` to be ${options.map((o) => `\`${stringify(o)}\``).join(" | ")}`
|
|
33
|
+
);
|
|
34
|
+
details.push("> Received `" + stringify(issue.input) + "`");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
27
38
|
if (details.length === 0) {
|
|
28
39
|
const expectedShapes = [];
|
|
29
40
|
for (const unionErrors of issue.errors) {
|
|
@@ -59,6 +70,22 @@ const errorMap = (issue) => {
|
|
|
59
70
|
return {
|
|
60
71
|
message: messages.concat(details).join("\n")
|
|
61
72
|
};
|
|
73
|
+
} else if (issue.code === "invalid_key") {
|
|
74
|
+
const keyIssues = issue.issues;
|
|
75
|
+
if (Array.isArray(keyIssues) && keyIssues.length > 0) {
|
|
76
|
+
const firstIssue = keyIssues[0];
|
|
77
|
+
const msg = firstIssue.message || "Invalid key in record";
|
|
78
|
+
return { message: prefix(baseErrorPath, msg) };
|
|
79
|
+
}
|
|
80
|
+
return { message: prefix(baseErrorPath, "Invalid key in record") };
|
|
81
|
+
} else if (issue.code === "invalid_element") {
|
|
82
|
+
const elementIssues = issue.issues;
|
|
83
|
+
if (Array.isArray(elementIssues) && elementIssues.length > 0) {
|
|
84
|
+
const firstIssue = elementIssues[0];
|
|
85
|
+
const msg = firstIssue.message || "Invalid element";
|
|
86
|
+
return { message: prefix(baseErrorPath, msg) };
|
|
87
|
+
}
|
|
88
|
+
return { message: prefix(baseErrorPath, "Invalid element") };
|
|
62
89
|
} else if (issue.code === "invalid_type") {
|
|
63
90
|
return {
|
|
64
91
|
message: prefix(
|
|
File without changes
|
|
@@ -1,12 +1,19 @@
|
|
|
1
|
-
export interface AstroLoggerDestination<T> {
|
|
2
|
-
|
|
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
|
-
|
|
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<
|
|
34
|
+
destination: AstroLoggerDestination<AstroLoggerMessage>;
|
|
27
35
|
level: AstroLoggerLevel;
|
|
28
|
-
|
|
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
|
|
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 }:
|
|
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;
|
package/dist/core/logger/core.js
CHANGED
|
@@ -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,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
|
+
};
|