Skip to content

Replace tsdown with Vite for bundling and update loader API#1606

Merged
Adammatthiesen merged 9 commits into
mainfrom
new-config-loader
Jul 17, 2026
Merged

Replace tsdown with Vite for bundling and update loader API#1606
Adammatthiesen merged 9 commits into
mainfrom
new-config-loader

Conversation

@Adammatthiesen

@Adammatthiesen Adammatthiesen commented Jul 16, 2026

Copy link
Copy Markdown
Member

This pull request migrates the @withstudiocms/config-utils package to use a Vite-based configuration loader, replacing the previous custom logic and dependencies. The new implementation leverages Vite's dev server to load configuration files, improving compatibility and reducing maintenance burden. Several utility types and functions related to the old config loading approach have been removed, and new Vite-specific utilities and plugins have been introduced to support the new loader.

Migration to Vite-based config loading:

  • Replaced the previous custom config file loader and bundler with a new loadConfigFile function that uses Vite's dev server to load and import configuration files, supporting both native Node ESM and Vite's SSR environment. (loader.ts, astro-integration-utils.ts) [1] [2] [3] [4]

  • Added a minimal Vite dev server creator utility (createMinimalViteDevServer) to facilitate one-shot config loading. (utils/createMinimalViteDevServer.ts)

  • Introduced a Vite plugin (vite-plugin-load-fallback) to enable config loading from custom file systems, with fallback logic for file resolution and hot module replacement. (utils/vite-plugin-load-fallback.ts)

Dependency and type cleanup:

  • Removed the tsdown dependency and all related types and functions for bundling and importing config files, as they are no longer needed with the Vite-based approach. (package.json, types.ts, dynamicResult.ts, tryCatch.ts, index.ts) [1] [2] [3] [4] [5]

Changelog:

  • Added a changeset entry documenting the migration to a Vite-based config loader. (.changeset/nice-books-mate.md)

Summary by CodeRabbit

  • New Features

    • Updated configuration loading to try native ESM first, with a Vite SSR fallback when needed.
    • Added support for injecting a custom filesystem into config resolution.
  • Bug Fixes

    • When no matching config file is found, loading now returns an empty configuration object.
    • Updated the StudioCMS CLI debug flow and database plugin config-loading to follow the new loader behavior.
  • Refactor

    • Simplified the loader API to a single options-based entry point (removing older bundling helpers).
    • Kept the deprecated config builder “effect” export as an alias of the main builder.
  • Tests

    • Refreshed loader tests to focus on fixture-based JavaScript/TypeScript scenarios.

Switch config loading from tsdown bundling to a minimal Vite
dev-server approach. Remove tsdown and tryCatch/dynamicResult utils,
add vite to dev/peerDependencies, update loader API and imports,
and delete obsolete tests targeting the old bundler.
@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1507225

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@withstudiocms/config-utils Minor
studiocms Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: b13923bb-875e-4630-9619-eacc79b3e02a

📥 Commits

Reviewing files that changed from the base of the PR and between 9c2a212 and 1507225.

📒 Files selected for processing (4)
  • packages/@withstudiocms/config-utils/test/fixtures/loader-both/example.config.js
  • packages/@withstudiocms/config-utils/test/fixtures/loader-both/example.config.ts
  • packages/@withstudiocms/config-utils/test/fixtures/loader-neither/.gitkeep
  • packages/@withstudiocms/config-utils/test/loader.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/@withstudiocms/config-utils/test/loader.test.ts

📝 Walkthrough

Walkthrough

The configuration loader now uses native ESM with a Vite SSR fallback and an injected filesystem. Astro and StudioCMS callers use the new options object, package metadata declares Vite, and loader tests cover JavaScript and TypeScript fixtures.

Changes

Configuration loading migration

Layer / File(s) Summary
Loader API and runtime strategy
packages/@withstudiocms/config-utils/src/loader.ts, packages/@withstudiocms/config-utils/src/utils/createMinimalViteDevServer.ts, packages/@withstudiocms/config-utils/src/types.ts
The loader accepts filesystem-aware options, attempts native ESM imports, falls back to Vite SSR, returns {} when no config exists, and removes bundled-loader interfaces.
Filesystem fallback plugin
packages/@withstudiocms/config-utils/src/utils/vite-plugin-load-fallback.ts
Vite plugins resolve and load configuration files through an injected filesystem and override HMR reads for updated source.
Integration wiring and package contract
packages/@withstudiocms/config-utils/package.json, packages/@withstudiocms/config-utils/src/astro-integration-utils.ts, packages/studiocms/src/cli/debug/index.ts, packages/studiocms/src/cli/utils/loadConfig.ts, packages/studiocms/src/db/plugins.ts, .changeset/nice-books-mate.md
Astro and StudioCMS pass root, configPaths, and fs to the loader; schema parsing remains in place, Vite is declared as a peer dependency, and the migration is recorded.
Fixture-based loader validation
packages/@withstudiocms/config-utils/test/fixtures/loader-js/example.config.js, packages/@withstudiocms/config-utils/test/fixtures/loader-ts/example.config.ts, packages/@withstudiocms/config-utils/test/fixtures/loader-both/example.config.js, packages/@withstudiocms/config-utils/test/fixtures/loader-both/example.config.ts, packages/@withstudiocms/config-utils/test/loader.test.ts
Loader tests load JavaScript and TypeScript fixtures, verify missing-config behavior, and confirm precedence for the first matching config path.

Sequence Diagram(s)

sequenceDiagram
  participant AstroOrStudioCMS
  participant loadConfigFile
  participant NativeESM
  participant ViteSSR
  AstroOrStudioCMS->>loadConfigFile: provide root, configPaths, and fs
  loadConfigFile->>NativeESM: load .js, .cjs, or .mjs config
  NativeESM-->>loadConfigFile: configuration or fallback error
  loadConfigFile->>ViteSSR: create minimal SSR server
  ViteSSR-->>loadConfigFile: load JavaScript or TypeScript config
  loadConfigFile-->>AstroOrStudioCMS: return configuration record
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title is descriptive and imperative, but it omits the required scope/module for this change. Rewrite it to include the affected module, e.g. 'config-utils: replace tsdown with Vite loader API'.
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch new-config-loader

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 16, 2026

Copy link
Copy Markdown
create-studiocms

npm i https://pkg.pr.new/create-studiocms@1606

effectify

npm i https://pkg.pr.new/effectify@1606

studiocms

npm i https://pkg.pr.new/studiocms@1606

@studiocms/auth0

npm i https://pkg.pr.new/@studiocms/auth0@1606

@studiocms/blog

npm i https://pkg.pr.new/@studiocms/blog@1606

@studiocms/cloudinary-image-service

npm i https://pkg.pr.new/@studiocms/cloudinary-image-service@1606

@studiocms/devapps

npm i https://pkg.pr.new/@studiocms/devapps@1606

@studiocms/discord

npm i https://pkg.pr.new/@studiocms/discord@1606

@studiocms/github

npm i https://pkg.pr.new/@studiocms/github@1606

@studiocms/google

npm i https://pkg.pr.new/@studiocms/google@1606

@studiocms/html

npm i https://pkg.pr.new/@studiocms/html@1606

@studiocms/markdoc

npm i https://pkg.pr.new/@studiocms/markdoc@1606

@studiocms/markdown-remark

npm i https://pkg.pr.new/@studiocms/markdown-remark@1606

@studiocms/md

npm i https://pkg.pr.new/@studiocms/md@1606

@studiocms/mdx

npm i https://pkg.pr.new/@studiocms/mdx@1606

@studiocms/s3-storage

npm i https://pkg.pr.new/@studiocms/s3-storage@1606

@studiocms/upgrade

npm i https://pkg.pr.new/@studiocms/upgrade@1606

@studiocms/wysiwyg

npm i https://pkg.pr.new/@studiocms/wysiwyg@1606

@withstudiocms/api-spec

npm i https://pkg.pr.new/@withstudiocms/api-spec@1606

@withstudiocms/auth-kit

npm i https://pkg.pr.new/@withstudiocms/auth-kit@1606

@withstudiocms/cli-kit

npm i https://pkg.pr.new/@withstudiocms/cli-kit@1606

@withstudiocms/component-registry

npm i https://pkg.pr.new/@withstudiocms/component-registry@1606

@withstudiocms/config-utils

npm i https://pkg.pr.new/@withstudiocms/config-utils@1606

@withstudiocms/effect

npm i https://pkg.pr.new/@withstudiocms/effect@1606

@withstudiocms/internal_helpers

npm i https://pkg.pr.new/@withstudiocms/internal_helpers@1606

@withstudiocms/kysely

npm i https://pkg.pr.new/@withstudiocms/kysely@1606

@withstudiocms/sdk

npm i https://pkg.pr.new/@withstudiocms/sdk@1606

@withstudiocms/template-lang

npm i https://pkg.pr.new/@withstudiocms/template-lang@1606

commit: 1507225

@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Allure Report Summary

Name Duration Stats New Flaky Retry Report
@studiocms/auth0 Tests 13ms Passed tests 2 0 0 0
@withstudiocms/auth-kit Tests 1s 366ms Passed tests 108 0 0 0
@studiocms/blog Tests 368ms Passed tests 66 0 0 0
@withstudiocms/buildkit Tests 130ms Passed tests 10 0 0 0
@withstudiocms/cli-kit Tests 461ms Passed tests 72 0 0 0
@studiocms/cloudinary-image-service Tests 102ms Passed tests 20 0 0 0
@withstudiocms/component-registry Tests 2s 939ms Passed tests 153 0 0 0
@withstudiocms/config-utils Tests 128ms Passed tests 8 6 0 0
@studiocms/devapps Tests 222ms Passed tests 116 0 0 0
@studiocms/discord Tests 19ms Passed tests 2 0 0 0
@withstudiocms/effect Tests 12s 674ms Passed tests 107 0 0 0
effectify Tests 889ms Passed tests 84 0 0 0
@studiocms/github Tests 16ms Passed tests 2 0 0 0
@studiocms/google Tests 14ms Passed tests 2 0 0 0
@studiocms/html Tests 79ms Passed tests 16 0 0 0
@withstudiocms/internal_helpers Tests 225ms Passed tests 118 2 0 0
@withstudiocms/kysely Tests 369ms Passed tests 36 0 0 0
@studiocms/markdoc Tests 128ms Passed tests 13 0 0 0
@studiocms/markdown-remark Tests 224ms Passed tests 38 0 0 0
@studiocms/md Tests 81ms Passed tests 12 0 0 0
@studiocms/mdx Tests 97ms Passed tests 12 0 0 0
studiocms Tests 1s 553ms Passed tests 344 0 0 0
@withstudiocms/template-lang Tests 44ms Passed tests 36 0 0 0
@studiocms/wysiwyg Tests 188ms Passed tests 50 0 0 0

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

@Adammatthiesen Adammatthiesen changed the title [WIP] Replace tsdown with Vite for bundling and update loader API Replace tsdown with Vite for bundling and update loader API Jul 16, 2026
@Adammatthiesen
Adammatthiesen marked this pull request as ready for review July 16, 2026 21:00
@Adammatthiesen
Adammatthiesen requested a review from a team as a code owner July 16, 2026 21:00

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (1)
packages/@withstudiocms/config-utils/test/loader.test.ts (1)

17-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Restore coverage for missing configs and path precedence.

The matrix only tests roots containing one candidate. Add cases asserting {} when none exist and that the first entry in configPaths wins when both files exist; both are changed loader contracts currently left unprotected.

Also applies to: 35-46

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/`@withstudiocms/config-utils/test/loader.test.ts at line 17, Extend
the loader test matrix around configPaths to cover roots with neither candidate,
asserting the loader returns {}; add a case where both example.config.js and
example.config.ts exist and assert the first configPaths entry is selected.
Preserve the existing single-candidate cases and verify precedence follows
configPaths order.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.changeset/nice-books-mate.md:
- Line 6: Update the changeset summary to use “Vite-based” and document that
loadConfigFile now uses an options-based API, callers must adapt accordingly,
and Vite SSR fallback loading has been added; briefly state the migration
rationale and relevant dependency/API impact in line with the pre-1.0 policy.

In `@packages/`@withstudiocms/config-utils/src/astro-integration-utils.ts:
- Around line 33-40: Update the missing-config handling around loadConfigFile so
an empty object result is recognized as “no config file found” rather than
treated as successfully loaded. Preserve the existing default-configuration
logging and effectSchema decoding for the missing-config path, while continuing
to parse non-empty loaded configuration normally.

In `@packages/`@withstudiocms/config-utils/src/loader.ts:
- Around line 30-35: Keep dynamically loaded configuration typed as unknown
until schema validation: update
packages/@withstudiocms/config-utils/src/loader.ts lines 30-35 to return unknown
or a validated Record<string, unknown>, and update the parse methods at
packages/studiocms/src/cli/utils/loadConfig.ts lines 23-25 and
packages/studiocms/src/db/plugins.ts lines 23-25 to accept unknown rather than
any or an overly specific type.
- Around line 1-3: Update packages/@withstudiocms/config-utils/src/loader.ts at
lines 1-3 and 30-35 to remove native access-based discovery and use the injected
fs implementation instead, ensuring injected-only configs reach the fallback
path. Update resolveId in
packages/@withstudiocms/config-utils/src/utils/vite-plugin-load-fallback.ts at
lines 54-67 to mark parentless top-level config entry imports with the fallback
flag.

---

Nitpick comments:
In `@packages/`@withstudiocms/config-utils/test/loader.test.ts:
- Line 17: Extend the loader test matrix around configPaths to cover roots with
neither candidate, asserting the loader returns {}; add a case where both
example.config.js and example.config.ts exist and assert the first configPaths
entry is selected. Preserve the existing single-candidate cases and verify
precedence follows configPaths order.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 62dc919c-17bd-4c43-a08f-a4aeebf83b13

📥 Commits

Reviewing files that changed from the base of the PR and between 6281424 and d47a91c.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (17)
  • .changeset/nice-books-mate.md
  • packages/@withstudiocms/config-utils/package.json
  • packages/@withstudiocms/config-utils/src/astro-integration-utils.ts
  • packages/@withstudiocms/config-utils/src/loader.ts
  • packages/@withstudiocms/config-utils/src/types.ts
  • packages/@withstudiocms/config-utils/src/utils/createMinimalViteDevServer.ts
  • packages/@withstudiocms/config-utils/src/utils/dynamicResult.ts
  • packages/@withstudiocms/config-utils/src/utils/index.ts
  • packages/@withstudiocms/config-utils/src/utils/tryCatch.ts
  • packages/@withstudiocms/config-utils/src/utils/vite-plugin-load-fallback.ts
  • packages/@withstudiocms/config-utils/test/fixtures/loader-js/example.config.js
  • packages/@withstudiocms/config-utils/test/fixtures/loader-ts/example.config.ts
  • packages/@withstudiocms/config-utils/test/loader.test.ts
  • packages/@withstudiocms/config-utils/test/utils/tryCatch.test.ts
  • packages/studiocms/src/cli/debug/index.ts
  • packages/studiocms/src/cli/utils/loadConfig.ts
  • packages/studiocms/src/db/plugins.ts
💤 Files with no reviewable changes (5)
  • packages/@withstudiocms/config-utils/test/utils/tryCatch.test.ts
  • packages/@withstudiocms/config-utils/src/utils/dynamicResult.ts
  • packages/@withstudiocms/config-utils/src/types.ts
  • packages/@withstudiocms/config-utils/src/utils/tryCatch.ts
  • packages/@withstudiocms/config-utils/src/utils/index.ts

Comment thread .changeset/nice-books-mate.md Outdated
Comment thread packages/@withstudiocms/config-utils/src/astro-integration-utils.ts Outdated
Comment thread packages/@withstudiocms/config-utils/src/loader.ts Outdated
Comment thread packages/@withstudiocms/config-utils/src/loader.ts Outdated
@Adammatthiesen
Adammatthiesen merged commit b42fb34 into main Jul 17, 2026
29 checks passed
@Adammatthiesen
Adammatthiesen deleted the new-config-loader branch July 17, 2026 00:21
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.

2 participants