Skip to content
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

feat: base RN upgrades experience #36

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 77 additions & 9 deletions packages/tools/src/react-native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ export const getReactNativeConfig = tool({
Returns:
- "root" - root directory of the project
- "path" - path to React Native CLI installation
- "version" - React Native version
- "platforms" - available platforms
- "project" - project configuration per platform

Expand All @@ -68,17 +67,10 @@ export const getReactNativeConfig = tool({
parameters: z.object({}),
execute: async () => {
try {
const {
root,
reactNativePath: path,
reactNativeVersion: version,
project,
platforms,
} = await loadReactNativeConfig()
const { root, reactNativePath: path, project, platforms } = await loadReactNativeConfig()
return {
root,
path,
version,
project,
platforms,
}
Expand Down Expand Up @@ -139,3 +131,79 @@ export const listReactNativeLibraries = tool({
}
},
})

export const getReactNativeReleases = tool({
description: dedent`
Gets releases of React Native from GitHub.

When upgrading React Native, ask user to select a version from the list.

RnDiffApp is the name of the app that generates diffs between two versions of React Native.

Make sure to replace RnDiffApp with the actual name of the app in the response.
`,
parameters: z.object({}),
execute: async () => {
try {
const response = await fetch(`https://api.github.com/repos/facebook/react-native/releases`)
const list = await response.json()

const mappedList = list
.filter((release: any) => !release.prerelease)
.map((release: any) => ({
name: release.name,
tag: release.tag_name,
}))

return {
success: true,
action: dedent`
Ask user to select a version from the list.
`,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no need for decent if single line.

Also, we can try Ask user to select a version from the list: ${mappedList} if it works .

This is all serialized to string anyway at the end of the day

releases: mappedList,
}
} catch (error) {
return {
error: error instanceof Error ? error.message : 'Failed to retrieve versions',
}
}
},
})

export const upgradeReactNativeDiff = tool({
description: dedent`
Upgrade React Native diff tool, returns a diff between two versions of React Native.

Parameters:
- "from" - source version, (Read the exact version from package.json using "readFile" tool). Example: "0.75.0"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I typically use this format just for Returns, because there's no validation. For parameters, I would just put this on the schema with zod.describe

- "to" - target version (latest React Native version). Example: "0.76.3"

Returns:
- "diff" - diff between two versions, containing differences in the project files you need to apply. Make sure to apply it 2 levels deep in the project tree.
When applying the diff, make sure to ask user for confirmation before proceeding. Don't read the files before applying the diff just apply it.
`,
parameters: z.object({
from: z.string(),
to: z.string(),
}),
execute: async ({ from, to }) => {
try {
const response = await fetch(
`https://raw.githubusercontent.com/react-native-community/rn-diff-purge/diffs/diffs/${from}..${to}.diff`
)
const diff = await response.text()

return {
success: true,
action: dedent`
Go over user file tree and apply diffs to the project.
`,
diff,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

save diff into file in os.tmp() and return path here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: in the future, we will need to unify our response formats. I think since AIs are conversational ,we can safely return Go over diff at path ${path} instead of returning it as an extra property

}
} catch (error) {
return {
error: error instanceof Error ? error.message : 'Failed to retrieve diff',
}
}
},
})