Skip to content

Commit

Permalink
feat(gatsby): Capture number of compiled TS files in Telemetry (#35023)
Browse files Browse the repository at this point in the history
Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
LekoArts and gatsbybot committed Mar 11, 2022
1 parent 79d5463 commit 5852dc8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/gatsby/src/utils/parcel/compile-gatsby-files.ts
Expand Up @@ -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`
Expand Down Expand Up @@ -46,7 +47,24 @@ export async function compileGatsbyFiles(siteRoot: string): Promise<void> {
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)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/worker/__tests__/config.ts
Expand Up @@ -9,6 +9,7 @@ jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackCli: jest.fn(),
isTrackingEnabled: jest.fn(),
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/worker/__tests__/datastore.ts
Expand Up @@ -12,6 +12,7 @@ jest.mock(`gatsby-telemetry`, () => {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
isTrackingEnabled: jest.fn(),
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/worker/__tests__/jobs.ts
Expand Up @@ -11,6 +11,7 @@ jest.mock(`gatsby-telemetry`, () => {
return {
decorateEvent: jest.fn(),
trackCli: jest.fn(),
isTrackingEnabled: jest.fn(),
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/worker/__tests__/queries.ts
Expand Up @@ -51,6 +51,7 @@ jest.mock(`gatsby-telemetry`, () => {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
isTrackingEnabled: jest.fn(),
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/worker/__tests__/schema.ts
Expand Up @@ -44,6 +44,7 @@ jest.mock(`gatsby-telemetry`, () => {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
isTrackingEnabled: jest.fn(),
}
})

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/worker/__tests__/share-state.ts
Expand Up @@ -12,6 +12,7 @@ jest.mock(`gatsby-telemetry`, () => {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
isTrackingEnabled: jest.fn(),
}
})

Expand Down

0 comments on commit 5852dc8

Please sign in to comment.