Skip to content

Commit

Permalink
Remove pagesDir and add isSrcDir to anonymous meta
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 14, 2019
1 parent 5b318e9 commit 6851de8
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 21 deletions.
16 changes: 7 additions & 9 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,22 +91,20 @@ export default async function build(dir: string, conf = null): Promise<void> {
const { target } = config
const buildId = await generateBuildId(config.generateBuildId, nanoid)
const distDir = path.join(dir, config.distDir)

const telemetry = new Telemetry({ distDir })

const publicDir = path.join(dir, 'public')
const pagesDir = findPagesDir(dir)

const telemetry = new Telemetry({
distDir,
isSrcDir: pagesDir.startsWith('src'),
})

let publicFiles: string[] = []
let hasPublicDir = false

let backgroundWork: (Promise<any> | undefined)[] = []
backgroundWork.push(
telemetry.record(
eventVersion({
cliCommand: 'build',
pagesDir: path.relative(dir, pagesDir),
})
),
telemetry.record(eventVersion({ cliCommand: 'build' })),
eventNextPlugins(path.resolve(dir)).then(events => telemetry.record(events))
)

Expand Down
12 changes: 5 additions & 7 deletions packages/next/server/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,11 @@ export default class DevServer extends Server {
await this.startWatcher()
this.setDevReady!()

const telemetry = new Telemetry({ distDir: this.distDir })
telemetry.record(
eventVersion({
cliCommand: 'dev',
pagesDir: relative(this.dir, this.pagesDir!),
})
)
const telemetry = new Telemetry({
distDir: this.distDir,
isSrcDir: this.pagesDir!.startsWith('src'),
})
telemetry.record(eventVersion({ cliCommand: 'dev' }))
}

protected async close() {
Expand Down
8 changes: 7 additions & 1 deletion packages/next/telemetry/anonymous-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,25 @@ type AnonymousMeta = {
isDocker: boolean
isNowDev: boolean
isCI: boolean
isSrcDir?: boolean
ciName: string | null
}

let traits: AnonymousMeta | undefined

export function getAnonymousMeta(): AnonymousMeta {
export function getAnonymousMeta({
isSrcDir,
}: {
isSrcDir?: boolean
}): AnonymousMeta {
if (traits) {
return traits
}

const cpus = os.cpus() || []
const { NOW_REGION } = process.env
traits = {
isSrcDir,
// Software information
systemPlatform: os.platform(),
systemRelease: os.release(),
Expand Down
2 changes: 0 additions & 2 deletions packages/next/telemetry/events/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ type EventCliSessionStarted = {
nextVersion: string
nodeVersion: string
cliCommand: string
pagesDir?: string
}

export function eventVersion(
Expand All @@ -22,7 +21,6 @@ export function eventVersion(
nextVersion: process.env.__NEXT_VERSION,
nodeVersion: process.version,
cliCommand: event.cliCommand,
pagesDir: event.pagesDir,
} as EventCliSessionStarted,
},
]
Expand Down
7 changes: 5 additions & 2 deletions packages/next/telemetry/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@ export class Telemetry {
private conf: Conf<any>
private sessionId: string
private rawProjectId: string
private isSrcDir?: boolean

constructor({ distDir }: { distDir: string }) {
constructor({ distDir, isSrcDir }: { distDir: string; isSrcDir?: boolean }) {
const storageDirectory = getStorageDirectory(distDir)

this.conf = new Conf({ projectName: 'nextjs', cwd: storageDirectory })
this.sessionId = randomBytes(32).toString('hex')
this.rawProjectId = getRawProjectId()
this.isSrcDir = isSrcDir

this.notify()
}
Expand Down Expand Up @@ -202,7 +204,8 @@ export class Telemetry {
projectId: this.projectId,
sessionId: this.sessionId,
}
const meta: EventMeta = getAnonymousMeta()
const meta: EventMeta = getAnonymousMeta({ isSrcDir: this.isSrcDir })

return _postPayload(`https://telemetry.nextjs.org/api/v1/record`, {
context,
meta,
Expand Down

0 comments on commit 6851de8

Please sign in to comment.