@baeckerherz/expo-mapbox-navigation 0.1.13 → 0.1.15

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.13",
3
+ "version": "0.1.15",
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,29 +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
- "MapboxMaps",
46
- ];
40
+ const PLUGIN_MARKER = "# @baeckerherz/expo-mapbox-navigation:";
47
41
  /**
48
- * Patches the iOS Podfile to add Mapbox Navigation SPM to the Pods project
49
- * and link it to the ExpoMapboxNavigation pod target, so the pod compiles
50
- * with the modules available (works on EAS and locally). Also sets
51
- * 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.
52
45
  */
53
- const withMapboxNavPodfile = (config, { navigationSdkVersion }) => {
46
+ const withMapboxNavPodfile = (config) => {
54
47
  return (0, config_plugins_1.withDangerousMod)(config, [
55
48
  "ios",
56
49
  async (config) => {
57
50
  const podfilePath = path.join(config.modRequest.platformProjectRoot, "Podfile");
58
51
  let contents = fs.readFileSync(podfilePath, "utf8");
59
- const versionEscaped = navigationSdkVersion.replace(/'/g, "\\\\'");
60
52
  const hook = `
61
- # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods + search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
62
- mapbox_nav_version = '${versionEscaped}'
53
+ ${PLUGIN_MARKER} framework search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
63
54
  installer.pods_project.targets.each do |target|
64
55
  if target.name.start_with?('Mapbox') || target.name == 'Turf'
65
56
  target.build_configurations.each do |cfg|
@@ -76,46 +67,18 @@ const withMapboxNavPodfile = (config, { navigationSdkVersion }) => {
76
67
  cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
77
68
  end
78
69
  end
79
- end
80
- target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
81
- if target
82
- project = installer.pods_project
83
- root = project.root_object
84
- pkg_ref = nil
85
- pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' } if root.package_references
86
- unless pkg_ref
87
- pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
88
- pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
89
- pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
90
- root.package_references << pkg_ref
91
- end
92
- ${MAPBOX_NAV_PRODUCTS.map((name) => `
93
- unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
94
- product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
95
- product_dep.package = pkg_ref
96
- product_dep.product_name = '${name}'
97
- target.package_product_dependencies << product_dep
98
- if target.frameworks_build_phases
99
- build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
100
- build_file.product_ref = product_dep
101
- target.frameworks_build_phases.files << build_file
102
- end
103
- end`).join("")}
104
- project.save
105
- workspace_path = Dir.glob(File.join(installer.sandbox.root, '..', '*.xcworkspace'))[0]
106
- scheme = workspace_path ? File.basename(workspace_path, '.xcworkspace') : nil
107
- if workspace_path && scheme
108
- Dir.chdir(File.dirname(workspace_path)) { system('xcodebuild', '-resolvePackageDependencies', '-workspace', File.basename(workspace_path), '-scheme', scheme, '-configuration', 'Release') }
109
- end
110
70
  end`;
111
- const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
112
- const rnPostInstallSuffix = "ccache_enabled?(podfile_properties),\n )\n end";
113
- const oldHookPattern = new RegExp(` # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods[\\s\\S]*?(?= react_native_post_install)`, "m");
114
- if (contents.match(oldHookPattern)) {
115
- 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)`), "");
116
75
  }
117
- if (!contents.includes(marker) && contents.includes(rnPostInstallSuffix)) {
118
- 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
+ }
119
82
  }
120
83
  fs.writeFileSync(podfilePath, contents);
121
84
  return config;
@@ -14,7 +14,11 @@ const withMapboxNavSPM = (config, { navigationSdkVersion }) => {
14
14
  const xcodeProject = config.modResults;
15
15
  const repoName = "mapbox-navigation-ios";
16
16
  const repoUrl = "https://github.com/mapbox/mapbox-navigation-ios.git";
17
- const products = ["MapboxNavigationUIKit", "MapboxNavigationCore"];
17
+ const products = [
18
+ "MapboxNavigationUIKit",
19
+ "MapboxNavigationCore",
20
+ "MapboxDirections",
21
+ ];
18
22
  if (!xcodeProject.hash.project.objects["XCRemoteSwiftPackageReference"]) {
19
23
  xcodeProject.hash.project.objects["XCRemoteSwiftPackageReference"] = {};
20
24
  }
@@ -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,28 +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
- "MapboxMaps",
11
- ];
12
-
13
- interface PodfileOptions {
14
- navigationSdkVersion: string;
15
- }
5
+ const PLUGIN_MARKER = "# @baeckerherz/expo-mapbox-navigation:";
16
6
 
17
7
  /**
18
- * Patches the iOS Podfile to add Mapbox Navigation SPM to the Pods project
19
- * and link it to the ExpoMapboxNavigation pod target, so the pod compiles
20
- * with the modules available (works on EAS and locally). Also sets
21
- * 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.
22
11
  */
23
- export const withMapboxNavPodfile: ConfigPlugin<PodfileOptions> = (
24
- config,
25
- { navigationSdkVersion }
26
- ) => {
12
+ export const withMapboxNavPodfile: ConfigPlugin = (config) => {
27
13
  return withDangerousMod(config, [
28
14
  "ios",
29
15
  async (config) => {
@@ -33,10 +19,8 @@ export const withMapboxNavPodfile: ConfigPlugin<PodfileOptions> = (
33
19
  );
34
20
  let contents = fs.readFileSync(podfilePath, "utf8");
35
21
 
36
- const versionEscaped = navigationSdkVersion.replace(/'/g, "\\\\'");
37
22
  const hook = `
38
- # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods + search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
39
- mapbox_nav_version = '${versionEscaped}'
23
+ ${PLUGIN_MARKER} framework search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
40
24
  installer.pods_project.targets.each do |target|
41
25
  if target.name.start_with?('Mapbox') || target.name == 'Turf'
42
26
  target.build_configurations.each do |cfg|
@@ -53,58 +37,32 @@ export const withMapboxNavPodfile: ConfigPlugin<PodfileOptions> = (
53
37
  cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
54
38
  end
55
39
  end
56
- end
57
- target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
58
- if target
59
- project = installer.pods_project
60
- root = project.root_object
61
- pkg_ref = nil
62
- pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' } if root.package_references
63
- unless pkg_ref
64
- pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
65
- pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
66
- pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
67
- root.package_references << pkg_ref
68
- end
69
- ${MAPBOX_NAV_PRODUCTS.map(
70
- (name) => `
71
- unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
72
- product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
73
- product_dep.package = pkg_ref
74
- product_dep.product_name = '${name}'
75
- target.package_product_dependencies << product_dep
76
- if target.frameworks_build_phases
77
- build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
78
- build_file.product_ref = product_dep
79
- target.frameworks_build_phases.files << build_file
80
- end
81
- end`
82
- ).join("")}
83
- project.save
84
- workspace_path = Dir.glob(File.join(installer.sandbox.root, '..', '*.xcworkspace'))[0]
85
- scheme = workspace_path ? File.basename(workspace_path, '.xcworkspace') : nil
86
- if workspace_path && scheme
87
- Dir.chdir(File.dirname(workspace_path)) { system('xcodebuild', '-resolvePackageDependencies', '-workspace', File.basename(workspace_path), '-scheme', scheme, '-configuration', 'Release') }
88
- end
89
40
  end`;
90
41
 
91
- const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
92
- const rnPostInstallSuffix =
93
- "ccache_enabled?(podfile_properties),\n )\n end";
94
- const oldHookPattern = new RegExp(
95
- ` # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods[\\s\\S]*?(?= react_native_post_install)`,
96
- "m"
42
+ const escapedMarker = PLUGIN_MARKER.replace(
43
+ /[.*+?^${}()|[\]\\]/g,
44
+ "\\$&"
97
45
  );
98
- if (contents.match(oldHookPattern)) {
99
- contents = contents.replace(oldHookPattern, "");
100
- }
101
- 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)) {
102
49
  contents = contents.replace(
103
- rnPostInstallSuffix,
104
- `ccache_enabled?(podfile_properties),\n )\n${hook}\n end`
50
+ new RegExp(
51
+ `\\n ${escapedMarker}[\\s\\S]*?(?=\\n end\\nend)`
52
+ ),
53
+ ""
105
54
  );
106
55
  }
107
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
+
108
66
  fs.writeFileSync(podfilePath, contents);
109
67
  return config;
110
68
  },
@@ -20,7 +20,11 @@ export const withMapboxNavSPM: ConfigPlugin<SPMConfig> = (
20
20
 
21
21
  const repoName = "mapbox-navigation-ios";
22
22
  const repoUrl = "https://github.com/mapbox/mapbox-navigation-ios.git";
23
- const products = ["MapboxNavigationUIKit", "MapboxNavigationCore"];
23
+ const products = [
24
+ "MapboxNavigationUIKit",
25
+ "MapboxNavigationCore",
26
+ "MapboxDirections",
27
+ ];
24
28
 
25
29
  if (!xcodeProject.hash.project.objects["XCRemoteSwiftPackageReference"]) {
26
30
  xcodeProject.hash.project.objects["XCRemoteSwiftPackageReference"] = {};