expo-modules-autolinking 0.8.0 → 0.10.0
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 +21 -4
- package/build/autolinking/findModules.js +4 -1
- package/build/autolinking/findModules.js.map +1 -1
- package/build/autolinking/mergeLinkingOptions.js +14 -13
- package/build/autolinking/mergeLinkingOptions.js.map +1 -1
- package/package.json +2 -2
- package/scripts/ios/autolinking_manager.rb +23 -2
- package/scripts/ios/cocoapods/pod_target.rb +1 -1
- package/scripts/ios/project_integrator.rb +2 -2
- package/scripts/ios/react_import_patcher.rb +9 -6
- package/src/autolinking/findModules.ts +9 -3
- package/src/autolinking/mergeLinkingOptions.ts +15 -14
package/CHANGELOG.md
CHANGED
|
@@ -10,21 +10,38 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
-
## 0.
|
|
13
|
+
## 0.10.0 — 2022-07-07
|
|
14
|
+
|
|
15
|
+
### 🐛 Bug fixes
|
|
16
|
+
|
|
17
|
+
- Added support for React Native 0.69.x ([#17629](https://github.com/expo/expo/pull/17629) by [@kudo](https://github.com/kudo))
|
|
18
|
+
- Use regex to match ignored modules in `expo_patch_react_imports!` and fix iOS build errors when the project is inside `react-native` named folder. ([#17968](https://github.com/expo/expo/pull/17968) by [@dmnkgrc](https://github.com/dmnkgrc))
|
|
19
|
+
|
|
20
|
+
## 0.9.0 — 2022-06-23
|
|
14
21
|
|
|
15
22
|
### 🎉 New features
|
|
16
23
|
|
|
17
|
-
-
|
|
24
|
+
- The `searchPaths` and `nativeModulesDir` options now support direct paths to specific module directories. ([#17922](https://github.com/expo/expo/pull/17922) by [@barthap](https://github.com/barthap))
|
|
25
|
+
|
|
26
|
+
## 0.8.1 — 2022-05-12
|
|
18
27
|
|
|
19
28
|
### 🐛 Bug fixes
|
|
20
29
|
|
|
21
|
-
-
|
|
30
|
+
- Fixed an infinite loop when the **package.json** is placed at the root path. ([#17440](https://github.com/expo/expo/pull/17440) by [@tsapeta](https://github.com/tsapeta))
|
|
22
31
|
|
|
23
|
-
## 0.
|
|
32
|
+
## 0.8.0 — 2022-05-06
|
|
24
33
|
|
|
25
34
|
### 🎉 New features
|
|
26
35
|
|
|
27
36
|
- Add `ios.debugOnly` to module config. ([#17331](https://github.com/expo/expo/pull/17331) by [@lukmccall](https://github.com/lukmccall))
|
|
37
|
+
- Setting `EXPO_CONFIGURATION_DEBUG` or `EXPO_CONFIGURATION_RELEASE` Swift flags on project targets. ([#17378](https://github.com/expo/expo/pull/17378) by [@tsapeta](https://github.com/tsapeta))
|
|
38
|
+
|
|
39
|
+
### 🐛 Bug fixes
|
|
40
|
+
|
|
41
|
+
- Fix debug-only modules weren't installed if the `DEBUG` flag wasn't present in `OTHER_SWIFT_FLAGS`. ([#17383](https://github.com/expo/expo/pull/17383) by [@lukmccall](https://github.com/lukmccall))
|
|
42
|
+
- Fix iOS build if project config name is other than RELEASE or DEBUG ([#17439](https://github.com/expo/expo/pull/17439) by [@uloco](https://github.com/uloco))
|
|
43
|
+
|
|
44
|
+
### 💡 Others
|
|
28
45
|
|
|
29
46
|
## 0.7.0 — 2022-04-18
|
|
30
47
|
|
|
@@ -104,11 +104,14 @@ function addRevisionToResults(results, name, revision) {
|
|
|
104
104
|
* // Given the following file exists: /foo/myapp/modules/mymodule/expo-module.config.json
|
|
105
105
|
* await findPackagesConfigPathsAsync('/foo/myapp/modules');
|
|
106
106
|
* // returns ['mymodule/expo-module.config.json']
|
|
107
|
+
*
|
|
108
|
+
* await findPackagesConfigPathsAsync('/foo/myapp/modules/mymodule');
|
|
109
|
+
* // returns ['expo-module.config.json']
|
|
107
110
|
* ```
|
|
108
111
|
*/
|
|
109
112
|
async function findPackagesConfigPathsAsync(searchPath) {
|
|
110
113
|
const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';
|
|
111
|
-
const paths = await (0, fast_glob_1.default)([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`], {
|
|
114
|
+
const paths = await (0, fast_glob_1.default)([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`, `./${bracedFilenames}`], {
|
|
112
115
|
cwd: searchPath,
|
|
113
116
|
});
|
|
114
117
|
// If the package has multiple configs (e.g. `unimodule.json` and `expo-module.config.json` during the transition time)
|
|
@@ -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,0DAAwE;AAExE,+DAAyF;AAEzF,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,GACf,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,CAAC;IAE1B,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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K,+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,YAAY,CAAC,4CAAsB,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 { requireAndResolveExpoModuleConfig } from '../ExpoModuleConfig';\nimport { PackageRevision, SearchOptions, SearchResults } from '../types';\nimport { mergeLinkingOptionsAsync, projectPackageJsonPath } from './mergeLinkingOptions';\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 =\n options.nativeModulesDir && fs.existsSync(options.nativeModulesDir)\n ? [options.nativeModulesDir, ...options.searchPaths]\n : options.searchPaths;\n\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 // 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) {\n return searchResults;\n }\n\n return filterToProjectDependencies(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 */\nasync function findPackagesConfigPathsAsync(searchPath: string): Promise<string[]> {\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 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 */\nfunction filterToProjectDependencies(\n results: SearchResults,\n options: Pick<SearchOptions, 'silent'> & { alwaysIncludedPackagesNames?: Set<string> } = {}\n) {\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 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,0DAAwE;AAExE,+DAAyF;AAEzF,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;I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AAC;YAEjD,IAAI,CAAC,eAAe,CAAC,cAAc,CAAC,EAAE;gBACpC,IAAI,yBAAiC,CAAC;gBAEtC,IAAI,gBAAgB,EAAE;oBACpB,eAAe,CAAC,cAAc,CAAC,GAAG,gBAAgB,CAAC;oBACnD,yBAAyB,GAAG,cAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;iBAC9E;qBAAM;oBACL,IAAI;wBACF;;;2BAGG;wBACH,MAAM,cAAc,GAAG,IAAA,sBAAa,EAAC,eAAe,CAAC,CAAC;wBACtD,yBAAyB,GAAG,cAAc,CAAC,OAAO,CAAC,GAAG,cAAc,eAAe,CAAC,CAAC;qBACtF;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,YAAY,CAAC,4CAAsB,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 { requireAndResolveExpoModuleConfig } from '../ExpoModuleConfig';\nimport { PackageRevision, SearchOptions, SearchResults } from '../types';\nimport { mergeLinkingOptionsAsync, projectPackageJsonPath } from './mergeLinkingOptions';\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 =\n options.nativeModulesDir && fs.existsSync(options.nativeModulesDir)\n ? [options.nativeModulesDir, ...options.searchPaths]\n : options.searchPaths;\n\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 // 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) {\n return searchResults;\n }\n\n return filterToProjectDependencies(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 */\nfunction filterToProjectDependencies(\n results: SearchResults,\n options: Pick<SearchOptions, 'silent'> & { alwaysIncludedPackagesNames?: Set<string> } = {}\n) {\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 visitPackage(projectPackageJsonPath);\n\n return filteredResults;\n}\n"]}
|
|
@@ -53,27 +53,28 @@ async function findDefaultPathsAsync(cwd) {
|
|
|
53
53
|
while ((pkgJsonPath = await (0, find_up_1.default)('package.json', { cwd: dir }))) {
|
|
54
54
|
dir = path_1.default.dirname(path_1.default.dirname(pkgJsonPath));
|
|
55
55
|
paths.push(path_1.default.join(pkgJsonPath, '..', 'node_modules'));
|
|
56
|
+
// This stops the infinite loop when the package.json is placed at the root dir.
|
|
57
|
+
if (path_1.default.dirname(dir) === dir) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
56
60
|
}
|
|
57
61
|
return paths;
|
|
58
62
|
}
|
|
59
63
|
/**
|
|
60
64
|
* Finds the real path to custom native modules directory.
|
|
65
|
+
* - When {@link cwd} is inside the project directory, the path is searched relatively
|
|
66
|
+
* to the project root (directory with the `package.json` file).
|
|
67
|
+
* - When {@link cwd} is outside project directory (no `package.json` found), it is relative to
|
|
68
|
+
* the current working directory (the {@link cwd} param).
|
|
69
|
+
*
|
|
70
|
+
* @param nativeModulesDir path to custom native modules directory. Defaults to `"./modules"` if null.
|
|
71
|
+
* @param cwd current working directory
|
|
61
72
|
* @returns resolved native modules directory or `null` if it is not found or doesn't exist.
|
|
62
73
|
*/
|
|
63
74
|
async function resolveNativeModulesDirAsync(nativeModulesDir, cwd) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (await fs_extra_1.default.pathExists(nativeModulesDirPath)) {
|
|
68
|
-
return nativeModulesDirPath;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
// if not found, try to find it relative to the package.json
|
|
72
|
-
const up = await (0, find_up_1.default)('package.json', { cwd });
|
|
73
|
-
if (!up) {
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
const resolvedPath = path_1.default.join(up, '..', nativeModulesDir || 'modules');
|
|
75
|
+
const packageJsonPath = await (0, find_up_1.default)('package.json', { cwd });
|
|
76
|
+
const projectRoot = packageJsonPath != null ? path_1.default.join(packageJsonPath, '..') : cwd;
|
|
77
|
+
const resolvedPath = path_1.default.resolve(projectRoot, nativeModulesDir || 'modules');
|
|
77
78
|
return fs_extra_1.default.existsSync(resolvedPath) ? resolvedPath : null;
|
|
78
79
|
}
|
|
79
80
|
//# sourceMappingURL=mergeLinkingOptions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeLinkingOptions.js","sourceRoot":"","sources":["../../src/autolinking/mergeLinkingOptions.ts"],"names":[],"mappings":";;;;;;AAAA,sDAA6B;AAC7B,wDAA0B;AAC1B,gDAAwB;AAIxB;;GAEG;AACU,QAAA,sBAAsB,GAAG,iBAAM,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAW,CAAC;AAEpG,mFAAmF;AACnF,IAAI,CAAC,8BAAsB,EAAE;IAC3B,MAAM,IAAI,KAAK,CAAC,8CAA8C,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;CACjF;AAED;;;;;GAKG;AACI,KAAK,UAAU,wBAAwB,CAC5C,eAA4B;;IAE5B,MAAM,WAAW,GAAG,OAAO,CAAC,8BAAsB,CAAC,CAAC;IACpD,MAAM,WAAW,GAAG,MAAA,WAAW,CAAC,IAAI,0CAAE,WAAW,CAAC;IAClD,MAAM,eAAe,GAAG,eAAe,CAAC,QAAQ,KAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,eAAe,CAAC,QAAQ,CAAC,CAAA,CAAC;IAC5F,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAChC,EAAE,EACF,WAAW,EACX,eAAe,EACf,eAAe,C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import path from 'path';\n\nimport { SearchOptions } from '../types';\n\n/**\n * Path to the `package.json` of the closest project in the current working dir.\n */\nexport const 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 * Merges autolinking options from different sources (the later the higher priority)\n * - options defined in package.json's `expo.autolinking` field\n * - platform-specific options from the above (e.g. `expo.autolinking.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 finalOptions.nativeModulesDir = await resolveNativeModulesDirAsync(\n finalOptions.nativeModulesDir,\n process.cwd()\n );\n\n return finalOptions;\n}\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 */\nasync 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 // This stops the infinite loop when the package.json is placed at the root dir.\n if (path.dirname(dir) === dir) {\n break;\n }\n }\n return paths;\n}\n\n/**\n * Finds the real path to custom native modules directory.\n * - When {@link cwd} is inside the project directory, the path is searched relatively\n * to the project root (directory with the `package.json` file).\n * - When {@link cwd} is outside project directory (no `package.json` found), it is relative to\n * the current working directory (the {@link cwd} param).\n *\n * @param nativeModulesDir path to custom native modules directory. Defaults to `\"./modules\"` if null.\n * @param cwd current working directory\n * @returns resolved native modules directory or `null` if it is not found or doesn't exist.\n */\nasync function resolveNativeModulesDirAsync(\n nativeModulesDir: string | null | undefined,\n cwd: string\n): Promise<string | null> {\n const packageJsonPath = await findUp('package.json', { cwd });\n const projectRoot = packageJsonPath != null ? path.join(packageJsonPath, '..') : cwd;\n const resolvedPath = path.resolve(projectRoot, nativeModulesDir || 'modules');\n return fs.existsSync(resolvedPath) ? resolvedPath : null;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-modules-autolinking",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "Scripts that autolink Expo modules.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -48,5 +48,5 @@
|
|
|
48
48
|
"find-up": "^5.0.0",
|
|
49
49
|
"fs-extra": "^9.1.0"
|
|
50
50
|
},
|
|
51
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "6e131f2da851a47c3a24eb3d6fc971a1a7822086"
|
|
52
52
|
}
|
|
@@ -26,7 +26,6 @@ module Expo
|
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
global_flags = @options.fetch(:flags, {})
|
|
29
|
-
tests = @options.fetch(:tests, [])
|
|
30
29
|
|
|
31
30
|
project_directory = Pod::Config.instance.project_root
|
|
32
31
|
|
|
@@ -44,10 +43,23 @@ module Expo
|
|
|
44
43
|
|
|
45
44
|
pod_options = {
|
|
46
45
|
:path => podspec_dir_path,
|
|
47
|
-
:testspecs => tests.include?(package.name) ? ['Tests'] : [],
|
|
48
46
|
:configuration => package.debugOnly ? ['Debug'] : [] # An empty array means all configurations
|
|
49
47
|
}.merge(global_flags, package.flags)
|
|
50
48
|
|
|
49
|
+
if links_for_testing?
|
|
50
|
+
podspec_file_path = File.join(podspec_dir_path, pod.pod_name + ".podspec")
|
|
51
|
+
podspec = Pod::Specification.from_file(podspec_file_path)
|
|
52
|
+
test_specs_names = podspec.test_specs.map { |test_spec|
|
|
53
|
+
test_spec.name.delete_prefix(podspec.name + "/")
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# Jump to the next package when it doesn't have any test specs (except interfaces, they're required)
|
|
57
|
+
# TODO: Can remove interface check once we move all the interfaces into the core.
|
|
58
|
+
next if test_specs_names.empty? && !pod.pod_name.end_with?('Interface')
|
|
59
|
+
|
|
60
|
+
pod_options[:testspecs] = test_specs_names
|
|
61
|
+
end
|
|
62
|
+
|
|
51
63
|
# Install the pod.
|
|
52
64
|
@podfile.pod(pod.pod_name, pod_options)
|
|
53
65
|
|
|
@@ -81,6 +93,15 @@ module Expo
|
|
|
81
93
|
@options.fetch(:providerName, Constants::MODULES_PROVIDER_FILE_NAME)
|
|
82
94
|
end
|
|
83
95
|
|
|
96
|
+
public def links_for_testing?
|
|
97
|
+
@options.fetch(:testsOnly, false)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# For now there is no need to generate the modules provider for testing.
|
|
101
|
+
public def should_generate_modules_provider?
|
|
102
|
+
return !links_for_testing?
|
|
103
|
+
end
|
|
104
|
+
|
|
84
105
|
# privates
|
|
85
106
|
|
|
86
107
|
private def resolve
|
|
@@ -29,7 +29,7 @@ module Pod
|
|
|
29
29
|
# strip expo go versioning prefix
|
|
30
30
|
normalized_name = name.gsub(/^ABI\d+_\d+_\d+/, '')
|
|
31
31
|
|
|
32
|
-
if ['React-Core'].include?(normalized_name) && product_module_name != name
|
|
32
|
+
if ['React-Core', 'React-RCTFabric'].include?(normalized_name) && product_module_name != name
|
|
33
33
|
return sandbox.public_headers.root + name + product_module_name
|
|
34
34
|
end
|
|
35
35
|
return nil
|
|
@@ -11,7 +11,7 @@ module Expo
|
|
|
11
11
|
# Find the targets that use expo modules and need the modules provider
|
|
12
12
|
targets_with_modules_provider = targets.select do |target|
|
|
13
13
|
autolinking_manager = target.target_definition.autolinking_manager
|
|
14
|
-
autolinking_manager.present?
|
|
14
|
+
autolinking_manager.present? && autolinking_manager.should_generate_modules_provider?
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
# Find existing PBXGroup for modules providers.
|
|
@@ -105,7 +105,7 @@ module Expo
|
|
|
105
105
|
def self.set_autolinking_configuration(project)
|
|
106
106
|
project.native_targets.each do |native_target|
|
|
107
107
|
native_target.build_configurations.each do |build_configuration|
|
|
108
|
-
configuration_flag = "-D #{CONFIGURATION_FLAG_PREFIX}#{build_configuration.
|
|
108
|
+
configuration_flag = "-D #{CONFIGURATION_FLAG_PREFIX}#{build_configuration.debug? ? "DEBUG" : "RELEASE"}"
|
|
109
109
|
build_settings = build_configuration.build_settings
|
|
110
110
|
|
|
111
111
|
# For some targets it might be `nil` by default which is an equivalent to `$(inherited)`
|
|
@@ -54,12 +54,15 @@ module Expo
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
result
|
|
58
|
+
.select { |dir| dir.include? '/node_modules/' }
|
|
59
|
+
.reject do |dir|
|
|
60
|
+
# Exclude known dirs unnecessary to patch and reduce processing time
|
|
61
|
+
# Since we are using real (absolute) pathnames we need to assert that we are inside of the node_modules
|
|
62
|
+
# directory to not collide with other directories in the user's filesystem.
|
|
63
|
+
# We reject the react-native package and packages starting with expo-
|
|
64
|
+
dir.match(%r{^.*/node_modules/(react-native(/.*)?|expo-.*)$})
|
|
65
|
+
end
|
|
63
66
|
end
|
|
64
67
|
|
|
65
68
|
end # class ReactImportPatcher
|
|
@@ -124,13 +124,19 @@ function addRevisionToResults(
|
|
|
124
124
|
* // Given the following file exists: /foo/myapp/modules/mymodule/expo-module.config.json
|
|
125
125
|
* await findPackagesConfigPathsAsync('/foo/myapp/modules');
|
|
126
126
|
* // returns ['mymodule/expo-module.config.json']
|
|
127
|
+
*
|
|
128
|
+
* await findPackagesConfigPathsAsync('/foo/myapp/modules/mymodule');
|
|
129
|
+
* // returns ['expo-module.config.json']
|
|
127
130
|
* ```
|
|
128
131
|
*/
|
|
129
132
|
async function findPackagesConfigPathsAsync(searchPath: string): Promise<string[]> {
|
|
130
133
|
const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';
|
|
131
|
-
const paths = await glob(
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
const paths = await glob(
|
|
135
|
+
[`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`, `./${bracedFilenames}`],
|
|
136
|
+
{
|
|
137
|
+
cwd: searchPath,
|
|
138
|
+
}
|
|
139
|
+
);
|
|
134
140
|
|
|
135
141
|
// If the package has multiple configs (e.g. `unimodule.json` and `expo-module.config.json` during the transition time)
|
|
136
142
|
// then we want to give `expo-module.config.json` the priority.
|
|
@@ -68,31 +68,32 @@ async function findDefaultPathsAsync(cwd: string): Promise<string[]> {
|
|
|
68
68
|
while ((pkgJsonPath = await findUp('package.json', { cwd: dir }))) {
|
|
69
69
|
dir = path.dirname(path.dirname(pkgJsonPath));
|
|
70
70
|
paths.push(path.join(pkgJsonPath, '..', 'node_modules'));
|
|
71
|
+
|
|
72
|
+
// This stops the infinite loop when the package.json is placed at the root dir.
|
|
73
|
+
if (path.dirname(dir) === dir) {
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
71
76
|
}
|
|
72
77
|
return paths;
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
/**
|
|
76
81
|
* Finds the real path to custom native modules directory.
|
|
82
|
+
* - When {@link cwd} is inside the project directory, the path is searched relatively
|
|
83
|
+
* to the project root (directory with the `package.json` file).
|
|
84
|
+
* - When {@link cwd} is outside project directory (no `package.json` found), it is relative to
|
|
85
|
+
* the current working directory (the {@link cwd} param).
|
|
86
|
+
*
|
|
87
|
+
* @param nativeModulesDir path to custom native modules directory. Defaults to `"./modules"` if null.
|
|
88
|
+
* @param cwd current working directory
|
|
77
89
|
* @returns resolved native modules directory or `null` if it is not found or doesn't exist.
|
|
78
90
|
*/
|
|
79
91
|
async function resolveNativeModulesDirAsync(
|
|
80
92
|
nativeModulesDir: string | null | undefined,
|
|
81
93
|
cwd: string
|
|
82
94
|
): Promise<string | null> {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (await fs.pathExists(nativeModulesDirPath)) {
|
|
87
|
-
return nativeModulesDirPath;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// if not found, try to find it relative to the package.json
|
|
92
|
-
const up = await findUp('package.json', { cwd });
|
|
93
|
-
if (!up) {
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
const resolvedPath = path.join(up, '..', nativeModulesDir || 'modules');
|
|
95
|
+
const packageJsonPath = await findUp('package.json', { cwd });
|
|
96
|
+
const projectRoot = packageJsonPath != null ? path.join(packageJsonPath, '..') : cwd;
|
|
97
|
+
const resolvedPath = path.resolve(projectRoot, nativeModulesDir || 'modules');
|
|
97
98
|
return fs.existsSync(resolvedPath) ? resolvedPath : null;
|
|
98
99
|
}
|