A library for interacting with the app.json configuration files in Expo projects
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Automatic detection and validation of Expo SDK versions from configuration files or installed packages, ensuring compatibility and proper versioning.
Resolve the Expo SDK version for a project from configuration or installed packages.
/**
* Resolve the Expo SDK Version from input config or installed expo package
* First checks the provided config, then falls back to package version detection
* @param projectRoot - Project root directory
* @param exp - Optional config object with sdkVersion
* @returns SDK version string (e.g., "51.0.0")
* @throws ConfigError if expo package not found or invalid
*/
function getExpoSDKVersion(
projectRoot: string,
exp?: Pick<ExpoConfig, 'sdkVersion'>
): string;Usage Examples:
import { getExpoSDKVersion } from "@expo/config";
// Get SDK version from project
const sdkVersion = getExpoSDKVersion("/path/to/expo-project");
// Result: "51.0.0" (from installed expo package or config)
// Use specific config
const configWithSDK = { sdkVersion: "50.0.0" };
const specifiedVersion = getExpoSDKVersion("/path/to/project", configWithSDK);
// Result: "50.0.0" (uses provided version)
// Auto-detect from installed expo package
const autoVersion = getExpoSDKVersion("/path/to/project", {});
// Reads from node_modules/expo/package.jsonThe SDK version resolution follows this priority order:
exp.sdkVersion is provided, use it directlyexpo packageThe function converts npm package versions to SDK versions:
51.0.15 → SDK version 51.0.050.1.2 → SDK version 50.0.049.0.21 → SDK version 49.0.0The major version number is preserved, while minor and patch are normalized to .0.0.
SDK version resolution may fail with specific error conditions:
// Thrown when expo package is not installed
throw new ConfigError(
"Cannot determine the project's Expo SDK version because the module `expo` is not installed. Install it with `npm install expo` and try again.",
'MODULE_NOT_FOUND'
);
// Thrown when expo package.json is invalid
throw new ConfigError(
"Cannot determine the project's Expo SDK version because the module `expo` has an invalid package.json (missing `version` field). Try reinstalling node modules and trying again.",
'MODULE_NOT_FOUND'
);Error Handling Examples:
import { getExpoSDKVersion, ConfigError } from "@expo/config";
try {
const sdkVersion = getExpoSDKVersion("/path/to/project");
console.log("SDK Version:", sdkVersion);
} catch (error) {
if (error instanceof ConfigError) {
switch (error.code) {
case 'MODULE_NOT_FOUND':
console.log("Please install expo: npm install expo");
break;
default:
console.log("Configuration error:", error.message);
}
}
}SDK version resolution is automatically integrated into the main configuration system:
import { getConfig } from "@expo/config";
// SDK version is automatically resolved and included
const config = getConfig("/path/to/project");
console.log("Auto-resolved SDK:", config.exp.sdkVersion);
// Skip SDK version validation for incomplete projects
const configNoSDK = getConfig("/path/to/project", {
skipSDKVersionRequirement: true
});
// Won't throw if expo package missing// Part of ExpoConfig interface
interface ExpoConfig {
/** Expo SDK version (e.g., "51.0.0", "UNVERSIONED") */
sdkVersion?: string;
// ... other config properties
}
// Error codes related to SDK version resolution
type ConfigErrorCode =
| 'MODULE_NOT_FOUND' // expo package not found
| 'INVALID_CONFIG' // invalid package.json
// ... other error codesDifferent SDK versions may have different configuration requirements:
The SDK version affects:
managed vs bare)