Skip to content

Commit c41fd52

Browse files
committed
fix: the code was incorrectly skipping
1 parent 428f1e9 commit c41fd52

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/generators/legacy-html/utils/safeCopy.mjs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,14 @@ import { glob } from 'glob';
1313
* @param {string} targetDir - Target directory path
1414
*/
1515
export async function safeCopy(srcDir, targetDir) {
16-
// Get all files in the source folder (no subdirectories expected)
1716
const files = await glob('*', {
1817
cwd: srcDir,
1918
dot: true,
2019
nodir: true,
2120
});
2221

23-
// Copy each file individually
2422
for (const file of files) {
2523
const sourcePath = join(srcDir, file);
26-
2724
const targetPath = join(targetDir, file);
2825

2926
const [sStat, tStat] = await Promise.allSettled([
@@ -32,17 +29,16 @@ export async function safeCopy(srcDir, targetDir) {
3229
]);
3330

3431
const shouldWrite =
35-
// the target file doesn't exist
36-
sStat.status === 'rejected' ||
37-
// file sizes are different
38-
sStat.size !== tStat.size ||
39-
// source got modified / is newer
40-
sStat.mtimeMs > tStat.mtimeMs;
41-
42-
if (shouldWrite) {
43-
const fileContent = await readFile(sourcePath);
32+
tStat.status === 'rejected' ||
33+
sStat.value.size !== tStat.value.size ||
34+
sStat.value.mtimeMs > tStat.value.mtimeMs;
4435

45-
await writeFile(targetPath, fileContent);
36+
if (!shouldWrite) {
37+
continue;
4638
}
39+
40+
const fileContent = await readFile(sourcePath);
41+
42+
await writeFile(targetPath, fileContent);
4743
}
4844
}

0 commit comments

Comments
 (0)