rsnext/packages/next/telemetry/anonymous-meta.ts

53 lines
1.3 KiB
TypeScript
Raw Normal View History

2020-03-29 01:33:35 +01:00
import isDockerFunction from 'next/dist/compiled/is-docker'
import isWslBoolean from 'next/dist/compiled/is-wsl'
2019-09-07 16:51:09 +02:00
import os from 'os'
import * as ciEnvironment from './ci-info'
2019-09-07 16:51:09 +02:00
type AnonymousMeta = {
systemPlatform: NodeJS.Platform
systemRelease: string
systemArchitecture: string
cpuCount: number
cpuModel: string | null
cpuSpeed: number | null
memoryInMb: number
isDocker: boolean
isNowDev: boolean
2019-10-23 03:13:18 +02:00
isWsl: boolean
2019-09-07 16:51:09 +02:00
isCI: boolean
ciName: string | null
nextVersion: string
2019-09-07 16:51:09 +02:00
}
let traits: AnonymousMeta | undefined
export function getAnonymousMeta(): AnonymousMeta {
if (traits) {
return traits
}
const cpus = os.cpus() || []
const { NOW_REGION } = process.env
2019-09-07 16:51:09 +02:00
traits = {
// Software information
systemPlatform: os.platform(),
systemRelease: os.release(),
systemArchitecture: os.arch(),
// Machine information
cpuCount: cpus.length,
cpuModel: cpus.length ? cpus[0].model : null,
cpuSpeed: cpus.length ? cpus[0].speed : null,
memoryInMb: Math.trunc(os.totalmem() / Math.pow(1024, 2)),
// Environment information
isDocker: isDockerFunction(),
isNowDev: NOW_REGION === 'dev1',
2019-10-23 03:13:18 +02:00
isWsl: isWslBoolean,
2019-09-07 16:51:09 +02:00
isCI: ciEnvironment.isCI,
ciName: (ciEnvironment.isCI && ciEnvironment.name) || null,
nextVersion: process.env.__NEXT_VERSION as string,
2019-09-07 16:51:09 +02:00
}
return traits
}