Skip to content

Commit

Permalink
[tools] Fix transforming binary files [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
tsapeta committed Sep 13, 2022
1 parent 7c2c37d commit f394898
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions tools/src/Transforms.ts
Expand Up @@ -125,8 +125,14 @@ export async function copyFileWithTransformsAsync(
// Transform source content.
const content = await getTransformedFileContentAsync(sourcePath, filteredContentTransforms);

// 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 f394898

Please sign in to comment.