Skip to content

Commit

Permalink
fix: Nsis license file encode issue (#8314)
Browse files Browse the repository at this point in the history
* add convertFileToUtf8WithBOMSync
  • Loading branch information
beyondkmp authored Jul 10, 2024
1 parent 35a0784 commit 1337f15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-donkeys-protect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"app-builder-lib": patch
---

change license file's encode to utf8 with BOM
15 changes: 15 additions & 0 deletions packages/app-builder-lib/src/targets/nsis/nsisLicense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ import { WinPackager } from "../../winPackager"
import { NsisOptions } from "./nsisOptions"
import { NsisScriptGenerator } from "./nsisScriptGenerator"
import { nsisTemplatesDir } from "./nsisUtil"
import * as fs from "fs"

function convertFileToUtf8WithBOMSync(filePath: string): boolean {
try {
const data = fs.readFileSync(filePath)
// UTF-8 BOM is EF BB BF
const BOM = Buffer.from([0xef, 0xbb, 0xbf])
const dataWithBOM = Buffer.concat([BOM, data])
fs.writeFileSync(filePath, dataWithBOM)
return true
} catch (err) {
console.error("Failed to convert file to UTF-8 with BOM: ", err)
return false
}
}
export async function computeLicensePage(packager: WinPackager, options: NsisOptions, scriptGenerator: NsisScriptGenerator, languages: Array<string>): Promise<void> {
const license = await getNotLocalizedLicenseFile(options.license, packager)
if (license != null) {
Expand Down Expand Up @@ -43,6 +57,7 @@ export async function computeLicensePage(packager: WinPackager, options: NsisOpt
let defaultFile: string | null = null
for (const item of licenseFiles) {
unspecifiedLangs.delete(item.langWithRegion)
convertFileToUtf8WithBOMSync(item.file)
if (defaultFile == null) {
defaultFile = item.file
}
Expand Down

0 comments on commit 1337f15

Please sign in to comment.