-
Notifications
You must be signed in to change notification settings - Fork 177
Feat: Generic Code Patching #781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a65c92b
poc for code patching
conico974 6e43665
review fix
conico974 b2e94bd
fix build
conico974 b6f2a11
use ContentUpdater plugin
conico974 d0fda25
added ast-grep code patcher
conico974 c9b8917
added some manifests
conico974 3542789
fix and add logs
conico974 0beaee9
fix to apply patch one after the other
conico974 7da13fe
review fix
conico974 c53d36e
improve typing
conico974 0917c34
simplified CodePatcher types
conico974 ea7f2b5
fix linting
conico974 4bf7f95
changed versions to be more user friendly
conico974 cb7cbd9
review
conico974 dcdb184
review fix
conico974 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3,21 +3,17 @@ import logger from "../../logger.js"; | |||||
| import type { getManifests } from "../copyTracedFiles.js"; | ||||||
| import * as buildHelper from "../helper.js"; | ||||||
|
|
||||||
| // Either before or after should be provided, otherwise just use the field directly | ||||||
| type Versions = | ||||||
| | `>=${number}.${number}.${number} <=${number}.${number}.${number}` | ||||||
| | `>=${number}.${number}.${number}` | ||||||
| | `<=${number}.${number}.${number}`; | ||||||
| export interface VersionedField<T> { | ||||||
| /** | ||||||
| * The version before which the field should be used | ||||||
| * If the version is less than or equal to this, the field will be used | ||||||
| * The versions of Next.js that this field should be used for | ||||||
| * Should be in the format `">=16.0.0 <=17.0.0"` or `">=16.0.0"` or `"<=17.0.0"` | ||||||
| * **Be careful with spaces** | ||||||
| */ | ||||||
| before?: | ||||||
| | `${number}` | ||||||
| | `${number}.${number}` | ||||||
| | `${number}.${number}.${number}`; | ||||||
| /** | ||||||
| * The version after which the field should be used | ||||||
| * If the version is greater than this, the field will be used | ||||||
| */ | ||||||
| after?: `${number}` | `${number}.${number}` | `${number}.${number}.${number}`; | ||||||
| versions?: Versions; | ||||||
| field: T; | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -51,27 +47,76 @@ export interface CodePatcher { | |||||
| patches: IndividualPatch | VersionedField<IndividualPatch>[]; | ||||||
| } | ||||||
|
|
||||||
| export function parseVersions(versions?: Versions): { | ||||||
| before?: string; | ||||||
| after?: string; | ||||||
| } { | ||||||
| if (!versions) { | ||||||
| return {}; | ||||||
| } | ||||||
| // We need to use regex to extract the versions | ||||||
| const versionRegex = /([<>]=?)([0-9]+\.[0-9]+\.[0-9]+)/g; | ||||||
| const matches = Array.from(versions.matchAll(versionRegex)); | ||||||
| if (matches.length === 0) { | ||||||
| throw new Error("Invalid version range, no matches found"); | ||||||
| } | ||||||
| if (matches.length > 2) { | ||||||
| throw new Error("Invalid version range, too many matches found"); | ||||||
| } | ||||||
| let after: string | undefined; | ||||||
| let before: string | undefined; | ||||||
| for (const match of matches) { | ||||||
| const [_, operator, version] = match; | ||||||
| if (operator === "<=") { | ||||||
| before = version; | ||||||
| } else if (operator === ">=") { | ||||||
|
||||||
| } else if (operator === ">=") { | |
| } else { |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
=is not optional\dfor digits