From 9f15df24a46f9118882285b1bec659be32dfeb9c Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 2 Mar 2022 16:04:24 +0100 Subject: [PATCH 1/7] initial --- packages/gatsby-telemetry/src/telemetry.ts | 1 + .../src/utils/parcel/compile-gatsby-files.ts | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-telemetry/src/telemetry.ts b/packages/gatsby-telemetry/src/telemetry.ts index 345687cb545c1..4a8b02ad41ecf 100644 --- a/packages/gatsby-telemetry/src/telemetry.ts +++ b/packages/gatsby-telemetry/src/telemetry.ts @@ -111,6 +111,7 @@ export interface ITelemetryTagsPayload { SSRCount?: number DSGCount?: number SSGCount?: number + compiledTSFilesCount?: number } errorV2?: IStructuredErrorV2 valueString?: string diff --git a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts index 94fe33181a516..7d27ec13f4f54 100644 --- a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts +++ b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts @@ -2,6 +2,7 @@ import { Parcel } from "@parcel/core" import type { Diagnostic } from "@parcel/diagnostic" import reporter from "gatsby-cli/lib/reporter" import { ensureDir, emptyDir, existsSync } from "fs-extra" +import telemetry from "gatsby-telemetry" export const COMPILED_CACHE_DIR = `.cache/compiled` export const PARCEL_CACHE_DIR = `.cache/.parcel-cache` @@ -46,7 +47,20 @@ export async function compileGatsbyFiles(siteRoot: string): Promise { const distDir = `${siteRoot}/${COMPILED_CACHE_DIR}` await ensureDir(distDir) await emptyDir(distDir) - await parcel.run() + const { bundleGraph } = await parcel.run() + + if (telemetry.isTrackingEnabled()) { + const bundles = bundleGraph.getBundles() + let compiledTSFilesCount = 0 + for (const bundle of bundles) { + if (bundle?.getMainEntry()?.filePath?.endsWith(`.ts`)) { + compiledTSFilesCount = compiledTSFilesCount + 1 + } + } + telemetry.addSiteMeasurement(`PARCEL_COMPILATION_END`, { + compiledTSFilesCount, + }) + } } catch (error) { if (error.diagnostics) { handleErrors(error.diagnostics) From dd82368ae8b8dbbf92fae753cce38f27ff54c2f8 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 2 Mar 2022 16:36:59 +0100 Subject: [PATCH 2/7] fix tests --- packages/gatsby/src/utils/worker/__tests__/config.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/gatsby/src/utils/worker/__tests__/config.ts b/packages/gatsby/src/utils/worker/__tests__/config.ts index efbea0a127542..bab6bebe5a9d2 100644 --- a/packages/gatsby/src/utils/worker/__tests__/config.ts +++ b/packages/gatsby/src/utils/worker/__tests__/config.ts @@ -9,6 +9,8 @@ jest.mock(`gatsby-telemetry`, () => { return { decorateEvent: jest.fn(), trackCli: jest.fn(), + addSiteMeasurement: jest.fn(), + isTrackingEnabled: jest.fn(), } }) From bf1c4d93aae93bda23cdbd2734b3e97fa394350d Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 2 Mar 2022 20:05:28 +0100 Subject: [PATCH 3/7] fix tests --- packages/gatsby/src/utils/worker/__tests__/jobs.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/gatsby/src/utils/worker/__tests__/jobs.ts b/packages/gatsby/src/utils/worker/__tests__/jobs.ts index 1e5b6ca1385e0..fbc74fb98ce1e 100644 --- a/packages/gatsby/src/utils/worker/__tests__/jobs.ts +++ b/packages/gatsby/src/utils/worker/__tests__/jobs.ts @@ -11,6 +11,8 @@ jest.mock(`gatsby-telemetry`, () => { return { decorateEvent: jest.fn(), trackCli: jest.fn(), + addSiteMeasurement: jest.fn(), + isTrackingEnabled: jest.fn(), } }) From 179d42c9ecfe82d71ce81c2dcd6a32b9e6e6c3fa Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 3 Mar 2022 10:21:50 +0100 Subject: [PATCH 4/7] tests... --- packages/gatsby/src/utils/worker/__tests__/config.ts | 1 - packages/gatsby/src/utils/worker/__tests__/datastore.ts | 1 + packages/gatsby/src/utils/worker/__tests__/jobs.ts | 1 - packages/gatsby/src/utils/worker/__tests__/queries.ts | 1 + packages/gatsby/src/utils/worker/__tests__/schema.ts | 1 + packages/gatsby/src/utils/worker/__tests__/share-state.ts | 1 + 6 files changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/worker/__tests__/config.ts b/packages/gatsby/src/utils/worker/__tests__/config.ts index bab6bebe5a9d2..70de779914467 100644 --- a/packages/gatsby/src/utils/worker/__tests__/config.ts +++ b/packages/gatsby/src/utils/worker/__tests__/config.ts @@ -9,7 +9,6 @@ jest.mock(`gatsby-telemetry`, () => { return { decorateEvent: jest.fn(), trackCli: jest.fn(), - addSiteMeasurement: jest.fn(), isTrackingEnabled: jest.fn(), } }) diff --git a/packages/gatsby/src/utils/worker/__tests__/datastore.ts b/packages/gatsby/src/utils/worker/__tests__/datastore.ts index b215d0ae53b29..e1a5ccb04d90d 100644 --- a/packages/gatsby/src/utils/worker/__tests__/datastore.ts +++ b/packages/gatsby/src/utils/worker/__tests__/datastore.ts @@ -12,6 +12,7 @@ jest.mock(`gatsby-telemetry`, () => { decorateEvent: jest.fn(), trackError: jest.fn(), trackCli: jest.fn(), + isTrackingEnabled: jest.fn(), } }) diff --git a/packages/gatsby/src/utils/worker/__tests__/jobs.ts b/packages/gatsby/src/utils/worker/__tests__/jobs.ts index fbc74fb98ce1e..3e4fefe7865eb 100644 --- a/packages/gatsby/src/utils/worker/__tests__/jobs.ts +++ b/packages/gatsby/src/utils/worker/__tests__/jobs.ts @@ -11,7 +11,6 @@ jest.mock(`gatsby-telemetry`, () => { return { decorateEvent: jest.fn(), trackCli: jest.fn(), - addSiteMeasurement: jest.fn(), isTrackingEnabled: jest.fn(), } }) diff --git a/packages/gatsby/src/utils/worker/__tests__/queries.ts b/packages/gatsby/src/utils/worker/__tests__/queries.ts index f76b6f6d842c0..ae813de156b55 100644 --- a/packages/gatsby/src/utils/worker/__tests__/queries.ts +++ b/packages/gatsby/src/utils/worker/__tests__/queries.ts @@ -51,6 +51,7 @@ jest.mock(`gatsby-telemetry`, () => { decorateEvent: jest.fn(), trackError: jest.fn(), trackCli: jest.fn(), + isTrackingEnabled: jest.fn(), } }) diff --git a/packages/gatsby/src/utils/worker/__tests__/schema.ts b/packages/gatsby/src/utils/worker/__tests__/schema.ts index 2ea7cb1076510..ccc7f0b445c1d 100644 --- a/packages/gatsby/src/utils/worker/__tests__/schema.ts +++ b/packages/gatsby/src/utils/worker/__tests__/schema.ts @@ -44,6 +44,7 @@ jest.mock(`gatsby-telemetry`, () => { decorateEvent: jest.fn(), trackError: jest.fn(), trackCli: jest.fn(), + isTrackingEnabled: jest.fn(), } }) diff --git a/packages/gatsby/src/utils/worker/__tests__/share-state.ts b/packages/gatsby/src/utils/worker/__tests__/share-state.ts index 58b8805653427..e1cbfd712b9ee 100644 --- a/packages/gatsby/src/utils/worker/__tests__/share-state.ts +++ b/packages/gatsby/src/utils/worker/__tests__/share-state.ts @@ -12,6 +12,7 @@ jest.mock(`gatsby-telemetry`, () => { decorateEvent: jest.fn(), trackError: jest.fn(), trackCli: jest.fn(), + isTrackingEnabled: jest.fn(), } }) From d871bfd0362c989c2577733330b1fb73879af4fd Mon Sep 17 00:00:00 2001 From: LekoArts Date: Thu, 3 Mar 2022 13:40:37 +0100 Subject: [PATCH 5/7] use trackCli --- packages/gatsby/src/utils/parcel/compile-gatsby-files.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts index 7d27ec13f4f54..020feb8eec279 100644 --- a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts +++ b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts @@ -57,8 +57,10 @@ export async function compileGatsbyFiles(siteRoot: string): Promise { compiledTSFilesCount = compiledTSFilesCount + 1 } } - telemetry.addSiteMeasurement(`PARCEL_COMPILATION_END`, { - compiledTSFilesCount, + telemetry.trackCli(`PARCEL_COMPILATION_END`, { + siteMeasurements: { + compiledTSFilesCount, + }, }) } } catch (error) { From 1ade30d504732e9dbd5df31d9c94b0fe5e2a318f Mon Sep 17 00:00:00 2001 From: LekoArts Date: Tue, 8 Mar 2022 10:41:49 +0100 Subject: [PATCH 6/7] apply jarmo comments --- packages/gatsby-telemetry/src/telemetry.ts | 1 - packages/gatsby/src/utils/parcel/compile-gatsby-files.ts | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-telemetry/src/telemetry.ts b/packages/gatsby-telemetry/src/telemetry.ts index 4a8b02ad41ecf..345687cb545c1 100644 --- a/packages/gatsby-telemetry/src/telemetry.ts +++ b/packages/gatsby-telemetry/src/telemetry.ts @@ -111,7 +111,6 @@ export interface ITelemetryTagsPayload { SSRCount?: number DSGCount?: number SSGCount?: number - compiledTSFilesCount?: number } errorV2?: IStructuredErrorV2 valueString?: string diff --git a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts index 020feb8eec279..ae83142820eb4 100644 --- a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts +++ b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts @@ -58,9 +58,8 @@ export async function compileGatsbyFiles(siteRoot: string): Promise { } } telemetry.trackCli(`PARCEL_COMPILATION_END`, { - siteMeasurements: { - compiledTSFilesCount, - }, + valueInteger: compiledTSFilesCount, + name: `count of compiled ts files`, }) } } catch (error) { From 8bbdd79b3caa50616c4fef83c7e8714ee24f5362 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 9 Mar 2022 09:51:08 +0100 Subject: [PATCH 7/7] skip sending telemetry when count is 0 --- packages/gatsby/src/utils/parcel/compile-gatsby-files.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts index ae83142820eb4..c1d8dce022e71 100644 --- a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts +++ b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts @@ -51,6 +51,9 @@ export async function compileGatsbyFiles(siteRoot: string): Promise { if (telemetry.isTrackingEnabled()) { const bundles = bundleGraph.getBundles() + + if (bundles.length === 0) return + let compiledTSFilesCount = 0 for (const bundle of bundles) { if (bundle?.getMainEntry()?.filePath?.endsWith(`.ts`)) {