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.
158 lines
3.4 KiB
TypeScript
158 lines
3.4 KiB
TypeScript
import {
|
|
projectShouldHaveNoGitChanges,
|
|
tryNextDev,
|
|
run,
|
|
useTempDir,
|
|
projectFilesShouldExist,
|
|
} from '../utils'
|
|
import { mapSrcFiles, projectSpecification } from '../lib/specification'
|
|
import { projectDepsShouldBe } from '../lib/utils'
|
|
|
|
function shouldBeApiTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
mode,
|
|
srcDir,
|
|
}: {
|
|
cwd: string
|
|
projectName: string
|
|
mode: 'js' | 'ts'
|
|
srcDir?: boolean
|
|
}) {
|
|
const template = 'app-api'
|
|
|
|
projectFilesShouldExist({
|
|
cwd,
|
|
projectName,
|
|
files: mapSrcFiles(projectSpecification[template][mode].files, srcDir),
|
|
})
|
|
|
|
projectDepsShouldBe({
|
|
type: 'dependencies',
|
|
cwd,
|
|
projectName,
|
|
deps: mapSrcFiles(projectSpecification[template][mode].deps, srcDir),
|
|
})
|
|
|
|
projectDepsShouldBe({
|
|
type: 'devDependencies',
|
|
cwd,
|
|
projectName,
|
|
deps: mapSrcFiles(projectSpecification[template][mode].devDeps, srcDir),
|
|
})
|
|
}
|
|
|
|
describe('create-next-app --api (Headless App)', () => {
|
|
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',
|
|
'--api',
|
|
'--no-src-dir',
|
|
'--no-import-alias',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
shouldBeApiTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
mode: 'js',
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
isApi: true,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
|
|
it('should create TypeScript project with --ts flag', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'app-ts'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--api',
|
|
'--no-src-dir',
|
|
'--no-import-alias',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
}
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
shouldBeApiTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
mode: 'ts',
|
|
})
|
|
await tryNextDev({ cwd, isApi: true, 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',
|
|
'--api',
|
|
'--src-dir',
|
|
'--no-import-alias',
|
|
'--no-agents-md',
|
|
...(process.env.NEXT_RSPACK ? ['--rspack'] : []),
|
|
],
|
|
nextTgzFilename,
|
|
{
|
|
cwd,
|
|
stdio: 'inherit',
|
|
}
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
shouldBeApiTemplateProject({
|
|
cwd,
|
|
projectName,
|
|
mode: 'ts',
|
|
srcDir: true,
|
|
})
|
|
await tryNextDev({
|
|
cwd,
|
|
isApi: true,
|
|
projectName,
|
|
})
|
|
})
|
|
})
|
|
})
|