Skip to content

Commit

Permalink
Fix to support Expo 47
Browse files Browse the repository at this point in the history
Applied fixes from coffeOwl shared here: expo/expo#18784 (comment)

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.
  • Loading branch information
sroske committed Jan 31, 2023
1 parent c8794ac commit f10a431
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion build/withWatermelon.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
declare const _default: (config: any) => any;
declare const _default: (config: any, options: any) => any;
export default _default;
20 changes: 13 additions & 7 deletions build/withWatermelon.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
},
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
};
27 changes: 17 additions & 10 deletions src/withWatermelon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
Expand Down Expand Up @@ -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;
};

0 comments on commit f10a431

Please sign in to comment.