Skip to content

fix(cli,framework): make scaffolded projects build and run out of the box#121

Merged
antosubash merged 2 commits intomainfrom
feature/quirky-jennings-068faf
Apr 23, 2026
Merged

fix(cli,framework): make scaffolded projects build and run out of the box#121
antosubash merged 2 commits intomainfrom
feature/quirky-jennings-068faf

Conversation

@antosubash
Copy link
Copy Markdown
Owner

Summary

sm new project produced a project that failed to compile, npm install, or serve API traffic. This PR fixes the full chain so a freshly-scaffolded app works end-to-end via the standard npm install && npm run build && dotnet run flow — no manual patching.

Root causes & fixes

Source generator emitted references to assemblies that lean hosts don't reference

AgentExtensionsEmitter.cs and SettingsExtensionsEmitter.cs unconditionally emitted global::SimpleModule.Agents.AgentRegistry and global::SimpleModule.Rag.RagSettingsDefinitions. A scaffolded host only references SimpleModule.Hosting, which does not transitively pull in Agents/Rag, so builds failed with CS0234: The type or namespace name 'Agents' does not exist in the namespace 'SimpleModule'.

Gated both emissions on new HasAgentsAssembly / HasRagAssembly symbol-presence flags in CoreSymbols.cs and plumbed them through DiscoveryData. In-repo host (which does reference Agents/Rag) still gets the full emission.

Startup DB init never created module tables for scaffolded apps

SimpleModuleHostExtensions.cs:146 called MigrateAsync on the Host DbContext, but scaffolded apps ship no migrations so no tables were created. First GET /api/items returned 500 with SQLite Error 1: 'no such table: Items_Items'.

Fall back to EnsureCreatedAsync when the context has no migrations; projects with migrations call MigrateAsync unchanged.

CLI sm new project generated a broken root package.json

ProjectTemplates.cs:704 had multiple issues:

  • Lowercased workspace path (src/testapp.Host/ClientApp) — only resolves on case-insensitive filesystems.
  • Missing @simplemodule/tsconfig dep → vite TSConfckParseError: failed to resolve "extends":"@simplemodule/tsconfig/base".
  • Missing esbuild peer dep → vite config load fails with Cannot find module 'esbuild'.
  • @inertiajs/react@^2.0.0 vs peer ^3.0.0, vite@^6.2.0 vs peer ^8.0.0 — both caused npm install to ERESOLVE.

Bumped all deps to match the framework packages' peer requirements:

Dep Before After
@inertiajs/react ^2.0.0 ^3.0.0
vite ^6.2.0 ^8.0.3
@vitejs/plugin-react ^4.4.0 ^6.0.1
cross-env ^7.0.3 ^10.1.0
typescript ^5.8.0 ^6.0.2
tailwindcss + @tailwindcss/vite ^4.2.1 ^4.2.2
@biomejs/biome ^2.4.6 ^2.4.10
esbuild missing ^0.27.0
@simplemodule/tsconfig missing matches framework version

Starter module's vite config + scripts were incompatible with vite 8

NewProjectCommand.cs:494-506:

  • vite.config.ts used __dirname, which is undefined under vite 8's configLoader=runner ESM loader. Switched to import.meta.dirname to match the in-repo module convention.
  • Starter module package.json had "build": "vite build" with no --configLoader runner flag, causing TS config loads to fail. Updated scripts to cross-env VITE_MODE=prod vite build --configLoader runner (and matching build:dev / watch), matching the in-repo module package.json shape.

Test plan

  • dotnet build framework/SimpleModule.Generator succeeds with new HasRagAssembly symbol plumbing
  • dotnet build template/SimpleModule.Host still succeeds (in-repo host references Agents/Rag)
  • Fresh sm new project DemoApp scaffolds
  • npm install resolves cleanly with no ERESOLVE errors (191 packages, no --legacy-peer-deps needed)
  • npm run build produces wwwroot/js/app.js + Items.pages.js
  • dotnet build on the scaffolded project succeeds (0 errors) — generator no longer emits dangling Agent/Rag references
  • dotnet run starts the host; EnsureCreated creates Items_Items table on first boot
  • GET /api/items returns HTTP 200 []
  • GET / returns HTTP 200 with the Inertia welcome page
  • GET /swagger/v1/swagger.json exposes /api/items

… box

sm new project produced a project that failed to compile, install, and
run. This fixes the full chain so a fresh scaffold works end-to-end via
the standard npm install && npm run build && dotnet run flow.

Generator (SimpleModule.Generator):
- AgentExtensions.g.cs and SettingsExtensions.g.cs unconditionally
  referenced SimpleModule.Agents.AgentRegistry / SimpleModule.Rag.*
  types. Projects that don't depend on those assemblies failed with
  CS0234. Gate the emissions on new HasAgentsAssembly / HasRagAssembly
  symbol-presence checks so lean hosts compile.

Host runtime (SimpleModule.Hosting):
- Dev/SQLite startup called MigrateAsync on the Host DbContext, but
  scaffolded apps ship no migrations, so module tables were never
  created and the first API call returned 500 ("no such table").
  Fall back to EnsureCreatedAsync when no migrations exist; projects
  with migrations still call MigrateAsync unchanged.

CLI templates (SimpleModule.Cli):
- Root package.json used lowercased workspace path
  (src/testapp.Host/ClientApp) that only resolves on case-insensitive
  filesystems. Use the actual project casing; npm name field stays
  lowercase.
- Missing @simplemodule/tsconfig and esbuild peer deps caused vite
  config load failures. Add both.
- @inertiajs/react (^2 -> ^3), vite (^6 -> ^8), @vitejs/plugin-react
  (^4 -> ^6), cross-env (^7 -> ^10), typescript (^5 -> ^6),
  tailwindcss (4.2.1 -> 4.2.2), @biomejs/biome (2.4.6 -> 2.4.10)
  bumped to match the framework packages peer deps.
- Starter module package.json used vite build without
  --configLoader runner, which fails loading TS configs under vite 8.
  Wrap with cross-env VITE_MODE and add --configLoader runner on
  build/build:dev/watch to match the in-repo module script shape.
- Starter module vite.config.ts used __dirname (CJS); vite 8
  configLoader=runner loads configs as ESM where __dirname is
  undefined. Use import.meta.dirname instead.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 23, 2026

Deploying simplemodule-website with  Cloudflare Pages  Cloudflare Pages

Latest commit: ecb3e55
Status: ✅  Deploy successful!
Preview URL: https://d2df0eca.simplemodule-website.pages.dev
Branch Preview URL: https://feature-quirky-jennings-068f.simplemodule-website.pages.dev

View logs

@antosubash antosubash merged commit 8e66dd0 into main Apr 23, 2026
5 checks passed
@antosubash antosubash deleted the feature/quirky-jennings-068faf branch April 23, 2026 20:25
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