chore: add mobile app

This commit is contained in:
2026-02-07 22:33:02 +01:00
parent db34640acc
commit e89384ad4e
29327 changed files with 3886944 additions and 12 deletions
@@ -0,0 +1,65 @@
import { discoverExpoModuleConfigAsync } from '../ExpoModuleConfig';
import { AutolinkingOptions } from '../commands/autolinkingOptions';
import {
type DependencyResolution,
scanDependenciesRecursively,
scanDependenciesInSearchPath,
filterMapResolutionResult,
mergeResolutionResults,
} from '../dependencies';
import { PackageRevision, SearchResults, SupportedPlatform } from '../types';
export async function resolveExpoModule(
resolution: DependencyResolution,
platform: SupportedPlatform,
excludeNames: Set<string>
): Promise<PackageRevision | null> {
if (excludeNames.has(resolution.name)) {
return null;
}
const expoModuleConfig = await discoverExpoModuleConfigAsync(resolution.path);
if (expoModuleConfig && expoModuleConfig.supportsPlatform(platform)) {
return {
name: resolution.name,
path: resolution.path,
version: resolution.version,
config: expoModuleConfig,
duplicates:
resolution.duplicates?.map((duplicate) => ({
name: duplicate.name,
path: duplicate.path,
version: duplicate.version,
})) ?? [],
};
} else {
return null;
}
}
interface FindModulesParams {
appRoot: string;
autolinkingOptions: AutolinkingOptions & { platform: SupportedPlatform };
}
/** Searches for modules to link based on given config. */
export async function findModulesAsync({
appRoot,
autolinkingOptions,
}: FindModulesParams): Promise<SearchResults> {
const excludeNames = new Set(autolinkingOptions.exclude);
// custom native modules should be resolved first so that they can override other modules
const searchPaths = autolinkingOptions.nativeModulesDir
? [autolinkingOptions.nativeModulesDir, ...autolinkingOptions.searchPaths]
: autolinkingOptions.searchPaths;
return filterMapResolutionResult(
mergeResolutionResults(
await Promise.all([
...searchPaths.map((searchPath) => scanDependenciesInSearchPath(searchPath)),
scanDependenciesRecursively(appRoot),
])
),
(resolution) => resolveExpoModule(resolution, autolinkingOptions.platform, excludeNames)
);
}
@@ -0,0 +1,45 @@
import { getLinkingImplementationForPlatform } from '../platforms';
import { ModuleDescriptor, ModuleDescriptorIos, SupportedPlatform } from '../types';
interface GeneratePackageListParams {
platform: SupportedPlatform;
targetPath: string;
namespace: string;
}
/** Generates a source file listing all packages to link (Android-only) */
export async function generatePackageListAsync(
modules: ModuleDescriptor[],
params: GeneratePackageListParams
) {
const platformLinking = getLinkingImplementationForPlatform(params.platform);
if (!('generatePackageListAsync' in platformLinking)) {
throw new Error(`Generating package list is not available for platform "${params.platform}"`);
}
await platformLinking.generatePackageListAsync(modules, params.targetPath, params.namespace);
}
interface GenerateModulesProviderParams {
platform: SupportedPlatform;
targetPath: string;
entitlementPath: string | null;
}
/** Generates ExpoModulesProvider file listing all packages to link (Apple-only)
*/
export async function generateModulesProviderAsync(
modules: ModuleDescriptor[],
params: GenerateModulesProviderParams
) {
const platformLinking = getLinkingImplementationForPlatform(params.platform);
if (!('generateModulesProviderAsync' in platformLinking)) {
throw new Error(
`Generating modules provider is not available for platform "${params.platform}"`
);
}
await platformLinking.generateModulesProviderAsync(
modules as ModuleDescriptorIos[],
params.targetPath,
params.entitlementPath
);
}
@@ -0,0 +1,18 @@
import { AutolinkingOptions } from '../commands/autolinkingOptions';
import { getLinkingImplementationForPlatform } from '../platforms';
import type { SupportedPlatform } from '../types';
interface GetConfigurationParams {
autolinkingOptions: AutolinkingOptions & { platform: SupportedPlatform };
}
export function getConfiguration({
autolinkingOptions,
}: GetConfigurationParams): Record<string, any> | undefined {
const platformLinking = getLinkingImplementationForPlatform(autolinkingOptions.platform);
if ('getConfiguration' in platformLinking) {
return platformLinking.getConfiguration(autolinkingOptions);
} else {
return undefined;
}
}
@@ -0,0 +1,58 @@
import { AutolinkingOptions, createAutolinkingOptionsLoader } from '../commands/autolinkingOptions';
import { ExtraDependencies, ModuleDescriptor, SearchResults, SupportedPlatform } from '../types';
import { findModulesAsync } from './findModules';
import { resolveExtraBuildDependenciesAsync, resolveModulesAsync } from './resolveModules';
export { getConfiguration } from './getConfiguration';
export { generateModulesProviderAsync, generatePackageListAsync } from './generatePackageList';
/** @deprecated */
export interface SearchOptions extends Partial<AutolinkingOptions> {
projectRoot: string;
platform: SupportedPlatform;
[extra: string]: unknown;
}
/** @deprecated */
export interface ResolveOptions {
projectRoot: string;
platform: SupportedPlatform;
[extra: string]: unknown;
}
/** @deprecated */
async function apiFindModulesAsync(providedOptions: SearchOptions): Promise<SearchResults> {
const autolinkingOptionsLoader = createAutolinkingOptionsLoader(providedOptions);
return findModulesAsync({
appRoot: await autolinkingOptionsLoader.getAppRoot(),
autolinkingOptions: await autolinkingOptionsLoader.getPlatformOptions(providedOptions.platform),
});
}
/** @deprecated */
async function apiResolveExtraBuildDependenciesAsync(
providedOptions: ResolveOptions
): Promise<ExtraDependencies> {
return resolveExtraBuildDependenciesAsync({
commandRoot: providedOptions.projectRoot,
platform: providedOptions.platform,
});
}
/** @deprecated */
async function apiResolveModulesAsync(
searchResults: SearchResults,
providedOptions: SearchOptions
): Promise<ModuleDescriptor[]> {
const autolinkingOptionsLoader = createAutolinkingOptionsLoader(providedOptions);
return resolveModulesAsync(
searchResults,
await autolinkingOptionsLoader.getPlatformOptions(providedOptions.platform)
);
}
export {
apiFindModulesAsync as findModulesAsync,
apiResolveExtraBuildDependenciesAsync as resolveExtraBuildDependenciesAsync,
apiResolveModulesAsync as resolveModulesAsync,
};
@@ -0,0 +1,59 @@
import { AutolinkingOptions } from '../commands/autolinkingOptions';
import { getLinkingImplementationForPlatform } from '../platforms';
import type {
ExtraDependencies,
ModuleDescriptor,
SearchResults,
SupportedPlatform,
} from '../types';
/** Resolves search results to a list of platform-specific configuration. */
export async function resolveModulesAsync(
searchResults: SearchResults,
autolinkingOptions: AutolinkingOptions & { platform: SupportedPlatform }
): Promise<ModuleDescriptor[]> {
const platformLinking = getLinkingImplementationForPlatform(autolinkingOptions.platform);
// Additional output property for Cocoapods flags
const extraOutput = { flags: autolinkingOptions.flags };
const moduleDescriptorList = await Promise.all(
Object.entries(searchResults).map(async ([packageName, revision]) => {
const resolvedModule = await platformLinking.resolveModuleAsync(
packageName,
revision,
extraOutput
);
return resolvedModule
? {
...resolvedModule,
packageVersion: revision.version,
packageName: resolvedModule.packageName ?? packageName,
}
: null;
})
);
return moduleDescriptorList
.filter((moduleDescriptor) => moduleDescriptor != null)
.sort((a, b) => a.packageName.localeCompare(b.packageName));
}
interface ResolveExtraBuildDependenciesParams {
commandRoot: string;
platform: SupportedPlatform;
}
/** Resolves the extra build dependencies for the project, such as additional Maven repositories or CocoaPods pods. */
export async function resolveExtraBuildDependenciesAsync({
commandRoot,
platform,
}: ResolveExtraBuildDependenciesParams): Promise<ExtraDependencies> {
const platformLinking = getLinkingImplementationForPlatform(platform);
const extraDependencies = await platformLinking.resolveExtraBuildDependenciesAsync(
// NOTE: We assume we must be inside the native folder here
// The `resolve` command either is invoked in the CWD of `./{android,ios}` or has a `--project-root`
// that's in the native directory
commandRoot
);
return extraDependencies ?? [];
}