Skip to content

Commit 46da96c

Browse files
Merge pull request #24 from starsstreaming/fix/dsh-profile-json-bom
fix: write DSH profile package.json without a UTF-8 BOM
2 parents 48106e3 + 9802378 commit 46da96c

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

packages/adapter-dsh/test/launcher-scripts.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ test("install-dsh-plugin wires a missing DSH home and can uninstall", () => {
160160
const webPatch = fs.readFileSync(path.join(web, "cordis.patch.yml"), "utf8");
161161
assert.match(webPatch, /@beauticode\/dsh-plugin/);
162162
assert.equal(fs.existsSync(path.join(home, "cordis.patch.yml")), false);
163+
const pkgBytes = fs.readFileSync(path.join(web, "package.json"));
164+
assert.notEqual(pkgBytes[0], 0xef, "profile package.json must not have a UTF-8 BOM");
165+
JSON.parse(pkgBytes.toString("utf8"));
163166
assert.ok(
164167
fs.existsSync(
165168
path.join(web, "node_modules", "@beauticode", "dsh-plugin", "index.mjs"),

scripts/install-dsh-plugin.ps1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ function Ensure-WebPackageDep {
185185
}
186186
if ($current -eq $linkSpec) { return }
187187
$deps | Add-Member -NotePropertyName $pluginName -NotePropertyValue $linkSpec -Force
188-
$json | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $webPackage -Encoding UTF8
188+
# Windows PowerShell 5.1 Set-Content -Encoding UTF8 writes a BOM.
189+
# DSH reads the profile manifest with JSON.parse and rejects that.
190+
$utf8 = New-Object System.Text.UTF8Encoding $false
191+
$text = $json | ConvertTo-Json -Depth 8
192+
[IO.File]::WriteAllText($webPackage, ($text.TrimEnd() + "`n"), $utf8)
189193
}
190194

191195
if (-not (Test-Path -LiteralPath $indexFile -PathType Leaf)) {

0 commit comments

Comments
 (0)