expo-modules-autolinking 1.5.2 → 1.7.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 +16 -0
- package/build/ExpoModuleConfig.js +1 -0
- package/build/ExpoModuleConfig.js.map +1 -1
- package/build/autolinking/findModules.js +18 -9
- package/build/autolinking/findModules.js.map +1 -1
- package/package.json +4 -5
- package/scripts/ios/xcode_env_generator.rb +24 -0
- package/src/autolinking/findModules.ts +22 -9
- package/tsconfig.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -10,6 +10,22 @@
|
|
|
10
10
|
|
|
11
11
|
### 💡 Others
|
|
12
12
|
|
|
13
|
+
## 1.7.0 — 2023-10-17
|
|
14
|
+
|
|
15
|
+
### 💡 Others
|
|
16
|
+
|
|
17
|
+
- Transpile for Node 18 (LTS). ([#24471](https://github.com/expo/expo/pull/24471) by [@EvanBacon](https://github.com/EvanBacon))
|
|
18
|
+
|
|
19
|
+
## 1.6.0 — 2023-09-15
|
|
20
|
+
|
|
21
|
+
### 🐛 Bug fixes
|
|
22
|
+
|
|
23
|
+
- Maintain hierarchical order when linking isolated modules ([#24351](https://github.com/expo/expo/pull/24351) by [@byCedric](https://github.com/byCedric))
|
|
24
|
+
|
|
25
|
+
### 💡 Others
|
|
26
|
+
|
|
27
|
+
- [iOS] Disable packager and bundle JS when EX_UPDATES_NATIVE_DEBUG set. ([#24366](https://github.com/expo/expo/pull/24366) by [@douglowder](https://github.com/douglowder))
|
|
28
|
+
|
|
13
29
|
## 1.5.2 — 2023-09-04
|
|
14
30
|
|
|
15
31
|
### 🐛 Bug fixes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoModuleConfig.js","sourceRoot":"","sources":["../src/ExpoModuleConfig.ts"],"names":[],"mappings":";;;AAEA,SAAS,QAAQ,CAAI,KAA0B;IAC7C,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QACxB,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CAAC;IACnD,CAAC;IAED;;OAEG;IACH,mBAAmB;QACjB,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;IACvD,CAAC;IAED;;OAEG;IACH,YAAY;QACV,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,SAAS,IAAI,KAAK,CAAC;IAChD,CAAC;IAED;;OAEG;IACH,cAAc;QACZ,MAAM,aAAa,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;QAE7C,4DAA4D;QAC5D,OAAO,aAAa,EAAE,OAAO,IAAI,aAAa,EAAE,iBAAiB,IAAI,EAAE,CAAC;IAC1E,CAAC;IAED;;OAEG;IACH,kBAAkB;QAChB,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,UAAU,IAAI,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED;;OAEG;IACH,oBAAoB;QAClB,OAAO,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,aAAa,IAAI,EAAE,CAAC,CAAC;IAC/D,CAAC;IAED;;OAEG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;CACF;AArFD,4CAqFC;AAED;;GAEG;AACH,SAAgB,iCAAiC,CAAC,IAAY;IAC5D,kDAAkD;IAClD,4DAA4D;IAC5D,OAAO,IAAI,gBAAgB,CAAC,OAAO,CAAC,IAAI,CAAwB,CAAC,CAAC;AACpE,CAAC;AAJD,8EAIC","sourcesContent":["import { AndroidGradlePluginDescriptor, RawExpoModuleConfig, SupportedPlatform } from './types';\n\nfunction arrayize<T>(value: T[] | T | undefined): T[] {\n if (Array.isArray(value)) {\n return value;\n }\n return value != null ? [value] : [];\n}\n\n/**\n * A class that wraps the raw config (`expo-module.json` or `unimodule.json`).\n */\nexport class ExpoModuleConfig {\n constructor(readonly rawConfig: RawExpoModuleConfig) {}\n\n /**\n * Whether the module supports given platform.\n */\n supportsPlatform(platform: SupportedPlatform): boolean {\n return this.rawConfig.platforms?.includes(platform) ?? false;\n }\n\n /**\n * Returns a list of names of Swift native modules classes to put to the generated modules provider file.\n */\n iosModules() {\n const iosConfig = this.rawConfig.ios;\n\n // `modulesClassNames` is a legacy name for the same config.\n return iosConfig?.modules ?? iosConfig?.modulesClassNames ?? [];\n }\n\n /**\n * Returns a list of names of Swift classes that receives AppDelegate life-cycle events.\n */\n iosAppDelegateSubscribers(): string[] {\n return this.rawConfig.ios?.appDelegateSubscribers ?? [];\n }\n\n /**\n * Returns a list of names of Swift classes that implement `ExpoReactDelegateHandler`.\n */\n iosReactDelegateHandlers(): string[] {\n return this.rawConfig.ios?.reactDelegateHandlers ?? [];\n }\n\n /**\n * Returns podspec paths defined by the module author.\n */\n iosPodspecPaths(): string[] {\n return arrayize(this.rawConfig.ios?.podspecPath);\n }\n\n /**\n * Returns the product module names, if defined by the module author.\n */\n iosSwiftModuleNames(): string[] {\n return arrayize(this.rawConfig.ios?.swiftModuleName);\n }\n\n /**\n * Returns whether this module will be added only to the debug configuration\n */\n iosDebugOnly(): boolean {\n return this.rawConfig.ios?.debugOnly ?? false;\n }\n\n /**\n * Returns a list of names of Kotlin native modules classes to put to the generated package provider file.\n */\n androidModules() {\n const androidConfig = this.rawConfig.android;\n\n // `modulesClassNames` is a legacy name for the same config.\n return androidConfig?.modules ?? androidConfig?.modulesClassNames ?? [];\n }\n\n /**\n * Returns build.gradle file paths defined by the module author.\n */\n androidGradlePaths(): string[] {\n return arrayize(this.rawConfig.android?.gradlePath ?? []);\n }\n\n /**\n * Returns gradle plugins descriptors defined by the module author.\n */\n androidGradlePlugins(): AndroidGradlePluginDescriptor[] {\n return arrayize(this.rawConfig.android?.gradlePlugins ?? []);\n }\n\n /**\n * Returns serializable raw config.\n */\n toJSON(): RawExpoModuleConfig {\n return this.rawConfig;\n }\n}\n\n/**\n * Reads the config at given path and returns the config wrapped by `ExpoModuleConfig` class.\n */\nexport function requireAndResolveExpoModuleConfig(path: string): ExpoModuleConfig {\n // TODO: Validate the raw config against a schema.\n // TODO: Support for `*.js` files, not only static `*.json`.\n return new ExpoModuleConfig(require(path) as RawExpoModuleConfig);\n}\n"]}
|
|
@@ -21,9 +21,10 @@ async function findModulesAsync(providedOptions) {
|
|
|
21
21
|
const results = new Map();
|
|
22
22
|
const nativeModuleNames = new Set();
|
|
23
23
|
// custom native modules should be resolved first so that they can override other modules
|
|
24
|
-
const searchPaths = options.nativeModulesDir && fs_extra_1.default.existsSync(options.nativeModulesDir)
|
|
24
|
+
const searchPaths = new Set(options.nativeModulesDir && fs_extra_1.default.existsSync(options.nativeModulesDir)
|
|
25
25
|
? [options.nativeModulesDir, ...options.searchPaths]
|
|
26
|
-
: options.searchPaths;
|
|
26
|
+
: options.searchPaths);
|
|
27
|
+
// `searchPaths` can be mutated to discover all "isolated modules groups", when using isolated modules
|
|
27
28
|
for (const searchPath of searchPaths) {
|
|
28
29
|
const isNativeModulesDir = searchPath === options.nativeModulesDir;
|
|
29
30
|
const packageConfigPaths = await findPackagesConfigPathsAsync(searchPath);
|
|
@@ -33,6 +34,20 @@ async function findModulesAsync(providedOptions) {
|
|
|
33
34
|
const { name, version } = resolvePackageNameAndVersion(packagePath, {
|
|
34
35
|
fallbackToDirName: isNativeModulesDir,
|
|
35
36
|
});
|
|
37
|
+
// Check if the project is using isolated modules, by checking
|
|
38
|
+
// if the parent dir of `packagePath` is a `node_modules` folder.
|
|
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)) {
|
|
49
|
+
searchPaths.add(maybeIsolatedModulesPath);
|
|
50
|
+
}
|
|
36
51
|
// we ignore the `exclude` option for custom native modules
|
|
37
52
|
if ((!isNativeModulesDir && options.exclude?.includes(name)) ||
|
|
38
53
|
!expoModuleConfig.supportsPlatform(options.platform)) {
|
|
@@ -109,13 +124,7 @@ function addRevisionToResults(results, name, revision) {
|
|
|
109
124
|
*/
|
|
110
125
|
async function findPackagesConfigPathsAsync(searchPath) {
|
|
111
126
|
const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';
|
|
112
|
-
const paths = await (0, fast_glob_1.default)([
|
|
113
|
-
`*/${bracedFilenames}`,
|
|
114
|
-
`@*/*/${bracedFilenames}`,
|
|
115
|
-
`./${bracedFilenames}`,
|
|
116
|
-
`.pnpm/*/node_modules/*/${bracedFilenames}`,
|
|
117
|
-
`.pnpm/*/node_modules/@*/*/${bracedFilenames}`,
|
|
118
|
-
], {
|
|
127
|
+
const paths = await (0, fast_glob_1.default)([`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`, `./${bracedFilenames}`], {
|
|
119
128
|
cwd: searchPath,
|
|
120
129
|
});
|
|
121
130
|
// 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,+DAAyF;AACzF,0DAAwE;AAGxE,8DAA8D;AAC9D,MAAM,4BAA4B,GAAG,CAAC,gBAAgB,EAAE,yBAAyB,CAAC,CAAC;AAEnF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CAAC,IAAI,CAAC,CAAC;QAEtC,4DAA4D;QAC5D,KAAK,MAAM,cAAc,IAAI,WAAW,CAAC,YAAY,EAAE;YACrD,MAAM,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;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 { mergeLinkingOptionsAsync, projectPackageJsonPath } 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 =\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 [\n `*/${bracedFilenames}`,\n `@*/*/${bracedFilenames}`,\n `./${bracedFilenames}`,\n `.pnpm/*/node_modules/*/${bracedFilenames}`,\n `.pnpm/*/node_modules/@*/*/${bracedFilenames}`,\n ],\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"]}
|
|
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,+DAAyF;AACzF,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;IAC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AO;SACR;QACD,eAAe,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAEtC,4DAA4D;QAC5D,KAAK,MAAM,cAAc,IAAI,WAAW,CAAC,YAAY,EAAE;YACrD,MAAM,gBAAgB,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;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 { mergeLinkingOptionsAsync, projectPackageJsonPath } 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) {\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-modules-autolinking",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.0",
|
|
4
4
|
"description": "Scripts that autolink Expo modules.",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -35,19 +35,18 @@
|
|
|
35
35
|
"homepage": "https://github.com/expo/expo/tree/main/packages/expo-modules-autolinking#readme",
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@expo/spawn-async": "^1.5.0",
|
|
38
|
-
"@tsconfig/node14": "^1.0.3",
|
|
39
38
|
"@types/fs-extra": "^9.0.11",
|
|
40
|
-
"expo-module-scripts": "~3.
|
|
39
|
+
"expo-module-scripts": "~3.2.0",
|
|
41
40
|
"minimatch": "^3.0.4",
|
|
42
41
|
"tempy": "^0.7.1"
|
|
43
42
|
},
|
|
44
43
|
"dependencies": {
|
|
45
|
-
"@expo/config": "~8.
|
|
44
|
+
"@expo/config": "~8.4.0",
|
|
46
45
|
"chalk": "^4.1.0",
|
|
47
46
|
"commander": "^7.2.0",
|
|
48
47
|
"fast-glob": "^3.2.5",
|
|
49
48
|
"find-up": "^5.0.0",
|
|
50
49
|
"fs-extra": "^9.1.0"
|
|
51
50
|
},
|
|
52
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "da25937e2a99661cbe5eb60ca1d8d6245fc96a50"
|
|
53
52
|
}
|
|
@@ -1,6 +1,30 @@
|
|
|
1
1
|
require 'open3'
|
|
2
2
|
require 'pathname'
|
|
3
3
|
|
|
4
|
+
def generate_or_remove_xcode_env_updates_file!()
|
|
5
|
+
project_directory = Pod::Config.instance.project_root
|
|
6
|
+
xcode_env_file = File.join(project_directory, '.xcode.env.updates')
|
|
7
|
+
|
|
8
|
+
ex_updates_native_debug = ENV['EX_UPDATES_NATIVE_DEBUG'] == '1' ||
|
|
9
|
+
ENV['EX_UPDATES_NATIVE_DEBUG'] == 'true'
|
|
10
|
+
if ex_updates_native_debug
|
|
11
|
+
Pod::UI.info "EX_UPDATES_NATIVE_DEBUG is set; auto-generating `.xcode.env.updates` to disable packager and generate debug bundle"
|
|
12
|
+
if File.exist?(xcode_env_file)
|
|
13
|
+
File.delete(xcode_env_file)
|
|
14
|
+
end
|
|
15
|
+
File.write(xcode_env_file, <<~EOS
|
|
16
|
+
export FORCE_BUNDLING=1
|
|
17
|
+
unset SKIP_BUNDLING
|
|
18
|
+
export RCT_NO_LAUNCH_PACKAGER=1
|
|
19
|
+
EOS
|
|
20
|
+
)
|
|
21
|
+
else
|
|
22
|
+
if File.exist?(xcode_env_file)
|
|
23
|
+
Pod::UI.info "EX_UPDATES_NATIVE_DEBUG has been unset; removing `.xcode.env.updates`"
|
|
24
|
+
File.delete(xcode_env_file)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
4
28
|
|
|
5
29
|
def maybe_generate_xcode_env_file!()
|
|
6
30
|
project_directory = Pod::Config.instance.project_root
|
|
@@ -21,11 +21,13 @@ export async function findModulesAsync(providedOptions: SearchOptions): Promise<
|
|
|
21
21
|
const nativeModuleNames = new Set<string>();
|
|
22
22
|
|
|
23
23
|
// custom native modules should be resolved first so that they can override other modules
|
|
24
|
-
const searchPaths =
|
|
24
|
+
const searchPaths = new Set(
|
|
25
25
|
options.nativeModulesDir && fs.existsSync(options.nativeModulesDir)
|
|
26
26
|
? [options.nativeModulesDir, ...options.searchPaths]
|
|
27
|
-
: options.searchPaths
|
|
27
|
+
: options.searchPaths
|
|
28
|
+
);
|
|
28
29
|
|
|
30
|
+
// `searchPaths` can be mutated to discover all "isolated modules groups", when using isolated modules
|
|
29
31
|
for (const searchPath of searchPaths) {
|
|
30
32
|
const isNativeModulesDir = searchPath === options.nativeModulesDir;
|
|
31
33
|
|
|
@@ -41,6 +43,23 @@ export async function findModulesAsync(providedOptions: SearchOptions): Promise<
|
|
|
41
43
|
fallbackToDirName: isNativeModulesDir,
|
|
42
44
|
});
|
|
43
45
|
|
|
46
|
+
// Check if the project is using isolated modules, by checking
|
|
47
|
+
// if the parent dir of `packagePath` is a `node_modules` folder.
|
|
48
|
+
// Isolated modules installs dependencies in small groups such as:
|
|
49
|
+
// - /.pnpm/expo@50.x.x(...)/node_modules/@expo/cli
|
|
50
|
+
// - /.pnpm/expo@50.x.x(...)/node_modules/expo
|
|
51
|
+
// - /.pnpm/expo@50.x.x(...)/node_modules/expo-application
|
|
52
|
+
// When isolated modules are detected, expand the `searchPaths`
|
|
53
|
+
// to include possible nested dependencies.
|
|
54
|
+
const maybeIsolatedModulesPath = path.join(
|
|
55
|
+
packagePath,
|
|
56
|
+
name.startsWith('@') && name.includes('/') ? '../..' : '..' // scoped packages are nested deeper
|
|
57
|
+
);
|
|
58
|
+
const isIsolatedModulesPath = path.basename(maybeIsolatedModulesPath) === 'node_modules';
|
|
59
|
+
if (isIsolatedModulesPath && !searchPaths.has(maybeIsolatedModulesPath)) {
|
|
60
|
+
searchPaths.add(maybeIsolatedModulesPath);
|
|
61
|
+
}
|
|
62
|
+
|
|
44
63
|
// we ignore the `exclude` option for custom native modules
|
|
45
64
|
if (
|
|
46
65
|
(!isNativeModulesDir && options.exclude?.includes(name)) ||
|
|
@@ -132,13 +151,7 @@ function addRevisionToResults(
|
|
|
132
151
|
async function findPackagesConfigPathsAsync(searchPath: string): Promise<string[]> {
|
|
133
152
|
const bracedFilenames = '{' + EXPO_MODULE_CONFIG_FILENAMES.join(',') + '}';
|
|
134
153
|
const paths = await glob(
|
|
135
|
-
[
|
|
136
|
-
`*/${bracedFilenames}`,
|
|
137
|
-
`@*/*/${bracedFilenames}`,
|
|
138
|
-
`./${bracedFilenames}`,
|
|
139
|
-
`.pnpm/*/node_modules/*/${bracedFilenames}`,
|
|
140
|
-
`.pnpm/*/node_modules/@*/*/${bracedFilenames}`,
|
|
141
|
-
],
|
|
154
|
+
[`*/${bracedFilenames}`, `@*/*/${bracedFilenames}`, `./${bracedFilenames}`],
|
|
142
155
|
{
|
|
143
156
|
cwd: searchPath,
|
|
144
157
|
}
|
package/tsconfig.json
CHANGED