Skip to content

Commit 744317b

Browse files
authored
fix(build): do not utf8-read/write images MONGOSH-763 (#869)
1 parent d2ffcea commit 744317b

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/build/src/packaging/package/helpers.ts

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,19 @@ export async function generateDirFromTemplate(sourceDir: string, interpolations:
6161
await copyDirAndApplyTemplates(sourceFile, targetFile);
6262
} else {
6363
const sourceText = await fs.readFile(sourceFile, 'utf8');
64-
const interpolatedText = sourceText.replace(
65-
/\{\{(\w+)\}\}/g,
66-
(_match, identifier) => {
67-
if (!(identifier in interpolations)) {
68-
throw new Error(`Need ${identifier} for replacement in ${sourceFile}`);
69-
}
70-
return interpolations[identifier];
71-
});
72-
await fs.writeFile(targetFile, interpolatedText);
64+
if (!sourceText.includes('\ufffd')) { // This is valid UTF-8, i.e. a text file
65+
const interpolatedText = sourceText.replace(
66+
/\{\{(\w+)\}\}/g,
67+
(_match, identifier) => {
68+
if (!(identifier in interpolations)) {
69+
throw new Error(`Need ${identifier} for replacement in ${sourceFile}`);
70+
}
71+
return interpolations[identifier];
72+
});
73+
await fs.writeFile(targetFile, interpolatedText);
74+
} else {
75+
await fs.copyFile(sourceFile, targetFile);
76+
}
7377
}
7478
}
7579
}

0 commit comments

Comments
 (0)