Skip to content

Commit

Permalink
Merge branch 'canary' into 05-16-upgrade_react_beta
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored May 16, 2024
2 parents df5934d + aed5242 commit f83ec5a
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 51 deletions.
17 changes: 9 additions & 8 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1710,14 +1710,15 @@ export default async function getBaseWebpackConfig(
const layer = resource.contextInfo.issuerLayer
let runtime

if (layer === WEBPACK_LAYERS.serverSideRendering) {
runtime = 'app-page'
} else if (!layer || layer === WEBPACK_LAYERS.api) {
runtime = 'pages'
} else {
throw new Error(
`shared-runtime module ${moduleName} cannot be used in ${layer} layer`
)
switch (layer) {
case WEBPACK_LAYERS.serverSideRendering:
case WEBPACK_LAYERS.reactServerComponents:
case WEBPACK_LAYERS.appPagesBrowser:
case WEBPACK_LAYERS.actionBrowser:
runtime = 'app-page'
break
default:
runtime = 'pages'
}
resource.request = `next/dist/server/future/route-modules/${runtime}/vendored/contexts/${moduleName}`
}
Expand Down
7 changes: 0 additions & 7 deletions test/e2e/app-dir/navigation/navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,11 +909,4 @@ describe('app dir - navigation', () => {
})
})
})

describe('pages api', () => {
it('should not error if just import the navigation api in pages/api', async () => {
const res = await next.fetch('/api/navigation')
expect(res.status).toBe(200)
})
})
})
5 changes: 0 additions & 5 deletions test/e2e/app-dir/navigation/pages/api/navigation.js

This file was deleted.

5 changes: 5 additions & 0 deletions test/e2e/app-dir/rsc-basic/app/shared-context/server/page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
require('next/router')

export default function Page() {
return <p>just work</p>
}
6 changes: 6 additions & 0 deletions test/e2e/app-dir/rsc-basic/pages/api/navigation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Use `require` to skip the api check
require('next/navigation')

export default function handle(_, res) {
res.send('just work')
}
14 changes: 14 additions & 0 deletions test/e2e/app-dir/rsc-basic/rsc-basic.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,20 @@ describe('app dir - rsc basics', () => {
})
}

describe('next internal shared context', () => {
it('should not error if just load next/navigation module in pages/api', async () => {
const res = await next.fetch('/api/navigation')
expect(res.status).toBe(200)
expect(await res.text()).toBe('just work')
})

it('should not error if just load next/router module in app page', async () => {
const res = await next.fetch('/shared-context/server')
expect(res.status).toBe(200)
expect(await res.text()).toContain('just work')
})
})

it('should correctly render page returning null', async () => {
const homeHTML = await next.render('/return-null/page')
const $ = cheerio.load(homeHTML)
Expand Down
47 changes: 37 additions & 10 deletions test/integration/create-next-app/examples.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../lib/create-next-install'
import {
EXAMPLE_PATH,
EXAMPLE_REPO,
Expand All @@ -10,12 +12,23 @@ import {
} from './utils'

describe('create-next-app --example', () => {
let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})
it('should create on valid Next.js example name', async () => {
await useTempDir(async (cwd) => {
const projectName = 'valid-example'
const res = await run([projectName, '--example', 'basic-css'], {
cwd,
})
const res = await run(
[projectName, '--example', 'basic-css'],
nextInstall.installDir,
{
cwd,
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
Expand All @@ -34,9 +47,13 @@ describe('create-next-app --example', () => {
it('should create with GitHub URL', async () => {
await useTempDir(async (cwd) => {
const projectName = 'github-url'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
})
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{
cwd,
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
Expand Down Expand Up @@ -64,6 +81,7 @@ describe('create-next-app --example', () => {
// GH#39665
'https://github.com/vercel/nextjs-portfolio-starter/',
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -97,6 +115,7 @@ describe('create-next-app --example', () => {
'--example-path',
EXAMPLE_PATH,
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -131,6 +150,7 @@ describe('create-next-app --example', () => {
'--example-path',
EXAMPLE_PATH,
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -168,6 +188,7 @@ describe('create-next-app --example', () => {
'__internal-testing-retry',
'--import-alias=@/*',
],
nextInstall.installDir,
{
cwd,
input: '\n', // 'Yes' to retry
Expand Down Expand Up @@ -199,6 +220,7 @@ describe('create-next-app --example', () => {
'default',
'--import-alias=@/*',
],
nextInstall.installDir,
{
cwd,
}
Expand All @@ -217,10 +239,14 @@ describe('create-next-app --example', () => {
it('should not create if --example flag value is invalid', async () => {
await useTempDir(async (cwd) => {
const projectName = 'invalid-example'
const res = await run([projectName, '--example', 'not a real example'], {
cwd,
reject: false,
})
const res = await run(
[projectName, '--example', 'not a real example'],
nextInstall.installDir,
{
cwd,
reject: false,
}
)

expect(res.exitCode).toBe(1)
projectFilesShouldNotExist({
Expand All @@ -244,6 +270,7 @@ describe('create-next-app --example', () => {
'--no-tailwind',
'--example',
],
nextInstall.installDir,
{
cwd,
reject: false,
Expand Down
13 changes: 13 additions & 0 deletions test/integration/create-next-app/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import {
projectFilesShouldExist,
projectFilesShouldNotExist,
} from './utils'
import { createNextInstall } from '../../lib/create-next-install'
import { trace } from 'next/dist/trace'

let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})

describe('create-next-app', () => {
it('should not create if the target directory is not empty', async () => {
Expand All @@ -25,6 +35,7 @@ describe('create-next-app', () => {
'--no-src-dir',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
reject: false,
Expand Down Expand Up @@ -64,6 +75,7 @@ describe('create-next-app', () => {
'--no-src-dir',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
reject: false,
Expand Down Expand Up @@ -93,6 +105,7 @@ describe('create-next-app', () => {
'--no-import-alias',
'--skip-install',
],
nextInstall.installDir,
{
cwd,
}
Expand Down
25 changes: 21 additions & 4 deletions test/integration/create-next-app/package-manager/bun.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { trace } from 'next/dist/trace'
import { createNextInstall } from '../../../lib/create-next-install'
import {
command,
DEFAULT_FILES,
Expand All @@ -16,6 +18,14 @@ beforeEach(async () => {
.catch(() => command('npm', ['i', '-g', 'bun']))
})

let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})

describe('create-next-app with package manager bun', () => {
it('should use bun for --use-bun flag', async () => {
await useTempDir(async (cwd) => {
Expand All @@ -31,6 +41,7 @@ describe('create-next-app with package manager bun', () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -59,6 +70,7 @@ it('should use bun when user-agent is bun', async () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'bun' },
Expand All @@ -79,6 +91,7 @@ it('should use bun for --use-bun flag with example', async () => {
const projectName = 'use-bun-with-example'
const res = await run(
[projectName, '--use-bun', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{ cwd }
)

Expand All @@ -94,10 +107,14 @@ it('should use bun for --use-bun flag with example', async () => {
it('should use bun when user-agent is bun with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-bun-with-example'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
env: { npm_config_user_agent: 'bun' },
})
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'bun' },
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
Expand Down
25 changes: 21 additions & 4 deletions test/integration/create-next-app/package-manager/npm.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
import { trace } from 'next/dist/trace'
import {
DEFAULT_FILES,
FULL_EXAMPLE_PATH,
projectFilesShouldExist,
run,
useTempDir,
} from '../utils'
import { createNextInstall } from '../../../lib/create-next-install'

const lockFile = 'package-lock.json'
const files = [...DEFAULT_FILES, lockFile]

let nextInstall: Awaited<ReturnType<typeof createNextInstall>>
beforeAll(async () => {
nextInstall = await createNextInstall({
parentSpan: trace('test'),
keepRepoDir: Boolean(process.env.NEXT_TEST_SKIP_CLEANUP),
})
})

describe('create-next-app with package manager npm', () => {
it('should use npm for --use-npm flag', async () => {
await useTempDir(async (cwd) => {
Expand All @@ -24,6 +34,7 @@ describe('create-next-app with package manager npm', () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
}
Expand Down Expand Up @@ -52,6 +63,7 @@ it('should use npm when user-agent is npm', async () => {
'--no-tailwind',
'--no-import-alias',
],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'npm' },
Expand All @@ -72,6 +84,7 @@ it('should use npm for --use-npm flag with example', async () => {
const projectName = 'use-npm-with-example'
const res = await run(
[projectName, '--use-npm', '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{ cwd }
)

Expand All @@ -87,10 +100,14 @@ it('should use npm for --use-npm flag with example', async () => {
it('should use npm when user-agent is npm with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-npm-with-example'
const res = await run([projectName, '--example', FULL_EXAMPLE_PATH], {
cwd,
env: { npm_config_user_agent: 'npm' },
})
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextInstall.installDir,
{
cwd,
env: { npm_config_user_agent: 'npm' },
}
)

expect(res.exitCode).toBe(0)
projectFilesShouldExist({
Expand Down
Loading

0 comments on commit f83ec5a

Please sign in to comment.