EvanBacon / expo-apple-targets

Config Plugin to setup Apple targets
308 stars 30 forks source link

feat: add support for custom bundle identifier #15

Open hannojg opened 10 months ago

hannojg commented 10 months ago

If we want to add for example a watch os widget extension to a watch target, it needs to start with same bundle id as the watch target. This gives the possibility to customise it.

Either pass a full bundle identifier, or start with a dot (.) so it will get appended to the main apps bundle id.

hesselbom commented 6 months ago

I have a related issue where I want to replace an existing project with a completely new Expo project, where the Watch app bundle id needs to match exactly the previous one. This PR would solve that issue.

FWIW here's the patch I'm using currently, inspired by this PR: patches/@bacons+apple-targets+0.0.3.patch

diff --git a/node_modules/@bacons/apple-targets/build/withWidget.js b/node_modules/@bacons/apple-targets/build/withWidget.js
index 0f7cec9..58d9f22 100644
--- a/node_modules/@bacons/apple-targets/build/withWidget.js
+++ b/node_modules/@bacons/apple-targets/build/withWidget.js
@@ -97,7 +97,9 @@ const withWidget = (config, props) => {
         },
     ]);
     const targetName = (_c = props.name) !== null && _c !== void 0 ? _c : widget;
-    const bundleId = config.ios.bundleIdentifier + "." + widget;
+    const bundleId = props.bundleIdentifier != null && props.bundleIdentifier.startsWith(".")
+      ? config.ios.bundleIdentifier + props.bundleIdentifier
+      : props.bundleIdentifier || config.ios.bundleIdentifier + "." + widget;
     (0, withXcodeChanges_1.withXcodeChanges)(config, {
         name: targetName,
         cwd: "../" +

It uses widget instead of targetName to more closely resemble the original code, but unsure what's best there.