fix(codemod): handle semver ranges in agents-md version detection#90067
Open
sleitor wants to merge 6 commits into
Open
fix(codemod): handle semver ranges in agents-md version detection#90067sleitor wants to merge 6 commits into
sleitor wants to merge 6 commits into
Conversation
Contributor
|
Allow CI Workflow Run
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
b52e95e to
937bc19
Compare
Contributor
Author
|
👋 Gentle ping — just checking if this is still on the radar for review. Happy to address any feedback or rebase if needed! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Fix
agents-mdcodemod failing when Next.js version is specified as a semver range inpackage.json(e.g.^16,~16.1.0) and the package is not yet installed.Why?
getNextjsVersion()only detects the installed version viarequire.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 returnsnulland the codemod fails with:How?
Added a fallback in
getNextjsVersion()that reads the version range frompackage.jsondependencies and extracts a concrete version using a new exportedextractVersionFromRange()helper:^16.1.3→16.1.3~16.1.0→16.1.0^16→16.0.0>=15.0.0→15.0.0^16.2.0-canary.16→16.2.0-canary.16The fallback is only used when
require.resolvefails and monorepo detection finds nothing.Checklist
fixes #numberFixes #89773
Fixes #89772