Skip to content

Commit dc17982

Browse files
authored
fix(init): generate .void types on install in scaffolded starters (#521)
Fixes #519 Add `"postinstall": "void prepare"` to the starter scripts. Init installs after writing the starter, so a new scaffold gets the types at that point, and a fresh clone gets them on install. This is the same approach as `nuxt prepare`. `EMPTY_PROJECT_ALLOWED_SCRIPTS` also allows `postinstall: void prepare`, so running init again on a starter still sees it as an empty project. Checked: - `init.test.ts` (`postinstall` in the React + D1 starter, and the deleted-starter check) - a 1.1.12 starter cloned fresh with `postinstall` added: `pnpm install` creates `.void/db.d.ts` and `routes.d.ts`, and `tsc` passes (it fails without it) 16 tests in `init.test.ts` fail locally on main too. This PR adds no new failures.
1 parent e2dfa11 commit dc17982

3 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎packages/void/src/cli/init.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ const EMPTY_PROJECT_ALLOWED_SCRIPTS: Record<string, Set<string> | undefined> = {
241241
dev: new Set(['vite', 'vp dev']),
242242
build: new Set(['vite build', 'vp build']),
243243
preview: new Set(['vite preview', 'vp preview']),
244+
postinstall: new Set(['void prepare']),
244245
};
245246
const EMPTY_PROJECT_STARTER_SCRIPT_COMMANDS = new Set(
246247
Object.values(EMPTY_PROJECT_ALLOWED_SCRIPTS).flatMap((commands) =>

‎packages/void/src/cli/template.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ export function createPagesStarterTemplate(options: {
189189
dev: toolchain === 'vite-plus' ? 'vp dev' : 'vite',
190190
build: toolchain === 'vite-plus' ? 'vp build' : 'vite build',
191191
preview: toolchain === 'vite-plus' ? 'vp preview' : 'vite preview',
192+
// `.void/` is gitignored, so fresh clones and new scaffolds need the
193+
// generated types before the editor opens tsconfig.json.
194+
postinstall: 'void prepare',
192195
},
193196
dependencies: {
194197
...SCAFFOLD_BASE_DEPENDENCIES,

‎packages/void/test/unit/init.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,7 @@ describe('isScaffoldableEmptyProject', () => {
12051205
dev: 'vp dev',
12061206
build: 'vp build',
12071207
preview: 'vp preview',
1208+
postinstall: 'void prepare',
12081209
},
12091210
dependencies: {
12101211
hono: '^4.11.9',
@@ -1321,6 +1322,7 @@ describe('isScaffoldableEmptyProject', () => {
13211322
expect(pkg.scripts.dev).toBe('vp dev');
13221323
expect(pkg.scripts.build).toBe('vp build');
13231324
expect(pkg.scripts.preview).toBe('vp preview');
1325+
expect(pkg.scripts.postinstall).toBe('void prepare');
13241326

13251327
const reactViteConfig = readFileSync(join(root, 'vite.config.ts'), 'utf-8');
13261328
expect(reactViteConfig).toContain('from "@void/react/plugin"');

0 commit comments

Comments
 (0)