Skip to content

Commit b708dee

Browse files
committed
feat: detect nitro preset
1 parent de550ab commit b708dee

File tree

5 files changed

+8
-3
lines changed

5 files changed

+8
-3
lines changed

src/context.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export async function createContext(nuxt: Nuxt, options: Required<TelemetryOptio
3131
const nodeVersion = process.version.replace('v', '')
3232
const isEdge = nuxtVersion.includes('edge')
3333
const agent = detectAgent()
34+
const nitroPreset = nuxt.options.nitro!.preset
3435

3536
return {
3637
nuxt,
@@ -49,6 +50,7 @@ export async function createContext(nuxt: Nuxt, options: Required<TelemetryOptio
4950
isAgent: isAgent,
5051
agentName: agent.name || null,
5152
concent: options.consent,
53+
nitroPreset,
5254
}
5355
}
5456

src/module.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ export default defineNuxtModule<TelemetryOptions>({
4949
logger.info('Seed generated:', toptions.seed)
5050
}
5151

52-
const t = new Telemetry(nuxt, toptions as typeof toptions & { consent: number })
53-
54-
nuxt.hook('modules:done', async () => {
52+
nuxt.hook('nitro:init', async (nitro) => {
53+
nuxt.options.nitro!.preset = nitro.options.preset
54+
const t = new Telemetry(nuxt, toptions as typeof toptions & { consent: number })
5555
t.createEvent('project')
5656
// Only send the session in development
5757
if (nuxt.options.dev) {

src/telemetry.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export class Telemetry {
7878
'projectSession',
7979
'isAgent',
8080
'agentName',
81+
'nitroPreset',
8182
] as const) {
8283
eventContext[key] = context[key]
8384
}

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export interface Context {
2525
isAgent: boolean
2626
agentName: string | null
2727
concent: number
28+
nitroPreset: string | null
2829
}
2930

3031
export interface Event {

test/e2e.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ describe('@nuxt/telemetry', () => {
7878
"context": {
7979
"cli": "programmatic",
8080
"isEdge": false,
81+
"nitroPreset": "node-server",
8182
"nuxtMajorVersion": 4,
8283
},
8384
"events": [

0 commit comments

Comments
 (0)