Skip to content

Commit

Permalink
fix(node): stripe bom
Browse files Browse the repository at this point in the history
fix #18911
  • Loading branch information
sapenlei committed Dec 18, 2024
1 parent 2b4f115 commit 5300196
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/vite/src/node/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,15 @@ export function findNearestMainPackageData(
)
}

function stripBOM(content: string) {
if (content.charCodeAt(0) === 0xfeff) {
content = content.slice(1)
}
return content
}

export function loadPackageData(pkgPath: string): PackageData {
const data = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'))
const data = JSON.parse(stripBOM(fs.readFileSync(pkgPath, 'utf-8')))
const pkgDir = normalizePath(path.dirname(pkgPath))
const { sideEffects } = data
let hasSideEffects: (id: string) => boolean | null
Expand Down

0 comments on commit 5300196

Please sign in to comment.