@baeckerherz/expo-mapbox-navigation 0.1.14 → 0.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@baeckerherz/expo-mapbox-navigation",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
4
4
  "description": "Expo module wrapping Mapbox Navigation SDK v3 for iOS and Android",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const config_plugins_1 = require("@expo/config-plugins");
4
+ const withMapboxNavSPM_1 = require("./withMapboxNavSPM");
4
5
  const withMapboxNavPodfile_1 = require("./withMapboxNavPodfile");
5
6
  const withMapboxNavGradle_1 = require("./withMapboxNavGradle");
6
7
  const withMapboxNavGradleProperties_1 = require("./withMapboxNavGradleProperties");
@@ -8,7 +9,6 @@ const withMapboxNavigation = (config, { mapboxAccessToken, mapboxSecretToken, na
8
9
  if (!mapboxAccessToken) {
9
10
  throw new Error("[@baeckerherz/expo-mapbox-navigation] mapboxAccessToken is required.");
10
11
  }
11
- // Inject MBXAccessToken and required background modes into Info.plist
12
12
  if (!config.ios)
13
13
  config.ios = {};
14
14
  if (!config.ios.infoPlist)
@@ -25,9 +25,14 @@ const withMapboxNavigation = (config, { mapboxAccessToken, mapboxSecretToken, na
25
25
  config.ios.infoPlist.NSLocationAlwaysAndWhenInUseUsageDescription =
26
26
  config.ios.infoPlist.NSLocationAlwaysAndWhenInUseUsageDescription ||
27
27
  "This app needs your location for turn-by-turn navigation, including in the background.";
28
- // iOS: Mapbox SPM is added only to the Pods project (Podfile hook) so the
29
- // ExpoMapboxNavigation pod links it; adding it to the app project too would cause duplicate symbols.
30
- config = (0, withMapboxNavPodfile_1.withMapboxNavPodfile)(config, { navigationSdkVersion });
28
+ // iOS: Add Mapbox Navigation SDK as SPM dependency to the app Xcode project.
29
+ // xcodebuild resolves SPM packages automatically during the build this
30
+ // works reliably on both local and EAS clean builds (unlike injecting SPM
31
+ // into the Pods project, where resolution depended on prior workspace state).
32
+ config = (0, withMapboxNavSPM_1.withMapboxNavSPM)(config, { navigationSdkVersion });
33
+ // iOS: Set framework search paths so the ExpoMapboxNavigation pod can find
34
+ // the SPM-built Mapbox frameworks at compile time.
35
+ config = (0, withMapboxNavPodfile_1.withMapboxNavPodfile)(config);
31
36
  // Android: Mapbox Maven repository and optional token for SDK download
32
37
  config = (0, withMapboxNavGradle_1.withMapboxNavGradle)(config);
33
38
  config = (0, withMapboxNavGradleProperties_1.withMapboxNavGradleProperties)(config, { mapboxSecretToken });
@@ -1,12 +1,7 @@
1
1
  import { ConfigPlugin } from "@expo/config-plugins";
2
- interface PodfileOptions {
3
- navigationSdkVersion: string;
4
- }
5
2
  /**
6
- * Patches the iOS Podfile to add Mapbox Navigation SPM to the Pods project
7
- * and link it to the ExpoMapboxNavigation pod target, so the pod compiles
8
- * with the modules available (works on EAS and locally). Also sets
9
- * BUILD_LIBRARY_FOR_DISTRIBUTION for Mapbox-related pods.
3
+ * Patches the Podfile post_install so ExpoMapboxNavigation can find
4
+ * SPM-built Mapbox frameworks (added to the app .xcodeproj by withMapboxNavSPM).
5
+ * Also enables BUILD_LIBRARY_FOR_DISTRIBUTION on Mapbox/Turf pod targets.
10
6
  */
11
- export declare const withMapboxNavPodfile: ConfigPlugin<PodfileOptions>;
12
- export {};
7
+ export declare const withMapboxNavPodfile: ConfigPlugin;
@@ -37,28 +37,20 @@ exports.withMapboxNavPodfile = void 0;
37
37
  const config_plugins_1 = require("@expo/config-plugins");
38
38
  const fs = __importStar(require("fs"));
39
39
  const path = __importStar(require("path"));
40
- const MAPBOX_NAV_URL = "https://github.com/mapbox/mapbox-navigation-ios.git";
41
- const MAPBOX_NAV_PRODUCTS = [
42
- "MapboxNavigationUIKit",
43
- "MapboxNavigationCore",
44
- "MapboxDirections",
45
- ];
40
+ const PLUGIN_MARKER = "# @baeckerherz/expo-mapbox-navigation:";
46
41
  /**
47
- * Patches the iOS Podfile to add Mapbox Navigation SPM to the Pods project
48
- * and link it to the ExpoMapboxNavigation pod target, so the pod compiles
49
- * with the modules available (works on EAS and locally). Also sets
50
- * BUILD_LIBRARY_FOR_DISTRIBUTION for Mapbox-related pods.
42
+ * Patches the Podfile post_install so ExpoMapboxNavigation can find
43
+ * SPM-built Mapbox frameworks (added to the app .xcodeproj by withMapboxNavSPM).
44
+ * Also enables BUILD_LIBRARY_FOR_DISTRIBUTION on Mapbox/Turf pod targets.
51
45
  */
52
- const withMapboxNavPodfile = (config, { navigationSdkVersion }) => {
46
+ const withMapboxNavPodfile = (config) => {
53
47
  return (0, config_plugins_1.withDangerousMod)(config, [
54
48
  "ios",
55
49
  async (config) => {
56
50
  const podfilePath = path.join(config.modRequest.platformProjectRoot, "Podfile");
57
51
  let contents = fs.readFileSync(podfilePath, "utf8");
58
- const versionEscaped = navigationSdkVersion.replace(/'/g, "\\\\'");
59
52
  const hook = `
60
- # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods + search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
61
- mapbox_nav_version = '${versionEscaped}'
53
+ ${PLUGIN_MARKER} framework search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
62
54
  installer.pods_project.targets.each do |target|
63
55
  if target.name.start_with?('Mapbox') || target.name == 'Turf'
64
56
  target.build_configurations.each do |cfg|
@@ -75,46 +67,18 @@ const withMapboxNavPodfile = (config, { navigationSdkVersion }) => {
75
67
  cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
76
68
  end
77
69
  end
78
- end
79
- target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
80
- if target
81
- project = installer.pods_project
82
- root = project.root_object
83
- pkg_ref = nil
84
- pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' } if root.package_references
85
- unless pkg_ref
86
- pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
87
- pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
88
- pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
89
- root.package_references << pkg_ref
90
- end
91
- ${MAPBOX_NAV_PRODUCTS.map((name) => `
92
- unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
93
- product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
94
- product_dep.package = pkg_ref
95
- product_dep.product_name = '${name}'
96
- target.package_product_dependencies << product_dep
97
- if target.frameworks_build_phases
98
- build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
99
- build_file.product_ref = product_dep
100
- target.frameworks_build_phases.files << build_file
101
- end
102
- end`).join("")}
103
- project.save
104
- workspace_path = Dir.glob(File.join(installer.sandbox.root, '..', '*.xcworkspace'))[0]
105
- scheme = workspace_path ? File.basename(workspace_path, '.xcworkspace') : nil
106
- if workspace_path && scheme
107
- Dir.chdir(File.dirname(workspace_path)) { system('xcodebuild', '-resolvePackageDependencies', '-workspace', File.basename(workspace_path), '-scheme', scheme, '-configuration', 'Release') }
108
- end
109
70
  end`;
110
- const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
111
- const rnPostInstallSuffix = "ccache_enabled?(podfile_properties),\n )\n end";
112
- const oldHookPattern = new RegExp(` # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods[\\s\\S]*?(?= react_native_post_install)`, "m");
113
- if (contents.match(oldHookPattern)) {
114
- contents = contents.replace(oldHookPattern, "");
71
+ const escapedMarker = PLUGIN_MARKER.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
72
+ // Remove any previously injected hook (handles upgrades from older plugin versions)
73
+ if (contents.includes(PLUGIN_MARKER)) {
74
+ contents = contents.replace(new RegExp(`\\n ${escapedMarker}[\\s\\S]*?(?=\\n end\\nend)`), "");
115
75
  }
116
- if (!contents.includes(marker) && contents.includes(rnPostInstallSuffix)) {
117
- contents = contents.replace(rnPostInstallSuffix, `ccache_enabled?(podfile_properties),\n )\n${hook}\n end`);
76
+ // Inject after react_native_post_install, before the post_install block closes
77
+ if (!contents.includes(PLUGIN_MARKER)) {
78
+ const insertion = /(ccache_enabled\?\(podfile_properties\),\n\s*\))\s*\n( end\nend)/;
79
+ if (insertion.test(contents)) {
80
+ contents = contents.replace(insertion, `$1\n${hook}\n$2`);
81
+ }
118
82
  }
119
83
  fs.writeFileSync(podfilePath, contents);
120
84
  return config;
@@ -1,4 +1,5 @@
1
1
  import { ConfigPlugin, createRunOncePlugin } from "@expo/config-plugins";
2
+ import { withMapboxNavSPM } from "./withMapboxNavSPM";
2
3
  import { withMapboxNavPodfile } from "./withMapboxNavPodfile";
3
4
  import { withMapboxNavGradle } from "./withMapboxNavGradle";
4
5
  import { withMapboxNavGradleProperties } from "./withMapboxNavGradleProperties";
@@ -28,7 +29,6 @@ const withMapboxNavigation: ConfigPlugin<PluginConfig> = (
28
29
  );
29
30
  }
30
31
 
31
- // Inject MBXAccessToken and required background modes into Info.plist
32
32
  if (!config.ios) config.ios = {};
33
33
  if (!config.ios.infoPlist) config.ios.infoPlist = {};
34
34
  config.ios.infoPlist.MBXAccessToken = mapboxAccessToken;
@@ -44,9 +44,15 @@ const withMapboxNavigation: ConfigPlugin<PluginConfig> = (
44
44
  config.ios.infoPlist.NSLocationAlwaysAndWhenInUseUsageDescription ||
45
45
  "This app needs your location for turn-by-turn navigation, including in the background.";
46
46
 
47
- // iOS: Mapbox SPM is added only to the Pods project (Podfile hook) so the
48
- // ExpoMapboxNavigation pod links it; adding it to the app project too would cause duplicate symbols.
49
- config = withMapboxNavPodfile(config, { navigationSdkVersion });
47
+ // iOS: Add Mapbox Navigation SDK as SPM dependency to the app Xcode project.
48
+ // xcodebuild resolves SPM packages automatically during the build this
49
+ // works reliably on both local and EAS clean builds (unlike injecting SPM
50
+ // into the Pods project, where resolution depended on prior workspace state).
51
+ config = withMapboxNavSPM(config, { navigationSdkVersion });
52
+
53
+ // iOS: Set framework search paths so the ExpoMapboxNavigation pod can find
54
+ // the SPM-built Mapbox frameworks at compile time.
55
+ config = withMapboxNavPodfile(config);
50
56
 
51
57
  // Android: Mapbox Maven repository and optional token for SDK download
52
58
  config = withMapboxNavGradle(config);
@@ -2,27 +2,14 @@ import { withDangerousMod, ConfigPlugin } from "@expo/config-plugins";
2
2
  import * as fs from "fs";
3
3
  import * as path from "path";
4
4
 
5
- const MAPBOX_NAV_URL = "https://github.com/mapbox/mapbox-navigation-ios.git";
6
- const MAPBOX_NAV_PRODUCTS = [
7
- "MapboxNavigationUIKit",
8
- "MapboxNavigationCore",
9
- "MapboxDirections",
10
- ];
11
-
12
- interface PodfileOptions {
13
- navigationSdkVersion: string;
14
- }
5
+ const PLUGIN_MARKER = "# @baeckerherz/expo-mapbox-navigation:";
15
6
 
16
7
  /**
17
- * Patches the iOS Podfile to add Mapbox Navigation SPM to the Pods project
18
- * and link it to the ExpoMapboxNavigation pod target, so the pod compiles
19
- * with the modules available (works on EAS and locally). Also sets
20
- * BUILD_LIBRARY_FOR_DISTRIBUTION for Mapbox-related pods.
8
+ * Patches the Podfile post_install so ExpoMapboxNavigation can find
9
+ * SPM-built Mapbox frameworks (added to the app .xcodeproj by withMapboxNavSPM).
10
+ * Also enables BUILD_LIBRARY_FOR_DISTRIBUTION on Mapbox/Turf pod targets.
21
11
  */
22
- export const withMapboxNavPodfile: ConfigPlugin<PodfileOptions> = (
23
- config,
24
- { navigationSdkVersion }
25
- ) => {
12
+ export const withMapboxNavPodfile: ConfigPlugin = (config) => {
26
13
  return withDangerousMod(config, [
27
14
  "ios",
28
15
  async (config) => {
@@ -32,10 +19,8 @@ export const withMapboxNavPodfile: ConfigPlugin<PodfileOptions> = (
32
19
  );
33
20
  let contents = fs.readFileSync(podfilePath, "utf8");
34
21
 
35
- const versionEscaped = navigationSdkVersion.replace(/'/g, "\\\\'");
36
22
  const hook = `
37
- # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods + search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
38
- mapbox_nav_version = '${versionEscaped}'
23
+ ${PLUGIN_MARKER} framework search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
39
24
  installer.pods_project.targets.each do |target|
40
25
  if target.name.start_with?('Mapbox') || target.name == 'Turf'
41
26
  target.build_configurations.each do |cfg|
@@ -52,58 +37,32 @@ export const withMapboxNavPodfile: ConfigPlugin<PodfileOptions> = (
52
37
  cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
53
38
  end
54
39
  end
55
- end
56
- target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
57
- if target
58
- project = installer.pods_project
59
- root = project.root_object
60
- pkg_ref = nil
61
- pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' } if root.package_references
62
- unless pkg_ref
63
- pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
64
- pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
65
- pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
66
- root.package_references << pkg_ref
67
- end
68
- ${MAPBOX_NAV_PRODUCTS.map(
69
- (name) => `
70
- unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
71
- product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
72
- product_dep.package = pkg_ref
73
- product_dep.product_name = '${name}'
74
- target.package_product_dependencies << product_dep
75
- if target.frameworks_build_phases
76
- build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
77
- build_file.product_ref = product_dep
78
- target.frameworks_build_phases.files << build_file
79
- end
80
- end`
81
- ).join("")}
82
- project.save
83
- workspace_path = Dir.glob(File.join(installer.sandbox.root, '..', '*.xcworkspace'))[0]
84
- scheme = workspace_path ? File.basename(workspace_path, '.xcworkspace') : nil
85
- if workspace_path && scheme
86
- Dir.chdir(File.dirname(workspace_path)) { system('xcodebuild', '-resolvePackageDependencies', '-workspace', File.basename(workspace_path), '-scheme', scheme, '-configuration', 'Release') }
87
- end
88
40
  end`;
89
41
 
90
- const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
91
- const rnPostInstallSuffix =
92
- "ccache_enabled?(podfile_properties),\n )\n end";
93
- const oldHookPattern = new RegExp(
94
- ` # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods[\\s\\S]*?(?= react_native_post_install)`,
95
- "m"
42
+ const escapedMarker = PLUGIN_MARKER.replace(
43
+ /[.*+?^${}()|[\]\\]/g,
44
+ "\\$&"
96
45
  );
97
- if (contents.match(oldHookPattern)) {
98
- contents = contents.replace(oldHookPattern, "");
99
- }
100
- if (!contents.includes(marker) && contents.includes(rnPostInstallSuffix)) {
46
+
47
+ // Remove any previously injected hook (handles upgrades from older plugin versions)
48
+ if (contents.includes(PLUGIN_MARKER)) {
101
49
  contents = contents.replace(
102
- rnPostInstallSuffix,
103
- `ccache_enabled?(podfile_properties),\n )\n${hook}\n end`
50
+ new RegExp(
51
+ `\\n ${escapedMarker}[\\s\\S]*?(?=\\n end\\nend)`
52
+ ),
53
+ ""
104
54
  );
105
55
  }
106
56
 
57
+ // Inject after react_native_post_install, before the post_install block closes
58
+ if (!contents.includes(PLUGIN_MARKER)) {
59
+ const insertion =
60
+ /(ccache_enabled\?\(podfile_properties\),\n\s*\))\s*\n( end\nend)/;
61
+ if (insertion.test(contents)) {
62
+ contents = contents.replace(insertion, `$1\n${hook}\n$2`);
63
+ }
64
+ }
65
+
107
66
  fs.writeFileSync(podfilePath, contents);
108
67
  return config;
109
68
  },