Files
next.js/test/integration/create-next-app/package-manager/yarn.test.ts
Jude GaoandGitHub b9ec2e4f8d [AI] Ship bundled docs in next and generate AGENTS.md in create-next-app (#89850)
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.
2026-02-11 21:50:12 +01:00

136 lines
3.0 KiB
TypeScript

import {
command,
DEFAULT_FILES,
FULL_EXAMPLE_PATH,
projectFilesShouldExist,
run,
useTempDir,
} from '../utils'
const lockFile = 'yarn.lock'
const files = [...DEFAULT_FILES, lockFile]
describe('create-next-app with package manager yarn', () => {
let nextTgzFilename: string
beforeAll(async () => {
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')
await command('yarn', ['--version'])
// install yarn if not available
.catch(() =>
command('corepack', ['prepare', '--activate', '[email protected]'])
)
.catch(() => command('npm', ['i', '-g', 'yarn']))
})
it('should use yarn for --use-yarn flag', async () => {
await useTempDir(async (cwd) => {
const projectName = 'use-yarn'
const res = await run(
[
projectName,
'--ts',
'--app',
'--use-yarn',
'--no-linter',
'--no-src-dir',
'--no-tailwind',
'--no-import-alias',
'--no-react-compiler',
'--no-agents-md',
],
nextTgzFilename,
{
cwd,
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})
it('should use yarn when user-agent is yarn', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-yarn'
const res = await run(
[
projectName,
'--ts',
'--app',
'--no-linter',
'--no-src-dir',
'--no-tailwind',
'--no-import-alias',
'--no-react-compiler',
'--no-agents-md',
],
nextTgzFilename,
{
cwd,
env: { npm_config_user_agent: 'yarn' },
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})
it('should use yarn for --use-yarn flag with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'use-yarn-with-example'
const res = await run(
[projectName, '--use-yarn', '--example', FULL_EXAMPLE_PATH],
nextTgzFilename,
{ cwd }
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})
it('should use yarn when user-agent is yarn with example', async () => {
await useTempDir(async (cwd) => {
const projectName = 'user-agent-yarn-with-example'
const res = await run(
[projectName, '--example', FULL_EXAMPLE_PATH],
nextTgzFilename,
{
cwd,
env: { npm_config_user_agent: 'yarn' },
}
)
expect(res.exitCode).toBe(0)
projectFilesShouldExist({
cwd,
projectName,
files,
})
})
})
})