Skip to content

Commit

Permalink
Read Gatsby version correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthachatterjee committed May 3, 2021
1 parent 311c9ec commit 338ba86
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/gatsby-telemetry/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,18 @@ export class AnalyticsTracker {
}

getGatsbyVersion(): SemVer {
const packageInfo = require(join(
process.cwd(),
`node_modules`,
`gatsby`,
`package.json`
))
try {
return packageInfo.version
const packageJson = join(
require
.resolve(`gatsby`)
.split(sep) // Resolve where current gatsby would be loaded from.
.slice(0, -3) // drop cache-dir/commonjs/gatsby-browser-entry.js
.join(sep),
`package.json`
)

const { version } = JSON.parse(fs.readFileSync(packageJson, `utf-8`))
return version
} catch (e) {
// ignore
}
Expand Down

0 comments on commit 338ba86

Please sign in to comment.