Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
NickGerleman committed Nov 14, 2023
1 parent 866f8ae commit 16a4d34
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions packages/docusaurus/src/webpack/plugins/WaitPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,17 @@ async function waitOn(filepath: string): Promise<void> {
let lastFileTime = -1;

for (;;) {
const size = await fileSize(filepath);

if (size !== null) {
if (size === lastFileSize) {
if (performance.now() - lastFileTime >= stabilityWindowMs) {
return;
}
} else {
let size = -1;
try {
size = (await stat(filepath)).size;
} catch (err) {}

if (size !== -1) {
if (lastFileTime === -1 || size !== lastFileSize) {
lastFileSize = size;
lastFileTime = performance.now();
} else if (performance.now() - lastFileTime >= stabilityWindowMs) {
return;
}
}

Expand All @@ -51,11 +52,3 @@ async function waitOn(filepath: string): Promise<void> {
});
}
}

async function fileSize(filepath: string): Promise<number | null> {
try {
return (await stat(filepath)).size;
} catch (err) {
return null;
}
}

0 comments on commit 16a4d34

Please sign in to comment.