mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
AI coding agents often rely on outdated training data when working with Next.js projects, leading to hallucinated APIs and deprecated patterns. This PR addresses that by shipping version-matched documentation inside the `next` npm package and generating agent instruction files during `create-next-app`. During `next` build, a new `copy_docs` task copies `docs/` from the repo root into `dist/docs/`. Since `"dist"` is already in the package's `files` array, the docs are automatically published at `node_modules/next/dist/docs/`. `create-next-app` gains a new `--agents-md` / `--no-agents-md` flag (defaults to `true`). When enabled it writes two files: - `AGENTS.md` — instructs agents to read `node_modules/next/dist/docs/` instead of relying on training data - `CLAUDE.md` — uses `@AGENTS.md` import syntax for Claude Code The option appears in the recommended defaults display and is prompted during the customize flow. Existing tests are updated with `--no-agents-md` to avoid the new prompt.
239 lines
5.4 KiB
TypeScript
239 lines
5.4 KiB
TypeScript
import {
|
|
projectShouldHaveNoGitChanges,
|
|
shouldBeTemplateProject,
|
|
tryNextDev,
|
|
run,
|
|
useTempDir,
|
|
} from '../utils'
|
|
|
|
describe('create-next-app --app (App Router)', () => {
|
|
let nextTgzFilename: string
|
|
|
|
beforeAll(() => {
|
|
if (!process.env.NEXT_TEST_PKG_PATHS) {
|
|
throw new Error('This test needs to be run with `node run-tests.js`.')
|
|
}
|
|
|
|
const pkgPaths = new Map<string, string>(
|
|
JSON.parse(process.env.NEXT_TEST_PKG_PATHS)
|
|
)
|
|
|
|
nextTgzFilename = pkgPaths.get('next')
|
|
})
|
|
|
|
it('should create JavaScript project with --js flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-js'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--js',
|
|
'--app',
|
|
'--eslint',
|
|
'--no-src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'js' })
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create TypeScript project with --ts flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-ts'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--no-src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({ cwd, projectName, template: 'app', mode: 'ts' })
|
|
await tryNextDev({ cwd, projectName })
|
|
projectShouldHaveNoGitChanges({ cwd, projectName })
|
|
})
|
|
})
|
|
|
|
it('should create project inside "src" directory with --src-dir flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-src-dir'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
stdio: 'inherit',
|
|
}
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app',
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create TailwindCSS project with --tailwind flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-tw'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
'--tailwind',
|
|
'--no-import-alias',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app-tw',
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create an empty project with --empty flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-empty'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
'--empty',
|
|
'--no-tailwind',
|
|
'--no-import-alias',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
const isEmpty = true
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app-empty',
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
isEmpty,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create an empty TailwindCSS project with --empty flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-tw-empty'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--app',
|
|
'--eslint',
|
|
'--src-dir',
|
|
'--tailwind',
|
|
'--empty',
|
|
'--no-import-alias',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
const isEmpty = true
|
|
expect(exitCode).toBe(0)
|
|
shouldBeTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
template: 'app-tw-empty',
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
projectName,
|
|
isEmpty,
|
|
})
|
|
})
|
|
})
|
|
})
|