Skip to content

Commit

Permalink
Merge branch 'canary' into shu/nvjs
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Nov 2, 2022
2 parents d73e429 + 2a9e2f1 commit 5888146
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 58 deletions.
2 changes: 1 addition & 1 deletion docs/api-reference/next/font.md
Expand Up @@ -295,7 +295,7 @@ import { greatVibes, sourceCodePro400 } from '@/fonts';

<div class="card">
<a href="/docs/basic-features/font-optimization.md">
<b>Font Optmization</b>
<b>Font Optimization</b>
<small>Learn how to optimize fonts with the Font module.</small>
</a>
</div>
2 changes: 1 addition & 1 deletion docs/api-reference/next/script.md
Expand Up @@ -246,7 +246,7 @@ export default function Page() {
<>
<Script
src="https://example.com/script.js"
onLoad={(e) => {
onError={(e) => {
console.error('Script failed to load', e)
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started.md
Expand Up @@ -2,7 +2,7 @@
description: Get started with Next.js in the official documentation, and learn more about all our features!
---

> Next.js 13 has been [publicly released](https://nextjs.org/blog/next-13), [read the docs here](https://beta.nextjs.org/docs).
> Next.js 13 was recently released, [learn more](https://nextjs.org/blog/next-13) and see the [upgrade guide](https://nextjs.org/docs/upgrading#upgrading-from-12-to-13). Version 13 also introduces beta features like the [`app` directory](https://beta.nextjs.org/docs/app-directory-roadmap) that works alongside the `pages` directory (stable) for incremental adoption. You can continue using `pages` in Next.js 13, but if you want to try the new `app` features, [see the new beta docs](https://beta.nextjs.org/docs).
# Getting Started

Expand Down
2 changes: 1 addition & 1 deletion docs/upgrading.md
Expand Up @@ -28,7 +28,7 @@ pnpm up next react react-dom eslint-config-next --latest

## Migrating shared features

Next.js 13 introduces a new [`app` directory](https://beta.nextjs.org/docs/routing/fundamentals) with new features and conventions. However, upgrading to Next.js 13 does **not** require using the new [`app` directory](https://beta.nextjs.org/docs/routing/fundamentals.md#the-app-directory).
Next.js 13 introduces a new [`app` directory](https://beta.nextjs.org/docs/routing/fundamentals) with new features and conventions. However, upgrading to Next.js 13 does **not** require using the new [`app` directory](https://beta.nextjs.org/docs/routing/fundamentals#the-app-directory).

You can continue using `pages` with new features that work in both directories, such as the updated [Image component](#image-component), [Link component](#link-component), [Script component](#script-component), and [Font optimization](#font-optimization).

Expand Down
2 changes: 2 additions & 0 deletions packages/next/build/index.ts
Expand Up @@ -341,6 +341,8 @@ export default async function build(
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
isCustomServer: null,
turboFlag: false,
pagesDir: !!pagesDir,
appDir: !!appDir,
})
)

Expand Down
6 changes: 6 additions & 0 deletions packages/next/cli/next-dev.ts
Expand Up @@ -36,6 +36,8 @@ const handleSessionStop = async () => {
cliCommand: 'dev',
turboFlag: isTurboSession,
durationMilliseconds: Date.now() - sessionStarted,
pagesDir: !!traceGlobals.get('pagesDir'),
appDir: !!traceGlobals.get('appDir'),
})
)
await telemetry.flush()
Expand Down Expand Up @@ -329,6 +331,8 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
const telemetry = new Telemetry({
distDir,
})
setGlobal('appDir', appDir)
setGlobal('pagesDir', pagesDir)
setGlobal('telemetry', telemetry)

telemetry.record(
Expand All @@ -342,6 +346,8 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
isCustomServer: false,
turboFlag: true,
pagesDir: !!pagesDir,
appDir: !!appDir,
})
)
const turboJson = findUp.sync('turbo.json', { cwd: dir })
Expand Down
2 changes: 2 additions & 0 deletions packages/next/export/index.ts
Expand Up @@ -183,6 +183,8 @@ export default async function exportApp(
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
isCustomServer: null,
turboFlag: false,
pagesDir: null,
appDir: null,
})
)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/next/server/dev/next-dev-server.ts
Expand Up @@ -729,9 +729,13 @@ export default class DevServer extends Server {
hasNowJson: !!(await findUp('now.json', { cwd: this.dir })),
isCustomServer: this.isCustomServer,
turboFlag: false,
pagesDir: !!this.pagesDir,
appDir: !!this.appDir,
})
)
// This is required by the tracing subsystem.
setGlobal('appDir', this.appDir)
setGlobal('pagesDir', this.pagesDir)
setGlobal('telemetry', telemetry)

process.on('unhandledRejection', (reason) => {
Expand Down
4 changes: 4 additions & 0 deletions packages/next/telemetry/events/session-stopped.ts
Expand Up @@ -6,6 +6,8 @@ export type EventCliSessionStopped = {
nodeVersion: string
turboFlag?: boolean | null
durationMilliseconds?: number | null
pagesDir?: boolean
appDir?: boolean
}

export function eventCliSession(
Expand All @@ -26,6 +28,8 @@ export function eventCliSession(
turboFlag: !!event.turboFlag,
}
: {}),
pagesDir: event.pagesDir,
appDir: event.appDir,
}
return [{ eventName: EVENT_VERSION, payload }]
}
4 changes: 4 additions & 0 deletions packages/next/telemetry/events/version.ts
Expand Up @@ -30,6 +30,8 @@ type EventCliSessionStarted = {
reactStrictMode: boolean
webpackVersion: number | null
turboFlag: boolean
appDir: boolean | null
pagesDir: boolean | null
}

function hasBabelConfig(dir: string): boolean {
Expand Down Expand Up @@ -113,6 +115,8 @@ export function eventCliSession(
reactStrictMode: !!nextConfig?.reactStrictMode,
webpackVersion: event.webpackVersion || null,
turboFlag: event.turboFlag || false,
appDir: event.appDir,
pagesDir: event.pagesDir,
}
return [{ eventName: EVENT_VERSION, payload }]
}
149 changes: 95 additions & 54 deletions test/integration/telemetry/test/index.test.js
Expand Up @@ -369,85 +369,124 @@ describe('Telemetry CLI', () => {
expect(stderr).toMatch(/isSrcDir.*?true/)
})

const setupAppDir = async () => {
await fs.writeFile(
path.join(__dirname, '../next.config.js'),
'module.exports = { experimental: { appDir: true } }'
)
await fs.mkdir(path.join(__dirname, '../app'))
await fs.writeFile(
path.join(__dirname, '../app/page.js'),
'export default function Page() { return "hello world" }'
)

return async function teardownAppDir() {
await fs.remove(path.join(__dirname, '../app'))
await fs.remove(path.join(__dirname, '../next.config.js'))
}
}

it('detects --turbo 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,
},
turbo: true,
})
await waitFor(1000)
const teardown = await setupAppDir()

if (app) {
await killApp(app)
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})
await waitFor(1000)

if (app) {
await killApp(app)
}
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/)
} finally {
await teardown()
}
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event1).toMatch(/"turboFlag": true/)
})

it('detects --turbo correctly for `next dev` stopped', 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,
},
turbo: true,
})
const teardown = await setupAppDir()

if (app) {
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
turbo: true,
})

const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
if (app) {
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)

expect(event1).toMatch(/"turboFlag": true/)
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"turboFlag": true/)
} finally {
await teardown()
}
})

it('detects correctly for `next dev` stopped (no turbo)', 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,
},
})
const teardown = await setupAppDir()

try {
const handleStderr = (msg) => {
stderr += msg
}
let app = await launchApp(appDir, port, {
onStderr: handleStderr,
env: {
NEXT_TELEMETRY_DEBUG: 1,
},
})

await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)

if (app) {
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
if (app) {
await killApp(app)
}
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)

const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
.exec(stderr)
.pop()

expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": true/)
} finally {
await teardown()
}
})

it('detect reportWebVitals correctly for `next build`', async () => {
Expand Down Expand Up @@ -567,6 +606,8 @@ describe('Telemetry CLI', () => {
expect(event1).toMatch(/"trailingSlashEnabled": false/)
expect(event1).toMatch(/"reactStrictMode": false/)
expect(event1).toMatch(/"turboFlag": false/)
expect(event1).toMatch(/"pagesDir": true/)
expect(event1).toMatch(/"appDir": false/)

await fs.rename(
path.join(appDir, 'next.config.i18n-images'),
Expand Down

0 comments on commit 5888146

Please sign in to comment.