Skip to content

Commit

Permalink
refactor: remove typegen flag
Browse files Browse the repository at this point in the history
  • Loading branch information
tylersayshi committed Sep 17, 2024
1 parent 167e908 commit 20bcdd6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 26 deletions.
1 change: 0 additions & 1 deletion examples/05_nossr/waku.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export default {
import('waku/middleware/rsc'),
import('waku/middleware/fallback'),
],
typegen: true,
};
2 changes: 0 additions & 2 deletions packages/waku/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ export interface Config {
* ]
*/
middleware?: () => Promise<{ default: Middleware }>[];

typegen?: boolean;
}

export function defineConfig(config: Config) {
Expand Down
1 change: 0 additions & 1 deletion packages/waku/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export async function resolveConfig(config: Config) {
privateDir: 'private',
rscPath: 'RSC',
middleware: DEFAULT_MIDDLEWARE,
typegen: false,
...config,
};
return resolvedConfig;
Expand Down
18 changes: 14 additions & 4 deletions packages/waku/src/lib/plugins/vite-plugin-typegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@ const generateFile = async (files: [string, string][]) => {

export const typegenPlugin = (): Plugin => {
return {
name: 'vite-file-watcher-plugin',
name: 'vite-fs-router-typegen-plugin',
apply: 'serve',
// TODO Check if in fs-router mode

async transform(code, id, options) {
console.log('transform', code, id, options);
return code;
},

configureServer(server) {
console.log('configureServer');
Expand All @@ -93,10 +100,13 @@ export const typegenPlugin = (): Plugin => {

void updateGeneratedFile();
},
handleHotUpdate(ctx) {
console.log('handleHotUpdate', ctx);
},

// not doing anything for now
// watchChange(change) {
// console.log('watchChange', change);
// },
watchChange(change) {
console.log('watchChange', change);
},
};
};
19 changes: 1 addition & 18 deletions packages/waku/src/lib/utils/vite-loader.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,14 @@
import { createServer as createViteServer } from 'vite';
import { fileURLToFilePath } from '../utils/path.js';
import { typegenPlugin } from '../plugins/vite-plugin-typegen.js';
import type { Config } from 'waku/config';

export const loadServerFile = async (fileURL: string) => {
// temp server to load the waku config to see if typegen is enabled
const viteTempServer = await createViteServer({
ssr: {
external: ['waku'],
},
});

let config: Config = {};
try {
config = (await viteTempServer.ssrLoadModule(fileURLToFilePath(fileURL)))
.default;
} finally {
await viteTempServer.close();
}

const vite = await createViteServer({
ssr: {
external: ['waku'],
},
plugins: config.typegen ? [typegenPlugin()] : [],
plugins: [typegenPlugin()],
});

try {
return vite.ssrLoadModule(fileURLToFilePath(fileURL));
} finally {
Expand Down

0 comments on commit 20bcdd6

Please sign in to comment.