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.
- package/astro.js +2 -2
- package/components/ViewTransitions.astro +65 -12
- package/dist/@types/astro.d.ts +68 -7
- package/dist/@types/astro.js +1 -0
- package/dist/assets/generate.js +7 -3
- package/dist/assets/image-endpoint.d.ts +1 -1
- package/dist/assets/image-endpoint.js +3 -3
- package/dist/assets/internal.js +1 -2
- package/dist/assets/services/noop.d.ts +3 -0
- package/dist/assets/services/noop.js +17 -0
- package/dist/assets/services/vendor/squoosh/image_data.js +3 -0
- package/dist/assets/services/vendor/squoosh/impl.js +2 -3
- package/dist/assets/services/vendor/squoosh/utils/workerPool.js +4 -0
- package/dist/assets/vendor/image-size/types/tiff.js +1 -1
- package/dist/assets/vendor/queue/queue.d.ts +3 -3
- package/dist/assets/vite-plugin-assets.d.ts +1 -1
- package/dist/assets/vite-plugin-assets.js +1 -23
- package/dist/cli/add/index.js +6 -9
- package/dist/cli/build/index.js +1 -1
- package/dist/cli/check/index.d.ts +2 -78
- package/dist/cli/check/index.js +23 -275
- package/dist/cli/dev/index.js +1 -1
- package/dist/cli/index.js +7 -13
- package/dist/cli/info/index.js +3 -4
- package/dist/cli/install-package.d.ts +7 -0
- package/dist/cli/install-package.js +102 -0
- package/dist/cli/preview/index.js +1 -1
- package/dist/cli/sync/index.js +1 -1
- package/dist/content/runtime-assets.js +1 -2
- package/dist/content/runtime.js +3 -5
- package/dist/content/server-listeners.js +1 -2
- package/dist/content/types-generator.js +8 -8
- package/dist/content/utils.js +3 -4
- package/dist/content/vite-plugin-content-assets.js +4 -6
- package/dist/content/vite-plugin-content-imports.js +1 -1
- package/dist/content/vite-plugin-content-virtual-mod.js +5 -6
- package/dist/core/app/index.js +5 -3
- package/dist/core/app/node.d.ts +1 -1
- package/dist/core/app/node.js +7 -2
- package/dist/core/build/css-asset-name.js +2 -4
- package/dist/core/build/generate.js +10 -17
- package/dist/core/build/graph.js +3 -4
- package/dist/core/build/index.js +8 -1
- package/dist/core/build/internal.js +2 -2
- package/dist/core/build/plugin.js +2 -4
- package/dist/core/build/plugins/plugin-analyzer.js +6 -9
- package/dist/core/build/plugins/plugin-component-entry.js +2 -4
- package/dist/core/build/plugins/plugin-css.js +6 -9
- package/dist/core/build/plugins/plugin-hoisted-scripts.js +2 -3
- package/dist/core/build/plugins/plugin-internals.js +1 -2
- package/dist/core/build/plugins/plugin-pages.js +5 -1
- package/dist/core/build/plugins/plugin-ssr.js +12 -8
- package/dist/core/build/static-build.js +8 -12
- package/dist/core/client-directive/build.js +1 -2
- package/dist/core/compile/compile.js +2 -1
- package/dist/core/compile/style.js +2 -3
- package/dist/core/config/schema.d.ts +8 -0
- package/dist/core/config/schema.js +11 -3
- package/dist/core/config/settings.js +3 -3
- package/dist/core/config/timer.js +5 -6
- package/dist/core/constants.js +1 -1
- package/dist/core/cookies/cookies.d.ts +5 -5
- package/dist/core/cookies/cookies.js +9 -9
- package/dist/core/create-vite.js +6 -28
- package/dist/core/dev/container.d.ts +0 -1
- package/dist/core/dev/container.js +0 -5
- package/dist/core/dev/dev.js +2 -3
- package/dist/core/dev/index.d.ts +1 -1
- package/dist/core/dev/index.js +1 -2
- package/dist/core/dev/restart.d.ts +1 -4
- package/dist/core/dev/restart.js +15 -19
- package/dist/core/endpoint/dev/index.js +1 -1
- package/dist/core/endpoint/index.js +3 -4
- package/dist/core/errors/dev/utils.js +12 -16
- package/dist/core/errors/dev/vite.js +11 -13
- package/dist/core/errors/errors-data.d.ts +21 -0
- package/dist/core/errors/errors-data.js +21 -0
- package/dist/core/errors/errors.js +12 -17
- package/dist/core/errors/overlay.js +7 -8
- package/dist/core/errors/utils.js +1 -1
- package/dist/core/fs/index.js +1 -1
- package/dist/core/logger/console.js +1 -1
- package/dist/core/logger/core.d.ts +26 -6
- package/dist/core/logger/core.js +54 -8
- package/dist/core/logger/node.d.ts +4 -4
- package/dist/core/logger/node.js +6 -6
- package/dist/core/messages.js +4 -5
- package/dist/core/module-loader/vite.js +2 -2
- package/dist/core/polyfill.js +12 -4
- package/dist/core/redirects/helpers.js +3 -3
- package/dist/core/render/core.js +1 -4
- package/dist/core/render/params-and-props.js +2 -3
- package/dist/core/render/result.js +1 -2
- package/dist/core/render/route-cache.d.ts +1 -2
- package/dist/core/render/route-cache.js +6 -11
- package/dist/core/routing/manifest/create.js +2 -6
- package/dist/core/routing/params.js +1 -1
- package/dist/core/routing/validation.js +7 -8
- package/dist/core/sync/index.js +1 -1
- package/dist/core/util.js +1 -1
- package/dist/events/error.js +1 -1
- package/dist/events/session.js +12 -13
- package/dist/integrations/astroFeaturesValidation.d.ts +14 -0
- package/dist/integrations/astroFeaturesValidation.js +109 -0
- package/dist/integrations/index.d.ts +3 -1
- package/dist/integrations/index.js +96 -31
- package/dist/jsx/babel.js +1 -2
- package/dist/prerender/metadata.js +1 -2
- package/dist/runtime/client/hmr.js +1 -2
- package/dist/runtime/server/astro-component.js +1 -2
- package/dist/runtime/server/astro-island.js +53 -55
- package/dist/runtime/server/astro-island.prebuilt.d.ts +1 -1
- package/dist/runtime/server/astro-island.prebuilt.js +1 -1
- package/dist/runtime/server/endpoint.d.ts +2 -1
- package/dist/runtime/server/endpoint.js +21 -27
- package/dist/runtime/server/hydration.js +9 -0
- package/dist/runtime/server/jsx.js +3 -2
- package/dist/runtime/server/render/astro/instance.js +6 -3
- package/dist/runtime/server/render/astro/render-template.js +4 -3
- package/dist/runtime/server/render/astro/render.js +3 -3
- package/dist/runtime/server/render/common.js +1 -1
- package/dist/runtime/server/render/component.js +11 -13
- package/dist/runtime/server/render/dom.js +1 -1
- package/dist/runtime/server/render/page.js +2 -3
- package/dist/runtime/server/render/slot.js +2 -1
- package/dist/runtime/server/render/util.js +1 -2
- package/dist/runtime/server/transition.d.ts +1 -0
- package/dist/runtime/server/transition.js +1 -0
- package/dist/transitions/vite-plugin-transitions.js +1 -0
- package/dist/vite-plugin-astro/compile.js +2 -3
- package/dist/vite-plugin-astro/hmr.js +3 -5
- package/dist/vite-plugin-astro/index.js +1 -1
- package/dist/vite-plugin-astro/metadata.js +1 -2
- package/dist/vite-plugin-astro-postprocess/index.js +1 -1
- package/dist/vite-plugin-astro-server/base.js +1 -2
- package/dist/vite-plugin-astro-server/controller.js +2 -3
- package/dist/vite-plugin-astro-server/css.js +1 -1
- package/dist/vite-plugin-astro-server/request.js +1 -1
- package/dist/vite-plugin-astro-server/route.js +1 -2
- package/dist/vite-plugin-astro-server/scripts.js +2 -3
- package/dist/vite-plugin-astro-server/vite.js +1 -1
- package/dist/vite-plugin-config-alias/index.js +1 -1
- package/dist/vite-plugin-env/index.js +2 -2
- package/dist/vite-plugin-head/index.js +4 -6
- package/dist/vite-plugin-html/index.js +1 -2
- package/dist/vite-plugin-html/transform/index.js +1 -1
- package/dist/vite-plugin-html/transform/slots.js +5 -6
- package/dist/vite-plugin-html/transform/utils.js +1 -2
- package/dist/vite-plugin-jsx/import-source.js +1 -2
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-jsx/tag.js +4 -6
- package/dist/vite-plugin-markdown/index.js +1 -2
- package/dist/vite-plugin-scanner/index.js +2 -1
- package/dist/vite-plugin-scanner/scan.js +1 -1
- package/dist/vite-plugin-scripts/index.js +1 -1
- package/dist/vite-plugin-scripts/page-ssr.js +2 -2
- package/package.json +13 -22
- package/tsconfigs/base.json +8 -6
- package/tsconfigs/strict.json +2 -3
- package/dist/cli/check/print.d.ts +0 -2
- package/dist/cli/check/print.js +0 -95
|
@@ -10,7 +10,7 @@ async function call(options) {
|
|
|
10
10
|
env,
|
|
11
11
|
mod: preload
|
|
12
12
|
});
|
|
13
|
-
return await callEndpoint(endpointHandler, env, ctx, middleware
|
|
13
|
+
return await callEndpoint(endpointHandler, env, ctx, middleware?.onRequest);
|
|
14
14
|
}
|
|
15
15
|
export {
|
|
16
16
|
call
|
|
@@ -59,7 +59,6 @@ function createAPIContext({
|
|
|
59
59
|
return context;
|
|
60
60
|
}
|
|
61
61
|
async function callEndpoint(mod, env, ctx, onRequest) {
|
|
62
|
-
var _a;
|
|
63
62
|
const context = createAPIContext({
|
|
64
63
|
request: ctx.request,
|
|
65
64
|
params: ctx.params,
|
|
@@ -74,11 +73,11 @@ async function callEndpoint(mod, env, ctx, onRequest) {
|
|
|
74
73
|
onRequest,
|
|
75
74
|
context,
|
|
76
75
|
async () => {
|
|
77
|
-
return await renderEndpoint(mod, context, env.ssr);
|
|
76
|
+
return await renderEndpoint(mod, context, env.ssr, env.logging);
|
|
78
77
|
}
|
|
79
78
|
);
|
|
80
79
|
} else {
|
|
81
|
-
response = await renderEndpoint(mod, context, env.ssr);
|
|
80
|
+
response = await renderEndpoint(mod, context, env.ssr, env.logging);
|
|
82
81
|
}
|
|
83
82
|
if (response instanceof Response) {
|
|
84
83
|
attachToResponse(response, context.cookies);
|
|
@@ -87,7 +86,7 @@ async function callEndpoint(mod, env, ctx, onRequest) {
|
|
|
87
86
|
response
|
|
88
87
|
};
|
|
89
88
|
}
|
|
90
|
-
if (env.ssr && !
|
|
89
|
+
if (env.ssr && !ctx.route?.prerender) {
|
|
91
90
|
if (response.hasOwnProperty("headers")) {
|
|
92
91
|
warn(
|
|
93
92
|
env.logging,
|
|
@@ -12,7 +12,6 @@ import { normalizeLF } from "../utils.js";
|
|
|
12
12
|
function collectErrorMetadata(e, rootFolder) {
|
|
13
13
|
const err = AggregateError.is(e) || Array.isArray(e.errors) ? e.errors : [e];
|
|
14
14
|
err.forEach((error) => {
|
|
15
|
-
var _a, _b;
|
|
16
15
|
if (e.stack) {
|
|
17
16
|
const stackInfo = collectInfoFromStacktrace(e);
|
|
18
17
|
error.stack = stackInfo.stack;
|
|
@@ -20,9 +19,9 @@ function collectErrorMetadata(e, rootFolder) {
|
|
|
20
19
|
error.plugin = stackInfo.plugin;
|
|
21
20
|
error.pluginCode = stackInfo.pluginCode;
|
|
22
21
|
}
|
|
23
|
-
const normalizedFile = normalizePath(
|
|
24
|
-
const normalizedRootFolder = removeLeadingForwardSlashWindows(
|
|
25
|
-
if (
|
|
22
|
+
const normalizedFile = normalizePath(error.loc?.file || "");
|
|
23
|
+
const normalizedRootFolder = removeLeadingForwardSlashWindows(rootFolder?.pathname || "");
|
|
24
|
+
if (error.loc?.file && rootFolder && (!normalizedFile?.startsWith(normalizedRootFolder) || !isAbsolute(normalizedFile))) {
|
|
26
25
|
error.loc.file = join(fileURLToPath(rootFolder), error.loc.file);
|
|
27
26
|
}
|
|
28
27
|
if (error.loc && (!error.frame || !error.fullCode)) {
|
|
@@ -42,22 +41,21 @@ function collectErrorMetadata(e, rootFolder) {
|
|
|
42
41
|
});
|
|
43
42
|
if (!AggregateError.is(e) && Array.isArray(e.errors)) {
|
|
44
43
|
e.errors.forEach((buildError, i) => {
|
|
45
|
-
var _a;
|
|
46
44
|
const { location, pluginName, text } = buildError;
|
|
47
45
|
if (text) {
|
|
48
46
|
err[i].message = text;
|
|
49
47
|
}
|
|
50
48
|
if (location) {
|
|
51
49
|
err[i].loc = { file: location.file, line: location.line, column: location.column };
|
|
52
|
-
err[i].id = err[0].id ||
|
|
50
|
+
err[i].id = err[0].id || location?.file;
|
|
53
51
|
}
|
|
54
52
|
if (err[i].frame) {
|
|
55
|
-
const errorLines =
|
|
53
|
+
const errorLines = err[i].frame?.trim().split("\n");
|
|
56
54
|
if (errorLines) {
|
|
57
|
-
err[i].frame = !/^\d/.test(errorLines[0]) ? errorLines
|
|
55
|
+
err[i].frame = !/^\d/.test(errorLines[0]) ? errorLines?.slice(1).join("\n") : err[i].frame;
|
|
58
56
|
}
|
|
59
57
|
}
|
|
60
|
-
const possibleFilePath =
|
|
58
|
+
const possibleFilePath = location?.file ?? err[i].id;
|
|
61
59
|
if (possibleFilePath && err[i].loc && (!err[i].frame || !err[i].fullCode)) {
|
|
62
60
|
try {
|
|
63
61
|
const fileContents = fs.readFileSync(possibleFilePath, "utf8");
|
|
@@ -78,14 +76,13 @@ function collectErrorMetadata(e, rootFolder) {
|
|
|
78
76
|
return err[0];
|
|
79
77
|
}
|
|
80
78
|
function generateHint(err) {
|
|
81
|
-
var _a, _b;
|
|
82
79
|
const commonBrowserAPIs = ["document", "window"];
|
|
83
80
|
if (/Unknown file extension \"\.(jsx|vue|svelte|astro|css)\" for /.test(err.message)) {
|
|
84
81
|
return "You likely need to add this package to `vite.ssr.noExternal` in your astro config file.";
|
|
85
82
|
} else if (commonBrowserAPIs.some((api) => err.toString().includes(api))) {
|
|
86
83
|
const hint = `Browser APIs are not available on the server.
|
|
87
84
|
|
|
88
|
-
${
|
|
85
|
+
${err.loc?.file?.endsWith(".astro") ? "Move your code to a <script> tag outside of the frontmatter, so the code runs on the client." : "If the code is in a framework component, try to access these objects after rendering using lifecycle methods or use a `client:only` directive to make the component exclusively run on the client."}
|
|
89
86
|
|
|
90
87
|
See https://docs.astro.build/en/guides/troubleshooting/#document-or-window-is-not-defined for more information.
|
|
91
88
|
`;
|
|
@@ -94,7 +91,6 @@ See https://docs.astro.build/en/guides/troubleshooting/#document-or-window-is-no
|
|
|
94
91
|
return err.hint;
|
|
95
92
|
}
|
|
96
93
|
function collectInfoFromStacktrace(error) {
|
|
97
|
-
var _a, _b, _c;
|
|
98
94
|
let stackInfo = {
|
|
99
95
|
stack: error.stack,
|
|
100
96
|
plugin: error.plugin,
|
|
@@ -104,10 +100,10 @@ function collectInfoFromStacktrace(error) {
|
|
|
104
100
|
stackInfo.stack = normalizeLF(error.stack);
|
|
105
101
|
const stackText = stripAnsi(error.stack);
|
|
106
102
|
if (!stackInfo.loc || !stackInfo.loc.column && !stackInfo.loc.line) {
|
|
107
|
-
const possibleFilePath =
|
|
103
|
+
const possibleFilePath = error.loc?.file || error.pluginCode || error.id || // TODO: this could be better, `src` might be something else
|
|
108
104
|
stackText.split("\n").find((ln) => ln.includes("src") || ln.includes("node_modules"));
|
|
109
|
-
const source = possibleFilePath
|
|
110
|
-
let file = source
|
|
105
|
+
const source = possibleFilePath?.replace(/^[^(]+\(([^)]+).*$/, "$1").replace(/^\s+at\s+/, "");
|
|
106
|
+
let file = source?.replace(/(:[0-9]+)/g, "");
|
|
111
107
|
const location = /:([0-9]+):([0-9]+)/g.exec(source) ?? [];
|
|
112
108
|
const line = location[1];
|
|
113
109
|
const column = location[2];
|
|
@@ -124,7 +120,7 @@ function collectInfoFromStacktrace(error) {
|
|
|
124
120
|
}
|
|
125
121
|
}
|
|
126
122
|
if (!stackInfo.plugin) {
|
|
127
|
-
stackInfo.plugin =
|
|
123
|
+
stackInfo.plugin = /withastro\/astro\/packages\/integrations\/([\w-]+)/gim.exec(stackText)?.at(1) || /(@astrojs\/[\w-]+)\/(server|client|index)/gim.exec(stackText)?.at(1) || void 0;
|
|
128
124
|
}
|
|
129
125
|
stackInfo.stack = cleanErrorStack(error.stack);
|
|
130
126
|
return stackInfo;
|
|
@@ -11,7 +11,6 @@ function enhanceViteSSRError({
|
|
|
11
11
|
loader,
|
|
12
12
|
renderers
|
|
13
13
|
}) {
|
|
14
|
-
var _a, _b, _c, _d, _e;
|
|
15
14
|
let safeError = createSafeError(error);
|
|
16
15
|
if (loader) {
|
|
17
16
|
try {
|
|
@@ -24,14 +23,14 @@ function enhanceViteSSRError({
|
|
|
24
23
|
const content = fs.readFileSync(path).toString();
|
|
25
24
|
const lns = content.split("\n");
|
|
26
25
|
let importName;
|
|
27
|
-
if (importName =
|
|
26
|
+
if (importName = safeError.message.match(/Failed to load url (.*?) \(resolved id:/)?.[1]) {
|
|
28
27
|
safeError.title = AstroErrorData.FailedToLoadModuleSSR.title;
|
|
29
28
|
safeError.name = "FailedToLoadModuleSSR";
|
|
30
29
|
safeError.message = AstroErrorData.FailedToLoadModuleSSR.message(importName);
|
|
31
30
|
safeError.hint = AstroErrorData.FailedToLoadModuleSSR.hint;
|
|
32
31
|
const line = lns.findIndex((ln) => ln.includes(importName));
|
|
33
32
|
if (line !== -1) {
|
|
34
|
-
const column =
|
|
33
|
+
const column = lns[line]?.indexOf(importName);
|
|
35
34
|
safeError.loc = {
|
|
36
35
|
file: path,
|
|
37
36
|
line: line + 1,
|
|
@@ -39,8 +38,8 @@ function enhanceViteSSRError({
|
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
40
|
}
|
|
42
|
-
const fileId = safeError.id ??
|
|
43
|
-
if (!
|
|
41
|
+
const fileId = safeError.id ?? safeError.loc?.file;
|
|
42
|
+
if (!renderers?.find((r) => r.name === "@astrojs/mdx") && safeError.message.match(/Syntax error/) && fileId?.match(/\.mdx$/)) {
|
|
44
43
|
safeError = new AstroError({
|
|
45
44
|
...AstroErrorData.MdxIntegrationMissingError,
|
|
46
45
|
message: AstroErrorData.MdxIntegrationMissingError.message(JSON.stringify(fileId)),
|
|
@@ -49,7 +48,7 @@ function enhanceViteSSRError({
|
|
|
49
48
|
});
|
|
50
49
|
}
|
|
51
50
|
if (/Invalid glob/.test(safeError.message)) {
|
|
52
|
-
const globPattern =
|
|
51
|
+
const globPattern = safeError.message.match(/glob: "(.+)" \(/)?.[1];
|
|
53
52
|
if (globPattern) {
|
|
54
53
|
safeError.message = AstroErrorData.InvalidGlob.message(globPattern);
|
|
55
54
|
safeError.name = "InvalidGlob";
|
|
@@ -57,7 +56,7 @@ function enhanceViteSSRError({
|
|
|
57
56
|
safeError.title = AstroErrorData.InvalidGlob.title;
|
|
58
57
|
const line = lns.findIndex((ln) => ln.includes(globPattern));
|
|
59
58
|
if (line !== -1) {
|
|
60
|
-
const column =
|
|
59
|
+
const column = lns[line]?.indexOf(globPattern);
|
|
61
60
|
safeError.loc = {
|
|
62
61
|
file: path,
|
|
63
62
|
line: line + 1,
|
|
@@ -72,7 +71,6 @@ function enhanceViteSSRError({
|
|
|
72
71
|
const ALTERNATIVE_JS_EXTS = ["cjs", "mjs"];
|
|
73
72
|
const ALTERNATIVE_MD_EXTS = ["mdoc"];
|
|
74
73
|
async function getViteErrorPayload(err) {
|
|
75
|
-
var _a, _b, _c, _d, _e, _f;
|
|
76
74
|
let plugin = err.plugin;
|
|
77
75
|
if (!plugin && err.hint) {
|
|
78
76
|
plugin = "astro";
|
|
@@ -82,7 +80,7 @@ async function getViteErrorPayload(err) {
|
|
|
82
80
|
const hasDocs = err.name in AstroErrorData;
|
|
83
81
|
const docslink = hasDocs ? `https://docs.astro.build/en/reference/errors/${getKebabErrorName(err.name)}/` : void 0;
|
|
84
82
|
const highlighter = await getHighlighter({ theme: "css-variables" });
|
|
85
|
-
let highlighterLang =
|
|
83
|
+
let highlighterLang = err.loc?.file?.split(".").pop();
|
|
86
84
|
if (ALTERNATIVE_JS_EXTS.includes(highlighterLang ?? "")) {
|
|
87
85
|
highlighterLang = "js";
|
|
88
86
|
}
|
|
@@ -91,7 +89,7 @@ async function getViteErrorPayload(err) {
|
|
|
91
89
|
}
|
|
92
90
|
const highlightedCode = err.fullCode ? highlighter.codeToHtml(err.fullCode, {
|
|
93
91
|
lang: highlighterLang,
|
|
94
|
-
lineOptions:
|
|
92
|
+
lineOptions: err.loc?.line ? [{ line: err.loc.line, classes: ["error-line"] }] : void 0
|
|
95
93
|
}) : void 0;
|
|
96
94
|
return {
|
|
97
95
|
type: "error",
|
|
@@ -105,9 +103,9 @@ async function getViteErrorPayload(err) {
|
|
|
105
103
|
highlightedCode,
|
|
106
104
|
docslink,
|
|
107
105
|
loc: {
|
|
108
|
-
file:
|
|
109
|
-
line:
|
|
110
|
-
column:
|
|
106
|
+
file: err.loc?.file,
|
|
107
|
+
line: err.loc?.line,
|
|
108
|
+
column: err.loc?.column
|
|
111
109
|
},
|
|
112
110
|
plugin,
|
|
113
111
|
stack: err.stack,
|
|
@@ -191,6 +191,27 @@ export declare const AstroErrorData: {
|
|
|
191
191
|
readonly message: (paramType: any) => string;
|
|
192
192
|
readonly hint: "See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.";
|
|
193
193
|
};
|
|
194
|
+
/**
|
|
195
|
+
* @docs
|
|
196
|
+
* @see
|
|
197
|
+
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
|
|
198
|
+
* @description
|
|
199
|
+
* `getStaticPaths`'s return value must be an array of objects. In most cases, this error happens because an array of array was returned. Using [`.flatMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) or a [`.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) call may be useful.
|
|
200
|
+
*
|
|
201
|
+
* ```ts title="pages/blog/[id].astro"
|
|
202
|
+
* export async function getStaticPaths() {
|
|
203
|
+
* return [ // <-- Array
|
|
204
|
+
* { params: { slug: "blog" } }, // <-- Object
|
|
205
|
+
* { params: { slug: "about" } }
|
|
206
|
+
* ];
|
|
207
|
+
*}
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
readonly InvalidGetStaticPathsEntry: {
|
|
211
|
+
readonly title: "Invalid entry inside getStaticPath's return value";
|
|
212
|
+
readonly message: (entryType: any) => string;
|
|
213
|
+
readonly hint: "If you're using a `.map` call, you might be looking for `.flatMap()` instead. See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths.";
|
|
214
|
+
};
|
|
194
215
|
/**
|
|
195
216
|
* @docs
|
|
196
217
|
* @see
|
|
@@ -191,6 +191,27 @@ See https://docs.astro.build/en/core-concepts/framework-components/ for more inf
|
|
|
191
191
|
message: (paramType) => `Invalid params given to \`getStaticPaths\` path. Expected an \`object\`, got \`${paramType}\``,
|
|
192
192
|
hint: "See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths."
|
|
193
193
|
},
|
|
194
|
+
/**
|
|
195
|
+
* @docs
|
|
196
|
+
* @see
|
|
197
|
+
* - [`getStaticPaths()`](https://docs.astro.build/en/reference/api-reference/#getstaticpaths)
|
|
198
|
+
* @description
|
|
199
|
+
* `getStaticPaths`'s return value must be an array of objects. In most cases, this error happens because an array of array was returned. Using [`.flatMap()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap) or a [`.flat()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flat) call may be useful.
|
|
200
|
+
*
|
|
201
|
+
* ```ts title="pages/blog/[id].astro"
|
|
202
|
+
* export async function getStaticPaths() {
|
|
203
|
+
* return [ // <-- Array
|
|
204
|
+
* { params: { slug: "blog" } }, // <-- Object
|
|
205
|
+
* { params: { slug: "about" } }
|
|
206
|
+
* ];
|
|
207
|
+
*}
|
|
208
|
+
* ```
|
|
209
|
+
*/
|
|
210
|
+
InvalidGetStaticPathsEntry: {
|
|
211
|
+
title: "Invalid entry inside getStaticPath's return value",
|
|
212
|
+
message: (entryType) => `Invalid entry returned by getStaticPaths. Expected an object, got \`${entryType}\``,
|
|
213
|
+
hint: "If you're using a `.map` call, you might be looking for `.flatMap()` instead. See https://docs.astro.build/en/reference/api-reference/#getstaticpaths for more information on getStaticPaths."
|
|
214
|
+
},
|
|
194
215
|
/**
|
|
195
216
|
* @docs
|
|
196
217
|
* @see
|
|
@@ -4,16 +4,19 @@ function isAstroError(e) {
|
|
|
4
4
|
return e instanceof Error && e.type === "AstroError";
|
|
5
5
|
}
|
|
6
6
|
class AstroError extends Error {
|
|
7
|
+
loc;
|
|
8
|
+
title;
|
|
9
|
+
hint;
|
|
10
|
+
frame;
|
|
11
|
+
type = "AstroError";
|
|
7
12
|
constructor(props, ...params) {
|
|
8
|
-
var _a;
|
|
9
13
|
super(...params);
|
|
10
|
-
this.type = "AstroError";
|
|
11
14
|
const { name, title, message, stack, location, hint, frame } = props;
|
|
12
15
|
this.title = title;
|
|
13
16
|
if (name && name !== "Error") {
|
|
14
17
|
this.name = name;
|
|
15
18
|
} else if (this.title) {
|
|
16
|
-
const errorData =
|
|
19
|
+
const errorData = getErrorDataByTitle(this.title)?.name;
|
|
17
20
|
if (errorData) {
|
|
18
21
|
this.name = errorData;
|
|
19
22
|
}
|
|
@@ -45,9 +48,9 @@ class AstroError extends Error {
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
class CompilerError extends AstroError {
|
|
51
|
+
type = "CompilerError";
|
|
48
52
|
constructor(props, ...params) {
|
|
49
53
|
super(props, ...params);
|
|
50
|
-
this.type = "CompilerError";
|
|
51
54
|
this.name = "CompilerError";
|
|
52
55
|
}
|
|
53
56
|
static is(err) {
|
|
@@ -55,38 +58,30 @@ class CompilerError extends AstroError {
|
|
|
55
58
|
}
|
|
56
59
|
}
|
|
57
60
|
class CSSError extends AstroError {
|
|
58
|
-
|
|
59
|
-
super(...arguments);
|
|
60
|
-
this.type = "CSSError";
|
|
61
|
-
}
|
|
61
|
+
type = "CSSError";
|
|
62
62
|
static is(err) {
|
|
63
63
|
return err.type === "CSSError";
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
class MarkdownError extends AstroError {
|
|
67
|
-
|
|
68
|
-
super(...arguments);
|
|
69
|
-
this.type = "MarkdownError";
|
|
70
|
-
}
|
|
67
|
+
type = "MarkdownError";
|
|
71
68
|
static is(err) {
|
|
72
69
|
return err.type === "MarkdownError";
|
|
73
70
|
}
|
|
74
71
|
}
|
|
75
72
|
class InternalError extends AstroError {
|
|
76
|
-
|
|
77
|
-
super(...arguments);
|
|
78
|
-
this.type = "InternalError";
|
|
79
|
-
}
|
|
73
|
+
type = "InternalError";
|
|
80
74
|
static is(err) {
|
|
81
75
|
return err.type === "InternalError";
|
|
82
76
|
}
|
|
83
77
|
}
|
|
84
78
|
class AggregateError extends AstroError {
|
|
79
|
+
type = "AggregateError";
|
|
80
|
+
errors;
|
|
85
81
|
// Despite being a collection of errors, AggregateError still needs to have a main error attached to it
|
|
86
82
|
// This is because Vite expects every thrown errors handled during HMR to be, well, Error and have a message
|
|
87
83
|
constructor(props, ...params) {
|
|
88
84
|
super(props, ...params);
|
|
89
|
-
this.type = "AggregateError";
|
|
90
85
|
this.errors = props.errors;
|
|
91
86
|
}
|
|
92
87
|
static is(err) {
|
|
@@ -579,6 +579,7 @@ const openNewWindowIcon = (
|
|
|
579
579
|
const { HTMLElement = class {
|
|
580
580
|
} } = globalThis;
|
|
581
581
|
class ErrorOverlay extends HTMLElement {
|
|
582
|
+
root;
|
|
582
583
|
constructor(err) {
|
|
583
584
|
super();
|
|
584
585
|
this.root = this.attachShadow({ mode: "open" });
|
|
@@ -586,15 +587,15 @@ class ErrorOverlay extends HTMLElement {
|
|
|
586
587
|
this.dir = "ltr";
|
|
587
588
|
const themeToggle = this.root.querySelector(".theme-toggle-checkbox");
|
|
588
589
|
if (localStorage.astroErrorOverlayTheme === "dark" || !("astroErrorOverlayTheme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches) {
|
|
589
|
-
this
|
|
590
|
+
this?.classList.add("astro-dark");
|
|
590
591
|
themeToggle.checked = true;
|
|
591
592
|
} else {
|
|
592
|
-
this
|
|
593
|
+
this?.classList.remove("astro-dark");
|
|
593
594
|
themeToggle.checked = false;
|
|
594
595
|
}
|
|
595
|
-
themeToggle
|
|
596
|
+
themeToggle?.addEventListener("click", () => {
|
|
596
597
|
const isDark = localStorage.astroErrorOverlayTheme === "dark";
|
|
597
|
-
this
|
|
598
|
+
this?.classList.toggle("astro-dark", !isDark);
|
|
598
599
|
localStorage.astroErrorOverlayTheme = isDark ? "light" : "dark";
|
|
599
600
|
});
|
|
600
601
|
this.text("#name", err.name);
|
|
@@ -641,10 +642,9 @@ class ErrorOverlay extends HTMLElement {
|
|
|
641
642
|
if (codeContent && err.highlightedCode) {
|
|
642
643
|
codeContent.innerHTML = err.highlightedCode;
|
|
643
644
|
window.requestAnimationFrame(() => {
|
|
644
|
-
var _a;
|
|
645
645
|
const errorLine = this.root.querySelector(".error-line");
|
|
646
646
|
if (errorLine) {
|
|
647
|
-
if (
|
|
647
|
+
if (errorLine.parentElement?.parentElement) {
|
|
648
648
|
errorLine.parentElement.parentElement.scrollTop = errorLine.offsetTop - errorLine.parentElement.parentElement.offsetTop - 8;
|
|
649
649
|
}
|
|
650
650
|
if (err.loc.column) {
|
|
@@ -695,8 +695,7 @@ class ErrorOverlay extends HTMLElement {
|
|
|
695
695
|
return linkContainer;
|
|
696
696
|
}
|
|
697
697
|
close() {
|
|
698
|
-
|
|
699
|
-
(_a = this.parentNode) == null ? void 0 : _a.removeChild(this);
|
|
698
|
+
this.parentNode?.removeChild(this);
|
|
700
699
|
}
|
|
701
700
|
}
|
|
702
701
|
function getOverlayCode() {
|
|
@@ -59,7 +59,7 @@ function formatYAMLException(e) {
|
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
function createSafeError(err) {
|
|
62
|
-
if (err instanceof Error ||
|
|
62
|
+
if (err instanceof Error || err?.name && err.message) {
|
|
63
63
|
return err;
|
|
64
64
|
} else {
|
|
65
65
|
const error = new Error(JSON.stringify(err));
|
package/dist/core/fs/index.js
CHANGED
|
@@ -2,30 +2,50 @@ interface LogWritable<T> {
|
|
|
2
2
|
write: (chunk: T) => boolean;
|
|
3
3
|
}
|
|
4
4
|
export type LoggerLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
|
|
5
|
-
export type LoggerEvent = 'info' | 'warn' | 'error';
|
|
6
5
|
export interface LogOptions {
|
|
7
6
|
dest: LogWritable<LogMessage>;
|
|
8
7
|
level: LoggerLevel;
|
|
9
8
|
}
|
|
10
9
|
export declare const dateTimeFormat: Intl.DateTimeFormat;
|
|
11
10
|
export interface LogMessage {
|
|
12
|
-
|
|
11
|
+
label: string | null;
|
|
13
12
|
level: LoggerLevel;
|
|
14
13
|
message: string;
|
|
15
14
|
}
|
|
16
15
|
export declare const levels: Record<LoggerLevel, number>;
|
|
17
16
|
/** Full logging API */
|
|
18
|
-
export declare function log(opts: LogOptions, level: LoggerLevel,
|
|
17
|
+
export declare function log(opts: LogOptions, level: LoggerLevel, label: string | null, message: string): void;
|
|
19
18
|
/** Emit a user-facing message. Useful for UI and other console messages. */
|
|
20
|
-
export declare function info(opts: LogOptions,
|
|
19
|
+
export declare function info(opts: LogOptions, label: string | null, message: string): void;
|
|
21
20
|
/** Emit a warning message. Useful for high-priority messages that aren't necessarily errors. */
|
|
22
|
-
export declare function warn(opts: LogOptions,
|
|
21
|
+
export declare function warn(opts: LogOptions, label: string | null, message: string): void;
|
|
23
22
|
/** Emit a error message, Useful when Astro can't recover from some error. */
|
|
24
|
-
export declare function error(opts: LogOptions,
|
|
23
|
+
export declare function error(opts: LogOptions, label: string | null, message: string): void;
|
|
25
24
|
type LogFn = typeof info | typeof warn | typeof error;
|
|
26
25
|
export declare function table(opts: LogOptions, columns: number[]): (logFn: LogFn, ...input: Array<any>) => void;
|
|
27
26
|
export declare function debug(...args: any[]): void;
|
|
28
27
|
export declare let defaultLogLevel: LoggerLevel;
|
|
29
28
|
/** Print out a timer message for debug() */
|
|
30
29
|
export declare function timerMessage(message: string, startTime?: number): string;
|
|
30
|
+
export declare class Logger {
|
|
31
|
+
options: LogOptions;
|
|
32
|
+
constructor(options: LogOptions);
|
|
33
|
+
info(label: string, message: string): void;
|
|
34
|
+
warn(label: string, message: string): void;
|
|
35
|
+
error(label: string, message: string): void;
|
|
36
|
+
debug(label: string, message: string): void;
|
|
37
|
+
}
|
|
38
|
+
export declare class AstroIntegrationLogger {
|
|
39
|
+
options: LogOptions;
|
|
40
|
+
label: string;
|
|
41
|
+
constructor(logging: LogOptions, label: string);
|
|
42
|
+
/**
|
|
43
|
+
* Creates a new logger instance with a new label, but the same log options.
|
|
44
|
+
*/
|
|
45
|
+
fork(label: string): AstroIntegrationLogger;
|
|
46
|
+
info(message: string): void;
|
|
47
|
+
warn(message: string): void;
|
|
48
|
+
error(message: string): void;
|
|
49
|
+
debug(message: string): void;
|
|
50
|
+
}
|
|
31
51
|
export {};
|
package/dist/core/logger/core.js
CHANGED
|
@@ -12,11 +12,11 @@ const levels = {
|
|
|
12
12
|
error: 50,
|
|
13
13
|
silent: 90
|
|
14
14
|
};
|
|
15
|
-
function log(opts, level,
|
|
15
|
+
function log(opts, level, label, message) {
|
|
16
16
|
const logLevel = opts.level;
|
|
17
17
|
const dest = opts.dest;
|
|
18
18
|
const event = {
|
|
19
|
-
|
|
19
|
+
label,
|
|
20
20
|
level,
|
|
21
21
|
message
|
|
22
22
|
};
|
|
@@ -25,14 +25,14 @@ function log(opts, level, type, message) {
|
|
|
25
25
|
}
|
|
26
26
|
dest.write(event);
|
|
27
27
|
}
|
|
28
|
-
function info(opts,
|
|
29
|
-
return log(opts, "info",
|
|
28
|
+
function info(opts, label, message) {
|
|
29
|
+
return log(opts, "info", label, message);
|
|
30
30
|
}
|
|
31
|
-
function warn(opts,
|
|
32
|
-
return log(opts, "warn",
|
|
31
|
+
function warn(opts, label, message) {
|
|
32
|
+
return log(opts, "warn", label, message);
|
|
33
33
|
}
|
|
34
|
-
function error(opts,
|
|
35
|
-
return log(opts, "error",
|
|
34
|
+
function error(opts, label, message) {
|
|
35
|
+
return log(opts, "error", label, message);
|
|
36
36
|
}
|
|
37
37
|
function table(opts, columns) {
|
|
38
38
|
return function logTable(logFn, ...input) {
|
|
@@ -75,7 +75,53 @@ function timerMessage(message, startTime = Date.now()) {
|
|
|
75
75
|
let timeDisplay = timeDiff < 750 ? `${Math.round(timeDiff)}ms` : `${(timeDiff / 1e3).toFixed(1)}s`;
|
|
76
76
|
return `${message} ${dim(timeDisplay)}`;
|
|
77
77
|
}
|
|
78
|
+
class Logger {
|
|
79
|
+
options;
|
|
80
|
+
constructor(options) {
|
|
81
|
+
this.options = options;
|
|
82
|
+
}
|
|
83
|
+
info(label, message) {
|
|
84
|
+
info(this.options, label, message);
|
|
85
|
+
}
|
|
86
|
+
warn(label, message) {
|
|
87
|
+
warn(this.options, label, message);
|
|
88
|
+
}
|
|
89
|
+
error(label, message) {
|
|
90
|
+
error(this.options, label, message);
|
|
91
|
+
}
|
|
92
|
+
debug(label, message) {
|
|
93
|
+
debug(this.options, label, message);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
class AstroIntegrationLogger {
|
|
97
|
+
options;
|
|
98
|
+
label;
|
|
99
|
+
constructor(logging, label) {
|
|
100
|
+
this.options = logging;
|
|
101
|
+
this.label = label;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Creates a new logger instance with a new label, but the same log options.
|
|
105
|
+
*/
|
|
106
|
+
fork(label) {
|
|
107
|
+
return new AstroIntegrationLogger(this.options, label);
|
|
108
|
+
}
|
|
109
|
+
info(message) {
|
|
110
|
+
info(this.options, this.label, message);
|
|
111
|
+
}
|
|
112
|
+
warn(message) {
|
|
113
|
+
warn(this.options, this.label, message);
|
|
114
|
+
}
|
|
115
|
+
error(message) {
|
|
116
|
+
error(this.options, this.label, message);
|
|
117
|
+
}
|
|
118
|
+
debug(message) {
|
|
119
|
+
debug(this.options, this.label, message);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
78
122
|
export {
|
|
123
|
+
AstroIntegrationLogger,
|
|
124
|
+
Logger,
|
|
79
125
|
dateTimeFormat,
|
|
80
126
|
debug,
|
|
81
127
|
defaultLogLevel,
|
|
@@ -12,7 +12,7 @@ export interface LogOptions {
|
|
|
12
12
|
}
|
|
13
13
|
export declare const nodeLogOptions: Required<LogOptions>;
|
|
14
14
|
export interface LogMessage {
|
|
15
|
-
|
|
15
|
+
label: string | null;
|
|
16
16
|
level: LoggerLevel;
|
|
17
17
|
message: string;
|
|
18
18
|
}
|
|
@@ -25,9 +25,9 @@ export declare const levels: Record<LoggerLevel, number>;
|
|
|
25
25
|
*/
|
|
26
26
|
export declare function debug(type: string, ...messages: Array<any>): any;
|
|
27
27
|
export declare const logger: {
|
|
28
|
-
info: (
|
|
29
|
-
warn: (
|
|
30
|
-
error: (
|
|
28
|
+
info: (label: string | null, message: string) => void;
|
|
29
|
+
warn: (label: string | null, message: string) => void;
|
|
30
|
+
error: (label: string | null, message: string) => void;
|
|
31
31
|
};
|
|
32
32
|
export declare function enableVerboseLogging(): void;
|
|
33
33
|
export {};
|
package/dist/core/logger/node.js
CHANGED
|
@@ -15,17 +15,17 @@ const nodeLogDestination = new Writable({
|
|
|
15
15
|
}
|
|
16
16
|
function getPrefix() {
|
|
17
17
|
let prefix = "";
|
|
18
|
-
let
|
|
19
|
-
if (
|
|
18
|
+
let label = event.label;
|
|
19
|
+
if (label) {
|
|
20
20
|
prefix += dim(dateTimeFormat.format(/* @__PURE__ */ new Date()) + " ");
|
|
21
21
|
if (event.level === "info") {
|
|
22
|
-
|
|
22
|
+
label = bold(cyan(`[${label}]`));
|
|
23
23
|
} else if (event.level === "warn") {
|
|
24
|
-
|
|
24
|
+
label = bold(yellow(`[${label}]`));
|
|
25
25
|
} else if (event.level === "error") {
|
|
26
|
-
|
|
26
|
+
label = bold(red(`[${label}]`));
|
|
27
27
|
}
|
|
28
|
-
prefix += `${
|
|
28
|
+
prefix += `${label} `;
|
|
29
29
|
}
|
|
30
30
|
return reset(prefix);
|
|
31
31
|
}
|