Skip to content

Commit

Permalink
fix: handle JSON.parse error
Browse files Browse the repository at this point in the history
  • Loading branch information
pacoyang committed Nov 13, 2023
1 parent 0b67dcc commit 7b11aea
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ export default class Build extends Command {

const pjson_file_path = upath.join(directory, 'package.json')
if (existsSync(pjson_file_path)) {
const pjson = JSON.parse(readFileSync(pjson_file_path).toString())
if (pjson.exports && typeof pjson.exports !== 'string') {
buildEntries = Object.entries(pjson.exports as Record<string, string>).reduce(
(acc, [key, value]) => {
acc[key] = value
return acc
},
{ ...buildEntries },
)
try {
const pjson = JSON.parse(readFileSync(pjson_file_path).toString())
if (pjson.exports && typeof pjson.exports !== 'string') {
buildEntries = Object.entries(pjson.exports as Record<string, string>).reduce(
(acc, [key, value]) => {
acc[key] = value
return acc
},
{ ...buildEntries },
)
}
} catch (error) {
this.error(`Error parsing package.json: ${error}`)
}
}

Expand Down

0 comments on commit 7b11aea

Please sign in to comment.