From 37a7eb17fe86fb075e030a5c7dc88e40f6961511 Mon Sep 17 00:00:00 2001 From: Francesco Moro Date: Fri, 11 Oct 2024 01:57:36 +0100 Subject: [PATCH] feat(expo): build w/package.json overrides/resolutions (#28254) ## Current Behavior When running nx build expo-app, the build executor copies dependencies and devDependencies of the workspace package.json (see copyPackageJsonAndLock function). The build executor does not copy the resolutions object (for yarn) nor the overrides object (for npm). ## Expected Behavior The build executor copies the overrides object or the resolutions object, if present in the package.json. The original project package.json is restored after the build is completed successfully or after it errors. ## Related Issue(s) #28249 Fixes # --- .../expo/src/executors/build/build.impl.ts | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/expo/src/executors/build/build.impl.ts b/packages/expo/src/executors/build/build.impl.ts index f93b5914a1f3c..0c57b34f7e101 100644 --- a/packages/expo/src/executors/build/build.impl.ts +++ b/packages/expo/src/executors/build/build.impl.ts @@ -143,6 +143,17 @@ function copyPackageJsonAndLock( projectPackageJson.dependencies = rootPackageJsonDependencies; projectPackageJson.devDependencies = rootPackageJsonDevDependencies; + const projectOverrides = projectPackageJson.overrides; + const projectResolutions = projectPackageJson.resolutions; + + if (rootPackageJson.overrides) { + projectPackageJson.overrides = rootPackageJson.overrides; + } + // if overrides exists, give precedence to it over resolutions + if (!rootPackageJson.overrides && rootPackageJson.resolutions) { + projectPackageJson.resolutions = rootPackageJson.resolutions; + } + // Copy dependencies from root package.json to project package.json writeJsonFile(packageJsonProject, projectPackageJson); @@ -153,6 +164,18 @@ function copyPackageJsonAndLock( // Reset project package.json to original state projectPackageJson.dependencies = projectPackageJsonDependencies; projectPackageJson.devDependencies = projectPackageJsonDevDependencies; + + if (projectOverrides) { + projectPackageJson.overrides = projectOverrides; + } else { + delete projectPackageJson.overrides; + } + if (projectResolutions) { + projectPackageJson.resolutions = projectResolutions; + } else { + delete projectPackageJson.resolutions; + } + writeFileSync( packageJsonProject, JSON.stringify(projectPackageJson, null, 2)