11import os from 'node:os'
22import { execSync } from 'node:child_process'
33import gitUrlParse from 'git-url-parse'
4- import { getNuxtVersion , isNuxt3 } from '@nuxt/kit'
4+ import { getNuxtVersion , isNuxtMajorVersion } from '@nuxt/kit'
55import isDocker from 'is-docker'
66import { provider } from 'std-env'
77import type { Nuxt } from '@nuxt/schema'
88import { detect } from 'package-manager-detector'
99import type { Context , GitData , TelemetryOptions } from './types'
1010import { hash } from './utils/hash'
1111
12+ function getNuxtMajorVersion ( nuxt : Nuxt ) {
13+ for ( let i = 4 ; i >= 2 ; i -- ) {
14+ const j = i as ( 2 | 3 | 4 )
15+ if ( isNuxtMajorVersion ( j , nuxt ) ) {
16+ return j
17+ }
18+ }
19+ return 2
20+ }
21+
1222export async function createContext ( nuxt : Nuxt , options : Required < TelemetryOptions > ) : Promise < Context > {
1323 const rootDir = nuxt . options . rootDir || process . cwd ( )
1424 const git = await getGit ( rootDir )
@@ -19,7 +29,7 @@ export async function createContext(nuxt: Nuxt, options: Required<TelemetryOptio
1929 const projectSession = getProjectSession ( projectHash , seed )
2030
2131 const nuxtVersion = getNuxtVersion ( nuxt )
22- const nuxtMajorVersion = isNuxt3 ( nuxt ) ? 3 : 2
32+ const nuxtMajorVersion = getNuxtMajorVersion ( nuxt )
2333 const nodeVersion = process . version . replace ( 'v' , '' )
2434 const isEdge = nuxtVersion . includes ( 'edge' )
2535
@@ -54,7 +64,7 @@ function getEnv(): Context['environment'] {
5464}
5565
5666function getCLI ( ) {
57- const entry = process . argv [ 1 ]
67+ const entry = process . argv [ 1 ] ?? ''
5868
5969 const knownCLIs = {
6070 'nuxt-ts.js' : 'nuxt-ts' ,
0 commit comments