Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Record src directory usage with version #9023

Merged
merged 7 commits into from
Oct 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/next/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,12 @@ export default async function build(dir: string, conf = null): Promise<void> {

let backgroundWork: (Promise<any> | undefined)[] = []
backgroundWork.push(
telemetry.record(eventVersion({ cliCommand: 'build' })),
telemetry.record(
eventVersion({
cliCommand: 'build',
isSrcDir: path.relative(dir, 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
7 changes: 6 additions & 1 deletion packages/next/server/next-dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,12 @@ export default class DevServer extends Server {
this.setDevReady!()

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

protected async close() {
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
68 changes: 67 additions & 1 deletion test/integration/telemetry/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
/* eslint-env jest */
/* global jasmine */
import { runNextCommand } from 'next-test-utils'
import path from 'path'
import fs from 'fs-extra'
import {
runNextCommand,
launchApp,
findPort,
killApp,
waitFor
} from 'next-test-utils'

jasmine.DEFAULT_TIMEOUT_INTERVAL = 1000 * 60 * 2

const appDir = path.join(__dirname, '..')

describe('Telemetry CLI', () => {
it('can print telemetry status', async () => {
const { stdout } = await runNextCommand(['telemetry'], {
Expand Down Expand Up @@ -59,4 +69,60 @@ describe('Telemetry CLI', () => {
expect(stdout).toMatch(/already disabled/)
expect(stdout).toMatch(/Status: Disabled/)
})

it('detects isSrcDir dir correctly for `next build`', async () => {
const { stderr } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
NEXT_TELEMETRY_DEBUG: 1
}
})

expect(stderr).toMatch(/isSrcDir.*?false/)

await fs.move(path.join(appDir, 'pages'), path.join(appDir, 'src/pages'))
const { stderr: stderr2 } = await runNextCommand(['build', appDir], {
stderr: true,
env: {
NEXT_TELEMETRY_DEBUG: 1
}
})
await fs.move(path.join(appDir, 'src/pages'), path.join(appDir, 'pages'))

expect(stderr2).toMatch(/isSrcDir.*?true/)
})

it('detects isSrcDir dir correctly for `next dev`', async () => {
let port = await findPort()
let stderr = ''

const handleStderr = msg => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1
}
})
await waitFor(1000)
await killApp(app)
expect(stderr).toMatch(/isSrcDir.*?false/)

await fs.move(path.join(appDir, 'pages'), path.join(appDir, 'src/pages'))
stderr = ''

port = await findPort()
app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1
}
})
await waitFor(1000)
await killApp(app)
await fs.move(path.join(appDir, 'src/pages'), path.join(appDir, 'pages'))

expect(stderr).toMatch(/isSrcDir.*?true/)
})
})