expo-modules-autolinking 0.3.4 → 0.5.2
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/CHANGELOG.md +46 -0
- package/build/ExpoModuleConfig.d.ts +16 -0
- package/build/ExpoModuleConfig.js +28 -0
- package/build/ExpoModuleConfig.js.map +1 -1
- package/build/ReactImportsPatcher.d.ts +14 -0
- package/build/ReactImportsPatcher.js +72 -0
- package/build/ReactImportsPatcher.js.map +1 -0
- package/build/autolinking.js +8 -7
- package/build/autolinking.js.map +1 -1
- package/build/index.js +17 -6
- package/build/index.js.map +1 -1
- package/build/platforms/android.js +22 -3
- package/build/platforms/android.js.map +1 -1
- package/build/platforms/ios.d.ts +4 -0
- package/build/platforms/ios.js +59 -11
- package/build/platforms/ios.js.map +1 -1
- package/build/types.d.ts +26 -0
- package/build/types.js.map +1 -1
- package/package.json +3 -3
- package/scripts/android/autolinking_implementation.gradle +4 -1
- package/scripts/ios/React-Core.modulemap +6 -0
- package/scripts/ios/autolinking_manager.rb +1 -0
- package/scripts/ios/cocoapods/sandbox.rb +75 -0
- package/scripts/ios/react_import_patcher.rb +72 -0
- package/src/ExpoModuleConfig.ts +28 -0
- package/src/ReactImportsPatcher.ts +78 -0
- package/src/autolinking.ts +8 -4
- package/src/index.ts +13 -0
- package/src/platforms/android.ts +22 -2
- package/src/platforms/ios.ts +68 -10
- package/src/types.ts +31 -0
- package/tsconfig.json +2 -1
package/src/platforms/ios.ts
CHANGED
|
@@ -4,6 +4,19 @@ import path from 'path';
|
|
|
4
4
|
|
|
5
5
|
import { ModuleDescriptor, PackageRevision, SearchOptions } from '../types';
|
|
6
6
|
|
|
7
|
+
async function findPodspecFile(revision: PackageRevision): Promise<string | undefined> {
|
|
8
|
+
if (revision.config?.iosPodspecPath()) {
|
|
9
|
+
return revision.config.iosPodspecPath();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const [podspecFile] = await glob('*/*.podspec', {
|
|
13
|
+
cwd: revision.path,
|
|
14
|
+
ignore: ['**/node_modules/**'],
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return podspecFile;
|
|
18
|
+
}
|
|
19
|
+
|
|
7
20
|
/**
|
|
8
21
|
* Resolves module search result with additional details required for iOS platform.
|
|
9
22
|
*/
|
|
@@ -12,11 +25,7 @@ export async function resolveModuleAsync(
|
|
|
12
25
|
revision: PackageRevision,
|
|
13
26
|
options: SearchOptions
|
|
14
27
|
): Promise<ModuleDescriptor | null> {
|
|
15
|
-
const
|
|
16
|
-
cwd: revision.path,
|
|
17
|
-
ignore: ['**/node_modules/**'],
|
|
18
|
-
});
|
|
19
|
-
|
|
28
|
+
const podspecFile = await findPodspecFile(revision);
|
|
20
29
|
if (!podspecFile) {
|
|
21
30
|
return null;
|
|
22
31
|
}
|
|
@@ -29,6 +38,8 @@ export async function resolveModuleAsync(
|
|
|
29
38
|
podspecDir,
|
|
30
39
|
flags: options.flags,
|
|
31
40
|
modulesClassNames: revision.config?.iosModulesClassNames(),
|
|
41
|
+
appDelegateSubscribers: revision.config?.iosAppDelegateSubscribers(),
|
|
42
|
+
reactDelegateHandlers: revision.config?.iosReactDelegateHandlers(),
|
|
32
43
|
};
|
|
33
44
|
}
|
|
34
45
|
|
|
@@ -52,9 +63,25 @@ async function generatePackageListFileContentAsync(
|
|
|
52
63
|
modules: ModuleDescriptor[],
|
|
53
64
|
className: string
|
|
54
65
|
): Promise<string> {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
66
|
+
const modulesToImport = modules.filter(
|
|
67
|
+
(module) =>
|
|
68
|
+
module.modulesClassNames.length ||
|
|
69
|
+
module.appDelegateSubscribers.length ||
|
|
70
|
+
module.reactDelegateHandlers.length
|
|
71
|
+
);
|
|
72
|
+
const pods = modulesToImport.map((module) => module.podName);
|
|
73
|
+
|
|
74
|
+
const modulesClassNames = []
|
|
75
|
+
.concat(...modulesToImport.map((module) => module.modulesClassNames))
|
|
76
|
+
.filter(Boolean);
|
|
77
|
+
|
|
78
|
+
const appDelegateSubscribers = []
|
|
79
|
+
.concat(...modulesToImport.map((module) => module.appDelegateSubscribers))
|
|
80
|
+
.filter(Boolean);
|
|
81
|
+
|
|
82
|
+
const reactDelegateHandlerModules = modulesToImport.filter(
|
|
83
|
+
(module) => !!module.reactDelegateHandlers.length
|
|
84
|
+
);
|
|
58
85
|
|
|
59
86
|
return `/**
|
|
60
87
|
* Automatically generated by expo-modules-autolinking.
|
|
@@ -68,9 +95,40 @@ ${pods.map((podName) => `import ${podName}\n`).join('')}
|
|
|
68
95
|
@objc(${className})
|
|
69
96
|
public class ${className}: ModulesProvider {
|
|
70
97
|
public override func getModuleClasses() -> [AnyModule.Type] {
|
|
71
|
-
return
|
|
72
|
-
|
|
98
|
+
return ${formatArrayOfClassNames(modulesClassNames)}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public override func getAppDelegateSubscribers() -> [ExpoAppDelegateSubscriber.Type] {
|
|
102
|
+
return ${formatArrayOfClassNames(appDelegateSubscribers)}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
public override func getReactDelegateHandlers() -> [ExpoReactDelegateHandlerTupleType] {
|
|
106
|
+
return ${formatArrayOfReactDelegateHandler(reactDelegateHandlerModules)}
|
|
73
107
|
}
|
|
74
108
|
}
|
|
75
109
|
`;
|
|
76
110
|
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Formats an array of class names to Swift's array containing these classes.
|
|
114
|
+
*/
|
|
115
|
+
function formatArrayOfClassNames(classNames: string[]): string {
|
|
116
|
+
const indent = ' ';
|
|
117
|
+
return `[${classNames.map((className) => `\n${indent.repeat(3)}${className}.self`).join(',')}
|
|
118
|
+
${indent.repeat(2)}]`;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Formats an array of modules to Swift's array containing ReactDelegateHandlers
|
|
123
|
+
*/
|
|
124
|
+
export function formatArrayOfReactDelegateHandler(modules: ModuleDescriptor[]): string {
|
|
125
|
+
const values: string[] = [];
|
|
126
|
+
for (const module of modules) {
|
|
127
|
+
for (const handler of module.reactDelegateHandlers) {
|
|
128
|
+
values.push(`(packageName: "${module.packageName}", handler: ${handler}.self)`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const indent = ' ';
|
|
132
|
+
return `[${values.map((value) => `\n${indent.repeat(3)}${value}`).join(',')}
|
|
133
|
+
${indent.repeat(2)}]`;
|
|
134
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -8,6 +8,7 @@ export interface SearchOptions {
|
|
|
8
8
|
ignorePaths?: string[] | null;
|
|
9
9
|
exclude?: string[] | null;
|
|
10
10
|
platform: SupportedPlatform;
|
|
11
|
+
silent?: boolean;
|
|
11
12
|
|
|
12
13
|
// Scratched from project's config
|
|
13
14
|
flags?: Record<string, any>;
|
|
@@ -23,6 +24,11 @@ export interface GenerateOptions extends ResolveOptions {
|
|
|
23
24
|
empty?: boolean;
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
export interface PatchReactImportsOptions {
|
|
28
|
+
podsRoot: string;
|
|
29
|
+
dryRun: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
26
32
|
export type PackageRevision = {
|
|
27
33
|
path: string;
|
|
28
34
|
version: string;
|
|
@@ -53,5 +59,30 @@ export interface RawExpoModuleConfig {
|
|
|
53
59
|
* Names of Swift native modules classes to put to the generated modules provider file.
|
|
54
60
|
*/
|
|
55
61
|
modulesClassNames?: string[];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.
|
|
65
|
+
*/
|
|
66
|
+
appDelegateSubscribers?: string[];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Names of Swift classes that implement `ExpoReactDelegateHandler` to hook React instance creation.
|
|
70
|
+
*/
|
|
71
|
+
reactDelegateHandlers?: string[];
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Podspec relative path.
|
|
75
|
+
*/
|
|
76
|
+
podspecPath?: string;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Android-specific config.
|
|
81
|
+
*/
|
|
82
|
+
android?: {
|
|
83
|
+
/**
|
|
84
|
+
* Full names (package + class name) of Kotlin native modules classes to put to the generated package provider file.
|
|
85
|
+
*/
|
|
86
|
+
modulesClassNames?: string[];
|
|
56
87
|
};
|
|
57
88
|
}
|