Skip to content

Commit

Permalink
fix(cli): improper MST removal when using CLI prompt, new arch compat (
Browse files Browse the repository at this point in the history
…#2785 by @frankcalise)

* fix(cli): proper union type for state mgmt when using prompts

* fix(boilerplate): lint fix when mst is removed

* fix(boilerplate): rehydrated not needed with removal of MST

* fix(new): new arch compat libs
  • Loading branch information
frankcalise authored Sep 26, 2024
1 parent ffd7911 commit 3956652
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
5 changes: 4 additions & 1 deletion boilerplate/app/devtools/ReactotronConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { ArgType } from "reactotron-core-client"
import { mst } from "reactotron-mst" // @mst remove-current-line
import mmkvPlugin from "reactotron-react-native-mmkv"

import { storage, clear } from "@/utils/storage"
import {
storage,
clear, // @mst remove-current-line
} from "@/utils/storage"
import { goBack, resetRoot, navigate } from "@/navigators/navigationUtilities"

import { Reactotron } from "./ReactotronClient"
Expand Down
3 changes: 2 additions & 1 deletion boilerplate/src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export default function Root() {

const [fontsLoaded, fontError] = useFonts(customFontsToLoad)

const loaded = fontsLoaded && rehydrated
const loaded = fontsLoaded
&& rehydrated // @mst remove-current-line

useEffect(() => {
if (fontError) throw fontError
Expand Down
16 changes: 14 additions & 2 deletions src/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ import type { ValidationsExports } from "../tools/validations"
import { boolFlag } from "../tools/flag"
import { cache } from "../tools/cache"
import { mstDependenciesToRemove } from "../tools/mst"
import { findAndRemoveDependencies } from "../tools/dependencies"
import {
findAndRemoveDependencies,
findAndUpdateDependencyVersions,
newArchCompatExpectedVersions,
} from "../tools/dependencies"
import { demoDependenciesToRemove, findDemoPatches } from "../tools/demo"

type Workflow = "cng" | "manual"
Expand Down Expand Up @@ -366,7 +370,7 @@ module.exports = {
format: prettyPrompt.format.boolean,
prefix,
}))
stateMgmt = includeMSTResponse.includeMST
stateMgmt = includeMSTResponse.includeMST ? "mst" : "none"
}
}

Expand Down Expand Up @@ -658,6 +662,14 @@ module.exports = {
packageJsonRaw = findAndRemoveDependencies(packageJsonRaw, mstDependenciesToRemove)
}

if (experimentalNewArch) {
log(`Swapping new architecture compatible dependencies...`)
packageJsonRaw = findAndUpdateDependencyVersions(
packageJsonRaw,
newArchCompatExpectedVersions,
)
}

// Then write it back out.
const packageJson = JSON.parse(packageJsonRaw)
write("./package.json", packageJson)
Expand Down
22 changes: 22 additions & 0 deletions src/tools/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,25 @@ export function removePackageJSONDependencies(
const updatedPackageJson = findAndRemoveDependencies(packageJsonRaw, dependenciesToRemove)
filesystem.write(packageJsonPath, updatedPackageJson)
}

export function findAndUpdateDependencyVersions(
packageJsonRaw: string,
dependencies: Record<string, string>,
): string {
let updatedPackageJson = packageJsonRaw

Object.keys(dependencies).forEach((depName) => {
const desiredVersion = dependencies[depName]
const regex = new RegExp(`"${depName}"\\s*:\\s*"[^"]+"`, "g")
updatedPackageJson = updatedPackageJson.replace(regex, `"${depName}": "${desiredVersion}"`)
})

// Make sure `expo-dev-client` is removed
updatedPackageJson = updatedPackageJson.replace(/"expo-dev-client"\s*:\s*"[^"]+",?/g, "")

return updatedPackageJson
}

export const newArchCompatExpectedVersions = {
"react-native-mmkv": "3.0.1",
}

0 comments on commit 3956652

Please sign in to comment.