@all-the.rest/astro-image-cdn 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ ISC License
2
+
3
+ Copyright (c) 2026 Florian Reisinger
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted, provided that the above
7
+ copyright notice and this permission notice appear in all copies.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15
+ PERFORMANCE OF THIS SOFTWARE.
package/NOTICE ADDED
@@ -0,0 +1,7 @@
1
+ This package independently reimplements image-processing behavior reviewed in
2
+ packages/tools/scripts/process-images.mjs from reisinger.pictures:
3
+ https://github.com/reisinger-pictures/reisinger.pictures
4
+
5
+ The upstream root package.json declares the ISC license. The repository has no
6
+ root LICENSE file and the referenced script has no separate license header.
7
+ No source code was copied verbatim into this package.
package/README.md CHANGED
@@ -1,3 +1,130 @@
1
- # Temporary Holding Version
1
+ # @all-the.rest/astro-image-cdn
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An Astro integration that creates content-addressed image variants in a persistent directory and wires those variants into Astro's native `Image`, `Picture`, and `getImage()` APIs.
4
+
5
+ Unlike Astro's built-in local service, generated variants are **not written to `dist/`**. They and the incremental cache remain in directories outside the site build output, so rebuilding the site does not throw away image work.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ pnpm add @all-the.rest/astro-image-cdn
11
+ ```
12
+
13
+ Sharp is included as a runtime dependency. Astro 7.4 or newer is required; the integration is verified with Astro 7.4.1.
14
+
15
+ ## Configure
16
+
17
+ ```js
18
+ // astro.config.mjs
19
+ import { defineConfig } from "astro/config";
20
+ import astroImageCdn from "@all-the.rest/astro-image-cdn";
21
+
22
+ export default defineConfig({
23
+ integrations: [
24
+ astroImageCdn({
25
+ baseUrl: "https://images.example.com",
26
+ }),
27
+ ],
28
+ });
29
+ ```
30
+
31
+ By default, the integration accepts imported local images from `src/`, writes generated image variants to `.imagedist/`, and stores the manifest and warm-cache state privately in `.astro-image-cdn/`. It processes only local images actually requested through Astro's `Image`, `Picture`, or `getImage()` APIs; it does not pre-scan or transform unrelated source images. Requested entries are merged into the private manifest/cache without dropping unrelated entries. The package does not create a public manifest. If a pre-existing `manifest.json` is found in the output directory while processing a requested image, it is left untouched and a warning explains how to inspect and manually move or remove it before publishing. The manifest contains source paths and hashes, so it belongs outside public output. The output and cache directories must be disjoint and are checked against Astro's resolved `outDir` and all canonicalized source roots.
32
+
33
+ Use Astro's native assets imports and components as usual:
34
+
35
+ ```astro
36
+ ---
37
+ import { Image, Picture, getImage } from "astro:assets";
38
+ import photo from "../assets/photo.jpg";
39
+
40
+ const socialImage = await getImage({ src: photo, width: 1200, format: "webp" });
41
+ ---
42
+
43
+ <Image src={photo} widths={[256, 640, 1200]} format="webp" alt="A landscape" />
44
+ <Picture src={photo} widths={[256, 640, 1200]} formats={["avif", "webp"]} alt="A landscape" />
45
+ <meta property="og:image" content={socialImage.src} />
46
+ ```
47
+
48
+ In production builds, `Image`, `Picture`, and `getImage()` generate absolute URLs under `baseUrl`. In `astro dev`, requested variants are served directly from `outputDir` at `/_astro-image-cdn/`; the URL is local and does not require a CDN upload. The integration does not upload assets, configure a CDN, deploy, or modify hosting configuration. Production output must be made available at the corresponding `baseUrl` by the site's separate publishing process.
49
+
50
+ For a locally linked package that should affect development only, set `devOnly: true`:
51
+
52
+ ```js
53
+ astroImageCdn({
54
+ devOnly: true,
55
+ })
56
+ ```
57
+
58
+ With this option, `astro dev` installs the image service and local asset route, while `astro build`, preview, and sync leave Astro's configured image service unchanged and do not invoke this package's image processor.
59
+
60
+ ## Options
61
+
62
+ | Option | Default | Meaning |
63
+ | --- | --- | --- |
64
+ | `baseUrl` | required unless `devOnly: true` | Public HTTP(S) CDN origin and optional path prefix. Usernames and passwords are rejected. It is not used by the local dev asset route. |
65
+ | `sources` | `["src"]` | Project-root-relative directories from which imported local images may be requested. No startup pre-scan is performed. |
66
+ | `outputDir` | `".imagedist"` | Persistent generated variants, relative to the project root. |
67
+ | `cacheDir` | `".astro-image-cdn"` | Private manifest and incremental fingerprints, relative to the project root. |
68
+ | `widths` | `[256, 640, 828, 1080, 1200, 1920, 2048]` | Requested widths; each source's native width is also generated. Values above the source width are omitted. |
69
+ | `formats` | `["avif", "webp"]` | Output encodings generated for every selected width. Supported: `avif`, `webp`, `jpeg`, `png`. |
70
+ | `quality` | `75` | Sharp encoder quality from 1 to 100. |
71
+ | `concurrency` | `4` | Maximum number of source images processed at once. |
72
+ | `devOnly` | `false` | Install the integration only for `astro dev`; other Astro commands retain their configured image service. |
73
+
74
+ Configured formats are generated alongside the source's native raster format (when supported). Astro 7.4's default output for raster images is WebP, independent of the order in `formats`; include `webp` or request a configured format explicitly. If the default or an explicit format is unavailable, the service reports which format needs to be added. For a custom `widths` list, include the widths used by your native image components. For a requested width between generated sizes, the service selects the next available variant, capped at the source's native width.
75
+
76
+ Animated or multi-page sources are rejected rather than silently flattened to a still frame, including GIF, WebP, AVIF sequences, and multi-page TIFF. Convert them to a static image or exclude them from the configured source directories.
77
+
78
+ SVG sources are copied through unchanged by default. The integration honors Astro's `image.dangerouslyProcessSVG` setting before rasterizing SVGs. Standalone `processImages()` calls also default to safe pass-through and require `dangerouslyProcessSVG: true` to create raster variants; only enable it for trusted SVG sources.
79
+
80
+ The generated transform is aspect-preserving. Per-image crops (a requested width/height ratio different from the source), `background` flattening, unsupported `fit` modes, and a per-image `quality` that differs from the integration setting are rejected instead of silently returning the wrong pixels. Use a pre-cropped source for alternate aspect ratios.
81
+
82
+ Image identity is the project-relative file path; no frontmatter, YAML sidecars, slugs, EXIF metadata, or generated content metadata are read. Imported local images inside `sources` are optimized. Astro's SVG component wrapper can omit its private filesystem path, so those SVG imports are resolved by basename and require a unique filename within `sources`. String/remote image sources are passed through as-is and are not optimized.
83
+
84
+ ## Persistence and cache behavior
85
+
86
+ - Source bytes, encoder settings, the transform implementation version, and the Sharp/libvips versions are fingerprinted with SHA-256.
87
+ - Variant filenames include that fingerprint, width, and format. Each manifest variant stores a SHA-256 digest; warm-cache reuse verifies the digest and rejects symlinks instead of trusting file existence alone.
88
+ - Each manifest is checked against the complete set of variants expected for its source and current options, so empty or partial entries trigger repair rather than a false cache hit.
89
+ - The private cache and manifest are updated atomically and only when their contents change. Concurrent native image requests are deduplicated and batched per event-loop turn; batches are serialized through one writer queue, while the configured concurrency controls processing within each batch. A pre-existing `manifest.json` in `outputDir` is detected, reported in the processing result, and warned about when an Astro-requested image or standalone bulk run processes images; it is never modified. Verify its ownership, then manually move it outside public output or remove it before publishing. A filesystem lock allows only one process to write a given output/cache pair; overlapping processes fail with the lock path instead of racing. If a process is interrupted, verify it has stopped and remove any leftover `.astro-image-cdn.lock` file before retrying; the next run can rebuild missing variants.
90
+ - Warm runs re-hash source bytes but skip Sharp transformations when the fingerprint and every expected output still match.
91
+ - Old content-addressed files are intentionally retained. Request-driven Astro processing preserves unrelated manifest entries; an explicit standalone `processImages()` run reconciles the manifest with the files found under its source directories. Neither mode deletes historical output files.
92
+ - Astro's `dist/` remains Astro-owned; this package does not copy into, clean, or deploy it.
93
+
94
+ ## API
95
+
96
+ The default export is the Astro integration. Its image processor runs only when a native Astro image API requests an imported local image. The exported `processImages()` API is a separate, explicit bulk operation for standalone build scripts; calling it scans every supported image under `sources`:
97
+
98
+ ```js
99
+ import { processImages } from "@all-the.rest/astro-image-cdn";
100
+
101
+ const result = await processImages({
102
+ rootDir: process.cwd(),
103
+ sources: ["src"],
104
+ outputDir: ".imagedist",
105
+ cacheDir: ".astro-image-cdn",
106
+ });
107
+ console.log(result);
108
+ ```
109
+
110
+ The returned counts distinguish newly processed images from warm-cache reuses. `manifestPath` points into the configured private `cacheDir`; `legacyPublicManifestPath` is set when a pre-existing public manifest was found. This API only generates files and a manifest; it performs no deployment.
111
+
112
+ The standalone processor rejects `outputDir` or `cacheDir` inside Astro's `publicDir`, including symlink aliases. It assumes `rootDir/public` by default; pass `publicDir` when the Astro project customizes that directory. The integration supplies Astro's configured `publicDir` automatically.
113
+
114
+ ## Development and verification
115
+
116
+ ```sh
117
+ pnpm install --frozen-lockfile
118
+ pnpm check
119
+ ratchet check
120
+ ```
121
+
122
+ The tests include real Astro static builds using `Image`, `Picture`, and `getImage()`, a real dev-server request served from local output, unrequested-image checks, a repeated warm build, and assertions that optimized variants remain outside `dist/`.
123
+
124
+ The npm workflow publishes only pushed `vMAJOR.MINOR.PATCH` version tags whose version matches `package.json`; verification and packaging use pnpm in a separate job without OIDC, while the minimal publishing job downloads the verified tarball and uses npm CLI only for OIDC publishing. The package's npm Trusted Publisher is configured for this repository's `.github/workflows/publish.yml` and the `npm publish` action.
125
+
126
+ Version 0.1.0 was bootstrapped manually because npm requires a package to exist before a trusted publisher can be configured ([`npm trust` prerequisites](https://docs.npmjs.com/cli/v12/commands/npm-trust/#prerequisites)). Subsequent version-tag releases use GitHub Actions OIDC and npm provenance, without a long-lived publish token. A new trusted-publisher configuration must complete its first successful publish within two days or it expires.
127
+
128
+ ## Provenance and license
129
+
130
+ The image-processing behavior was independently reimplemented for this package after reviewing `packages/tools/scripts/process-images.mjs` in [reisinger.pictures](https://github.com/reisinger-pictures/reisinger.pictures). The upstream root `package.json` declares ISC, but that repository contains no root license text and the script has no separate copyright or license header; no source code was copied verbatim. See [NOTICE](NOTICE) and [LICENSE](LICENSE).
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@all-the.rest/astro-image-cdn",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.1",
4
+ "description": "Persistent, incremental image variants for Astro's native image components",
5
+ "type": "module",
6
+ "license": "ISC",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/all-the-rest/astro-image-cdn.git"
10
+ },
11
+ "homepage": "https://github.com/all-the-rest/astro-image-cdn#readme",
12
+ "files": [
13
+ "src/",
14
+ "README.md",
15
+ "LICENSE",
16
+ "NOTICE"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "types": "./src/index.d.ts",
21
+ "import": "./src/index.js"
22
+ },
23
+ "./service": "./src/service.js"
24
+ },
25
+ "engines": {
26
+ "node": ">=22.22.0"
27
+ },
28
+ "peerDependencies": {
29
+ "astro": ">=7.4.0"
30
+ },
31
+ "dependencies": {
32
+ "sharp": "^0.35.5"
33
+ },
34
+ "devDependencies": {
35
+ "@types/node": "^22.19.3",
36
+ "astro": "7.4.1",
37
+ "typescript": "5.9.3"
38
+ },
39
+ "scripts": {
40
+ "test": "node --test",
41
+ "test:astro": "node --test tests/astro-build.test.js",
42
+ "check": "node --check src/index.js && node --check src/processor.js && node --check src/service.js && node --check src/dev-server.js && pnpm typecheck && pnpm test",
43
+ "typecheck": "tsc --noEmit"
44
+ }
6
45
  }
@@ -0,0 +1,74 @@
1
+ import { lstat, readFile } from "node:fs/promises";
2
+ import path from "node:path";
3
+
4
+ export const DEV_ASSET_PREFIX = "/_astro-image-cdn/";
5
+
6
+ const CONTENT_TYPES = {
7
+ avif: "image/avif",
8
+ jpeg: "image/jpeg",
9
+ jpg: "image/jpeg",
10
+ png: "image/png",
11
+ svg: "image/svg+xml; charset=utf-8",
12
+ webp: "image/webp",
13
+ };
14
+
15
+ function notFound(response) {
16
+ response.statusCode = 404;
17
+ response.end("Not found");
18
+ }
19
+
20
+ function createAssetMiddleware(outputDir) {
21
+ return async (request, response, next) => {
22
+ let pathname;
23
+ try {
24
+ pathname = new URL(request.url ?? "/", "http://astro-image-cdn.local").pathname;
25
+ } catch {
26
+ return next();
27
+ }
28
+ if (!pathname.startsWith(DEV_ASSET_PREFIX)) return next();
29
+
30
+ if (request.method !== "GET" && request.method !== "HEAD") {
31
+ response.setHeader("Allow", "GET, HEAD");
32
+ response.statusCode = 405;
33
+ response.end("Method not allowed");
34
+ return;
35
+ }
36
+
37
+ let relativePath;
38
+ try {
39
+ relativePath = decodeURIComponent(pathname.slice(DEV_ASSET_PREFIX.length));
40
+ } catch {
41
+ return notFound(response);
42
+ }
43
+ const segments = relativePath.split("/");
44
+ if (!relativePath || segments.some((segment) => !segment || segment === "." || segment === ".." || segment.includes("\\"))) {
45
+ return notFound(response);
46
+ }
47
+
48
+ let filePath = outputDir;
49
+ try {
50
+ for (const [index, segment] of segments.entries()) {
51
+ filePath = path.join(filePath, segment);
52
+ const fileInfo = await lstat(filePath);
53
+ const isFile = index === segments.length - 1;
54
+ if (fileInfo.isSymbolicLink() || (isFile ? !fileInfo.isFile() : !fileInfo.isDirectory())) {
55
+ return notFound(response);
56
+ }
57
+ }
58
+ const data = await readFile(filePath);
59
+ const extension = path.extname(filePath).slice(1).toLowerCase();
60
+ response.statusCode = 200;
61
+ response.setHeader("Content-Type", CONTENT_TYPES[extension] ?? "application/octet-stream");
62
+ response.setHeader("Content-Length", data.byteLength);
63
+ response.setHeader("Cache-Control", "public, max-age=31536000, immutable");
64
+ response.end(request.method === "HEAD" ? undefined : data);
65
+ } catch (error) {
66
+ if (error.code === "ENOENT" || error.code === "ENOTDIR") return notFound(response);
67
+ return next(error);
68
+ }
69
+ };
70
+ }
71
+
72
+ export function installDevAssetMiddleware(server, outputDir) {
73
+ server.middlewares.use(createAssetMiddleware(path.resolve(outputDir)));
74
+ }
package/src/index.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ import type { AstroIntegration } from "astro";
2
+
3
+ interface AstroImageCdnBaseOptions {
4
+ /** Directories that may contain imported local images, relative to Astro's project root. Defaults to ["src"]. */
5
+ sources?: string[];
6
+ /** Persistent generated image directory, relative to the project root. Defaults to ".imagedist". */
7
+ outputDir?: string;
8
+ /** Incremental state directory, relative to the project root. Defaults to ".astro-image-cdn". */
9
+ cacheDir?: string;
10
+ /** Widths generated in addition to each source image's native width. */
11
+ widths?: number[];
12
+ /** Output formats generated for every source. Defaults to ["avif", "webp"]. */
13
+ formats?: Array<"avif" | "webp" | "jpeg" | "png">;
14
+ /** Encoder quality from 1 to 100. Defaults to 75. */
15
+ quality?: number;
16
+ /** Maximum number of images processed concurrently. Defaults to 4. */
17
+ concurrency?: number;
18
+ }
19
+
20
+ export type AstroImageCdnOptions = AstroImageCdnBaseOptions & (
21
+ | {
22
+ /** Public HTTP(S) CDN origin and optional path prefix. */
23
+ baseUrl: string;
24
+ devOnly?: false;
25
+ }
26
+ | {
27
+ /** Optional because development assets are served locally in dev-only mode. */
28
+ baseUrl?: string;
29
+ /** Enable only for `astro dev`; build, preview, and sync leave Astro's image service unchanged. */
30
+ devOnly: true;
31
+ }
32
+ );
33
+
34
+ export interface ProcessImagesOptions extends AstroImageCdnBaseOptions {
35
+ rootDir: string;
36
+ /** Astro's public directory, relative to rootDir. Defaults to "public". */
37
+ publicDir?: string;
38
+ /** Permit Sharp to rasterize trusted SVG sources. Defaults to false. */
39
+ dangerouslyProcessSVG?: boolean;
40
+ }
41
+
42
+ export interface ProcessImagesResult {
43
+ processed: number;
44
+ skipped: number;
45
+ imageCount: number;
46
+ manifestPath: string;
47
+ legacyPublicManifestPath?: string;
48
+ }
49
+
50
+ export default function astroImageCdn(options: AstroImageCdnOptions): AstroIntegration;
51
+
52
+ export declare function processImages(options: ProcessImagesOptions): Promise<ProcessImagesResult>;
package/src/index.js ADDED
@@ -0,0 +1,153 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { fileURLToPath } from "node:url";
3
+ import { realpathSync } from "node:fs";
4
+ import path from "node:path";
5
+ import { DEFAULT_IMAGE_FORMATS, DEFAULT_IMAGE_WIDTHS } from "./processor.js";
6
+ import { installDevAssetMiddleware } from "./dev-server.js";
7
+
8
+ const serviceEntrypoint = fileURLToPath(new URL("./service.js", import.meta.url));
9
+
10
+ function normalizeBaseUrl(baseUrl) {
11
+ let url;
12
+ try {
13
+ url = new URL(baseUrl);
14
+ } catch {
15
+ throw new TypeError("astroImageCdn requires an absolute http(s) baseUrl");
16
+ }
17
+ const authority = baseUrl.match(/^[a-z][a-z\d+.-]*:\/\/([^/?#]*)/i)?.[1] ?? "";
18
+ if (url.username || url.password || authority.includes("@")) {
19
+ throw new TypeError("baseUrl must not include username or password credentials");
20
+ }
21
+ if (!["http:", "https:"].includes(url.protocol) || url.search || url.hash) {
22
+ throw new TypeError("baseUrl must be an http(s) origin/path without a query or fragment");
23
+ }
24
+ return url.toString().replace(/\/$/, "");
25
+ }
26
+
27
+ function resolveDirectories(rootDir, options) {
28
+ return {
29
+ sources: (options.sources ?? ["src"]).map((source) => path.resolve(rootDir, source)),
30
+ outputDir: path.resolve(rootDir, options.outputDir ?? ".imagedist"),
31
+ cacheDir: path.resolve(rootDir, options.cacheDir ?? ".astro-image-cdn"),
32
+ };
33
+ }
34
+
35
+ function isInside(parent, candidate) {
36
+ const relative = path.relative(parent, candidate);
37
+ return relative === "" || (!relative.startsWith(`..${path.sep}`) && relative !== ".." && !path.isAbsolute(relative));
38
+ }
39
+
40
+ function canonicalizePath(value) {
41
+ let candidate = path.resolve(value);
42
+ const suffix = [];
43
+ while (true) {
44
+ try {
45
+ return path.join(realpathSync(candidate), ...suffix.reverse());
46
+ } catch (error) {
47
+ if (error.code !== "ENOENT" && error.code !== "ENOTDIR") throw error;
48
+ const parent = path.dirname(candidate);
49
+ if (parent === candidate) throw error;
50
+ suffix.push(path.basename(candidate));
51
+ candidate = parent;
52
+ }
53
+ }
54
+ }
55
+
56
+ function assertOutsideBuildOutput(candidate, outDir, label) {
57
+ const canonicalOutDir = canonicalizePath(outDir);
58
+ const canonicalCandidate = canonicalizePath(candidate);
59
+ if (isInside(canonicalOutDir, canonicalCandidate)) {
60
+ throw new Error(`astroImageCdn ${label} must be outside Astro's build output directory (${canonicalOutDir}); received ${canonicalCandidate}`);
61
+ }
62
+ }
63
+
64
+ function assertOutsidePublicDirectory(candidate, publicDir, label) {
65
+ const canonicalPublicDir = canonicalizePath(publicDir);
66
+ const canonicalCandidate = canonicalizePath(candidate);
67
+ if (isInside(canonicalPublicDir, canonicalCandidate)) {
68
+ throw new Error(`astroImageCdn ${label} must be outside Astro's public directory (${canonicalPublicDir}); received ${canonicalCandidate}`);
69
+ }
70
+ }
71
+
72
+ function assertDirectoriesDoNotOverlap(outputDir, cacheDir) {
73
+ const canonicalOutputDir = canonicalizePath(outputDir);
74
+ const canonicalCacheDir = canonicalizePath(cacheDir);
75
+ if (isInside(canonicalOutputDir, canonicalCacheDir) || isInside(canonicalCacheDir, canonicalOutputDir)) {
76
+ throw new Error(`astroImageCdn outputDir and cacheDir must not overlap; received ${canonicalOutputDir} and ${canonicalCacheDir}`);
77
+ }
78
+ }
79
+
80
+ export default function astroImageCdn(options) {
81
+ if (!options || (typeof options.baseUrl !== "string" && options.devOnly !== true)) {
82
+ throw new TypeError("astroImageCdn requires a baseUrl unless devOnly is true");
83
+ }
84
+ const baseUrl = typeof options.baseUrl === "string" ? normalizeBaseUrl(options.baseUrl) : "";
85
+ let projectRoot;
86
+ let outputDir;
87
+ let cacheDir;
88
+ let imageOptions;
89
+ let active = false;
90
+ let devMode = false;
91
+
92
+ return {
93
+ name: "@all-the.rest/astro-image-cdn",
94
+ hooks: {
95
+ "astro:config:setup"({ config, command = "build", updateConfig }) {
96
+ active = !options.devOnly || command === "dev";
97
+ devMode = command === "dev";
98
+ if (!active) return;
99
+ projectRoot = realpathSync(fileURLToPath(config.root));
100
+ const directories = resolveDirectories(projectRoot, options);
101
+ outputDir = directories.outputDir;
102
+ cacheDir = directories.cacheDir;
103
+ imageOptions = {
104
+ ...options,
105
+ rootDir: projectRoot,
106
+ sources: directories.sources,
107
+ publicDir: config.publicDir ? fileURLToPath(config.publicDir) : path.join(projectRoot, "public"),
108
+ outputDir,
109
+ cacheDir,
110
+ baseUrl,
111
+ widths: options.widths ?? DEFAULT_IMAGE_WIDTHS,
112
+ formats: options.formats ?? DEFAULT_IMAGE_FORMATS,
113
+ quality: options.quality ?? 75,
114
+ concurrency: options.concurrency ?? 4,
115
+ dangerouslyProcessSVG: config.image?.dangerouslyProcessSVG ?? false,
116
+ devMode,
117
+ requestSessionId: randomUUID(),
118
+ };
119
+ const vite = devMode
120
+ ? {
121
+ plugins: [{
122
+ name: "@all-the.rest/astro-image-cdn:dev-assets",
123
+ configureServer(server) {
124
+ installDevAssetMiddleware(server, outputDir);
125
+ },
126
+ }],
127
+ }
128
+ : {};
129
+ updateConfig({
130
+ image: {
131
+ service: {
132
+ entrypoint: serviceEntrypoint,
133
+ config: imageOptions,
134
+ },
135
+ },
136
+ vite,
137
+ });
138
+ },
139
+ "astro:config:done"({ config }) {
140
+ if (!active) return;
141
+ const outDir = fileURLToPath(config.outDir);
142
+ const publicDir = fileURLToPath(config.publicDir);
143
+ assertOutsideBuildOutput(outputDir, outDir, "outputDir");
144
+ assertOutsideBuildOutput(cacheDir, outDir, "cacheDir");
145
+ assertOutsidePublicDirectory(outputDir, publicDir, "outputDir");
146
+ assertOutsidePublicDirectory(cacheDir, publicDir, "cacheDir");
147
+ assertDirectoriesDoNotOverlap(outputDir, cacheDir);
148
+ },
149
+ },
150
+ };
151
+ }
152
+
153
+ export { processImages } from "./processor.js";