Skip to content

fix: avoid bundling package.json in output - #142

Open
ajth-in wants to merge 1 commit into
cloudinary-community:mainfrom
ajth-in:fix/avoid-bundling-package-json
Open

ajth-in wants to merge 1 commit into
cloudinary-community:mainfrom
ajth-in:fix/avoid-bundling-package-json

Conversation

@ajth-in

@ajth-in ajth-in commented Oct 25, 2026 •

Copy link
Copy Markdown

Description

Fixes #141

This is an optimization that reduces the published dist output by ~1.37 KB (~480 B gzip) by no longer bundling the entire astro-cloudinary/package.json just to read the version number used for analytics.

getCloudinaryAnalytics in astro-cloudinary/src/lib/cloudinary.ts:38 attaches SDK/tech versions to every generated Cloudinary URL:

export function getCloudinaryAnalytics(analytics?: AnalyticsOptions) {
  return Object.assign({
    product: ASTRO_CLOUDINARY_ANALYTICS_PRODUCT_ID,
    sdkCode: ASTRO_CLOUDINARY_ANALYTICS_ID,
    sdkSemver: ASTRO_CLOUDINARY_VERSION,
    techVersion: ASTRO_VERSION,
    feature: ''
  }, analytics)
}

Those constants come from astro-cloudinary/src/constants/analytics.ts, which imported both:

  • astro/package.json (the peer dependency), and
  • ../../package.json (this package).

The second import inlined the entire astro-cloudinary/package.json manifest as a JS object inside the shared tsup chunk (dist/chunk-*.js), which is imported by both dist/helpers/index.js and dist/loaders/index.js.

Changes

  • Replaced import pkg from '../../package.json' with a build-time constant, __ASTRO_CLOUDINARY_VERSION__, injected via tsup's define option. Only the version string is now emitted instead of the whole manifest (including scripts, devDependencies, repository, etc.).

Result

The shared analytics chunk before and after the change:

Build Shared analytics chunk Size
Before dist/chunk-M4MK3WLV.js (full manifest inlined) 1,987 B
After dist/chunk-STN24IAD.js (version string only) 619 B

Total dist output drops from ~11.64 KB to ~10.28 KB.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Fix or improve the documentation
  • This change requires a documentation update

Checklist

  • I have followed the contributing guidelines of this project as mentioned in CONTRIBUTING.md
  • I have created an issue ticket for this PR
  • I have checked to ensure there aren't other open Pull Requests for the same update/change?
  • I have performed a self-review of my own code
  • I have run the build locally to ensure it passes
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes needed to the documentation

@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

@ajth-in is attempting to deploy a commit to the Cloudinary DevX Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

1 participant