expo-modules-autolinking 1.11.1 → 1.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/build/autolinking/findModules.js +3 -12
- package/build/autolinking/findModules.js.map +1 -1
- package/build/autolinking/index.d.ts +2 -2
- package/build/autolinking/index.js +2 -1
- package/build/autolinking/index.js.map +1 -1
- package/build/autolinking/utils.d.ts +4 -0
- package/build/autolinking/utils.js +23 -1
- package/build/autolinking/utils.js.map +1 -1
- package/build/index.js +32 -0
- package/build/index.js.map +1 -1
- package/build/reactNativeConfig/androidResolver.d.ts +19 -0
- package/build/reactNativeConfig/androidResolver.js +208 -0
- package/build/reactNativeConfig/androidResolver.js.map +1 -0
- package/build/reactNativeConfig/config.d.ts +5 -0
- package/build/reactNativeConfig/config.js +56 -0
- package/build/reactNativeConfig/config.js.map +1 -0
- package/build/reactNativeConfig/index.d.ts +2 -0
- package/build/reactNativeConfig/index.js +19 -0
- package/build/reactNativeConfig/index.js.map +1 -0
- package/build/reactNativeConfig/iosResolver.d.ts +2 -0
- package/build/reactNativeConfig/iosResolver.js +28 -0
- package/build/reactNativeConfig/iosResolver.js.map +1 -0
- package/build/reactNativeConfig/reactNativeConfig.d.ts +12 -0
- package/build/reactNativeConfig/reactNativeConfig.js +117 -0
- package/build/reactNativeConfig/reactNativeConfig.js.map +1 -0
- package/build/reactNativeConfig/reactNativeConfig.types.d.ts +93 -0
- package/build/reactNativeConfig/reactNativeConfig.types.js +3 -0
- package/build/reactNativeConfig/reactNativeConfig.types.js.map +1 -0
- package/build/reactNativeConfig/utils.d.ts +20 -0
- package/build/reactNativeConfig/utils.js +58 -0
- package/build/reactNativeConfig/utils.js.map +1 -0
- package/jest.config.js +1 -1
- package/package.json +5 -3
- package/src/autolinking/findModules.ts +3 -14
- package/src/autolinking/index.ts +6 -1
- package/src/autolinking/utils.ts +22 -0
- package/src/index.ts +46 -3
- package/src/reactNativeConfig/androidResolver.ts +255 -0
- package/src/reactNativeConfig/config.ts +54 -0
- package/src/reactNativeConfig/index.ts +2 -0
- package/src/reactNativeConfig/iosResolver.ts +31 -0
- package/src/reactNativeConfig/reactNativeConfig.ts +163 -0
- package/src/reactNativeConfig/reactNativeConfig.types.ts +105 -0
- package/src/reactNativeConfig/utils.ts +66 -0
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,16 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 1.11.2 — 2024-08-14
|
|
14
|
+
|
|
15
|
+
### 🎉 New features
|
|
16
|
+
|
|
17
|
+
- Added `react-native-config` command to support core autolinking for react-native. ([#29818](https://github.com/expo/expo/pull/29818) by [@kudo](https://github.com/kudo))
|
|
18
|
+
|
|
19
|
+
### 🐛 Bug fixes
|
|
20
|
+
|
|
21
|
+
- Added missing `project.android.packageName` in react-native-config for Android core autolinking. ([#30913](https://github.com/expo/expo/pull/30913) by [@kudo](https://github.com/kudo))
|
|
22
|
+
|
|
13
23
|
## 1.11.1 — 2024-04-23
|
|
14
24
|
|
|
15
25
|
_This version does not introduce any user-facing changes._
|
|
@@ -10,6 +10,7 @@ const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
|
10
10
|
const module_1 = require("module");
|
|
11
11
|
const path_1 = __importDefault(require("path"));
|
|
12
12
|
const mergeLinkingOptions_1 = require("./mergeLinkingOptions");
|
|
13
|
+
const utils_1 = require("./utils");
|
|
13
14
|
const ExpoModuleConfig_1 = require("../ExpoModuleConfig");
|
|
14
15
|
// Names of the config files. From lowest to highest priority.
|
|
15
16
|
const EXPO_MODULE_CONFIG_FILENAMES = ['unimodule.json', 'expo-module.config.json'];
|
|
@@ -34,18 +35,8 @@ async function findModulesAsync(providedOptions) {
|
|
|
34
35
|
const { name, version } = resolvePackageNameAndVersion(packagePath, {
|
|
35
36
|
fallbackToDirName: isNativeModulesDir,
|
|
36
37
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
// Isolated modules installs dependencies in small groups such as:
|
|
40
|
-
// - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli
|
|
41
|
-
// - /.pnpm/expo@50.x.x(...)/node_modules/expo
|
|
42
|
-
// - /.pnpm/expo@50.x.x(...)/node_modules/expo-application
|
|
43
|
-
// When isolated modules are detected, expand the `searchPaths`
|
|
44
|
-
// to include possible nested dependencies.
|
|
45
|
-
const maybeIsolatedModulesPath = path_1.default.join(packagePath, name.startsWith('@') && name.includes('/') ? '../..' : '..' // scoped packages are nested deeper
|
|
46
|
-
);
|
|
47
|
-
const isIsolatedModulesPath = path_1.default.basename(maybeIsolatedModulesPath) === 'node_modules';
|
|
48
|
-
if (isIsolatedModulesPath && !searchPaths.has(maybeIsolatedModulesPath)) {
|
|
38
|
+
const maybeIsolatedModulesPath = (0, utils_1.getIsolatedModulesPath)(packagePath, name);
|
|
39
|
+
if (maybeIsolatedModulesPath) {
|
|
49
40
|
searchPaths.add(maybeIsolatedModulesPath);
|
|
50
41
|
}
|
|
51
42
|
// we ignore the `exclude` option for custom native modules
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findModules.js","sourceRoot":"","sources":["../../src/autolinking/findModules.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,0DAA6B;AAC7B,wDAA0B;AAC1B,mCAAuC;AACvC,gDAAwB;AAExB,+DAAiG;AACjG,0DAAwE;AAGxE,8DAA8D;AAC9D,MAAM,4BAA4B,GAAG,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,CAAC;AAEnF;;GAEG;AACI,KAAK,UAAU,gBAAgB,CAAC,eAA8B;IACnE,MAAM,OAAO,GAAG,MAAM,IAAA,8CAAwB,EAAC,eAAe,CAAC,CAAC;IAChE,MAAM,OAAO,GAAiC,IAAI,GAAG,EAAE,CAAC;IAExD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE5C,yFAAyF;IACzF,MAAM,WAAW,GAAG,IAA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AAC,CAAC;aACzC;SACF;IACH,CAAC;IAED,2BAA2B;IAC3B,MAAM,sBAAsB,GAAG,MAAM,IAAA,oDAA8B,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACzF,YAAY,CAAC,sBAAsB,CAAC,CAAC;IAErC,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import chalk from 'chalk';\nimport glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport { createRequire } from 'module';\nimport path from 'path';\n\nimport { getProjectPackageJsonPathAsync, mergeLinkingOptionsAsync } from './mergeLinkingOptions';\nimport { requireAndResolveExpoModuleConfig } from '../ExpoModuleConfig';\nimport { PackageRevision, SearchOptions, SearchResults } 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 * 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: Map<string, PackageRevision> = new Map();\n\n const nativeModuleNames = new Set<string>();\n\n // custom native modules should be resolved first so that they can override other modules\n const searchPaths = new Set(\n options.nativeModulesDir && fs.existsSync(options.nativeModulesDir)\n ? [options.nativeModulesDir, ...options.searchPaths]\n : options.searchPaths\n );\n\n // `searchPaths` can be mutated to discover all \"isolated modules groups\", when using isolated modules\n for (const searchPath of searchPaths) {\n const isNativeModulesDir = searchPath === options.nativeModulesDir;\n\n const packageConfigPaths = await findPackagesConfigPathsAsync(searchPath);\n\n for (const packageConfigPath of packageConfigPaths) {\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\n const { name, version } = resolvePackageNameAndVersion(packagePath, {\n fallbackToDirName: isNativeModulesDir,\n });\n\n // Check if the project is using isolated modules, by checking\n // if the parent dir of `packagePath` is a `node_modules` folder.\n // Isolated modules installs dependencies in small groups such as:\n // - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli\n // - /.pnpm/expo@50.x.x(...)/node_modules/expo\n // - /.pnpm/expo@50.x.x(...)/node_modules/expo-application\n // When isolated modules are detected, expand the `searchPaths`\n // to include possible nested dependencies.\n const maybeIsolatedModulesPath = path.join(\n packagePath,\n name.startsWith('@') && name.includes('/') ? '../..' : '..' // scoped packages are nested deeper\n );\n const isIsolatedModulesPath = path.basename(maybeIsolatedModulesPath) === 'node_modules';\n if (isIsolatedModulesPath && !searchPaths.has(maybeIsolatedModulesPath)) {\n searchPaths.add(maybeIsolatedModulesPath);\n }\n\n // we ignore the `exclude` option for custom native modules\n if (\n (!isNativeModulesDir && options.exclude?.includes(name)) ||\n !expoModuleConfig.supportsPlatform(options.platform)\n ) {\n continue;\n }\n\n // add the current revision to the results\n const currentRevision: PackageRevision = {\n path: packagePath,\n version,\n config: expoModuleConfig,\n };\n addRevisionToResults(results, name, currentRevision);\n\n // if the module is a native module, we need to add it to the nativeModuleNames set\n if (isNativeModulesDir && !nativeModuleNames.has(name)) {\n nativeModuleNames.add(name);\n }\n }\n }\n\n const searchResults: SearchResults = Object.fromEntries(results.entries());\n\n // It doesn't make much sense to strip modules if there is only one search path.\n // (excluding custom native modules 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 || options.onlyProjectDeps === false) {\n return searchResults;\n }\n\n return await filterToProjectDependenciesAsync(searchResults, {\n ...providedOptions,\n // Custom native modules are not filtered out\n // when they're not specified in package.json dependencies.\n alwaysIncludedPackagesNames: nativeModuleNames,\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\n/**\n * Adds {@link revision} to the {@link results} map\n * or to package duplicates if it already exists.\n * @param results [mutable] yet resolved packages map\n * @param name resolved package name\n * @param revision resolved package revision\n */\nfunction addRevisionToResults(\n results: Map<string, PackageRevision>,\n name: string,\n revision: PackageRevision\n): void {\n if (!results.has(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.set(name, {\n ...revision,\n duplicates: [],\n });\n } else if (\n results.get(name)?.path !== revision.path &&\n results.get(name)?.duplicates?.every(({ path }) => path !== revision.path)\n ) {\n const { config, duplicates, ...duplicateEntry } = revision;\n results.get(name)?.duplicates?.push(duplicateEntry);\n }\n}\n\n/**\n * Returns paths to the highest priority config files, relative to the {@link searchPath}.\n * @example\n * ```\n * // Given the following file exists: /foo/myapp/modules/mymodule/expo-module.config.json\n * await findPackagesConfigPathsAsync('/foo/myapp/modules');\n * // returns ['mymodule/expo-module.config.json']\n *\n * await findPackagesConfigPathsAsync('/foo/myapp/modules/mymodule');\n * // returns ['expo-module.config.json']\n * ```\n */\nasync function findPackagesConfigPathsAsync(searchPath: string): Promise<string[]> {\n const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';\n const paths = await glob(\n [`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`, `./${bracedFilenames}`],\n {\n cwd: searchPath,\n }\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 return 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\n/**\n * Resolves package name and version for the given {@link packagePath} from its `package.json`.\n * if {@link fallbackToDirName} is true, it returns the dir name when `package.json` doesn't exist.\n * @returns object with `name` and `version` properties. `version` falls back to `UNVERSIONED` if cannot be resolved.\n */\nfunction resolvePackageNameAndVersion(\n packagePath: string,\n { fallbackToDirName }: { fallbackToDirName?: boolean } = {}\n): { name: string; version: string } {\n try {\n const { name, version } = require(path.join(packagePath, 'package.json'));\n return { name, version: version || 'UNVERSIONED' };\n } catch (e) {\n if (fallbackToDirName) {\n // we don't have the package.json name, so we'll use the directory name\n return {\n name: path.basename(packagePath),\n version: 'UNVERSIONED',\n };\n } else {\n throw e;\n }\n }\n}\n\n/**\n * Filters out packages that are not the dependencies of the project.\n */\nasync function filterToProjectDependenciesAsync(\n results: SearchResults,\n options: Pick<SearchOptions, 'projectRoot' | 'silent'> & {\n alwaysIncludedPackagesNames?: Set<string>;\n }\n): Promise<SearchResults> {\n const filteredResults: SearchResults = {};\n const visitedPackages = new Set<string>();\n\n // iterate through always included package names and add them to the visited packages\n // if the results contains them\n for (const name of options.alwaysIncludedPackagesNames ?? []) {\n if (results[name] && !visitedPackages.has(name)) {\n filteredResults[name] = results[name];\n visitedPackages.add(name);\n }\n }\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 /**\n * Custom `require` that resolves from the current working dir instead of this script path.\n * **Requires Node v12.2.0**\n */\n const projectRequire = createRequire(packageJsonPath);\n dependencyPackageJsonPath = projectRequire.resolve(`${dependencyName}/package.json`);\n } catch (error: any) {\n // Some packages don't include package.json in its `exports` field,\n // but none of our packages do that, so it seems fine to just ignore that type of error.\n // Related issue: https://github.com/react-native-community/cli/issues/1168\n if (!options.silent && error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {\n console.warn(\n chalk.yellow(`⚠️ Cannot resolve the path to \"${dependencyName}\" package.`)\n );\n }\n continue;\n }\n }\n\n // Visit the dependency package.\n visitPackage(dependencyPackageJsonPath);\n }\n }\n }\n\n // Visit project's package.\n const projectPackageJsonPath = await getProjectPackageJsonPathAsync(options.projectRoot);\n visitPackage(projectPackageJsonPath);\n\n return filteredResults;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"findModules.js","sourceRoot":"","sources":["../../src/autolinking/findModules.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,0DAA6B;AAC7B,wDAA0B;AAC1B,mCAAuC;AACvC,gDAAwB;AAExB,+DAAiG;AACjG,mCAAiD;AACjD,0DAAwE;AAGxE,8DAA8D;AAC9D,MAAM,4BAA4B,GAAG,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,CAAC;AAEnF;;GAEG;AACI,KAAK,UAAU,gBAAgB,CAAC,eAA8B;IACnE,MAAM,OAAO,GAAG,MAAM,IAAA,8CAAwB,EAAC,eAAe,CAAC,CAAC;IAChE,MAAM,OAAO,GAAiC,IAAI,GAAG,EAAE,CAAC;IAExD,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAE5C,yFAAyF;IACzF,MAAM,WAAW,GAAG,IAAI,GAAG,CACzB,OAAO,CAAC,gBAAgB,IAAI,kBAAE,CAAC,UAAU,CAAC,OAAO,CAAC,gBAAgB,CAAC;QACjE,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC;QACpD,CAAC,CAAC,OAAO,CAAC,WAAW,CACxB,CAAC;IAEF,sGAAsG;IACtG,KAAK,MAAM,UAAU,IAAI,WAAW,EAAE;QACpC,MAAM,kBAAkB,GAAG,UAAU,KAAK,OAAO,CAAC,gBAAgB,CAAC;QAEnE,MAAM,kBAAkB,GAAG,MAAM,4BAA4B,CAAC,UAAU,CAAC,CAAC;QAE1E,KAAK,MAAM,iBAAiB,IAAI,kBAAkB,EAAE;YAClD,MAAM,WAAW,GAAG,MAAM,kBAAE,CAAC,QAAQ,CAAC,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BACtF;oBAAC,OAAO,KAAU,EAAE;wBACnB,mEAAmE;wBACnE,wFAAwF;wBACxF,2EAA2E;wBAC3E,IAAI,CAAC,OAAO,CAAC,MAAM,IAAI,KAAK,CAAC,IAAI,KAAK,+BAA+B,EAAE;4BACrE,OAAO,CAAC,IAAI,CACV,eAAK,CAAC,MAAM,CAAC,mCAAmC,cAAc,YAAY,CAAC,CAC5E,CAAC;yBACH;wBACD,SAAS;qBACV;iBACF;gBAED,gCAAgC;gBAChC,YAAY,CAAC,yBAAyB,CAAC,CAAC;aACzC;SACF;IACH,CAAC;IAED,2BAA2B;IAC3B,MAAM,sBAAsB,GAAG,MAAM,IAAA,oDAA8B,EAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACzF,YAAY,CAAC,sBAAsB,CAAC,CAAC;IAErC,OAAO,eAAe,CAAC;AACzB,CAAC","sourcesContent":["import chalk from 'chalk';\nimport glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport { createRequire } from 'module';\nimport path from 'path';\n\nimport { getProjectPackageJsonPathAsync, mergeLinkingOptionsAsync } from './mergeLinkingOptions';\nimport { getIsolatedModulesPath } from './utils';\nimport { requireAndResolveExpoModuleConfig } from '../ExpoModuleConfig';\nimport { PackageRevision, SearchOptions, SearchResults } 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 * 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: Map<string, PackageRevision> = new Map();\n\n const nativeModuleNames = new Set<string>();\n\n // custom native modules should be resolved first so that they can override other modules\n const searchPaths = new Set(\n options.nativeModulesDir && fs.existsSync(options.nativeModulesDir)\n ? [options.nativeModulesDir, ...options.searchPaths]\n : options.searchPaths\n );\n\n // `searchPaths` can be mutated to discover all \"isolated modules groups\", when using isolated modules\n for (const searchPath of searchPaths) {\n const isNativeModulesDir = searchPath === options.nativeModulesDir;\n\n const packageConfigPaths = await findPackagesConfigPathsAsync(searchPath);\n\n for (const packageConfigPath of packageConfigPaths) {\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\n const { name, version } = resolvePackageNameAndVersion(packagePath, {\n fallbackToDirName: isNativeModulesDir,\n });\n\n const maybeIsolatedModulesPath = getIsolatedModulesPath(packagePath, name);\n if (maybeIsolatedModulesPath) {\n searchPaths.add(maybeIsolatedModulesPath);\n }\n\n // we ignore the `exclude` option for custom native modules\n if (\n (!isNativeModulesDir && options.exclude?.includes(name)) ||\n !expoModuleConfig.supportsPlatform(options.platform)\n ) {\n continue;\n }\n\n // add the current revision to the results\n const currentRevision: PackageRevision = {\n path: packagePath,\n version,\n config: expoModuleConfig,\n };\n addRevisionToResults(results, name, currentRevision);\n\n // if the module is a native module, we need to add it to the nativeModuleNames set\n if (isNativeModulesDir && !nativeModuleNames.has(name)) {\n nativeModuleNames.add(name);\n }\n }\n }\n\n const searchResults: SearchResults = Object.fromEntries(results.entries());\n\n // It doesn't make much sense to strip modules if there is only one search path.\n // (excluding custom native modules 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 || options.onlyProjectDeps === false) {\n return searchResults;\n }\n\n return await filterToProjectDependenciesAsync(searchResults, {\n ...providedOptions,\n // Custom native modules are not filtered out\n // when they're not specified in package.json dependencies.\n alwaysIncludedPackagesNames: nativeModuleNames,\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\n/**\n * Adds {@link revision} to the {@link results} map\n * or to package duplicates if it already exists.\n * @param results [mutable] yet resolved packages map\n * @param name resolved package name\n * @param revision resolved package revision\n */\nfunction addRevisionToResults(\n results: Map<string, PackageRevision>,\n name: string,\n revision: PackageRevision\n): void {\n if (!results.has(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.set(name, {\n ...revision,\n duplicates: [],\n });\n } else if (\n results.get(name)?.path !== revision.path &&\n results.get(name)?.duplicates?.every(({ path }) => path !== revision.path)\n ) {\n const { config, duplicates, ...duplicateEntry } = revision;\n results.get(name)?.duplicates?.push(duplicateEntry);\n }\n}\n\n/**\n * Returns paths to the highest priority config files, relative to the {@link searchPath}.\n * @example\n * ```\n * // Given the following file exists: /foo/myapp/modules/mymodule/expo-module.config.json\n * await findPackagesConfigPathsAsync('/foo/myapp/modules');\n * // returns ['mymodule/expo-module.config.json']\n *\n * await findPackagesConfigPathsAsync('/foo/myapp/modules/mymodule');\n * // returns ['expo-module.config.json']\n * ```\n */\nasync function findPackagesConfigPathsAsync(searchPath: string): Promise<string[]> {\n const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';\n const paths = await glob(\n [`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`, `./${bracedFilenames}`],\n {\n cwd: searchPath,\n }\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 return 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\n/**\n * Resolves package name and version for the given {@link packagePath} from its `package.json`.\n * if {@link fallbackToDirName} is true, it returns the dir name when `package.json` doesn't exist.\n * @returns object with `name` and `version` properties. `version` falls back to `UNVERSIONED` if cannot be resolved.\n */\nfunction resolvePackageNameAndVersion(\n packagePath: string,\n { fallbackToDirName }: { fallbackToDirName?: boolean } = {}\n): { name: string; version: string } {\n try {\n const { name, version } = require(path.join(packagePath, 'package.json'));\n return { name, version: version || 'UNVERSIONED' };\n } catch (e) {\n if (fallbackToDirName) {\n // we don't have the package.json name, so we'll use the directory name\n return {\n name: path.basename(packagePath),\n version: 'UNVERSIONED',\n };\n } else {\n throw e;\n }\n }\n}\n\n/**\n * Filters out packages that are not the dependencies of the project.\n */\nasync function filterToProjectDependenciesAsync(\n results: SearchResults,\n options: Pick<SearchOptions, 'projectRoot' | 'silent'> & {\n alwaysIncludedPackagesNames?: Set<string>;\n }\n): Promise<SearchResults> {\n const filteredResults: SearchResults = {};\n const visitedPackages = new Set<string>();\n\n // iterate through always included package names and add them to the visited packages\n // if the results contains them\n for (const name of options.alwaysIncludedPackagesNames ?? []) {\n if (results[name] && !visitedPackages.has(name)) {\n filteredResults[name] = results[name];\n visitedPackages.add(name);\n }\n }\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 /**\n * Custom `require` that resolves from the current working dir instead of this script path.\n * **Requires Node v12.2.0**\n */\n const projectRequire = createRequire(packageJsonPath);\n dependencyPackageJsonPath = projectRequire.resolve(`${dependencyName}/package.json`);\n } catch (error: any) {\n // Some packages don't include package.json in its `exports` field,\n // but none of our packages do that, so it seems fine to just ignore that type of error.\n // Related issue: https://github.com/react-native-community/cli/issues/1168\n if (!options.silent && error.code !== 'ERR_PACKAGE_PATH_NOT_EXPORTED') {\n console.warn(\n chalk.yellow(`⚠️ Cannot resolve the path to \"${dependencyName}\" package.`)\n );\n }\n continue;\n }\n }\n\n // Visit the dependency package.\n visitPackage(dependencyPackageJsonPath);\n }\n }\n }\n\n // Visit project's package.\n const projectPackageJsonPath = await getProjectPackageJsonPathAsync(options.projectRoot);\n visitPackage(projectPackageJsonPath);\n\n return filteredResults;\n}\n"]}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { findModulesAsync } from './findModules';
|
|
2
|
-
import { mergeLinkingOptionsAsync, resolveSearchPathsAsync } from './mergeLinkingOptions';
|
|
2
|
+
import { getProjectPackageJsonPathAsync, mergeLinkingOptionsAsync, resolveSearchPathsAsync } from './mergeLinkingOptions';
|
|
3
3
|
import { resolveExtraBuildDependenciesAsync, resolveModulesAsync } from './resolveModules';
|
|
4
4
|
import type { ModuleDescriptor, SearchOptions } from '../types';
|
|
5
|
-
export { findModulesAsync, mergeLinkingOptionsAsync, resolveExtraBuildDependenciesAsync, resolveModulesAsync, resolveSearchPathsAsync, };
|
|
5
|
+
export { findModulesAsync, getProjectPackageJsonPathAsync, mergeLinkingOptionsAsync, resolveExtraBuildDependenciesAsync, resolveModulesAsync, resolveSearchPathsAsync, };
|
|
6
6
|
export { generatePackageListAsync } from './generatePackageList';
|
|
7
7
|
export { verifySearchResults } from './verifySearchResults';
|
|
8
8
|
export * from '../types';
|
|
@@ -14,10 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.queryAutolinkingModulesFromProjectAsync = exports.verifySearchResults = exports.generatePackageListAsync = exports.resolveSearchPathsAsync = exports.resolveModulesAsync = exports.resolveExtraBuildDependenciesAsync = exports.mergeLinkingOptionsAsync = exports.findModulesAsync = void 0;
|
|
17
|
+
exports.queryAutolinkingModulesFromProjectAsync = exports.verifySearchResults = exports.generatePackageListAsync = exports.resolveSearchPathsAsync = exports.resolveModulesAsync = exports.resolveExtraBuildDependenciesAsync = exports.mergeLinkingOptionsAsync = exports.getProjectPackageJsonPathAsync = exports.findModulesAsync = void 0;
|
|
18
18
|
const findModules_1 = require("./findModules");
|
|
19
19
|
Object.defineProperty(exports, "findModulesAsync", { enumerable: true, get: function () { return findModules_1.findModulesAsync; } });
|
|
20
20
|
const mergeLinkingOptions_1 = require("./mergeLinkingOptions");
|
|
21
|
+
Object.defineProperty(exports, "getProjectPackageJsonPathAsync", { enumerable: true, get: function () { return mergeLinkingOptions_1.getProjectPackageJsonPathAsync; } });
|
|
21
22
|
Object.defineProperty(exports, "mergeLinkingOptionsAsync", { enumerable: true, get: function () { return mergeLinkingOptions_1.mergeLinkingOptionsAsync; } });
|
|
22
23
|
Object.defineProperty(exports, "resolveSearchPathsAsync", { enumerable: true, get: function () { return mergeLinkingOptions_1.resolveSearchPathsAsync; } });
|
|
23
24
|
const resolveModules_1 = require("./resolveModules");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/autolinking/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAiD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/autolinking/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+CAAiD;AAU/C,iGAVO,8BAAgB,OAUP;AATlB,+DAI+B;AAM7B,+GATA,oDAA8B,OASA;AAC9B,yGATA,8CAAwB,OASA;AAGxB,wGAXA,6CAAuB,OAWA;AATzB,qDAA2F;AAOzF,mHAPO,mDAAkC,OAOP;AAClC,oGAR2C,oCAAmB,OAQ3C;AAGrB,6DAAiE;AAAxD,+HAAA,wBAAwB,OAAA;AACjC,6DAA4D;AAAnD,0HAAA,mBAAmB,OAAA;AAC5B,2CAAyB;AAEzB;;GAEG;AACI,KAAK,UAAU,uCAAuC,CAC3D,WAAmB,EACnB,OAAwE;IAExE,MAAM,WAAW,GAAG,MAAM,IAAA,6CAAuB,EAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACrE,MAAM,WAAW,GAAG,MAAM,IAAA,8CAAwB,EAAC,EAAE,GAAG,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC,CAAC;IAC7F,MAAM,aAAa,GAAG,MAAM,IAAA,8BAAgB,EAAC,WAAW,CAAC,CAAC;IAC1D,OAAO,MAAM,IAAA,oCAAmB,EAAC,aAAa,EAAE,WAAW,CAAC,CAAC;AAC/D,CAAC;AARD,0FAQC","sourcesContent":["import { findModulesAsync } from './findModules';\nimport {\n getProjectPackageJsonPathAsync,\n mergeLinkingOptionsAsync,\n resolveSearchPathsAsync,\n} from './mergeLinkingOptions';\nimport { resolveExtraBuildDependenciesAsync, resolveModulesAsync } from './resolveModules';\nimport type { ModuleDescriptor, SearchOptions } from '../types';\n\nexport {\n findModulesAsync,\n getProjectPackageJsonPathAsync,\n mergeLinkingOptionsAsync,\n resolveExtraBuildDependenciesAsync,\n resolveModulesAsync,\n resolveSearchPathsAsync,\n};\nexport { generatePackageListAsync } from './generatePackageList';\nexport { verifySearchResults } from './verifySearchResults';\nexport * from '../types';\n\n/**\n * Programmatic API to query autolinked modules for a project.\n */\nexport async function queryAutolinkingModulesFromProjectAsync(\n projectRoot: string,\n options: Pick<SearchOptions, 'platform' | 'exclude' | 'onlyProjectDeps'>\n): Promise<ModuleDescriptor[]> {\n const searchPaths = await resolveSearchPathsAsync(null, projectRoot);\n const linkOptions = await mergeLinkingOptionsAsync({ ...options, projectRoot, searchPaths });\n const searchResults = await findModulesAsync(linkOptions);\n return await resolveModulesAsync(searchResults, linkOptions);\n}\n"]}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
import { SupportedPlatform } from '../types';
|
|
2
2
|
export declare function getLinkingImplementationForPlatform(platform: SupportedPlatform): any;
|
|
3
|
+
/**
|
|
4
|
+
* Get the possible path to the pnpm isolated modules folder.
|
|
5
|
+
*/
|
|
6
|
+
export declare function getIsolatedModulesPath(packagePath: string, packageName: string): string | null;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getLinkingImplementationForPlatform = void 0;
|
|
6
|
+
exports.getIsolatedModulesPath = exports.getLinkingImplementationForPlatform = void 0;
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
4
8
|
function getLinkingImplementationForPlatform(platform) {
|
|
5
9
|
switch (platform) {
|
|
6
10
|
case 'ios':
|
|
@@ -15,4 +19,22 @@ function getLinkingImplementationForPlatform(platform) {
|
|
|
15
19
|
}
|
|
16
20
|
}
|
|
17
21
|
exports.getLinkingImplementationForPlatform = getLinkingImplementationForPlatform;
|
|
22
|
+
/**
|
|
23
|
+
* Get the possible path to the pnpm isolated modules folder.
|
|
24
|
+
*/
|
|
25
|
+
function getIsolatedModulesPath(packagePath, packageName) {
|
|
26
|
+
// Check if the project is using isolated modules, by checking
|
|
27
|
+
// if the parent dir of `packagePath` is a `node_modules` folder.
|
|
28
|
+
// Isolated modules installs dependencies in small groups such as:
|
|
29
|
+
// - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli
|
|
30
|
+
// - /.pnpm/expo@50.x.x(...)/node_modules/expo
|
|
31
|
+
// - /.pnpm/expo@50.x.x(...)/node_modules/expo-application
|
|
32
|
+
// When isolated modules are detected, expand the `searchPaths`
|
|
33
|
+
// to include possible nested dependencies.
|
|
34
|
+
const maybeIsolatedModulesPath = path_1.default.join(packagePath, packageName.startsWith('@') && packageName.includes('/') ? '../..' : '..' // scoped packages are nested deeper
|
|
35
|
+
);
|
|
36
|
+
const isIsolatedModulesPath = path_1.default.basename(maybeIsolatedModulesPath) === 'node_modules';
|
|
37
|
+
return isIsolatedModulesPath ? maybeIsolatedModulesPath : null;
|
|
38
|
+
}
|
|
39
|
+
exports.getIsolatedModulesPath = getIsolatedModulesPath;
|
|
18
40
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/autolinking/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/autolinking/utils.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAIxB,SAAgB,mCAAmC,CAAC,QAA2B;IAC7E,QAAQ,QAAQ,EAAE;QAChB,KAAK,KAAK,CAAC;QACX,KAAK,OAAO,CAAC;QACb,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,OAAO,CAAC,oBAAoB,CAAC,CAAC;QACvC,KAAK,SAAS;YACZ,OAAO,OAAO,CAAC,sBAAsB,CAAC,CAAC;QACzC,KAAK,UAAU;YACb,OAAO,OAAO,CAAC,uBAAuB,CAAC,CAAC;KAC3C;AACH,CAAC;AAZD,kFAYC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,WAAmB,EAAE,WAAmB;IAC7E,8DAA8D;IAC9D,iEAAiE;IACjE,kEAAkE;IAClE,qDAAqD;IACrD,gDAAgD;IAChD,4DAA4D;IAC5D,+DAA+D;IAC/D,2CAA2C;IAC3C,MAAM,wBAAwB,GAAG,cAAI,CAAC,IAAI,CACxC,WAAW,EACX,WAAW,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,oCAAoC;KAC/G,CAAC;IACF,MAAM,qBAAqB,GAAG,cAAI,CAAC,QAAQ,CAAC,wBAAwB,CAAC,KAAK,cAAc,CAAC;IACzF,OAAO,qBAAqB,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC;AAfD,wDAeC","sourcesContent":["import path from 'path';\n\nimport { SupportedPlatform } from '../types';\n\nexport function getLinkingImplementationForPlatform(platform: SupportedPlatform) {\n switch (platform) {\n case 'ios':\n case 'macos':\n case 'tvos':\n case 'apple':\n return require('../platforms/apple');\n case 'android':\n return require('../platforms/android');\n case 'devtools':\n return require('../platforms/devtools');\n }\n}\n\n/**\n * Get the possible path to the pnpm isolated modules folder.\n */\nexport function getIsolatedModulesPath(packagePath: string, packageName: string): string | null {\n // Check if the project is using isolated modules, by checking\n // if the parent dir of `packagePath` is a `node_modules` folder.\n // Isolated modules installs dependencies in small groups such as:\n // - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli\n // - /.pnpm/expo@50.x.x(...)/node_modules/expo\n // - /.pnpm/expo@50.x.x(...)/node_modules/expo-application\n // When isolated modules are detected, expand the `searchPaths`\n // to include possible nested dependencies.\n const maybeIsolatedModulesPath = path.join(\n packagePath,\n packageName.startsWith('@') && packageName.includes('/') ? '../..' : '..' // scoped packages are nested deeper\n );\n const isIsolatedModulesPath = path.basename(maybeIsolatedModulesPath) === 'node_modules';\n return isIsolatedModulesPath ? maybeIsolatedModulesPath : null;\n}\n"]}
|
package/build/index.js
CHANGED
|
@@ -4,8 +4,10 @@ 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 path_1 = __importDefault(require("path"));
|
|
7
8
|
const ReactImportsPatcher_1 = require("./ReactImportsPatcher");
|
|
8
9
|
const autolinking_1 = require("./autolinking");
|
|
10
|
+
const reactNativeConfig_1 = require("./reactNativeConfig");
|
|
9
11
|
/**
|
|
10
12
|
* Registers a command that only searches for available expo modules.
|
|
11
13
|
*/
|
|
@@ -42,6 +44,35 @@ function registerPatchReactImportsCommand() {
|
|
|
42
44
|
.option('--dry-run', 'Only list files without writing changes to the file system')
|
|
43
45
|
.action(ReactImportsPatcher_1.patchReactImportsAsync);
|
|
44
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Registry the `react-native-config` command.
|
|
49
|
+
*/
|
|
50
|
+
function registerReactNativeConfigCommand() {
|
|
51
|
+
return commander_1.default
|
|
52
|
+
.command('react-native-config [paths...]')
|
|
53
|
+
.option('-p, --platform [platform]', 'The platform that the resulting modules must support. Available options: "android", "ios"', 'ios')
|
|
54
|
+
.addOption(new commander_1.default.Option('--project-root <projectRoot>', 'The path to the root of the project').default(process.cwd(), 'process.cwd()'))
|
|
55
|
+
.option('-j, --json', 'Output results in the plain JSON format.', () => true, false)
|
|
56
|
+
.action(async (paths, options) => {
|
|
57
|
+
if (!['android', 'ios'].includes(options.platform)) {
|
|
58
|
+
throw new Error(`Unsupported platform: ${options.platform}`);
|
|
59
|
+
}
|
|
60
|
+
const projectRoot = path_1.default.dirname(await (0, autolinking_1.getProjectPackageJsonPathAsync)(options.projectRoot));
|
|
61
|
+
const searchPaths = await (0, autolinking_1.resolveSearchPathsAsync)(paths, projectRoot);
|
|
62
|
+
const providedOptions = {
|
|
63
|
+
platform: options.platform,
|
|
64
|
+
projectRoot,
|
|
65
|
+
searchPaths,
|
|
66
|
+
};
|
|
67
|
+
const results = await (0, reactNativeConfig_1.createReactNativeConfigAsync)(providedOptions);
|
|
68
|
+
if (options.json) {
|
|
69
|
+
console.log(JSON.stringify(results));
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
console.log(require('util').inspect(results, false, null, true));
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
45
76
|
module.exports = async function (args) {
|
|
46
77
|
// Searches for available expo modules.
|
|
47
78
|
registerSearchCommand('search', async (results, options) => {
|
|
@@ -89,6 +120,7 @@ module.exports = async function (args) {
|
|
|
89
120
|
.option('-t, --target <path>', 'Path to the target file, where the package list should be written to.')
|
|
90
121
|
.option('-p, --packages <packages...>', 'Names of the packages to include in the generated modules provider.');
|
|
91
122
|
registerPatchReactImportsCommand();
|
|
123
|
+
registerReactNativeConfigCommand();
|
|
92
124
|
await commander_1.default
|
|
93
125
|
.version(require('expo-modules-autolinking/package.json').version)
|
|
94
126
|
.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,+DAA+D;AAC/D,+CAOuB;AASvB;;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,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACpD;SACA,MAAM,CACL,4BAA4B,EAC5B,uDAAuD,EACvD,CAAC,KAAK,EAAE,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CACpD;SACA,MAAM,CACL,2BAA2B,EAC3B,6FAA6F,EAC7F,OAAO,CACR;SACA,MAAM,CAAC,UAAU,EAAE,6BAA6B,CAAC;SACjD,SAAS,CACR,IAAI,mBAAS,CAAC,MAAM,CAClB,8BAA8B,EAC9B,qCAAqC,CACtC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,eAAe,CAAC,CAC1C;SACA,MAAM,CACL,qBAAqB,EACrB,yEAAyE,EACzE,IAAI,CACL;SACA,MAAM,CAAC,wBAAwB,EAAE,iCAAiC,EAAE,KAAK,CAAC;SAC1E,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,MA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IACvE,sBAAsB,CACpB,2BAA2B,EAC3B,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE;QACzB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,MAAM,IAAA,iCAAmB,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC5D,MAAM,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;QAE1F,IAAA,sCAAwB,EAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC,CACF;SACE,MAAM,CACL,qBAAqB,EACrB,uEAAuE,CACxE;SACA,MAAM,CACL,8BAA8B,EAC9B,qEAAqE,CACtE,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 resolveExtraBuildDependenciesAsync,\n resolveModulesAsync,\n verifySearchResults,\n generatePackageListAsync,\n mergeLinkingOptionsAsync,\n} from './autolinking';\nimport {\n GenerateModulesProviderOptions,\n GenerateOptions,\n ResolveOptions,\n SearchOptions,\n SearchResults,\n} 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: \"apple\", \"android\"',\n 'apple'\n )\n .option('--silent', 'Silence resolution warnings')\n .addOption(\n new commander.Option(\n '--project-root <projectRoot>',\n 'The path to the root of the project'\n ).default(process.cwd(), 'process.cwd()')\n )\n .option(\n '--only-project-deps',\n 'For a monorepo, include only modules that are the project dependencies.',\n true\n )\n .option('--no-only-project-deps', 'Opposite of --only-project-deps', false)\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, options) => {\n const numberOfDuplicates = verifySearchResults(results, options);\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 const extraDependencies = await resolveExtraBuildDependenciesAsync(options);\n\n if (options.json) {\n console.log(JSON.stringify({ extraDependencies, modules }));\n } else {\n console.log(require('util').inspect({ extraDependencies, modules }, false, null, true));\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 // It's deprecated, use `generate-modules-provider` instead.\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 // Generates a source file listing all packages to link in the runtime.\n registerResolveCommand<GenerateModulesProviderOptions>(\n 'generate-modules-provider',\n async (results, options) => {\n const packages = options.packages ?? [];\n const modules = await resolveModulesAsync(results, options);\n const filteredModules = modules.filter((module) => packages.includes(module.packageName));\n\n generatePackageListAsync(filteredModules, options);\n }\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 '-p, --packages <packages...>',\n 'Names of the packages to include in the generated modules provider.'\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"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAClC,gDAAwB;AAExB,+DAA+D;AAC/D,+CASuB;AACvB,2DAAgG;AAShG;;GAEG;AACH,SAAS,qBAAqB,CAC5B,WAAmB,EACnB,EAAwD;IAExD,OAAO,mBAAS;SACb,OAAO,CAAC,GAAG,WAAW,aAAa,CAAC;SACpC,MAAM,CACL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AE1F,IAAA,sCAAwB,EAAC,eAAe,EAAE,OAAO,CAAC,CAAC;IACrD,CAAC,CACF;SACE,MAAM,CACL,qBAAqB,EACrB,uEAAuE,CACxE;SACA,MAAM,CACL,8BAA8B,EAC9B,qEAAqE,CACtE,CAAC;IAEJ,gCAAgC,EAAE,CAAC;IACnC,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';\nimport path from 'path';\n\nimport { patchReactImportsAsync } from './ReactImportsPatcher';\nimport {\n findModulesAsync,\n generatePackageListAsync,\n getProjectPackageJsonPathAsync,\n mergeLinkingOptionsAsync,\n resolveExtraBuildDependenciesAsync,\n resolveModulesAsync,\n resolveSearchPathsAsync,\n verifySearchResults,\n} from './autolinking';\nimport { type RNConfigCommandOptions, createReactNativeConfigAsync } from './reactNativeConfig';\nimport type {\n GenerateModulesProviderOptions,\n GenerateOptions,\n ResolveOptions,\n SearchOptions,\n SearchResults,\n} 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: \"apple\", \"android\"',\n 'apple'\n )\n .option('--silent', 'Silence resolution warnings')\n .addOption(\n new commander.Option(\n '--project-root <projectRoot>',\n 'The path to the root of the project'\n ).default(process.cwd(), 'process.cwd()')\n )\n .option(\n '--only-project-deps',\n 'For a monorepo, include only modules that are the project dependencies.',\n true\n )\n .option('--no-only-project-deps', 'Opposite of --only-project-deps', false)\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\n/**\n * Registry the `react-native-config` command.\n */\nfunction registerReactNativeConfigCommand() {\n return commander\n .command('react-native-config [paths...]')\n .option(\n '-p, --platform [platform]',\n 'The platform that the resulting modules must support. Available options: \"android\", \"ios\"',\n 'ios'\n )\n .addOption(\n new commander.Option(\n '--project-root <projectRoot>',\n 'The path to the root of the project'\n ).default(process.cwd(), 'process.cwd()')\n )\n .option<boolean>('-j, --json', 'Output results in the plain JSON format.', () => true, false)\n .action(async (paths, options) => {\n if (!['android', 'ios'].includes(options.platform)) {\n throw new Error(`Unsupported platform: ${options.platform}`);\n }\n const projectRoot = path.dirname(await getProjectPackageJsonPathAsync(options.projectRoot));\n const searchPaths = await resolveSearchPathsAsync(paths, projectRoot);\n const providedOptions: RNConfigCommandOptions = {\n platform: options.platform,\n projectRoot,\n searchPaths,\n };\n const results = await createReactNativeConfigAsync(providedOptions);\n if (options.json) {\n console.log(JSON.stringify(results));\n } else {\n console.log(require('util').inspect(results, false, null, true));\n }\n });\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, options) => {\n const numberOfDuplicates = verifySearchResults(results, options);\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 const extraDependencies = await resolveExtraBuildDependenciesAsync(options);\n\n if (options.json) {\n console.log(JSON.stringify({ extraDependencies, modules }));\n } else {\n console.log(require('util').inspect({ extraDependencies, modules }, false, null, true));\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 // It's deprecated, use `generate-modules-provider` instead.\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 // Generates a source file listing all packages to link in the runtime.\n registerResolveCommand<GenerateModulesProviderOptions>(\n 'generate-modules-provider',\n async (results, options) => {\n const packages = options.packages ?? [];\n const modules = await resolveModulesAsync(results, options);\n const filteredModules = modules.filter((module) => packages.includes(module.packageName));\n\n generatePackageListAsync(filteredModules, options);\n }\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 '-p, --packages <packages...>',\n 'Names of the packages to include in the generated modules provider.'\n );\n\n registerPatchReactImportsCommand();\n registerReactNativeConfigCommand();\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"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { RNConfigDependencyAndroid, RNConfigReactNativePlatformsConfigAndroid } from './reactNativeConfig.types';
|
|
2
|
+
export declare function resolveDependencyConfigImplAndroidAsync(packageRoot: string, reactNativeConfig: RNConfigReactNativePlatformsConfigAndroid | null | undefined): Promise<RNConfigDependencyAndroid | null>;
|
|
3
|
+
/**
|
|
4
|
+
* Parse the `RNConfigDependencyAndroid.packageName`
|
|
5
|
+
*/
|
|
6
|
+
export declare function parsePackageNameAsync(manifestPath: string | null, gradlePath: string | null): Promise<string | null>;
|
|
7
|
+
/**
|
|
8
|
+
* Parse the Java or Kotlin class name to for `ReactPackage` or `TurboReactPackage`.
|
|
9
|
+
*/
|
|
10
|
+
export declare function parseNativePackageClassNameAsync(packageRoot: string, androidDir: string): Promise<string | null>;
|
|
11
|
+
export declare function parseLibraryNameAsync(androidDir: string, packageJson: any): Promise<string | null>;
|
|
12
|
+
export declare function parseComponentDescriptorsAsync(packageRoot: string, pacakgeJson: any): Promise<string[]>;
|
|
13
|
+
export declare function findGradleAndManifestAsync({ androidDir, isLibrary, }: {
|
|
14
|
+
androidDir: string;
|
|
15
|
+
isLibrary: boolean;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
gradle: string;
|
|
18
|
+
manifest: string;
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.findGradleAndManifestAsync = exports.parseComponentDescriptorsAsync = exports.parseLibraryNameAsync = exports.parseNativePackageClassNameAsync = exports.parsePackageNameAsync = exports.resolveDependencyConfigImplAndroidAsync = void 0;
|
|
7
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
8
|
+
const promises_1 = __importDefault(require("fs/promises"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
async function resolveDependencyConfigImplAndroidAsync(packageRoot, reactNativeConfig) {
|
|
12
|
+
if (reactNativeConfig === null) {
|
|
13
|
+
// Skip autolinking for this package.
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const androidDir = path_1.default.join(packageRoot, 'android');
|
|
17
|
+
const { gradle, manifest } = await findGradleAndManifestAsync({ androidDir, isLibrary: true });
|
|
18
|
+
if (!manifest && !gradle) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
const packageName = reactNativeConfig?.packageName ||
|
|
22
|
+
(await parsePackageNameAsync(path_1.default.join(androidDir, manifest), path_1.default.join(androidDir, gradle)));
|
|
23
|
+
const nativePackageClassName = await parseNativePackageClassNameAsync(packageRoot, androidDir);
|
|
24
|
+
if (!nativePackageClassName) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const packageJson = JSON.parse(await promises_1.default.readFile(path_1.default.join(packageRoot, 'package.json'), 'utf8'));
|
|
28
|
+
const packageImportPath = reactNativeConfig?.packageImportPath || `import ${packageName}.${nativePackageClassName};`;
|
|
29
|
+
const packageInstance = reactNativeConfig?.packageInstance || `new ${nativePackageClassName}()`;
|
|
30
|
+
const buildTypes = reactNativeConfig?.buildTypes || [];
|
|
31
|
+
const dependencyConfiguration = reactNativeConfig?.dependencyConfiguration;
|
|
32
|
+
const libraryName = reactNativeConfig?.libraryName || (await parseLibraryNameAsync(androidDir, packageJson));
|
|
33
|
+
const componentDescriptors = reactNativeConfig?.componentDescriptors ||
|
|
34
|
+
(await parseComponentDescriptorsAsync(packageRoot, packageJson));
|
|
35
|
+
let cmakeListsPath = reactNativeConfig?.cmakeListsPath
|
|
36
|
+
? path_1.default.join(androidDir, reactNativeConfig?.cmakeListsPath)
|
|
37
|
+
: path_1.default.join(androidDir, 'build/generated/source/codegen/jni/CMakeLists.txt');
|
|
38
|
+
const cxxModuleCMakeListsModuleName = reactNativeConfig?.cxxModuleCMakeListsModuleName || null;
|
|
39
|
+
const cxxModuleHeaderName = reactNativeConfig?.cxxModuleHeaderName || null;
|
|
40
|
+
let cxxModuleCMakeListsPath = reactNativeConfig?.cxxModuleCMakeListsPath
|
|
41
|
+
? path_1.default.join(androidDir, reactNativeConfig?.cxxModuleCMakeListsPath)
|
|
42
|
+
: null;
|
|
43
|
+
if (process.platform === 'win32') {
|
|
44
|
+
cmakeListsPath = cmakeListsPath.replace(/\\/g, '/');
|
|
45
|
+
if (cxxModuleCMakeListsPath) {
|
|
46
|
+
cxxModuleCMakeListsPath = cxxModuleCMakeListsPath.replace(/\\/g, '/');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
const result = {
|
|
50
|
+
sourceDir: androidDir,
|
|
51
|
+
packageImportPath,
|
|
52
|
+
packageInstance,
|
|
53
|
+
dependencyConfiguration,
|
|
54
|
+
buildTypes,
|
|
55
|
+
libraryName,
|
|
56
|
+
componentDescriptors,
|
|
57
|
+
cmakeListsPath,
|
|
58
|
+
cxxModuleCMakeListsModuleName,
|
|
59
|
+
cxxModuleCMakeListsPath,
|
|
60
|
+
cxxModuleHeaderName,
|
|
61
|
+
};
|
|
62
|
+
if (!result.libraryName) {
|
|
63
|
+
delete result.libraryName;
|
|
64
|
+
}
|
|
65
|
+
if (!result.dependencyConfiguration) {
|
|
66
|
+
delete result.dependencyConfiguration;
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
exports.resolveDependencyConfigImplAndroidAsync = resolveDependencyConfigImplAndroidAsync;
|
|
71
|
+
/**
|
|
72
|
+
* Parse the `RNConfigDependencyAndroid.packageName`
|
|
73
|
+
*/
|
|
74
|
+
async function parsePackageNameAsync(manifestPath, gradlePath) {
|
|
75
|
+
if (gradlePath) {
|
|
76
|
+
const gradleContents = await promises_1.default.readFile(gradlePath, 'utf8');
|
|
77
|
+
const match = gradleContents.match(/namespace\s*[=]*\s*["'](.+?)["']/);
|
|
78
|
+
if (match) {
|
|
79
|
+
return match[1];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (manifestPath) {
|
|
83
|
+
const manifestContents = await promises_1.default.readFile(manifestPath, 'utf8');
|
|
84
|
+
const match = manifestContents.match(/package="(.+?)"/);
|
|
85
|
+
if (match) {
|
|
86
|
+
return match[1];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
exports.parsePackageNameAsync = parsePackageNameAsync;
|
|
92
|
+
/**
|
|
93
|
+
* Parse the Java or Kotlin class name to for `ReactPackage` or `TurboReactPackage`.
|
|
94
|
+
*/
|
|
95
|
+
async function parseNativePackageClassNameAsync(packageRoot, androidDir) {
|
|
96
|
+
const matched = await (0, utils_1.globMatchFunctorFirstAsync)('**/*Package.{java,kt}', matchNativePackageClassName, { cwd: androidDir });
|
|
97
|
+
if (matched) {
|
|
98
|
+
return matched;
|
|
99
|
+
}
|
|
100
|
+
// Early return if the module is an Expo module
|
|
101
|
+
if (await (0, utils_1.fileExistsAsync)(path_1.default.join(packageRoot, 'expo-module.config.json'))) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return await (0, utils_1.globMatchFunctorFirstAsync)('**/*.{java,kt}', matchNativePackageClassName, {
|
|
105
|
+
cwd: androidDir,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
exports.parseNativePackageClassNameAsync = parseNativePackageClassNameAsync;
|
|
109
|
+
let lazyReactPackageRegex = null;
|
|
110
|
+
let lazyTurboReactPackageRegex = null;
|
|
111
|
+
function matchNativePackageClassName(filePath, contents) {
|
|
112
|
+
const fileContents = contents.toString();
|
|
113
|
+
// [0] Match ReactPackage
|
|
114
|
+
if (!lazyReactPackageRegex) {
|
|
115
|
+
lazyReactPackageRegex =
|
|
116
|
+
/class\s+(\w+[^(\s]*)[\s\w():]*(\s+implements\s+|:)[\s\w():,]*[^{]*ReactPackage/;
|
|
117
|
+
}
|
|
118
|
+
const matchReactPackage = fileContents.match(lazyReactPackageRegex);
|
|
119
|
+
if (matchReactPackage) {
|
|
120
|
+
return matchReactPackage[1];
|
|
121
|
+
}
|
|
122
|
+
// [1] Match TurboReactPackage
|
|
123
|
+
if (!lazyTurboReactPackageRegex) {
|
|
124
|
+
lazyTurboReactPackageRegex =
|
|
125
|
+
/class\s+(\w+[^(\s]*)[\s\w():]*(\s+extends\s+|:)[\s\w():,]*[^{]*TurboReactPackage/;
|
|
126
|
+
}
|
|
127
|
+
const matchTurboReactPackage = fileContents.match(lazyTurboReactPackageRegex);
|
|
128
|
+
if (matchTurboReactPackage) {
|
|
129
|
+
return matchTurboReactPackage[1];
|
|
130
|
+
}
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
async function parseLibraryNameAsync(androidDir, packageJson) {
|
|
134
|
+
// [0] `codegenConfig.name` from package.json
|
|
135
|
+
if (packageJson.codegenConfig?.name) {
|
|
136
|
+
return packageJson.codegenConfig.name;
|
|
137
|
+
}
|
|
138
|
+
const libraryNameRegExp = /libraryName = ["'](.+)["']/;
|
|
139
|
+
const gradlePath = path_1.default.join(androidDir, 'build.gradle');
|
|
140
|
+
// [1] `libraryName` from build.gradle
|
|
141
|
+
if (await (0, utils_1.fileExistsAsync)(gradlePath)) {
|
|
142
|
+
const buildGradleContents = await promises_1.default.readFile(gradlePath, 'utf8');
|
|
143
|
+
const match = buildGradleContents.match(libraryNameRegExp);
|
|
144
|
+
if (match) {
|
|
145
|
+
return match[1];
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
// [2] `libraryName` from build.gradle.kts
|
|
149
|
+
const gradleKtsPath = path_1.default.join(androidDir, 'build.gradle.kts');
|
|
150
|
+
if (await (0, utils_1.fileExistsAsync)(gradleKtsPath)) {
|
|
151
|
+
const buildGradleContents = await promises_1.default.readFile(gradleKtsPath, 'utf8');
|
|
152
|
+
const match = buildGradleContents.match(libraryNameRegExp);
|
|
153
|
+
if (match) {
|
|
154
|
+
return match[1];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return null;
|
|
158
|
+
}
|
|
159
|
+
exports.parseLibraryNameAsync = parseLibraryNameAsync;
|
|
160
|
+
async function parseComponentDescriptorsAsync(packageRoot, pacakgeJson) {
|
|
161
|
+
const jsRoot = pacakgeJson?.codegenConfig?.jsSrcsDir
|
|
162
|
+
? path_1.default.join(packageRoot, pacakgeJson.codegenConfig.jsSrcsDir)
|
|
163
|
+
: packageRoot;
|
|
164
|
+
const results = await (0, utils_1.globMatchFunctorAllAsync)('**/*.{js,jsx,ts,tsx}', matchComponentDescriptors, {
|
|
165
|
+
cwd: jsRoot,
|
|
166
|
+
ignore: ['**/node_modules/**'],
|
|
167
|
+
});
|
|
168
|
+
// Filter out duplicates as it happens that libraries contain multiple outputs due to package publishing.
|
|
169
|
+
// TODO: consider using "codegenConfig" to avoid this.
|
|
170
|
+
return Array.from(new Set(results));
|
|
171
|
+
}
|
|
172
|
+
exports.parseComponentDescriptorsAsync = parseComponentDescriptorsAsync;
|
|
173
|
+
let lazyCodegenComponentRegex = null;
|
|
174
|
+
function matchComponentDescriptors(filePath, contents) {
|
|
175
|
+
const fileContents = contents.toString();
|
|
176
|
+
if (!lazyCodegenComponentRegex) {
|
|
177
|
+
lazyCodegenComponentRegex =
|
|
178
|
+
/codegenNativeComponent(<.*>)?\s*\(\s*["'`](\w+)["'`](,?[\s\S]+interfaceOnly:\s*(\w+))?/m;
|
|
179
|
+
}
|
|
180
|
+
const match = fileContents.match(lazyCodegenComponentRegex);
|
|
181
|
+
if (!(match?.[4] === 'true') && match?.[2]) {
|
|
182
|
+
return `${match[2]}ComponentDescriptor`;
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
async function findGradleAndManifestAsync({ androidDir, isLibrary, }) {
|
|
187
|
+
const globExcludes = [
|
|
188
|
+
'node_modules/**',
|
|
189
|
+
'**/build/**',
|
|
190
|
+
'**/debug/**',
|
|
191
|
+
'Examples/**',
|
|
192
|
+
'examples/**',
|
|
193
|
+
'**/Pods/**',
|
|
194
|
+
'**/sdks/hermes/android/**',
|
|
195
|
+
'**/src/androidTest/**',
|
|
196
|
+
'**/src/test/**',
|
|
197
|
+
];
|
|
198
|
+
const gradlePattern = isLibrary ? 'build.gradle{,.kts}' : 'app/build.gradle{,.kts}';
|
|
199
|
+
const [manifests, gradles] = await Promise.all([
|
|
200
|
+
(0, fast_glob_1.default)('**/AndroidManifest.xml', { cwd: androidDir, ignore: globExcludes }),
|
|
201
|
+
(0, fast_glob_1.default)(gradlePattern, { cwd: androidDir, ignore: globExcludes }),
|
|
202
|
+
]);
|
|
203
|
+
const manifest = manifests.find((manifest) => manifest.includes('src/main/')) ?? manifests[0];
|
|
204
|
+
const gradle = gradles[0];
|
|
205
|
+
return { gradle, manifest };
|
|
206
|
+
}
|
|
207
|
+
exports.findGradleAndManifestAsync = findGradleAndManifestAsync;
|
|
208
|
+
//# sourceMappingURL=androidResolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"androidResolver.js","sourceRoot":"","sources":["../../src/reactNativeConfig/androidResolver.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA6B;AAC7B,2DAA6B;AAC7B,gDAAwB;AAMxB,mCAAgG;AAEzF,KAAK,UAAU,uCAAuC,CAC3D,WAAmB,EACnB,iBAA+E;IAE/E,IAAI,iBAAiB,KAAK,IAAI,EAAE;QAC9B,qCAAqC;QACrC,OAAO,IAAI,CAAC;KACb;IACD,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACrD,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,0BAA0B,CAAC,E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IACD,OAAO,IAAI,CAAC;AACd,CAAC;AAEM,KAAK,UAAU,0BAA0B,CAAC,EAC/C,UAAU,EACV,SAAS,GAIV;IACC,MAAM,YAAY,GAAG;QACnB,iBAAiB;QACjB,aAAa;QACb,aAAa;QACb,aAAa;QACb,aAAa;QACb,YAAY;QACZ,2BAA2B;QAC3B,uBAAuB;QACvB,gBAAgB;KACjB,CAAC;IACF,MAAM,aAAa,GAAG,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,yBAAyB,CAAC;IACpF,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC7C,IAAA,mBAAI,EAAC,wBAAwB,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;QACzE,IAAA,mBAAI,EAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;KAC/D,CAAC,CAAC;IACH,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC;IAC9F,MAAM,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AAC9B,CAAC;AA1BD,gEA0BC","sourcesContent":["import glob from 'fast-glob';\nimport fs from 'fs/promises';\nimport path from 'path';\n\nimport type {\n RNConfigDependencyAndroid,\n RNConfigReactNativePlatformsConfigAndroid,\n} from './reactNativeConfig.types';\nimport { fileExistsAsync, globMatchFunctorAllAsync, globMatchFunctorFirstAsync } from './utils';\n\nexport async function resolveDependencyConfigImplAndroidAsync(\n packageRoot: string,\n reactNativeConfig: RNConfigReactNativePlatformsConfigAndroid | null | undefined\n): Promise<RNConfigDependencyAndroid | null> {\n if (reactNativeConfig === null) {\n // Skip autolinking for this package.\n return null;\n }\n const androidDir = path.join(packageRoot, 'android');\n const { gradle, manifest } = await findGradleAndManifestAsync({ androidDir, isLibrary: true });\n if (!manifest && !gradle) {\n return null;\n }\n\n const packageName =\n reactNativeConfig?.packageName ||\n (await parsePackageNameAsync(path.join(androidDir, manifest), path.join(androidDir, gradle)));\n const nativePackageClassName = await parseNativePackageClassNameAsync(packageRoot, androidDir);\n\n if (!nativePackageClassName) {\n return null;\n }\n\n const packageJson = JSON.parse(await fs.readFile(path.join(packageRoot, 'package.json'), 'utf8'));\n const packageImportPath =\n reactNativeConfig?.packageImportPath || `import ${packageName}.${nativePackageClassName};`;\n const packageInstance = reactNativeConfig?.packageInstance || `new ${nativePackageClassName}()`;\n const buildTypes = reactNativeConfig?.buildTypes || [];\n const dependencyConfiguration = reactNativeConfig?.dependencyConfiguration;\n const libraryName =\n reactNativeConfig?.libraryName || (await parseLibraryNameAsync(androidDir, packageJson));\n const componentDescriptors =\n reactNativeConfig?.componentDescriptors ||\n (await parseComponentDescriptorsAsync(packageRoot, packageJson));\n let cmakeListsPath = reactNativeConfig?.cmakeListsPath\n ? path.join(androidDir, reactNativeConfig?.cmakeListsPath)\n : path.join(androidDir, 'build/generated/source/codegen/jni/CMakeLists.txt');\n const cxxModuleCMakeListsModuleName = reactNativeConfig?.cxxModuleCMakeListsModuleName || null;\n const cxxModuleHeaderName = reactNativeConfig?.cxxModuleHeaderName || null;\n let cxxModuleCMakeListsPath = reactNativeConfig?.cxxModuleCMakeListsPath\n ? path.join(androidDir, reactNativeConfig?.cxxModuleCMakeListsPath)\n : null;\n if (process.platform === 'win32') {\n cmakeListsPath = cmakeListsPath.replace(/\\\\/g, '/');\n if (cxxModuleCMakeListsPath) {\n cxxModuleCMakeListsPath = cxxModuleCMakeListsPath.replace(/\\\\/g, '/');\n }\n }\n\n const result: RNConfigDependencyAndroid = {\n sourceDir: androidDir,\n packageImportPath,\n packageInstance,\n dependencyConfiguration,\n buildTypes,\n libraryName,\n componentDescriptors,\n cmakeListsPath,\n cxxModuleCMakeListsModuleName,\n cxxModuleCMakeListsPath,\n cxxModuleHeaderName,\n };\n if (!result.libraryName) {\n delete result.libraryName;\n }\n if (!result.dependencyConfiguration) {\n delete result.dependencyConfiguration;\n }\n return result;\n}\n\n/**\n * Parse the `RNConfigDependencyAndroid.packageName`\n */\nexport async function parsePackageNameAsync(\n manifestPath: string | null,\n gradlePath: string | null\n) {\n if (gradlePath) {\n const gradleContents = await fs.readFile(gradlePath, 'utf8');\n const match = gradleContents.match(/namespace\\s*[=]*\\s*[\"'](.+?)[\"']/);\n if (match) {\n return match[1];\n }\n }\n if (manifestPath) {\n const manifestContents = await fs.readFile(manifestPath, 'utf8');\n const match = manifestContents.match(/package=\"(.+?)\"/);\n if (match) {\n return match[1];\n }\n }\n return null;\n}\n\n/**\n * Parse the Java or Kotlin class name to for `ReactPackage` or `TurboReactPackage`.\n */\nexport async function parseNativePackageClassNameAsync(\n packageRoot: string,\n androidDir: string\n): Promise<string | null> {\n const matched = await globMatchFunctorFirstAsync(\n '**/*Package.{java,kt}',\n matchNativePackageClassName,\n { cwd: androidDir }\n );\n if (matched) {\n return matched;\n }\n\n // Early return if the module is an Expo module\n if (await fileExistsAsync(path.join(packageRoot, 'expo-module.config.json'))) {\n return null;\n }\n\n return await globMatchFunctorFirstAsync('**/*.{java,kt}', matchNativePackageClassName, {\n cwd: androidDir,\n });\n}\n\nlet lazyReactPackageRegex: RegExp | null = null;\nlet lazyTurboReactPackageRegex: RegExp | null = null;\nfunction matchNativePackageClassName(filePath: string, contents: Buffer): string | null {\n const fileContents = contents.toString();\n\n // [0] Match ReactPackage\n if (!lazyReactPackageRegex) {\n lazyReactPackageRegex =\n /class\\s+(\\w+[^(\\s]*)[\\s\\w():]*(\\s+implements\\s+|:)[\\s\\w():,]*[^{]*ReactPackage/;\n }\n const matchReactPackage = fileContents.match(lazyReactPackageRegex);\n if (matchReactPackage) {\n return matchReactPackage[1];\n }\n\n // [1] Match TurboReactPackage\n if (!lazyTurboReactPackageRegex) {\n lazyTurboReactPackageRegex =\n /class\\s+(\\w+[^(\\s]*)[\\s\\w():]*(\\s+extends\\s+|:)[\\s\\w():,]*[^{]*TurboReactPackage/;\n }\n const matchTurboReactPackage = fileContents.match(lazyTurboReactPackageRegex);\n if (matchTurboReactPackage) {\n return matchTurboReactPackage[1];\n }\n\n return null;\n}\n\nexport async function parseLibraryNameAsync(\n androidDir: string,\n packageJson: any\n): Promise<string | null> {\n // [0] `codegenConfig.name` from package.json\n if (packageJson.codegenConfig?.name) {\n return packageJson.codegenConfig.name;\n }\n\n const libraryNameRegExp = /libraryName = [\"'](.+)[\"']/;\n const gradlePath = path.join(androidDir, 'build.gradle');\n // [1] `libraryName` from build.gradle\n if (await fileExistsAsync(gradlePath)) {\n const buildGradleContents = await fs.readFile(gradlePath, 'utf8');\n const match = buildGradleContents.match(libraryNameRegExp);\n if (match) {\n return match[1];\n }\n }\n\n // [2] `libraryName` from build.gradle.kts\n const gradleKtsPath = path.join(androidDir, 'build.gradle.kts');\n if (await fileExistsAsync(gradleKtsPath)) {\n const buildGradleContents = await fs.readFile(gradleKtsPath, 'utf8');\n const match = buildGradleContents.match(libraryNameRegExp);\n if (match) {\n return match[1];\n }\n }\n\n return null;\n}\n\nexport async function parseComponentDescriptorsAsync(\n packageRoot: string,\n pacakgeJson: any\n): Promise<string[]> {\n const jsRoot = pacakgeJson?.codegenConfig?.jsSrcsDir\n ? path.join(packageRoot, pacakgeJson.codegenConfig.jsSrcsDir)\n : packageRoot;\n const results = await globMatchFunctorAllAsync(\n '**/*.{js,jsx,ts,tsx}',\n matchComponentDescriptors,\n {\n cwd: jsRoot,\n ignore: ['**/node_modules/**'],\n }\n );\n\n // Filter out duplicates as it happens that libraries contain multiple outputs due to package publishing.\n // TODO: consider using \"codegenConfig\" to avoid this.\n return Array.from(new Set(results));\n}\n\nlet lazyCodegenComponentRegex: RegExp | null = null;\nfunction matchComponentDescriptors(filePath: string, contents: Buffer): string | null {\n const fileContents = contents.toString();\n\n if (!lazyCodegenComponentRegex) {\n lazyCodegenComponentRegex =\n /codegenNativeComponent(<.*>)?\\s*\\(\\s*[\"'`](\\w+)[\"'`](,?[\\s\\S]+interfaceOnly:\\s*(\\w+))?/m;\n }\n const match = fileContents.match(lazyCodegenComponentRegex);\n if (!(match?.[4] === 'true') && match?.[2]) {\n return `${match[2]}ComponentDescriptor`;\n }\n return null;\n}\n\nexport async function findGradleAndManifestAsync({\n androidDir,\n isLibrary,\n}: {\n androidDir: string;\n isLibrary: boolean;\n}): Promise<{ gradle: string; manifest: string }> {\n const globExcludes = [\n 'node_modules/**',\n '**/build/**',\n '**/debug/**',\n 'Examples/**',\n 'examples/**',\n '**/Pods/**',\n '**/sdks/hermes/android/**',\n '**/src/androidTest/**',\n '**/src/test/**',\n ];\n const gradlePattern = isLibrary ? 'build.gradle{,.kts}' : 'app/build.gradle{,.kts}';\n const [manifests, gradles] = await Promise.all([\n glob('**/AndroidManifest.xml', { cwd: androidDir, ignore: globExcludes }),\n glob(gradlePattern, { cwd: androidDir, ignore: globExcludes }),\n ]);\n const manifest = manifests.find((manifest) => manifest.includes('src/main/')) ?? manifests[0];\n const gradle = gradles[0];\n return { gradle, manifest };\n}\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { RNConfigReactNativeConfig } from './reactNativeConfig.types';
|
|
2
|
+
/**
|
|
3
|
+
* Load the `react-native.config.js` or `react-native.config.ts` from the package.
|
|
4
|
+
*/
|
|
5
|
+
export declare function loadConfigAsync<T extends RNConfigReactNativeConfig>(packageRoot: string): Promise<T | null>;
|