@next/codemod 16.3.0-canary.81 → 16.3.0-canary.82

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/upgrade.js CHANGED
@@ -47,6 +47,7 @@ const picocolors_1 = __importDefault(require("picocolors"));
47
47
  const handle_package_1 = require("../lib/handle-package");
48
48
  const transform_1 = require("./transform");
49
49
  const utils_1 = require("../lib/utils");
50
+ const agents_md_1 = require("../lib/agents-md");
50
51
  const shared_1 = require("./shared");
51
52
  const optionalNextjsPackages = [
52
53
  'create-next-app',
@@ -380,6 +381,14 @@ async function runUpgrade(revision, options) {
380
381
  if (codemods.length > 0) {
381
382
  console.log(`${picocolors_1.default.green('✔')} Codemods have been applied successfully.`);
382
383
  }
384
+ try {
385
+ if ((0, agents_md_1.refreshAgentRulesBlock)(cwd) === 'refreshed') {
386
+ console.log(`${picocolors_1.default.green('✔')} Refreshed the managed agent-rules block in AGENTS.md / CLAUDE.md to match the upgraded Next.js.`);
387
+ }
388
+ }
389
+ catch {
390
+ // The block refresh is best-effort — never fail the upgrade over it.
391
+ }
383
392
  warnDependenciesOutOfRange(appPackageJson, versionMapping);
384
393
  endMessage(targetNextVersion);
385
394
  }
package/lib/agents-md.js CHANGED
@@ -9,6 +9,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
9
9
  return (mod && mod.__esModule) ? mod : { "default": mod };
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.refreshAgentRulesBlock = refreshAgentRulesBlock;
12
13
  exports.getNextjsVersion = getNextjsVersion;
13
14
  exports.getBundledDocsInfo = getBundledDocsInfo;
14
15
  exports.getBundledDocsLinkPath = getBundledDocsLinkPath;
@@ -22,6 +23,49 @@ const execa_1 = __importDefault(require("execa"));
22
23
  const fs_1 = __importDefault(require("fs"));
23
24
  const path_1 = __importDefault(require("path"));
24
25
  const os_1 = __importDefault(require("os"));
26
+ const AGENT_RULES_START_MARKER = '<!-- BEGIN:nextjs-agent-rules -->';
27
+ /**
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.
31
+ *
32
+ * Delegates to the installed package's own generator
33
+ * (`next/dist/server/lib/generate-agent-files`), so the block text is
34
+ * always the one shipped with that version — this codemod never
35
+ * carries its own copy. Returns `'refreshed'` when a file was
36
+ * rewritten, `'current'` when the block was already up to date, and
37
+ * `'skipped'` when there is nothing to do: the project never adopted
38
+ * the managed block, or the installed Next.js predates the generator
39
+ * (< 16.3).
40
+ */
41
+ 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)
53
+ return 'skipped';
54
+ let writeAgentFiles;
55
+ try {
56
+ const generatorPath = require.resolve('next/dist/server/lib/generate-agent-files', { paths: [cwd] });
57
+ writeAgentFiles = require(generatorPath).writeAgentFiles;
58
+ if (typeof writeAgentFiles !== 'function')
59
+ return 'skipped';
60
+ }
61
+ catch {
62
+ return 'skipped';
63
+ }
64
+ const result = writeAgentFiles(cwd);
65
+ return result.agentsMd === 'updated' || result.claudeMd === 'updated'
66
+ ? 'refreshed'
67
+ : 'current';
68
+ }
25
69
  function getNextjsVersion(cwd) {
26
70
  try {
27
71
  const nextPkgPath = require.resolve('next/package.json', { paths: [cwd] });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@next/codemod",
3
- "version": "16.3.0-canary.81",
3
+ "version": "16.3.0-canary.82",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",