Skip to content

Commit 427c434

Browse files
committed
only write to file if changed
1 parent 12d23c6 commit 427c434

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,19 @@ export const build = async (options: BuildOptions): Promise<BuildResult> => {
108108
// Create the directory if it doesn't exist
109109
await fs.mkdir(dirName, { recursive: true });
110110

111-
// Write the file
112-
await fs.writeFile(fullPath, result, "utf8");
111+
// Only write the file if content has changed
112+
let shouldWrite = true;
113+
try {
114+
const existingContent = await fs.readFile(fullPath, "utf8");
115+
shouldWrite = existingContent !== result;
116+
} catch {
117+
// File doesn't exist or can't be read, so we should write it
118+
shouldWrite = true;
119+
}
120+
121+
if (shouldWrite) {
122+
await fs.writeFile(fullPath, result, "utf8");
123+
}
113124

114125
// Record successful file write
115126
await fs.stat(fullPath);

0 commit comments

Comments
 (0)