Replace tsdown with Vite for bundling and update loader API#1606
Conversation
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 detectedLatest commit: 1507225 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe 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. ChangesConfiguration loading migration
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
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
create-studiocms
effectify
studiocms
@studiocms/auth0
@studiocms/blog
@studiocms/cloudinary-image-service
@studiocms/devapps
@studiocms/discord
@studiocms/github
@studiocms/google
@studiocms/html
@studiocms/markdoc
@studiocms/markdown-remark
@studiocms/md
@studiocms/mdx
@studiocms/s3-storage
@studiocms/upgrade
@studiocms/wysiwyg
@withstudiocms/api-spec
@withstudiocms/auth-kit
@withstudiocms/cli-kit
@withstudiocms/component-registry
@withstudiocms/config-utils
@withstudiocms/effect
@withstudiocms/internal_helpers
@withstudiocms/kysely
@withstudiocms/sdk
@withstudiocms/template-lang
commit: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Nitpick comments (1)
packages/@withstudiocms/config-utils/test/loader.test.ts (1)
17-17: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winRestore 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 inconfigPathswins 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
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (17)
.changeset/nice-books-mate.mdpackages/@withstudiocms/config-utils/package.jsonpackages/@withstudiocms/config-utils/src/astro-integration-utils.tspackages/@withstudiocms/config-utils/src/loader.tspackages/@withstudiocms/config-utils/src/types.tspackages/@withstudiocms/config-utils/src/utils/createMinimalViteDevServer.tspackages/@withstudiocms/config-utils/src/utils/dynamicResult.tspackages/@withstudiocms/config-utils/src/utils/index.tspackages/@withstudiocms/config-utils/src/utils/tryCatch.tspackages/@withstudiocms/config-utils/src/utils/vite-plugin-load-fallback.tspackages/@withstudiocms/config-utils/test/fixtures/loader-js/example.config.jspackages/@withstudiocms/config-utils/test/fixtures/loader-ts/example.config.tspackages/@withstudiocms/config-utils/test/loader.test.tspackages/@withstudiocms/config-utils/test/utils/tryCatch.test.tspackages/studiocms/src/cli/debug/index.tspackages/studiocms/src/cli/utils/loadConfig.tspackages/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
This pull request migrates the
@withstudiocms/config-utilspackage 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
loadConfigFilefunction 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:
tsdowndependency 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:
.changeset/nice-books-mate.md)Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Tests