Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit 835a01b

Browse files
committed
chore(cli): move import, fix parallel generation on watch
1 parent 92814ca commit 835a01b

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

packages/cli/src/actions/generate.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { createJiti } from 'jiti';
88
import fs from 'node:fs';
99
import path from 'node:path';
1010
import { pathToFileURL } from 'node:url';
11+
import { watch } from 'chokidar';
1112
import ora, { type Ora } from 'ora';
1213
import { CliError } from '../cli-error';
1314
import * as corePlugins from '../plugins';
@@ -48,10 +49,9 @@ export async function run(options: Options) {
4849
).map((v) => v.$cstNode!.parent!.element.$document!.uri!.fsPath),
4950
);
5051

51-
const { watch } = await import('chokidar');
52-
5352
const watchedPaths = getRootModelWatchPaths(model);
5453
let reGenerateSchemaTimeout: ReturnType<typeof setTimeout> | undefined;
54+
let generationInProgress = false;
5555

5656
if (logsEnabled) {
5757
const logPaths = [...watchedPaths].map((at) => `- ${at}`).join('\n');
@@ -70,6 +70,12 @@ export async function run(options: Options) {
7070

7171
// prevent save multiple files and run multiple times
7272
reGenerateSchemaTimeout = setTimeout(async () => {
73+
if (generationInProgress) {
74+
return;
75+
}
76+
77+
generationInProgress = true;
78+
7379
if (logsEnabled) {
7480
console.log('Got changes, run generation!');
7581
}
@@ -102,6 +108,8 @@ export async function run(options: Options) {
102108
} catch (e) {
103109
console.error(e);
104110
}
111+
112+
generationInProgress = false;
105113
}, 500);
106114
};
107115

0 commit comments

Comments
 (0)