Skip to content

Commit

Permalink
[tools] Fix transforming binary files
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta committed Sep 26, 2022
1 parent d16cdc5 commit 1110cef
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/src/Transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,14 @@ export async function copyFileWithTransformsAsync(
transformMatchPath: sourceFile,
});

// Save transformed source file at renamed target path.
await fs.outputFile(targetPath, content);
if (filteredContentTransforms.length > 0) {
// Save transformed source file at renamed target path.
await fs.outputFile(targetPath, content);
} else {
// When there are no transforms, it's safer to just copy the file.
// Only then binary files will be copied properly since the `content` is utf8-encoded.
await fs.copy(sourcePath, targetPath, { overwrite: true });
}

// Keep original file mode if needed.
if (options.keepFileMode) {
Expand Down

0 comments on commit 1110cef

Please sign in to comment.