@baeckerherz/expo-mapbox-navigation 0.1.7 → 0.1.9

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.7",
3
+ "version": "0.1.9",
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",
@@ -28,8 +28,8 @@ const withMapboxNavigation = (config, { mapboxAccessToken, mapboxSecretToken, na
28
28
  "This app needs your location for turn-by-turn navigation, including in the background.";
29
29
  // iOS: Inject SPM package references
30
30
  config = (0, withMapboxNavSPM_1.withMapboxNavSPM)(config, { navigationSdkVersion });
31
- // iOS: Patch Podfile for SPM framework visibility
32
- config = (0, withMapboxNavPodfile_1.withMapboxNavPodfile)(config);
31
+ // iOS: Patch Podfile so ExpoMapboxNavigation pod has Mapbox SPM dependency
32
+ config = (0, withMapboxNavPodfile_1.withMapboxNavPodfile)(config, { navigationSdkVersion });
33
33
  // Android: Mapbox Maven repository and optional token for SDK download
34
34
  config = (0, withMapboxNavGradle_1.withMapboxNavGradle)(config);
35
35
  config = (0, withMapboxNavGradleProperties_1.withMapboxNavGradleProperties)(config, { mapboxSecretToken });
@@ -1,7 +1,12 @@
1
1
  import { ConfigPlugin } from "@expo/config-plugins";
2
+ interface PodfileOptions {
3
+ navigationSdkVersion: string;
4
+ }
2
5
  /**
3
- * Patches the iOS Podfile to make SPM framework products visible
4
- * to the ExpoMapboxNavigation pod target, and sets BUILD_LIBRARY_FOR_DISTRIBUTION
5
- * for Mapbox-related pods.
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.
6
10
  */
7
- export declare const withMapboxNavPodfile: ConfigPlugin;
11
+ export declare const withMapboxNavPodfile: ConfigPlugin<PodfileOptions>;
12
+ export {};
@@ -37,36 +37,67 @@ 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 = ["MapboxNavigationUIKit", "MapboxNavigationCore"];
40
42
  /**
41
- * Patches the iOS Podfile to make SPM framework products visible
42
- * to the ExpoMapboxNavigation pod target, and sets BUILD_LIBRARY_FOR_DISTRIBUTION
43
- * for Mapbox-related pods.
43
+ * Patches the iOS Podfile to add Mapbox Navigation SPM to the Pods project
44
+ * and link it to the ExpoMapboxNavigation pod target, so the pod compiles
45
+ * with the modules available (works on EAS and locally). Also sets
46
+ * BUILD_LIBRARY_FOR_DISTRIBUTION for Mapbox-related pods.
44
47
  */
45
- const withMapboxNavPodfile = (config) => {
48
+ const withMapboxNavPodfile = (config, { navigationSdkVersion }) => {
46
49
  return (0, config_plugins_1.withDangerousMod)(config, [
47
50
  "ios",
48
51
  async (config) => {
49
52
  const podfilePath = path.join(config.modRequest.platformProjectRoot, "Podfile");
50
53
  let contents = fs.readFileSync(podfilePath, "utf8");
54
+ const versionEscaped = navigationSdkVersion.replace(/'/g, "\\\\'");
51
55
  const hook = `
52
- # @baeckerherz/expo-mapbox-navigation: Make SPM frameworks visible to the pod target
56
+ # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods + search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
57
+ mapbox_nav_version = '${versionEscaped}'
53
58
  installer.pods_project.targets.each do |target|
54
- if target.name == 'ExpoMapboxNavigation'
55
- target.build_configurations.each do |config|
56
- shared_products = '$(BUILT_PRODUCTS_DIR)/..'
57
- config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= ['$(inherited)']
58
- config.build_settings['FRAMEWORK_SEARCH_PATHS'] << shared_products
59
- config.build_settings['SWIFT_INCLUDE_PATHS'] ||= ['$(inherited)']
60
- config.build_settings['SWIFT_INCLUDE_PATHS'] << shared_products
59
+ if target.name.start_with?('Mapbox') || target.name == 'Turf'
60
+ target.build_configurations.each do |cfg|
61
+ cfg.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
61
62
  end
62
63
  end
63
- if target.name.start_with?('Mapbox') || target.name == 'Turf'
64
- target.build_configurations.each do |config|
65
- config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
64
+ if target.name == 'ExpoMapboxNavigation'
65
+ target.build_configurations.each do |cfg|
66
+ cfg.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= ['$(inherited)']
67
+ cfg.build_settings['FRAMEWORK_SEARCH_PATHS'] << '$(BUILT_PRODUCTS_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
68
+ cfg.build_settings['FRAMEWORK_SEARCH_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
69
+ cfg.build_settings['SWIFT_INCLUDE_PATHS'] ||= ['$(inherited)']
70
+ cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
71
+ cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
66
72
  end
67
73
  end
74
+ end
75
+ target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
76
+ if target
77
+ project = installer.pods_project
78
+ root = project.root_object
79
+ pkg_ref = nil
80
+ pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' } if root.package_references
81
+ unless pkg_ref
82
+ pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
83
+ pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
84
+ pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
85
+ root.package_references << pkg_ref
86
+ end
87
+ ${MAPBOX_NAV_PRODUCTS.map((name) => `
88
+ unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
89
+ product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
90
+ product_dep.package = pkg_ref
91
+ product_dep.product_name = '${name}'
92
+ target.package_product_dependencies << product_dep
93
+ build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
94
+ build_file.product_ref = product_dep
95
+ target.frameworks_build_phases.files << build_file
96
+ end`).join("")}
97
+ project.save
68
98
  end`;
69
- if (!contents.includes("@baeckerherz/expo-mapbox-navigation: Make SPM frameworks")) {
99
+ const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
100
+ if (!contents.includes(marker)) {
70
101
  if (contents.includes("post_install do |installer|")) {
71
102
  contents = contents.replace("post_install do |installer|", `post_install do |installer|${hook}`);
72
103
  }
@@ -48,8 +48,8 @@ const withMapboxNavigation: ConfigPlugin<PluginConfig> = (
48
48
  // iOS: Inject SPM package references
49
49
  config = withMapboxNavSPM(config, { navigationSdkVersion });
50
50
 
51
- // iOS: Patch Podfile for SPM framework visibility
52
- config = withMapboxNavPodfile(config);
51
+ // iOS: Patch Podfile so ExpoMapboxNavigation pod has Mapbox SPM dependency
52
+ config = withMapboxNavPodfile(config, { navigationSdkVersion });
53
53
 
54
54
  // Android: Mapbox Maven repository and optional token for SDK download
55
55
  config = withMapboxNavGradle(config);
@@ -2,12 +2,23 @@ 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 = ["MapboxNavigationUIKit", "MapboxNavigationCore"];
7
+
8
+ interface PodfileOptions {
9
+ navigationSdkVersion: string;
10
+ }
11
+
5
12
  /**
6
- * Patches the iOS Podfile to make SPM framework products visible
7
- * to the ExpoMapboxNavigation pod target, and sets BUILD_LIBRARY_FOR_DISTRIBUTION
8
- * for Mapbox-related pods.
13
+ * Patches the iOS Podfile to add Mapbox Navigation SPM to the Pods project
14
+ * and link it to the ExpoMapboxNavigation pod target, so the pod compiles
15
+ * with the modules available (works on EAS and locally). Also sets
16
+ * BUILD_LIBRARY_FOR_DISTRIBUTION for Mapbox-related pods.
9
17
  */
10
- export const withMapboxNavPodfile: ConfigPlugin = (config) => {
18
+ export const withMapboxNavPodfile: ConfigPlugin<PodfileOptions> = (
19
+ config,
20
+ { navigationSdkVersion }
21
+ ) => {
11
22
  return withDangerousMod(config, [
12
23
  "ios",
13
24
  async (config) => {
@@ -17,30 +28,56 @@ export const withMapboxNavPodfile: ConfigPlugin = (config) => {
17
28
  );
18
29
  let contents = fs.readFileSync(podfilePath, "utf8");
19
30
 
31
+ const versionEscaped = navigationSdkVersion.replace(/'/g, "\\\\'");
20
32
  const hook = `
21
- # @baeckerherz/expo-mapbox-navigation: Make SPM frameworks visible to the pod target
33
+ # @baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods + search paths + BUILD_LIBRARY_FOR_DISTRIBUTION
34
+ mapbox_nav_version = '${versionEscaped}'
22
35
  installer.pods_project.targets.each do |target|
23
- if target.name == 'ExpoMapboxNavigation'
24
- target.build_configurations.each do |config|
25
- shared_products = '$(BUILT_PRODUCTS_DIR)/..'
26
- config.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= ['$(inherited)']
27
- config.build_settings['FRAMEWORK_SEARCH_PATHS'] << shared_products
28
- config.build_settings['SWIFT_INCLUDE_PATHS'] ||= ['$(inherited)']
29
- config.build_settings['SWIFT_INCLUDE_PATHS'] << shared_products
36
+ if target.name.start_with?('Mapbox') || target.name == 'Turf'
37
+ target.build_configurations.each do |cfg|
38
+ cfg.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
30
39
  end
31
40
  end
32
- if target.name.start_with?('Mapbox') || target.name == 'Turf'
33
- target.build_configurations.each do |config|
34
- config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
41
+ if target.name == 'ExpoMapboxNavigation'
42
+ target.build_configurations.each do |cfg|
43
+ cfg.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= ['$(inherited)']
44
+ cfg.build_settings['FRAMEWORK_SEARCH_PATHS'] << '$(BUILT_PRODUCTS_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
45
+ cfg.build_settings['FRAMEWORK_SEARCH_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
46
+ cfg.build_settings['SWIFT_INCLUDE_PATHS'] ||= ['$(inherited)']
47
+ cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)'
48
+ cfg.build_settings['SWIFT_INCLUDE_PATHS'] << '$(BUILT_PRODUCTS_DIR)/..'
35
49
  end
36
50
  end
51
+ end
52
+ target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
53
+ if target
54
+ project = installer.pods_project
55
+ root = project.root_object
56
+ pkg_ref = nil
57
+ pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' } if root.package_references
58
+ unless pkg_ref
59
+ pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
60
+ pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
61
+ pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
62
+ root.package_references << pkg_ref
63
+ end
64
+ ${MAPBOX_NAV_PRODUCTS.map(
65
+ (name) => `
66
+ unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
67
+ product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
68
+ product_dep.package = pkg_ref
69
+ product_dep.product_name = '${name}'
70
+ target.package_product_dependencies << product_dep
71
+ build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
72
+ build_file.product_ref = product_dep
73
+ target.frameworks_build_phases.files << build_file
74
+ end`
75
+ ).join("")}
76
+ project.save
37
77
  end`;
38
78
 
39
- if (
40
- !contents.includes(
41
- "@baeckerherz/expo-mapbox-navigation: Make SPM frameworks"
42
- )
43
- ) {
79
+ const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
80
+ if (!contents.includes(marker)) {
44
81
  if (contents.includes("post_install do |installer|")) {
45
82
  contents = contents.replace(
46
83
  "post_install do |installer|",