Skip to content

Commit

Permalink
Move isSrcDir back to eventVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Oct 23, 2019
1 parent 5c01535 commit 517914b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 22 deletions.
16 changes: 11 additions & 5 deletions packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,29 @@ export default async function build(dir: string, conf = null): Promise<void> {
)
}

const buildSpinner = createSpinner({
prefixText: 'Creating an optimized production build',
})

const config = loadConfig(PHASE_PRODUCTION_BUILD, dir, conf)
const { target } = config
const buildId = await generateBuildId(config.generateBuildId, nanoid)
const distDir = path.join(dir, config.distDir)
const publicDir = path.join(dir, 'public')
const pagesDir = findPagesDir(dir)
const telemetry = new Telemetry({
distDir,
isSrcDir: pagesDir.startsWith('src'),
})
const telemetry = new Telemetry({ distDir })

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

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

Expand Down
2 changes: 1 addition & 1 deletion packages/next/export/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default async function(
const distDir = join(dir, nextConfig.distDir)
if (!options.buildExport) {
const telemetry = new Telemetry({ distDir })
telemetry.record(eventVersion({ cliCommand: 'export' }))
telemetry.record(eventVersion({ cliCommand: 'export', isSrcDir: null }))
}

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

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

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

let traits: AnonymousMeta | undefined

export function getAnonymousMeta({
isSrcDir,
}: {
isSrcDir?: boolean
}): AnonymousMeta {
export function getAnonymousMeta(): 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: 2 additions & 0 deletions packages/next/telemetry/events/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ type EventCliSessionStarted = {
nextVersion: string
nodeVersion: string
cliCommand: string
isSrcDir: boolean | null
}

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

constructor({ distDir, isSrcDir }: { distDir: string; isSrcDir?: boolean }) {
constructor({ distDir }: { distDir: string }) {
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 @@ -204,7 +202,7 @@ export class Telemetry {
projectId: this.projectId,
sessionId: this.sessionId,
}
const meta: EventMeta = getAnonymousMeta({ isSrcDir: this.isSrcDir })
const meta: EventMeta = getAnonymousMeta()

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

0 comments on commit 517914b

Please sign in to comment.