Skip to content

Commit

Permalink
fix(telemetry): Avoid getConfig for CRWA (#7621)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Choudhury <[email protected]>
  • Loading branch information
2 people authored and jtoar committed Feb 14, 2023
1 parent 4512e27 commit e4ee251
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/telemetry/src/sendTelemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const SENSITIVE_ARG_POSITIONS: SensitiveArgPositions = {

interface Args {
redwoodVersion?: string
command?: string
}

/** Gets diagnostic info and sanitizes by removing references to paths */
Expand Down Expand Up @@ -88,6 +89,12 @@ const getInfo = async (presets: Args = {}) => {
const cpu = await system.cpu()
const mem = await system.mem()

// Must only call getConfig() once the project is setup - so not within telemetry for CRWA
// Default to 'webpack' for new projects
const webBundler = presets.command?.startsWith('create redwood-app')
? 'webpack'
: getConfig().web.bundler

return {
os: info.System?.OS?.split(' ')[0],
osVersion: info.System?.OS?.split(' ')[1],
Expand All @@ -99,7 +106,7 @@ const getInfo = async (presets: Args = {}) => {
redwoodVersion:
presets.redwoodVersion || info.npmPackages['@redwoodjs/core']?.installed,
system: `${cpu.physicalCores}.${Math.round(mem.total / 1073741824)}`,
webBundler: getConfig().web.bundler,
webBundler,
}
}

Expand Down Expand Up @@ -165,15 +172,16 @@ const buildPayload = async () => {

const argv = require('yargs/yargs')(processArgv.slice(2)).parse()
const rootDir = argv.root
const command = argv.argv ? sanitizeArgv(JSON.parse(argv.argv)) : ''
payload = {
type: argv.type || 'command',
command: argv.argv ? sanitizeArgv(JSON.parse(argv.argv)) : '',
command,
duration: argv.duration ? parseInt(argv.duration) : null,
uid: uniqueId(rootDir) || null,
ci: ci.isCI,
redwoodCi: !!process.env.REDWOOD_CI,
NODE_ENV: process.env.NODE_ENV || null,
...(await getInfo({ redwoodVersion: argv.rwVersion })),
...(await getInfo({ redwoodVersion: argv.rwVersion, command })),
}

if (argv.error) {
Expand Down Expand Up @@ -221,6 +229,10 @@ const uniqueId = (rootDir: string | null) => {
) {
uuid = uuidv4()
try {
// Create `.redwood` directory if it does not exist
if (!fs.existsSync(path.dirname(telemetryCachePath))) {
fs.mkdirSync(path.dirname(telemetryCachePath), { recursive: true })
}
fs.writeFileSync(telemetryCachePath, uuid)
} catch (error) {
console.error('\nCould not create telemetry.txt file\n')
Expand Down

0 comments on commit e4ee251

Please sign in to comment.