Skip to content

Commit 5b093de

Browse files
Fix bom in json (#46)
* Fix BOM issue in package.json by using Node.js for file writing Replace PowerShell file writing with Node.js to ensure UTF-8 without BOM. This prevents npm install failures caused by BOM in package.json files.
1 parent 98afc11 commit 5b093de

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

test-example.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,11 @@ function Process-AspNetCoreProject {
229229
}
230230

231231
if ($updated) {
232-
#$packageJson | ConvertTo-Json -Depth 10 | Set-Content -Path $packageJsonPath -Encoding UTF8
232+
$tempJsonPath = [System.IO.Path]::GetTempFileName()
233233
$jsonContent = $packageJson | ConvertTo-Json -Depth 10
234-
[System.IO.File]::WriteAllText($packageJsonPath, $jsonContent, [System.Text.UTF8Encoding]::new($false))
234+
[System.IO.File]::WriteAllText($tempJsonPath, $jsonContent, [System.Text.UTF8Encoding]::new($false))
235+
node -e "const fs = require('fs'); const data = fs.readFileSync('$($tempJsonPath -replace '\\', '/')', 'utf8'); fs.writeFileSync('$($packageJsonPath -replace '\\', '/')', data, 'utf8');"
236+
Remove-Item $tempJsonPath -ErrorAction SilentlyContinue
235237
Write-Host "Updated package.json with valid versions."
236238
} else {
237239
Write-Host "No matching dependencies found in package.json to update."

0 commit comments

Comments
 (0)