astro 5.2.6 → 5.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/container/index.js +1 -0
- package/dist/content/content-layer.js +3 -3
- package/dist/content/loaders/glob.js +6 -5
- package/dist/content/runtime-assets.d.ts +1 -1
- package/dist/content/types-generator.js +6 -11
- package/dist/content/vite-plugin-content-virtual-mod.js +2 -2
- package/dist/core/app/middlewares.js +5 -4
- package/dist/core/app/types.d.ts +7 -0
- package/dist/core/build/generate.js +1 -0
- package/dist/core/build/plugins/plugin-manifest.js +4 -5
- package/dist/core/build/static-build.d.ts +0 -1
- package/dist/core/build/static-build.js +4 -23
- package/dist/core/config/schema.d.ts +278 -312
- package/dist/core/config/schema.js +22 -22
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +2 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.d.ts +74 -28
- package/dist/core/errors/errors-data.js +33 -12
- package/dist/core/messages.js +2 -2
- package/dist/core/render-context.js +1 -0
- package/dist/core/routing/rewrite.js +15 -2
- package/dist/core/session.d.ts +3 -1
- package/dist/core/session.js +37 -8
- package/dist/integrations/hooks.js +2 -0
- package/dist/runtime/server/endpoint.js +8 -2
- package/dist/runtime/server/render/any.d.ts +1 -1
- package/dist/runtime/server/render/any.js +79 -30
- package/dist/runtime/server/render/astro/instance.d.ts +4 -3
- package/dist/runtime/server/render/astro/instance.js +14 -6
- package/dist/runtime/server/render/astro/render-template.d.ts +1 -1
- package/dist/runtime/server/render/astro/render-template.js +21 -11
- package/dist/runtime/server/render/astro/render.js +12 -5
- package/dist/runtime/server/render/component.d.ts +1 -1
- package/dist/runtime/server/render/component.js +9 -7
- package/dist/runtime/server/render/head.js +3 -0
- package/dist/runtime/server/render/script.js +3 -1
- package/dist/runtime/server/render/util.d.ts +13 -7
- package/dist/runtime/server/render/util.js +23 -12
- package/dist/types/public/config.d.ts +33 -21
- package/dist/types/public/internal.d.ts +1 -0
- package/dist/vite-plugin-astro-server/plugin.js +2 -1
- package/package.json +4 -4
package/dist/container/index.js
CHANGED
|
@@ -38,6 +38,7 @@ function createManifest(manifest, renderers, middleware) {
|
|
|
38
38
|
clientDirectives: manifest?.clientDirectives ?? getDefaultClientDirectives(),
|
|
39
39
|
renderers: renderers ?? manifest?.renderers ?? [],
|
|
40
40
|
base: manifest?.base ?? ASTRO_CONFIG_DEFAULTS.base,
|
|
41
|
+
userAssetsBase: manifest?.userAssetsBase ?? "",
|
|
41
42
|
componentMetadata: manifest?.componentMetadata ?? /* @__PURE__ */ new Map(),
|
|
42
43
|
inlinedScripts: manifest?.inlinedScripts ?? /* @__PURE__ */ new Map(),
|
|
43
44
|
i18n: manifest?.i18n,
|
|
@@ -153,7 +153,7 @@ ${contentConfig.error.message}`);
|
|
|
153
153
|
logger.info("Content config changed");
|
|
154
154
|
shouldClear = true;
|
|
155
155
|
}
|
|
156
|
-
if (previousAstroVersion && previousAstroVersion !== "5.
|
|
156
|
+
if (previousAstroVersion && previousAstroVersion !== "5.3.1") {
|
|
157
157
|
logger.info("Astro version changed");
|
|
158
158
|
shouldClear = true;
|
|
159
159
|
}
|
|
@@ -161,8 +161,8 @@ ${contentConfig.error.message}`);
|
|
|
161
161
|
logger.info("Clearing content store");
|
|
162
162
|
this.#store.clearAll();
|
|
163
163
|
}
|
|
164
|
-
if ("5.
|
|
165
|
-
await this.#store.metaStore().set("astro-version", "5.
|
|
164
|
+
if ("5.3.1") {
|
|
165
|
+
await this.#store.metaStore().set("astro-version", "5.3.1");
|
|
166
166
|
}
|
|
167
167
|
if (currentConfigDigest) {
|
|
168
168
|
await this.#store.metaStore().set("content-config-digest", currentConfigDigest);
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { promises as fs, existsSync } from "node:fs";
|
|
2
2
|
import { relative } from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
-
import fastGlob from "fast-glob";
|
|
5
4
|
import { bold, green } from "kleur/colors";
|
|
6
|
-
import micromatch from "micromatch";
|
|
7
5
|
import pLimit from "p-limit";
|
|
6
|
+
import picomatch from "picomatch";
|
|
7
|
+
import { glob as tinyglobby } from "tinyglobby";
|
|
8
8
|
import { getContentEntryIdAndSlug, posixRelative } from "../utils.js";
|
|
9
9
|
function generateIdDefault({ entry, base, data }) {
|
|
10
10
|
if (data.slug) {
|
|
@@ -154,8 +154,9 @@ function glob(globOptions) {
|
|
|
154
154
|
if (!exists) {
|
|
155
155
|
logger.warn(`The base directory "${fileURLToPath(baseDir)}" does not exist.`);
|
|
156
156
|
}
|
|
157
|
-
const files = await
|
|
158
|
-
cwd: fileURLToPath(baseDir)
|
|
157
|
+
const files = await tinyglobby(globOptions.pattern, {
|
|
158
|
+
cwd: fileURLToPath(baseDir),
|
|
159
|
+
expandDirectories: false
|
|
159
160
|
});
|
|
160
161
|
if (exists && files.length === 0) {
|
|
161
162
|
logger.warn(
|
|
@@ -220,7 +221,7 @@ function glob(globOptions) {
|
|
|
220
221
|
return;
|
|
221
222
|
}
|
|
222
223
|
watcher.add(filePath);
|
|
223
|
-
const matchesGlob = (entry) => !entry.startsWith("../") &&
|
|
224
|
+
const matchesGlob = (entry) => !entry.startsWith("../") && picomatch.isMatch(entry, globOptions.pattern);
|
|
224
225
|
const basePath = fileURLToPath(baseDir);
|
|
225
226
|
async function onChange(changedPath) {
|
|
226
227
|
const entry = posixRelative(basePath, changedPath);
|
|
@@ -4,8 +4,8 @@ export declare function createImage(pluginContext: PluginContext, shouldEmitFile
|
|
|
4
4
|
ASTRO_ASSET: string;
|
|
5
5
|
width: number;
|
|
6
6
|
height: number;
|
|
7
|
-
format: import("../assets/types.js").ImageInputFormat;
|
|
8
7
|
src: string;
|
|
8
|
+
format: import("../assets/types.js").ImageInputFormat;
|
|
9
9
|
fsPath: string;
|
|
10
10
|
orientation?: number | undefined;
|
|
11
11
|
}, string>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
3
|
-
import glob from "fast-glob";
|
|
4
3
|
import { bold, cyan } from "kleur/colors";
|
|
4
|
+
import { glob } from "tinyglobby";
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
6
|
import { z } from "zod";
|
|
7
7
|
import { zodToJsonSchema } from "zod-to-json-schema";
|
|
@@ -48,20 +48,15 @@ async function createContentTypesGenerator({
|
|
|
48
48
|
}
|
|
49
49
|
const globResult = await glob("**", {
|
|
50
50
|
cwd: fileURLToPath(contentPaths.contentDir),
|
|
51
|
-
|
|
52
|
-
readdir: fs.readdir.bind(fs),
|
|
53
|
-
readdirSync: fs.readdirSync.bind(fs)
|
|
54
|
-
},
|
|
55
|
-
onlyFiles: false,
|
|
56
|
-
objectMode: true
|
|
51
|
+
absolute: true
|
|
57
52
|
});
|
|
58
|
-
for (const
|
|
59
|
-
const fullPath = path.join(fileURLToPath(contentPaths.contentDir), entry.path);
|
|
53
|
+
for (const fullPath of globResult) {
|
|
60
54
|
const entryURL = pathToFileURL(fullPath);
|
|
61
55
|
if (entryURL.href.startsWith(contentPaths.config.url.href)) continue;
|
|
62
|
-
|
|
56
|
+
const stat = fs.statSync(fullPath);
|
|
57
|
+
if (stat.isFile()) {
|
|
63
58
|
events.push({ name: "add", entry: entryURL });
|
|
64
|
-
} else if (
|
|
59
|
+
} else if (stat.isDirectory()) {
|
|
65
60
|
events.push({ name: "addDir", entry: entryURL });
|
|
66
61
|
}
|
|
67
62
|
}
|
|
@@ -2,8 +2,8 @@ import nodeFs from "node:fs";
|
|
|
2
2
|
import { extname } from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import { dataToEsm } from "@rollup/pluginutils";
|
|
5
|
-
import glob from "fast-glob";
|
|
6
5
|
import pLimit from "p-limit";
|
|
6
|
+
import { glob } from "tinyglobby";
|
|
7
7
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
8
8
|
import { rootRelativePath } from "../core/viteUtils.js";
|
|
9
9
|
import { createDefaultAstroMetadata } from "../vite-plugin-astro/metadata.js";
|
|
@@ -225,7 +225,7 @@ async function generateLookupMap({
|
|
|
225
225
|
{
|
|
226
226
|
absolute: true,
|
|
227
227
|
cwd: fileURLToPath(root),
|
|
228
|
-
|
|
228
|
+
expandDirectories: false
|
|
229
229
|
}
|
|
230
230
|
);
|
|
231
231
|
const limit = pLimit(10);
|
|
@@ -4,26 +4,27 @@ const FORM_CONTENT_TYPES = [
|
|
|
4
4
|
"multipart/form-data",
|
|
5
5
|
"text/plain"
|
|
6
6
|
];
|
|
7
|
+
const SAFE_METHODS = ["GET", "HEAD", "OPTIONS"];
|
|
7
8
|
function createOriginCheckMiddleware() {
|
|
8
9
|
return defineMiddleware((context, next) => {
|
|
9
10
|
const { request, url, isPrerendered } = context;
|
|
10
11
|
if (isPrerendered) {
|
|
11
12
|
return next();
|
|
12
13
|
}
|
|
13
|
-
if (request.method
|
|
14
|
+
if (SAFE_METHODS.includes(request.method)) {
|
|
14
15
|
return next();
|
|
15
16
|
}
|
|
16
|
-
const
|
|
17
|
+
const isSameOrigin = request.headers.get("origin") === url.origin;
|
|
17
18
|
const hasContentType = request.headers.has("content-type");
|
|
18
19
|
if (hasContentType) {
|
|
19
20
|
const formLikeHeader = hasFormLikeHeader(request.headers.get("content-type"));
|
|
20
|
-
if (formLikeHeader && !
|
|
21
|
+
if (formLikeHeader && !isSameOrigin) {
|
|
21
22
|
return new Response(`Cross-site ${request.method} form submissions are forbidden`, {
|
|
22
23
|
status: 403
|
|
23
24
|
});
|
|
24
25
|
}
|
|
25
26
|
} else {
|
|
26
|
-
if (!
|
|
27
|
+
if (!isSameOrigin) {
|
|
27
28
|
return new Response(`Cross-site ${request.method} form submissions are forbidden`, {
|
|
28
29
|
status: 403
|
|
29
30
|
});
|
package/dist/core/app/types.d.ts
CHANGED
|
@@ -38,6 +38,13 @@ export type SSRManifest = {
|
|
|
38
38
|
routes: RouteInfo[];
|
|
39
39
|
site?: string;
|
|
40
40
|
base: string;
|
|
41
|
+
/**
|
|
42
|
+
* The base of the assets generated **by the user**. For example, scripts created by the user falls under this category.
|
|
43
|
+
*
|
|
44
|
+
* The value of this field comes from `vite.base`. We aren't usually this tight to vite in our code base, so probably
|
|
45
|
+
* this should be refactored somehow.
|
|
46
|
+
*/
|
|
47
|
+
userAssetsBase: string | undefined;
|
|
41
48
|
trailingSlash: AstroConfig['trailingSlash'];
|
|
42
49
|
buildFormat: NonNullable<AstroConfig['build']>['format'];
|
|
43
50
|
compressHTML: boolean;
|
|
@@ -388,6 +388,7 @@ function createBuildManifest(settings, internals, renderers, middleware, key) {
|
|
|
388
388
|
compressHTML: settings.config.compressHTML,
|
|
389
389
|
renderers,
|
|
390
390
|
base: settings.config.base,
|
|
391
|
+
userAssetsBase: settings.config?.vite?.base,
|
|
391
392
|
assetsPrefix: settings.config.build.assetsPrefix,
|
|
392
393
|
site: settings.config.site,
|
|
393
394
|
componentMetadata: internals.componentMetadata,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fileURLToPath } from "node:url";
|
|
2
|
-
import glob from "
|
|
2
|
+
import { glob } from "tinyglobby";
|
|
3
3
|
import { getAssetsPrefix } from "../../../assets/utils/getAssetsPrefix.js";
|
|
4
4
|
import { normalizeTheLocale } from "../../../i18n/index.js";
|
|
5
5
|
import { toFallbackType, toRoutingStrategy } from "../../../i18n/utils.js";
|
|
@@ -41,9 +41,7 @@ function vitePluginManifest(options, internals) {
|
|
|
41
41
|
`import { deserializeManifest as _deserializeManifest } from 'astro/app'`,
|
|
42
42
|
`import { _privateSetManifestDontUseThis } from 'astro:ssr-manifest'`
|
|
43
43
|
];
|
|
44
|
-
const resolvedDriver = await resolveSessionDriver(
|
|
45
|
-
options.settings.config.experimental?.session?.driver
|
|
46
|
-
);
|
|
44
|
+
const resolvedDriver = await resolveSessionDriver(options.settings.config.session?.driver);
|
|
47
45
|
const contents = [
|
|
48
46
|
`const manifest = _deserializeManifest('${manifestReplace}');`,
|
|
49
47
|
`if (manifest.sessionConfig) manifest.sessionConfig.driverModule = ${resolvedDriver ? `() => import(${JSON.stringify(resolvedDriver)})` : "null"};`,
|
|
@@ -218,6 +216,7 @@ function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
|
218
216
|
routes,
|
|
219
217
|
site: settings.config.site,
|
|
220
218
|
base: settings.config.base,
|
|
219
|
+
userAssetsBase: settings.config?.vite?.base,
|
|
221
220
|
trailingSlash: settings.config.trailingSlash,
|
|
222
221
|
compressHTML: settings.config.compressHTML,
|
|
223
222
|
assetsPrefix: settings.config.build.assetsPrefix,
|
|
@@ -232,7 +231,7 @@ function buildManifest(opts, internals, staticFiles, encodedKey) {
|
|
|
232
231
|
checkOrigin: (settings.config.security?.checkOrigin && settings.buildOutput === "server") ?? false,
|
|
233
232
|
serverIslandNameMap: Array.from(settings.serverIslandNameMap),
|
|
234
233
|
key: encodedKey,
|
|
235
|
-
sessionConfig: settings.config.
|
|
234
|
+
sessionConfig: settings.config.session
|
|
236
235
|
};
|
|
237
236
|
}
|
|
238
237
|
export {
|
|
@@ -6,7 +6,6 @@ export declare function viteBuild(opts: StaticBuildOptions): Promise<{
|
|
|
6
6
|
ssrOutputChunkNames: string[];
|
|
7
7
|
}>;
|
|
8
8
|
export declare function staticBuild(opts: StaticBuildOptions, internals: BuildInternals, ssrOutputChunkNames: string[]): Promise<void>;
|
|
9
|
-
export declare function copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles?: boolean): Promise<void[] | undefined>;
|
|
10
9
|
/**
|
|
11
10
|
* This function takes the virtual module name of any page entrypoint and
|
|
12
11
|
* transforms it to generate a final `.mjs` output file.
|
|
@@ -2,8 +2,8 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
4
|
import { teardown } from "@astrojs/compiler";
|
|
5
|
-
import glob from "fast-glob";
|
|
6
5
|
import { bgGreen, black, green } from "kleur/colors";
|
|
6
|
+
import { glob } from "tinyglobby";
|
|
7
7
|
import * as vite from "vite";
|
|
8
8
|
import { createBuildInternals } from "../../core/build/internal.js";
|
|
9
9
|
import { emptyDir, removeEmptyDirs } from "../../core/fs/index.js";
|
|
@@ -185,8 +185,8 @@ async function clientBuild(opts, internals, input, container) {
|
|
|
185
185
|
const ssr = settings.buildOutput === "server";
|
|
186
186
|
const out = ssr ? settings.config.build.client : getOutDirWithinCwd(settings.config.outDir);
|
|
187
187
|
if (!input.size) {
|
|
188
|
-
if (ssr) {
|
|
189
|
-
await
|
|
188
|
+
if (ssr && fs.existsSync(settings.config.publicDir)) {
|
|
189
|
+
await fs.promises.cp(settings.config.publicDir, out, { recursive: true, force: true });
|
|
190
190
|
}
|
|
191
191
|
return null;
|
|
192
192
|
}
|
|
@@ -283,29 +283,11 @@ async function cleanServerOutput(opts, ssrOutputChunkNames, internals) {
|
|
|
283
283
|
await Promise.all(
|
|
284
284
|
fileNames.filter((fileName) => fileName.endsWith(".d.ts")).map((fileName) => fs.promises.rm(new URL(fileName, out)))
|
|
285
285
|
);
|
|
286
|
-
await
|
|
286
|
+
await fs.promises.cp(out, opts.settings.config.outDir, { recursive: true, force: true });
|
|
287
287
|
await fs.promises.rm(out, { recursive: true });
|
|
288
288
|
return;
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
|
-
async function copyFiles(fromFolder, toFolder, includeDotfiles = false) {
|
|
292
|
-
const files = await glob("**/*", {
|
|
293
|
-
cwd: fileURLToPath(fromFolder),
|
|
294
|
-
dot: includeDotfiles
|
|
295
|
-
});
|
|
296
|
-
if (files.length === 0) return;
|
|
297
|
-
return await Promise.all(
|
|
298
|
-
files.map(async function copyFile(filename) {
|
|
299
|
-
const from = new URL(filename, fromFolder);
|
|
300
|
-
const to = new URL(filename, toFolder);
|
|
301
|
-
const lastFolder = new URL("./", to);
|
|
302
|
-
return fs.promises.mkdir(lastFolder, { recursive: true }).then(async function fsCopyFile() {
|
|
303
|
-
const p = await fs.promises.copyFile(from, to, fs.constants.COPYFILE_FICLONE);
|
|
304
|
-
return p;
|
|
305
|
-
});
|
|
306
|
-
})
|
|
307
|
-
);
|
|
308
|
-
}
|
|
309
291
|
async function ssrMoveAssets(opts) {
|
|
310
292
|
opts.logger.info("build", "Rearranging server assets...");
|
|
311
293
|
const serverRoot = opts.settings.buildOutput === "static" ? opts.settings.config.build.client : opts.settings.config.build.server;
|
|
@@ -336,7 +318,6 @@ function makeAstroPageEntryPointFileName(prefix, facadeModuleId, routes) {
|
|
|
336
318
|
return `pages${name.replace(/\/$/, "/index").replaceAll(/[[\]]/g, "_").replaceAll("...", "---")}.astro.mjs`;
|
|
337
319
|
}
|
|
338
320
|
export {
|
|
339
|
-
copyFiles,
|
|
340
321
|
makeAstroPageEntryPointFileName,
|
|
341
322
|
staticBuild,
|
|
342
323
|
viteBuild
|