From f10a431349a4ab24429251da9c54b6fed60d7532 Mon Sep 17 00:00:00 2001 From: Shawn Roske Date: Tue, 31 Jan 2023 13:28:29 -0600 Subject: [PATCH] Fix to support Expo 47 Applied fixes from coffeOwl shared here: https://github.com/expo/expo/issues/18784#issuecomment-1333726866 fix for android build Added the watermelon db package to the main activity init package list as it appears to be needed (i.e. auto-linking is not working for me). Also added an escape for the simulator architecture exclusion to the config option for the expo plugin. --- build/withWatermelon.d.ts | 2 +- build/withWatermelon.js | 20 +++++++++++++------- src/withWatermelon.ts | 27 +++++++++++++++++---------- 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/build/withWatermelon.d.ts b/build/withWatermelon.d.ts index 1bc35bd..0476aa0 100644 --- a/build/withWatermelon.d.ts +++ b/build/withWatermelon.d.ts @@ -1,2 +1,2 @@ -declare const _default: (config: any) => any; +declare const _default: (config: any, options: any) => any; export default _default; diff --git a/build/withWatermelon.js b/build/withWatermelon.js index 232ace6..129727c 100644 --- a/build/withWatermelon.js +++ b/build/withWatermelon.js @@ -41,6 +41,7 @@ function setAndroidMainApplication(config) { const filePath = `${root}/app/src/main/java/${(_b = (_a = config === null || config === void 0 ? void 0 : config.android) === null || _a === void 0 ? void 0 : _a.package) === null || _b === void 0 ? void 0 : _b.replace(/\./g, "/")}/MainApplication.java`; const contents = await fs.readFile(filePath, "utf-8"); let updated = (0, insertLinesHelper_1.insertLinesHelper)("import com.nozbe.watermelondb.WatermelonDBPackage;", "import java.util.List;", contents); + updated = (0, insertLinesHelper_1.insertLinesHelper)(" packages.add(new WatermelonDBPackage());", " // Packages that cannot be autolinked yet can be added manually here, for example:", updated); await fs.writeFile(filePath, updated); return config; }, @@ -95,11 +96,13 @@ const withCocoaPods = (config) => { const contents = await fs.readFile(filePath, "utf-8"); const watermelonPath = isWatermelonDBInstalled(config.modRequest.projectRoot); if (watermelonPath) { - await fs.writeFile(filePath, ` -pod 'WatermelonDB', :path => '../node_modules/@nozbe/watermelondb' -pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi', :modular_headers => true -pod 'simdjson', path: '../node_modules/@nozbe/simdjson'\n - ` + contents); + const patchKey = "post_install"; + const slicedContent = contents.split(patchKey); + slicedContent[0] += `\n + pod 'WatermelonDB', :path => '../node_modules/@nozbe/watermelondb' + pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi', :modular_headers => true + pod 'simdjson', path: '../node_modules/@nozbe/simdjson'\n\n `; + await fs.writeFile(filePath, slicedContent.join(patchKey)); } else { throw new Error("Please make sure you have watermelondb installed"); @@ -144,13 +147,16 @@ function replace(contents, match, replace) { return contents.replace(match, replace); } // @ts-ignore -exports.default = (config) => { +exports.default = (config, options) => { + var _a; config = setAppSettingBuildGradle(config); config = setAppBuildGradle(config); config = setAndroidMainApplication(config); config = setAppDelegate(config); config = setWmelonBridgingHeader(config); config = withCocoaPods(config); - config = withExcludedSimulatorArchitectures(config); + if ((_a = options === null || options === void 0 ? void 0 : options.excludeSimulatorArchitectures) !== null && _a !== void 0 ? _a : true) { + config = withExcludedSimulatorArchitectures(config); + } return config; }; diff --git a/src/withWatermelon.ts b/src/withWatermelon.ts index f207a73..5b586ec 100644 --- a/src/withWatermelon.ts +++ b/src/withWatermelon.ts @@ -63,6 +63,12 @@ function setAndroidMainApplication(config: ExportedConfigWithProps) { contents ); + updated = insertLinesHelper( + " packages.add(new WatermelonDBPackage());", + " // Packages that cannot be autolinked yet can be added manually here, for example:", + updated + ); + await fs.writeFile(filePath, updated); return config; @@ -144,14 +150,13 @@ const withCocoaPods = (config: ExportedConfigWithProps) => { ); if (watermelonPath) { - await fs.writeFile( - filePath, - ` -pod 'WatermelonDB', :path => '../node_modules/@nozbe/watermelondb' -pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi', :modular_headers => true -pod 'simdjson', path: '../node_modules/@nozbe/simdjson'\n - ` + contents - ); + const patchKey = "post_install"; + const slicedContent = contents.split(patchKey); + slicedContent[0] += `\n + pod 'WatermelonDB', :path => '../node_modules/@nozbe/watermelondb' + pod 'React-jsi', :path => '../node_modules/react-native/ReactCommon/jsi', :modular_headers => true + pod 'simdjson', path: '../node_modules/@nozbe/simdjson'\n\n `; + await fs.writeFile(filePath, slicedContent.join(patchKey)) } else { throw new Error("Please make sure you have watermelondb installed"); } @@ -207,13 +212,15 @@ function replace(contents: string, match: string, replace: string): string { } // @ts-ignore -export default (config) => { +export default (config, options) => { config = setAppSettingBuildGradle(config); config = setAppBuildGradle(config); config = setAndroidMainApplication(config); config = setAppDelegate(config); config = setWmelonBridgingHeader(config); config = withCocoaPods(config); - config = withExcludedSimulatorArchitectures(config); + if ( options?.excludeSimulatorArchitectures ?? true ) { + config = withExcludedSimulatorArchitectures(config); + } return config; };