astro 5.0.0-alpha.4 → 5.0.0-alpha.5
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/dist/actions/integration.js +2 -2
- package/dist/actions/runtime/middleware.js +1 -1
- package/dist/assets/build/generate.js +4 -4
- package/dist/assets/endpoint/config.d.ts +3 -2
- package/dist/assets/endpoint/config.js +24 -7
- package/dist/assets/vite-plugin-assets.js +2 -3
- package/dist/config/index.js +3 -1
- package/dist/content/vite-plugin-content-imports.js +2 -3
- package/dist/content/vite-plugin-content-virtual-mod.js +1 -2
- package/dist/core/build/common.d.ts +2 -1
- package/dist/core/build/common.js +7 -7
- package/dist/core/build/generate.js +5 -5
- package/dist/core/build/index.js +13 -7
- package/dist/core/build/page-data.js +1 -1
- package/dist/core/build/pipeline.js +3 -6
- package/dist/core/build/plugins/plugin-content.js +2 -2
- package/dist/core/build/plugins/plugin-manifest.js +1 -1
- package/dist/core/build/plugins/plugin-pages.js +1 -1
- package/dist/core/build/plugins/plugin-prerender.js +1 -1
- package/dist/core/build/plugins/plugin-ssr.js +1 -2
- package/dist/core/build/static-build.js +9 -14
- package/dist/core/config/schema.d.ts +12 -12
- package/dist/core/config/schema.js +26 -11
- package/dist/core/config/settings.js +2 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.d.ts +5 -2
- package/dist/core/create-vite.js +5 -4
- package/dist/core/dev/container.js +18 -4
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +2 -2
- package/dist/core/errors/errors-data.js +3 -3
- package/dist/core/messages.js +2 -2
- package/dist/core/middleware/index.js +1 -0
- package/dist/core/middleware/vite-plugin.js +1 -1
- package/dist/core/preview/index.js +3 -1
- package/dist/core/render-context.d.ts +1 -1
- package/dist/core/render-context.js +11 -10
- package/dist/core/request.d.ts +1 -1
- package/dist/core/request.js +1 -4
- package/dist/core/routing/dev-default.d.ts +3 -0
- package/dist/core/routing/dev-default.js +10 -0
- package/dist/core/routing/manifest/create.d.ts +5 -1
- package/dist/core/routing/manifest/create.js +43 -8
- package/dist/core/sync/index.d.ts +3 -2
- package/dist/core/sync/index.js +8 -5
- package/dist/core/util.d.ts +1 -3
- package/dist/core/util.js +3 -11
- package/dist/integrations/features-validation.d.ts +2 -2
- package/dist/integrations/features-validation.js +8 -8
- package/dist/integrations/hooks.d.ts +4 -4
- package/dist/integrations/hooks.js +15 -10
- package/dist/prerender/utils.d.ts +2 -1
- package/dist/prerender/utils.js +4 -6
- package/dist/runtime/server/endpoint.d.ts +1 -1
- package/dist/runtime/server/endpoint.js +3 -3
- package/dist/types/astro.d.ts +5 -0
- package/dist/types/public/config.d.ts +50 -11
- package/dist/types/public/context.d.ts +4 -0
- package/dist/types/public/integrations.d.ts +5 -0
- package/dist/vite-plugin-astro-server/pipeline.js +3 -3
- package/dist/vite-plugin-astro-server/plugin.d.ts +4 -2
- package/dist/vite-plugin-astro-server/plugin.js +19 -12
- package/dist/vite-plugin-astro-server/route.js +1 -1
- package/dist/vite-plugin-env/index.d.ts +1 -3
- package/dist/vite-plugin-env/index.js +1 -19
- package/dist/vite-plugin-scanner/index.d.ts +3 -2
- package/dist/vite-plugin-scanner/index.js +15 -21
- package/package.json +3 -2
- package/dist/vite-plugin-scanner/scan.d.ts +0 -3
- package/dist/vite-plugin-scanner/scan.js +0 -58
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ActionsWithoutServerOutputError } from "../core/errors/errors-data.js";
|
|
2
2
|
import { AstroError } from "../core/errors/errors.js";
|
|
3
|
-
import {
|
|
3
|
+
import { viteID } from "../core/util.js";
|
|
4
4
|
import { ACTIONS_TYPES_FILE, VIRTUAL_MODULE_ID } from "./consts.js";
|
|
5
5
|
function astroIntegrationActionsRouteHandler({
|
|
6
6
|
settings
|
|
@@ -20,7 +20,7 @@ function astroIntegrationActionsRouteHandler({
|
|
|
20
20
|
});
|
|
21
21
|
},
|
|
22
22
|
"astro:config:done": async (params) => {
|
|
23
|
-
if (
|
|
23
|
+
if (params.buildOutput === "static") {
|
|
24
24
|
const error = new AstroError(ActionsWithoutServerOutputError);
|
|
25
25
|
error.stack = void 0;
|
|
26
26
|
throw error;
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
serializeActionResult
|
|
8
8
|
} from "./virtual/shared.js";
|
|
9
9
|
const onRequest = defineMiddleware(async (context, next) => {
|
|
10
|
-
if (context.
|
|
10
|
+
if (context.isPrerendered) {
|
|
11
11
|
if (context.request.method === "POST") {
|
|
12
12
|
console.warn(
|
|
13
13
|
yellow("[astro:actions]"),
|
|
@@ -6,12 +6,11 @@ import { getTimeStat } from "../../core/build/util.js";
|
|
|
6
6
|
import { AstroError } from "../../core/errors/errors.js";
|
|
7
7
|
import { AstroErrorData } from "../../core/errors/index.js";
|
|
8
8
|
import { isRemotePath, removeLeadingForwardSlash } from "../../core/path.js";
|
|
9
|
-
import { isServerLikeOutput } from "../../core/util.js";
|
|
10
9
|
import { getConfiguredImageService } from "../internal.js";
|
|
11
10
|
import { isESMImportedImage } from "../utils/imageKind.js";
|
|
12
11
|
import { loadRemoteImage } from "./remote.js";
|
|
13
12
|
async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
14
|
-
const { config, logger } = pipeline;
|
|
13
|
+
const { config, logger, settings } = pipeline;
|
|
15
14
|
let useCache = true;
|
|
16
15
|
const assetsCacheDir = new URL("assets/", config.cacheDir);
|
|
17
16
|
const count = { total: totalCount, current: 1 };
|
|
@@ -24,8 +23,9 @@ async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
|
24
23
|
);
|
|
25
24
|
useCache = false;
|
|
26
25
|
}
|
|
26
|
+
const isServerOutput = settings.buildOutput === "server";
|
|
27
27
|
let serverRoot, clientRoot;
|
|
28
|
-
if (
|
|
28
|
+
if (isServerOutput) {
|
|
29
29
|
serverRoot = config.build.server;
|
|
30
30
|
clientRoot = config.build.client;
|
|
31
31
|
} else {
|
|
@@ -34,7 +34,7 @@ async function prepareAssetsGenerationEnv(pipeline, totalCount) {
|
|
|
34
34
|
}
|
|
35
35
|
return {
|
|
36
36
|
logger,
|
|
37
|
-
isSSR:
|
|
37
|
+
isSSR: isServerOutput,
|
|
38
38
|
count,
|
|
39
39
|
useCache,
|
|
40
40
|
assetsCacheDir,
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import type { AstroSettings } from '../../types/astro.js';
|
|
2
|
-
export declare function injectImageEndpoint(settings: AstroSettings, mode: 'dev' | 'build'):
|
|
1
|
+
import type { AstroSettings, ManifestData } from '../../types/astro.js';
|
|
2
|
+
export declare function injectImageEndpoint(settings: AstroSettings, manifest: ManifestData, mode: 'dev' | 'build', cwd?: string): void;
|
|
3
|
+
export declare function ensureImageEndpointRoute(settings: AstroSettings, manifest: ManifestData, mode: 'dev' | 'build', cwd?: string): void;
|
|
@@ -1,12 +1,29 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolveInjectedRoute } from "../../core/routing/manifest/create.js";
|
|
2
|
+
function injectImageEndpoint(settings, manifest, mode, cwd) {
|
|
3
|
+
manifest.routes.push(getImageEndpointData(settings, mode, cwd));
|
|
4
|
+
}
|
|
5
|
+
function ensureImageEndpointRoute(settings, manifest, mode, cwd) {
|
|
6
|
+
if (!manifest.routes.some((route) => route.route === "/_image")) {
|
|
7
|
+
manifest.routes.push(getImageEndpointData(settings, mode, cwd));
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function getImageEndpointData(settings, mode, cwd) {
|
|
2
11
|
const endpointEntrypoint = settings.config.image.endpoint ?? (mode === "dev" ? "astro/assets/endpoint/node" : "astro/assets/endpoint/generic");
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
return {
|
|
13
|
+
type: "endpoint",
|
|
14
|
+
isIndex: false,
|
|
15
|
+
route: "/_image",
|
|
16
|
+
pattern: /^\/_image$/,
|
|
17
|
+
segments: [[{ content: "_image", dynamic: false, spread: false }]],
|
|
18
|
+
params: [],
|
|
19
|
+
component: resolveInjectedRoute(endpointEntrypoint, settings.config.root, cwd).component,
|
|
20
|
+
generate: () => "",
|
|
21
|
+
pathname: "/_image",
|
|
22
|
+
prerender: false,
|
|
23
|
+
fallbackRoutes: []
|
|
24
|
+
};
|
|
9
25
|
}
|
|
10
26
|
export {
|
|
27
|
+
ensureImageEndpointRoute,
|
|
11
28
|
injectImageEndpoint
|
|
12
29
|
};
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
removeBase,
|
|
10
10
|
removeQueryString
|
|
11
11
|
} from "../core/path.js";
|
|
12
|
-
import { isServerLikeOutput } from "../core/util.js";
|
|
13
12
|
import { VALID_INPUT_FORMATS, VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
|
|
14
13
|
import { getAssetsPrefix } from "./utils/getAssetsPrefix.js";
|
|
15
14
|
import { isESMImportedImage } from "./utils/imageKind.js";
|
|
@@ -102,7 +101,7 @@ function assets({
|
|
|
102
101
|
// so that it's tree-shaken away for all platforms that don't need it.
|
|
103
102
|
export const outDir = /* #__PURE__ */ new URL(${JSON.stringify(
|
|
104
103
|
new URL(
|
|
105
|
-
|
|
104
|
+
settings.buildOutput === "server" ? settings.config.build.client : settings.config.outDir
|
|
106
105
|
)
|
|
107
106
|
)});
|
|
108
107
|
export const assetsDir = /* #__PURE__ */ new URL(${JSON.stringify(
|
|
@@ -175,7 +174,7 @@ function assets({
|
|
|
175
174
|
if (options?.ssr) {
|
|
176
175
|
return `export default ${getProxyCode(
|
|
177
176
|
imageMetadata,
|
|
178
|
-
|
|
177
|
+
settings.buildOutput === "server"
|
|
179
178
|
)}`;
|
|
180
179
|
} else {
|
|
181
180
|
globalThis.astroAsset.referencedImages.add(imageMetadata.fsPath);
|
package/dist/config/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Logger } from "../core/logger/core.js";
|
|
2
|
+
import { createRouteManifest } from "../core/routing/index.js";
|
|
2
3
|
function defineConfig(config) {
|
|
3
4
|
return config;
|
|
4
5
|
}
|
|
@@ -29,6 +30,7 @@ function getViteConfig(userViteConfig, inlineAstroConfig = {}) {
|
|
|
29
30
|
const { astroConfig: config } = await resolveConfig(inlineAstroConfig, cmd);
|
|
30
31
|
let settings = await createSettings(config, userViteConfig.root);
|
|
31
32
|
settings = await runHookConfigSetup({ settings, command: cmd, logger });
|
|
33
|
+
const manifest = await createRouteManifest({ settings }, logger);
|
|
32
34
|
const viteConfig = await createVite(
|
|
33
35
|
{
|
|
34
36
|
mode,
|
|
@@ -37,7 +39,7 @@ function getViteConfig(userViteConfig, inlineAstroConfig = {}) {
|
|
|
37
39
|
astroContentListenPlugin({ settings, logger, fs })
|
|
38
40
|
]
|
|
39
41
|
},
|
|
40
|
-
{ settings, logger, mode, sync: false }
|
|
42
|
+
{ settings, logger, mode, sync: false, manifest }
|
|
41
43
|
);
|
|
42
44
|
await runHookConfigDone({ settings, logger });
|
|
43
45
|
return mergeConfig(viteConfig, userViteConfig);
|
|
@@ -4,7 +4,6 @@ import * as devalue from "devalue";
|
|
|
4
4
|
import { getProxyCode } from "../assets/utils/proxy.js";
|
|
5
5
|
import { AstroError } from "../core/errors/errors.js";
|
|
6
6
|
import { AstroErrorData } from "../core/errors/index.js";
|
|
7
|
-
import { isServerLikeOutput } from "../core/util.js";
|
|
8
7
|
import { CONTENT_FLAG, DATA_FLAG } from "./consts.js";
|
|
9
8
|
import {
|
|
10
9
|
getContentEntryExts,
|
|
@@ -76,7 +75,7 @@ function astroContentImportPlugin({
|
|
|
76
75
|
const code = `
|
|
77
76
|
export const id = ${JSON.stringify(id)};
|
|
78
77
|
export const collection = ${JSON.stringify(collection)};
|
|
79
|
-
export const data = ${stringifyEntryData(data,
|
|
78
|
+
export const data = ${stringifyEntryData(data, settings.buildOutput === "server")};
|
|
80
79
|
export const _internal = {
|
|
81
80
|
type: 'data',
|
|
82
81
|
filePath: ${JSON.stringify(_internal.filePath)},
|
|
@@ -100,7 +99,7 @@ export const _internal = {
|
|
|
100
99
|
export const collection = ${JSON.stringify(collection)};
|
|
101
100
|
export const slug = ${JSON.stringify(slug)};
|
|
102
101
|
export const body = ${JSON.stringify(body)};
|
|
103
|
-
export const data = ${stringifyEntryData(data,
|
|
102
|
+
export const data = ${stringifyEntryData(data, settings.buildOutput === "server")};
|
|
104
103
|
export const _internal = {
|
|
105
104
|
type: 'content',
|
|
106
105
|
filePath: ${JSON.stringify(_internal.filePath)},
|
|
@@ -7,7 +7,6 @@ import pLimit from "p-limit";
|
|
|
7
7
|
import { encodeName } from "../core/build/util.js";
|
|
8
8
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
9
9
|
import { appendForwardSlash, removeFileExtension } from "../core/path.js";
|
|
10
|
-
import { isServerLikeOutput } from "../core/util.js";
|
|
11
10
|
import { rootRelativePath } from "../core/viteUtils.js";
|
|
12
11
|
import { createDefaultAstroMetadata } from "../vite-plugin-astro/metadata.js";
|
|
13
12
|
import {
|
|
@@ -43,7 +42,7 @@ function astroContentVirtualModPlugin({
|
|
|
43
42
|
fs
|
|
44
43
|
}) {
|
|
45
44
|
let IS_DEV = false;
|
|
46
|
-
const IS_SERVER =
|
|
45
|
+
const IS_SERVER = settings.buildOutput === "server";
|
|
47
46
|
let dataStoreFile;
|
|
48
47
|
return {
|
|
49
48
|
name: "astro-content-virtual-mod-plugin",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { AstroSettings } from '../../types/astro.js';
|
|
1
2
|
import type { AstroConfig } from '../../types/public/config.js';
|
|
2
3
|
import type { RouteData } from '../../types/public/internal.js';
|
|
3
|
-
export declare function getOutFolder(
|
|
4
|
+
export declare function getOutFolder(astroSettings: AstroSettings, pathname: string, routeData: RouteData): URL;
|
|
4
5
|
export declare function getOutFile(astroConfig: AstroConfig, outFolder: URL, pathname: string, routeData: RouteData): URL;
|
|
5
6
|
/**
|
|
6
7
|
* Ensures the `outDir` is within `process.cwd()`. If not it will fallback to `<cwd>/.astro`.
|
|
@@ -3,15 +3,15 @@ import { fileURLToPath, pathToFileURL } from "node:url";
|
|
|
3
3
|
import { appendForwardSlash } from "../../core/path.js";
|
|
4
4
|
const STATUS_CODE_PAGES = /* @__PURE__ */ new Set(["/404", "/500"]);
|
|
5
5
|
const FALLBACK_OUT_DIR_NAME = "./.astro/";
|
|
6
|
-
function getOutRoot(
|
|
7
|
-
if (
|
|
8
|
-
return new URL("./",
|
|
6
|
+
function getOutRoot(astroSettings) {
|
|
7
|
+
if (astroSettings.buildOutput === "static") {
|
|
8
|
+
return new URL("./", astroSettings.config.outDir);
|
|
9
9
|
} else {
|
|
10
|
-
return new URL("./",
|
|
10
|
+
return new URL("./", astroSettings.config.build.client);
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
function getOutFolder(
|
|
14
|
-
const outRoot = getOutRoot(
|
|
13
|
+
function getOutFolder(astroSettings, pathname, routeData) {
|
|
14
|
+
const outRoot = getOutRoot(astroSettings);
|
|
15
15
|
const routeType = routeData.type;
|
|
16
16
|
switch (routeType) {
|
|
17
17
|
case "endpoint":
|
|
@@ -19,7 +19,7 @@ function getOutFolder(astroConfig, pathname, routeData) {
|
|
|
19
19
|
case "fallback":
|
|
20
20
|
case "page":
|
|
21
21
|
case "redirect":
|
|
22
|
-
switch (
|
|
22
|
+
switch (astroSettings.config.build.format) {
|
|
23
23
|
case "directory": {
|
|
24
24
|
if (STATUS_CODE_PAGES.has(pathname)) {
|
|
25
25
|
return new URL("." + appendForwardSlash(npath.dirname(pathname)), outRoot);
|
|
@@ -25,19 +25,19 @@ import { callGetStaticPaths } from "../render/route-cache.js";
|
|
|
25
25
|
import { createRequest } from "../request.js";
|
|
26
26
|
import { matchRoute } from "../routing/match.js";
|
|
27
27
|
import { stringifyParams } from "../routing/params.js";
|
|
28
|
-
import { getOutputFilename
|
|
28
|
+
import { getOutputFilename } from "../util.js";
|
|
29
29
|
import { getOutFile, getOutFolder } from "./common.js";
|
|
30
30
|
import { cssOrder, mergeInlineCss } from "./internal.js";
|
|
31
31
|
import { BuildPipeline } from "./pipeline.js";
|
|
32
32
|
import { getTimeStat, shouldAppendForwardSlash } from "./util.js";
|
|
33
33
|
async function generatePages(options, internals) {
|
|
34
34
|
const generatePagesTimer = performance.now();
|
|
35
|
-
const ssr =
|
|
35
|
+
const ssr = options.settings.buildOutput === "server";
|
|
36
36
|
let manifest;
|
|
37
37
|
if (ssr) {
|
|
38
38
|
manifest = await BuildPipeline.retrieveManifest(options, internals);
|
|
39
39
|
} else {
|
|
40
|
-
const baseDirectory = getOutputDirectory(options.settings
|
|
40
|
+
const baseDirectory = getOutputDirectory(options.settings);
|
|
41
41
|
const renderersEntryUrl = new URL("renderers.mjs", baseDirectory);
|
|
42
42
|
const renderers = await import(renderersEntryUrl.toString());
|
|
43
43
|
let middleware = (_, next) => next();
|
|
@@ -108,7 +108,7 @@ ${bgGreen(black(` ${verb} static routes `))}`);
|
|
|
108
108
|
`));
|
|
109
109
|
delete globalThis?.astroAsset?.addStaticImage;
|
|
110
110
|
}
|
|
111
|
-
await runHookBuildGenerated({
|
|
111
|
+
await runHookBuildGenerated({ settings: options.settings, logger });
|
|
112
112
|
}
|
|
113
113
|
const THRESHOLD_SLOW_RENDER_TIME_MS = 500;
|
|
114
114
|
async function generatePage(pageData, ssrEntry, builtPaths, pipeline) {
|
|
@@ -328,7 +328,7 @@ async function generatePath(pathname, pipeline, gopts, route) {
|
|
|
328
328
|
if (!response.body) return;
|
|
329
329
|
body = Buffer.from(await response.arrayBuffer());
|
|
330
330
|
}
|
|
331
|
-
const outFolder = getOutFolder(
|
|
331
|
+
const outFolder = getOutFolder(pipeline.settings, pathname, route);
|
|
332
332
|
const outFile = getOutFile(config, outFolder, pathname, route);
|
|
333
333
|
route.distURL = outFile;
|
|
334
334
|
await fs.promises.mkdir(outFolder, { recursive: true });
|
package/dist/core/build/index.js
CHANGED
|
@@ -16,12 +16,13 @@ import { createNodeLogger } from "../config/logging.js";
|
|
|
16
16
|
import { createSettings } from "../config/settings.js";
|
|
17
17
|
import { createVite } from "../create-vite.js";
|
|
18
18
|
import { createKey } from "../encryption.js";
|
|
19
|
+
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
19
20
|
import { levels, timerMessage } from "../logger/core.js";
|
|
20
21
|
import { apply as applyPolyfill } from "../polyfill.js";
|
|
21
22
|
import { createRouteManifest } from "../routing/index.js";
|
|
22
23
|
import { getServerIslandRouteData } from "../server-islands/endpoint.js";
|
|
23
24
|
import { clearContentLayerCache } from "../sync/index.js";
|
|
24
|
-
import { ensureProcessNodeEnv
|
|
25
|
+
import { ensureProcessNodeEnv } from "../util.js";
|
|
25
26
|
import { collectPagesData } from "./page-data.js";
|
|
26
27
|
import { staticBuild, viteBuild } from "./static-build.js";
|
|
27
28
|
import { getTimeStat } from "./util.js";
|
|
@@ -79,10 +80,13 @@ class AstroBuilder {
|
|
|
79
80
|
command: "build",
|
|
80
81
|
logger
|
|
81
82
|
});
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
this.manifest = await createRouteManifest({ settings: this.settings }, this.logger);
|
|
84
|
+
if (this.settings.buildOutput === "server") {
|
|
85
|
+
injectImageEndpoint(this.settings, this.manifest, "build");
|
|
86
|
+
}
|
|
87
|
+
if (!this.settings.config.adapter && this.settings.buildOutput === "server") {
|
|
88
|
+
throw new AstroError(AstroErrorData.NoAdapterInstalled);
|
|
84
89
|
}
|
|
85
|
-
this.manifest = createRouteManifest({ settings: this.settings }, this.logger);
|
|
86
90
|
const viteConfig = await createVite(
|
|
87
91
|
{
|
|
88
92
|
mode: this.mode,
|
|
@@ -96,7 +100,8 @@ class AstroBuilder {
|
|
|
96
100
|
logger: this.logger,
|
|
97
101
|
mode: "build",
|
|
98
102
|
command: "build",
|
|
99
|
-
sync: false
|
|
103
|
+
sync: false,
|
|
104
|
+
manifest: this.manifest
|
|
100
105
|
}
|
|
101
106
|
);
|
|
102
107
|
await runHookConfigDone({ settings: this.settings, logger });
|
|
@@ -104,7 +109,8 @@ class AstroBuilder {
|
|
|
104
109
|
await syncInternal({
|
|
105
110
|
settings: this.settings,
|
|
106
111
|
logger,
|
|
107
|
-
fs
|
|
112
|
+
fs,
|
|
113
|
+
manifest: this.manifest
|
|
108
114
|
});
|
|
109
115
|
return { viteConfig };
|
|
110
116
|
}
|
|
@@ -155,7 +161,7 @@ class AstroBuilder {
|
|
|
155
161
|
});
|
|
156
162
|
this.logger.debug("build", timerMessage("Additional assets copied", this.timer.assetsStart));
|
|
157
163
|
await runHookBuildDone({
|
|
158
|
-
|
|
164
|
+
settings: this.settings,
|
|
159
165
|
pages: pageNames,
|
|
160
166
|
routes: Object.values(allPages).flat().map((pageData) => pageData.route).concat(
|
|
161
167
|
this.settings.config.experimental.serverIslands ? [getServerIslandRouteData(this.settings.config)] : []
|
|
@@ -6,7 +6,6 @@ import { Pipeline } from "../render/index.js";
|
|
|
6
6
|
import { createAssetLink, createStylesheetElementSet } from "../render/ssr-element.js";
|
|
7
7
|
import { createDefaultRoutes } from "../routing/default.js";
|
|
8
8
|
import { findRouteToRewrite } from "../routing/rewrite.js";
|
|
9
|
-
import { isServerLikeOutput } from "../util.js";
|
|
10
9
|
import { getOutDirWithinCwd } from "./common.js";
|
|
11
10
|
import { cssOrder, getPageData, mergeInlineCss } from "./internal.js";
|
|
12
11
|
import { ASTRO_PAGE_MODULE_ID, ASTRO_PAGE_RESOLVED_MODULE_ID } from "./plugins/plugin-pages.js";
|
|
@@ -31,7 +30,7 @@ class BuildPipeline extends Pipeline {
|
|
|
31
30
|
resolveCache.set(specifier, assetLink);
|
|
32
31
|
return assetLink;
|
|
33
32
|
}
|
|
34
|
-
const serverLike =
|
|
33
|
+
const serverLike = settings.buildOutput === "server";
|
|
35
34
|
const streaming = serverLike;
|
|
36
35
|
super(
|
|
37
36
|
options.logger,
|
|
@@ -56,8 +55,7 @@ class BuildPipeline extends Pipeline {
|
|
|
56
55
|
*/
|
|
57
56
|
#routesByFilePath = /* @__PURE__ */ new WeakMap();
|
|
58
57
|
get outFolder() {
|
|
59
|
-
|
|
60
|
-
return ssr ? this.settings.config.build.server : getOutDirWithinCwd(this.settings.config.outDir);
|
|
58
|
+
return this.settings.buildOutput === "server" ? this.settings.config.build.server : getOutDirWithinCwd(this.settings.config.outDir);
|
|
61
59
|
}
|
|
62
60
|
static create({
|
|
63
61
|
internals,
|
|
@@ -80,8 +78,7 @@ class BuildPipeline extends Pipeline {
|
|
|
80
78
|
* @param staticBuildOptions
|
|
81
79
|
*/
|
|
82
80
|
static async retrieveManifest(staticBuildOptions, internals) {
|
|
83
|
-
const
|
|
84
|
-
const baseDirectory = getOutputDirectory(config);
|
|
81
|
+
const baseDirectory = getOutputDirectory(staticBuildOptions.settings);
|
|
85
82
|
const manifestEntryUrl = new URL(
|
|
86
83
|
`${internals.manifestFileName}?time=${Date.now()}`,
|
|
87
84
|
baseDirectory
|
|
@@ -365,7 +365,7 @@ function pluginContent(opts, internals) {
|
|
|
365
365
|
targets: ["server"],
|
|
366
366
|
hooks: {
|
|
367
367
|
async "build:before"() {
|
|
368
|
-
if (!isContentCollectionsCacheEnabled(opts.settings
|
|
368
|
+
if (!isContentCollectionsCacheEnabled(opts.settings)) {
|
|
369
369
|
return { vitePlugin: void 0 };
|
|
370
370
|
}
|
|
371
371
|
const lookupMap = await generateLookupMap({ settings: opts.settings, fs: fsMod });
|
|
@@ -374,7 +374,7 @@ function pluginContent(opts, internals) {
|
|
|
374
374
|
};
|
|
375
375
|
},
|
|
376
376
|
async "build:post"() {
|
|
377
|
-
if (!isContentCollectionsCacheEnabled(opts.settings
|
|
377
|
+
if (!isContentCollectionsCacheEnabled(opts.settings)) {
|
|
378
378
|
return;
|
|
379
379
|
}
|
|
380
380
|
const promises = [];
|
|
@@ -132,7 +132,7 @@ function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
|
132
132
|
for (const route of opts.manifest.routes) {
|
|
133
133
|
if (!route.prerender) continue;
|
|
134
134
|
if (!route.pathname) continue;
|
|
135
|
-
const outFolder = getOutFolder(opts.settings
|
|
135
|
+
const outFolder = getOutFolder(opts.settings, route.pathname, route);
|
|
136
136
|
const outFile = getOutFile(opts.settings.config, outFolder, route.pathname, route);
|
|
137
137
|
const file = outFile.toString().replace(opts.settings.config.build.client.toString(), "");
|
|
138
138
|
routes.push({
|
|
@@ -8,7 +8,7 @@ function vitePluginPages(opts, internals) {
|
|
|
8
8
|
return {
|
|
9
9
|
name: "@astro/plugin-build-pages",
|
|
10
10
|
options(options) {
|
|
11
|
-
if (opts.settings.
|
|
11
|
+
if (opts.settings.buildOutput === "static") {
|
|
12
12
|
const inputs = /* @__PURE__ */ new Set();
|
|
13
13
|
for (const pageData of Object.values(opts.allPages)) {
|
|
14
14
|
if (routeIsRedirect(pageData.route)) {
|
|
@@ -60,7 +60,7 @@ function getNonPrerenderOnlyChunks(bundle, internals) {
|
|
|
60
60
|
return nonPrerenderOnlyChunks;
|
|
61
61
|
}
|
|
62
62
|
function pluginPrerender(opts, internals) {
|
|
63
|
-
if (opts.settings.
|
|
63
|
+
if (opts.settings.buildOutput === "static") {
|
|
64
64
|
return { targets: ["server"] };
|
|
65
65
|
}
|
|
66
66
|
return {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { routeIsRedirect } from "../../redirects/index.js";
|
|
2
2
|
import { VIRTUAL_ISLAND_MAP_ID } from "../../server-islands/vite-plugin-server-islands.js";
|
|
3
|
-
import { isServerLikeOutput } from "../../util.js";
|
|
4
3
|
import { addRollupInput } from "../add-rollup-input.js";
|
|
5
4
|
import { SSR_MANIFEST_VIRTUAL_MODULE_ID } from "./plugin-manifest.js";
|
|
6
5
|
import { MIDDLEWARE_MODULE_ID } from "./plugin-middleware.js";
|
|
@@ -107,7 +106,7 @@ function vitePluginSSR(internals, adapter, options) {
|
|
|
107
106
|
};
|
|
108
107
|
}
|
|
109
108
|
function pluginSSR(options, internals) {
|
|
110
|
-
const ssr =
|
|
109
|
+
const ssr = options.settings.buildOutput === "server";
|
|
111
110
|
return {
|
|
112
111
|
targets: ["server"],
|
|
113
112
|
hooks: {
|
|
@@ -17,11 +17,9 @@ import {
|
|
|
17
17
|
} from "../../core/build/internal.js";
|
|
18
18
|
import { emptyDir, removeEmptyDirs } from "../../core/fs/index.js";
|
|
19
19
|
import { appendForwardSlash, prependForwardSlash, removeFileExtension } from "../../core/path.js";
|
|
20
|
-
import { isModeServerWithNoAdapter, isServerLikeOutput } from "../../core/util.js";
|
|
21
20
|
import { runHookBuildSetup } from "../../integrations/hooks.js";
|
|
22
21
|
import { getOutputDirectory } from "../../prerender/utils.js";
|
|
23
22
|
import { PAGE_SCRIPT_ID } from "../../vite-plugin-scripts/index.js";
|
|
24
|
-
import { AstroError, AstroErrorData } from "../errors/index.js";
|
|
25
23
|
import { routeIsRedirect } from "../redirects/index.js";
|
|
26
24
|
import { getOutDirWithinCwd } from "./common.js";
|
|
27
25
|
import { CHUNKS_PATH } from "./consts.js";
|
|
@@ -38,9 +36,6 @@ import { ASTRO_PAGE_EXTENSION_POST_PATTERN } from "./plugins/util.js";
|
|
|
38
36
|
import { encodeName, getTimeStat, viteBuildReturnToRollupOutputs } from "./util.js";
|
|
39
37
|
async function viteBuild(opts) {
|
|
40
38
|
const { allPages, settings, logger } = opts;
|
|
41
|
-
if (isModeServerWithNoAdapter(opts.settings)) {
|
|
42
|
-
throw new AstroError(AstroErrorData.NoAdapterInstalled);
|
|
43
|
-
}
|
|
44
39
|
settings.timer.start("SSR build");
|
|
45
40
|
const pageInput = /* @__PURE__ */ new Set();
|
|
46
41
|
const internals = createBuildInternals();
|
|
@@ -99,15 +94,15 @@ async function viteBuild(opts) {
|
|
|
99
94
|
}
|
|
100
95
|
async function staticBuild(opts, internals, ssrOutputChunkNames, contentFileNames) {
|
|
101
96
|
const { settings } = opts;
|
|
102
|
-
switch (
|
|
103
|
-
case
|
|
97
|
+
switch (settings.buildOutput) {
|
|
98
|
+
case "static": {
|
|
104
99
|
settings.timer.start("Static generate");
|
|
105
100
|
await generatePages(opts, internals);
|
|
106
101
|
await cleanServerOutput(opts, ssrOutputChunkNames, contentFileNames, internals);
|
|
107
102
|
settings.timer.end("Static generate");
|
|
108
103
|
return;
|
|
109
104
|
}
|
|
110
|
-
case
|
|
105
|
+
case "server": {
|
|
111
106
|
settings.timer.start("Server generate");
|
|
112
107
|
await generatePages(opts, internals);
|
|
113
108
|
await cleanStaticOutput(opts, internals);
|
|
@@ -125,8 +120,8 @@ ${bgMagenta(black(" finalizing server assets "))}
|
|
|
125
120
|
async function ssrBuild(opts, internals, input, container, logger) {
|
|
126
121
|
const buildID = Date.now().toString();
|
|
127
122
|
const { allPages, settings, viteConfig } = opts;
|
|
128
|
-
const ssr =
|
|
129
|
-
const out = getOutputDirectory(settings
|
|
123
|
+
const ssr = settings.buildOutput === "server";
|
|
124
|
+
const out = getOutputDirectory(settings);
|
|
130
125
|
const routes = Object.values(allPages).flatMap((pageData) => pageData.route);
|
|
131
126
|
const isContentCache = !ssr && settings.config.experimental.contentCollectionCache;
|
|
132
127
|
const { lastVitePlugins, vitePlugins } = await container.runBeforeHook("server", input);
|
|
@@ -238,7 +233,7 @@ async function ssrBuild(opts, internals, input, container, logger) {
|
|
|
238
233
|
}
|
|
239
234
|
async function clientBuild(opts, internals, input, container) {
|
|
240
235
|
const { settings, viteConfig } = opts;
|
|
241
|
-
const ssr =
|
|
236
|
+
const ssr = settings.buildOutput === "server";
|
|
242
237
|
const out = ssr ? settings.config.build.client : getOutDirWithinCwd(settings.config.outDir);
|
|
243
238
|
if (!input.size) {
|
|
244
239
|
if (ssr) {
|
|
@@ -290,7 +285,7 @@ async function runPostBuildHooks(container, ssrOutputs, clientOutputs) {
|
|
|
290
285
|
const config = container.options.settings.config;
|
|
291
286
|
const build = container.options.settings.config.build;
|
|
292
287
|
for (const [fileName, mutation] of mutations) {
|
|
293
|
-
const root =
|
|
288
|
+
const root = container.options.settings.buildOutput === "server" ? mutation.targets.includes("server") ? build.server : build.client : getOutDirWithinCwd(config.outDir);
|
|
294
289
|
const fullPath = path.join(fileURLToPath(root), fileName);
|
|
295
290
|
const fileURL = pathToFileURL(fullPath);
|
|
296
291
|
await fs.promises.mkdir(new URL("./", fileURL), { recursive: true });
|
|
@@ -298,7 +293,7 @@ async function runPostBuildHooks(container, ssrOutputs, clientOutputs) {
|
|
|
298
293
|
}
|
|
299
294
|
}
|
|
300
295
|
async function cleanStaticOutput(opts, internals) {
|
|
301
|
-
const ssr =
|
|
296
|
+
const ssr = opts.settings.buildOutput === "server";
|
|
302
297
|
const out = ssr ? opts.settings.config.build.server : getOutDirWithinCwd(opts.settings.config.outDir);
|
|
303
298
|
await Promise.all(
|
|
304
299
|
internals.prerenderOnlyChunks.map(async (chunk) => {
|
|
@@ -363,7 +358,7 @@ async function copyFiles(fromFolder, toFolder, includeDotfiles = false) {
|
|
|
363
358
|
}
|
|
364
359
|
async function ssrMoveAssets(opts) {
|
|
365
360
|
opts.logger.info("build", "Rearranging server assets...");
|
|
366
|
-
const serverRoot = opts.settings.
|
|
361
|
+
const serverRoot = opts.settings.buildOutput === "static" ? opts.settings.config.build.client : opts.settings.config.build.server;
|
|
367
362
|
const clientRoot = opts.settings.config.build.client;
|
|
368
363
|
const assets = opts.settings.config.build.assets;
|
|
369
364
|
const serverAssets = new URL(`./${assets}/`, appendForwardSlash(serverRoot.toString()));
|