Skip to content

Commit 94e4a9b

Browse files
committed
fix: Add try catch on generate to keep vite running
1 parent f772ad9 commit 94e4a9b

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/index.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@ export default function VitePluginGraphQLCodegen(): Plugin {
1818
viteConfig = resolvedConfig;
1919
},
2020
async buildStart() {
21-
await generate(codegenContext);
21+
try {
22+
await generate(codegenContext);
23+
} catch (error) {
24+
console.log('Something went wrong.');
25+
}
2226
},
2327
configureServer(server) {
24-
const listener = (path = '') => {
28+
const listener = async (path = '') => {
2529
const { generates, documents } = codegenContext.getConfig();
2630

2731
// Check if file is a generated file
@@ -30,11 +34,15 @@ export default function VitePluginGraphQLCodegen(): Plugin {
3034
if (isGenerated) return;
3135

3236
// Check if file is an operation document
33-
const [, fileName = ''] = path.split(`${viteConfig.root}/`);
34-
const isDocument = minimatch(fileName, documents);
37+
const [, relativePath = ''] = path.split(`${viteConfig.root}/`);
38+
const isDocument = minimatch(relativePath, documents);
3539
if (!isDocument) return;
3640

37-
generate(codegenContext);
41+
try {
42+
await generate(codegenContext);
43+
} catch (error) {
44+
console.log('Something went wrong. Please save the file again.');
45+
}
3846
};
3947

4048
server.watcher.on('add', listener);

0 commit comments

Comments
 (0)