Skip to content

Commit a079f1f

Browse files
authored
fix: partial output lost when change multiple files at the same time (#576)
1 parent 377b727 commit a079f1f

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/builder/bundless/index.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,27 @@ async function bundless(
185185
// watching for watch mode
186186
logger.event(`Start watching ${opts.configProvider.input} directory...`);
187187

188+
// debounce transform to combine multiple changes
189+
const handleTransform = (() => {
190+
const pendingSet = new Set<string>();
191+
const startTransform = lodash.debounce(() => {
192+
transformFiles([...pendingSet], opts);
193+
pendingSet.clear();
194+
}, WATCH_DEBOUNCE_STEP);
195+
196+
return (filePath: string) => {
197+
pendingSet.add(filePath);
198+
startTransform();
199+
};
200+
})();
188201
const watcher = chokidar
189202
.watch(opts.configProvider.input, {
190203
cwd: opts.cwd,
191204
ignoreInitial: true,
192205
ignored: DEFAULT_BUNDLESS_IGNORES,
193206
})
194-
.on('add', (rltFilePath) => {
195-
transformFiles([rltFilePath], opts);
196-
})
197-
.on(
198-
'change',
199-
lodash.debounce(
200-
(filePath: string) => {
201-
transformFiles([filePath], opts);
202-
},
203-
WATCH_DEBOUNCE_STEP,
204-
{ leading: true, trailing: false },
205-
),
206-
)
207+
.on('add', handleTransform)
208+
.on('change', handleTransform)
207209
.on('unlink', (rltFilePath) => {
208210
const isTsFile = /\.tsx?$/.test(rltFilePath);
209211
const config = opts.configProvider.getConfigForFile(rltFilePath);

0 commit comments

Comments
 (0)