Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby): Capture number of compiled TS files in Telemetry #35023

Merged
merged 8 commits into from
Mar 11, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/gatsby-telemetry/src/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export interface ITelemetryTagsPayload {
SSRCount?: number
DSGCount?: number
SSGCount?: number
compiledTSFilesCount?: number
}
errorV2?: IStructuredErrorV2
valueString?: string
Expand Down
16 changes: 15 additions & 1 deletion packages/gatsby/src/utils/parcel/compile-gatsby-files.ts
Original file line number Diff line number Diff line change
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,20 @@ 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()
let compiledTSFilesCount = 0
for (const bundle of bundles) {
if (bundle?.getMainEntry()?.filePath?.endsWith(`.ts`)) {
compiledTSFilesCount = compiledTSFilesCount + 1
}
}
telemetry.addSiteMeasurement(`PARCEL_COMPILATION_END`, {
LekoArts marked this conversation as resolved.
Show resolved Hide resolved
compiledTSFilesCount,
})
}
} catch (error) {
if (error.diagnostics) {
handleErrors(error.diagnostics)
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/src/utils/worker/__tests__/config.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jest.mock(`gatsby-telemetry`, () => {
decorateEvent: jest.fn(),
trackError: jest.fn(),
trackCli: jest.fn(),
isTrackingEnabled: jest.fn(),
}
})

Expand Down