Skip to content

Commit

Permalink
fix: check if package.json exists
Browse files Browse the repository at this point in the history
  • Loading branch information
pacoyang committed Nov 12, 2023
1 parent 12106a9 commit 927cd8b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/commands/build.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { lstatSync, readFileSync } from 'node:fs'
import { lstatSync, readFileSync, existsSync } from 'node:fs'
import upath from 'upath'
import { Args, Command, Flags, ux } from '@oclif/core'
import chalk from 'chalk'
Expand Down Expand Up @@ -48,15 +48,20 @@ export default class Build extends Command {
let buildEntries: Record<string, string> = {
[upath.parse(script).name]: script,
}
const pjson = JSON.parse(readFileSync(upath.join(directory, 'package.json')).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 },
)


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 },
)
}
}

for (const i in buildEntries) {
Expand Down

0 comments on commit 927cd8b

Please sign in to comment.