diff --git a/.changeset/heavy-dragons-tie.md b/.changeset/heavy-dragons-tie.md new file mode 100644 index 0000000000..7a29c5b0d7 --- /dev/null +++ b/.changeset/heavy-dragons-tie.md @@ -0,0 +1,6 @@ +--- +'houdini-react': patch +'houdini': patch +--- + +Fix bug when generating fresh project files with a local schema diff --git a/e2e/react/package.json b/e2e/react/package.json index 33be5d0483..f501d116f3 100644 --- a/e2e/react/package.json +++ b/e2e/react/package.json @@ -11,7 +11,7 @@ "build:build": "pnpm build: && pnpm build", "dev": "vite dev", "build": "vite build", - "tests": "playwright test", + "tests": "npm run build && playwright test", "test": "npm run tests", "tw": "npx tailwindcss -i ./src/styles.css -o ./public/assets/output.css --watch", "preview": "vite dev" diff --git a/e2e/react/tsconfig.json b/e2e/react/tsconfig.json index 0dd61e17a0..fd3238fb29 100644 --- a/e2e/react/tsconfig.json +++ b/e2e/react/tsconfig.json @@ -1,35 +1,3 @@ { - "compilerOptions": { - "baseUrl": ".", - "paths": { - "$houdini": ["./$houdini"], - "$houdini/*": ["./$houdini/*"], - "~": ["./src"], - "~/*": ["./src/*"] - }, - "rootDirs": [".", "./$houdini/types"], - "target": "ESNext", - "useDefineForClassFields": true, - "lib": ["DOM", "DOM.Iterable", "ESNext"], - "allowJs": false, - "skipLibCheck": true, - "esModuleInterop": false, - "allowSyntheticDefaultImports": true, - "strict": true, - "forceConsistentCasingInFileNames": true, - "module": "ESNext", - "moduleResolution": "Node", - "resolveJsonModule": true, - "isolatedModules": true, - "noEmit": true, - "jsx": "react-jsx" - }, - "include": [ - "ambient.d.ts", - "./types/**/$types.d.ts", - "./vite.config.ts", - "./src/**/*.ts", - "./src/**/*.tsx" - ], - "exclude": ["../node_modules/**", "./[!ambient.d.ts]**"] + "extends": "./$houdini/tsconfig.json" } diff --git a/packages/houdini-react/src/plugin/codegen/typeRoot.ts b/packages/houdini-react/src/plugin/codegen/typeRoot.ts index e78d129575..7e78714ab8 100644 --- a/packages/houdini-react/src/plugin/codegen/typeRoot.ts +++ b/packages/houdini-react/src/plugin/codegen/typeRoot.ts @@ -121,53 +121,6 @@ ${ ]) } -export async function writeTsconfig(config: Config) { - await fs.writeFile( - path.join(config.rootDir, 'tsconfig.json'), - JSON.stringify( - { - compilerOptions: { - paths: { - $houdini: ['.'], - '$houdini/*': ['./*'], - '~': ['../src'], - '~/*': ['../src/*'], - }, - rootDirs: ['..', './types'], - target: 'ESNext', - useDefineForClassFields: true, - lib: ['DOM', 'DOM.Iterable', 'ESNext'], - allowJs: false, - skipLibCheck: true, - esModuleInterop: false, - allowSyntheticDefaultImports: true, - strict: true, - forceConsistentCasingInFileNames: true, - module: 'ESNext', - moduleResolution: 'Node', - resolveJsonModule: true, - isolatedModules: true, - noEmit: true, - jsx: 'react-jsx', - }, - include: [ - 'ambient.d.ts', - './types/**/$types.d.ts', - '../vite.config.ts', - '../src/**/*.js', - '../src/**/*.ts', - '../src/**/*.jsx', - '../src/**/*.tsx', - '../src/+app.d.ts', - ], - exclude: ['../node_modules/**', './[!ambient.d.ts]**'], - }, - null, - 4 - ) - ) -} - function paramsType(config: Config, params?: PageManifest['params']): string { return `{ ${Object.entries(params ?? {}) diff --git a/packages/houdini-react/src/plugin/vite.tsx b/packages/houdini-react/src/plugin/vite.tsx index 6a50660111..3d041cefa0 100644 --- a/packages/houdini-react/src/plugin/vite.tsx +++ b/packages/houdini-react/src/plugin/vite.tsx @@ -9,11 +9,9 @@ import { routerConventions, } from 'houdini' import React from 'react' -import ReactDOM from 'react-dom/server' import { build, ConfigEnv, type BuildOptions, type Connect } from 'vite' import { manifest, setManifest } from '.' -import { writeTsconfig } from './codegen/typeRoot' let viteEnv: ConfigEnv let devServer = false @@ -115,10 +113,6 @@ export default { return id.substring(id.indexOf('virtual:houdini')) }, - async buildStart({ houdiniConfig }) { - await writeTsconfig(houdiniConfig) - }, - async closeBundle(config) { // skip close bundles during dev mode if (isSecondaryBuild() || viteEnv.mode !== 'production' || devServer) { @@ -363,7 +357,6 @@ root.render(React.createElement(App, { // capture the request before vite's dev server processes it. async configureServer(server) { devServer = true - await writeTsconfig(server.houdiniConfig) server.middlewares.use(async (req, res, next) => { if (!req.url) { diff --git a/packages/houdini/src/lib/typescript.ts b/packages/houdini/src/lib/typescript.ts index a1ad8fdf04..dd76d49f76 100644 --- a/packages/houdini/src/lib/typescript.ts +++ b/packages/houdini/src/lib/typescript.ts @@ -2,7 +2,7 @@ import type { StatementKind, TSTypeKind } from 'ast-types/lib/gen/kinds' import * as graphql from 'graphql' import * as recast from 'recast' -import { ensureImports, type Config, path } from '.' +import { ensureImports, type Config, path, fs } from '.' import { unwrapType, TypeWrapper } from './graphql' const AST = recast.types.builders @@ -222,3 +222,52 @@ export function scalarPropertyValue( } } } + +export async function writeTsConfig(config: Config) { + await fs.mkdirp(config.rootDir) + await fs.writeFile( + path.join(config.rootDir, 'tsconfig.json'), + JSON.stringify( + { + compilerOptions: { + baseUrl: '.', + paths: { + $houdini: ['.'], + '$houdini/*': ['./*'], + '~': ['../src'], + '~/*': ['../src/*'], + }, + rootDirs: ['..', './types'], + target: 'ESNext', + useDefineForClassFields: true, + lib: ['DOM', 'DOM.Iterable', 'ESNext'], + allowJs: false, + skipLibCheck: true, + esModuleInterop: false, + allowSyntheticDefaultImports: true, + strict: true, + forceConsistentCasingInFileNames: true, + module: 'ESNext', + moduleResolution: 'Node', + resolveJsonModule: true, + isolatedModules: true, + noEmit: true, + jsx: 'react-jsx', + }, + include: [ + 'ambient.d.ts', + './types/**/$types.d.ts', + '../vite.config.ts', + '../src/**/*.js', + '../src/**/*.ts', + '../src/**/*.jsx', + '../src/**/*.tsx', + '../src/+app.d.ts', + ], + exclude: ['../node_modules/**', './[!ambient.d.ts]**'], + }, + null, + 4 + ) + ) +} diff --git a/packages/houdini/src/vite/houdini.ts b/packages/houdini/src/vite/houdini.ts index e37ad7798e..67b43430a0 100644 --- a/packages/houdini/src/vite/houdini.ts +++ b/packages/houdini/src/vite/houdini.ts @@ -14,6 +14,7 @@ import { load_manifest, loadLocalSchema, isSecondaryBuild, + writeTsConfig, } from '../lib' let config: Config @@ -152,6 +153,8 @@ export default function Plugin(opts: PluginConfig = {}): VitePlugin { // when the build starts, we need to make sure to generate async buildStart(args) { + await writeTsConfig(config) + // check if the adapter has a pre hook if (config.adapter?.pre && viteEnv.command === 'build' && !isSecondaryBuild()) { await config.adapter.pre({ @@ -213,6 +216,8 @@ export default function Plugin(opts: PluginConfig = {}): VitePlugin { async configureServer(server) { devServer = true + await writeTsConfig(config) + // if there is a local schema we need to use that when generating if (config.localSchema) { config.schema = (await server.ssrLoadModule(config.localSchemaPath))