@baeckerherz/expo-mapbox-navigation 0.1.7 → 0.1.8

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.8",
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,56 @@ 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 + 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
61
- end
62
- end
63
59
  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'
60
+ target.build_configurations.each do |cfg|
61
+ cfg.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
66
62
  end
67
63
  end
64
+ end
65
+ target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
66
+ if target
67
+ project = installer.pods_project
68
+ root = project.root_object
69
+ pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' }
70
+ unless pkg_ref
71
+ pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
72
+ pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
73
+ pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
74
+ root.package_references << pkg_ref
75
+ end
76
+ ${MAPBOX_NAV_PRODUCTS.map((name) => `
77
+ unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
78
+ product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
79
+ product_dep.package = pkg_ref
80
+ product_dep.product_name = '${name}'
81
+ target.package_product_dependencies << product_dep
82
+ build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
83
+ build_file.product_ref = product_dep
84
+ target.frameworks_build_phases.files << build_file
85
+ end`).join("")}
86
+ project.save
68
87
  end`;
69
- if (!contents.includes("@baeckerherz/expo-mapbox-navigation: Make SPM frameworks")) {
88
+ const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
89
+ if (!contents.includes(marker)) {
70
90
  if (contents.includes("post_install do |installer|")) {
71
91
  contents = contents.replace("post_install do |installer|", `post_install do |installer|${hook}`);
72
92
  }
@@ -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,45 @@ 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 + 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
30
- end
31
- end
32
36
  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'
37
+ target.build_configurations.each do |cfg|
38
+ cfg.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES'
35
39
  end
36
40
  end
41
+ end
42
+ target = installer.pods_project.targets.find { |t| t.name == 'ExpoMapboxNavigation' }
43
+ if target
44
+ project = installer.pods_project
45
+ root = project.root_object
46
+ pkg_ref = root.package_references.find { |r| r.respond_to?(:repositoryURL) && r.repositoryURL == '${MAPBOX_NAV_URL}' }
47
+ unless pkg_ref
48
+ pkg_ref = project.new(Xcodeproj::Project::Object::XCRemoteSwiftPackageReference)
49
+ pkg_ref.repositoryURL = '${MAPBOX_NAV_URL}'
50
+ pkg_ref.requirement = { 'kind' => 'exactVersion', 'version' => mapbox_nav_version }
51
+ root.package_references << pkg_ref
52
+ end
53
+ ${MAPBOX_NAV_PRODUCTS.map(
54
+ (name) => `
55
+ unless target.package_product_dependencies.any? { |d| d.product_name == '${name}' }
56
+ product_dep = project.new(Xcodeproj::Project::Object::XCSwiftPackageProductDependency)
57
+ product_dep.package = pkg_ref
58
+ product_dep.product_name = '${name}'
59
+ target.package_product_dependencies << product_dep
60
+ build_file = project.new(Xcodeproj::Project::Object::PBXBuildFile)
61
+ build_file.product_ref = product_dep
62
+ target.frameworks_build_phases.files << build_file
63
+ end`
64
+ ).join("")}
65
+ project.save
37
66
  end`;
38
67
 
39
- if (
40
- !contents.includes(
41
- "@baeckerherz/expo-mapbox-navigation: Make SPM frameworks"
42
- )
43
- ) {
68
+ const marker = "@baeckerherz/expo-mapbox-navigation: Mapbox SPM in Pods";
69
+ if (!contents.includes(marker)) {
44
70
  if (contents.includes("post_install do |installer|")) {
45
71
  contents = contents.replace(
46
72
  "post_install do |installer|",