From 93271c1898c40b0bb02a733c30c6ff97ccb18a29 Mon Sep 17 00:00:00 2001 From: mottox2 Date: Wed, 11 Mar 2020 23:38:16 +0900 Subject: [PATCH 1/2] chore(gatsby-cli): Convert util/version to typescript --- packages/gatsby-cli/src/util/{version.js => version.ts} | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) rename packages/gatsby-cli/src/util/{version.js => version.ts} (70%) diff --git a/packages/gatsby-cli/src/util/version.js b/packages/gatsby-cli/src/util/version.ts similarity index 70% rename from packages/gatsby-cli/src/util/version.js rename to packages/gatsby-cli/src/util/version.ts index c6b3ae35be8de..d69532d7bfd10 100644 --- a/packages/gatsby-cli/src/util/version.js +++ b/packages/gatsby-cli/src/util/version.ts @@ -1,8 +1,8 @@ -const { setDefaultTags } = require(`gatsby-telemetry`) -const path = require(`path`) +import { setDefaultTags } from "gatsby-telemetry" +import path from "path" -exports.getLocalGatsbyVersion = () => { - let version +export const getLocalGatsbyVersion = (): string => { + let version = `` try { const packageInfo = require(path.join( process.cwd(), From ac071e977b830723e592389409878c92d0e464a4 Mon Sep 17 00:00:00 2001 From: mottox2 Date: Fri, 13 Mar 2020 00:16:24 +0900 Subject: [PATCH 2/2] chore(gatsby-cli): Use gatsby-core-utils --- packages/gatsby-cli/src/util/version.ts | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/packages/gatsby-cli/src/util/version.ts b/packages/gatsby-cli/src/util/version.ts index d69532d7bfd10..8e680b0087eaf 100644 --- a/packages/gatsby-cli/src/util/version.ts +++ b/packages/gatsby-cli/src/util/version.ts @@ -1,24 +1,13 @@ import { setDefaultTags } from "gatsby-telemetry" -import path from "path" +import { getGatsbyVersion } from "gatsby-core-utils" export const getLocalGatsbyVersion = (): string => { - let version = `` - try { - const packageInfo = require(path.join( - process.cwd(), - `node_modules`, - `gatsby`, - `package.json` - )) - version = packageInfo.version + const version = getGatsbyVersion() - try { - setDefaultTags({ installedGatsbyVersion: version }) - } catch (e) { - // ignore - } - } catch (err) { - /* ignore */ + try { + setDefaultTags({ installedGatsbyVersion: version }) + } catch (e) { + // ignore } return version