Skip to content

fix(codemod): handle semver ranges in agents-md version detection#90067

Open
sleitor wants to merge 6 commits into
vercel:canaryfrom
sleitor:fix/agents-md-version-range-detection
Open

fix(codemod): handle semver ranges in agents-md version detection#90067
sleitor wants to merge 6 commits into
vercel:canaryfrom
sleitor:fix/agents-md-version-range-detection

Conversation

@sleitor
Copy link
Copy Markdown
Contributor

@sleitor sleitor commented Feb 17, 2026

What?

Fix agents-md codemod failing when Next.js version is specified as a semver range in package.json (e.g. ^16, ~16.1.0) and the package is not yet installed.

Why?

getNextjsVersion() only detects the installed version via require.resolve('next/package.json'). When Next.js isn't installed yet (common when running the codemod for the first time, or when an AI agent re-runs the generated command in a fresh sandbox), the function returns null and the codemod fails with:

Could not find documentation for Next.js v16. This version may not exist on GitHub yet.

How?

Added a fallback in getNextjsVersion() that reads the version range from package.json dependencies and extracts a concrete version using a new exported extractVersionFromRange() helper:

  • ^16.1.316.1.3
  • ~16.1.016.1.0
  • ^1616.0.0
  • >=15.0.015.0.0
  • ^16.2.0-canary.1616.2.0-canary.16

The fallback is only used when require.resolve fails and monorepo detection finds nothing.

Checklist

  • Related issues linked using fixes #number
  • Tests added
  • Errors have a helpful link attached — N/A (no new error messages)

Fixes #89773
Fixes #89772

@nextjs-bot
Copy link
Copy Markdown
Contributor

nextjs-bot commented Feb 17, 2026

Allow CI Workflow Run

  • approve CI run for commit: e64b452

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Added extractVersionFromRange() to parse semver ranges (^16.1.3,
~15.0.0, >=14.0.0) and extract the base version. Updated
getNextjsVersion() to fall back to package.json
dependencies/devDependencies when Next.js is not installed (e.g.,
fresh projects before npm install).

Added unit tests for extractVersionFromRange and getNextjsVersion
with fixture-based testing.

Fixes vercel#89773
Fixes vercel#89772
@sleitor sleitor force-pushed the fix/agents-md-version-range-detection branch from b52e95e to 937bc19 Compare February 17, 2026 19:08
@sleitor
Copy link
Copy Markdown
Contributor Author

sleitor commented Apr 7, 2026

👋 Gentle ping — just checking if this is still on the radar for review. Happy to address any feedback or rebase if needed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

agents-md does not detect version properly if ranges are used agents-md provides non-working command in AGENTS.md instructions

2 participants