Skip to content

Commit

Permalink
fix: fix getPackageVersion (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Sep 14, 2022
1 parent b5c0470 commit d57335a
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 142 deletions.
22 changes: 18 additions & 4 deletions node/package_json.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,22 @@
import { createRequire } from 'module'
import { readFileSync } from 'fs'

const require = createRequire(import.meta.url)
const pkgJson = require('../package.json')
import { findUpSync } from 'find-up'

const getPackageVersion = (): string => pkgJson.version
const getPackageVersion = () => {
const packageJSONPath = findUpSync('package.json', { cwd: import.meta.url })

if (packageJSONPath === undefined) {
return ''
}

try {
const packageJSON = readFileSync(packageJSONPath, 'utf8')
const { version } = JSON.parse(packageJSON)

return version as string
} catch {
return ''
}
}

export { getPackageVersion }

0 comments on commit d57335a

Please sign in to comment.