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.
114 lines
3.3 KiB
TypeScript
114 lines
3.3 KiB
TypeScript
import { existsSync } from 'fs'
|
|
import { readFile } from 'fs/promises'
|
|
import { join } from 'path'
|
|
import { run, useTempDir } from './utils'
|
|
|
|
describe('create-next-app ESLint configuration', () => {
|
|
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 generate eslint.config.mjs for TypeScript project with ESLint', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'test-eslint-ts'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--ts',
|
|
'--eslint',
|
|
'--no-tailwind',
|
|
'--no-src-dir',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
'--app',
|
|
'--no-import-alias',
|
|
'--skip-install',
|
|
],
|
|
nextTgzFilename,
|
|
{ cwd }
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
const projectDir = join(cwd, projectName)
|
|
|
|
// Should have eslint.config.mjs
|
|
expect(existsSync(join(projectDir, 'eslint.config.mjs'))).toBe(true)
|
|
|
|
// Should NOT have biome.json
|
|
expect(existsSync(join(projectDir, 'biome.json'))).toBe(false)
|
|
|
|
// Check eslint.config.mjs content
|
|
const eslintConfig = await readFile(
|
|
join(projectDir, 'eslint.config.mjs'),
|
|
'utf8'
|
|
)
|
|
expect(eslintConfig).toContain('next/core-web-vitals')
|
|
expect(eslintConfig).toContain('next/typescript')
|
|
|
|
// Check package.json scripts
|
|
const packageJson = JSON.parse(
|
|
await readFile(join(projectDir, 'package.json'), 'utf8')
|
|
)
|
|
expect(packageJson.scripts.lint).toBe('eslint')
|
|
expect(packageJson.devDependencies.eslint).toBeTruthy()
|
|
expect(packageJson.devDependencies['eslint-config-next']).toBeTruthy()
|
|
})
|
|
})
|
|
|
|
it('should generate eslint.config.mjs for JavaScript project with ESLint', async () => {
|
|
await useTempDir(async (cwd) => {
|
|
const projectName = 'test-eslint-js'
|
|
const { exitCode } = await run(
|
|
[
|
|
projectName,
|
|
'--js',
|
|
'--eslint',
|
|
'--no-tailwind',
|
|
'--no-src-dir',
|
|
'--no-react-compiler',
|
|
'--no-agents-md',
|
|
'--app',
|
|
'--no-import-alias',
|
|
'--skip-install',
|
|
],
|
|
nextTgzFilename,
|
|
{ cwd }
|
|
)
|
|
|
|
expect(exitCode).toBe(0)
|
|
|
|
const projectDir = join(cwd, projectName)
|
|
|
|
// Should have eslint.config.mjs
|
|
expect(existsSync(join(projectDir, 'eslint.config.mjs'))).toBe(true)
|
|
|
|
// Check eslint.config.mjs content for JS project
|
|
const eslintConfig = await readFile(
|
|
join(projectDir, 'eslint.config.mjs'),
|
|
'utf8'
|
|
)
|
|
expect(eslintConfig).toContain('next/core-web-vitals')
|
|
expect(eslintConfig).not.toContain('next/typescript')
|
|
|
|
// Check package.json scripts
|
|
const packageJson = JSON.parse(
|
|
await readFile(join(projectDir, 'package.json'), 'utf8')
|
|
)
|
|
expect(packageJson.scripts.lint).toBe('eslint')
|
|
expect(packageJson.devDependencies.eslint).toBeTruthy()
|
|
expect(packageJson.devDependencies['eslint-config-next']).toBeTruthy()
|
|
})
|
|
})
|
|
})
|