astro 2.1.1 → 2.1.3
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/client-base.d.ts +2 -1
- package/client-image.d.ts +7 -14
- package/dist/@types/astro.d.ts +2 -2
- package/dist/assets/consts.d.ts +5 -1
- package/dist/assets/consts.js +0 -3
- package/dist/assets/internal.d.ts +1 -1
- package/dist/assets/services/service.d.ts +5 -3
- package/dist/assets/types.d.ts +3 -3
- package/dist/assets/utils/emitAsset.d.ts +2 -0
- package/dist/assets/utils/emitAsset.js +31 -0
- package/dist/assets/utils/metadata.d.ts +1 -1
- package/dist/assets/utils/metadata.js +4 -3
- package/dist/assets/utils/queryParams.d.ts +1 -1
- package/dist/assets/utils/transformToPath.d.ts +1 -1
- package/dist/assets/vite-plugin-assets.d.ts +1 -1
- package/dist/assets/vite-plugin-assets.js +31 -28
- package/dist/content/error-map.d.ts +2 -0
- package/dist/content/error-map.js +75 -0
- package/dist/content/index.d.ts +1 -0
- package/dist/content/index.js +2 -0
- package/dist/content/runtime-assets.d.ts +8 -0
- package/dist/content/runtime-assets.js +24 -0
- package/dist/content/{internal.d.ts → runtime.d.ts} +1 -19
- package/dist/content/{internal.js → runtime.js} +28 -43
- package/dist/content/template/virtual-mod-assets.d.mts +1 -0
- package/dist/content/template/virtual-mod.d.mts +0 -1
- package/dist/content/utils.d.ts +7 -2
- package/dist/content/utils.js +18 -26
- package/dist/content/vite-plugin-content-assets.d.ts +2 -2
- package/dist/content/vite-plugin-content-imports.d.ts +1 -1
- package/dist/content/vite-plugin-content-imports.js +4 -10
- package/dist/content/vite-plugin-content-virtual-mod.js +4 -2
- package/dist/core/add/index.js +15 -0
- package/dist/core/app/node.d.ts +1 -1
- package/dist/core/build/add-rollup-input.d.ts +1 -1
- package/dist/core/build/css-asset-name.d.ts +1 -1
- package/dist/core/build/index.d.ts +1 -1
- package/dist/core/build/internal.d.ts +16 -6
- package/dist/core/build/internal.js +2 -2
- package/dist/core/build/plugins/index.js +2 -0
- package/dist/core/build/plugins/plugin-alias-resolve.d.ts +1 -1
- package/dist/core/build/plugins/plugin-analyzer.js +12 -2
- package/dist/core/build/plugins/plugin-component-entry.d.ts +11 -0
- package/dist/core/build/plugins/plugin-component-entry.js +74 -0
- package/dist/core/build/plugins/plugin-hoisted-scripts.d.ts +2 -2
- package/dist/core/build/plugins/plugin-internals.js +2 -1
- package/dist/core/build/plugins/plugin-ssr.d.ts +1 -1
- package/dist/core/build/static-build.js +2 -2
- package/dist/core/config/config.d.ts +1 -1
- package/dist/core/config/schema.d.ts +1 -1
- package/dist/core/constants.js +1 -1
- package/dist/core/create-vite.js +5 -1
- package/dist/core/dev/container.d.ts +2 -2
- package/dist/core/dev/dev.d.ts +2 -2
- package/dist/core/dev/dev.js +1 -1
- package/dist/core/errors/errors-data.js +3 -1
- package/dist/core/errors/errors.d.ts +1 -1
- package/dist/core/errors/utils.d.ts +1 -1
- package/dist/core/messages.d.ts +2 -2
- package/dist/core/messages.js +2 -2
- package/dist/core/preview/static-preview-server.d.ts +1 -1
- package/dist/core/preview/vite-plugin-astro-preview.d.ts +2 -2
- package/dist/core/render/dev/css.d.ts +1 -1
- package/dist/core/render/paginate.d.ts +1 -1
- package/dist/core/sync/index.js +1 -0
- package/dist/events/error.d.ts +1 -1
- package/dist/integrations/index.d.ts +1 -1
- package/dist/runtime/server/jsx.d.ts +1 -1
- package/dist/runtime/server/render/tags.d.ts +1 -1
- package/dist/vite-plugin-astro/compile.d.ts +1 -1
- package/dist/vite-plugin-astro-server/plugin.d.ts +1 -1
- package/dist/vite-plugin-astro-server/route.d.ts +1 -1
- package/dist/vite-plugin-head-propagation/index.d.ts +1 -1
- package/dist/vite-plugin-html/transform/slots.d.ts +1 -1
- package/dist/vite-plugin-html/transform/utils.d.ts +1 -1
- package/dist/vite-plugin-inject-env-ts/index.js +3 -1
- package/dist/vite-plugin-integrations-container/index.d.ts +3 -3
- package/dist/vite-plugin-jsx/import-source.d.ts +2 -2
- package/dist/vite-plugin-markdown/content-entry-type.d.ts +1 -1
- package/dist/vite-plugin-scanner/index.d.ts +1 -1
- package/dist/vite-plugin-scanner/scan.d.ts +1 -1
- package/dist/vite-plugin-scripts/index.d.ts +2 -2
- package/dist/vite-plugin-scripts/page-ssr.d.ts +1 -1
- package/package.json +4 -2
- package/src/content/template/virtual-mod-assets.mjs +7 -0
- package/src/content/template/virtual-mod.mjs +1 -7
package/client-base.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ declare module 'astro:assets' {
|
|
|
4
4
|
// Exporting things one by one is a bit cumbersome, not sure if there's a better way - erika, 2023-02-03
|
|
5
5
|
type AstroAssets = {
|
|
6
6
|
getImage: typeof import('./dist/assets/index.js').getImage;
|
|
7
|
+
getConfiguredImageService: typeof import('./dist/assets/index.js').getConfiguredImageService;
|
|
7
8
|
Image: typeof import('./components/Image.astro').default;
|
|
8
9
|
};
|
|
9
10
|
|
|
@@ -20,7 +21,7 @@ declare module 'astro:assets' {
|
|
|
20
21
|
export type RemoteImageProps = Simplify<
|
|
21
22
|
import('./dist/assets/types.js').RemoteImageProps<ImgAttributes>
|
|
22
23
|
>;
|
|
23
|
-
export const { getImage, Image }: AstroAssets;
|
|
24
|
+
export const { getImage, getConfiguredImageService, Image }: AstroAssets;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
type MD = import('./dist/@types/astro').MarkdownInstance<Record<string, any>>;
|
package/client-image.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
/// <reference path="./client-base.d.ts" />
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
// TODO: Merge this file with `client-base.d.ts` in 3.0, when the `astro:assets` feature isn't under a flag anymore.
|
|
4
|
+
|
|
5
|
+
type InputFormat = import('./dist/assets/types.js').InputFormat;
|
|
4
6
|
|
|
5
7
|
interface ImageMetadata {
|
|
6
8
|
src: string;
|
|
@@ -9,23 +11,10 @@ interface ImageMetadata {
|
|
|
9
11
|
format: InputFormat;
|
|
10
12
|
}
|
|
11
13
|
|
|
12
|
-
// images
|
|
13
|
-
declare module '*.avif' {
|
|
14
|
-
const metadata: ImageMetadata;
|
|
15
|
-
export default metadata;
|
|
16
|
-
}
|
|
17
14
|
declare module '*.gif' {
|
|
18
15
|
const metadata: ImageMetadata;
|
|
19
16
|
export default metadata;
|
|
20
17
|
}
|
|
21
|
-
declare module '*.heic' {
|
|
22
|
-
const metadata: ImageMetadata;
|
|
23
|
-
export default metadata;
|
|
24
|
-
}
|
|
25
|
-
declare module '*.heif' {
|
|
26
|
-
const metadata: ImageMetadata;
|
|
27
|
-
export default metadata;
|
|
28
|
-
}
|
|
29
18
|
declare module '*.jpeg' {
|
|
30
19
|
const metadata: ImageMetadata;
|
|
31
20
|
export default metadata;
|
|
@@ -46,3 +35,7 @@ declare module '*.webp' {
|
|
|
46
35
|
const metadata: ImageMetadata;
|
|
47
36
|
export default metadata;
|
|
48
37
|
}
|
|
38
|
+
declare module '*.svg' {
|
|
39
|
+
const metadata: ImageMetadata;
|
|
40
|
+
export default metadata;
|
|
41
|
+
}
|
package/dist/@types/astro.d.ts
CHANGED
|
@@ -15,10 +15,10 @@ import type { AstroTimer } from '../core/config/timer';
|
|
|
15
15
|
import type { AstroCookies } from '../core/cookies';
|
|
16
16
|
import type { LogOptions } from '../core/logger/core';
|
|
17
17
|
import type { AstroComponentFactory, AstroComponentInstance } from '../runtime/server';
|
|
18
|
-
import { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
|
|
18
|
+
import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js';
|
|
19
19
|
export type { MarkdownHeading, MarkdownMetadata, MarkdownRenderingResult, RehypePlugins, RemarkPlugins, ShikiConfig, } from '@astrojs/markdown-remark';
|
|
20
20
|
export type { ExternalImageService, LocalImageService } from '../assets/services/service';
|
|
21
|
-
export type { ImageTransform } from '../assets/types';
|
|
21
|
+
export type { ImageMetadata, ImageTransform } from '../assets/types';
|
|
22
22
|
export type { SSRManifest } from '../core/app/types';
|
|
23
23
|
export type { AstroCookies } from '../core/cookies';
|
|
24
24
|
export interface AstroBuiltinProps {
|
package/dist/assets/consts.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export declare const VIRTUAL_MODULE_ID = "astro:assets";
|
|
2
2
|
export declare const VIRTUAL_SERVICE_ID = "virtual:image-service";
|
|
3
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Valid formats for optimizations in our base services.
|
|
5
|
+
* Certain formats can be imported (namely SVGs) but not optimized, so they are excluded from this list.
|
|
6
|
+
*/
|
|
7
|
+
export declare const VALID_INPUT_FORMATS: readonly ["jpeg", "jpg", "png", "tiff", "webp", "gif"];
|
|
4
8
|
export declare const VALID_OUTPUT_FORMATS: readonly ["avif", "png", "webp", "jpeg", "jpg"];
|
package/dist/assets/consts.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { StaticBuildOptions } from '../core/build/types.js';
|
|
1
|
+
import type { StaticBuildOptions } from '../core/build/types.js';
|
|
2
2
|
import { ImageService } from './services/service.js';
|
|
3
3
|
import type { ImageMetadata, ImageTransform } from './types.js';
|
|
4
4
|
export declare function isESMImportedImage(src: ImageMetadata | string): src is ImageMetadata;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { ImageTransform, OutputFormat } from '../types.js';
|
|
2
|
+
import type { ImageTransform, OutputFormat } from '../types.js';
|
|
3
3
|
export type ImageService = LocalImageService | ExternalImageService;
|
|
4
4
|
export declare function isLocalService(service: ImageService | undefined): service is LocalImageService;
|
|
5
5
|
export declare function parseQuality(quality: string): string | number;
|
|
@@ -63,8 +63,10 @@ export type BaseServiceTransform = {
|
|
|
63
63
|
* }
|
|
64
64
|
* ```
|
|
65
65
|
*
|
|
66
|
-
* This service
|
|
67
|
-
*
|
|
66
|
+
* This service adhere to the included services limitations:
|
|
67
|
+
* - Remote images are passed as is.
|
|
68
|
+
* - Only a limited amount of formats are supported.
|
|
69
|
+
* - For remote images, `width` and `height` are always required.
|
|
68
70
|
*
|
|
69
71
|
*/
|
|
70
72
|
export declare const baseService: Omit<LocalImageService, 'transform'>;
|
package/dist/assets/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { VALID_INPUT_FORMATS, VALID_OUTPUT_FORMATS } from './consts.js';
|
|
2
|
-
import { ImageService } from './services/service.js';
|
|
1
|
+
import type { VALID_INPUT_FORMATS, VALID_OUTPUT_FORMATS } from './consts.js';
|
|
2
|
+
import type { ImageService } from './services/service.js';
|
|
3
3
|
export type ImageQualityPreset = 'low' | 'mid' | 'high' | 'max' | (string & {});
|
|
4
4
|
export type ImageQuality = ImageQualityPreset | number;
|
|
5
|
-
export type InputFormat = (typeof VALID_INPUT_FORMATS)[number] |
|
|
5
|
+
export type InputFormat = (typeof VALID_INPUT_FORMATS)[number] | 'svg';
|
|
6
6
|
export type OutputFormat = (typeof VALID_OUTPUT_FORMATS)[number] | (string & {});
|
|
7
7
|
declare global {
|
|
8
8
|
var astroAsset: {
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
4
|
+
import { rootRelativePath } from "../../core/util.js";
|
|
5
|
+
import { imageMetadata } from "./metadata.js";
|
|
6
|
+
async function emitESMImage(id, watchMode, fileEmitter, settings) {
|
|
7
|
+
const url = pathToFileURL(id);
|
|
8
|
+
const meta = await imageMetadata(url);
|
|
9
|
+
if (!meta) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (!watchMode) {
|
|
13
|
+
const pathname = decodeURI(url.pathname);
|
|
14
|
+
const filename = path.basename(pathname, path.extname(pathname) + `.${meta.format}`);
|
|
15
|
+
const handle = fileEmitter({
|
|
16
|
+
name: filename,
|
|
17
|
+
source: await fs.promises.readFile(url),
|
|
18
|
+
type: "asset"
|
|
19
|
+
});
|
|
20
|
+
meta.src = `__ASTRO_ASSET_IMAGE__${handle}__`;
|
|
21
|
+
} else {
|
|
22
|
+
url.searchParams.append("origWidth", meta.width.toString());
|
|
23
|
+
url.searchParams.append("origHeight", meta.height.toString());
|
|
24
|
+
url.searchParams.append("origFormat", meta.format);
|
|
25
|
+
meta.src = rootRelativePath(settings.config, url);
|
|
26
|
+
}
|
|
27
|
+
return meta;
|
|
28
|
+
}
|
|
29
|
+
export {
|
|
30
|
+
emitESMImage
|
|
31
|
+
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { createRequire } from "module";
|
|
2
1
|
import fs from "node:fs/promises";
|
|
3
2
|
import { fileURLToPath } from "node:url";
|
|
4
|
-
|
|
5
|
-
const sizeOf = require2("image-size");
|
|
3
|
+
let sizeOf;
|
|
6
4
|
async function imageMetadata(src, data) {
|
|
5
|
+
if (!sizeOf) {
|
|
6
|
+
sizeOf = await import("image-size").then((mod) => mod.default);
|
|
7
|
+
}
|
|
7
8
|
let file = data;
|
|
8
9
|
if (!file) {
|
|
9
10
|
try {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ImageMetadata } from '../types.js';
|
|
1
|
+
import type { ImageMetadata } from '../types.js';
|
|
2
2
|
export declare function getOrigQueryParams(params: URLSearchParams): Omit<ImageMetadata, 'src'> | undefined;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { ImageTransform } from '../types.js';
|
|
1
|
+
import type { ImageTransform } from '../types.js';
|
|
2
2
|
export declare function propsToFilename(transform: ImageTransform): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type * as vite from 'vite';
|
|
2
|
-
import { AstroPluginOptions } from '../@types/astro';
|
|
2
|
+
import type { AstroPluginOptions } from '../@types/astro';
|
|
3
3
|
export default function assets({ settings, logging, mode, }: AstroPluginOptions & {
|
|
4
4
|
mode: string;
|
|
5
5
|
}): vite.Plugin[];
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
+
import { bold } from "kleur/colors";
|
|
1
2
|
import MagicString from "magic-string";
|
|
2
3
|
import mime from "mime";
|
|
3
4
|
import fs from "node:fs/promises";
|
|
4
|
-
import path from "node:path";
|
|
5
5
|
import { Readable } from "node:stream";
|
|
6
|
-
import { fileURLToPath
|
|
6
|
+
import { fileURLToPath } from "node:url";
|
|
7
7
|
import { normalizePath } from "vite";
|
|
8
8
|
import { error } from "../core/logger/core.js";
|
|
9
9
|
import { joinPaths, prependForwardSlash } from "../core/path.js";
|
|
10
|
-
import { rootRelativePath } from "../core/util.js";
|
|
11
10
|
import { VIRTUAL_MODULE_ID, VIRTUAL_SERVICE_ID } from "./consts.js";
|
|
12
11
|
import { isESMImportedImage } from "./internal.js";
|
|
13
12
|
import { isLocalService } from "./services/service.js";
|
|
14
13
|
import { copyWasmFiles } from "./services/vendor/squoosh/copy-wasm.js";
|
|
14
|
+
import { emitESMImage } from "./utils/emitAsset.js";
|
|
15
15
|
import { imageMetadata } from "./utils/metadata.js";
|
|
16
16
|
import { getOrigQueryParams } from "./utils/queryParams.js";
|
|
17
17
|
import { propsToFilename } from "./utils/transformToPath.js";
|
|
@@ -21,8 +21,27 @@ function assets({
|
|
|
21
21
|
logging,
|
|
22
22
|
mode
|
|
23
23
|
}) {
|
|
24
|
+
var _a;
|
|
24
25
|
let resolvedConfig;
|
|
25
26
|
globalThis.astroAsset = {};
|
|
27
|
+
const UNSUPPORTED_ADAPTERS = /* @__PURE__ */ new Set([
|
|
28
|
+
"@astrojs/cloudflare",
|
|
29
|
+
"@astrojs/deno",
|
|
30
|
+
"@astrojs/netlify/edge-functions",
|
|
31
|
+
"@astrojs/vercel/edge"
|
|
32
|
+
]);
|
|
33
|
+
const adapterName = (_a = settings.config.adapter) == null ? void 0 : _a.name;
|
|
34
|
+
if (["astro/assets/services/sharp", "astro/assets/services/squoosh"].includes(
|
|
35
|
+
settings.config.image.service
|
|
36
|
+
) && adapterName && UNSUPPORTED_ADAPTERS.has(adapterName)) {
|
|
37
|
+
error(
|
|
38
|
+
logging,
|
|
39
|
+
"assets",
|
|
40
|
+
`The currently selected adapter \`${adapterName}\` does not run on Node, however the currently used image service depends on Node built-ins. ${bold(
|
|
41
|
+
"Your project will NOT be able to build."
|
|
42
|
+
)}`
|
|
43
|
+
);
|
|
44
|
+
}
|
|
26
45
|
return [
|
|
27
46
|
{
|
|
28
47
|
name: "astro:assets",
|
|
@@ -56,8 +75,8 @@ function assets({
|
|
|
56
75
|
},
|
|
57
76
|
configureServer(server) {
|
|
58
77
|
server.middlewares.use(async (req, res, next) => {
|
|
59
|
-
var
|
|
60
|
-
if ((
|
|
78
|
+
var _a2;
|
|
79
|
+
if ((_a2 = req.url) == null ? void 0 : _a2.startsWith("/_image")) {
|
|
61
80
|
if (!isLocalService(globalThis.astroAsset.imageService)) {
|
|
62
81
|
return next();
|
|
63
82
|
}
|
|
@@ -66,8 +85,8 @@ function assets({
|
|
|
66
85
|
if (!filePath) {
|
|
67
86
|
return next();
|
|
68
87
|
}
|
|
69
|
-
const filePathURL = new URL(filePath,
|
|
70
|
-
const file = await fs.readFile(filePathURL
|
|
88
|
+
const filePathURL = new URL("." + filePath, settings.config.root);
|
|
89
|
+
const file = await fs.readFile(filePathURL);
|
|
71
90
|
let meta = getOrigQueryParams(filePathURL.searchParams);
|
|
72
91
|
if (!meta) {
|
|
73
92
|
meta = await imageMetadata(filePathURL, file);
|
|
@@ -86,7 +105,10 @@ function assets({
|
|
|
86
105
|
data = result.data;
|
|
87
106
|
format = result.format;
|
|
88
107
|
}
|
|
89
|
-
res.setHeader(
|
|
108
|
+
res.setHeader(
|
|
109
|
+
"Content-Type",
|
|
110
|
+
mime.getType(fileURLToPath(filePathURL)) || `image/${format}`
|
|
111
|
+
);
|
|
90
112
|
res.setHeader("Cache-Control", "max-age=360000");
|
|
91
113
|
const stream = Readable.from(data);
|
|
92
114
|
return stream.pipe(res);
|
|
@@ -157,26 +179,7 @@ function assets({
|
|
|
157
179
|
},
|
|
158
180
|
async load(id) {
|
|
159
181
|
if (/\.(jpeg|jpg|png|tiff|webp|gif|svg)$/.test(id)) {
|
|
160
|
-
const
|
|
161
|
-
const meta = await imageMetadata(url);
|
|
162
|
-
if (!meta) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (!this.meta.watchMode) {
|
|
166
|
-
const pathname = decodeURI(url.pathname);
|
|
167
|
-
const filename = path.basename(pathname, path.extname(pathname) + `.${meta.format}`);
|
|
168
|
-
const handle = this.emitFile({
|
|
169
|
-
name: filename,
|
|
170
|
-
source: await fs.readFile(url),
|
|
171
|
-
type: "asset"
|
|
172
|
-
});
|
|
173
|
-
meta.src = `__ASTRO_ASSET_IMAGE__${handle}__`;
|
|
174
|
-
} else {
|
|
175
|
-
url.searchParams.append("origWidth", meta.width.toString());
|
|
176
|
-
url.searchParams.append("origHeight", meta.height.toString());
|
|
177
|
-
url.searchParams.append("origFormat", meta.format);
|
|
178
|
-
meta.src = rootRelativePath(settings.config, url);
|
|
179
|
-
}
|
|
182
|
+
const meta = await emitESMImage(id, this.meta.watchMode, this.emitFile, settings);
|
|
180
183
|
return `export default ${JSON.stringify(meta)}`;
|
|
181
184
|
}
|
|
182
185
|
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
const errorMap = (baseError, ctx) => {
|
|
2
|
+
const baseErrorPath = flattenErrorPath(baseError.path);
|
|
3
|
+
if (baseError.code === "invalid_union") {
|
|
4
|
+
let typeOrLiteralErrByPath = /* @__PURE__ */ new Map();
|
|
5
|
+
for (const unionError of baseError.unionErrors.map((e) => e.errors).flat()) {
|
|
6
|
+
if (unionError.code === "invalid_type" || unionError.code === "invalid_literal") {
|
|
7
|
+
const flattenedErrorPath = flattenErrorPath(unionError.path);
|
|
8
|
+
if (typeOrLiteralErrByPath.has(flattenedErrorPath)) {
|
|
9
|
+
typeOrLiteralErrByPath.get(flattenedErrorPath).expected.push(unionError.expected);
|
|
10
|
+
} else {
|
|
11
|
+
typeOrLiteralErrByPath.set(flattenedErrorPath, {
|
|
12
|
+
code: unionError.code,
|
|
13
|
+
received: unionError.received,
|
|
14
|
+
expected: [unionError.expected]
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
let messages = [
|
|
20
|
+
prefix(
|
|
21
|
+
baseErrorPath,
|
|
22
|
+
typeOrLiteralErrByPath.size ? "Did not match union:" : "Did not match union."
|
|
23
|
+
)
|
|
24
|
+
];
|
|
25
|
+
return {
|
|
26
|
+
message: messages.concat(
|
|
27
|
+
[...typeOrLiteralErrByPath.entries()].filter(([, error]) => error.expected.length === baseError.unionErrors.length).map(
|
|
28
|
+
([key, error]) => key === baseErrorPath ? `> ${getTypeOrLiteralMsg(error)}` : `> ${prefix(key, getTypeOrLiteralMsg(error))}`
|
|
29
|
+
)
|
|
30
|
+
).join("\n")
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
if (baseError.code === "invalid_literal" || baseError.code === "invalid_type") {
|
|
34
|
+
return {
|
|
35
|
+
message: prefix(
|
|
36
|
+
baseErrorPath,
|
|
37
|
+
getTypeOrLiteralMsg({
|
|
38
|
+
code: baseError.code,
|
|
39
|
+
received: baseError.received,
|
|
40
|
+
expected: [baseError.expected]
|
|
41
|
+
})
|
|
42
|
+
)
|
|
43
|
+
};
|
|
44
|
+
} else if (baseError.message) {
|
|
45
|
+
return { message: prefix(baseErrorPath, baseError.message) };
|
|
46
|
+
} else {
|
|
47
|
+
return { message: prefix(baseErrorPath, ctx.defaultError) };
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const getTypeOrLiteralMsg = (error) => {
|
|
51
|
+
if (error.received === "undefined")
|
|
52
|
+
return "Required";
|
|
53
|
+
const expectedDeduped = new Set(error.expected);
|
|
54
|
+
switch (error.code) {
|
|
55
|
+
case "invalid_type":
|
|
56
|
+
return `Expected type \`${unionExpectedVals(expectedDeduped)}\`, received ${JSON.stringify(
|
|
57
|
+
error.received
|
|
58
|
+
)}`;
|
|
59
|
+
case "invalid_literal":
|
|
60
|
+
return `Expected \`${unionExpectedVals(expectedDeduped)}\`, received ${JSON.stringify(
|
|
61
|
+
error.received
|
|
62
|
+
)}`;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const prefix = (key, msg) => key.length ? `**${key}**: ${msg}` : msg;
|
|
66
|
+
const unionExpectedVals = (expectedVals) => [...expectedVals].map((expectedVal, idx) => {
|
|
67
|
+
if (idx === 0)
|
|
68
|
+
return JSON.stringify(expectedVal);
|
|
69
|
+
const sep = " | ";
|
|
70
|
+
return `${sep}${JSON.stringify(expectedVal)}`;
|
|
71
|
+
}).join("");
|
|
72
|
+
const flattenErrorPath = (errorPath) => errorPath.join(".");
|
|
73
|
+
export {
|
|
74
|
+
errorMap
|
|
75
|
+
};
|
package/dist/content/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { errorMap } from './error-map.js';
|
|
1
2
|
export { attachContentServerListeners } from './server-listeners.js';
|
|
2
3
|
export { createContentTypesGenerator } from './types-generator.js';
|
|
3
4
|
export { contentObservable, getContentPaths, getDotAstroTypeReference } from './utils.js';
|
package/dist/content/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { errorMap } from "./error-map.js";
|
|
1
2
|
import { attachContentServerListeners } from "./server-listeners.js";
|
|
2
3
|
import { createContentTypesGenerator } from "./types-generator.js";
|
|
3
4
|
import { contentObservable, getContentPaths, getDotAstroTypeReference } from "./utils.js";
|
|
@@ -11,6 +12,7 @@ export {
|
|
|
11
12
|
attachContentServerListeners,
|
|
12
13
|
contentObservable,
|
|
13
14
|
createContentTypesGenerator,
|
|
15
|
+
errorMap,
|
|
14
16
|
getContentPaths,
|
|
15
17
|
getDotAstroTypeReference
|
|
16
18
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { type Metadata } from '../assets/utils/metadata.js';
|
|
3
|
+
export declare function createImage(options: {
|
|
4
|
+
assetsDir: string;
|
|
5
|
+
relAssetsDir: string;
|
|
6
|
+
}): () => z.ZodEffects<z.ZodString, (Metadata & {
|
|
7
|
+
__astro_asset: true;
|
|
8
|
+
}) | undefined, string>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { imageMetadata } from "../assets/utils/metadata.js";
|
|
3
|
+
function createImage(options) {
|
|
4
|
+
return () => {
|
|
5
|
+
if (options.assetsDir === "undefined") {
|
|
6
|
+
throw new Error("Enable `experimental.assets` in your Astro config to use image()");
|
|
7
|
+
}
|
|
8
|
+
return z.string().transform(async (imagePath) => {
|
|
9
|
+
const fullPath = new URL(imagePath, options.assetsDir);
|
|
10
|
+
return await getImageMetadata(fullPath);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async function getImageMetadata(imagePath) {
|
|
15
|
+
const meta = await imageMetadata(imagePath);
|
|
16
|
+
if (!meta) {
|
|
17
|
+
return void 0;
|
|
18
|
+
}
|
|
19
|
+
delete meta.orientation;
|
|
20
|
+
return { ...meta, __astro_asset: true };
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
createImage
|
|
24
|
+
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { type Metadata } from '../assets/utils/metadata.js';
|
|
3
1
|
type GlobResult = Record<string, () => Promise<any>>;
|
|
4
2
|
type CollectionToEntryMap = Record<string, GlobResult>;
|
|
5
3
|
export declare function createCollectionToGlobResultMap({ globResult, contentDir, }: {
|
|
@@ -9,18 +7,7 @@ export declare function createCollectionToGlobResultMap({ globResult, contentDir
|
|
|
9
7
|
export declare function createGetCollection({ collectionToEntryMap, collectionToRenderEntryMap, }: {
|
|
10
8
|
collectionToEntryMap: CollectionToEntryMap;
|
|
11
9
|
collectionToRenderEntryMap: CollectionToEntryMap;
|
|
12
|
-
}): (collection: string, filter?: ((entry: any) => unknown) | undefined) => Promise<
|
|
13
|
-
id: any;
|
|
14
|
-
slug: any;
|
|
15
|
-
body: any;
|
|
16
|
-
collection: any;
|
|
17
|
-
data: any;
|
|
18
|
-
render(): Promise<{
|
|
19
|
-
Content: import("../runtime/server/index.js").AstroComponentFactory;
|
|
20
|
-
headings: any;
|
|
21
|
-
remarkPluginFrontmatter: any;
|
|
22
|
-
}>;
|
|
23
|
-
}[]>;
|
|
10
|
+
}): (collection: string, filter?: ((entry: any) => unknown) | undefined) => Promise<any[]>;
|
|
24
11
|
export declare function createGetEntryBySlug({ getCollection, collectionToRenderEntryMap, }: {
|
|
25
12
|
getCollection: ReturnType<typeof createGetCollection>;
|
|
26
13
|
collectionToRenderEntryMap: CollectionToEntryMap;
|
|
@@ -36,9 +23,4 @@ export declare function createGetEntryBySlug({ getCollection, collectionToRender
|
|
|
36
23
|
remarkPluginFrontmatter: any;
|
|
37
24
|
}>;
|
|
38
25
|
} | undefined>;
|
|
39
|
-
export declare function createImage(options: {
|
|
40
|
-
assetsDir: string;
|
|
41
|
-
}): () => z.ZodEffects<z.ZodString, (Metadata & {
|
|
42
|
-
__astro_asset: true;
|
|
43
|
-
}) | undefined, string>;
|
|
44
26
|
export {};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import { z } from "zod";
|
|
2
|
-
import { imageMetadata } from "../assets/utils/metadata.js";
|
|
3
1
|
import { AstroError, AstroErrorData } from "../core/errors/index.js";
|
|
4
2
|
import { prependForwardSlash } from "../core/path.js";
|
|
5
3
|
import {
|
|
@@ -30,33 +28,40 @@ function createCollectionToGlobResultMap({
|
|
|
30
28
|
}
|
|
31
29
|
return collectionToGlobResultMap;
|
|
32
30
|
}
|
|
31
|
+
const cacheEntriesByCollection = /* @__PURE__ */ new Map();
|
|
33
32
|
function createGetCollection({
|
|
34
33
|
collectionToEntryMap,
|
|
35
34
|
collectionToRenderEntryMap
|
|
36
35
|
}) {
|
|
37
36
|
return async function getCollection(collection, filter) {
|
|
38
37
|
const lazyImports = Object.values(collectionToEntryMap[collection] ?? {});
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
38
|
+
let entries = [];
|
|
39
|
+
if (import.meta.env.PROD && cacheEntriesByCollection.has(collection)) {
|
|
40
|
+
entries = cacheEntriesByCollection.get(collection);
|
|
41
|
+
} else {
|
|
42
|
+
entries = await Promise.all(
|
|
43
|
+
lazyImports.map(async (lazyImport) => {
|
|
44
|
+
const entry = await lazyImport();
|
|
45
|
+
return {
|
|
46
|
+
id: entry.id,
|
|
47
|
+
slug: entry.slug,
|
|
48
|
+
body: entry.body,
|
|
49
|
+
collection: entry.collection,
|
|
50
|
+
data: entry.data,
|
|
51
|
+
async render() {
|
|
52
|
+
return render({
|
|
53
|
+
collection: entry.collection,
|
|
54
|
+
id: entry.id,
|
|
55
|
+
collectionToRenderEntryMap
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
})
|
|
60
|
+
);
|
|
61
|
+
cacheEntriesByCollection.set(collection, entries);
|
|
62
|
+
}
|
|
58
63
|
if (typeof filter === "function") {
|
|
59
|
-
return
|
|
64
|
+
return entries.filter(filter);
|
|
60
65
|
} else {
|
|
61
66
|
return entries;
|
|
62
67
|
}
|
|
@@ -159,28 +164,8 @@ async function render({
|
|
|
159
164
|
remarkPluginFrontmatter: mod.frontmatter ?? {}
|
|
160
165
|
};
|
|
161
166
|
}
|
|
162
|
-
function createImage(options) {
|
|
163
|
-
return () => {
|
|
164
|
-
if (options.assetsDir === "undefined") {
|
|
165
|
-
throw new Error("Enable `experimental.assets` in your Astro config to use image()");
|
|
166
|
-
}
|
|
167
|
-
return z.string().transform(async (imagePath) => {
|
|
168
|
-
const fullPath = new URL(imagePath, options.assetsDir);
|
|
169
|
-
return await getImageMetadata(fullPath);
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
async function getImageMetadata(imagePath) {
|
|
174
|
-
const meta = await imageMetadata(imagePath);
|
|
175
|
-
if (!meta) {
|
|
176
|
-
return void 0;
|
|
177
|
-
}
|
|
178
|
-
delete meta.orientation;
|
|
179
|
-
return { ...meta, __astro_asset: true };
|
|
180
|
-
}
|
|
181
167
|
export {
|
|
182
168
|
createCollectionToGlobResultMap,
|
|
183
169
|
createGetCollection,
|
|
184
|
-
createGetEntryBySlug
|
|
185
|
-
createImage
|
|
170
|
+
createGetEntryBySlug
|
|
186
171
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const image: any;
|
package/dist/content/utils.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
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
5
|
import { ViteDevServer } from 'vite';
|
|
5
6
|
import { z } from 'zod';
|
|
6
|
-
import { AstroConfig, AstroSettings } from '../@types/astro.js';
|
|
7
|
+
import type { AstroConfig, AstroSettings } from '../@types/astro.js';
|
|
7
8
|
export declare const collectionConfigParser: z.ZodObject<{
|
|
8
9
|
schema: z.ZodOptional<z.ZodAny>;
|
|
9
10
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -46,7 +47,10 @@ export type EntryInfo = {
|
|
|
46
47
|
export declare const msg: {
|
|
47
48
|
collectionConfigMissing: (collection: string) => string;
|
|
48
49
|
};
|
|
49
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Mutate (arf) the entryData to reroute assets to their final paths
|
|
52
|
+
*/
|
|
53
|
+
export declare function patchAssets(frontmatterEntry: Record<string, any>, watchMode: boolean, fileEmitter: EmitFile, astroSettings: AstroSettings): Promise<void>;
|
|
50
54
|
export declare function getEntrySlug({ id, collection, slug, unvalidatedSlug, }: EntryInfo & {
|
|
51
55
|
unvalidatedSlug?: unknown;
|
|
52
56
|
}): string;
|
|
@@ -106,6 +110,7 @@ export type ContentPaths = {
|
|
|
106
110
|
cacheDir: URL;
|
|
107
111
|
typesTemplate: URL;
|
|
108
112
|
virtualModTemplate: URL;
|
|
113
|
+
virtualAssetsModTemplate: URL;
|
|
109
114
|
config: {
|
|
110
115
|
exists: boolean;
|
|
111
116
|
url: URL;
|