Skip to content

Code review fixes#2

Merged
imagekitio merged 45 commits intomainfrom
review
May 5, 2026
Merged

Code review fixes#2
imagekitio merged 45 commits intomainfrom
review

Conversation

@imagekitio
Copy link
Copy Markdown
Contributor

No description provided.

manu4543 added 4 commits May 3, 2026 15:38
- Deleted the fixtures.ts file as it was no longer needed.
- Updated images.spec.ts to remove redundant tests and simplify image loading checks.
- Removed edge case tests for video components and unnecessary attributes in videos.spec.ts.
- Updated package.json to include @imagekit/javascript dependency.
- Modified upload-auth.ts to use the correct public key environment variable.
- Changed images.astro to use astro:assets for image handling and removed outdated examples.
- Updated upload.astro to use the new upload method from @imagekit/javascript.
- Implement getSrcSet to generate responsive variants from widths/densities
- Apply user transformations first, append trailing step with crop:at_max
- Drop fit/position mapping (incompatible with at_max)
- Drop redundant height from final transform step (at_max preserves AR)
- Resolve urlEndpoint from prop > integration config > env vars
- Strip ImageKit-internal props from rendered <img> attributes
- Update test-app images.astro cases (urlEndpoint override, absolute URL,
  layout=none for densities) and refresh snapshots
…module

- Add virtual:@imagekit/astro/config Vite plugin in the integration that
  exposes the resolved urlEndpoint and transformationPosition
- Video.astro consumes the virtual module so urlEndpoint can come from
  imagekit({ urlEndpoint }) in astro.config.mjs without env vars or props
- Resolution priority: prop > integration config > PUBLIC_/IMAGEKIT_URL_ENDPOINT
- Inject type declaration for the virtual module via injectTypes so
  consumer projects get autocomplete and typecheck
- Update test-app videos.astro and refresh snapshots
@imagekitio imagekitio changed the title Review Code review fixes May 3, 2026
manu4543 added 8 commits May 4, 2026 09:48
…PUBLIC_ env

Centralize ImageKit config resolution, harden the image service, and
simplify the OG helper. Also remove PUBLIC_IMAGEKIT_URL_ENDPOINT since
every SDK caller runs server-side.

Resolution & integration:
- getImageKitConfig is the single resolver: prop > integration config
  (virtual:@imagekit/astro/config) > IMAGEKIT_URL_ENDPOINT
- Video.astro delegates to getImageKitConfig instead of resolving inline
- Integration only carries forward known service config keys
  (urlEndpoint, transformationPosition); foreign keys from a previous
  service no longer leak through
- Warn when urlEndpoint cannot be parsed as a URL
- Mark virtual:@imagekit/astro/config external in tsup

Image service:
- Throw a clear error when no urlEndpoint can be resolved (was: silent '')
- Add IKImageTransform type, remove all `as any` casts
- Align quality presets with Astro sharp defaults (low/mid/high/max
  = 25/50/75/100, was 30/80/90/95)

Helpers & types:
- Drop `format` option from getOgImageTags; emit a single image URL for
  og:image and twitter:image (ImageKit auto-format negotiates
  WebP/AVIF/JPEG via the Accept header)
- VideoProps extends Astro's HTMLAttributes<'video'> for full HTML
  video attribute autocomplete (replaces [key: string]: unknown)

test-app:
- Add /og page exercising getOgImageTags (default, minimal, custom
  dimensions + transformation)
- Link /og from index page
…K srcs

Convert image service from ExternalImageService to LocalImageService and
delegate non-ImageKit srcs (local assets, allow-listed external hosts) to
Astro's bundled sharp service. ImageKit URLs continue to bypass /_image and
go straight to ik.imagekit.io with full IK transformations.

- Add `additionalEndpoints?: string[]` option for multi-account / custom
  IK domains; their hosts auto-merge into image.domains and image.remotePatterns
- Drop `domains` and `remotePatterns` from imagekit() options; non-IK hosts
  belong in image.domains / image.remotePatterns directly
- Pass `imagekitHosts` through service config so the service knows which
  absolute URLs to treat as IK
- isImageKitSrc routes /_astro/, /@fs/, /@id/, data:, blob:, and non-IK
  http(s) hosts to sharp; everything else goes to IK
- Wire parseURL/transform/propertiesToHash from sharp so /_image accepts
  non-IK requests (fixes "Configured image service is not a local service")
- validateOptions delegates to sharp for non-IK srcs (enables size inference)

Test app:
- Add additionalEndpoints (ik.imgkit.net) and image.domains (placehold.co)
- Add hero.jpg local asset + sharp-delegation cases on /images
- Add /md page with 5 routing cases and Playwright snapshot spec
- Update /images snapshots: full-width srcset shrinks (LocalImageService
  uses LIMITED_RESOLUTIONS instead of DEFAULT_RESOLUTIONS)

Docs:
- README "How it works" section explaining the two-path routing
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR turns the repository into a pnpm workspace monorepo containing the @imagekit/astro SDK package plus a test-app used to exercise the integration across multiple Astro major versions, with Playwright E2E coverage and CI/publish workflows.

Changes:

  • Added the @imagekit/astro package implementation: integration, image service (sharp delegation + ImageKit fast-path), components (<Video />, <OgImage />), helpers, and server upload auth helper.
  • Added an Astro test app with pages covering Image/Video/OG/Markdown behaviors plus Playwright E2E tests and versioned snapshots.
  • Added multi-version test script, pnpm workspace setup, and GitHub Actions CI + publish workflow.

Reviewed changes

Copilot reviewed 56 out of 62 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
test-app/tsconfig.json Adds strict TS config for the test app.
test-app/src/pages/videos.astro Video component demo cases for E2E snapshots.
test-app/src/pages/upload.astro Upload demo UI + client-side upload call.
test-app/src/pages/og.astro <OgImage> + getOgImageUrl() demo page.
test-app/src/pages/md.md Markdown image pipeline coverage page.
test-app/src/pages/index.astro Test app landing page linking to demos.
test-app/src/pages/images.astro Extensive <Image> behavior matrix for snapshots.
test-app/src/pages/api/upload-auth.ts API route generating upload auth params (plus CI fallback).
test-app/src/env.d.ts Astro env typing references for test app.
test-app/README.md Test app usage docs (run/tests/upload demo).
test-app/playwright.config.ts Playwright setup + per-Astro-version snapshot directories.
test-app/package.json Test app dependencies/scripts (Astro, Playwright, adapters).
test-app/e2e/videos.spec.ts E2E snapshot test for /videos.
test-app/e2e/og.spec.ts E2E assertions for OG/Twitter meta tags.
test-app/e2e/md.spec.ts E2E snapshot test for /md.
test-app/e2e/images.spec.ts E2E snapshot test for /images.
test-app/e2e/snapshot/astro-default/videos.spec.ts/Videos-page-renders-correctly-1.txt Baseline snapshot for videos page (default matrix entry).
test-app/e2e/snapshot/astro-default/images.spec.ts/Image-page-renders-correctly-1.txt Baseline snapshot for images page (default matrix entry).
test-app/e2e/snapshot/astro-6/videos.spec.ts/Videos-page-renders-correctly-1.txt Snapshot for Astro 6 videos rendering.
test-app/e2e/snapshot/astro-6/md.spec.ts/Markdown-page-renders-correctly-1.txt Snapshot for Astro 6 markdown rendering.
test-app/e2e/snapshot/astro-6/images.spec.ts/Image-page-renders-correctly-1.txt Snapshot for Astro 6 images rendering.
test-app/e2e/snapshot/astro-5/videos.spec.ts/Videos-page-renders-correctly-1.txt Snapshot for Astro 5 videos rendering.
test-app/e2e/snapshot/astro-5/md.spec.ts/Markdown-page-renders-correctly-1.txt Snapshot for Astro 5 markdown rendering.
test-app/e2e/snapshot/astro-5/images.spec.ts/Image-page-renders-correctly-1.txt Snapshot for Astro 5 images rendering.
test-app/e2e/snapshot/astro-4/videos.spec.ts/Videos-page-renders-correctly-1.txt Snapshot for Astro 4 videos rendering.
test-app/e2e/snapshot/astro-4/md.spec.ts/Markdown-page-renders-correctly-1.txt Snapshot for Astro 4 markdown rendering.
test-app/e2e/snapshot/astro-4/images.spec.ts/Image-page-renders-correctly-1.txt Snapshot for Astro 4 images rendering.
test-app/e2e/snapshot/astro-3/videos.spec.ts/Videos-page-renders-correctly-1.txt Snapshot for Astro 3 videos rendering.
test-app/e2e/snapshot/astro-3/md.spec.ts/Markdown-page-renders-correctly-1.txt Snapshot for Astro 3 markdown rendering.
test-app/e2e/snapshot/astro-3/images.spec.ts/Image-page-renders-correctly-1.txt Snapshot for Astro 3 images rendering.
test-app/astro.config.mjs Configures ImageKit integration + node adapter + image domains/layout.
test-app/.gitignore Ignores build artifacts, Playwright outputs, env files.
test-app/.env.example Example env vars for upload auth demo.
scripts/test-all-versions.sh Local script to run/update E2E across Astro 3–6 using packed tarball.
README.md Replaces root README with full SDK documentation and examples.
pnpm-workspace.yaml Declares workspace packages (imagekit-astro, test-app).
package.json Adds monorepo root scripts and pnpm packageManager metadata.
LICENSE Adds MIT license file at repo root.
imagekit-astro/tsup.config.ts Builds multiple entrypoints (integration/helpers/server/image-service).
imagekit-astro/tsconfig.json TS config for SDK package build/types.
imagekit-astro/src/types/index.ts Public prop/type definitions for Video and OG helpers/components.
imagekit-astro/src/services/imagekit-service.ts Image service implementing IK URL generation + sharp delegation.
imagekit-astro/src/server/uploadAuth.ts Server-side getUploadAuthParams() implementation.
imagekit-astro/src/server/index.ts Exports server helper + types.
imagekit-astro/src/lib/imagekit.ts Resolves ImageKit config from props/virtual module/env.
imagekit-astro/src/integration.ts Astro integration wiring: image service, remotePatterns/domains, injectTypes.
imagekit-astro/src/helpers/index.ts getOgImageUrl() helper.
imagekit-astro/src/constants/sizes.ts OG image default sizes constants.
imagekit-astro/src/components/Video.astro <Video /> component emitting <video> with IK URL.
imagekit-astro/src/components/OgImage.astro <OgImage /> component emitting OG/Twitter <meta> tags.
imagekit-astro/src/components/index.ts Component barrel exports.
imagekit-astro/package.json Package metadata + exports map for subpath entrypoints.
imagekit-astro/package-lock.json NPM lockfile committed under SDK package directory.
imagekit-astro/index.ts SDK root entry exports components/helpers/types.
imagekit-astro/astro.d.ts Declares *.astro module typings and virtual config module typing.
imagekit-astro/.gitignore Ignores dist and staged README/LICENSE within package.
.npmrc pnpm behavior settings for the workspace.
.gitignore Root ignore rules including tarballs and test artifacts.
.github/workflows/publish.yml Release-triggered build + npm publish with provenance.
.github/workflows/ci.yml CI matrix running E2E against Astro 3–6.
Files not reviewed (1)
  • imagekit-astro/package-lock.json: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread imagekit-astro/package.json Outdated
Comment thread test-app/src/pages/upload.astro
Comment thread test-app/README.md
Comment thread imagekit-astro/package-lock.json
@SwarnimDoegar
Copy link
Copy Markdown
Collaborator

The content collection example given in readme works as expected. But there are some type errors. Type error fixed code. Needs to be updated in imagekit-docs as well:

// src/content.config.ts

import { defineCollection } from 'astro:content';
import { z } from 'astro/zod';
import ImageKit from '@imagekit/nodejs';
import type { Files } from '@imagekit/nodejs/resources/files/files';

const client = new ImageKit({
  privateKey: import.meta.env.IMAGEKIT_PRIVATE_KEY,
});

const gallery = defineCollection({
  loader: async () => {
    const assets = await client.assets.list({
      type: 'file',       // exclude folders
      fileType: 'image',  // only image files
      skip: 0,
      limit: 50,
    });

    return assets
      .filter((asset): asset is Files.File =>
        asset.type === 'file' && !!asset.fileId && !!asset.url
      )
      .map((asset) => ({
        id: asset.fileId ?? '',
        url: asset.url ?? '',
        width: asset.width ?? 0,
        height: asset.height ?? 0,
        name: asset.name ?? '',
        tags: asset.tags ?? [],
      }));
  },
  schema: z.object({
    url: z.string().url(),
    width: z.number(),
    height: z.number(),
    name: z.string(),
    tags: z.array(z.string()),
  }),
});

export const collections = { gallery };

manu4543 added 3 commits May 5, 2026 14:16
…ata-astro-image-pos attribute and clean up formatting
…dist/index.js

chore(tsup): add onSuccess script to copy .astro source files to dist for correct resolution
@imagekitio imagekitio merged commit 6c27bff into main May 5, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants