diff --git a/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts b/packages/gatsby/src/utils/parcel/compile-gatsby-files.ts index 94fe33181a516..c1d8dce022e71 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,24 @@ 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() + + if (bundles.length === 0) return + + let compiledTSFilesCount = 0 + for (const bundle of bundles) { + if (bundle?.getMainEntry()?.filePath?.endsWith(`.ts`)) { + compiledTSFilesCount = compiledTSFilesCount + 1 + } + } + telemetry.trackCli(`PARCEL_COMPILATION_END`, { + valueInteger: compiledTSFilesCount, + name: `count of compiled ts files`, + }) + } } catch (error) { if (error.diagnostics) { handleErrors(error.diagnostics) diff --git a/packages/gatsby/src/utils/worker/__tests__/config.ts b/packages/gatsby/src/utils/worker/__tests__/config.ts index efbea0a127542..70de779914467 100644 --- a/packages/gatsby/src/utils/worker/__tests__/config.ts +++ b/packages/gatsby/src/utils/worker/__tests__/config.ts @@ -9,6 +9,7 @@ jest.mock(`gatsby-telemetry`, () => { return { decorateEvent: jest.fn(), trackCli: 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 1e5b6ca1385e0..3e4fefe7865eb 100644 --- a/packages/gatsby/src/utils/worker/__tests__/jobs.ts +++ b/packages/gatsby/src/utils/worker/__tests__/jobs.ts @@ -11,6 +11,7 @@ jest.mock(`gatsby-telemetry`, () => { return { decorateEvent: jest.fn(), trackCli: 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(), } })