Skip to content

Commit

Permalink
Write tsconfig before all generates (#1179)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis authored Sep 28, 2023
1 parent d5cced8 commit 20702a9
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/mean-apes-judge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'houdini-react': patch
---

Fix another bug when deploying a fresh installation
3 changes: 1 addition & 2 deletions packages/houdini-react/src/plugin/codegen/typeRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export async function generate_type_root({
}

await Promise.all([
tsconfig(config),
...Object.entries(pages).map(async ([relative_path, { page, layout }]) => {
// the type root must mirror the source tree
const target_dir = path.join(config.typeRootDir, relative_path)
Expand Down Expand Up @@ -109,7 +108,7 @@ ${layout.query_options
])
}

async function tsconfig(config: Config) {
export async function writeTsconfig(config: Config) {
await fs.writeFile(
path.join(config.rootDir, 'tsconfig.json'),
JSON.stringify(
Expand Down
7 changes: 7 additions & 0 deletions packages/houdini-react/src/plugin/vite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import type { BuildOptions } from 'vite'

import { setManifest } from '.'
import { writeTsconfig } from './codegen/typeRoot'

// in order to coordinate the client and server, the client's pending request cache
// needs to start with a value for every query that we are sending on the server.
Expand Down Expand Up @@ -91,6 +92,12 @@ export default {
return id.substring(id.indexOf('virtual:houdini'))
},

async buildStart({ houdiniConfig }) {
if (!isSecondaryBuild()) {
await writeTsconfig(houdiniConfig)
}
},

async load(id, { config }) {
// we only care about the virtual modules that generate
if (!id.startsWith('virtual:houdini')) {
Expand Down
24 changes: 12 additions & 12 deletions packages/houdini/src/vite/houdini.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ export default function Plugin(opts: PluginConfig = {}): VitePlugin {

// when the build starts, we need to make sure to generate
async buildStart(args) {
for (const plugin of config.plugins) {
if (typeof plugin.vite?.buildStart !== 'function') {
continue
}

// @ts-expect-error
plugin.vite!.buildStart.call(this, {
...args,
houdiniConfig: config,
})
}

// we need to generate the runtime if we are building in production
if (viteEnv.mode === 'production' && !isSecondaryBuild()) {
// make sure we have an up-to-date schema
Expand All @@ -142,18 +154,6 @@ export default function Plugin(opts: PluginConfig = {}): VitePlugin {
throw e
}
}

for (const plugin of config.plugins) {
if (typeof plugin.vite?.buildStart !== 'function') {
continue
}

// @ts-expect-error
plugin.vite!.buildStart.call(this, {
...args,
houdiniConfig: config,
})
}
},

options(options) {
Expand Down

0 comments on commit 20702a9

Please sign in to comment.