@next/codemod 16.4.0-canary.37 → 16.4.0-canary.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/agents-md.js CHANGED
@@ -37,7 +37,7 @@ async function runAgentsMd(options) {
37
37
  // --version provided: --output is required
38
38
  if (!options.output) {
39
39
  throw new shared_1.BadInput('When using --version, --output is also required.\n' +
40
- 'Example: npx @next/codemod agents-md --version 15.1.3 --output CLAUDE.md');
40
+ 'Example: npx @next/codemod agents-md --version 15.1.3 --output AGENTS.md');
41
41
  }
42
42
  nextjsVersion = options.version;
43
43
  targetFile = options.output;
@@ -58,7 +58,7 @@ async function runAgentsMd(options) {
58
58
  nextjsVersion = promptedOptions.nextVersion;
59
59
  targetFile = promptedOptions.targetFile;
60
60
  }
61
- const claudeMdPath = path_1.default.join(cwd, targetFile);
61
+ const agentsMdPath = path_1.default.join(cwd, targetFile);
62
62
  // Next.js >= 16.2.0 ships its docs inside the published package. When the
63
63
  // installed version matches the requested one, index the bundled docs
64
64
  // directly instead of downloading a copy into .next-docs.
@@ -73,8 +73,8 @@ async function runAgentsMd(options) {
73
73
  let sizeBefore = 0;
74
74
  let isNewFile = true;
75
75
  let existingContent = '';
76
- if (fs_1.default.existsSync(claudeMdPath)) {
77
- existingContent = fs_1.default.readFileSync(claudeMdPath, 'utf-8');
76
+ if (fs_1.default.existsSync(agentsMdPath)) {
77
+ existingContent = fs_1.default.readFileSync(agentsMdPath, 'utf-8');
78
78
  sizeBefore = Buffer.byteLength(existingContent, 'utf-8');
79
79
  isNewFile = false;
80
80
  }
@@ -94,13 +94,13 @@ async function runAgentsMd(options) {
94
94
  }
95
95
  const docFiles = (0, agents_md_1.collectDocFiles)(docsPath);
96
96
  const sections = (0, agents_md_1.buildDocTree)(docFiles);
97
- const indexContent = (0, agents_md_1.generateClaudeMdIndex)({
97
+ const indexContent = (0, agents_md_1.generateAgentsMdIndex)({
98
98
  docsPath: docsLinkPath,
99
99
  sections,
100
100
  outputFile: targetFile,
101
101
  });
102
- const newContent = (0, agents_md_1.injectIntoClaudeMd)(existingContent, indexContent);
103
- fs_1.default.writeFileSync(claudeMdPath, newContent, 'utf-8');
102
+ const newContent = (0, agents_md_1.injectIntoAgentsMd)(existingContent, indexContent);
103
+ fs_1.default.writeFileSync(agentsMdPath, newContent, 'utf-8');
104
104
  const sizeAfter = Buffer.byteLength(newContent, 'utf-8');
105
105
  // .next-docs only exists on the download path; bundled docs live in
106
106
  // node_modules, which is already ignored.
@@ -136,7 +136,6 @@ async function promptForOptions(cwd) {
136
136
  name: 'targetFile',
137
137
  message: 'Target markdown file',
138
138
  choices: [
139
- { title: 'CLAUDE.md', value: 'CLAUDE.md' },
140
139
  { title: 'AGENTS.md', value: 'AGENTS.md' },
141
140
  { title: 'Custom...', value: '__custom__' },
142
141
  ],
@@ -154,7 +153,7 @@ async function promptForOptions(cwd) {
154
153
  type: 'text',
155
154
  name: 'customFile',
156
155
  message: 'Enter custom file path',
157
- initial: 'CLAUDE.md',
156
+ initial: 'AGENTS.md',
158
157
  validate: (value) => value.trim() ? true : 'Please enter a file path',
159
158
  }, { onCancel: utils_1.onCancel });
160
159
  if (customResponse.customFile === undefined) {
@@ -63,7 +63,7 @@ program
63
63
  .command('agents-md')
64
64
  .description('Generate Next.js documentation index for AI coding agents (Claude, Cursor, etc.).')
65
65
  .option('--version <version>', 'Next.js version (auto-detected if not provided)')
66
- .option('--output <file>', 'Target file path (e.g., CLAUDE.md, AGENTS.md)')
66
+ .option('--output <file>', 'Target file path (e.g., AGENTS.md)')
67
67
  .action(async (options) => {
68
68
  try {
69
69
  await (0, agents_md_1.runAgentsMd)(options);
package/bin/upgrade.js CHANGED
@@ -394,7 +394,7 @@ async function runUpgrade(revision, options) {
394
394
  }
395
395
  try {
396
396
  if ((0, agents_md_1.refreshAgentRulesBlock)(cwd) === 'refreshed') {
397
- console.log(`${picocolors_1.default.green('✔')} Refreshed the managed agent-rules block in AGENTS.md / CLAUDE.md to match the upgraded Next.js.`);
397
+ console.log(`${picocolors_1.default.green('✔')} Refreshed the managed agent-rules block in AGENTS.md to match the upgraded Next.js.`);
398
398
  }
399
399
  }
400
400
  catch {
@@ -11,7 +11,7 @@ const { getNextjsVersion } = require('../../lib/agents-md')
11
11
  * TRUE E2E TESTS
12
12
  * These tests invoke the actual CLI entry point (runAgentsMd),
13
13
  * simulating what happens when a user runs:
14
- * npx @next/codemod agents-md --version 15.0.0 --output CLAUDE.md
14
+ * npx @next/codemod agents-md --version 15.0.0 --output AGENTS.md
15
15
  */
16
16
  describe('agents-md e2e (CLI invocation)', () => {
17
17
  let testProjectDir
@@ -45,7 +45,7 @@ describe('agents-md e2e (CLI invocation)', () => {
45
45
  }
46
46
  })
47
47
 
48
- it('creates CLAUDE.md and .next-docs directory when run with --version and --output', async () => {
48
+ it('creates AGENTS.md and .next-docs directory when run with --version and --output', async () => {
49
49
  // Create a minimal package.json (not required, but realistic)
50
50
  const packageJson = {
51
51
  name: 'test-project',
@@ -67,7 +67,7 @@ describe('agents-md e2e (CLI invocation)', () => {
67
67
  // Run the actual CLI command
68
68
  await runAgentsMd({
69
69
  version: '15.0.0',
70
- output: 'CLAUDE.md',
70
+ output: 'AGENTS.md',
71
71
  })
72
72
 
73
73
  // Verify .next-docs directory was created and populated
@@ -83,20 +83,20 @@ describe('agents-md e2e (CLI invocation)', () => {
83
83
  )
84
84
  expect(mdxFiles.length).toBeGreaterThan(0)
85
85
 
86
- // Verify CLAUDE.md was created
87
- const claudeMdPath = path.join(testProjectDir, 'CLAUDE.md')
88
- expect(fs.existsSync(claudeMdPath)).toBe(true)
86
+ // Verify AGENTS.md was created
87
+ const agentsMdPath = path.join(testProjectDir, 'AGENTS.md')
88
+ expect(fs.existsSync(agentsMdPath)).toBe(true)
89
89
 
90
- const claudeMdContent = fs.readFileSync(claudeMdPath, 'utf-8')
90
+ const agentsMdContent = fs.readFileSync(agentsMdPath, 'utf-8')
91
91
 
92
92
  // Verify content structure
93
- expect(claudeMdContent).toContain('<!-- NEXT-AGENTS-MD-START -->')
94
- expect(claudeMdContent).toContain('<!-- NEXT-AGENTS-MD-END -->')
95
- expect(claudeMdContent).toContain('[Next.js Docs Index]')
96
- expect(claudeMdContent).toContain('root: ./.next-docs')
93
+ expect(agentsMdContent).toContain('<!-- NEXT-AGENTS-MD-START -->')
94
+ expect(agentsMdContent).toContain('<!-- NEXT-AGENTS-MD-END -->')
95
+ expect(agentsMdContent).toContain('[Next.js Docs Index]')
96
+ expect(agentsMdContent).toContain('root: ./.next-docs')
97
97
 
98
98
  // Verify paths are normalized to forward slashes (cross-platform)
99
- const lines = claudeMdContent.split('|')
99
+ const lines = agentsMdContent.split('|')
100
100
  const pathLines = lines.filter((line) => line.includes(':'))
101
101
  pathLines.forEach((line) => {
102
102
  // Should not contain Windows backslashes in the output
@@ -117,19 +117,19 @@ describe('agents-md e2e (CLI invocation)', () => {
117
117
  const output = consoleOutput.join('\n')
118
118
  expect(output).toContain('Downloading Next.js')
119
119
  expect(output).toContain('15.0.0')
120
- expect(output).toContain('CLAUDE.md')
120
+ expect(output).toContain('AGENTS.md')
121
121
  } finally {
122
122
  // Restore original directory
123
123
  process.chdir(originalCwd)
124
124
  }
125
125
  })
126
126
 
127
- it('updates existing CLAUDE.md without losing content', async () => {
127
+ it('updates existing AGENTS.md without losing content', async () => {
128
128
  const originalCwd = process.cwd()
129
129
  process.chdir(testProjectDir)
130
130
 
131
131
  try {
132
- // Create existing CLAUDE.md with custom content
132
+ // Create existing AGENTS.md with custom content
133
133
  const existingContent = `# My Project
134
134
 
135
135
  This is my project documentation.
@@ -138,31 +138,28 @@ This is my project documentation.
138
138
  - Feature 1
139
139
  - Feature 2
140
140
  `
141
- fs.writeFileSync(
142
- path.join(testProjectDir, 'CLAUDE.md'),
143
- existingContent
144
- )
141
+ fs.writeFileSync(path.join(testProjectDir, 'AGENTS.md'), existingContent)
145
142
 
146
143
  // Run CLI
147
144
  await runAgentsMd({
148
145
  version: '15.0.0',
149
- output: 'CLAUDE.md',
146
+ output: 'AGENTS.md',
150
147
  })
151
148
 
152
149
  // Verify file was updated, not replaced
153
- const claudeMdContent = fs.readFileSync(
154
- path.join(testProjectDir, 'CLAUDE.md'),
150
+ const agentsMdContent = fs.readFileSync(
151
+ path.join(testProjectDir, 'AGENTS.md'),
155
152
  'utf-8'
156
153
  )
157
154
 
158
155
  // Original content should still be there
159
- expect(claudeMdContent).toContain('# My Project')
160
- expect(claudeMdContent).toContain('This is my project documentation.')
161
- expect(claudeMdContent).toContain('## Features')
156
+ expect(agentsMdContent).toContain('# My Project')
157
+ expect(agentsMdContent).toContain('This is my project documentation.')
158
+ expect(agentsMdContent).toContain('## Features')
162
159
 
163
160
  // New index should be injected
164
- expect(claudeMdContent).toContain('<!-- NEXT-AGENTS-MD-START -->')
165
- expect(claudeMdContent).toContain('[Next.js Docs Index]')
161
+ expect(agentsMdContent).toContain('<!-- NEXT-AGENTS-MD-START -->')
162
+ expect(agentsMdContent).toContain('[Next.js Docs Index]')
166
163
  } finally {
167
164
  process.chdir(originalCwd)
168
165
  }
@@ -179,9 +176,8 @@ This is my project documentation.
179
176
  output: 'AGENTS.md',
180
177
  })
181
178
 
182
- // Verify AGENTS.md was created (not CLAUDE.md)
179
+ // Verify AGENTS.md was created
183
180
  expect(fs.existsSync(path.join(testProjectDir, 'AGENTS.md'))).toBe(true)
184
- expect(fs.existsSync(path.join(testProjectDir, 'CLAUDE.md'))).toBe(false)
185
181
 
186
182
  const agentsMdContent = fs.readFileSync(
187
183
  path.join(testProjectDir, 'AGENTS.md'),
@@ -216,11 +212,11 @@ This is my project documentation.
216
212
  // Run from subdirectory - should create files in CWD (subdirectory)
217
213
  await runAgentsMd({
218
214
  version: '15.0.0',
219
- output: 'CLAUDE.md',
215
+ output: 'AGENTS.md',
220
216
  })
221
217
 
222
218
  // Verify files created in subdirectory
223
- expect(fs.existsSync(path.join(subDir, 'CLAUDE.md'))).toBe(true)
219
+ expect(fs.existsSync(path.join(subDir, 'AGENTS.md'))).toBe(true)
224
220
  expect(fs.existsSync(path.join(subDir, '.next-docs'))).toBe(true)
225
221
  } finally {
226
222
  process.chdir(originalCwd)
@@ -234,20 +230,20 @@ This is my project documentation.
234
230
  try {
235
231
  await runAgentsMd({
236
232
  version: '15.0.0',
237
- output: 'CLAUDE.md',
233
+ output: 'AGENTS.md',
238
234
  })
239
235
 
240
- const claudeMdContent = fs.readFileSync(
241
- path.join(testProjectDir, 'CLAUDE.md'),
236
+ const agentsMdContent = fs.readFileSync(
237
+ path.join(testProjectDir, 'AGENTS.md'),
242
238
  'utf-8'
243
239
  )
244
240
 
245
241
  // Extract the index content between markers
246
242
  const startMarker = '<!-- NEXT-AGENTS-MD-START -->'
247
243
  const endMarker = '<!-- NEXT-AGENTS-MD-END -->'
248
- const startIdx = claudeMdContent.indexOf(startMarker) + startMarker.length
249
- const endIdx = claudeMdContent.indexOf(endMarker)
250
- const indexContent = claudeMdContent.slice(startIdx, endIdx)
244
+ const startIdx = agentsMdContent.indexOf(startMarker) + startMarker.length
245
+ const endIdx = agentsMdContent.indexOf(endMarker)
246
+ const indexContent = agentsMdContent.slice(startIdx, endIdx)
251
247
 
252
248
  // Parse the index (format: "dir:{file1,file2}|dir2:{file3}")
253
249
  const sections = indexContent.split('|').filter((s) => s.includes(':'))
@@ -276,7 +272,7 @@ This is my project documentation.
276
272
  // Use a known stable version
277
273
  await runAgentsMd({
278
274
  version: '14.2.0',
279
- output: 'CLAUDE.md',
275
+ output: 'AGENTS.md',
280
276
  })
281
277
 
282
278
  // Verify docs were downloaded
@@ -331,7 +327,7 @@ This is my project documentation.
331
327
  process.chdir(testProjectDir)
332
328
 
333
329
  try {
334
- await runAgentsMd({ output: 'CLAUDE.md' })
330
+ await runAgentsMd({ output: 'AGENTS.md' })
335
331
 
336
332
  // No .next-docs copy and no .gitignore entry for it
337
333
  expect(fs.existsSync(path.join(testProjectDir, '.next-docs'))).toBe(
@@ -341,14 +337,14 @@ This is my project documentation.
341
337
  false
342
338
  )
343
339
 
344
- const claudeMdContent = fs.readFileSync(
345
- path.join(testProjectDir, 'CLAUDE.md'),
340
+ const agentsMdContent = fs.readFileSync(
341
+ path.join(testProjectDir, 'AGENTS.md'),
346
342
  'utf-8'
347
343
  )
348
- expect(claudeMdContent).toContain(
344
+ expect(agentsMdContent).toContain(
349
345
  'root: ./node_modules/next/dist/docs'
350
346
  )
351
- expect(claudeMdContent).toContain('01-installation.md')
347
+ expect(agentsMdContent).toContain('01-installation.md')
352
348
 
353
349
  const output = consoleOutput.join('\n')
354
350
  expect(output).toContain('bundled with Next.js')
@@ -390,17 +386,17 @@ This is my project documentation.
390
386
  process.chdir(testProjectDir)
391
387
 
392
388
  try {
393
- await runAgentsMd({ version: '15.0.0', output: 'CLAUDE.md' })
389
+ await runAgentsMd({ version: '15.0.0', output: 'AGENTS.md' })
394
390
 
395
391
  expect(fs.existsSync(path.join(testProjectDir, '.next-docs'))).toBe(
396
392
  true
397
393
  )
398
394
 
399
- const claudeMdContent = fs.readFileSync(
400
- path.join(testProjectDir, 'CLAUDE.md'),
395
+ const agentsMdContent = fs.readFileSync(
396
+ path.join(testProjectDir, 'AGENTS.md'),
401
397
  'utf-8'
402
398
  )
403
- expect(claudeMdContent).toContain('root: ./.next-docs')
399
+ expect(agentsMdContent).toContain('root: ./.next-docs')
404
400
 
405
401
  const output = consoleOutput.join('\n')
406
402
  expect(output).toContain('Downloading')
package/lib/agents-md.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * agents-md: Generate Next.js documentation index for AI coding agents.
4
4
  *
5
5
  * Downloads docs from GitHub via git sparse-checkout, builds a compact
6
- * index of all doc files, and injects it into CLAUDE.md or AGENTS.md.
6
+ * index of all doc files, and injects it into AGENTS.md.
7
7
  */
8
8
  var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
@@ -16,8 +16,8 @@ exports.getBundledDocsLinkPath = getBundledDocsLinkPath;
16
16
  exports.pullDocs = pullDocs;
17
17
  exports.collectDocFiles = collectDocFiles;
18
18
  exports.buildDocTree = buildDocTree;
19
- exports.generateClaudeMdIndex = generateClaudeMdIndex;
20
- exports.injectIntoClaudeMd = injectIntoClaudeMd;
19
+ exports.generateAgentsMdIndex = generateAgentsMdIndex;
20
+ exports.injectIntoAgentsMd = injectIntoAgentsMd;
21
21
  exports.ensureGitignoreEntry = ensureGitignoreEntry;
22
22
  const execa_1 = __importDefault(require("execa"));
23
23
  const fs_1 = __importDefault(require("fs"));
@@ -26,8 +26,7 @@ const os_1 = __importDefault(require("os"));
26
26
  const AGENT_RULES_START_MARKER = '<!-- BEGIN:nextjs-agent-rules -->';
27
27
  /**
28
28
  * After an upgrade, refresh the managed agent-rules block in
29
- * AGENTS.md / CLAUDE.md so its content matches the Next.js version
30
- * that is now installed.
29
+ * AGENTS.md so its content matches the Next.js version that is now installed.
31
30
  *
32
31
  * Delegates to the installed package's own generator
33
32
  * (`next/dist/server/lib/generate-agent-files`), so the block text is
@@ -39,17 +38,14 @@ const AGENT_RULES_START_MARKER = '<!-- BEGIN:nextjs-agent-rules -->';
39
38
  * (< 16.3).
40
39
  */
41
40
  function refreshAgentRulesBlock(cwd) {
42
- const hostsBlock = ['AGENTS.md', 'CLAUDE.md'].some((file) => {
43
- try {
44
- return fs_1.default
45
- .readFileSync(path_1.default.join(cwd, file), 'utf-8')
46
- .includes(AGENT_RULES_START_MARKER);
47
- }
48
- catch {
49
- return false;
50
- }
51
- });
52
- if (!hostsBlock)
41
+ let agentsMdContent;
42
+ try {
43
+ agentsMdContent = fs_1.default.readFileSync(path_1.default.join(cwd, 'AGENTS.md'), 'utf-8');
44
+ }
45
+ catch {
46
+ return 'skipped';
47
+ }
48
+ if (!agentsMdContent.includes(AGENT_RULES_START_MARKER))
53
49
  return 'skipped';
54
50
  let writeAgentFiles;
55
51
  try {
@@ -62,9 +58,7 @@ function refreshAgentRulesBlock(cwd) {
62
58
  return 'skipped';
63
59
  }
64
60
  const result = writeAgentFiles(cwd);
65
- return result.agentsMd === 'updated' || result.claudeMd === 'updated'
66
- ? 'refreshed'
67
- : 'current';
61
+ return result.agentsMd === 'updated' ? 'refreshed' : 'current';
68
62
  }
69
63
  function getNextjsVersion(cwd) {
70
64
  try {
@@ -263,13 +257,13 @@ function buildDocTree(files) {
263
257
  }
264
258
  return sortedSections;
265
259
  }
266
- function generateClaudeMdIndex(data) {
260
+ function generateAgentsMdIndex(data) {
267
261
  const { docsPath, sections, outputFile } = data;
268
262
  const parts = [];
269
263
  parts.push('[Next.js Docs Index]');
270
264
  parts.push(`root: ${docsPath}`);
271
265
  parts.push('STOP. What you remember about Next.js is WRONG for this project. Always search docs and read before any task.');
272
- const targetFile = outputFile || 'CLAUDE.md';
266
+ const targetFile = outputFile || 'AGENTS.md';
273
267
  parts.push(`If docs missing, run this command first: npx @next/codemod agents-md --output ${targetFile}`);
274
268
  const allFiles = collectAllFilesFromSections(sections);
275
269
  const grouped = groupByDirectory(allFiles);
@@ -312,17 +306,17 @@ function hasExistingIndex(content) {
312
306
  function wrapWithMarkers(content) {
313
307
  return `${START_MARKER}${content}${END_MARKER}`;
314
308
  }
315
- function injectIntoClaudeMd(claudeMdContent, indexContent) {
309
+ function injectIntoAgentsMd(agentsMdContent, indexContent) {
316
310
  const wrappedContent = wrapWithMarkers(indexContent);
317
- if (hasExistingIndex(claudeMdContent)) {
318
- const startIdx = claudeMdContent.indexOf(START_MARKER);
319
- const endIdx = claudeMdContent.indexOf(END_MARKER) + END_MARKER.length;
320
- return (claudeMdContent.slice(0, startIdx) +
311
+ if (hasExistingIndex(agentsMdContent)) {
312
+ const startIdx = agentsMdContent.indexOf(START_MARKER);
313
+ const endIdx = agentsMdContent.indexOf(END_MARKER) + END_MARKER.length;
314
+ return (agentsMdContent.slice(0, startIdx) +
321
315
  wrappedContent +
322
- claudeMdContent.slice(endIdx));
316
+ agentsMdContent.slice(endIdx));
323
317
  }
324
- const separator = claudeMdContent.endsWith('\n') ? '\n' : '\n\n';
325
- return claudeMdContent + separator + wrappedContent + '\n';
318
+ const separator = agentsMdContent.endsWith('\n') ? '\n' : '\n\n';
319
+ return agentsMdContent + separator + wrappedContent + '\n';
326
320
  }
327
321
  const GITIGNORE_ENTRY = '.next-docs/';
328
322
  function ensureGitignoreEntry(cwd) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/codemod",
3
- "version": "16.4.0-canary.37",
3
+ "version": "16.4.0-canary.39",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,7 +20,7 @@ const utils_1 = require("../lib/utils");
20
20
  */
21
21
  function transformer(file, _api) {
22
22
  if (process.env.NODE_ENV !== 'test' &&
23
- !/(^|[/\\])app[/\\].*?(page|layout|default)\.[^/\\]+$/.test(file.path)) {
23
+ !/(^|[/\\])app[/\\](?:.*[/\\])?(page|layout|default)\.[^/\\]+$/.test(file.path)) {
24
24
  return file.source;
25
25
  }
26
26
  const j = (0, parser_1.createParserFromPath)(file.path);