Skip to content

Commit 5888146

Browse files
committed
Merge branch 'canary' into shu/nvjs
2 parents d73e429 + 2a9e2f1 commit 5888146

File tree

11 files changed

+121
-58
lines changed

11 files changed

+121
-58
lines changed

docs/api-reference/next/font.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ import { greatVibes, sourceCodePro400 } from '@/fonts';
295295

296296
<div class="card">
297297
<a href="/docs/basic-features/font-optimization.md">
298-
<b>Font Optmization</b>
298+
<b>Font Optimization</b>
299299
<small>Learn how to optimize fonts with the Font module.</small>
300300
</a>
301301
</div>

docs/api-reference/next/script.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ export default function Page() {
246246
<>
247247
<Script
248248
src="https://example.com/script.js"
249-
onLoad={(e) => {
249+
onError={(e) => {
250250
console.error('Script failed to load', e)
251251
}}
252252
/>

docs/getting-started.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
description: Get started with Next.js in the official documentation, and learn more about all our features!
33
---
44

5-
> Next.js 13 has been [publicly released](https://nextjs.org/blog/next-13), [read the docs here](https://beta.nextjs.org/docs).
5+
> 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).
66
77
# Getting Started
88

docs/upgrading.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pnpm up next react react-dom eslint-config-next --latest
2828

2929
## Migrating shared features
3030

31-
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).
31+
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).
3232

3333
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).
3434

packages/next/build/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ export default async function build(
341341
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
342342
isCustomServer: null,
343343
turboFlag: false,
344+
pagesDir: !!pagesDir,
345+
appDir: !!appDir,
344346
})
345347
)
346348

packages/next/cli/next-dev.ts

+6
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ const handleSessionStop = async () => {
3636
cliCommand: 'dev',
3737
turboFlag: isTurboSession,
3838
durationMilliseconds: Date.now() - sessionStarted,
39+
pagesDir: !!traceGlobals.get('pagesDir'),
40+
appDir: !!traceGlobals.get('appDir'),
3941
})
4042
)
4143
await telemetry.flush()
@@ -329,6 +331,8 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
329331
const telemetry = new Telemetry({
330332
distDir,
331333
})
334+
setGlobal('appDir', appDir)
335+
setGlobal('pagesDir', pagesDir)
332336
setGlobal('telemetry', telemetry)
333337

334338
telemetry.record(
@@ -342,6 +346,8 @@ If you cannot make the changes above, but still want to try out\nNext.js v13 wit
342346
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
343347
isCustomServer: false,
344348
turboFlag: true,
349+
pagesDir: !!pagesDir,
350+
appDir: !!appDir,
345351
})
346352
)
347353
const turboJson = findUp.sync('turbo.json', { cwd: dir })

packages/next/export/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ export default async function exportApp(
183183
hasNowJson: !!(await findUp('now.json', { cwd: dir })),
184184
isCustomServer: null,
185185
turboFlag: false,
186+
pagesDir: null,
187+
appDir: null,
186188
})
187189
)
188190
}

packages/next/server/dev/next-dev-server.ts

+4
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,13 @@ export default class DevServer extends Server {
729729
hasNowJson: !!(await findUp('now.json', { cwd: this.dir })),
730730
isCustomServer: this.isCustomServer,
731731
turboFlag: false,
732+
pagesDir: !!this.pagesDir,
733+
appDir: !!this.appDir,
732734
})
733735
)
734736
// This is required by the tracing subsystem.
737+
setGlobal('appDir', this.appDir)
738+
setGlobal('pagesDir', this.pagesDir)
735739
setGlobal('telemetry', telemetry)
736740

737741
process.on('unhandledRejection', (reason) => {

packages/next/telemetry/events/session-stopped.ts

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ export type EventCliSessionStopped = {
66
nodeVersion: string
77
turboFlag?: boolean | null
88
durationMilliseconds?: number | null
9+
pagesDir?: boolean
10+
appDir?: boolean
911
}
1012

1113
export function eventCliSession(
@@ -26,6 +28,8 @@ export function eventCliSession(
2628
turboFlag: !!event.turboFlag,
2729
}
2830
: {}),
31+
pagesDir: event.pagesDir,
32+
appDir: event.appDir,
2933
}
3034
return [{ eventName: EVENT_VERSION, payload }]
3135
}

packages/next/telemetry/events/version.ts

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ type EventCliSessionStarted = {
3030
reactStrictMode: boolean
3131
webpackVersion: number | null
3232
turboFlag: boolean
33+
appDir: boolean | null
34+
pagesDir: boolean | null
3335
}
3436

3537
function hasBabelConfig(dir: string): boolean {
@@ -113,6 +115,8 @@ export function eventCliSession(
113115
reactStrictMode: !!nextConfig?.reactStrictMode,
114116
webpackVersion: event.webpackVersion || null,
115117
turboFlag: event.turboFlag || false,
118+
appDir: event.appDir,
119+
pagesDir: event.pagesDir,
116120
}
117121
return [{ eventName: EVENT_VERSION, payload }]
118122
}

test/integration/telemetry/test/index.test.js

+95-54
Original file line numberDiff line numberDiff line change
@@ -369,85 +369,124 @@ describe('Telemetry CLI', () => {
369369
expect(stderr).toMatch(/isSrcDir.*?true/)
370370
})
371371

372+
const setupAppDir = async () => {
373+
await fs.writeFile(
374+
path.join(__dirname, '../next.config.js'),
375+
'module.exports = { experimental: { appDir: true } }'
376+
)
377+
await fs.mkdir(path.join(__dirname, '../app'))
378+
await fs.writeFile(
379+
path.join(__dirname, '../app/page.js'),
380+
'export default function Page() { return "hello world" }'
381+
)
382+
383+
return async function teardownAppDir() {
384+
await fs.remove(path.join(__dirname, '../app'))
385+
await fs.remove(path.join(__dirname, '../next.config.js'))
386+
}
387+
}
388+
372389
it('detects --turbo correctly for `next dev`', async () => {
373390
let port = await findPort()
374391
let stderr = ''
375392

376-
const handleStderr = (msg) => {
377-
stderr += msg
378-
}
379-
let app = await launchApp(appDir, port, {
380-
onStderr: handleStderr,
381-
env: {
382-
NEXT_TELEMETRY_DEBUG: 1,
383-
},
384-
turbo: true,
385-
})
386-
await waitFor(1000)
393+
const teardown = await setupAppDir()
387394

388-
if (app) {
389-
await killApp(app)
395+
try {
396+
const handleStderr = (msg) => {
397+
stderr += msg
398+
}
399+
let app = await launchApp(appDir, port, {
400+
onStderr: handleStderr,
401+
env: {
402+
NEXT_TELEMETRY_DEBUG: 1,
403+
},
404+
turbo: true,
405+
})
406+
await waitFor(1000)
407+
408+
if (app) {
409+
await killApp(app)
410+
}
411+
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
412+
.exec(stderr)
413+
.pop()
414+
415+
expect(event1).toMatch(/"pagesDir": true/)
416+
expect(event1).toMatch(/"turboFlag": true/)
417+
} finally {
418+
await teardown()
390419
}
391-
const event1 = /NEXT_CLI_SESSION_STARTED[\s\S]+?{([\s\S]+?)}/
392-
.exec(stderr)
393-
.pop()
394-
395-
expect(event1).toMatch(/"turboFlag": true/)
396420
})
397421

398422
it('detects --turbo correctly for `next dev` stopped', async () => {
399423
let port = await findPort()
400424
let stderr = ''
401425

402-
const handleStderr = (msg) => {
403-
stderr += msg
404-
}
405-
let app = await launchApp(appDir, port, {
406-
onStderr: handleStderr,
407-
env: {
408-
NEXT_TELEMETRY_DEBUG: 1,
409-
},
410-
turbo: true,
411-
})
426+
const teardown = await setupAppDir()
412427

413-
if (app) {
414-
await killApp(app)
415-
}
416-
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
428+
try {
429+
const handleStderr = (msg) => {
430+
stderr += msg
431+
}
432+
let app = await launchApp(appDir, port, {
433+
onStderr: handleStderr,
434+
env: {
435+
NEXT_TELEMETRY_DEBUG: 1,
436+
},
437+
turbo: true,
438+
})
417439

418-
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
419-
.exec(stderr)
420-
.pop()
440+
if (app) {
441+
await killApp(app)
442+
}
443+
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
421444

422-
expect(event1).toMatch(/"turboFlag": true/)
445+
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
446+
.exec(stderr)
447+
.pop()
448+
449+
expect(event1).toMatch(/"pagesDir": true/)
450+
expect(event1).toMatch(/"turboFlag": true/)
451+
} finally {
452+
await teardown()
453+
}
423454
})
424455

425456
it('detects correctly for `next dev` stopped (no turbo)', async () => {
426457
let port = await findPort()
427458
let stderr = ''
428459

429-
const handleStderr = (msg) => {
430-
stderr += msg
431-
}
432-
let app = await launchApp(appDir, port, {
433-
onStderr: handleStderr,
434-
env: {
435-
NEXT_TELEMETRY_DEBUG: 1,
436-
},
437-
})
460+
const teardown = await setupAppDir()
461+
462+
try {
463+
const handleStderr = (msg) => {
464+
stderr += msg
465+
}
466+
let app = await launchApp(appDir, port, {
467+
onStderr: handleStderr,
468+
env: {
469+
NEXT_TELEMETRY_DEBUG: 1,
470+
},
471+
})
438472

439-
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
473+
await check(() => stderr, /NEXT_CLI_SESSION_STARTED/)
440474

441-
if (app) {
442-
await killApp(app)
443-
}
444-
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
475+
if (app) {
476+
await killApp(app)
477+
}
478+
await check(() => stderr, /NEXT_CLI_SESSION_STOPPED/)
445479

446-
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
447-
.exec(stderr)
448-
.pop()
480+
const event1 = /NEXT_CLI_SESSION_STOPPED[\s\S]+?{([\s\S]+?)}/
481+
.exec(stderr)
482+
.pop()
449483

450-
expect(event1).toMatch(/"turboFlag": false/)
484+
expect(event1).toMatch(/"turboFlag": false/)
485+
expect(event1).toMatch(/"pagesDir": true/)
486+
expect(event1).toMatch(/"appDir": true/)
487+
} finally {
488+
await teardown()
489+
}
451490
})
452491

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

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

0 commit comments

Comments
 (0)