astro 2.1.5 → 2.1.6
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/content/runtime-assets.js +3 -3
- package/dist/content/utils.d.ts +2 -2
- package/dist/content/utils.js +27 -1
- package/dist/content/vite-plugin-content-imports.js +5 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/messages.js +2 -2
- package/dist/vite-plugin-config-alias/index.d.ts +7 -2
- package/dist/vite-plugin-config-alias/index.js +41 -32
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { pathToFileURL } from "url";
|
|
1
2
|
import { z } from "zod";
|
|
2
3
|
import { imageMetadata } from "../assets/utils/metadata.js";
|
|
3
4
|
function createImage(options) {
|
|
@@ -5,9 +6,8 @@ function createImage(options) {
|
|
|
5
6
|
if (options.assetsDir === "undefined") {
|
|
6
7
|
throw new Error("Enable `experimental.assets` in your Astro config to use image()");
|
|
7
8
|
}
|
|
8
|
-
return z.string().transform(async (imagePath) => {
|
|
9
|
-
|
|
10
|
-
return await getImageMetadata(fullPath);
|
|
9
|
+
return z.string({ description: "__image" }).transform(async (imagePath) => {
|
|
10
|
+
return await getImageMetadata(pathToFileURL(imagePath));
|
|
11
11
|
});
|
|
12
12
|
};
|
|
13
13
|
}
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import matter from 'gray-matter';
|
|
3
3
|
import fsMod from 'node:fs';
|
|
4
|
-
import type { EmitFile } from 'rollup';
|
|
4
|
+
import type { EmitFile, PluginContext } from 'rollup';
|
|
5
5
|
import { type ViteDevServer } from 'vite';
|
|
6
6
|
import { z } from 'zod';
|
|
7
7
|
import type { AstroConfig, AstroSettings } from '../@types/astro.js';
|
|
@@ -57,7 +57,7 @@ export declare function getEntrySlug({ id, collection, slug, unvalidatedSlug, }:
|
|
|
57
57
|
export declare function getEntryData(entry: EntryInfo & {
|
|
58
58
|
unvalidatedData: Record<string, unknown>;
|
|
59
59
|
_internal: EntryInternal;
|
|
60
|
-
}, collectionConfig: CollectionConfig): Promise<{
|
|
60
|
+
}, collectionConfig: CollectionConfig, resolver: (idToResolve: string) => ReturnType<PluginContext['resolve']>): Promise<{
|
|
61
61
|
[x: string]: unknown;
|
|
62
62
|
}>;
|
|
63
63
|
export declare function getContentEntryExts(settings: Pick<AstroSettings, 'contentEntryTypes'>): string[];
|
package/dist/content/utils.js
CHANGED
|
@@ -56,7 +56,7 @@ function getEntrySlug({
|
|
|
56
56
|
});
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
|
-
async function getEntryData(entry, collectionConfig) {
|
|
59
|
+
async function getEntryData(entry, collectionConfig, resolver) {
|
|
60
60
|
let { slug, ...data } = entry.unvalidatedData;
|
|
61
61
|
if (collectionConfig.schema) {
|
|
62
62
|
if (typeof collectionConfig.schema === "object" && !("safeParseAsync" in collectionConfig.schema)) {
|
|
@@ -73,6 +73,32 @@ async function getEntryData(entry, collectionConfig) {
|
|
|
73
73
|
message: AstroErrorData.ContentSchemaContainsSlugError.message(entry.collection)
|
|
74
74
|
});
|
|
75
75
|
}
|
|
76
|
+
async function preprocessAssetPaths(object) {
|
|
77
|
+
if (typeof object !== "object" || object === null)
|
|
78
|
+
return;
|
|
79
|
+
for (let [schemaName, schema] of Object.entries(object)) {
|
|
80
|
+
if (schema._def.description === "__image") {
|
|
81
|
+
object[schemaName] = z.preprocess(
|
|
82
|
+
async (value) => {
|
|
83
|
+
var _a;
|
|
84
|
+
if (!value || typeof value !== "string")
|
|
85
|
+
return value;
|
|
86
|
+
return (_a = await resolver(value)) == null ? void 0 : _a.id;
|
|
87
|
+
},
|
|
88
|
+
schema,
|
|
89
|
+
{ description: void 0 }
|
|
90
|
+
);
|
|
91
|
+
} else if ("shape" in schema) {
|
|
92
|
+
await preprocessAssetPaths(schema.shape);
|
|
93
|
+
} else if ("unwrap" in schema) {
|
|
94
|
+
const unwrapped = schema.unwrap().shape;
|
|
95
|
+
if (unwrapped) {
|
|
96
|
+
await preprocessAssetPaths(unwrapped);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
await preprocessAssetPaths(collectionConfig.schema.shape);
|
|
76
102
|
const parsed = await collectionConfig.schema.safeParseAsync(entry.unvalidatedData, {
|
|
77
103
|
errorMap
|
|
78
104
|
});
|
|
@@ -161,7 +161,11 @@ export const _internal = {
|
|
|
161
161
|
const _internal = { filePath: fileId, rawData };
|
|
162
162
|
const slug = getEntrySlug({ id, collection, slug: generatedSlug, unvalidatedSlug });
|
|
163
163
|
const collectionConfig = contentConfig == null ? void 0 : contentConfig.collections[collection];
|
|
164
|
-
let data = collectionConfig ? await getEntryData(
|
|
164
|
+
let data = collectionConfig ? await getEntryData(
|
|
165
|
+
{ id, collection, slug, _internal, unvalidatedData },
|
|
166
|
+
collectionConfig,
|
|
167
|
+
(idToResolve) => pluginContext.resolve(idToResolve, fileId)
|
|
168
|
+
) : unvalidatedData;
|
|
165
169
|
await patchAssets(data, pluginContext.meta.watchMode, pluginContext.emitFile, settings);
|
|
166
170
|
const contentEntryModule = {
|
|
167
171
|
id,
|
package/dist/core/constants.js
CHANGED
package/dist/core/dev/dev.js
CHANGED
|
@@ -52,7 +52,7 @@ async function dev(settings, options) {
|
|
|
52
52
|
isRestart: options.isRestart
|
|
53
53
|
})
|
|
54
54
|
);
|
|
55
|
-
const currentVersion = "2.1.
|
|
55
|
+
const currentVersion = "2.1.6";
|
|
56
56
|
if (currentVersion.includes("-")) {
|
|
57
57
|
warn(options.logging, null, msg.prerelease({ currentVersion }));
|
|
58
58
|
}
|
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.1.
|
|
50
|
+
const version = "2.1.6";
|
|
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.1.
|
|
236
|
+
`v${"2.1.6"}`
|
|
237
237
|
)} ${headline}`
|
|
238
238
|
);
|
|
239
239
|
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import type { AstroSettings } from '../@types/astro';
|
|
2
|
-
import type
|
|
2
|
+
import type * as vite from 'vite';
|
|
3
|
+
/** Result of successfully parsed tsconfig.json or jsconfig.json. */
|
|
4
|
+
export declare interface Alias {
|
|
5
|
+
find: RegExp;
|
|
6
|
+
replacement: string;
|
|
7
|
+
}
|
|
3
8
|
/** Returns a Vite plugin used to alias paths from tsconfig.json and jsconfig.json. */
|
|
4
9
|
export default function configAliasVitePlugin({ settings, }: {
|
|
5
10
|
settings: AstroSettings;
|
|
6
|
-
}):
|
|
11
|
+
}): vite.PluginOption;
|
|
@@ -1,55 +1,64 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
|
|
3
|
-
const getConfigAlias = (
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
const normalize = (pathname) => String(pathname).split(path.sep).join(path.posix.sep);
|
|
3
|
+
const getConfigAlias = (settings) => {
|
|
4
|
+
const config = settings.tsConfig;
|
|
5
|
+
const configPath = settings.tsConfigPath;
|
|
6
|
+
if (!config || !configPath)
|
|
7
|
+
return null;
|
|
8
|
+
const compilerOptions = Object(config.compilerOptions);
|
|
9
|
+
if (!compilerOptions.baseUrl)
|
|
10
|
+
return null;
|
|
11
|
+
const baseUrl = path.posix.resolve(
|
|
12
|
+
path.posix.dirname(normalize(configPath).replace(/^\/?/, "/")),
|
|
13
|
+
normalize(compilerOptions.baseUrl)
|
|
14
|
+
);
|
|
4
15
|
const aliases = [];
|
|
5
|
-
for (
|
|
16
|
+
for (let [alias, values] of Object.entries(
|
|
17
|
+
Object(compilerOptions.paths)
|
|
18
|
+
)) {
|
|
19
|
+
values = [].concat(values);
|
|
6
20
|
const find = new RegExp(
|
|
7
21
|
`^${[...alias].map(
|
|
8
22
|
(segment) => segment === "*" ? "(.+)" : segment.replace(/[\\^$*+?.()|[\]{}]/, "\\$&")
|
|
9
23
|
).join("")}$`
|
|
10
24
|
);
|
|
11
25
|
let matchId = 0;
|
|
12
|
-
for (
|
|
26
|
+
for (let value of values) {
|
|
13
27
|
const replacement = [...path.posix.resolve(baseUrl, value)].map((segment) => segment === "*" ? `$${++matchId}` : segment === "$" ? "$$" : segment).join("");
|
|
14
28
|
aliases.push({ find, replacement });
|
|
15
29
|
}
|
|
16
30
|
}
|
|
31
|
+
aliases.push({
|
|
32
|
+
find: /^(?!\.*\/)(.+)$/,
|
|
33
|
+
replacement: `${[...baseUrl].map((segment) => segment === "$" ? "$$" : segment).join("")}/$1`
|
|
34
|
+
});
|
|
17
35
|
return aliases;
|
|
18
36
|
};
|
|
19
37
|
function configAliasVitePlugin({
|
|
20
38
|
settings
|
|
21
39
|
}) {
|
|
22
|
-
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (!baseUrl || !paths)
|
|
27
|
-
return null;
|
|
28
|
-
const resolvedBaseUrl = path.posix.resolve(
|
|
29
|
-
path.posix.dirname(slash(tsConfigPath).replace(/^\/?/, "/")),
|
|
30
|
-
slash(baseUrl)
|
|
31
|
-
);
|
|
32
|
-
const configAlias = getConfigAlias(paths, resolvedBaseUrl);
|
|
40
|
+
const { config } = settings;
|
|
41
|
+
const configAlias = getConfigAlias(settings);
|
|
42
|
+
if (!configAlias)
|
|
43
|
+
return {};
|
|
33
44
|
return {
|
|
34
45
|
name: "astro:tsconfig-alias",
|
|
35
46
|
enforce: "pre",
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
async resolveId(sourceId, importer, options) {
|
|
48
|
+
const resolvedId = await this.resolve(sourceId, importer, { skipSelf: true, ...options });
|
|
49
|
+
if (resolvedId)
|
|
50
|
+
return resolvedId;
|
|
51
|
+
for (const alias of configAlias) {
|
|
52
|
+
if (alias.find.test(sourceId)) {
|
|
53
|
+
const aliasedSourceId = sourceId.replace(alias.find, alias.replacement);
|
|
54
|
+
const resolvedAliasedId = await this.resolve(aliasedSourceId, importer, {
|
|
55
|
+
skipSelf: true,
|
|
56
|
+
...options
|
|
57
|
+
});
|
|
58
|
+
if (resolvedAliasedId)
|
|
59
|
+
return resolvedAliasedId;
|
|
60
|
+
}
|
|
43
61
|
}
|
|
44
|
-
},
|
|
45
|
-
async resolveId(id, importer, options) {
|
|
46
|
-
if (id.startsWith(".") || path.isAbsolute(id))
|
|
47
|
-
return;
|
|
48
|
-
const resolved = path.posix.join(resolvedBaseUrl, id);
|
|
49
|
-
return await this.resolve(resolved, importer, {
|
|
50
|
-
skipSelf: true,
|
|
51
|
-
...options
|
|
52
|
-
});
|
|
53
62
|
}
|
|
54
63
|
};
|
|
55
64
|
}
|