astro 2.8.2 → 2.8.4
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/components/Code.astro +1 -1
- package/dist/@types/astro.d.ts +2 -2
- package/dist/assets/consts.d.ts +4 -4
- package/dist/assets/consts.js +11 -3
- package/dist/assets/index.d.ts +0 -2
- package/dist/assets/index.js +0 -4
- package/dist/assets/services/service.d.ts +1 -1
- package/dist/assets/services/service.js +6 -3
- package/dist/assets/services/sharp.js +3 -0
- package/dist/assets/services/squoosh.js +25 -0
- package/dist/assets/services/vendor/squoosh/avif/avif_node_dec.js +3 -3
- package/dist/assets/services/vendor/squoosh/avif/avif_node_enc.js +3 -3
- package/dist/assets/services/vendor/squoosh/image-pool.js +2 -2
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_dec.js +3 -3
- package/dist/assets/services/vendor/squoosh/mozjpeg/mozjpeg_node_enc.js +3 -3
- package/dist/assets/services/vendor/squoosh/webp/webp_node_dec.js +3 -3
- package/dist/assets/services/vendor/squoosh/webp/webp_node_enc.js +3 -3
- package/dist/assets/types.d.ts +1 -0
- package/dist/assets/utils/emitAsset.d.ts +2 -2
- package/dist/assets/utils/metadata.d.ts +1 -4
- package/dist/assets/utils/transformToPath.js +1 -1
- package/dist/assets/vendor/image-size/index.js +2 -2
- package/dist/assets/vendor/image-size/types/tiff.js +1 -1
- package/dist/cli/add/index.d.ts +1 -2
- package/dist/cli/add/index.js +7 -4
- package/dist/cli/check/index.d.ts +1 -1
- package/dist/cli/check/index.js +2 -2
- package/dist/cli/check/print.js +1 -1
- package/dist/cli/dev/index.js +1 -1
- package/dist/cli/index.js +8 -28
- package/dist/cli/info/index.d.ts +1 -2
- package/dist/cli/info/index.js +2 -2
- package/dist/cli/load-settings.js +1 -1
- package/dist/cli/sync/index.js +1 -1
- package/dist/cli/throw-and-exit.d.ts +2 -0
- package/dist/cli/throw-and-exit.js +21 -0
- package/dist/config/index.js +1 -1
- package/dist/content/runtime-assets.d.ts +1 -1
- package/dist/content/runtime-assets.js +1 -1
- package/dist/content/vite-plugin-content-imports.js +1 -1
- package/dist/core/app/index.d.ts +3 -1
- package/dist/core/app/index.js +33 -47
- package/dist/core/app/node.d.ts +1 -1
- package/dist/core/app/node.js +3 -3
- package/dist/core/build/common.js +2 -2
- package/dist/core/build/css-asset-name.js +2 -2
- package/dist/core/build/generate.d.ts +1 -1
- package/dist/core/build/generate.js +21 -43
- package/dist/core/build/index.js +9 -2
- package/dist/core/build/static-build.js +8 -6
- package/dist/core/compile/compile.js +1 -1
- package/dist/core/compile/style.js +1 -1
- package/dist/core/config/config.d.ts +1 -1
- package/dist/core/config/config.js +16 -22
- package/dist/core/config/merge.js +10 -0
- package/dist/core/config/schema.d.ts +1 -1
- package/dist/core/config/schema.js +1 -6
- package/dist/core/config/settings.js +1 -1
- package/dist/core/config/timer.js +1 -1
- package/dist/core/config/tsconfig.js +2 -2
- package/dist/core/config/vite-load.d.ts +1 -1
- package/dist/core/config/vite-load.js +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.d.ts +1 -1
- package/dist/core/create-vite.js +2 -2
- package/dist/core/dev/container.d.ts +3 -3
- package/dist/core/dev/container.js +1 -1
- package/dist/core/dev/dev.d.ts +2 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/dev/vite.js +2 -2
- package/dist/core/errors/errors-data.d.ts +1 -1
- package/dist/core/errors/errors-data.js +2 -2
- package/dist/core/fs/index.js +4 -4
- package/dist/core/logger/node.d.ts +1 -1
- package/dist/core/logger/node.js +2 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/module-loader/loader.d.ts +1 -1
- package/dist/core/module-loader/loader.js +1 -1
- package/dist/core/module-loader/vite.js +1 -1
- package/dist/core/preview/index.js +1 -1
- package/dist/core/preview/static-preview-server.d.ts +1 -1
- package/dist/core/preview/static-preview-server.js +1 -1
- package/dist/core/preview/vite-plugin-astro-preview.js +2 -2
- package/dist/core/render/core.d.ts +9 -2
- package/dist/core/render/core.js +34 -1
- package/dist/core/render/dev/environment.d.ts +2 -2
- package/dist/core/render/dev/environment.js +6 -7
- package/dist/core/render/dev/index.js +3 -29
- package/dist/core/render/dev/vite.js +1 -1
- package/dist/core/render/index.d.ts +1 -1
- package/dist/core/render/index.js +2 -2
- package/dist/core/request.d.ts +1 -1
- package/dist/core/routing/manifest/create.d.ts +1 -1
- package/dist/core/routing/manifest/create.js +22 -3
- package/dist/core/util.js +3 -3
- package/dist/integrations/index.d.ts +1 -1
- package/dist/vite-plugin-astro-server/base.js +1 -1
- package/dist/vite-plugin-astro-server/plugin.d.ts +10 -2
- package/dist/vite-plugin-astro-server/plugin.js +34 -9
- package/dist/vite-plugin-astro-server/request.d.ts +12 -3
- package/dist/vite-plugin-astro-server/request.js +23 -15
- package/dist/vite-plugin-astro-server/response.d.ts +1 -1
- package/dist/vite-plugin-astro-server/route.d.ts +15 -3
- package/dist/vite-plugin-astro-server/route.js +32 -20
- package/dist/vite-plugin-config-alias/index.js +1 -1
- package/dist/vite-plugin-env/index.js +5 -2
- package/dist/vite-plugin-jsx/index.js +1 -1
- package/dist/vite-plugin-load-fallback/index.d.ts +1 -1
- package/dist/vite-plugin-load-fallback/index.js +2 -2
- package/dist/vite-plugin-utils/index.js +1 -1
- package/package.json +3 -3
package/dist/core/dev/dev.js
CHANGED
|
@@ -54,7 +54,7 @@ async function dev(settings, options) {
|
|
|
54
54
|
isRestart: options.isRestart
|
|
55
55
|
})
|
|
56
56
|
);
|
|
57
|
-
const currentVersion = "2.8.
|
|
57
|
+
const currentVersion = "2.8.4";
|
|
58
58
|
if (currentVersion.includes("-")) {
|
|
59
59
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
60
60
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
2
3
|
import { getHighlighter } from "shiki";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
4
|
import { AstroErrorData } from "../errors-data.js";
|
|
5
5
|
import { AstroError } from "../errors.js";
|
|
6
6
|
import { createSafeError } from "../utils.js";
|
|
@@ -438,7 +438,7 @@ export declare const AstroErrorData: {
|
|
|
438
438
|
readonly UnsupportedImageFormat: {
|
|
439
439
|
readonly title: "Unsupported image format";
|
|
440
440
|
readonly message: (format: string, imagePath: string, supportedFormats: readonly string[]) => string;
|
|
441
|
-
readonly hint: "
|
|
441
|
+
readonly hint: "Using an `img` tag directly instead of the `Image` component might be what you're looking for.";
|
|
442
442
|
};
|
|
443
443
|
/**
|
|
444
444
|
* @docs
|
|
@@ -452,8 +452,8 @@ Expected \`${defaultExpectedValue}\` value but got \`${suffix}\`.`;
|
|
|
452
452
|
title: "Unsupported image format",
|
|
453
453
|
message: (format, imagePath, supportedFormats) => `Received unsupported format \`${format}\` from \`${imagePath}\`. Currently only ${supportedFormats.join(
|
|
454
454
|
", "
|
|
455
|
-
)} are supported
|
|
456
|
-
hint: "
|
|
455
|
+
)} are supported by our image services.`,
|
|
456
|
+
hint: "Using an `img` tag directly instead of the `Image` component might be what you're looking for."
|
|
457
457
|
},
|
|
458
458
|
/**
|
|
459
459
|
* @docs
|
package/dist/core/fs/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { appendForwardSlash } from "../path.js";
|
|
5
5
|
const isWindows = process.platform === "win32";
|
|
6
6
|
function removeDir(_dir) {
|
|
@@ -55,7 +55,7 @@ function emptyDir(_dir, skip) {
|
|
|
55
55
|
* Permission to use, copy, modify, and/or distribute this software for any
|
|
56
56
|
purpose with or without fee is hereby granted, provided that the above
|
|
57
57
|
copyright notice and this permission notice appear in all copies.
|
|
58
|
-
*
|
|
58
|
+
*
|
|
59
59
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
60
60
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
61
61
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
package/dist/core/logger/node.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import debugPackage from "debug";
|
|
2
2
|
import { bold, cyan, dim, red, reset, yellow } from "kleur/colors";
|
|
3
|
-
import * as readline from "readline";
|
|
4
|
-
import { Writable } from "stream";
|
|
3
|
+
import * as readline from "node:readline";
|
|
4
|
+
import { Writable } from "node:stream";
|
|
5
5
|
import stringWidth from "string-width";
|
|
6
6
|
import { dateTimeFormat, error, info, warn } from "./core.js";
|
|
7
7
|
let lastMessage;
|
package/dist/core/messages.js
CHANGED
|
@@ -47,7 +47,7 @@ function serverStart({
|
|
|
47
47
|
base,
|
|
48
48
|
isRestart = false
|
|
49
49
|
}) {
|
|
50
|
-
const version = "2.8.
|
|
50
|
+
const version = "2.8.4";
|
|
51
51
|
const localPrefix = `${dim("\u2503")} Local `;
|
|
52
52
|
const networkPrefix = `${dim("\u2503")} Network `;
|
|
53
53
|
const emptyPrefix = " ".repeat(11);
|
|
@@ -233,7 +233,7 @@ function printHelp({
|
|
|
233
233
|
message.push(
|
|
234
234
|
linebreak(),
|
|
235
235
|
` ${bgGreen(black(` ${commandName} `))} ${green(
|
|
236
|
-
`v${"2.8.
|
|
236
|
+
`v${"2.8.4"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type * as fs from 'fs';
|
|
2
|
+
import type * as fs from 'node:fs';
|
|
3
3
|
import type { TypedEventEmitter } from '../../@types/typed-emitter';
|
|
4
4
|
export type LoaderEvents = {
|
|
5
5
|
'file-add': (msg: [path: string, stats?: fs.Stats | undefined]) => void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cyan } from "kleur/colors";
|
|
2
2
|
import { createRequire } from "module";
|
|
3
|
-
import { pathToFileURL } from "url";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
4
|
import { runHookConfigDone, runHookConfigSetup } from "../../integrations/index.js";
|
|
5
5
|
import { printHelp } from "../messages.js";
|
|
6
6
|
import createStaticPreviewServer from "./static-preview-server.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { fileURLToPath } from "node:url";
|
|
1
2
|
import { performance } from "perf_hooks";
|
|
2
3
|
import enableDestroy from "server-destroy";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
4
4
|
import { preview } from "vite";
|
|
5
5
|
import { error, info } from "../logger/core.js";
|
|
6
6
|
import * as msg from "../messages.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import { fileURLToPath } from "url";
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
3
|
import { notFoundTemplate, subpathNotUsedTemplate } from "../../template/4xx.js";
|
|
4
4
|
import { stripBase } from "./util.js";
|
|
5
5
|
const HAS_FILE_EXTENSION_REGEXP = /^.*\.[^\\]+$/;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AstroCookies, ComponentInstance } from '../../@types/astro';
|
|
1
|
+
import type { AstroCookies, ComponentInstance, MiddlewareHandler } from '../../@types/astro';
|
|
2
2
|
import type { RenderContext } from './context.js';
|
|
3
3
|
import type { Environment } from './environment.js';
|
|
4
4
|
export type RenderPage = {
|
|
@@ -7,4 +7,11 @@ export type RenderPage = {
|
|
|
7
7
|
env: Environment;
|
|
8
8
|
cookies: AstroCookies;
|
|
9
9
|
};
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* It attempts to render a page.
|
|
12
|
+
*
|
|
13
|
+
* ## Errors
|
|
14
|
+
*
|
|
15
|
+
* It throws an error if the page can't be rendered.
|
|
16
|
+
*/
|
|
17
|
+
export declare function tryRenderPage<MiddlewareReturnType = Response>(renderContext: Readonly<RenderContext>, env: Readonly<Environment>, mod: Readonly<ComponentInstance>, onRequest?: MiddlewareHandler<MiddlewareReturnType>): Promise<Response>;
|
package/dist/core/render/core.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { renderPage as runtimeRenderPage } from "../../runtime/server/index.js";
|
|
2
2
|
import { attachToResponse } from "../cookies/index.js";
|
|
3
|
+
import { createAPIContext } from "../endpoint/index.js";
|
|
4
|
+
import { callMiddleware } from "../middleware/callMiddleware.js";
|
|
3
5
|
import { redirectRouteGenerate, redirectRouteStatus, routeIsRedirect } from "../redirects/index.js";
|
|
4
6
|
import { createResult } from "./result.js";
|
|
5
7
|
async function renderPage({ mod, renderContext, env, cookies }) {
|
|
@@ -51,6 +53,37 @@ async function renderPage({ mod, renderContext, env, cookies }) {
|
|
|
51
53
|
}
|
|
52
54
|
return response;
|
|
53
55
|
}
|
|
56
|
+
async function tryRenderPage(renderContext, env, mod, onRequest) {
|
|
57
|
+
const apiContext = createAPIContext({
|
|
58
|
+
request: renderContext.request,
|
|
59
|
+
params: renderContext.params,
|
|
60
|
+
props: renderContext.props,
|
|
61
|
+
site: env.site,
|
|
62
|
+
adapterName: env.adapterName
|
|
63
|
+
});
|
|
64
|
+
if (onRequest) {
|
|
65
|
+
return await callMiddleware(
|
|
66
|
+
env.logging,
|
|
67
|
+
onRequest,
|
|
68
|
+
apiContext,
|
|
69
|
+
() => {
|
|
70
|
+
return renderPage({
|
|
71
|
+
mod,
|
|
72
|
+
renderContext,
|
|
73
|
+
env,
|
|
74
|
+
cookies: apiContext.cookies
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
} else {
|
|
79
|
+
return await renderPage({
|
|
80
|
+
mod,
|
|
81
|
+
renderContext,
|
|
82
|
+
env,
|
|
83
|
+
cookies: apiContext.cookies
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
54
87
|
export {
|
|
55
|
-
|
|
88
|
+
tryRenderPage
|
|
56
89
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AstroSettings } from '../../../@types/astro';
|
|
1
|
+
import type { AstroSettings, SSRManifest } from '../../../@types/astro';
|
|
2
2
|
import type { LogOptions } from '../../logger/core.js';
|
|
3
3
|
import type { ModuleLoader } from '../../module-loader/index';
|
|
4
4
|
import type { Environment } from '../index';
|
|
@@ -6,4 +6,4 @@ export type DevelopmentEnvironment = Environment & {
|
|
|
6
6
|
loader: ModuleLoader;
|
|
7
7
|
settings: AstroSettings;
|
|
8
8
|
};
|
|
9
|
-
export declare function createDevelopmentEnvironment(settings: AstroSettings, logging: LogOptions, loader: ModuleLoader): DevelopmentEnvironment;
|
|
9
|
+
export declare function createDevelopmentEnvironment(manifest: SSRManifest, settings: AstroSettings, logging: LogOptions, loader: ModuleLoader): DevelopmentEnvironment;
|
|
@@ -2,21 +2,20 @@ import { isServerLikeOutput } from "../../../prerender/utils.js";
|
|
|
2
2
|
import { createEnvironment } from "../index.js";
|
|
3
3
|
import { RouteCache } from "../route-cache.js";
|
|
4
4
|
import { createResolve } from "./resolve.js";
|
|
5
|
-
function createDevelopmentEnvironment(settings, logging, loader) {
|
|
6
|
-
var _a;
|
|
5
|
+
function createDevelopmentEnvironment(manifest, settings, logging, loader) {
|
|
7
6
|
const mode = "development";
|
|
8
7
|
let env = createEnvironment({
|
|
9
|
-
adapterName:
|
|
8
|
+
adapterName: manifest.adapterName,
|
|
10
9
|
logging,
|
|
11
|
-
markdown:
|
|
10
|
+
markdown: manifest.markdown,
|
|
12
11
|
mode,
|
|
13
12
|
// This will be overridden in the dev server
|
|
14
13
|
renderers: [],
|
|
15
|
-
clientDirectives:
|
|
16
|
-
compressHTML:
|
|
14
|
+
clientDirectives: manifest.clientDirectives,
|
|
15
|
+
compressHTML: manifest.compressHTML,
|
|
17
16
|
resolve: createResolve(loader, settings.config.root),
|
|
18
17
|
routeCache: new RouteCache(logging, mode),
|
|
19
|
-
site:
|
|
18
|
+
site: manifest.site,
|
|
20
19
|
ssr: isServerLikeOutput(settings.config),
|
|
21
20
|
streaming: true
|
|
22
21
|
});
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { PAGE_SCRIPT_ID } from "../../../vite-plugin-scripts/index.js";
|
|
2
|
-
import { createAPIContext } from "../../endpoint/index.js";
|
|
3
2
|
import { enhanceViteSSRError } from "../../errors/dev/index.js";
|
|
4
3
|
import { AggregateError, CSSError, MarkdownError } from "../../errors/index.js";
|
|
5
|
-
import { callMiddleware } from "../../middleware/callMiddleware.js";
|
|
6
4
|
import { isPage, resolveIdToUrl, viteID } from "../../util.js";
|
|
7
|
-
import { createRenderContext, loadRenderers,
|
|
5
|
+
import { createRenderContext, loadRenderers, tryRenderPage } from "../index.js";
|
|
8
6
|
import { getStylesForURL } from "./css.js";
|
|
9
7
|
import { getComponentMetadata } from "./metadata.js";
|
|
10
8
|
import { getScriptsForURL } from "./scripts.js";
|
|
@@ -104,32 +102,8 @@ async function renderPage(options) {
|
|
|
104
102
|
mod,
|
|
105
103
|
env
|
|
106
104
|
});
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
params: renderContext.params,
|
|
110
|
-
props: renderContext.props,
|
|
111
|
-
adapterName: options.env.adapterName
|
|
112
|
-
});
|
|
113
|
-
if (options.middleware) {
|
|
114
|
-
if ((_a = options.middleware) == null ? void 0 : _a.onRequest) {
|
|
115
|
-
const onRequest = options.middleware.onRequest;
|
|
116
|
-
const response = await callMiddleware(env.logging, onRequest, apiContext, () => {
|
|
117
|
-
return coreRenderPage({
|
|
118
|
-
mod,
|
|
119
|
-
renderContext,
|
|
120
|
-
env: options.env,
|
|
121
|
-
cookies: apiContext.cookies
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
return response;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return await coreRenderPage({
|
|
128
|
-
mod,
|
|
129
|
-
renderContext,
|
|
130
|
-
env: options.env,
|
|
131
|
-
cookies: apiContext.cookies
|
|
132
|
-
});
|
|
105
|
+
const onRequest = (_a = options.middleware) == null ? void 0 : _a.onRequest;
|
|
106
|
+
return tryRenderPage(renderContext, env, mod, onRequest);
|
|
133
107
|
}
|
|
134
108
|
export {
|
|
135
109
|
createDevelopmentEnvironment,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { createRenderContext } from './context.js';
|
|
2
2
|
export type { RenderContext } from './context.js';
|
|
3
|
-
export {
|
|
3
|
+
export { tryRenderPage } from './core.js';
|
|
4
4
|
export type { Environment } from './environment';
|
|
5
5
|
export { createEnvironment } from './environment.js';
|
|
6
6
|
export { getParamsAndProps } from './params-and-props.js';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRenderContext } from "./context.js";
|
|
2
|
-
import {
|
|
2
|
+
import { tryRenderPage } from "./core.js";
|
|
3
3
|
import { createEnvironment } from "./environment.js";
|
|
4
4
|
import { getParamsAndProps } from "./params-and-props.js";
|
|
5
5
|
import { loadRenderer, loadRenderers } from "./renderer.js";
|
|
@@ -9,5 +9,5 @@ export {
|
|
|
9
9
|
getParamsAndProps,
|
|
10
10
|
loadRenderer,
|
|
11
11
|
loadRenderers,
|
|
12
|
-
|
|
12
|
+
tryRenderPage
|
|
13
13
|
};
|
package/dist/core/request.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { IncomingHttpHeaders } from 'http';
|
|
2
|
+
import type { IncomingHttpHeaders } from 'node:http';
|
|
3
3
|
import type { LogOptions } from './logger/core';
|
|
4
4
|
type HeaderType = Headers | Record<string, any> | IncomingHttpHeaders;
|
|
5
5
|
type RequestBody = ArrayBuffer | Blob | ReadableStream | URLSearchParams | FormData;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { AstroSettings, ManifestData } from '../../../@types/astro';
|
|
3
3
|
import type { LogOptions } from '../../logger/core';
|
|
4
|
-
import nodeFs from 'fs';
|
|
4
|
+
import nodeFs from 'node:fs';
|
|
5
5
|
export interface CreateRouteManifestParams {
|
|
6
6
|
/** Astro Settings object */
|
|
7
7
|
settings: AstroSettings;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import nodeFs from "fs";
|
|
2
1
|
import { createRequire } from "module";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import nodeFs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
5
|
import { getPrerenderDefault } from "../../../prerender/utils.js";
|
|
6
6
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "../../constants.js";
|
|
7
7
|
import { warn } from "../../logger/core.js";
|
|
@@ -313,6 +313,25 @@ This route collides with: "${collision.component}".`
|
|
|
313
313
|
redirect: to,
|
|
314
314
|
redirectRoute: routes.find((r) => r.route === to)
|
|
315
315
|
};
|
|
316
|
+
const lastSegmentIsDynamic = (r) => {
|
|
317
|
+
var _a2, _b;
|
|
318
|
+
return !!((_b = (_a2 = r.segments.at(-1)) == null ? void 0 : _a2.at(-1)) == null ? void 0 : _b.dynamic);
|
|
319
|
+
};
|
|
320
|
+
const redirBase = path.posix.dirname(route);
|
|
321
|
+
const dynamicRedir = lastSegmentIsDynamic(routeData);
|
|
322
|
+
let i = 0;
|
|
323
|
+
for (const existingRoute of routes) {
|
|
324
|
+
if (existingRoute.route === route) {
|
|
325
|
+
routes.splice(i + 1, 0, routeData);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
const base = path.posix.dirname(existingRoute.route);
|
|
329
|
+
if (base === redirBase && !dynamicRedir && lastSegmentIsDynamic(existingRoute)) {
|
|
330
|
+
routes.splice(i, 0, routeData);
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
i++;
|
|
334
|
+
}
|
|
316
335
|
routes.push(routeData);
|
|
317
336
|
});
|
|
318
337
|
return {
|
package/dist/core/util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import { fileURLToPath } from "url";
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { normalizePath } from "vite";
|
|
5
5
|
import { isServerLikeOutput } from "../prerender/utils.js";
|
|
6
6
|
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from "./constants.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type { AddressInfo } from 'net';
|
|
2
|
+
import type { AddressInfo } from 'node:net';
|
|
3
3
|
import type { InlineConfig, ViteDevServer } from 'vite';
|
|
4
4
|
import type { AstroConfig, AstroSettings, RouteData } from '../@types/astro.js';
|
|
5
5
|
import type { SerializedSSRManifest } from '../core/app/types';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import type fs from 'node:fs';
|
|
2
3
|
import type * as vite from 'vite';
|
|
3
|
-
import type { AstroSettings } from '../@types/astro';
|
|
4
|
-
import type fs from 'fs';
|
|
4
|
+
import type { AstroSettings, SSRManifest } from '../@types/astro';
|
|
5
5
|
import type { LogOptions } from '../core/logger/core.js';
|
|
6
6
|
export interface AstroPluginOptions {
|
|
7
7
|
settings: AstroSettings;
|
|
@@ -9,3 +9,11 @@ export interface AstroPluginOptions {
|
|
|
9
9
|
fs: typeof fs;
|
|
10
10
|
}
|
|
11
11
|
export default function createVitePluginAstroServer({ settings, logging, fs: fsMod, }: AstroPluginOptions): vite.Plugin;
|
|
12
|
+
/**
|
|
13
|
+
* It creates a `SSRManifest` from the `AstroSettings`.
|
|
14
|
+
*
|
|
15
|
+
* Renderers needs to be pulled out from the page module emitted during the build.
|
|
16
|
+
* @param settings
|
|
17
|
+
* @param renderers
|
|
18
|
+
*/
|
|
19
|
+
export declare function createDevelopmentManifest(settings: AstroSettings): SSRManifest;
|
|
@@ -14,13 +14,14 @@ function createVitePluginAstroServer({
|
|
|
14
14
|
name: "astro:server",
|
|
15
15
|
configureServer(viteServer) {
|
|
16
16
|
const loader = createViteLoader(viteServer);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
const manifest = createDevelopmentManifest(settings);
|
|
18
|
+
const env = createDevelopmentEnvironment(manifest, settings, logging, loader);
|
|
19
|
+
let manifestData = createRouteManifest({ settings, fsMod }, logging);
|
|
20
|
+
const controller = createController({ loader });
|
|
20
21
|
function rebuildManifest(needsManifestRebuild) {
|
|
21
22
|
env.routeCache.clearAll();
|
|
22
23
|
if (needsManifestRebuild) {
|
|
23
|
-
|
|
24
|
+
manifestData = createRouteManifest({ settings }, logging);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
viteServer.watcher.on("add", rebuildManifest.bind(null, true));
|
|
@@ -33,13 +34,20 @@ function createVitePluginAstroServer({
|
|
|
33
34
|
handle: baseMiddleware(settings, logging)
|
|
34
35
|
});
|
|
35
36
|
}
|
|
36
|
-
viteServer.middlewares.use(async function astroDevHandler(
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
viteServer.middlewares.use(async function astroDevHandler(request, response) {
|
|
38
|
+
if (request.url === void 0 || !request.method) {
|
|
39
|
+
response.writeHead(500, "Incomplete request");
|
|
40
|
+
response.end();
|
|
40
41
|
return;
|
|
41
42
|
}
|
|
42
|
-
handleRequest(
|
|
43
|
+
handleRequest({
|
|
44
|
+
env,
|
|
45
|
+
manifestData,
|
|
46
|
+
controller,
|
|
47
|
+
incomingRequest: request,
|
|
48
|
+
incomingResponse: response,
|
|
49
|
+
manifest
|
|
50
|
+
});
|
|
43
51
|
});
|
|
44
52
|
};
|
|
45
53
|
},
|
|
@@ -52,6 +60,23 @@ function createVitePluginAstroServer({
|
|
|
52
60
|
}
|
|
53
61
|
};
|
|
54
62
|
}
|
|
63
|
+
function createDevelopmentManifest(settings) {
|
|
64
|
+
return {
|
|
65
|
+
compressHTML: settings.config.compressHTML,
|
|
66
|
+
assets: /* @__PURE__ */ new Set(),
|
|
67
|
+
entryModules: {},
|
|
68
|
+
routes: [],
|
|
69
|
+
adapterName: "",
|
|
70
|
+
markdown: settings.config.markdown,
|
|
71
|
+
clientDirectives: settings.clientDirectives,
|
|
72
|
+
renderers: [],
|
|
73
|
+
base: settings.config.base,
|
|
74
|
+
assetsPrefix: settings.config.build.assetsPrefix,
|
|
75
|
+
site: settings.config.site ? new URL(settings.config.base, settings.config.site).toString() : settings.config.site,
|
|
76
|
+
componentMetadata: /* @__PURE__ */ new Map()
|
|
77
|
+
};
|
|
78
|
+
}
|
|
55
79
|
export {
|
|
80
|
+
createDevelopmentManifest,
|
|
56
81
|
createVitePluginAstroServer as default
|
|
57
82
|
};
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type http from 'http';
|
|
3
|
-
import type { ManifestData } from '../@types/astro';
|
|
2
|
+
import type http from 'node:http';
|
|
3
|
+
import type { ManifestData, SSRManifest } from '../@types/astro';
|
|
4
4
|
import type { DevelopmentEnvironment } from '../core/render/dev/index';
|
|
5
5
|
import type { DevServerController } from './controller';
|
|
6
|
+
type HandleRequest = {
|
|
7
|
+
env: DevelopmentEnvironment;
|
|
8
|
+
manifestData: ManifestData;
|
|
9
|
+
controller: DevServerController;
|
|
10
|
+
incomingRequest: http.IncomingMessage;
|
|
11
|
+
incomingResponse: http.ServerResponse;
|
|
12
|
+
manifest: SSRManifest;
|
|
13
|
+
};
|
|
6
14
|
/** The main logic to route dev server requests to pages in Astro. */
|
|
7
|
-
export declare function handleRequest(env
|
|
15
|
+
export declare function handleRequest({ env, manifestData, controller, incomingRequest, incomingResponse, manifest, }: HandleRequest): Promise<void>;
|
|
16
|
+
export {};
|
|
@@ -8,14 +8,21 @@ import { isServerLikeOutput } from "../prerender/utils.js";
|
|
|
8
8
|
import { runWithErrorHandling } from "./controller.js";
|
|
9
9
|
import { handle500Response } from "./response.js";
|
|
10
10
|
import { handleRoute, matchRoute } from "./route.js";
|
|
11
|
-
async function handleRequest(
|
|
11
|
+
async function handleRequest({
|
|
12
|
+
env,
|
|
13
|
+
manifestData,
|
|
14
|
+
controller,
|
|
15
|
+
incomingRequest,
|
|
16
|
+
incomingResponse,
|
|
17
|
+
manifest
|
|
18
|
+
}) {
|
|
12
19
|
const { settings, loader: moduleLoader } = env;
|
|
13
20
|
const { config } = settings;
|
|
14
|
-
const origin = `${moduleLoader.isHttps() ? "https" : "http"}://${
|
|
21
|
+
const origin = `${moduleLoader.isHttps() ? "https" : "http"}://${incomingRequest.headers.host}`;
|
|
15
22
|
const buildingToSSR = isServerLikeOutput(config);
|
|
16
|
-
const url = new URL(origin +
|
|
23
|
+
const url = new URL(origin + incomingRequest.url);
|
|
17
24
|
let pathname;
|
|
18
|
-
if (config.trailingSlash === "never" && !
|
|
25
|
+
if (config.trailingSlash === "never" && !incomingRequest.url) {
|
|
19
26
|
pathname = "";
|
|
20
27
|
} else {
|
|
21
28
|
pathname = decodeURI(url.pathname);
|
|
@@ -28,13 +35,13 @@ async function handleRequest(env, manifest, controller, req, res) {
|
|
|
28
35
|
}
|
|
29
36
|
}
|
|
30
37
|
let body = void 0;
|
|
31
|
-
if (!(
|
|
38
|
+
if (!(incomingRequest.method === "GET" || incomingRequest.method === "HEAD")) {
|
|
32
39
|
let bytes = [];
|
|
33
40
|
await new Promise((resolve) => {
|
|
34
|
-
|
|
41
|
+
incomingRequest.on("data", (part) => {
|
|
35
42
|
bytes.push(part);
|
|
36
43
|
});
|
|
37
|
-
|
|
44
|
+
incomingRequest.on("end", resolve);
|
|
38
45
|
});
|
|
39
46
|
body = Buffer.concat(bytes);
|
|
40
47
|
}
|
|
@@ -42,19 +49,20 @@ async function handleRequest(env, manifest, controller, req, res) {
|
|
|
42
49
|
controller,
|
|
43
50
|
pathname,
|
|
44
51
|
async run() {
|
|
45
|
-
const matchedRoute = await matchRoute(pathname, env,
|
|
52
|
+
const matchedRoute = await matchRoute(pathname, env, manifestData);
|
|
46
53
|
const resolvedPathname = (matchedRoute == null ? void 0 : matchedRoute.resolvedPathname) ?? pathname;
|
|
47
|
-
return await handleRoute(
|
|
54
|
+
return await handleRoute({
|
|
48
55
|
matchedRoute,
|
|
49
56
|
url,
|
|
50
|
-
resolvedPathname,
|
|
57
|
+
pathname: resolvedPathname,
|
|
51
58
|
body,
|
|
52
59
|
origin,
|
|
53
60
|
env,
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
61
|
+
manifestData,
|
|
62
|
+
incomingRequest,
|
|
63
|
+
incomingResponse,
|
|
64
|
+
manifest
|
|
65
|
+
});
|
|
58
66
|
},
|
|
59
67
|
onError(_err) {
|
|
60
68
|
const err = createSafeError(_err);
|
|
@@ -65,7 +73,7 @@ async function handleRequest(env, manifest, controller, req, res) {
|
|
|
65
73
|
const errorWithMetadata = collectErrorMetadata(err, config.root);
|
|
66
74
|
telemetry.record(eventError({ cmd: "dev", err: errorWithMetadata, isFatal: false }));
|
|
67
75
|
error(env.logging, null, msg.formatErrorMessage(errorWithMetadata));
|
|
68
|
-
handle500Response(moduleLoader,
|
|
76
|
+
handle500Response(moduleLoader, incomingResponse, errorWithMetadata);
|
|
69
77
|
return err;
|
|
70
78
|
}
|
|
71
79
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type http from 'http';
|
|
2
|
+
import type http from 'node:http';
|
|
3
3
|
import type { ErrorWithMetadata } from '../core/errors/index.js';
|
|
4
4
|
import type { ModuleLoader } from '../core/module-loader/index';
|
|
5
5
|
export declare function handle404Response(origin: string, req: http.IncomingMessage, res: http.ServerResponse): Promise<void>;
|