expo-modules-autolinking 0.4.0 → 0.5.3
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 +23 -0
- package/build/ExpoModuleConfig.d.ts +8 -0
- package/build/ExpoModuleConfig.js +14 -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/index.js +10 -0
- package/build/index.js.map +1 -1
- package/build/platforms/ios.d.ts +4 -0
- package/build/platforms/ios.js +38 -7
- package/build/platforms/ios.js.map +1 -1
- package/build/types.d.ts +12 -0
- package/build/types.js.map +1 -1
- package/package.json +2 -2
- package/scripts/ios/React-Core.modulemap +6 -0
- package/scripts/ios/autolinking_manager.rb +1 -1
- package/scripts/ios/cocoapods/sandbox.rb +75 -0
- package/scripts/ios/react_import_patcher.rb +66 -0
- package/src/ExpoModuleConfig.ts +14 -0
- package/src/ReactImportsPatcher.ts +78 -0
- package/src/index.ts +12 -0
- package/src/platforms/ios.ts +42 -6
- package/src/types.ts +15 -0
- package/tsconfig.json +2 -1
- package/scripts/ios/cocoapods/pod_target.rb +0 -38
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,28 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 0.5.3 — 2021-12-28
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Fix `expo_patch_react_imports!` error when there are pods with absolute path. ([#15699](https://github.com/expo/expo/pull/15699) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
19
|
+
## 0.5.2 — 2021-12-22
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- Introduce `expo_patch_react_imports!` to transform double-quoted React imports into angle-brackets in order to fix third-party libraries incompatibility with SDK 44. ([#15655](https://github.com/expo/expo/pull/15655) by [@kudo](https://github.com/kudo))
|
|
24
|
+
|
|
25
|
+
## 0.5.1 — 2021-12-15
|
|
26
|
+
|
|
27
|
+
_This version does not introduce any user-facing changes._
|
|
28
|
+
|
|
29
|
+
## 0.5.0 — 2021-12-03
|
|
30
|
+
|
|
31
|
+
### 🎉 New features
|
|
32
|
+
|
|
33
|
+
- Patch React podspecs on the fly to support Swift integration. ([#15299](https://github.com/expo/expo/pull/15299) by [@kudo](https://github.com/kudo))
|
|
34
|
+
|
|
13
35
|
## 0.4.0 — 2021-11-17
|
|
14
36
|
|
|
15
37
|
### 🎉 New features
|
|
@@ -17,6 +39,7 @@
|
|
|
17
39
|
- Added "silent" property for silencing resolution warnings. ([#14891](https://github.com/expo/expo/pull/14891) by [@EvanBacon](https://github.com/EvanBacon))
|
|
18
40
|
- 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))
|
|
19
41
|
- 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))
|
|
42
|
+
- Introduce React Native bridge delegate handlers on iOS. ([#15138](https://github.com/expo/expo/pull/15138) by [@kudo](https://github.com/kudo))
|
|
20
43
|
|
|
21
44
|
### 🐛 Bug fixes
|
|
22
45
|
|
|
@@ -17,6 +17,14 @@ export declare class ExpoModuleConfig {
|
|
|
17
17
|
* Returns a list of names of Swift classes that receives AppDelegate life-cycle events.
|
|
18
18
|
*/
|
|
19
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;
|
|
20
28
|
/**
|
|
21
29
|
* Returns a list of names of Kotlin native modules classes to put to the generated package provider file.
|
|
22
30
|
*/
|
|
@@ -29,6 +29,20 @@ class ExpoModuleConfig {
|
|
|
29
29
|
var _a, _b;
|
|
30
30
|
return (_b = (_a = this.rawConfig.ios) === null || _a === void 0 ? void 0 : _a.appDelegateSubscribers) !== null && _b !== void 0 ? _b : [];
|
|
31
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
|
+
}
|
|
32
46
|
/**
|
|
33
47
|
* Returns a list of names of Kotlin native modules classes to put to the generated package provider file.
|
|
34
48
|
*/
|
|
@@ -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,E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AAO,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"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { PatchReactImportsOptions } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Remove all double-quoted react header imports
|
|
4
|
+
* @param dirs target directories to patch
|
|
5
|
+
* @param options PatchReactImportsOptions
|
|
6
|
+
*/
|
|
7
|
+
export declare function patchReactImportsAsync(dirs: string[], options: PatchReactImportsOptions): Promise<void>;
|
|
8
|
+
/**
|
|
9
|
+
* Patch imports from a file
|
|
10
|
+
* @param headerSet prebuilt React-Core header set
|
|
11
|
+
* @param file target patch file
|
|
12
|
+
* @param dryRun true if not writing changes to file
|
|
13
|
+
*/
|
|
14
|
+
export declare function patchFileAsync(headerSet: Set<string>, file: string, dryRun: boolean): Promise<void>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.patchFileAsync = exports.patchReactImportsAsync = void 0;
|
|
8
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
10
|
+
const path_1 = __importDefault(require("path"));
|
|
11
|
+
/**
|
|
12
|
+
* Remove all double-quoted react header imports
|
|
13
|
+
* @param dirs target directories to patch
|
|
14
|
+
* @param options PatchReactImportsOptions
|
|
15
|
+
*/
|
|
16
|
+
async function patchReactImportsAsync(dirs, options) {
|
|
17
|
+
const headerSet = await generateReactHeaderSetAsync(path_1.default.join(options.podsRoot, 'Headers', 'Public', 'React-Core', 'React'));
|
|
18
|
+
await Promise.all(dirs.map((dir) => patchDirAsync(headerSet, dir, options.dryRun)));
|
|
19
|
+
}
|
|
20
|
+
exports.patchReactImportsAsync = patchReactImportsAsync;
|
|
21
|
+
/**
|
|
22
|
+
* Generate `React-Core` public header names as a set, will transform necessary headers based on this set.
|
|
23
|
+
*/
|
|
24
|
+
async function generateReactHeaderSetAsync(reactHeaderDir) {
|
|
25
|
+
const files = await (0, fast_glob_1.default)('*.h', { cwd: reactHeaderDir });
|
|
26
|
+
return new Set(files);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Patch imports from a file
|
|
30
|
+
* @param headerSet prebuilt React-Core header set
|
|
31
|
+
* @param file target patch file
|
|
32
|
+
* @param dryRun true if not writing changes to file
|
|
33
|
+
*/
|
|
34
|
+
async function patchFileAsync(headerSet, file, dryRun) {
|
|
35
|
+
let changed = false;
|
|
36
|
+
const content = await fs_extra_1.default.readFile(file, 'utf-8');
|
|
37
|
+
const transformContent = content.replace(/^#import\s+"(.+)"$/gm, (match, headerName) => {
|
|
38
|
+
// `#import "RCTBridge.h"` -> `#import <React/RCTBridge.h>`
|
|
39
|
+
if (headerSet.has(headerName)) {
|
|
40
|
+
changed = true;
|
|
41
|
+
return `#import <React/${headerName}>`;
|
|
42
|
+
}
|
|
43
|
+
// `#import "React/RCTBridge.h"` -> `#import <React/RCTBridge.h>`
|
|
44
|
+
if (headerName.startsWith('React/')) {
|
|
45
|
+
const name = headerName.substring(6);
|
|
46
|
+
if (headerSet.has(name)) {
|
|
47
|
+
changed = true;
|
|
48
|
+
return `#import <React/${name}>`;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// Otherwise, return original import
|
|
52
|
+
return match;
|
|
53
|
+
});
|
|
54
|
+
if (changed) {
|
|
55
|
+
console.log(`Patching imports for file: ${file}`);
|
|
56
|
+
}
|
|
57
|
+
if (!dryRun) {
|
|
58
|
+
await fs_extra_1.default.writeFile(file, transformContent);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.patchFileAsync = patchFileAsync;
|
|
62
|
+
/**
|
|
63
|
+
* Patch imports from a directory
|
|
64
|
+
* @param headerSet prebuilt React-Core header set
|
|
65
|
+
* @param file target patch file
|
|
66
|
+
* @param dryRun true if not writing changes to file
|
|
67
|
+
*/
|
|
68
|
+
async function patchDirAsync(headerSet, dir, dryRun) {
|
|
69
|
+
const files = await (0, fast_glob_1.default)('**/*.{h,m,mm}', { cwd: dir, absolute: true });
|
|
70
|
+
return Promise.all(files.map((file) => patchFileAsync(headerSet, file, dryRun)));
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=ReactImportsPatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactImportsPatcher.js","sourceRoot":"","sources":["../src/ReactImportsPatcher.ts"],"names":[],"mappings":";AAAA,8DAA8D;;;;;;AAE9D,0DAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAIxB;;;;GAIG;AACI,KAAK,UAAU,sBAAsB,CAAC,IAAc,EAAE,OAAiC;IAC5F,MAAM,SAAS,GAAG,MAAM,2BAA2B,CACjD,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,CACxE,CAAC;IACF,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;AACtF,CAAC;AALD,wDAKC;AAED;;GAEG;AACH,KAAK,UAAU,2BAA2B,CAAC,cAAsB;IAC/D,MAAM,KAAK,GAAG,MAAM,IAAA,mBAAI,EAAC,KAAK,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,CAAC,CAAC;IACzD,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;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,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,SAAS,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;AACnF,CAAC","sourcesContent":["// Copyright 2018-present 650 Industries. All rights reserved.\n\nimport glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { PatchReactImportsOptions } from './types';\n\n/**\n * Remove all double-quoted react header imports\n * @param dirs target directories to patch\n * @param options PatchReactImportsOptions\n */\nexport async function patchReactImportsAsync(dirs: string[], options: PatchReactImportsOptions) {\n const headerSet = await generateReactHeaderSetAsync(\n path.join(options.podsRoot, 'Headers', 'Public', 'React-Core', 'React')\n );\n await Promise.all(dirs.map((dir) => patchDirAsync(headerSet, dir, options.dryRun)));\n}\n\n/**\n * Generate `React-Core` public header names as a set, will transform necessary headers based on this set.\n */\nasync function generateReactHeaderSetAsync(reactHeaderDir: string): Promise<Set<string>> {\n const files = await glob('*.h', { cwd: reactHeaderDir });\n return new Set(files);\n}\n\n/**\n * Patch imports from a file\n * @param headerSet prebuilt React-Core header set\n * @param file target patch file\n * @param dryRun true if not writing changes to file\n */\nexport async function patchFileAsync(headerSet: Set<string>, file: string, dryRun: boolean) {\n let changed = false;\n const content = await fs.readFile(file, 'utf-8');\n const transformContent = content.replace(\n /^#import\\s+\"(.+)\"$/gm,\n (match: string, headerName: string): string => {\n // `#import \"RCTBridge.h\"` -> `#import <React/RCTBridge.h>`\n if (headerSet.has(headerName)) {\n changed = true;\n return `#import <React/${headerName}>`;\n }\n\n // `#import \"React/RCTBridge.h\"` -> `#import <React/RCTBridge.h>`\n if (headerName.startsWith('React/')) {\n const name = headerName.substring(6);\n if (headerSet.has(name)) {\n changed = true;\n return `#import <React/${name}>`;\n }\n }\n\n // Otherwise, return original import\n return match;\n }\n );\n\n if (changed) {\n console.log(`Patching imports for file: ${file}`);\n }\n if (!dryRun) {\n await fs.writeFile(file, transformContent);\n }\n}\n\n/**\n * Patch imports from a directory\n * @param headerSet prebuilt React-Core header set\n * @param file target patch file\n * @param dryRun true if not writing changes to file\n */\nasync function patchDirAsync(headerSet: Set<string>, dir: string, dryRun: boolean) {\n const files = await glob('**/*.{h,m,mm}', { cwd: dir, absolute: true });\n return Promise.all(files.map((file) => patchFileAsync(headerSet, file, dryRun)));\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const commander_1 = __importDefault(require("commander"));
|
|
7
|
+
const ReactImportsPatcher_1 = require("./ReactImportsPatcher");
|
|
7
8
|
const autolinking_1 = require("./autolinking");
|
|
8
9
|
/**
|
|
9
10
|
* Registers a command that only searches for available expo modules.
|
|
@@ -30,6 +31,14 @@ function registerSearchCommand(commandName, fn) {
|
|
|
30
31
|
function registerResolveCommand(commandName, fn) {
|
|
31
32
|
return registerSearchCommand(commandName, fn);
|
|
32
33
|
}
|
|
34
|
+
// Register for `patch-react-imports` command
|
|
35
|
+
function registerPatchReactImportsCommand() {
|
|
36
|
+
return commander_1.default
|
|
37
|
+
.command('patch-react-imports [paths...]')
|
|
38
|
+
.requiredOption('--pods-root <podsRoot>', 'The path to `Pods` directory')
|
|
39
|
+
.option('--dry-run', 'Only list files without writing changes to the file system')
|
|
40
|
+
.action(ReactImportsPatcher_1.patchReactImportsAsync);
|
|
41
|
+
}
|
|
33
42
|
module.exports = async function (args) {
|
|
34
43
|
// Searches for available expo modules.
|
|
35
44
|
registerSearchCommand('search', async (results, options) => {
|
|
@@ -65,6 +74,7 @@ module.exports = async function (args) {
|
|
|
65
74
|
.option('-t, --target <path>', 'Path to the target file, where the package list should be written to.')
|
|
66
75
|
.option('-n, --namespace <namespace>', 'Java package name under which the package list should be placed.')
|
|
67
76
|
.option('--empty', 'Whether to only generate an empty list. Might be used when the user opts-out of autolinking.', false);
|
|
77
|
+
registerPatchReactImportsCommand();
|
|
68
78
|
await commander_1.default
|
|
69
79
|
.version(require('expo-modules-autolinking/package.json').version)
|
|
70
80
|
.description('CLI command that searches for Expo modules to autolink them.')
|
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,UAAU,EAAE,6BAA6B,CAAC;SACjD,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,MAAM,IAAA,sCAAwB,EAAc;YAC1D,GAAG,eAAe;YAClB,WAAW;SACZ,CAAC,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,IAAA,8BAAgB,EAAC,OAAO,CAAC,CAAC;QACtD,OAAO,MAAM,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAC7B,WAAm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,CAAC,CAAC,CAAC,MAAM,CAAU,YAAY,EAAE,0CAA0C,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAEhG,wDAAwD;IACxD,sBAAsB,CAAkB,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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAElC,+DAA+D;AAC/D,+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,UAAU,EAAE,6BAA6B,CAAC;SACjD,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE;QAC7C,MAAM,OAAO,GAAG,MAAM,IAAA,sCAAwB,EAAc;YAC1D,GAAG,eAAe;YAClB,WAAW;SACZ,CAAC,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,IAAA,8BAAgB,EAAC,OAAO,CAAC,CAAC;QACtD,OAAO,MAAM,EAAE,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;GAEG;AACH,SAAS,sBAAsB,CAC7B,WAAmB,EACnB,EAAwD;IAExD,OAAO,qBAAqB,CAAc,WAAW,EAAE,EAAE,CAAC,CAAC;A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AAG,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;SAC1C;aAAM;YACL,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;SAC1B;IACH,CAAC,CAAC,CAAC,MAAM,CAAU,YAAY,EAAE,0CAA0C,EAAE,GAAG,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAEhG,wDAAwD;IACxD,sBAAsB,CAAkB,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,gCAAgC,EAAE,CAAC;IAEnC,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 { patchReactImportsAsync } from './ReactImportsPatcher';\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\n// Register for `patch-react-imports` command\nfunction registerPatchReactImportsCommand() {\n return commander\n .command('patch-react-imports [paths...]')\n .requiredOption('--pods-root <podsRoot>', 'The path to `Pods` directory')\n .option('--dry-run', 'Only list files without writing changes to the file system')\n .action(patchReactImportsAsync);\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 registerPatchReactImportsCommand();\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"]}
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
async function findPodspecFile(revision) {
|
|
11
|
+
var _a;
|
|
12
|
+
if ((_a = revision.config) === null || _a === void 0 ? void 0 : _a.iosPodspecPath()) {
|
|
13
|
+
return revision.config.iosPodspecPath();
|
|
14
|
+
}
|
|
15
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
|
}
|
|
@@ -27,6 +35,7 @@ async function resolveModuleAsync(packageName, revision, options) {
|
|
|
27
35
|
flags: options.flags,
|
|
28
36
|
modulesClassNames: (_a = revision.config) === null || _a === void 0 ? void 0 : _a.iosModulesClassNames(),
|
|
29
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(),
|
|
30
39
|
};
|
|
31
40
|
}
|
|
32
41
|
exports.resolveModuleAsync = resolveModuleAsync;
|
|
@@ -43,7 +52,9 @@ exports.generatePackageListAsync = generatePackageListAsync;
|
|
|
43
52
|
* Generates the string to put into the generated package list.
|
|
44
53
|
*/
|
|
45
54
|
async function generatePackageListFileContentAsync(modules, className) {
|
|
46
|
-
const modulesToImport = modules.filter((module) => module.modulesClassNames.length
|
|
55
|
+
const modulesToImport = modules.filter((module) => module.modulesClassNames.length ||
|
|
56
|
+
module.appDelegateSubscribers.length ||
|
|
57
|
+
module.reactDelegateHandlers.length);
|
|
47
58
|
const pods = modulesToImport.map((module) => module.podName);
|
|
48
59
|
const modulesClassNames = []
|
|
49
60
|
.concat(...modulesToImport.map((module) => module.modulesClassNames))
|
|
@@ -51,6 +62,7 @@ async function generatePackageListFileContentAsync(modules, className) {
|
|
|
51
62
|
const appDelegateSubscribers = []
|
|
52
63
|
.concat(...modulesToImport.map((module) => module.appDelegateSubscribers))
|
|
53
64
|
.filter(Boolean);
|
|
65
|
+
const reactDelegateHandlerModules = modulesToImport.filter((module) => !!module.reactDelegateHandlers.length);
|
|
54
66
|
return `/**
|
|
55
67
|
* Automatically generated by expo-modules-autolinking.
|
|
56
68
|
*
|
|
@@ -69,6 +81,10 @@ public class ${className}: ModulesProvider {
|
|
|
69
81
|
public override func getAppDelegateSubscribers() -> [ExpoAppDelegateSubscriber.Type] {
|
|
70
82
|
return ${formatArrayOfClassNames(appDelegateSubscribers)}
|
|
71
83
|
}
|
|
84
|
+
|
|
85
|
+
public override func getReactDelegateHandlers() -> [ExpoReactDelegateHandlerTupleType] {
|
|
86
|
+
return ${formatArrayOfReactDelegateHandler(reactDelegateHandlerModules)}
|
|
87
|
+
}
|
|
72
88
|
}
|
|
73
89
|
`;
|
|
74
90
|
}
|
|
@@ -80,4 +96,19 @@ function formatArrayOfClassNames(classNames) {
|
|
|
80
96
|
return `[${classNames.map((className) => `\n${indent.repeat(3)}${className}.self`).join(',')}
|
|
81
97
|
${indent.repeat(2)}]`;
|
|
82
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;
|
|
83
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,eAAe,CAAC,QAAyB;;IACtD,IAAI,MAAA,QAAQ,CAAC,MAAM,0CAAE,cAAc,EAAE,EAAE;QACrC,OAAO,QAAQ,CAAC,MAAM,CAAC,cAAc,EAAE,CAAC;KACzC;IAED,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,IAAA,mBAAI,EAAC,aAAa,EAAE;QAC9C,GAAG,EAAE,QAAQ,CAAC,IAAI;QAClB,MAAM,EAAE,CAAC,oBAAoB,CAAC;KAC/B,CAAC,CAAC;IAEH,OAAO,WAAW,CAAC;AACrB,CAAC;AAED;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,WAAmB,EACnB,QAAyB,EACzB,OAAsB;;IAEtB,MAAM,WAAW,GAAG,MAAM,eAAe,CAAC,QAAQ,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE;QAChB,OAAO,IAAI,CAAC;KACb;IAED,MAAM,OAAO,GAAG,cAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,cAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC;IACtE,MAAM,UAAU,GAAG,cAAI,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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
|
@@ -16,6 +16,10 @@ export interface GenerateOptions extends ResolveOptions {
|
|
|
16
16
|
namespace?: string;
|
|
17
17
|
empty?: boolean;
|
|
18
18
|
}
|
|
19
|
+
export interface PatchReactImportsOptions {
|
|
20
|
+
podsRoot: string;
|
|
21
|
+
dryRun: boolean;
|
|
22
|
+
}
|
|
19
23
|
export declare type PackageRevision = {
|
|
20
24
|
path: string;
|
|
21
25
|
version: string;
|
|
@@ -46,6 +50,14 @@ export interface RawExpoModuleConfig {
|
|
|
46
50
|
* Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.
|
|
47
51
|
*/
|
|
48
52
|
appDelegateSubscribers?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* Names of Swift classes that implement `ExpoReactDelegateHandler` to hook React instance creation.
|
|
55
|
+
*/
|
|
56
|
+
reactDelegateHandlers?: string[];
|
|
57
|
+
/**
|
|
58
|
+
* Podspec relative path.
|
|
59
|
+
*/
|
|
60
|
+
podspecPath?: string;
|
|
49
61
|
};
|
|
50
62
|
/**
|
|
51
63
|
* Android-specific config.
|
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 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 /**\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"]}
|
|
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 interface PatchReactImportsOptions {\n podsRoot: string;\n dryRun: 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.3",
|
|
4
4
|
"description": "Scripts that autolink Expo modules.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"find-up": "^5.0.0",
|
|
48
48
|
"fs-extra": "^9.1.0"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "17fe5449b2edaf40c631180e6b817cc4f502d331"
|
|
51
51
|
}
|
|
@@ -2,7 +2,7 @@ require_relative 'constants'
|
|
|
2
2
|
require_relative 'package'
|
|
3
3
|
|
|
4
4
|
# Require extensions to CocoaPods' classes
|
|
5
|
-
require_relative 'cocoapods/
|
|
5
|
+
require_relative 'cocoapods/sandbox'
|
|
6
6
|
require_relative 'cocoapods/target_definition'
|
|
7
7
|
require_relative 'cocoapods/user_project_integrator'
|
|
8
8
|
|
|
@@ -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
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
module Expo
|
|
4
|
+
class ReactImportPatcher
|
|
5
|
+
|
|
6
|
+
public def initialize(installer, options)
|
|
7
|
+
@root = installer.sandbox.root
|
|
8
|
+
@module_dirs = get_module_dirs(installer)
|
|
9
|
+
@options = options
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
public def run!
|
|
13
|
+
args = [
|
|
14
|
+
'node',
|
|
15
|
+
'--eval',
|
|
16
|
+
'require(\'expo-modules-autolinking\')(process.argv.slice(1))',
|
|
17
|
+
'patch-react-imports',
|
|
18
|
+
'--pods-root',
|
|
19
|
+
Shellwords.escape(File.expand_path(@root)),
|
|
20
|
+
]
|
|
21
|
+
|
|
22
|
+
if @options[:dry_run]
|
|
23
|
+
args.append('--dry-run')
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
@module_dirs.each do |dir|
|
|
27
|
+
args.append(Shellwords.escape(File.expand_path(dir)))
|
|
28
|
+
end
|
|
29
|
+
Pod::UI.message "Executing ReactImportsPatcher node command: #{args.join(' ')}"
|
|
30
|
+
|
|
31
|
+
time_begin = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
32
|
+
system(*args)
|
|
33
|
+
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - time_begin
|
|
34
|
+
Pod::UI.info "expo_patch_react_imports! took #{elapsed_time.round(4)} seconds to transform files."
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private def get_module_dirs(installer)
|
|
38
|
+
unless installer.pods_project
|
|
39
|
+
Pod::UI.message '`pods_project` not found. This is expected when `:incremental_installation` is enabled in your project\'s Podfile.'
|
|
40
|
+
return []
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
result = []
|
|
44
|
+
installer.pods_project.development_pods.children.each do |pod|
|
|
45
|
+
if pod.is_a?(Xcodeproj::Project::Object::PBXFileReference) && pod.path.end_with?('.xcodeproj')
|
|
46
|
+
# Support generate_multiple_pod_projects or use_frameworks!
|
|
47
|
+
project = Xcodeproj::Project.open(File.join(installer.sandbox.root, pod.path))
|
|
48
|
+
groups = project.groups.select { |group| !(['Dependencies', 'Frameworks', 'Products'].include? group.name) }
|
|
49
|
+
groups.each do |group|
|
|
50
|
+
result.append(group.real_path.to_s)
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
result.append(pod.real_path.to_s)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
return result.select { |dir|
|
|
58
|
+
# Exclude known dirs unnecessary to patch and reduce processing time
|
|
59
|
+
!dir.include?('/react-native/') &&
|
|
60
|
+
!dir.end_with?('/react-native') &&
|
|
61
|
+
!dir.include?('/expo-')
|
|
62
|
+
}
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
end # class ReactImportPatcher
|
|
66
|
+
end # module Expo
|
package/src/ExpoModuleConfig.ts
CHANGED
|
@@ -27,6 +27,20 @@ export class ExpoModuleConfig {
|
|
|
27
27
|
return this.rawConfig.ios?.appDelegateSubscribers ?? [];
|
|
28
28
|
}
|
|
29
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
|
+
|
|
30
44
|
/**
|
|
31
45
|
* Returns a list of names of Kotlin native modules classes to put to the generated package provider file.
|
|
32
46
|
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Copyright 2018-present 650 Industries. All rights reserved.
|
|
2
|
+
|
|
3
|
+
import glob from 'fast-glob';
|
|
4
|
+
import fs from 'fs-extra';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
|
|
7
|
+
import { PatchReactImportsOptions } from './types';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Remove all double-quoted react header imports
|
|
11
|
+
* @param dirs target directories to patch
|
|
12
|
+
* @param options PatchReactImportsOptions
|
|
13
|
+
*/
|
|
14
|
+
export async function patchReactImportsAsync(dirs: string[], options: PatchReactImportsOptions) {
|
|
15
|
+
const headerSet = await generateReactHeaderSetAsync(
|
|
16
|
+
path.join(options.podsRoot, 'Headers', 'Public', 'React-Core', 'React')
|
|
17
|
+
);
|
|
18
|
+
await Promise.all(dirs.map((dir) => patchDirAsync(headerSet, dir, options.dryRun)));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Generate `React-Core` public header names as a set, will transform necessary headers based on this set.
|
|
23
|
+
*/
|
|
24
|
+
async function generateReactHeaderSetAsync(reactHeaderDir: string): Promise<Set<string>> {
|
|
25
|
+
const files = await glob('*.h', { cwd: reactHeaderDir });
|
|
26
|
+
return new Set(files);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Patch imports from a file
|
|
31
|
+
* @param headerSet prebuilt React-Core header set
|
|
32
|
+
* @param file target patch file
|
|
33
|
+
* @param dryRun true if not writing changes to file
|
|
34
|
+
*/
|
|
35
|
+
export async function patchFileAsync(headerSet: Set<string>, file: string, dryRun: boolean) {
|
|
36
|
+
let changed = false;
|
|
37
|
+
const content = await fs.readFile(file, 'utf-8');
|
|
38
|
+
const transformContent = content.replace(
|
|
39
|
+
/^#import\s+"(.+)"$/gm,
|
|
40
|
+
(match: string, headerName: string): string => {
|
|
41
|
+
// `#import "RCTBridge.h"` -> `#import <React/RCTBridge.h>`
|
|
42
|
+
if (headerSet.has(headerName)) {
|
|
43
|
+
changed = true;
|
|
44
|
+
return `#import <React/${headerName}>`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// `#import "React/RCTBridge.h"` -> `#import <React/RCTBridge.h>`
|
|
48
|
+
if (headerName.startsWith('React/')) {
|
|
49
|
+
const name = headerName.substring(6);
|
|
50
|
+
if (headerSet.has(name)) {
|
|
51
|
+
changed = true;
|
|
52
|
+
return `#import <React/${name}>`;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Otherwise, return original import
|
|
57
|
+
return match;
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
if (changed) {
|
|
62
|
+
console.log(`Patching imports for file: ${file}`);
|
|
63
|
+
}
|
|
64
|
+
if (!dryRun) {
|
|
65
|
+
await fs.writeFile(file, transformContent);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Patch imports from a directory
|
|
71
|
+
* @param headerSet prebuilt React-Core header set
|
|
72
|
+
* @param file target patch file
|
|
73
|
+
* @param dryRun true if not writing changes to file
|
|
74
|
+
*/
|
|
75
|
+
async function patchDirAsync(headerSet: Set<string>, dir: string, dryRun: boolean) {
|
|
76
|
+
const files = await glob('**/*.{h,m,mm}', { cwd: dir, absolute: true });
|
|
77
|
+
return Promise.all(files.map((file) => patchFileAsync(headerSet, file, dryRun)));
|
|
78
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import commander from 'commander';
|
|
2
2
|
|
|
3
|
+
import { patchReactImportsAsync } from './ReactImportsPatcher';
|
|
3
4
|
import {
|
|
4
5
|
findModulesAsync,
|
|
5
6
|
resolveModulesAsync,
|
|
@@ -54,6 +55,15 @@ function registerResolveCommand<OptionsType extends ResolveOptions>(
|
|
|
54
55
|
return registerSearchCommand<OptionsType>(commandName, fn);
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
// Register for `patch-react-imports` command
|
|
59
|
+
function registerPatchReactImportsCommand() {
|
|
60
|
+
return commander
|
|
61
|
+
.command('patch-react-imports [paths...]')
|
|
62
|
+
.requiredOption('--pods-root <podsRoot>', 'The path to `Pods` directory')
|
|
63
|
+
.option('--dry-run', 'Only list files without writing changes to the file system')
|
|
64
|
+
.action(patchReactImportsAsync);
|
|
65
|
+
}
|
|
66
|
+
|
|
57
67
|
module.exports = async function (args: string[]) {
|
|
58
68
|
// Searches for available expo modules.
|
|
59
69
|
registerSearchCommand<SearchOptions & { json?: boolean }>('search', async (results, options) => {
|
|
@@ -102,6 +112,8 @@ module.exports = async function (args: string[]) {
|
|
|
102
112
|
false
|
|
103
113
|
);
|
|
104
114
|
|
|
115
|
+
registerPatchReactImportsCommand();
|
|
116
|
+
|
|
105
117
|
await commander
|
|
106
118
|
.version(require('expo-modules-autolinking/package.json').version)
|
|
107
119
|
.description('CLI command that searches for Expo modules to autolink them.')
|
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
|
}
|
|
@@ -30,6 +39,7 @@ export async function resolveModuleAsync(
|
|
|
30
39
|
flags: options.flags,
|
|
31
40
|
modulesClassNames: revision.config?.iosModulesClassNames(),
|
|
32
41
|
appDelegateSubscribers: revision.config?.iosAppDelegateSubscribers(),
|
|
42
|
+
reactDelegateHandlers: revision.config?.iosReactDelegateHandlers(),
|
|
33
43
|
};
|
|
34
44
|
}
|
|
35
45
|
|
|
@@ -54,7 +64,10 @@ async function generatePackageListFileContentAsync(
|
|
|
54
64
|
className: string
|
|
55
65
|
): Promise<string> {
|
|
56
66
|
const modulesToImport = modules.filter(
|
|
57
|
-
(module) =>
|
|
67
|
+
(module) =>
|
|
68
|
+
module.modulesClassNames.length ||
|
|
69
|
+
module.appDelegateSubscribers.length ||
|
|
70
|
+
module.reactDelegateHandlers.length
|
|
58
71
|
);
|
|
59
72
|
const pods = modulesToImport.map((module) => module.podName);
|
|
60
73
|
|
|
@@ -66,6 +79,10 @@ async function generatePackageListFileContentAsync(
|
|
|
66
79
|
.concat(...modulesToImport.map((module) => module.appDelegateSubscribers))
|
|
67
80
|
.filter(Boolean);
|
|
68
81
|
|
|
82
|
+
const reactDelegateHandlerModules = modulesToImport.filter(
|
|
83
|
+
(module) => !!module.reactDelegateHandlers.length
|
|
84
|
+
);
|
|
85
|
+
|
|
69
86
|
return `/**
|
|
70
87
|
* Automatically generated by expo-modules-autolinking.
|
|
71
88
|
*
|
|
@@ -84,6 +101,10 @@ public class ${className}: ModulesProvider {
|
|
|
84
101
|
public override func getAppDelegateSubscribers() -> [ExpoAppDelegateSubscriber.Type] {
|
|
85
102
|
return ${formatArrayOfClassNames(appDelegateSubscribers)}
|
|
86
103
|
}
|
|
104
|
+
|
|
105
|
+
public override func getReactDelegateHandlers() -> [ExpoReactDelegateHandlerTupleType] {
|
|
106
|
+
return ${formatArrayOfReactDelegateHandler(reactDelegateHandlerModules)}
|
|
107
|
+
}
|
|
87
108
|
}
|
|
88
109
|
`;
|
|
89
110
|
}
|
|
@@ -96,3 +117,18 @@ function formatArrayOfClassNames(classNames: string[]): string {
|
|
|
96
117
|
return `[${classNames.map((className) => `\n${indent.repeat(3)}${className}.self`).join(',')}
|
|
97
118
|
${indent.repeat(2)}]`;
|
|
98
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
|
@@ -24,6 +24,11 @@ export interface GenerateOptions extends ResolveOptions {
|
|
|
24
24
|
empty?: boolean;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
+
export interface PatchReactImportsOptions {
|
|
28
|
+
podsRoot: string;
|
|
29
|
+
dryRun: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
27
32
|
export type PackageRevision = {
|
|
28
33
|
path: string;
|
|
29
34
|
version: string;
|
|
@@ -59,6 +64,16 @@ export interface RawExpoModuleConfig {
|
|
|
59
64
|
* Names of Swift classes that hooks into `ExpoAppDelegate` to receive AppDelegate life-cycle events.
|
|
60
65
|
*/
|
|
61
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;
|
|
62
77
|
};
|
|
63
78
|
|
|
64
79
|
/**
|
package/tsconfig.json
CHANGED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
# Overrides CocoaPods `PodTarget` class to make the `ReactCommon` pod define a module
|
|
2
|
-
# and tell CocoaPods to generate a modulemap for it. This is needed for Swift/JSI integration
|
|
3
|
-
# until the upstream podspec add `DEFINES_MODULE => YES` to build settings.
|
|
4
|
-
# See: https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/target/pod_target.rb
|
|
5
|
-
|
|
6
|
-
module Pod
|
|
7
|
-
class PodTarget
|
|
8
|
-
|
|
9
|
-
private
|
|
10
|
-
|
|
11
|
-
_original_defines_module = instance_method(:defines_module?)
|
|
12
|
-
|
|
13
|
-
public
|
|
14
|
-
|
|
15
|
-
# @return [Boolean] Whether the target defines a "module"
|
|
16
|
-
# (and thus will need a module map and umbrella header).
|
|
17
|
-
#
|
|
18
|
-
# @note Static library targets can temporarily opt in to this behavior by setting
|
|
19
|
-
# `DEFINES_MODULE = YES` in their specification's `pod_target_xcconfig`.
|
|
20
|
-
#
|
|
21
|
-
define_method(:defines_module?) do
|
|
22
|
-
# Call the original method
|
|
23
|
-
original_result = _original_defines_module.bind(self).()
|
|
24
|
-
|
|
25
|
-
# Make ReactCommon specs define a module. This is required for ExpoModulesCore
|
|
26
|
-
# to use `ReactCommon/turbomodule/core` subspec as a module, from Swift.
|
|
27
|
-
# It also needs to handle versioned pods in Expo Go, so we check if the pod name
|
|
28
|
-
# ends with `ReactCommon` instead of checking if they're equal.
|
|
29
|
-
if !original_result && name.end_with?('ReactCommon')
|
|
30
|
-
root_spec.consumer(platform).pod_target_xcconfig['DEFINES_MODULE'] = 'YES'
|
|
31
|
-
return @defines_module = true
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
# Return the original value if not applicable for hack.
|
|
35
|
-
return original_result
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|