fix(client): type import.meta.main for run-if-main idioms (#2811)#2955
Merged
viniciusdacal merged 2 commits intomainfrom Apr 22, 2026
Merged
fix(client): type import.meta.main for run-if-main idioms (#2811)#2955viniciusdacal merged 2 commits intomainfrom
viniciusdacal merged 2 commits intomainfrom
Conversation
Closes #2811. Follow-up to #2777. The vtz runtime (via deno_core) already sets `import.meta.main` on every module — true for the entry module, false for imports — so the standard "run if main" guard works without polyfill. Previously the type was only visible to projects that pulled in bun-types. Add `readonly main: boolean` to the client augmentation so any tsconfig that includes `"types": ["vertz/client"]` (or `"@vertz/ui/client"`) gets it automatically. Scaffolded apps already have this entry. Drop bun-types from sites/dev-orchestrator where it was only kept for this type. examples/entity-todo and packages/icons keep their existing type resolution — entity-todo still uses Bun.Transpiler in its test compiler plugin, and icons picks up types globally. Also add Rust integration tests verifying the runtime guarantee: `test_import_meta_main_true_for_entry_module` and `test_import_meta_main_false_for_imported_module`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Review follow-up. bun-types declares `ImportMeta.main` as mutable `main: boolean` (not readonly). Declaration merging requires identical modifiers across declarations, so a project that keeps BOTH bun-types and vertz/client in its tsconfig `types` would hit `TS2687: All declarations must have identical modifiers` once `skipLibCheck` is turned off. The monorepo's skipLibCheck: true silences it today, but it's a latent footgun for downstream users. Drop `readonly` to match bun-types exactly. `import.meta.main` isn't meant to be mutated by anyone anyway. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2811.
Summary
Follow-up to #2777. The vtz runtime (via
deno_core) already setsimport.meta.mainon every module —truefor the entry module,falsefor imports — so the standard "run if main" guard works without any polyfill. This PR types it invertz/clientso apps don't needbun-typesjust to satisfy TypeScript.Public API Changes
Addition:
ImportMeta.main: booleandeclared inpackages/ui/client.d.ts. Projects with"types": ["vertz/client"](or"@vertz/ui/client") get it automatically. Scaffolded apps already have this tsconfig entry.Declared as mutable (not
readonly) on purpose —bun-typesdeclares the same property asmain: boolean. Declaration merging requires identical modifiers (TS2687), so matching bun-types avoids a conflict for anyone who keeps both in their tsconfigtypes.Breaking / deferred: None.
Changes
packages/ui/client.d.ts— addmain: booleantoImportMeta.packages/ui/src/__tests__/import-meta-hot.test-d.ts,packages/vertz/src/__tests__/import-meta-hot.test-d.ts— flip@ts-expect-errorassertions from "not declared" toexpectTypeOf<boolean>().native/vtz/tests/v8_integration.rs— addtest_import_meta_main_true_for_entry_moduleandtest_import_meta_main_false_for_imported_module.sites/dev-orchestrator/tsconfig.json+package.json— dropbun-types(only kept for this type; noBun.*API usage anywhere else).examples/entity-todokeepsbun-typesbecause its test compiler plugin still usesBun.Transpiler.packages/mint-docs/guides/env.mdx,packages/site/pages/guides/env.mdx— document the idiom and tie the type tovertz/client..changeset/import-meta-main-type-2811.md— patch bump for@vertz/uiandvertz.Acceptance criteria (from #2811)
import.meta.main— it's already a runtime guarantee via deno_core; now a typed framework-standard idiom.vertz/client/@vertz/ui/clientwith JSDoc.import.meta.main.guides/env.mdx(both mint-docs and site) reflect the decision.Test plan
cargo test --test v8_integration test_import_meta_main— 2 new Rust integration tests pass (main/side modules).vtz testinpackages/ui,packages/vertz,packages/create-vertz-app,packages/icons— all green.tsc --noEmitinpackages/ui,packages/vertz,sites/dev-orchestrator— clean (dev-orchestrator has one pre-existing unrelated error inagent-detail.tsx).vtz run format+vtz run lint— clean.cargo fmt --all -- --check+cargo clippy --all-targets -- -D warnings— clean.Reviews
Adversarial self-review surfaced a latent declaration-merge conflict between
readonly mainand bun-types' mutablemain. Fixed in commit 6117fd9.