expo-modules-autolinking 0.0.3 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/ExpoModuleConfig.d.ts +24 -0
- package/build/ExpoModuleConfig.js +42 -0
- package/build/ExpoModuleConfig.js.map +1 -0
- package/build/autolinking.d.ts +0 -4
- package/build/autolinking.js +104 -25
- package/build/autolinking.js.map +1 -1
- package/build/index.js +11 -5
- package/build/index.js.map +1 -1
- package/build/platforms/android.js +23 -6
- package/build/platforms/android.js.map +1 -1
- package/build/platforms/ios.d.ts +4 -0
- package/build/platforms/ios.js +38 -1
- package/build/platforms/ios.js.map +1 -1
- package/build/types.d.ts +22 -2
- package/build/types.js.map +1 -1
- package/e2e/TestUtils.ts +53 -0
- package/jest.config.js +5 -0
- package/package.json +5 -3
- package/scripts/android/autolinking_implementation.gradle +248 -0
- package/scripts/ios/autolinking_manager.rb +137 -0
- package/scripts/ios/cocoapods/target_definition.rb +22 -0
- package/scripts/ios/cocoapods/user_project_integrator.rb +61 -0
- package/scripts/ios/constants.rb +7 -0
- package/scripts/ios/package.rb +33 -0
- package/scripts/ios/project_integrator.rb +102 -0
- package/src/ExpoModuleConfig.ts +38 -0
- package/src/autolinking.ts +120 -24
- package/src/index.ts +15 -10
- package/src/platforms/android.ts +28 -9
- package/src/platforms/ios.ts +45 -0
- package/src/types.ts +25 -2
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { RawExpoModuleConfig, SupportedPlatform } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A class that wraps the raw config (`expo-module.json` or `unimodule.json`).
|
|
4
|
+
*/
|
|
5
|
+
export declare class ExpoModuleConfig {
|
|
6
|
+
readonly rawConfig: RawExpoModuleConfig;
|
|
7
|
+
constructor(rawConfig: RawExpoModuleConfig);
|
|
8
|
+
/**
|
|
9
|
+
* Whether the module supports given platform.
|
|
10
|
+
*/
|
|
11
|
+
supportsPlatform(platform: SupportedPlatform): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Returns a list of names of Swift native modules classes to put to the generated modules provider file.
|
|
14
|
+
*/
|
|
15
|
+
iosModulesClassNames(): string[];
|
|
16
|
+
/**
|
|
17
|
+
* Returns serializable raw config.
|
|
18
|
+
*/
|
|
19
|
+
toJSON(): RawExpoModuleConfig;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Reads the config at given path and returns the config wrapped by `ExpoModuleConfig` class.
|
|
23
|
+
*/
|
|
24
|
+
export declare function requireAndResolveExpoModuleConfig(path: string): ExpoModuleConfig;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireAndResolveExpoModuleConfig = exports.ExpoModuleConfig = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* A class that wraps the raw config (`expo-module.json` or `unimodule.json`).
|
|
6
|
+
*/
|
|
7
|
+
class ExpoModuleConfig {
|
|
8
|
+
constructor(rawConfig) {
|
|
9
|
+
this.rawConfig = rawConfig;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Whether the module supports given platform.
|
|
13
|
+
*/
|
|
14
|
+
supportsPlatform(platform) {
|
|
15
|
+
var _a, _b;
|
|
16
|
+
return (_b = (_a = this.rawConfig.platforms) === null || _a === void 0 ? void 0 : _a.includes(platform)) !== null && _b !== void 0 ? _b : false;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Returns a list of names of Swift native modules classes to put to the generated modules provider file.
|
|
20
|
+
*/
|
|
21
|
+
iosModulesClassNames() {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
return (_b = (_a = this.rawConfig.ios) === null || _a === void 0 ? void 0 : _a.modulesClassNames) !== null && _b !== void 0 ? _b : [];
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Returns serializable raw config.
|
|
27
|
+
*/
|
|
28
|
+
toJSON() {
|
|
29
|
+
return this.rawConfig;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
exports.ExpoModuleConfig = ExpoModuleConfig;
|
|
33
|
+
/**
|
|
34
|
+
* Reads the config at given path and returns the config wrapped by `ExpoModuleConfig` class.
|
|
35
|
+
*/
|
|
36
|
+
function requireAndResolveExpoModuleConfig(path) {
|
|
37
|
+
// TODO: Validate the raw config against a schema.
|
|
38
|
+
// TODO: Support for `*.js` files, not only static `*.json`.
|
|
39
|
+
return new ExpoModuleConfig(require(path));
|
|
40
|
+
}
|
|
41
|
+
exports.requireAndResolveExpoModuleConfig = requireAndResolveExpoModuleConfig;
|
|
42
|
+
//# sourceMappingURL=ExpoModuleConfig.js.map
|
|
@@ -0,0 +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;AAvBD,4CAuBC;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 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.d.ts
CHANGED
|
@@ -4,10 +4,6 @@ import { GenerateOptions, ModuleDescriptor, ResolveOptions, SearchOptions, Searc
|
|
|
4
4
|
* going up through the path components. This makes workspaces work out-of-the-box without any configs.
|
|
5
5
|
*/
|
|
6
6
|
export declare function resolveSearchPathsAsync(searchPaths: string[] | null, cwd: string): Promise<string[]>;
|
|
7
|
-
/**
|
|
8
|
-
* Finds project's package.json and returns its path.
|
|
9
|
-
*/
|
|
10
|
-
export declare function findPackageJsonPathAsync(): Promise<string | null>;
|
|
11
7
|
/**
|
|
12
8
|
* Looks up for workspace's `node_modules` paths.
|
|
13
9
|
*/
|
package/build/autolinking.js
CHANGED
|
@@ -3,32 +3,39 @@ 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.resolveModulesAsync = exports.verifySearchResults = exports.mergeLinkingOptionsAsync = exports.findModulesAsync = exports.findDefaultPathsAsync = exports.
|
|
6
|
+
exports.generatePackageListAsync = exports.resolveModulesAsync = exports.verifySearchResults = exports.mergeLinkingOptionsAsync = exports.findModulesAsync = exports.findDefaultPathsAsync = exports.resolveSearchPathsAsync = void 0;
|
|
7
7
|
const chalk_1 = __importDefault(require("chalk"));
|
|
8
8
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
9
|
const find_up_1 = __importDefault(require("find-up"));
|
|
10
10
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
11
|
+
const module_1 = require("module");
|
|
11
12
|
const path_1 = __importDefault(require("path"));
|
|
12
|
-
|
|
13
|
-
|
|
13
|
+
const ExpoModuleConfig_1 = require("./ExpoModuleConfig");
|
|
14
|
+
// Names of the config files. From lowest to highest priority.
|
|
15
|
+
const EXPO_MODULE_CONFIG_FILENAMES = ['unimodule.json', 'expo-module.config.json'];
|
|
16
|
+
/**
|
|
17
|
+
* Path to the `package.json` of the closest project in the current working dir.
|
|
18
|
+
*/
|
|
19
|
+
const projectPackageJsonPath = find_up_1.default.sync('package.json', { cwd: process.cwd() });
|
|
20
|
+
// This won't happen in usual scenarios, but we need to unwrap the optional path :)
|
|
21
|
+
if (!projectPackageJsonPath) {
|
|
22
|
+
throw new Error(`Couldn't find "package.json" up from path "${process.cwd()}"`);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Custom `require` that resolves from the current working dir instead of this script path.
|
|
26
|
+
* **Requires Node v12.2.0**
|
|
27
|
+
*/
|
|
28
|
+
const projectRequire = module_1.createRequire(projectPackageJsonPath);
|
|
14
29
|
/**
|
|
15
30
|
* Resolves autolinking search paths. If none is provided, it accumulates all node_modules when
|
|
16
31
|
* going up through the path components. This makes workspaces work out-of-the-box without any configs.
|
|
17
32
|
*/
|
|
18
33
|
async function resolveSearchPathsAsync(searchPaths, cwd) {
|
|
19
34
|
return searchPaths && searchPaths.length > 0
|
|
20
|
-
? searchPaths.map(searchPath => path_1.default.resolve(cwd, searchPath))
|
|
35
|
+
? searchPaths.map((searchPath) => path_1.default.resolve(cwd, searchPath))
|
|
21
36
|
: await findDefaultPathsAsync(cwd);
|
|
22
37
|
}
|
|
23
38
|
exports.resolveSearchPathsAsync = resolveSearchPathsAsync;
|
|
24
|
-
/**
|
|
25
|
-
* Finds project's package.json and returns its path.
|
|
26
|
-
*/
|
|
27
|
-
async function findPackageJsonPathAsync() {
|
|
28
|
-
var _a;
|
|
29
|
-
return (_a = (await find_up_1.default('package.json', { cwd: process.cwd() }))) !== null && _a !== void 0 ? _a : null;
|
|
30
|
-
}
|
|
31
|
-
exports.findPackageJsonPathAsync = findPackageJsonPathAsync;
|
|
32
39
|
/**
|
|
33
40
|
* Looks up for workspace's `node_modules` paths.
|
|
34
41
|
*/
|
|
@@ -47,18 +54,28 @@ exports.findDefaultPathsAsync = findDefaultPathsAsync;
|
|
|
47
54
|
* Searches for modules to link based on given config.
|
|
48
55
|
*/
|
|
49
56
|
async function findModulesAsync(providedOptions) {
|
|
50
|
-
var _a, _b, _c
|
|
57
|
+
var _a, _b, _c;
|
|
51
58
|
const options = await mergeLinkingOptionsAsync(providedOptions);
|
|
52
59
|
const results = {};
|
|
53
60
|
for (const searchPath of options.searchPaths) {
|
|
54
|
-
const
|
|
61
|
+
const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';
|
|
62
|
+
const paths = await fast_glob_1.default([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`], {
|
|
55
63
|
cwd: searchPath,
|
|
56
64
|
});
|
|
57
|
-
|
|
65
|
+
// If the package has multiple configs (e.g. `unimodule.json` and `expo-module.config.json` during the transition time)
|
|
66
|
+
// then we want to give `expo-module.config.json` the priority.
|
|
67
|
+
const uniqueConfigPaths = Object.values(paths.reduce((acc, configPath) => {
|
|
68
|
+
const dirname = path_1.default.dirname(configPath);
|
|
69
|
+
if (!acc[dirname] || configPriority(configPath) > configPriority(acc[dirname])) {
|
|
70
|
+
acc[dirname] = configPath;
|
|
71
|
+
}
|
|
72
|
+
return acc;
|
|
73
|
+
}, {}));
|
|
74
|
+
for (const packageConfigPath of uniqueConfigPaths) {
|
|
58
75
|
const packagePath = await fs_extra_1.default.realpath(path_1.default.join(searchPath, path_1.default.dirname(packageConfigPath)));
|
|
59
|
-
const
|
|
76
|
+
const expoModuleConfig = ExpoModuleConfig_1.requireAndResolveExpoModuleConfig(path_1.default.join(packagePath, path_1.default.basename(packageConfigPath)));
|
|
60
77
|
const { name, version } = require(path_1.default.join(packagePath, 'package.json'));
|
|
61
|
-
if (((_a = options.exclude) === null || _a === void 0 ? void 0 : _a.includes(name)) || !
|
|
78
|
+
if (((_a = options.exclude) === null || _a === void 0 ? void 0 : _a.includes(name)) || !expoModuleConfig.supportsPlatform(options.platform)) {
|
|
62
79
|
continue;
|
|
63
80
|
}
|
|
64
81
|
const currentRevision = {
|
|
@@ -67,17 +84,74 @@ async function findModulesAsync(providedOptions) {
|
|
|
67
84
|
};
|
|
68
85
|
if (!results[name]) {
|
|
69
86
|
// The revision that was found first will be the main one.
|
|
70
|
-
// An array of duplicates
|
|
71
|
-
results[name] = {
|
|
87
|
+
// An array of duplicates and the config are needed only here.
|
|
88
|
+
results[name] = {
|
|
89
|
+
...currentRevision,
|
|
90
|
+
config: expoModuleConfig,
|
|
91
|
+
duplicates: [],
|
|
92
|
+
};
|
|
72
93
|
}
|
|
73
|
-
else if (results[name].path !== packagePath &&
|
|
74
|
-
(
|
|
94
|
+
else if (results[name].path !== packagePath &&
|
|
95
|
+
((_b = results[name].duplicates) === null || _b === void 0 ? void 0 : _b.every(({ path }) => path !== packagePath))) {
|
|
96
|
+
(_c = results[name].duplicates) === null || _c === void 0 ? void 0 : _c.push(currentRevision);
|
|
75
97
|
}
|
|
76
98
|
}
|
|
77
99
|
}
|
|
78
|
-
|
|
100
|
+
// It doesn't make much sense to strip modules if there is only one search path.
|
|
101
|
+
// Workspace root usually doesn't specify all its dependencies (see Expo Go),
|
|
102
|
+
// so in this case we should link everything.
|
|
103
|
+
if (options.searchPaths.length <= 1) {
|
|
104
|
+
return results;
|
|
105
|
+
}
|
|
106
|
+
return filterToProjectDependencies(results);
|
|
79
107
|
}
|
|
80
108
|
exports.findModulesAsync = findModulesAsync;
|
|
109
|
+
/**
|
|
110
|
+
* Filters out packages that are not the dependencies of the project.
|
|
111
|
+
*/
|
|
112
|
+
function filterToProjectDependencies(results) {
|
|
113
|
+
const filteredResults = {};
|
|
114
|
+
const visitedPackages = new Set();
|
|
115
|
+
// Helper for traversing the dependency hierarchy.
|
|
116
|
+
function visitPackage(packageJsonPath) {
|
|
117
|
+
const packageJson = require(packageJsonPath);
|
|
118
|
+
// Prevent getting into the recursive loop.
|
|
119
|
+
if (visitedPackages.has(packageJson.name)) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
visitedPackages.add(packageJson.name);
|
|
123
|
+
// Iterate over the dependencies to find transitive modules.
|
|
124
|
+
for (const dependencyName in packageJson.dependencies) {
|
|
125
|
+
const dependencyResult = results[dependencyName];
|
|
126
|
+
if (!filteredResults[dependencyName]) {
|
|
127
|
+
let dependencyPackageJsonPath;
|
|
128
|
+
if (dependencyResult) {
|
|
129
|
+
filteredResults[dependencyName] = dependencyResult;
|
|
130
|
+
dependencyPackageJsonPath = path_1.default.join(dependencyResult.path, 'package.json');
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
try {
|
|
134
|
+
dependencyPackageJsonPath = projectRequire.resolve(`${dependencyName}/package.json`);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
// Some packages don't include package.json in its `exports` field,
|
|
138
|
+
// but none of our packages do that, so it seems fine to just ignore that type of error.
|
|
139
|
+
// Related issue: https://github.com/react-native-community/cli/issues/1168
|
|
140
|
+
if (error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {
|
|
141
|
+
console.warn(chalk_1.default.yellow(`⚠️ Cannot resolve the path to "${dependencyName}" package.`));
|
|
142
|
+
}
|
|
143
|
+
continue;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
// Visit the dependency package.
|
|
147
|
+
visitPackage(dependencyPackageJsonPath);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Visit project's package.
|
|
152
|
+
visitPackage(projectPackageJsonPath);
|
|
153
|
+
return filteredResults;
|
|
154
|
+
}
|
|
81
155
|
/**
|
|
82
156
|
* Merges autolinking options from different sources (the later the higher priority)
|
|
83
157
|
* - options defined in package.json's `expoModules` field
|
|
@@ -86,8 +160,7 @@ exports.findModulesAsync = findModulesAsync;
|
|
|
86
160
|
*/
|
|
87
161
|
async function mergeLinkingOptionsAsync(providedOptions) {
|
|
88
162
|
var _a;
|
|
89
|
-
const
|
|
90
|
-
const packageJson = packageJsonPath ? require(packageJsonPath) : {};
|
|
163
|
+
const packageJson = require(projectPackageJsonPath);
|
|
91
164
|
const baseOptions = (_a = packageJson.expo) === null || _a === void 0 ? void 0 : _a.autolinking;
|
|
92
165
|
const platformOptions = providedOptions.platform && (baseOptions === null || baseOptions === void 0 ? void 0 : baseOptions[providedOptions.platform]);
|
|
93
166
|
const finalOptions = Object.assign({}, baseOptions, platformOptions, providedOptions);
|
|
@@ -102,7 +175,7 @@ exports.mergeLinkingOptionsAsync = mergeLinkingOptionsAsync;
|
|
|
102
175
|
function verifySearchResults(searchResults) {
|
|
103
176
|
var _a;
|
|
104
177
|
const cwd = process.cwd();
|
|
105
|
-
const relativePath = pkg => path_1.default.relative(cwd, pkg.path);
|
|
178
|
+
const relativePath = (pkg) => path_1.default.relative(cwd, pkg.path);
|
|
106
179
|
let counter = 0;
|
|
107
180
|
for (const moduleName in searchResults) {
|
|
108
181
|
const revision = searchResults[moduleName];
|
|
@@ -154,4 +227,10 @@ async function generatePackageListAsync(modules, options) {
|
|
|
154
227
|
}
|
|
155
228
|
}
|
|
156
229
|
exports.generatePackageListAsync = generatePackageListAsync;
|
|
230
|
+
/**
|
|
231
|
+
* Returns the priority of the config at given path. Higher number means higher priority.
|
|
232
|
+
*/
|
|
233
|
+
function configPriority(fullpath) {
|
|
234
|
+
return EXPO_MODULE_CONFIG_FILENAMES.indexOf(path_1.default.basename(fullpath));
|
|
235
|
+
}
|
|
157
236
|
//# sourceMappingURL=autolinking.js.map
|
package/build/autolinking.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"autolinking.js","sourceRoot":"","sources":["../src/autolinking.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,0DAA6B;AAC7B,sDAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAWxB,qCAAqC;AACrC,MAAM,2BAA2B,GAAG,gBAAgB,CAAC;AAErD;;;GAGG;AACI,KAAK,UAAU,uBAAuB,CAC3C,WAA4B,EAC5B,GAAW;IAEX,OAAO,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAC1C,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,UAAU,CAAC,EAAE,CAAC,cAAI,CAAC,OAAO,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;QAC9D,CAAC,CAAC,MAAM,qBAAqB,CAAC,GAAG,CAAC,CAAC;AACvC,CAAC;AAPD,0DAOC;AAED;;GAEG;AACI,KAAK,UAAU,wBAAwB;;IAC5C,aAAO,CAAC,MAAM,iBAAM,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,mCAAI,IAAI,CAAC;AACxE,CAAC;AAFD,4DAEC;AAED;;GAEG;AACI,KAAK,UAAU,qBAAqB,CAAC,GAAW;IACrD,MAAM,KAAK,GAAG,EAAE,CAAC;IACjB,IAAI,GAAG,GAAG,GAAG,CAAC;IACd,IAAI,WAA+B,CAAC;IAEpC,OAAO,CAAC,WAAW,GAAG,MAAM,iBAAM,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE;QACjE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,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,MAAM,eAAe,CAAC,kBAAkB,CAC7D,WAAW,EACX,QAAQ,EACR,OAAO,CACR,CAAC;QACF,OAAO,cAAc;YACnB,CAAC,CAAC;gBACE,WAAW;gBACX,cAAc,EAAE,QAAQ,CAAC,OAAO;gBAChC,GAAG,cAAc;aAClB;YACH,CAAC,CAAC,IAAI,CAAC;IACX,CAAC,CAAC,CACH,CACF;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,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","sourcesContent":["import chalk from 'chalk';\nimport glob from 'fast-glob';\nimport findUp from 'find-up';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport {\n GenerateOptions,\n ModuleDescriptor,\n PackageRevision,\n ResolveOptions,\n SearchOptions,\n SearchResults,\n} from './types';\n\n// TODO: Rename to `expo-module.json`\nconst EXPO_MODULE_CONFIG_FILENAME = 'unimodule.json';\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 * Finds project's package.json and returns its path.\n */\nexport async function findPackageJsonPathAsync(): Promise<string | null> {\n return (await findUp('package.json', { cwd: process.cwd() })) ?? null;\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 paths = await glob(\n [`*/${EXPO_MODULE_CONFIG_FILENAME}`, `@*/*/${EXPO_MODULE_CONFIG_FILENAME}`],\n {\n cwd: searchPath,\n }\n );\n\n for (const packageConfigPath of paths) {\n const packagePath = await fs.realpath(path.join(searchPath, path.dirname(packageConfigPath)));\n const packageConfig = require(path.join(packagePath, EXPO_MODULE_CONFIG_FILENAME));\n const { name, version } = require(path.join(packagePath, 'package.json'));\n\n if (options.exclude?.includes(name) || !packageConfig.platforms?.includes(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 is needed only here.\n results[name] = { ...currentRevision, duplicates: [] };\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 return results;\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 packageJsonPath = await findPackageJsonPathAsync();\n const packageJson = packageJsonPath ? require(packageJsonPath) : {};\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"]}
|
|
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,sBAAa,CAAC,sBAAsB,CAAC,CAAC;AAE7D;;;GAGG;AACI,KAAK,UAAU,uBAAuB,CAC3C,WAA4B,EAC5B,GAAW;IAEX,OAAO,WAAW,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC;QAC1C,CAAC,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,UAAU,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AC,GAAG,CAAC,KAAK,EAAE,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,EAAE;QAClE,MAAM,cAAc,GAAG,MAAM,eAAe,CAAC,kBAAkB,CAC7D,WAAW,EACX,QAAQ,EACR,OAAO,CACR,CAAC;QACF,OAAO,cAAc;YACnB,CAAC,CAAC;gBACE,WAAW;gBACX,cAAc,EAAE,QAAQ,CAAC,OAAO;gBAChC,GAAG,cAAc;aAClB;YACH,CAAC,CAAC,IAAI,CAAC;IACX,CAAC,CAAC,CACH,CACF;SACE,MAAM,CAAC,OAAO,CAAC;SACf,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,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"]}
|
package/build/index.js
CHANGED
|
@@ -13,6 +13,7 @@ function registerSearchCommand(commandName, fn) {
|
|
|
13
13
|
.command(`${commandName} [paths...]`)
|
|
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
|
+
.option('-p, --platform [platform]', 'The platform that the resulting modules must support. Available options: "ios", "android"', 'ios')
|
|
16
17
|
.action(async (searchPaths, providedOptions) => {
|
|
17
18
|
const options = await autolinking_1.mergeLinkingOptionsAsync({
|
|
18
19
|
...providedOptions,
|
|
@@ -26,15 +27,20 @@ function registerSearchCommand(commandName, fn) {
|
|
|
26
27
|
* Registers a command that searches for modules and then resolves them for specific platform.
|
|
27
28
|
*/
|
|
28
29
|
function registerResolveCommand(commandName, fn) {
|
|
29
|
-
return registerSearchCommand(commandName, fn)
|
|
30
|
+
return registerSearchCommand(commandName, fn);
|
|
30
31
|
}
|
|
31
32
|
module.exports = async function (args) {
|
|
32
33
|
// Searches for available expo modules.
|
|
33
|
-
registerSearchCommand('search', async (results) => {
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
registerSearchCommand('search', async (results, options) => {
|
|
35
|
+
if (options.json) {
|
|
36
|
+
console.log(JSON.stringify(results));
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
console.log(require('util').inspect(results, false, null, true));
|
|
40
|
+
}
|
|
41
|
+
}).option('-j, --json', 'Output results in the plain JSON format.', () => true, false);
|
|
36
42
|
// Checks whether there are no resolving issues in the current setup.
|
|
37
|
-
registerSearchCommand('verify', results => {
|
|
43
|
+
registerSearchCommand('verify', (results) => {
|
|
38
44
|
const numberOfDuplicates = autolinking_1.verifySearchResults(results);
|
|
39
45
|
if (!numberOfDuplicates) {
|
|
40
46
|
console.log('✅ Everything is fine!');
|
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,MAA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,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 .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"]}
|
|
@@ -25,6 +25,10 @@ async function resolveModuleAsync(packageName, revision) {
|
|
|
25
25
|
cwd: revision.path,
|
|
26
26
|
ignore: ['**/node_modules/**'],
|
|
27
27
|
});
|
|
28
|
+
// Just in case where the module doesn't have its own `build.gradle`.
|
|
29
|
+
if (!buildGradleFile) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
28
32
|
const sourceDir = path_1.default.dirname(path_1.default.join(revision.path, buildGradleFile));
|
|
29
33
|
return {
|
|
30
34
|
projectName: convertPackageNameToProjectName(packageName),
|
|
@@ -36,19 +40,24 @@ exports.resolveModuleAsync = resolveModuleAsync;
|
|
|
36
40
|
* Generates the string to put into the generated package list.
|
|
37
41
|
*/
|
|
38
42
|
async function generatePackageListFileContentAsync(modules, namespace) {
|
|
39
|
-
|
|
43
|
+
// TODO: Instead of ignoring `expo` here, make the package class paths configurable from `expo-module.config.json`.
|
|
44
|
+
const packagesClasses = await findAndroidPackagesAsync(modules.filter((module) => module.packageName !== 'expo'));
|
|
40
45
|
return `package ${namespace};
|
|
41
46
|
|
|
42
47
|
import java.util.Arrays;
|
|
43
48
|
import java.util.List;
|
|
44
|
-
import
|
|
49
|
+
import expo.modules.core.interfaces.Package;
|
|
45
50
|
|
|
46
51
|
public class ExpoModulesPackageList {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
${packagesClasses.map(packageClass => ` new ${packageClass}()`).join(',\n')}
|
|
52
|
+
private static class LazyHolder {
|
|
53
|
+
static final List<Package> packagesList = Arrays.<Package>asList(
|
|
54
|
+
${packagesClasses.map((packageClass) => ` new ${packageClass}()`).join(',\n')}
|
|
50
55
|
);
|
|
51
56
|
}
|
|
57
|
+
|
|
58
|
+
public static List<Package> getPackageList() {
|
|
59
|
+
return LazyHolder.packagesList;
|
|
60
|
+
}
|
|
52
61
|
}
|
|
53
62
|
`;
|
|
54
63
|
}
|
|
@@ -60,8 +69,16 @@ async function findAndroidPackagesAsync(modules) {
|
|
|
60
69
|
});
|
|
61
70
|
for (const file of files) {
|
|
62
71
|
const fileContent = await fs_extra_1.default.readFile(path_1.default.join(module.sourceDir, file), 'utf8');
|
|
72
|
+
const packageRegex = (() => {
|
|
73
|
+
if (process.env.EXPO_SHOULD_USE_LEGACY_PACKAGE_INTERFACE) {
|
|
74
|
+
return /\bimport\s+org\.unimodules\.core\.(interfaces\.Package|BasePackage)\b/;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
return /\bimport\s+expo\.modules\.core\.(interfaces\.Package|BasePackage)\b/;
|
|
78
|
+
}
|
|
79
|
+
})();
|
|
63
80
|
// Very naive check to skip non-expo packages
|
|
64
|
-
if (
|
|
81
|
+
if (!packageRegex.test(fileContent)) {
|
|
65
82
|
continue;
|
|
66
83
|
}
|
|
67
84
|
const classPathMatches = fileContent.match(/^package ([\w.]+)\b/m);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"android.js","sourceRoot":"","sources":["../../src/platforms/android.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,wDA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;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 };\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 return `package ${namespace};\n\nimport java.util.Arrays;\nimport java.util.List;\nimport expo.modules.core.interfaces.Package;\n\npublic class ExpoModulesPackageList {\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\n public static List<Package> getPackageList() {\n return LazyHolder.packagesList;\n }\n}\n`;\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('src/**/*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
|
@@ -3,3 +3,7 @@ import { ModuleDescriptor, PackageRevision, SearchOptions } from '../types';
|
|
|
3
3
|
* Resolves module search result with additional details required for iOS platform.
|
|
4
4
|
*/
|
|
5
5
|
export declare function resolveModuleAsync(packageName: string, revision: PackageRevision, options: SearchOptions): Promise<ModuleDescriptor | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Generates Swift file that contains all autolinked Swift packages.
|
|
8
|
+
*/
|
|
9
|
+
export declare function generatePackageListAsync(modules: ModuleDescriptor[], targetPath: string): Promise<void>;
|
package/build/platforms/ios.js
CHANGED
|
@@ -3,13 +3,15 @@ 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.resolveModuleAsync = void 0;
|
|
6
|
+
exports.generatePackageListAsync = exports.resolveModuleAsync = void 0;
|
|
7
7
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
/**
|
|
10
11
|
* Resolves module search result with additional details required for iOS platform.
|
|
11
12
|
*/
|
|
12
13
|
async function resolveModuleAsync(packageName, revision, options) {
|
|
14
|
+
var _a;
|
|
13
15
|
const [podspecFile] = await fast_glob_1.default('*/*.podspec', {
|
|
14
16
|
cwd: revision.path,
|
|
15
17
|
ignore: ['**/node_modules/**'],
|
|
@@ -23,7 +25,42 @@ async function resolveModuleAsync(packageName, revision, options) {
|
|
|
23
25
|
podName,
|
|
24
26
|
podspecDir,
|
|
25
27
|
flags: options.flags,
|
|
28
|
+
modulesClassNames: (_a = revision.config) === null || _a === void 0 ? void 0 : _a.iosModulesClassNames(),
|
|
26
29
|
};
|
|
27
30
|
}
|
|
28
31
|
exports.resolveModuleAsync = resolveModuleAsync;
|
|
32
|
+
/**
|
|
33
|
+
* Generates Swift file that contains all autolinked Swift packages.
|
|
34
|
+
*/
|
|
35
|
+
async function generatePackageListAsync(modules, targetPath) {
|
|
36
|
+
const className = path_1.default.basename(targetPath, path_1.default.extname(targetPath));
|
|
37
|
+
const generatedFileContent = await generatePackageListFileContentAsync(modules, className);
|
|
38
|
+
await fs_extra_1.default.outputFile(targetPath, generatedFileContent);
|
|
39
|
+
}
|
|
40
|
+
exports.generatePackageListAsync = generatePackageListAsync;
|
|
41
|
+
/**
|
|
42
|
+
* Generates the string to put into the generated package list.
|
|
43
|
+
*/
|
|
44
|
+
async function generatePackageListFileContentAsync(modules, className) {
|
|
45
|
+
const modulesToProvide = modules.filter((module) => module.modulesClassNames.length > 0);
|
|
46
|
+
const pods = modulesToProvide.map((module) => module.podName);
|
|
47
|
+
const classNames = [].concat(...modulesToProvide.map((module) => module.modulesClassNames));
|
|
48
|
+
return `/**
|
|
49
|
+
* Automatically generated by expo-modules-autolinking.
|
|
50
|
+
*
|
|
51
|
+
* This autogenerated class provides a list of classes of native Expo modules,
|
|
52
|
+
* but only these that are written in Swift and use the new API for creating Expo modules.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
import ExpoModulesCore
|
|
56
|
+
${pods.map((podName) => `import ${podName}\n`).join('')}
|
|
57
|
+
@objc(${className})
|
|
58
|
+
public class ${className}: ModulesProvider {
|
|
59
|
+
public override func getModuleClasses() -> [AnyModule.Type] {
|
|
60
|
+
return [${classNames.map((className) => `\n ${className}.self`).join(',')}
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
`;
|
|
65
|
+
}
|
|
29
66
|
//# sourceMappingURL=ios.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ios.js","sourceRoot":"","sources":["../../src/platforms/ios.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,gDAAwB;AAIxB;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,WAAmB,EACnB,QAAyB,EACzB,OAAsB
|
|
1
|
+
{"version":3,"file":"ios.js","sourceRoot":"","sources":["../../src/platforms/ios.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAIxB;;GAEG;AACI,KAAK,UAAU,kBAAkB,CACtC,WAAmB,EACnB,QAAyB,EACzB,OAAsB;;IAEtB,MAAM,CAAC,WAAW,CAAC,GAAG,MAAM,mBAAI,CAAC,aAAa,EAAE;QAC9C,GAAG,EAAE,QAAQ,CAAC,IAAI;QAClB,MAAM,EAAE,CAAC,oBAAoB,CAAC;KAC/B,CAAC,CAAC;IAEH,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,CAAC,OAAO,CAAC,cAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC;IAEvE,OAAO;QACL,OAAO;QACP,UAAU;QACV,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,iBAAiB,EAAE,MAAA,QAAQ,CAAC,MAAM,0CAAE,oBAAoB,EAAE;KAC3D,CAAC;AACJ,CAAC;AAvBD,gDAuBC;AAED;;GAEG;AACI,KAAK,UAAU,wBAAwB,CAC5C,OAA2B,EAC3B,UAAkB;IAElB,MAAM,SAAS,GAAG,cAAI,CAAC,QAAQ,CAAC,UAAU,EAAE,cAAI,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC;IACtE,MAAM,oBAAoB,GAAG,MAAM,mCAAmC,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAE3F,MAAM,kBAAE,CAAC,UAAU,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAC;AACxD,CAAC;AARD,4DAQC;AAED;;GAEG;AACH,KAAK,UAAU,mCAAmC,CAChD,OAA2B,EAC3B,SAAiB;IAEjB,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACzF,MAAM,IAAI,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC9D,MAAM,UAAU,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAE5F,OAAO;;;;;;;;EAQP,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,OAAO,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;QAC/C,SAAS;eACF,SAAS;;cAEV,UAAU,CAAC,GAAG,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,WAAW,SAAS,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;;;;CAIjF,CAAC;AACF,CAAC","sourcesContent":["import glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport path from 'path';\n\nimport { ModuleDescriptor, PackageRevision, SearchOptions } from '../types';\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 glob('*/*.podspec', {\n cwd: revision.path,\n ignore: ['**/node_modules/**'],\n });\n\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 };\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 modulesToProvide = modules.filter((module) => module.modulesClassNames.length > 0);\n const pods = modulesToProvide.map((module) => module.podName);\n const classNames = [].concat(...modulesToProvide.map((module) => module.modulesClassNames));\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 [${classNames.map((className) => `\\n ${className}.self`).join(',')}\n ]\n }\n}\n`;\n}\n"]}
|