expo-modules-autolinking 0.3.3 → 0.5.1
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 +40 -0
- package/README.md +1 -1
- package/build/ExpoModuleConfig.d.ts +16 -0
- package/build/ExpoModuleConfig.js +28 -0
- package/build/ExpoModuleConfig.js.map +1 -1
- package/build/autolinking.js +8 -7
- package/build/autolinking.js.map +1 -1
- package/build/index.js +7 -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 +22 -0
- package/build/types.js.map +1 -1
- package/package.json +3 -3
- package/scripts/android/autolinking_implementation.gradle +8 -5
- 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/src/ExpoModuleConfig.ts +28 -0
- package/src/autolinking.ts +8 -4
- package/src/index.ts +1 -0
- package/src/platforms/android.ts +22 -2
- package/src/platforms/ios.ts +68 -10
- package/src/types.ts +26 -0
- package/tsconfig.json +2 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unpublished
|
|
4
|
+
|
|
5
|
+
### 🛠 Breaking changes
|
|
6
|
+
|
|
7
|
+
### 🎉 New features
|
|
8
|
+
|
|
9
|
+
### 🐛 Bug fixes
|
|
10
|
+
|
|
11
|
+
### 💡 Others
|
|
12
|
+
|
|
13
|
+
## 0.5.1 — 2021-12-15
|
|
14
|
+
|
|
15
|
+
_This version does not introduce any user-facing changes._
|
|
16
|
+
|
|
17
|
+
## 0.5.0 — 2021-12-03
|
|
18
|
+
|
|
19
|
+
### 🎉 New features
|
|
20
|
+
|
|
21
|
+
- Patch React podspecs on the fly to support Swift integration. ([#15299](https://github.com/expo/expo/pull/15299) by [@kudo](https://github.com/kudo))
|
|
22
|
+
|
|
23
|
+
## 0.4.0 — 2021-11-17
|
|
24
|
+
|
|
25
|
+
### 🎉 New features
|
|
26
|
+
|
|
27
|
+
- Added "silent" property for silencing resolution warnings. ([#14891](https://github.com/expo/expo/pull/14891) by [@EvanBacon](https://github.com/EvanBacon))
|
|
28
|
+
- Listing module's app delegate subscribers in the generated `ExpoModulesProvider.swift`. ([#14867](https://github.com/expo/expo/pull/14867) by [@tsapeta](https://github.com/tsapeta))
|
|
29
|
+
- Search for Android package in the entire source code other than just `src` directory. ([#14883](https://github.com/expo/expo/pull/14883) by [@kudo](https://github.com/kudo))
|
|
30
|
+
- Introduce React Native bridge delegate handlers on iOS. ([#15138](https://github.com/expo/expo/pull/15138) by [@kudo](https://github.com/kudo))
|
|
31
|
+
|
|
32
|
+
### 🐛 Bug fixes
|
|
33
|
+
|
|
34
|
+
- Fix Gradle error when running Gradle from outside of the project directory. ([#15109](https://github.com/expo/expo/pull/15109) by [@kudo](https://github.com/kudo))
|
|
35
|
+
|
|
36
|
+
## 0.3.3 — 2021-10-21
|
|
37
|
+
|
|
38
|
+
### 🐛 Bug fixes
|
|
39
|
+
|
|
40
|
+
- Resolved race condition when generating `ExpoModulesProvider.swift`. ([#14822](https://github.com/expo/expo/pull/14822) by [@awinograd](https://github.com/awinograd))
|
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ For managed [managed](https://docs.expo.io/versions/latest/introduction/managed-
|
|
|
13
13
|
|
|
14
14
|
# Installation in bare React Native projects
|
|
15
15
|
|
|
16
|
-
For bare React Native projects, you must ensure that you have [installed and configured the `
|
|
16
|
+
For bare React Native projects, you must ensure that you have [installed and configured the `expo` package](https://docs.expo.dev/bare/installing-expo-modules/) before continuing.
|
|
17
17
|
|
|
18
18
|
### Add the package to your npm dependencies
|
|
19
19
|
|
|
@@ -13,6 +13,22 @@ export declare class ExpoModuleConfig {
|
|
|
13
13
|
* Returns a list of names of Swift native modules classes to put to the generated modules provider file.
|
|
14
14
|
*/
|
|
15
15
|
iosModulesClassNames(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Returns a list of names of Swift classes that receives AppDelegate life-cycle events.
|
|
18
|
+
*/
|
|
19
|
+
iosAppDelegateSubscribers(): string[];
|
|
20
|
+
/**
|
|
21
|
+
* Returns a list of names of Swift classes that implement `ExpoReactDelegateHandler`.
|
|
22
|
+
*/
|
|
23
|
+
iosReactDelegateHandlers(): string[];
|
|
24
|
+
/**
|
|
25
|
+
* Returns a podspec path defined by the module author.
|
|
26
|
+
*/
|
|
27
|
+
iosPodspecPath(): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Returns a list of names of Kotlin native modules classes to put to the generated package provider file.
|
|
30
|
+
*/
|
|
31
|
+
androidModulesClassNames(): string[];
|
|
16
32
|
/**
|
|
17
33
|
* Returns serializable raw config.
|
|
18
34
|
*/
|
|
@@ -22,6 +22,34 @@ class ExpoModuleConfig {
|
|
|
22
22
|
var _a, _b;
|
|
23
23
|
return (_b = (_a = this.rawConfig.ios) === null || _a === void 0 ? void 0 : _a.modulesClassNames) !== null && _b !== void 0 ? _b : [];
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns a list of names of Swift classes that receives AppDelegate life-cycle events.
|
|
27
|
+
*/
|
|
28
|
+
iosAppDelegateSubscribers() {
|
|
29
|
+
var _a, _b;
|
|
30
|
+
return (_b = (_a = this.rawConfig.ios) === null || _a === void 0 ? void 0 : _a.appDelegateSubscribers) !== null && _b !== void 0 ? _b : [];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns a list of names of Swift classes that implement `ExpoReactDelegateHandler`.
|
|
34
|
+
*/
|
|
35
|
+
iosReactDelegateHandlers() {
|
|
36
|
+
var _a, _b;
|
|
37
|
+
return (_b = (_a = this.rawConfig.ios) === null || _a === void 0 ? void 0 : _a.reactDelegateHandlers) !== null && _b !== void 0 ? _b : [];
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns a podspec path defined by the module author.
|
|
41
|
+
*/
|
|
42
|
+
iosPodspecPath() {
|
|
43
|
+
var _a;
|
|
44
|
+
return (_a = this.rawConfig.ios) === null || _a === void 0 ? void 0 : _a.podspecPath;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns a list of names of Kotlin native modules classes to put to the generated package provider file.
|
|
48
|
+
*/
|
|
49
|
+
androidModulesClassNames() {
|
|
50
|
+
var _a, _b;
|
|
51
|
+
return (_b = (_a = this.rawConfig.android) === null || _a === void 0 ? void 0 : _a.modulesClassNames) !== null && _b !== void 0 ? _b : [];
|
|
52
|
+
}
|
|
25
53
|
/**
|
|
26
54
|
* Returns serializable raw config.
|
|
27
55
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoModuleConfig.js","sourceRoot":"","sources":["../src/ExpoModuleConfig.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,gBAAgB;IAC3B,YAAqB,SAA8B;QAA9B,cAAS,GAAT,SAAS,CAAqB;IAAG,CAAC;IAEvD;;OAEG;IACH,gBAAgB,CAAC,QAA2B;;QAC1C,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,SAAS,0CAAE,QAAQ,CAAC,QAAQ,CAAC,mCAAI,KAAK,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,oBAAoB;;QAClB,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,0CAAE,iBAAiB,mCAAI,EAAE,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;
|
|
1
|
+
{"version":3,"file":"ExpoModuleConfig.js","sourceRoot":"","sources":["../src/ExpoModuleConfig.ts"],"names":[],"mappings":";;;AAEA;;GAEG;AACH,MAAa,gBAAgB;IAC3B,YAAqB,SAA8B;QAA9B,cAAS,GAAT,SAAS,CAAqB;IAAG,CAAC;IAEvD;;OAEG;IACH,gBAAgB,CAAC,QAA2B;;QAC1C,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,SAAS,0CAAE,QAAQ,CAAC,QAAQ,CAAC,mCAAI,KAAK,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,oBAAoB;;QAClB,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,0CAAE,iBAAiB,mCAAI,EAAE,CAAC;IACrD,CAAC;IAED;;OAEG;IACH,yBAAyB;;QACvB,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,0CAAE,sBAAsB,mCAAI,EAAE,CAAC;IAC1D,CAAC;IAED;;OAEG;IACH,wBAAwB;;QACtB,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,0CAAE,qBAAqB,mCAAI,EAAE,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,cAAc;;QACZ,OAAO,MAAA,IAAI,CAAC,SAAS,CAAC,GAAG,0CAAE,WAAW,CAAC;IACzC,CAAC;IAED;;OAEG;IACH,wBAAwB;;QACtB,OAAO,MAAA,MAAA,IAAI,CAAC,SAAS,CAAC,OAAO,0CAAE,iBAAiB,mCAAI,EAAE,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AAnDD,4CAmDC;AAED;;GAEG;AACH,SAAgB,iCAAiC,CAAC,IAAY;IAC5D,kDAAkD;IAClD,4DAA4D;IAC5D,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAwB,CAAC,CAAC;AACpE,CAAC;AAJD,8EAIC","sourcesContent":["import { RawExpoModuleConfig, SupportedPlatform } from './types';\n\n/**\n * A class that wraps the raw config (`expo-module.json` or `unimodule.json`).\n */\nexport class ExpoModuleConfig {\n constructor(readonly rawConfig: RawExpoModuleConfig) {}\n\n /**\n * Whether the module supports given platform.\n */\n supportsPlatform(platform: SupportedPlatform): boolean {\n return this.rawConfig.platforms?.includes(platform) ?? false;\n }\n\n /**\n * Returns a list of names of Swift native modules classes to put to the generated modules provider file.\n */\n iosModulesClassNames() {\n return this.rawConfig.ios?.modulesClassNames ?? [];\n }\n\n /**\n * Returns a list of names of Swift classes that receives AppDelegate life-cycle events.\n */\n iosAppDelegateSubscribers(): string[] {\n return this.rawConfig.ios?.appDelegateSubscribers ?? [];\n }\n\n /**\n * Returns a list of names of Swift classes that implement `ExpoReactDelegateHandler`.\n */\n iosReactDelegateHandlers(): string[] {\n return this.rawConfig.ios?.reactDelegateHandlers ?? [];\n }\n\n /**\n * Returns a podspec path defined by the module author.\n */\n iosPodspecPath(): string | undefined {\n return this.rawConfig.ios?.podspecPath;\n }\n\n /**\n * Returns a list of names of Kotlin native modules classes to put to the generated package provider file.\n */\n androidModulesClassNames() {\n return this.rawConfig.android?.modulesClassNames ?? [];\n }\n\n /**\n * Returns serializable raw config.\n */\n toJSON(): RawExpoModuleConfig {\n return this.rawConfig;\n }\n}\n\n/**\n * Reads the config at given path and returns the config wrapped by `ExpoModuleConfig` class.\n */\nexport function requireAndResolveExpoModuleConfig(path: string): ExpoModuleConfig {\n // TODO: Validate the raw config against a schema.\n // TODO: Support for `*.js` files, not only static `*.json`.\n return new ExpoModuleConfig(require(path) as RawExpoModuleConfig);\n}\n"]}
|
package/build/autolinking.js
CHANGED
|
@@ -25,7 +25,7 @@ if (!projectPackageJsonPath) {
|
|
|
25
25
|
* Custom `require` that resolves from the current working dir instead of this script path.
|
|
26
26
|
* **Requires Node v12.2.0**
|
|
27
27
|
*/
|
|
28
|
-
const projectRequire = module_1.createRequire(projectPackageJsonPath);
|
|
28
|
+
const projectRequire = (0, module_1.createRequire)(projectPackageJsonPath);
|
|
29
29
|
/**
|
|
30
30
|
* Resolves autolinking search paths. If none is provided, it accumulates all node_modules when
|
|
31
31
|
* going up through the path components. This makes workspaces work out-of-the-box without any configs.
|
|
@@ -43,7 +43,7 @@ async function findDefaultPathsAsync(cwd) {
|
|
|
43
43
|
const paths = [];
|
|
44
44
|
let dir = cwd;
|
|
45
45
|
let pkgJsonPath;
|
|
46
|
-
while ((pkgJsonPath = await find_up_1.default('package.json', { cwd: dir }))) {
|
|
46
|
+
while ((pkgJsonPath = await (0, find_up_1.default)('package.json', { cwd: dir }))) {
|
|
47
47
|
dir = path_1.default.dirname(path_1.default.dirname(pkgJsonPath));
|
|
48
48
|
paths.push(path_1.default.join(pkgJsonPath, '..', 'node_modules'));
|
|
49
49
|
}
|
|
@@ -59,7 +59,7 @@ async function findModulesAsync(providedOptions) {
|
|
|
59
59
|
const results = {};
|
|
60
60
|
for (const searchPath of options.searchPaths) {
|
|
61
61
|
const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';
|
|
62
|
-
const paths = await fast_glob_1.default([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`], {
|
|
62
|
+
const paths = await (0, fast_glob_1.default)([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`], {
|
|
63
63
|
cwd: searchPath,
|
|
64
64
|
});
|
|
65
65
|
// If the package has multiple configs (e.g. `unimodule.json` and `expo-module.config.json` during the transition time)
|
|
@@ -73,7 +73,7 @@ async function findModulesAsync(providedOptions) {
|
|
|
73
73
|
}, {}));
|
|
74
74
|
for (const packageConfigPath of uniqueConfigPaths) {
|
|
75
75
|
const packagePath = await fs_extra_1.default.realpath(path_1.default.join(searchPath, path_1.default.dirname(packageConfigPath)));
|
|
76
|
-
const expoModuleConfig = ExpoModuleConfig_1.requireAndResolveExpoModuleConfig(path_1.default.join(packagePath, path_1.default.basename(packageConfigPath)));
|
|
76
|
+
const expoModuleConfig = (0, ExpoModuleConfig_1.requireAndResolveExpoModuleConfig)(path_1.default.join(packagePath, path_1.default.basename(packageConfigPath)));
|
|
77
77
|
const { name, version } = require(path_1.default.join(packagePath, 'package.json'));
|
|
78
78
|
if (((_a = options.exclude) === null || _a === void 0 ? void 0 : _a.includes(name)) || !expoModuleConfig.supportsPlatform(options.platform)) {
|
|
79
79
|
continue;
|
|
@@ -103,13 +103,13 @@ async function findModulesAsync(providedOptions) {
|
|
|
103
103
|
if (options.searchPaths.length <= 1) {
|
|
104
104
|
return results;
|
|
105
105
|
}
|
|
106
|
-
return filterToProjectDependencies(results);
|
|
106
|
+
return filterToProjectDependencies(results, providedOptions);
|
|
107
107
|
}
|
|
108
108
|
exports.findModulesAsync = findModulesAsync;
|
|
109
109
|
/**
|
|
110
110
|
* Filters out packages that are not the dependencies of the project.
|
|
111
111
|
*/
|
|
112
|
-
function filterToProjectDependencies(results) {
|
|
112
|
+
function filterToProjectDependencies(results, options = {}) {
|
|
113
113
|
const filteredResults = {};
|
|
114
114
|
const visitedPackages = new Set();
|
|
115
115
|
// Helper for traversing the dependency hierarchy.
|
|
@@ -137,7 +137,7 @@ function filterToProjectDependencies(results) {
|
|
|
137
137
|
// Some packages don't include package.json in its `exports` field,
|
|
138
138
|
// but none of our packages do that, so it seems fine to just ignore that type of error.
|
|
139
139
|
// Related issue: https://github.com/react-native-community/cli/issues/1168
|
|
140
|
-
if (error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
140
|
+
if (!options.silent && error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
141
141
|
console.warn(chalk_1.default.yellow(`⚠️ Cannot resolve the path to "${dependencyName}" package.`));
|
|
142
142
|
}
|
|
143
143
|
continue;
|
|
@@ -224,6 +224,7 @@ async function generatePackageListAsync(modules, options) {
|
|
|
224
224
|
}
|
|
225
225
|
catch (e) {
|
|
226
226
|
console.error(chalk_1.default.red(`Generating package list is not available for platform: ${options.platform}`));
|
|
227
|
+
throw e;
|
|
227
228
|
}
|
|
228
229
|
}
|
|
229
230
|
exports.generatePackageListAsync = generatePackageListAsync;
|
package/build/autolinking.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autolinking.js","sourceRoot":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,CAAC,CAAC;AAChE,CAAC;AA1BD,kDA0BC;AAED;;;GAGG;AACI,KAAK,UAAU,wBAAwB,CAC5C,OAA2B,EAC3B,OAAwB;IAExB,IAAI;QACF,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;QACnE,MAAM,eAAe,CAAC,wBAAwB,CAAC,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC;KAC5F;IAAC,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,KAAK,CACX,eAAK,CAAC,GAAG,CAAC,0DAA0D,OAAO,CAAC,QAAQ,EAAE,CAAC,CACxF,CAAC;KACH;AACH,CAAC;AAZD,4DAYC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,QAAgB;IACtC,OAAO,4BAA4B,CAAC,OAAO,CAAC,cAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import chalk from 'chalk';\nimport glob from 'fast-glob';\nimport findUp from 'find-up';\nimport fs from 'fs-extra';\nimport { createRequire } from 'module';\nimport path from 'path';\n\nimport { requireAndResolveExpoModuleConfig } from './ExpoModuleConfig';\nimport {\n GenerateOptions,\n ModuleDescriptor,\n PackageRevision,\n ResolveOptions,\n SearchOptions,\n SearchResults,\n} from './types';\n\n// Names of the config files. From lowest to highest priority.\nconst EXPO_MODULE_CONFIG_FILENAMES = ['unimodule.json', 'expo-module.config.json'];\n\n/**\n * Path to the `package.json` of the closest project in the current working dir.\n */\nconst projectPackageJsonPath = findUp.sync('package.json', { cwd: process.cwd() }) as string;\n\n// This won't happen in usual scenarios, but we need to unwrap the optional path :)\nif (!projectPackageJsonPath) {\n throw new Error(`Couldn't find \"package.json\" up from path \"${process.cwd()}\"`);\n}\n\n/**\n * Custom `require` that resolves from the current working dir instead of this script path.\n * **Requires Node v12.2.0**\n */\nconst projectRequire = createRequire(projectPackageJsonPath);\n\n/**\n * Resolves autolinking search paths. If none is provided, it accumulates all node_modules when\n * going up through the path components. This makes workspaces work out-of-the-box without any configs.\n */\nexport async function resolveSearchPathsAsync(\n searchPaths: string[] | null,\n cwd: string\n): Promise<string[]> {\n return searchPaths && searchPaths.length > 0\n ? searchPaths.map((searchPath) => path.resolve(cwd, searchPath))\n : await findDefaultPathsAsync(cwd);\n}\n\n/**\n * Looks up for workspace's `node_modules` paths.\n */\nexport async function findDefaultPathsAsync(cwd: string): Promise<string[]> {\n const paths = [];\n let dir = cwd;\n let pkgJsonPath: string | undefined;\n\n while ((pkgJsonPath = await findUp('package.json', { cwd: dir }))) {\n dir = path.dirname(path.dirname(pkgJsonPath));\n paths.push(path.join(pkgJsonPath, '..', 'node_modules'));\n }\n return paths;\n}\n\n/**\n * Searches for modules to link based on given config.\n */\nexport async function findModulesAsync(providedOptions: SearchOptions): Promise<SearchResults> {\n const options = await mergeLinkingOptionsAsync(providedOptions);\n const results: SearchResults = {};\n\n for (const searchPath of options.searchPaths) {\n const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';\n const paths = await glob([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`], {\n cwd: searchPath,\n });\n\n // If the package has multiple configs (e.g. `unimodule.json` and `expo-module.config.json` during the transition time)\n // then we want to give `expo-module.config.json` the priority.\n const uniqueConfigPaths: string[] = Object.values(\n paths.reduce<Record<string, string>>((acc, configPath) => {\n const dirname = path.dirname(configPath);\n\n if (!acc[dirname] || configPriority(configPath) > configPriority(acc[dirname])) {\n acc[dirname] = configPath;\n }\n return acc;\n }, {})\n );\n\n for (const packageConfigPath of uniqueConfigPaths) {\n const packagePath = await fs.realpath(path.join(searchPath, path.dirname(packageConfigPath)));\n const expoModuleConfig = requireAndResolveExpoModuleConfig(\n path.join(packagePath, path.basename(packageConfigPath))\n );\n const { name, version } = require(path.join(packagePath, 'package.json'));\n\n if (options.exclude?.includes(name) || !expoModuleConfig.supportsPlatform(options.platform)) {\n continue;\n }\n\n const currentRevision: PackageRevision = {\n path: packagePath,\n version,\n };\n\n if (!results[name]) {\n // The revision that was found first will be the main one.\n // An array of duplicates and the config are needed only here.\n results[name] = {\n ...currentRevision,\n config: expoModuleConfig,\n duplicates: [],\n };\n } else if (\n results[name].path !== packagePath &&\n results[name].duplicates?.every(({ path }) => path !== packagePath)\n ) {\n results[name].duplicates?.push(currentRevision);\n }\n }\n }\n\n // It doesn't make much sense to strip modules if there is only one search path.\n // Workspace root usually doesn't specify all its dependencies (see Expo Go),\n // so in this case we should link everything.\n if (options.searchPaths.length <= 1) {\n return results;\n }\n return filterToProjectDependencies(results);\n}\n\n/**\n * Filters out packages that are not the dependencies of the project.\n */\nfunction filterToProjectDependencies(results: SearchResults) {\n const filteredResults: SearchResults = {};\n const visitedPackages = new Set<string>();\n\n // Helper for traversing the dependency hierarchy.\n function visitPackage(packageJsonPath: string) {\n const packageJson = require(packageJsonPath);\n\n // Prevent getting into the recursive loop.\n if (visitedPackages.has(packageJson.name)) {\n return;\n }\n visitedPackages.add(packageJson.name);\n\n // Iterate over the dependencies to find transitive modules.\n for (const dependencyName in packageJson.dependencies) {\n const dependencyResult = results[dependencyName];\n\n if (!filteredResults[dependencyName]) {\n let dependencyPackageJsonPath: string;\n\n if (dependencyResult) {\n filteredResults[dependencyName] = dependencyResult;\n dependencyPackageJsonPath = path.join(dependencyResult.path, 'package.json');\n } else {\n try {\n dependencyPackageJsonPath = projectRequire.resolve(`${dependencyName}/package.json`);\n } catch (error) {\n // Some packages don't include package.json in its `exports` field,\n // but none of our packages do that, so it seems fine to just ignore that type of error.\n // Related issue: https://github.com/react-native-community/cli/issues/1168\n if (error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {\n console.warn(\n chalk.yellow(`⚠️ Cannot resolve the path to \"${dependencyName}\" package.`)\n );\n }\n continue;\n }\n }\n\n // Visit the dependency package.\n visitPackage(dependencyPackageJsonPath);\n }\n }\n }\n\n // Visit project's package.\n visitPackage(projectPackageJsonPath);\n\n return filteredResults;\n}\n\n/**\n * Merges autolinking options from different sources (the later the higher priority)\n * - options defined in package.json's `expoModules` field\n * - platform-specific options from the above (e.g. `expoModules.ios`)\n * - options provided to the CLI command\n */\nexport async function mergeLinkingOptionsAsync<OptionsType extends SearchOptions>(\n providedOptions: OptionsType\n): Promise<OptionsType> {\n const packageJson = require(projectPackageJsonPath);\n const baseOptions = packageJson.expo?.autolinking;\n const platformOptions = providedOptions.platform && baseOptions?.[providedOptions.platform];\n const finalOptions = Object.assign(\n {},\n baseOptions,\n platformOptions,\n providedOptions\n ) as OptionsType;\n\n // Makes provided paths absolute or falls back to default paths if none was provided.\n finalOptions.searchPaths = await resolveSearchPathsAsync(finalOptions.searchPaths, process.cwd());\n\n return finalOptions;\n}\n\n/**\n * Verifies the search results by checking whether there are no duplicates.\n */\nexport function verifySearchResults(searchResults: SearchResults): number {\n const cwd = process.cwd();\n const relativePath: (pkg: PackageRevision) => string = (pkg) => path.relative(cwd, pkg.path);\n let counter = 0;\n\n for (const moduleName in searchResults) {\n const revision = searchResults[moduleName];\n\n if (revision.duplicates?.length) {\n console.warn(`⚠️ Found multiple revisions of ${chalk.green(moduleName)}`);\n console.log(` - ${chalk.magenta(relativePath(revision))} (${chalk.cyan(revision.version)})`);\n\n for (const duplicate of revision.duplicates) {\n console.log(` - ${chalk.gray(relativePath(duplicate))} (${chalk.gray(duplicate.version)})`);\n }\n counter++;\n }\n }\n if (counter > 0) {\n console.warn(\n '⚠️ Please get rid of multiple revisions as it may introduce some side effects or compatibility issues'\n );\n }\n return counter;\n}\n\n/**\n * Resolves search results to a list of platform-specific configuration.\n */\nexport async function resolveModulesAsync(\n searchResults: SearchResults,\n options: ResolveOptions\n): Promise<ModuleDescriptor[]> {\n const platformLinking = require(`./platforms/${options.platform}`);\n\n return (\n await Promise.all(\n Object.entries(searchResults).map(async ([packageName, revision]) => {\n const resolvedModule = await platformLinking.resolveModuleAsync(\n packageName,\n revision,\n options\n );\n return resolvedModule\n ? {\n packageName,\n packageVersion: revision.version,\n ...resolvedModule,\n }\n : null;\n })\n )\n )\n .filter(Boolean)\n .sort((a, b) => a.packageName.localeCompare(b.packageName));\n}\n\n/**\n * Generates a source file listing all packages to link.\n * Right know it works only for Android platform.\n */\nexport async function generatePackageListAsync(\n modules: ModuleDescriptor[],\n options: GenerateOptions\n) {\n try {\n const platformLinking = require(`./platforms/${options.platform}`);\n await platformLinking.generatePackageListAsync(modules, options.target, options.namespace);\n } catch (e) {\n console.error(\n chalk.red(`Generating package list is not available for platform: ${options.platform}`)\n );\n }\n}\n\n/**\n * Returns the priority of the config at given path. Higher number means higher priority.\n */\nfunction configPriority(fullpath: string): number {\n return EXPO_MODULE_CONFIG_FILENAMES.indexOf(path.basename(fullpath));\n}\n"]}
|
|
1
|
+
{"version":3,"file":"autolinking.js","sourceRoot":"","sources":["../src/autolinking.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,0DAA6B;AAC7B,sDAA6B;AAC7B,wDAA0B;AAC1B,mCAAuC;AACvC,gDAAwB;AAExB,yDAAuE;AAUvE,8DAA8D;AAC9D,MAAM,4BAA4B,GAAG,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,CAAC;AAEnF;;GAEG;AACH,MAAM,sBAAsB,GAAG,iBAAM,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAW,CAAC;AAE7F,mFAAmF;AACnF,IAAI,CAAC,sBAAsB,EAAE;IAC3B,MAAM,IAAI,KAAK,CAAC,8CAA8C,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CACjF;AAED;;;GAGG;AACH,MAAM,cAAc,GAAG,IAAA,sBAAa,EAAC,sBAAsB,CAAC,CAAC;AAE7D;;;GAGG;AACI,KAAK,UAAU,uBAAuB,CAC3C,WAA4B,EAC5B,GAAW;IAEX,OAAO,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAC1C,CAAC,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AAC","sourcesContent":["import chalk from 'chalk';\nimport glob from 'fast-glob';\nimport findUp from 'find-up';\nimport fs from 'fs-extra';\nimport { createRequire } from 'module';\nimport path from 'path';\n\nimport { requireAndResolveExpoModuleConfig } from './ExpoModuleConfig';\nimport {\n GenerateOptions,\n ModuleDescriptor,\n PackageRevision,\n ResolveOptions,\n SearchOptions,\n SearchResults,\n} from './types';\n\n// Names of the config files. From lowest to highest priority.\nconst EXPO_MODULE_CONFIG_FILENAMES = ['unimodule.json', 'expo-module.config.json'];\n\n/**\n * Path to the `package.json` of the closest project in the current working dir.\n */\nconst projectPackageJsonPath = findUp.sync('package.json', { cwd: process.cwd() }) as string;\n\n// This won't happen in usual scenarios, but we need to unwrap the optional path :)\nif (!projectPackageJsonPath) {\n throw new Error(`Couldn't find \"package.json\" up from path \"${process.cwd()}\"`);\n}\n\n/**\n * Custom `require` that resolves from the current working dir instead of this script path.\n * **Requires Node v12.2.0**\n */\nconst projectRequire = createRequire(projectPackageJsonPath);\n\n/**\n * Resolves autolinking search paths. If none is provided, it accumulates all node_modules when\n * going up through the path components. This makes workspaces work out-of-the-box without any configs.\n */\nexport async function resolveSearchPathsAsync(\n searchPaths: string[] | null,\n cwd: string\n): Promise<string[]> {\n return searchPaths && searchPaths.length > 0\n ? searchPaths.map((searchPath) => path.resolve(cwd, searchPath))\n : await findDefaultPathsAsync(cwd);\n}\n\n/**\n * Looks up for workspace's `node_modules` paths.\n */\nexport async function findDefaultPathsAsync(cwd: string): Promise<string[]> {\n const paths = [];\n let dir = cwd;\n let pkgJsonPath: string | undefined;\n\n while ((pkgJsonPath = await findUp('package.json', { cwd: dir }))) {\n dir = path.dirname(path.dirname(pkgJsonPath));\n paths.push(path.join(pkgJsonPath, '..', 'node_modules'));\n }\n return paths;\n}\n\n/**\n * Searches for modules to link based on given config.\n */\nexport async function findModulesAsync(providedOptions: SearchOptions): Promise<SearchResults> {\n const options = await mergeLinkingOptionsAsync(providedOptions);\n const results: SearchResults = {};\n\n for (const searchPath of options.searchPaths) {\n const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';\n const paths = await glob([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`], {\n cwd: searchPath,\n });\n\n // If the package has multiple configs (e.g. `unimodule.json` and `expo-module.config.json` during the transition time)\n // then we want to give `expo-module.config.json` the priority.\n const uniqueConfigPaths: string[] = Object.values(\n paths.reduce<Record<string, string>>((acc, configPath) => {\n const dirname = path.dirname(configPath);\n\n if (!acc[dirname] || configPriority(configPath) > configPriority(acc[dirname])) {\n acc[dirname] = configPath;\n }\n return acc;\n }, {})\n );\n\n for (const packageConfigPath of uniqueConfigPaths) {\n const packagePath = await fs.realpath(path.join(searchPath, path.dirname(packageConfigPath)));\n const expoModuleConfig = requireAndResolveExpoModuleConfig(\n path.join(packagePath, path.basename(packageConfigPath))\n );\n const { name, version } = require(path.join(packagePath, 'package.json'));\n\n if (options.exclude?.includes(name) || !expoModuleConfig.supportsPlatform(options.platform)) {\n continue;\n }\n\n const currentRevision: PackageRevision = {\n path: packagePath,\n version,\n };\n\n if (!results[name]) {\n // The revision that was found first will be the main one.\n // An array of duplicates and the config are needed only here.\n results[name] = {\n ...currentRevision,\n config: expoModuleConfig,\n duplicates: [],\n };\n } else if (\n results[name].path !== packagePath &&\n results[name].duplicates?.every(({ path }) => path !== packagePath)\n ) {\n results[name].duplicates?.push(currentRevision);\n }\n }\n }\n\n // It doesn't make much sense to strip modules if there is only one search path.\n // Workspace root usually doesn't specify all its dependencies (see Expo Go),\n // so in this case we should link everything.\n if (options.searchPaths.length <= 1) {\n return results;\n }\n return filterToProjectDependencies(results, providedOptions);\n}\n\n/**\n * Filters out packages that are not the dependencies of the project.\n */\nfunction filterToProjectDependencies(\n results: SearchResults,\n options: Pick<SearchOptions, 'silent'> = {}\n) {\n const filteredResults: SearchResults = {};\n const visitedPackages = new Set<string>();\n\n // Helper for traversing the dependency hierarchy.\n function visitPackage(packageJsonPath: string) {\n const packageJson = require(packageJsonPath);\n\n // Prevent getting into the recursive loop.\n if (visitedPackages.has(packageJson.name)) {\n return;\n }\n visitedPackages.add(packageJson.name);\n\n // Iterate over the dependencies to find transitive modules.\n for (const dependencyName in packageJson.dependencies) {\n const dependencyResult = results[dependencyName];\n\n if (!filteredResults[dependencyName]) {\n let dependencyPackageJsonPath: string;\n\n if (dependencyResult) {\n filteredResults[dependencyName] = dependencyResult;\n dependencyPackageJsonPath = path.join(dependencyResult.path, 'package.json');\n } else {\n try {\n dependencyPackageJsonPath = projectRequire.resolve(`${dependencyName}/package.json`);\n } catch (error: any) {\n // Some packages don't include package.json in its `exports` field,\n // but none of our packages do that, so it seems fine to just ignore that type of error.\n // Related issue: https://github.com/react-native-community/cli/issues/1168\n if (!options.silent && error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {\n console.warn(\n chalk.yellow(`⚠️ Cannot resolve the path to \"${dependencyName}\" package.`)\n );\n }\n continue;\n }\n }\n\n // Visit the dependency package.\n visitPackage(dependencyPackageJsonPath);\n }\n }\n }\n\n // Visit project's package.\n visitPackage(projectPackageJsonPath);\n\n return filteredResults;\n}\n\n/**\n * Merges autolinking options from different sources (the later the higher priority)\n * - options defined in package.json's `expoModules` field\n * - platform-specific options from the above (e.g. `expoModules.ios`)\n * - options provided to the CLI command\n */\nexport async function mergeLinkingOptionsAsync<OptionsType extends SearchOptions>(\n providedOptions: OptionsType\n): Promise<OptionsType> {\n const packageJson = require(projectPackageJsonPath);\n const baseOptions = packageJson.expo?.autolinking;\n const platformOptions = providedOptions.platform && baseOptions?.[providedOptions.platform];\n const finalOptions = Object.assign(\n {},\n baseOptions,\n platformOptions,\n providedOptions\n ) as OptionsType;\n\n // Makes provided paths absolute or falls back to default paths if none was provided.\n finalOptions.searchPaths = await resolveSearchPathsAsync(finalOptions.searchPaths, process.cwd());\n\n return finalOptions;\n}\n\n/**\n * Verifies the search results by checking whether there are no duplicates.\n */\nexport function verifySearchResults(searchResults: SearchResults): number {\n const cwd = process.cwd();\n const relativePath: (pkg: PackageRevision) => string = (pkg) => path.relative(cwd, pkg.path);\n let counter = 0;\n\n for (const moduleName in searchResults) {\n const revision = searchResults[moduleName];\n\n if (revision.duplicates?.length) {\n console.warn(`⚠️ Found multiple revisions of ${chalk.green(moduleName)}`);\n console.log(` - ${chalk.magenta(relativePath(revision))} (${chalk.cyan(revision.version)})`);\n\n for (const duplicate of revision.duplicates) {\n console.log(` - ${chalk.gray(relativePath(duplicate))} (${chalk.gray(duplicate.version)})`);\n }\n counter++;\n }\n }\n if (counter > 0) {\n console.warn(\n '⚠️ Please get rid of multiple revisions as it may introduce some side effects or compatibility issues'\n );\n }\n return counter;\n}\n\n/**\n * Resolves search results to a list of platform-specific configuration.\n */\nexport async function resolveModulesAsync(\n searchResults: SearchResults,\n options: ResolveOptions\n): Promise<ModuleDescriptor[]> {\n const platformLinking = require(`./platforms/${options.platform}`);\n\n return (\n await Promise.all(\n Object.entries(searchResults).map(async ([packageName, revision]) => {\n const resolvedModule = await platformLinking.resolveModuleAsync(\n packageName,\n revision,\n options\n );\n return resolvedModule\n ? {\n packageName,\n packageVersion: revision.version,\n ...resolvedModule,\n }\n : null;\n })\n )\n )\n .filter(Boolean)\n .sort((a, b) => a.packageName.localeCompare(b.packageName));\n}\n\n/**\n * Generates a source file listing all packages to link.\n * Right know it works only for Android platform.\n */\nexport async function generatePackageListAsync(\n modules: ModuleDescriptor[],\n options: GenerateOptions\n) {\n try {\n const platformLinking = require(`./platforms/${options.platform}`);\n await platformLinking.generatePackageListAsync(modules, options.target, options.namespace);\n } catch (e) {\n console.error(\n chalk.red(`Generating package list is not available for platform: ${options.platform}`)\n );\n throw e;\n }\n}\n\n/**\n * Returns the priority of the config at given path. Higher number means higher priority.\n */\nfunction configPriority(fullpath: string): number {\n return EXPO_MODULE_CONFIG_FILENAMES.indexOf(path.basename(fullpath));\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -14,12 +14,13 @@ function registerSearchCommand(commandName, fn) {
|
|
|
14
14
|
.option('-i, --ignore-paths <ignorePaths...>', 'Paths to ignore when looking up for modules.', (value, previous) => (previous !== null && previous !== void 0 ? previous : []).concat(value))
|
|
15
15
|
.option('-e, --exclude <exclude...>', 'Package names to exclude when looking up for modules.', (value, previous) => (previous !== null && previous !== void 0 ? previous : []).concat(value))
|
|
16
16
|
.option('-p, --platform [platform]', 'The platform that the resulting modules must support. Available options: "ios", "android"', 'ios')
|
|
17
|
+
.option('--silent', 'Silence resolution warnings')
|
|
17
18
|
.action(async (searchPaths, providedOptions) => {
|
|
18
|
-
const options = await autolinking_1.mergeLinkingOptionsAsync({
|
|
19
|
+
const options = await (0, autolinking_1.mergeLinkingOptionsAsync)({
|
|
19
20
|
...providedOptions,
|
|
20
21
|
searchPaths,
|
|
21
22
|
});
|
|
22
|
-
const searchResults = await autolinking_1.findModulesAsync(options);
|
|
23
|
+
const searchResults = await (0, autolinking_1.findModulesAsync)(options);
|
|
23
24
|
return await fn(searchResults, options);
|
|
24
25
|
});
|
|
25
26
|
}
|
|
@@ -41,14 +42,14 @@ module.exports = async function (args) {
|
|
|
41
42
|
}).option('-j, --json', 'Output results in the plain JSON format.', () => true, false);
|
|
42
43
|
// Checks whether there are no resolving issues in the current setup.
|
|
43
44
|
registerSearchCommand('verify', (results) => {
|
|
44
|
-
const numberOfDuplicates = autolinking_1.verifySearchResults(results);
|
|
45
|
+
const numberOfDuplicates = (0, autolinking_1.verifySearchResults)(results);
|
|
45
46
|
if (!numberOfDuplicates) {
|
|
46
47
|
console.log('✅ Everything is fine!');
|
|
47
48
|
}
|
|
48
49
|
});
|
|
49
50
|
// Searches for available expo modules and resolves the results for given platform.
|
|
50
51
|
registerResolveCommand('resolve', async (results, options) => {
|
|
51
|
-
const modules = await autolinking_1.resolveModulesAsync(results, options);
|
|
52
|
+
const modules = await (0, autolinking_1.resolveModulesAsync)(results, options);
|
|
52
53
|
if (options.json) {
|
|
53
54
|
console.log(JSON.stringify({ modules }));
|
|
54
55
|
}
|
|
@@ -58,8 +59,8 @@ module.exports = async function (args) {
|
|
|
58
59
|
}).option('-j, --json', 'Output results in the plain JSON format.', () => true, false);
|
|
59
60
|
// Generates a source file listing all packages to link.
|
|
60
61
|
registerResolveCommand('generate-package-list', async (results, options) => {
|
|
61
|
-
const modules = options.empty ? [] : await autolinking_1.resolveModulesAsync(results, options);
|
|
62
|
-
autolinking_1.generatePackageListAsync(modules, options);
|
|
62
|
+
const modules = options.empty ? [] : await (0, autolinking_1.resolveModulesAsync)(results, options);
|
|
63
|
+
(0, autolinking_1.generatePackageListAsync)(modules, options);
|
|
63
64
|
})
|
|
64
65
|
.option('-t, --target <path>', 'Path to the target file, where the package list should be written to.')
|
|
65
66
|
.option('-n, --namespace <namespace>', 'Java package name under which the package list should be placed.')
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAElC,+CAMuB;AAGvB;;GAEG;AACH,SAAS,qBAAqB,CAC5B,WAAmB,EACnB,EAAwD;IAExD,OAAO,mBAAS;SACb,OAAO,CAAC,GAAG,WAAW,aAAa,CAAC;SACpC,MAAM,CACL,qCAAqC,EACrC,8CAA8C,EAC9C,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACpD;SACA,MAAM,CACL,4BAA4B,EAC5B,uDAAuD,EACvD,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,aAAR,QAAQ,cAAR,QAAQ,GAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACpD;SACA,MAAM,CACL,2BAA2B,EAC3B,2FAA2F,EAC3F,KAAK,CACN;SACA,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE;QAC7C,MA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B,uBAAuB,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1F,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAA,iCAAmB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QACjF,IAAA,sCAAwB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC,CAAC;SACC,MAAM,CACL,qBAAqB,EACrB,uEAAuE,CACxE;SACA,MAAM,CACL,6BAA6B,EAC7B,kEAAkE,CACnE;SACA,MAAM,CACL,SAAS,EACT,8FAA8F,EAC9F,KAAK,CACN,CAAC;IAEJ,MAAM,mBAAS;SACZ,OAAO,CAAC,OAAO,CAAC,uCAAuC,CAAC,CAAC,OAAO,CAAC;SACjE,WAAW,CAAC,8DAA8D,CAAC;SAC3E,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,CAAC;AACxC,CAAC,CAAC","sourcesContent":["import commander from 'commander';\n\nimport {\n findModulesAsync,\n resolveModulesAsync,\n verifySearchResults,\n generatePackageListAsync,\n mergeLinkingOptionsAsync,\n} from './autolinking';\nimport { GenerateOptions, ResolveOptions, SearchOptions, SearchResults } from './types';\n\n/**\n * Registers a command that only searches for available expo modules.\n */\nfunction registerSearchCommand<OptionsType extends SearchOptions>(\n commandName: string,\n fn: (search: SearchResults, options: OptionsType) => any\n) {\n return commander\n .command(`${commandName} [paths...]`)\n .option<string[] | null>(\n '-i, --ignore-paths <ignorePaths...>',\n 'Paths to ignore when looking up for modules.',\n (value, previous) => (previous ?? []).concat(value)\n )\n .option<string[] | null>(\n '-e, --exclude <exclude...>',\n 'Package names to exclude when looking up for modules.',\n (value, previous) => (previous ?? []).concat(value)\n )\n .option(\n '-p, --platform [platform]',\n 'The platform that the resulting modules must support. Available options: \"ios\", \"android\"',\n 'ios'\n )\n .option('--silent', 'Silence resolution warnings')\n .action(async (searchPaths, providedOptions) => {\n const options = await mergeLinkingOptionsAsync<OptionsType>({\n ...providedOptions,\n searchPaths,\n });\n const searchResults = await findModulesAsync(options);\n return await fn(searchResults, options);\n });\n}\n\n/**\n * Registers a command that searches for modules and then resolves them for specific platform.\n */\nfunction registerResolveCommand<OptionsType extends ResolveOptions>(\n commandName: string,\n fn: (search: SearchResults, options: OptionsType) => any\n) {\n return registerSearchCommand<OptionsType>(commandName, fn);\n}\n\nmodule.exports = async function (args: string[]) {\n // Searches for available expo modules.\n registerSearchCommand<SearchOptions & { json?: boolean }>('search', async (results, options) => {\n if (options.json) {\n console.log(JSON.stringify(results));\n } else {\n console.log(require('util').inspect(results, false, null, true));\n }\n }).option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false);\n\n // Checks whether there are no resolving issues in the current setup.\n registerSearchCommand('verify', (results) => {\n const numberOfDuplicates = verifySearchResults(results);\n if (!numberOfDuplicates) {\n console.log('✅ Everything is fine!');\n }\n });\n\n // Searches for available expo modules and resolves the results for given platform.\n registerResolveCommand('resolve', async (results, options) => {\n const modules = await resolveModulesAsync(results, options);\n\n if (options.json) {\n console.log(JSON.stringify({ modules }));\n } else {\n console.log({ modules });\n }\n }).option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false);\n\n // Generates a source file listing all packages to link.\n registerResolveCommand<GenerateOptions>('generate-package-list', async (results, options) => {\n const modules = options.empty ? [] : await resolveModulesAsync(results, options);\n generatePackageListAsync(modules, options);\n })\n .option(\n '-t, --target <path>',\n 'Path to the target file, where the package list should be written to.'\n )\n .option(\n '-n, --namespace <namespace>',\n 'Java package name under which the package list should be placed.'\n )\n .option(\n '--empty',\n 'Whether to only generate an empty list. Might be used when the user opts-out of autolinking.',\n false\n );\n\n await commander\n .version(require('expo-modules-autolinking/package.json').version)\n .description('CLI command that searches for Expo modules to autolink them.')\n .parseAsync(args, { from: 'user' });\n};\n"]}
|
|
@@ -17,11 +17,12 @@ async function generatePackageListAsync(modules, targetPath, namespace) {
|
|
|
17
17
|
exports.generatePackageListAsync = generatePackageListAsync;
|
|
18
18
|
async function resolveModuleAsync(packageName, revision) {
|
|
19
19
|
// TODO: Relative source dir should be configurable through the module config.
|
|
20
|
+
var _a;
|
|
20
21
|
// Don't link itself... :D
|
|
21
22
|
if (packageName === '@unimodules/react-native-adapter') {
|
|
22
23
|
return null;
|
|
23
24
|
}
|
|
24
|
-
const [buildGradleFile] = await fast_glob_1.default('*/build.gradle', {
|
|
25
|
+
const [buildGradleFile] = await (0, fast_glob_1.default)('*/build.gradle', {
|
|
25
26
|
cwd: revision.path,
|
|
26
27
|
ignore: ['**/node_modules/**'],
|
|
27
28
|
});
|
|
@@ -33,6 +34,7 @@ async function resolveModuleAsync(packageName, revision) {
|
|
|
33
34
|
return {
|
|
34
35
|
projectName: convertPackageNameToProjectName(packageName),
|
|
35
36
|
sourceDir,
|
|
37
|
+
modulesClassNames: (_a = revision.config) === null || _a === void 0 ? void 0 : _a.androidModulesClassNames(),
|
|
36
38
|
};
|
|
37
39
|
}
|
|
38
40
|
exports.resolveModuleAsync = resolveModuleAsync;
|
|
@@ -42,29 +44,46 @@ exports.resolveModuleAsync = resolveModuleAsync;
|
|
|
42
44
|
async function generatePackageListFileContentAsync(modules, namespace) {
|
|
43
45
|
// TODO: Instead of ignoring `expo` here, make the package class paths configurable from `expo-module.config.json`.
|
|
44
46
|
const packagesClasses = await findAndroidPackagesAsync(modules.filter((module) => module.packageName !== 'expo'));
|
|
47
|
+
const modulesClasses = await findAndroidModules(modules);
|
|
45
48
|
return `package ${namespace};
|
|
46
49
|
|
|
47
50
|
import java.util.Arrays;
|
|
48
51
|
import java.util.List;
|
|
49
52
|
import expo.modules.core.interfaces.Package;
|
|
53
|
+
import expo.modules.kotlin.modules.Module;
|
|
54
|
+
import expo.modules.kotlin.ModulesProvider;
|
|
50
55
|
|
|
51
|
-
public class ExpoModulesPackageList {
|
|
56
|
+
public class ExpoModulesPackageList implements ModulesProvider {
|
|
52
57
|
private static class LazyHolder {
|
|
53
58
|
static final List<Package> packagesList = Arrays.<Package>asList(
|
|
54
59
|
${packagesClasses.map((packageClass) => ` new ${packageClass}()`).join(',\n')}
|
|
55
60
|
);
|
|
61
|
+
|
|
62
|
+
static final List<Class<? extends Module>> modulesList = Arrays.<Class<? extends Module>>asList(
|
|
63
|
+
${modulesClasses.map((moduleClass) => ` ${moduleClass}.class`).join(',\n')}
|
|
64
|
+
);
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
public static List<Package> getPackageList() {
|
|
59
68
|
return LazyHolder.packagesList;
|
|
60
69
|
}
|
|
70
|
+
|
|
71
|
+
@Override
|
|
72
|
+
public List<Class<? extends Module>> getModulesList() {
|
|
73
|
+
return LazyHolder.modulesList;
|
|
74
|
+
}
|
|
61
75
|
}
|
|
62
76
|
`;
|
|
63
77
|
}
|
|
78
|
+
function findAndroidModules(modules) {
|
|
79
|
+
const modulesToProvide = modules.filter((module) => module.modulesClassNames.length > 0);
|
|
80
|
+
const classNames = [].concat(...modulesToProvide.map((module) => module.modulesClassNames));
|
|
81
|
+
return classNames;
|
|
82
|
+
}
|
|
64
83
|
async function findAndroidPackagesAsync(modules) {
|
|
65
84
|
const classes = [];
|
|
66
85
|
await Promise.all(modules.map(async (module) => {
|
|
67
|
-
const files = await fast_glob_1.default('
|
|
86
|
+
const files = await (0, fast_glob_1.default)('**/*Package.{java,kt}', {
|
|
68
87
|
cwd: module.sourceDir,
|
|
69
88
|
});
|
|
70
89
|
for (const file of files) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/platforms/android.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAIxB;;GAEG;AACI,KAAK,UAAU,wBAAwB,CAC5C,OAA2B,EAC3B,UAAkB,EAClB,SAAiB;IAEjB,MAAM,oBAAoB,GAAG,MAAM,mCAAmC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IA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tB,CAAC,CAAC;QAEH,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACxB,MAAM,WAAW,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,cAAI,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,CAAC;YAEjF,MAAM,YAAY,GAAG,CAAC,GAAG,EAAE;gBACzB,IAAI,OAAO,CAAC,GAAG,CAAC,wCAAwC,EAAE;oBACxD,OAAO,uEAAuE,CAAC;iBAChF;qBAAM;oBACL,OAAO,qEAAqE,CAAC;iBAC9E;YACH,CAAC,CAAC,EAAE,CAAC;YAEL,6CAA6C;YAC7C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,WAAW,CAAC,EAAE;gBACnC,SAAS;aACV;YAED,MAAM,gBAAgB,GAAG,WAAW,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;YAEnE,IAAI,gBAAgB,EAAE;gBACpB,MAAM,QAAQ,GAAG,cAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,cAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;gBACzD,OAAO,CAAC,IAAI,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC,CAAC;aACpD;SACF;IACH,CAAC,CAAC,CACH,CAAC;IACF,OAAO,OAAO,CAAC,IAAI,EAAE,CAAC;AACxB,CAAC;AAED;;;GAGG;AACH,SAAS,+BAA+B,CAAC,WAAmB;IAC1D,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC7D,CAAC","sourcesContent":["import glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { ModuleDescriptor, PackageRevision } from '../types';\n\n/**\n * Generates Java file that contains all autolinked packages.\n */\nexport async function generatePackageListAsync(\n modules: ModuleDescriptor[],\n targetPath: string,\n namespace: string\n): Promise<void> {\n const generatedFileContent = await generatePackageListFileContentAsync(modules, namespace);\n await fs.outputFile(targetPath, generatedFileContent);\n}\n\nexport async function resolveModuleAsync(\n packageName: string,\n revision: PackageRevision\n): Promise<ModuleDescriptor | null> {\n // TODO: Relative source dir should be configurable through the module config.\n\n // Don't link itself... :D\n if (packageName === '@unimodules/react-native-adapter') {\n return null;\n }\n\n const [buildGradleFile] = await glob('*/build.gradle', {\n cwd: revision.path,\n ignore: ['**/node_modules/**'],\n });\n\n // Just in case where the module doesn't have its own `build.gradle`.\n if (!buildGradleFile) {\n return null;\n }\n\n const sourceDir = path.dirname(path.join(revision.path, buildGradleFile));\n\n return {\n projectName: convertPackageNameToProjectName(packageName),\n sourceDir,\n modulesClassNames: revision.config?.androidModulesClassNames(),\n };\n}\n\n/**\n * Generates the string to put into the generated package list.\n */\nasync function generatePackageListFileContentAsync(\n modules: ModuleDescriptor[],\n namespace: string\n): Promise<string> {\n // TODO: Instead of ignoring `expo` here, make the package class paths configurable from `expo-module.config.json`.\n const packagesClasses = await findAndroidPackagesAsync(\n modules.filter((module) => module.packageName !== 'expo')\n );\n\n const modulesClasses = await findAndroidModules(modules);\n\n return `package ${namespace};\n\nimport java.util.Arrays;\nimport java.util.List;\nimport expo.modules.core.interfaces.Package;\nimport expo.modules.kotlin.modules.Module;\nimport expo.modules.kotlin.ModulesProvider;\n\npublic class ExpoModulesPackageList implements ModulesProvider {\n private static class LazyHolder {\n static final List<Package> packagesList = Arrays.<Package>asList(\n${packagesClasses.map((packageClass) => ` new ${packageClass}()`).join(',\\n')}\n );\n\n static final List<Class<? extends Module>> modulesList = Arrays.<Class<? extends Module>>asList(\n ${modulesClasses.map((moduleClass) => ` ${moduleClass}.class`).join(',\\n')}\n );\n }\n\n public static List<Package> getPackageList() {\n return LazyHolder.packagesList;\n }\n\n @Override\n public List<Class<? extends Module>> getModulesList() {\n return LazyHolder.modulesList;\n }\n}\n`;\n}\n\nfunction findAndroidModules(modules: ModuleDescriptor[]): string[] {\n const modulesToProvide = modules.filter((module) => module.modulesClassNames.length > 0);\n const classNames = [].concat(...modulesToProvide.map((module) => module.modulesClassNames));\n return classNames;\n}\n\nasync function findAndroidPackagesAsync(modules: ModuleDescriptor[]): Promise<string[]> {\n const classes: string[] = [];\n\n await Promise.all(\n modules.map(async (module) => {\n const files = await glob('**/*Package.{java,kt}', {\n cwd: module.sourceDir,\n });\n\n for (const file of files) {\n const fileContent = await fs.readFile(path.join(module.sourceDir, file), 'utf8');\n\n const packageRegex = (() => {\n if (process.env.EXPO_SHOULD_USE_LEGACY_PACKAGE_INTERFACE) {\n return /\\bimport\\s+org\\.unimodules\\.core\\.(interfaces\\.Package|BasePackage)\\b/;\n } else {\n return /\\bimport\\s+expo\\.modules\\.core\\.(interfaces\\.Package|BasePackage)\\b/;\n }\n })();\n\n // Very naive check to skip non-expo packages\n if (!packageRegex.test(fileContent)) {\n continue;\n }\n\n const classPathMatches = fileContent.match(/^package ([\\w.]+)\\b/m);\n\n if (classPathMatches) {\n const basename = path.basename(file, path.extname(file));\n classes.push(`${classPathMatches[1]}.${basename}`);\n }\n }\n })\n );\n return classes.sort();\n}\n\n/**\n * Converts the package name to Android's project name.\n * Example: `@unimodules/core` → `unimodules-core`\n */\nfunction convertPackageNameToProjectName(projectName: string): string {\n return projectName.replace(/^@/g, '').replace(/\\W+/g, '-');\n}\n"]}
|
package/build/platforms/ios.d.ts
CHANGED
|
@@ -7,3 +7,7 @@ export declare function resolveModuleAsync(packageName: string, revision: Packag
|
|
|
7
7
|
* Generates Swift file that contains all autolinked Swift packages.
|
|
8
8
|
*/
|
|
9
9
|
export declare function generatePackageListAsync(modules: ModuleDescriptor[], targetPath: string): Promise<void>;
|
|
10
|
+
/**
|
|
11
|
+
* Formats an array of modules to Swift's array containing ReactDelegateHandlers
|
|
12
|
+
*/
|
|
13
|
+
export declare function formatArrayOfReactDelegateHandler(modules: ModuleDescriptor[]): string;
|
package/build/platforms/ios.js
CHANGED
|
@@ -3,19 +3,27 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generatePackageListAsync = exports.resolveModuleAsync = void 0;
|
|
6
|
+
exports.formatArrayOfReactDelegateHandler = exports.generatePackageListAsync = exports.resolveModuleAsync = void 0;
|
|
7
7
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
8
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
|
-
|
|
11
|
-
* Resolves module search result with additional details required for iOS platform.
|
|
12
|
-
*/
|
|
13
|
-
async function resolveModuleAsync(packageName, revision, options) {
|
|
10
|
+
async function findPodspecFile(revision) {
|
|
14
11
|
var _a;
|
|
15
|
-
|
|
12
|
+
if ((_a = revision.config) === null || _a === void 0 ? void 0 : _a.iosPodspecPath()) {
|
|
13
|
+
return revision.config.iosPodspecPath();
|
|
14
|
+
}
|
|
15
|
+
const [podspecFile] = await (0, fast_glob_1.default)('*/*.podspec', {
|
|
16
16
|
cwd: revision.path,
|
|
17
17
|
ignore: ['**/node_modules/**'],
|
|
18
18
|
});
|
|
19
|
+
return podspecFile;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Resolves module search result with additional details required for iOS platform.
|
|
23
|
+
*/
|
|
24
|
+
async function resolveModuleAsync(packageName, revision, options) {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const podspecFile = await findPodspecFile(revision);
|
|
19
27
|
if (!podspecFile) {
|
|
20
28
|
return null;
|
|
21
29
|
}
|
|
@@ -26,6 +34,8 @@ async function resolveModuleAsync(packageName, revision, options) {
|
|
|
26
34
|
podspecDir,
|
|
27
35
|
flags: options.flags,
|
|
28
36
|
modulesClassNames: (_a = revision.config) === null || _a === void 0 ? void 0 : _a.iosModulesClassNames(),
|
|
37
|
+
appDelegateSubscribers: (_b = revision.config) === null || _b === void 0 ? void 0 : _b.iosAppDelegateSubscribers(),
|
|
38
|
+
reactDelegateHandlers: (_c = revision.config) === null || _c === void 0 ? void 0 : _c.iosReactDelegateHandlers(),
|
|
29
39
|
};
|
|
30
40
|
}
|
|
31
41
|
exports.resolveModuleAsync = resolveModuleAsync;
|
|
@@ -42,9 +52,17 @@ exports.generatePackageListAsync = generatePackageListAsync;
|
|
|
42
52
|
* Generates the string to put into the generated package list.
|
|
43
53
|
*/
|
|
44
54
|
async function generatePackageListFileContentAsync(modules, className) {
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
const modulesToImport = modules.filter((module) => module.modulesClassNames.length ||
|
|
56
|
+
module.appDelegateSubscribers.length ||
|
|
57
|
+
module.reactDelegateHandlers.length);
|
|
58
|
+
const pods = modulesToImport.map((module) => module.podName);
|
|
59
|
+
const modulesClassNames = []
|
|
60
|
+
.concat(...modulesToImport.map((module) => module.modulesClassNames))
|
|
61
|
+
.filter(Boolean);
|
|
62
|
+
const appDelegateSubscribers = []
|
|
63
|
+
.concat(...modulesToImport.map((module) => module.appDelegateSubscribers))
|
|
64
|
+
.filter(Boolean);
|
|
65
|
+
const reactDelegateHandlerModules = modulesToImport.filter((module) => !!module.reactDelegateHandlers.length);
|
|
48
66
|
return `/**
|
|
49
67
|
* Automatically generated by expo-modules-autolinking.
|
|
50
68
|
*
|
|
@@ -57,10 +75,40 @@ ${pods.map((podName) => `import ${podName}\n`).join('')}
|
|
|
57
75
|
@objc(${className})
|
|
58
76
|
public class ${className}: ModulesProvider {
|
|
59
77
|
public override func getModuleClasses() -> [AnyModule.Type] {
|
|
60
|
-
return
|
|
61
|
-
|
|
78
|
+
return ${formatArrayOfClassNames(modulesClassNames)}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public override func getAppDelegateSubscribers() -> [ExpoAppDelegateSubscriber.Type] {
|
|
82
|
+
return ${formatArrayOfClassNames(appDelegateSubscribers)}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public override func getReactDelegateHandlers() -> [ExpoReactDelegateHandlerTupleType] {
|
|
86
|
+
return ${formatArrayOfReactDelegateHandler(reactDelegateHandlerModules)}
|
|
62
87
|
}
|
|
63
88
|
}
|
|
64
89
|
`;
|
|
65
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Formats an array of class names to Swift's array containing these classes.
|
|
93
|
+
*/
|
|
94
|
+
function formatArrayOfClassNames(classNames) {
|
|
95
|
+
const indent = ' ';
|
|
96
|
+
return `[${classNames.map((className) => `\n${indent.repeat(3)}${className}.self`).join(',')}
|
|
97
|
+
${indent.repeat(2)}]`;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Formats an array of modules to Swift's array containing ReactDelegateHandlers
|
|
101
|
+
*/
|
|
102
|
+
function formatArrayOfReactDelegateHandler(modules) {
|
|
103
|
+
const values = [];
|
|
104
|
+
for (const module of modules) {
|
|
105
|
+
for (const handler of module.reactDelegateHandlers) {
|
|
106
|
+
values.push(`(packageName: "${module.packageName}", handler: ${handler}.self)`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
const indent = ' ';
|
|
110
|
+
return `[${values.map((value) => `\n${indent.repeat(3)}${value}`).join(',')}
|
|
111
|
+
${indent.repeat(2)}]`;
|
|
112
|
+
}
|
|
113
|
+
exports.formatArrayOfReactDelegateHandler = formatArrayOfReactDelegateHandler;
|
|
66
114
|
//# sourceMappingURL=ios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.js","sourceRoot":"","sources":["../../src/platforms/ios.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAIxB
|
|
1
|
+
{"version":3,"file":"ios.js","sourceRoot":"","sources":["../../src/platforms/ios.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAIxB,KAAK,UAAU,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SAAS;;aAEX,uBAAuB,CAAC,iBAAiB,CAAC;;;;aAI1C,uBAAuB,CAAC,sBAAsB,CAAC;;;;aAI/C,iCAAiC,CAAC,2BAA2B,CAAC;;;CAG1E,CAAC;AACF,CAAC;AAED;;GAEG;AACH,SAAS,uBAAuB,CAAC,UAAoB;IACnD,MAAM,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,SAAS,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;EAC5F,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;AACtB,CAAC;AAED;;GAEG;AACH,SAAgB,iCAAiC,CAAC,OAA2B;IAC3E,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE;QAC5B,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,qBAAqB,EAAE;YAClD,MAAM,CAAC,IAAI,CAAC,kBAAkB,MAAM,CAAC,WAAW,eAAe,OAAO,QAAQ,CAAC,CAAC;SACjF;KACF;IACD,MAAM,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;EAC3E,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,CAAC;AACtB,CAAC;AAVD,8EAUC","sourcesContent":["import glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { ModuleDescriptor, PackageRevision, SearchOptions } from '../types';\n\nasync function findPodspecFile(revision: PackageRevision): Promise<string | undefined> {\n if (revision.config?.iosPodspecPath()) {\n return revision.config.iosPodspecPath();\n }\n\n const [podspecFile] = await glob('*/*.podspec', {\n cwd: revision.path,\n ignore: ['**/node_modules/**'],\n });\n\n return podspecFile;\n}\n\n/**\n * Resolves module search result with additional details required for iOS platform.\n */\nexport async function resolveModuleAsync(\n packageName: string,\n revision: PackageRevision,\n options: SearchOptions\n): Promise<ModuleDescriptor | null> {\n const podspecFile = await findPodspecFile(revision);\n if (!podspecFile) {\n return null;\n }\n\n const podName = path.basename(podspecFile, path.extname(podspecFile));\n const podspecDir = path.dirname(path.join(revision.path, podspecFile));\n\n return {\n podName,\n podspecDir,\n flags: options.flags,\n modulesClassNames: revision.config?.iosModulesClassNames(),\n appDelegateSubscribers: revision.config?.iosAppDelegateSubscribers(),\n reactDelegateHandlers: revision.config?.iosReactDelegateHandlers(),\n };\n}\n\n/**\n * Generates Swift file that contains all autolinked Swift packages.\n */\nexport async function generatePackageListAsync(\n modules: ModuleDescriptor[],\n targetPath: string\n): Promise<void> {\n const className = path.basename(targetPath, path.extname(targetPath));\n const generatedFileContent = await generatePackageListFileContentAsync(modules, className);\n\n await fs.outputFile(targetPath, generatedFileContent);\n}\n\n/**\n * Generates the string to put into the generated package list.\n */\nasync function generatePackageListFileContentAsync(\n modules: ModuleDescriptor[],\n className: string\n): Promise<string> {\n const modulesToImport = modules.filter(\n (module) =>\n module.modulesClassNames.length ||\n module.appDelegateSubscribers.length ||\n module.reactDelegateHandlers.length\n );\n const pods = modulesToImport.map((module) => module.podName);\n\n const modulesClassNames = []\n .concat(...modulesToImport.map((module) => module.modulesClassNames))\n .filter(Boolean);\n\n const appDelegateSubscribers = []\n .concat(...modulesToImport.map((module) => module.appDelegateSubscribers))\n .filter(Boolean);\n\n const reactDelegateHandlerModules = modulesToImport.filter(\n (module) => !!module.reactDelegateHandlers.length\n );\n\n return `/**\n * Automatically generated by expo-modules-autolinking.\n *\n * This autogenerated class provides a list of classes of native Expo modules,\n * but only these that are written in Swift and use the new API for creating Expo modules.\n */\n\nimport ExpoModulesCore\n${pods.map((podName) => `import ${podName}\\n`).join('')}\n@objc(${className})\npublic class ${className}: ModulesProvider {\n public override func getModuleClasses() -> [AnyModule.Type] {\n return ${formatArrayOfClassNames(modulesClassNames)}\n }\n\n public override func getAppDelegateSubscribers() -> [ExpoAppDelegateSubscriber.Type] {\n return ${formatArrayOfClassNames(appDelegateSubscribers)}\n }\n\n public override func getReactDelegateHandlers() -> [ExpoReactDelegateHandlerTupleType] {\n return ${formatArrayOfReactDelegateHandler(reactDelegateHandlerModules)}\n }\n}\n`;\n}\n\n/**\n * Formats an array of class names to Swift's array containing these classes.\n */\nfunction formatArrayOfClassNames(classNames: string[]): string {\n const indent = ' ';\n return `[${classNames.map((className) => `\\n${indent.repeat(3)}${className}.self`).join(',')}\n${indent.repeat(2)}]`;\n}\n\n/**\n * Formats an array of modules to Swift's array containing ReactDelegateHandlers\n */\nexport function formatArrayOfReactDelegateHandler(modules: ModuleDescriptor[]): string {\n const values: string[] = [];\n for (const module of modules) {\n for (const handler of module.reactDelegateHandlers) {\n values.push(`(packageName: \"${module.packageName}\", handler: ${handler}.self)`);\n }\n }\n const indent = ' ';\n return `[${values.map((value) => `\\n${indent.repeat(3)}${value}`).join(',')}\n${indent.repeat(2)}]`;\n}\n"]}
|
package/build/types.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export interface SearchOptions {
|
|
|
5
5
|
ignorePaths?: string[] | null;
|
|
6
6
|
exclude?: string[] | null;
|
|
7
7
|
platform: SupportedPlatform;
|
|
8
|
+
silent?: boolean;
|
|
8
9
|
flags?: Record<string, any>;
|
|
9
10
|
}
|
|
10
11
|
export interface ResolveOptions extends SearchOptions {
|
|
@@ -41,5 +42,26 @@ export interface RawExpoModuleConfig {
|
|
|
41
42
|
* Names of Swift native modules classes to put to the generated modules provider file.
|
|
42
43
|
*/
|
|
43
44
|
modulesClassNames?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.
|
|
47
|
+
*/
|
|
48
|
+
appDelegateSubscribers?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* Names of Swift classes that implement `ExpoReactDelegateHandler` to hook React instance creation.
|
|
51
|
+
*/
|
|
52
|
+
reactDelegateHandlers?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Podspec relative path.
|
|
55
|
+
*/
|
|
56
|
+
podspecPath?: string;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Android-specific config.
|
|
60
|
+
*/
|
|
61
|
+
android?: {
|
|
62
|
+
/**
|
|
63
|
+
* Full names (package + class name) of Kotlin native modules classes to put to the generated package provider file.
|
|
64
|
+
*/
|
|
65
|
+
modulesClassNames?: string[];
|
|
44
66
|
};
|
|
45
67
|
}
|
package/build/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ExpoModuleConfig } from './ExpoModuleConfig';\n\nexport type SupportedPlatform = 'ios' | 'android' | 'web';\n\nexport interface SearchOptions {\n // Available in the CLI\n searchPaths: string[];\n ignorePaths?: string[] | null;\n exclude?: string[] | null;\n platform: SupportedPlatform;\n\n // Scratched from project's config\n flags?: Record<string, any>;\n}\n\nexport interface ResolveOptions extends SearchOptions {\n json?: boolean;\n}\n\nexport interface GenerateOptions extends ResolveOptions {\n target: string;\n namespace?: string;\n empty?: boolean;\n}\n\nexport type PackageRevision = {\n path: string;\n version: string;\n config?: ExpoModuleConfig;\n duplicates?: PackageRevision[];\n};\n\nexport type SearchResults = {\n [moduleName: string]: PackageRevision;\n};\n\nexport type ModuleDescriptor = Record<string, any>;\n\n/**\n * Represents a raw config from `expo-module.json`.\n */\nexport interface RawExpoModuleConfig {\n /**\n * An array of supported platforms.\n */\n platforms?: SupportedPlatform[];\n\n /**\n * iOS-specific config.\n */\n ios?: {\n /**\n * Names of Swift native modules classes to put to the generated modules provider file.\n */\n modulesClassNames?: string[];\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { ExpoModuleConfig } from './ExpoModuleConfig';\n\nexport type SupportedPlatform = 'ios' | 'android' | 'web';\n\nexport interface SearchOptions {\n // Available in the CLI\n searchPaths: string[];\n ignorePaths?: string[] | null;\n exclude?: string[] | null;\n platform: SupportedPlatform;\n silent?: boolean;\n\n // Scratched from project's config\n flags?: Record<string, any>;\n}\n\nexport interface ResolveOptions extends SearchOptions {\n json?: boolean;\n}\n\nexport interface GenerateOptions extends ResolveOptions {\n target: string;\n namespace?: string;\n empty?: boolean;\n}\n\nexport type PackageRevision = {\n path: string;\n version: string;\n config?: ExpoModuleConfig;\n duplicates?: PackageRevision[];\n};\n\nexport type SearchResults = {\n [moduleName: string]: PackageRevision;\n};\n\nexport type ModuleDescriptor = Record<string, any>;\n\n/**\n * Represents a raw config from `expo-module.json`.\n */\nexport interface RawExpoModuleConfig {\n /**\n * An array of supported platforms.\n */\n platforms?: SupportedPlatform[];\n\n /**\n * iOS-specific config.\n */\n ios?: {\n /**\n * Names of Swift native modules classes to put to the generated modules provider file.\n */\n modulesClassNames?: string[];\n\n /**\n * Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.\n */\n appDelegateSubscribers?: string[];\n\n /**\n * Names of Swift classes that implement `ExpoReactDelegateHandler` to hook React instance creation.\n */\n reactDelegateHandlers?: string[];\n\n /**\n * Podspec relative path.\n */\n podspecPath?: string;\n };\n\n /**\n * Android-specific config.\n */\n android?: {\n /**\n * Full names (package + class name) of Kotlin native modules classes to put to the generated package provider file.\n */\n modulesClassNames?: string[];\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-modules-autolinking",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.1",
|
|
4
4
|
"description": "Scripts that autolink Expo modules.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -44,8 +44,8 @@
|
|
|
44
44
|
"chalk": "^4.1.0",
|
|
45
45
|
"commander": "^7.2.0",
|
|
46
46
|
"fast-glob": "^3.2.5",
|
|
47
|
-
"find-up": "
|
|
47
|
+
"find-up": "^5.0.0",
|
|
48
48
|
"fs-extra": "^9.1.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "779a011c9a6a436d3e69df0f8f7d1a4703fb297a"
|
|
51
51
|
}
|
|
@@ -44,7 +44,7 @@ class ExpoAutolinkingManager {
|
|
|
44
44
|
String[] args = convertOptionsToCommandArgs('resolve', this.options)
|
|
45
45
|
args += ['--json']
|
|
46
46
|
|
|
47
|
-
String output = exec(args)
|
|
47
|
+
String output = exec(args, projectDir)
|
|
48
48
|
Object json = new JsonSlurper().parseText(output)
|
|
49
49
|
|
|
50
50
|
cachedResolvingResults = json
|
|
@@ -84,11 +84,11 @@ class ExpoAutolinkingManager {
|
|
|
84
84
|
args += '--empty'
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
exec(args)
|
|
87
|
+
exec(args, project.rootDir)
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
-
static String exec(String[] commandArgs) {
|
|
91
|
-
Process proc = commandArgs.execute()
|
|
90
|
+
static String exec(String[] commandArgs, File dir) {
|
|
91
|
+
Process proc = commandArgs.execute(null, dir)
|
|
92
92
|
StringBuffer outputStream = new StringBuffer()
|
|
93
93
|
proc.waitForProcessOutput(outputStream, System.err)
|
|
94
94
|
return outputStream.toString()
|
|
@@ -166,6 +166,7 @@ if (rootProject instanceof ProjectDescriptor) {
|
|
|
166
166
|
return
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
println ''
|
|
169
170
|
println 'Using expo modules'
|
|
170
171
|
|
|
171
172
|
for (module in modules) {
|
|
@@ -181,8 +182,10 @@ if (rootProject instanceof ProjectDescriptor) {
|
|
|
181
182
|
continue
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
println "
|
|
185
|
+
println " - ${Colors.GREEN}${module.name}${Colors.RESET} (${module.version})"
|
|
185
186
|
}
|
|
187
|
+
|
|
188
|
+
println ''
|
|
186
189
|
}
|
|
187
190
|
|
|
188
191
|
// Adding dependencies
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# Overrides CocoaPods `Sandbox` class to patch podspecs on the fly
|
|
2
|
+
# See: https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/sandbox.rb
|
|
3
|
+
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
module Pod
|
|
7
|
+
class Sandbox
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
_original_store_podspec = instance_method(:store_podspec)
|
|
11
|
+
|
|
12
|
+
public
|
|
13
|
+
|
|
14
|
+
define_method(:store_podspec) do |name, podspec, _external_source, json|
|
|
15
|
+
spec = _original_store_podspec.bind(self).(name, podspec, _external_source, json)
|
|
16
|
+
patched_spec = nil
|
|
17
|
+
|
|
18
|
+
# Patch `React-Core.podspec` for clang to generate correct submodules for swift integration
|
|
19
|
+
if name == 'React-Core'
|
|
20
|
+
spec_json = JSON.parse(spec.to_pretty_json)
|
|
21
|
+
|
|
22
|
+
# CocoaPods's default modulemap did not generate submodules correctly
|
|
23
|
+
# `ios/Pods/Headers/Public/React/React-Core.modulemap`
|
|
24
|
+
# ```
|
|
25
|
+
# module React {
|
|
26
|
+
# umbrella header "React-Core-umbrella.h"
|
|
27
|
+
#
|
|
28
|
+
# export *
|
|
29
|
+
# module * { export * }
|
|
30
|
+
# }
|
|
31
|
+
# ```
|
|
32
|
+
# clang will generate submodules for headers relative to the umbrella header directory.
|
|
33
|
+
# https://github.com/llvm/llvm-project/blob/2782cb8da0b3c180fa7c8627cb255a026f3d25a2/clang/lib/Lex/ModuleMap.cpp#L1133
|
|
34
|
+
# In this case, it is `ios/Pods/Headers/Public/React`.
|
|
35
|
+
# But React headers are placed in `ios/Pods/Headers/Public/React-Core/React`, so clang cannot find the headers and generate submodules.
|
|
36
|
+
# We patch `React-Core.podspec` to use custom modulemap and use `umbrella "../../Public/React-Core/React"` for clang to generate submodules correctly.
|
|
37
|
+
# Since CocoaPods generates the umbrella headers based on public headers,
|
|
38
|
+
# it is pretty safe to replace the umbrella header with the `umbrella` directory search inside the public headers directory.
|
|
39
|
+
spec_json['module_map'] ||= File.join(__dir__, '..', 'React-Core.modulemap')
|
|
40
|
+
|
|
41
|
+
# clang module does not support objc++.
|
|
42
|
+
# We should put Hermes headers inside private headers directory.
|
|
43
|
+
# Otherwise, clang will throw errors in building module.
|
|
44
|
+
hermes_subspec_index = spec_json['subspecs'].index { |subspec| subspec['name'] == 'Hermes' }
|
|
45
|
+
if hermes_subspec_index
|
|
46
|
+
spec_json['subspecs'][hermes_subspec_index]['private_header_files'] ||= [
|
|
47
|
+
'ReactCommon/hermes/executor/*.h',
|
|
48
|
+
'ReactCommon/hermes/inspector/*.h',
|
|
49
|
+
'ReactCommon/hermes/inspector/chrome/*.h',
|
|
50
|
+
'ReactCommon/hermes/inspector/detail/*.h',
|
|
51
|
+
]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
patched_spec = Specification.from_json(spec_json.to_json)
|
|
55
|
+
|
|
56
|
+
# Patch `ReactCommon.podspec` to define module
|
|
57
|
+
elsif name == 'ReactCommon'
|
|
58
|
+
spec_json = JSON.parse(podspec.to_pretty_json)
|
|
59
|
+
spec_json['pod_target_xcconfig']['DEFINES_MODULE'] = 'YES'
|
|
60
|
+
patched_spec = Specification.from_json(spec_json.to_json)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
if patched_spec != nil
|
|
64
|
+
# Store the patched spec with original checksum and local saved file path
|
|
65
|
+
patched_spec.defined_in_file = spec.defined_in_file
|
|
66
|
+
patched_spec.instance_variable_set(:@checksum, spec.checksum)
|
|
67
|
+
@stored_podspecs[spec.name] = patched_spec
|
|
68
|
+
return patched_spec
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
return spec
|
|
72
|
+
end # define_method(:store_podspec)
|
|
73
|
+
|
|
74
|
+
end # class Sandbox
|
|
75
|
+
end # module Pod
|
package/src/ExpoModuleConfig.ts
CHANGED
|
@@ -20,6 +20,34 @@ export class ExpoModuleConfig {
|
|
|
20
20
|
return this.rawConfig.ios?.modulesClassNames ?? [];
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
/**
|
|
24
|
+
* Returns a list of names of Swift classes that receives AppDelegate life-cycle events.
|
|
25
|
+
*/
|
|
26
|
+
iosAppDelegateSubscribers(): string[] {
|
|
27
|
+
return this.rawConfig.ios?.appDelegateSubscribers ?? [];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Returns a list of names of Swift classes that implement `ExpoReactDelegateHandler`.
|
|
32
|
+
*/
|
|
33
|
+
iosReactDelegateHandlers(): string[] {
|
|
34
|
+
return this.rawConfig.ios?.reactDelegateHandlers ?? [];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Returns a podspec path defined by the module author.
|
|
39
|
+
*/
|
|
40
|
+
iosPodspecPath(): string | undefined {
|
|
41
|
+
return this.rawConfig.ios?.podspecPath;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Returns a list of names of Kotlin native modules classes to put to the generated package provider file.
|
|
46
|
+
*/
|
|
47
|
+
androidModulesClassNames() {
|
|
48
|
+
return this.rawConfig.android?.modulesClassNames ?? [];
|
|
49
|
+
}
|
|
50
|
+
|
|
23
51
|
/**
|
|
24
52
|
* Returns serializable raw config.
|
|
25
53
|
*/
|
package/src/autolinking.ts
CHANGED
|
@@ -127,13 +127,16 @@ export async function findModulesAsync(providedOptions: SearchOptions): Promise<
|
|
|
127
127
|
if (options.searchPaths.length <= 1) {
|
|
128
128
|
return results;
|
|
129
129
|
}
|
|
130
|
-
return filterToProjectDependencies(results);
|
|
130
|
+
return filterToProjectDependencies(results, providedOptions);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
/**
|
|
134
134
|
* Filters out packages that are not the dependencies of the project.
|
|
135
135
|
*/
|
|
136
|
-
function filterToProjectDependencies(
|
|
136
|
+
function filterToProjectDependencies(
|
|
137
|
+
results: SearchResults,
|
|
138
|
+
options: Pick<SearchOptions, 'silent'> = {}
|
|
139
|
+
) {
|
|
137
140
|
const filteredResults: SearchResults = {};
|
|
138
141
|
const visitedPackages = new Set<string>();
|
|
139
142
|
|
|
@@ -160,11 +163,11 @@ function filterToProjectDependencies(results: SearchResults) {
|
|
|
160
163
|
} else {
|
|
161
164
|
try {
|
|
162
165
|
dependencyPackageJsonPath = projectRequire.resolve(`${dependencyName}/package.json`);
|
|
163
|
-
} catch (error) {
|
|
166
|
+
} catch (error: any) {
|
|
164
167
|
// Some packages don't include package.json in its `exports` field,
|
|
165
168
|
// but none of our packages do that, so it seems fine to just ignore that type of error.
|
|
166
169
|
// Related issue: https://github.com/react-native-community/cli/issues/1168
|
|
167
|
-
if (error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
170
|
+
if (!options.silent && error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
168
171
|
console.warn(
|
|
169
172
|
chalk.yellow(`⚠️ Cannot resolve the path to "${dependencyName}" package.`)
|
|
170
173
|
);
|
|
@@ -285,6 +288,7 @@ export async function generatePackageListAsync(
|
|
|
285
288
|
console.error(
|
|
286
289
|
chalk.red(`Generating package list is not available for platform: ${options.platform}`)
|
|
287
290
|
);
|
|
291
|
+
throw e;
|
|
288
292
|
}
|
|
289
293
|
}
|
|
290
294
|
|
package/src/index.ts
CHANGED
|
@@ -33,6 +33,7 @@ function registerSearchCommand<OptionsType extends SearchOptions>(
|
|
|
33
33
|
'The platform that the resulting modules must support. Available options: "ios", "android"',
|
|
34
34
|
'ios'
|
|
35
35
|
)
|
|
36
|
+
.option('--silent', 'Silence resolution warnings')
|
|
36
37
|
.action(async (searchPaths, providedOptions) => {
|
|
37
38
|
const options = await mergeLinkingOptionsAsync<OptionsType>({
|
|
38
39
|
...providedOptions,
|
package/src/platforms/android.ts
CHANGED
|
@@ -42,6 +42,7 @@ export async function resolveModuleAsync(
|
|
|
42
42
|
return {
|
|
43
43
|
projectName: convertPackageNameToProjectName(packageName),
|
|
44
44
|
sourceDir,
|
|
45
|
+
modulesClassNames: revision.config?.androidModulesClassNames(),
|
|
45
46
|
};
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -57,32 +58,51 @@ async function generatePackageListFileContentAsync(
|
|
|
57
58
|
modules.filter((module) => module.packageName !== 'expo')
|
|
58
59
|
);
|
|
59
60
|
|
|
61
|
+
const modulesClasses = await findAndroidModules(modules);
|
|
62
|
+
|
|
60
63
|
return `package ${namespace};
|
|
61
64
|
|
|
62
65
|
import java.util.Arrays;
|
|
63
66
|
import java.util.List;
|
|
64
67
|
import expo.modules.core.interfaces.Package;
|
|
68
|
+
import expo.modules.kotlin.modules.Module;
|
|
69
|
+
import expo.modules.kotlin.ModulesProvider;
|
|
65
70
|
|
|
66
|
-
public class ExpoModulesPackageList {
|
|
71
|
+
public class ExpoModulesPackageList implements ModulesProvider {
|
|
67
72
|
private static class LazyHolder {
|
|
68
73
|
static final List<Package> packagesList = Arrays.<Package>asList(
|
|
69
74
|
${packagesClasses.map((packageClass) => ` new ${packageClass}()`).join(',\n')}
|
|
70
75
|
);
|
|
76
|
+
|
|
77
|
+
static final List<Class<? extends Module>> modulesList = Arrays.<Class<? extends Module>>asList(
|
|
78
|
+
${modulesClasses.map((moduleClass) => ` ${moduleClass}.class`).join(',\n')}
|
|
79
|
+
);
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
public static List<Package> getPackageList() {
|
|
74
83
|
return LazyHolder.packagesList;
|
|
75
84
|
}
|
|
85
|
+
|
|
86
|
+
@Override
|
|
87
|
+
public List<Class<? extends Module>> getModulesList() {
|
|
88
|
+
return LazyHolder.modulesList;
|
|
89
|
+
}
|
|
76
90
|
}
|
|
77
91
|
`;
|
|
78
92
|
}
|
|
79
93
|
|
|
94
|
+
function findAndroidModules(modules: ModuleDescriptor[]): string[] {
|
|
95
|
+
const modulesToProvide = modules.filter((module) => module.modulesClassNames.length > 0);
|
|
96
|
+
const classNames = [].concat(...modulesToProvide.map((module) => module.modulesClassNames));
|
|
97
|
+
return classNames;
|
|
98
|
+
}
|
|
99
|
+
|
|
80
100
|
async function findAndroidPackagesAsync(modules: ModuleDescriptor[]): Promise<string[]> {
|
|
81
101
|
const classes: string[] = [];
|
|
82
102
|
|
|
83
103
|
await Promise.all(
|
|
84
104
|
modules.map(async (module) => {
|
|
85
|
-
const files = await glob('
|
|
105
|
+
const files = await glob('**/*Package.{java,kt}', {
|
|
86
106
|
cwd: module.sourceDir,
|
|
87
107
|
});
|
|
88
108
|
|
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>;
|
|
@@ -53,5 +54,30 @@ export interface RawExpoModuleConfig {
|
|
|
53
54
|
* Names of Swift native modules classes to put to the generated modules provider file.
|
|
54
55
|
*/
|
|
55
56
|
modulesClassNames?: string[];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.
|
|
60
|
+
*/
|
|
61
|
+
appDelegateSubscribers?: string[];
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Names of Swift classes that implement `ExpoReactDelegateHandler` to hook React instance creation.
|
|
65
|
+
*/
|
|
66
|
+
reactDelegateHandlers?: string[];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Podspec relative path.
|
|
70
|
+
*/
|
|
71
|
+
podspecPath?: string;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Android-specific config.
|
|
76
|
+
*/
|
|
77
|
+
android?: {
|
|
78
|
+
/**
|
|
79
|
+
* Full names (package + class name) of Kotlin native modules classes to put to the generated package provider file.
|
|
80
|
+
*/
|
|
81
|
+
modulesClassNames?: string[];
|
|
56
82
|
};
|
|
57
83
|
}
|