astro 5.0.0-alpha.3 → 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/content-layer.d.ts +6 -1
- package/dist/content/content-layer.js +3 -18
- package/dist/content/data-store.d.ts +3 -3
- package/dist/content/data-store.js +7 -7
- package/dist/content/loaders/types.d.ts +4 -5
- package/dist/content/mutable-data-store.d.ts +4 -4
- package/dist/content/mutable-data-store.js +2 -2
- package/dist/content/vite-plugin-content-imports.js +2 -3
- package/dist/content/vite-plugin-content-virtual-mod.js +3 -7
- 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 -29
- package/dist/core/config/schema.js +28 -15
- 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/dev/restart.js +7 -9
- 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 +34 -7
- 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 +25 -22
- 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 -209
- 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 +5 -4
- package/dist/core/sync/constants.d.ts +0 -1
- package/dist/core/sync/constants.js +0 -4
- package/dist/core/sync/write-files.d.ts +0 -4
- package/dist/core/sync/write-files.js +0 -67
- 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);
|
|
@@ -35,7 +35,12 @@ export declare class ContentLayer {
|
|
|
35
35
|
export declare function simpleLoader<TData extends {
|
|
36
36
|
id: string;
|
|
37
37
|
}>(handler: () => Array<TData> | Promise<Array<TData>>, context: LoaderContext): Promise<void>;
|
|
38
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Get the path to the data store file.
|
|
40
|
+
* During development, this is in the `.astro` directory so that the Vite watcher can see it.
|
|
41
|
+
* In production, it's in the cache directory so that it's preserved between builds.
|
|
42
|
+
*/
|
|
43
|
+
export declare function getDataStoreFile(settings: AstroSettings, isDev?: boolean): URL;
|
|
39
44
|
export declare const globalContentLayer: {
|
|
40
45
|
init: (options: ContentLayerOptions) => ContentLayer;
|
|
41
46
|
get: () => ContentLayer | null;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { promises as fs, existsSync } from "node:fs";
|
|
2
2
|
import * as fastq from "fastq";
|
|
3
3
|
import xxhash from "xxhash-wasm";
|
|
4
|
-
import { AstroUserError } from "../core/errors/errors.js";
|
|
5
4
|
import {
|
|
6
5
|
ASSET_IMPORTS_FILE,
|
|
7
6
|
CONTENT_LAYER_TYPE,
|
|
@@ -103,18 +102,6 @@ class ContentLayer {
|
|
|
103
102
|
logger.debug("Content config not loaded, skipping sync");
|
|
104
103
|
return;
|
|
105
104
|
}
|
|
106
|
-
if (!this.#settings.config.experimental.contentLayer) {
|
|
107
|
-
const contentLayerCollections = Object.entries(contentConfig.config.collections).filter(
|
|
108
|
-
([_, collection]) => collection.type === CONTENT_LAYER_TYPE
|
|
109
|
-
);
|
|
110
|
-
if (contentLayerCollections.length > 0) {
|
|
111
|
-
throw new AstroUserError(
|
|
112
|
-
`The following collections have a loader defined, but the content layer is not enabled: ${contentLayerCollections.map(([title]) => title).join(", ")}.`,
|
|
113
|
-
"To enable the Content Layer API, set `experimental: { contentLayer: true }` in your Astro config file."
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
105
|
logger.info("Syncing content");
|
|
119
106
|
const { digest: currentConfigDigest } = contentConfig.config;
|
|
120
107
|
this.#lastConfigDigest = currentConfigDigest;
|
|
@@ -228,11 +215,9 @@ async function simpleLoader(handler, context) {
|
|
|
228
215
|
context.store.set({ id: raw.id, data: item });
|
|
229
216
|
}
|
|
230
217
|
}
|
|
231
|
-
function getDataStoreFile(settings) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
process?.env.NODE_ENV === "development" ? settings.dotAstroDir : settings.config.cacheDir
|
|
235
|
-
);
|
|
218
|
+
function getDataStoreFile(settings, isDev) {
|
|
219
|
+
isDev ??= process?.env.NODE_ENV === "development";
|
|
220
|
+
return new URL(DATA_STORE_FILE, isDev ? settings.dotAstroDir : settings.config.cacheDir);
|
|
236
221
|
}
|
|
237
222
|
function contentLayerSingleton() {
|
|
238
223
|
let instance = null;
|
|
@@ -36,7 +36,7 @@ export interface DataEntry<TData extends Record<string, unknown> = Record<string
|
|
|
36
36
|
* A read-only data store for content collections. This is used to retrieve data from the content layer at runtime.
|
|
37
37
|
* To add or modify data, use {@link MutableDataStore} instead.
|
|
38
38
|
*/
|
|
39
|
-
export declare class
|
|
39
|
+
export declare class ImmutableDataStore {
|
|
40
40
|
protected _collections: Map<string, Map<string, any>>;
|
|
41
41
|
constructor();
|
|
42
42
|
get<T = DataEntry>(collectionName: string, key: string): T | undefined;
|
|
@@ -50,6 +50,6 @@ export declare class DataStore {
|
|
|
50
50
|
* Attempts to load a DataStore from the virtual module.
|
|
51
51
|
* This only works in Vite.
|
|
52
52
|
*/
|
|
53
|
-
static fromModule(): Promise<
|
|
54
|
-
static fromMap(data: Map<string, Map<string, any>>): Promise<
|
|
53
|
+
static fromModule(): Promise<ImmutableDataStore>;
|
|
54
|
+
static fromMap(data: Map<string, Map<string, any>>): Promise<ImmutableDataStore>;
|
|
55
55
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as devalue from "devalue";
|
|
2
|
-
class
|
|
2
|
+
class ImmutableDataStore {
|
|
3
3
|
_collections = /* @__PURE__ */ new Map();
|
|
4
4
|
constructor() {
|
|
5
5
|
this._collections = /* @__PURE__ */ new Map();
|
|
@@ -40,16 +40,16 @@ class DataStore {
|
|
|
40
40
|
try {
|
|
41
41
|
const data = await import("astro:data-layer-content");
|
|
42
42
|
if (data.default instanceof Map) {
|
|
43
|
-
return
|
|
43
|
+
return ImmutableDataStore.fromMap(data.default);
|
|
44
44
|
}
|
|
45
45
|
const map = devalue.unflatten(data.default);
|
|
46
|
-
return
|
|
46
|
+
return ImmutableDataStore.fromMap(map);
|
|
47
47
|
} catch {
|
|
48
48
|
}
|
|
49
|
-
return new
|
|
49
|
+
return new ImmutableDataStore();
|
|
50
50
|
}
|
|
51
51
|
static async fromMap(data) {
|
|
52
|
-
const store = new
|
|
52
|
+
const store = new ImmutableDataStore();
|
|
53
53
|
store._collections = data;
|
|
54
54
|
return store;
|
|
55
55
|
}
|
|
@@ -59,7 +59,7 @@ function dataStoreSingleton() {
|
|
|
59
59
|
return {
|
|
60
60
|
get: async () => {
|
|
61
61
|
if (!instance) {
|
|
62
|
-
instance =
|
|
62
|
+
instance = ImmutableDataStore.fromModule();
|
|
63
63
|
}
|
|
64
64
|
return instance;
|
|
65
65
|
},
|
|
@@ -70,6 +70,6 @@ function dataStoreSingleton() {
|
|
|
70
70
|
}
|
|
71
71
|
const globalDataStore = dataStoreSingleton();
|
|
72
72
|
export {
|
|
73
|
-
|
|
73
|
+
ImmutableDataStore,
|
|
74
74
|
globalDataStore
|
|
75
75
|
};
|
|
@@ -2,8 +2,8 @@ import type { FSWatcher } from 'vite';
|
|
|
2
2
|
import type { ZodSchema } from 'zod';
|
|
3
3
|
import type { AstroIntegrationLogger } from '../../core/logger/core.js';
|
|
4
4
|
import type { AstroConfig } from '../../types/public/config.js';
|
|
5
|
-
import type {
|
|
6
|
-
|
|
5
|
+
import type { DataStore, MetaStore } from '../mutable-data-store.js';
|
|
6
|
+
export type { DataStore, MetaStore };
|
|
7
7
|
export interface ParseDataOptions<TData extends Record<string, unknown>> {
|
|
8
8
|
/** The ID of the entry. Unique per collection */
|
|
9
9
|
id: string;
|
|
@@ -15,8 +15,8 @@ export interface ParseDataOptions<TData extends Record<string, unknown>> {
|
|
|
15
15
|
export interface LoaderContext {
|
|
16
16
|
/** The unique name of the collection */
|
|
17
17
|
collection: string;
|
|
18
|
-
/** A database
|
|
19
|
-
store:
|
|
18
|
+
/** A database to store the actual data */
|
|
19
|
+
store: DataStore;
|
|
20
20
|
/** A simple KV store, designed for things like sync tokens */
|
|
21
21
|
meta: MetaStore;
|
|
22
22
|
logger: AstroIntegrationLogger;
|
|
@@ -30,7 +30,6 @@ export interface LoaderContext {
|
|
|
30
30
|
watcher?: FSWatcher;
|
|
31
31
|
/** If the loader has been triggered by an integration, this may optionally contain extra data set by that integration */
|
|
32
32
|
refreshContextData?: Record<string, unknown>;
|
|
33
|
-
entryTypes: Map<string, ContentEntryType>;
|
|
34
33
|
}
|
|
35
34
|
export interface Loader {
|
|
36
35
|
/** Unique name of the loader, e.g. the npm package name */
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type PathLike } from 'node:fs';
|
|
2
|
-
import { type DataEntry,
|
|
2
|
+
import { type DataEntry, ImmutableDataStore, type RenderedContent } from './data-store.js';
|
|
3
3
|
/**
|
|
4
4
|
* Extends the DataStore with the ability to change entries and write them to disk.
|
|
5
5
|
* This is kept as a separate class to avoid needing node builtins at runtime, when read-only access is all that is needed.
|
|
6
6
|
*/
|
|
7
|
-
export declare class MutableDataStore extends
|
|
7
|
+
export declare class MutableDataStore extends ImmutableDataStore {
|
|
8
8
|
#private;
|
|
9
9
|
set(collectionName: string, key: string, value: unknown): void;
|
|
10
10
|
delete(collectionName: string, key: string): void;
|
|
@@ -15,7 +15,7 @@ export declare class MutableDataStore extends DataStore {
|
|
|
15
15
|
addModuleImport(fileName: string): void;
|
|
16
16
|
writeAssetImports(filePath: PathLike): Promise<void>;
|
|
17
17
|
writeModuleImports(filePath: PathLike): Promise<void>;
|
|
18
|
-
scopedStore(collectionName: string):
|
|
18
|
+
scopedStore(collectionName: string): DataStore;
|
|
19
19
|
/**
|
|
20
20
|
* Returns a MetaStore for a given collection, or if no collection is provided, the default meta collection.
|
|
21
21
|
*/
|
|
@@ -31,7 +31,7 @@ export declare class MutableDataStore extends DataStore {
|
|
|
31
31
|
static fromString(data: string): Promise<MutableDataStore>;
|
|
32
32
|
static fromFile(filePath: string | URL): Promise<MutableDataStore>;
|
|
33
33
|
}
|
|
34
|
-
export interface
|
|
34
|
+
export interface DataStore {
|
|
35
35
|
get: <TData extends Record<string, unknown> = Record<string, unknown>>(key: string) => DataEntry<TData> | undefined;
|
|
36
36
|
entries: () => Array<[id: string, DataEntry]>;
|
|
37
37
|
set: <TData extends Record<string, unknown>>(opts: {
|
|
@@ -4,10 +4,10 @@ import { Traverse } from "neotraverse/modern";
|
|
|
4
4
|
import { imageSrcToImportId, importIdToSymbolName } from "../assets/utils/resolveImports.js";
|
|
5
5
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
6
6
|
import { IMAGE_IMPORT_PREFIX } from "./consts.js";
|
|
7
|
-
import {
|
|
7
|
+
import { ImmutableDataStore } from "./data-store.js";
|
|
8
8
|
import { contentModuleToId } from "./utils.js";
|
|
9
9
|
const SAVE_DEBOUNCE_MS = 500;
|
|
10
|
-
class MutableDataStore extends
|
|
10
|
+
class MutableDataStore extends ImmutableDataStore {
|
|
11
11
|
#file;
|
|
12
12
|
#assetsFile;
|
|
13
13
|
#modulesFile;
|
|
@@ -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 {
|
|
@@ -17,7 +16,6 @@ import {
|
|
|
17
16
|
CONTENT_FLAG,
|
|
18
17
|
CONTENT_RENDER_FLAG,
|
|
19
18
|
DATA_FLAG,
|
|
20
|
-
DATA_STORE_FILE,
|
|
21
19
|
DATA_STORE_VIRTUAL_ID,
|
|
22
20
|
MODULES_IMPORTS_FILE,
|
|
23
21
|
MODULES_MJS_ID,
|
|
@@ -26,6 +24,7 @@ import {
|
|
|
26
24
|
RESOLVED_VIRTUAL_MODULE_ID,
|
|
27
25
|
VIRTUAL_MODULE_ID
|
|
28
26
|
} from "./consts.js";
|
|
27
|
+
import { getDataStoreFile } from "./content-layer.js";
|
|
29
28
|
import {
|
|
30
29
|
getContentEntryIdAndSlug,
|
|
31
30
|
getContentPaths,
|
|
@@ -43,17 +42,14 @@ 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",
|
|
50
49
|
enforce: "pre",
|
|
51
50
|
configResolved(config) {
|
|
52
51
|
IS_DEV = config.mode === "development";
|
|
53
|
-
dataStoreFile =
|
|
54
|
-
DATA_STORE_FILE,
|
|
55
|
-
IS_DEV ? settings.dotAstroDir : settings.config.cacheDir
|
|
56
|
-
);
|
|
52
|
+
dataStoreFile = getDataStoreFile(settings, IS_DEV);
|
|
57
53
|
},
|
|
58
54
|
async resolveId(id) {
|
|
59
55
|
if (id === VIRTUAL_MODULE_ID) {
|
|
@@ -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({
|