Repository: expo/expo
File: packages/expo-build-properties/src/pluginConfig.ts (TypeScript)

Code before:
  if (
    config &&
    typeof config === 'object' &&
    'android' in config &&
    config.android &&
    typeof config.android === 'object'
  ) {
    const androidConfig = config.android as PluginConfigTypeAndroid & Record<string, unknown>;
    if (androidConfig.enableProguardInReleaseBuilds != null) {
      if (androidConfig.enableMinifyInReleaseBuilds === undefined) {
        androidConfig.enableMinifyInReleaseBuilds = !!androidConfig.enableProguardInReleaseBuilds;
      }
    }
  }
};

/**
 * Reads the hermes-compiler version from node_modules
 * @ignore
 */
function getHermesCompilerVersion(projectRoot: string): string | null {
  const hermesCompilerPackageJsonPath = resolveFrom.silent(
    resolveFrom.silent(projectRoot, 'react-native/package.json') ?? projectRoot,
    'hermes-compiler/package.json'
  );
  if (!hermesCompilerPackageJsonPath || !fs.existsSync(hermesCompilerPackageJsonPath)) {
    return null;
  }

  try {
    const packageJson = JSON.parse(fs.readFileSync(hermesCompilerPackageJsonPath, 'utf8'));
    return packageJson.version ?? null;
  } catch {
    return null;
  }
}

/**
 * @ignore
 */
export function validateConfig(config: unknown, projectRoot?: string): PluginConfigType {
  fixupDeprecatedEnableProguardInReleaseBuilds(config);
  validate(schema, config);
  maybeThrowInvalidVersions(config);

  if (
    config.android?.enableShrinkResourcesInReleaseBuilds === true &&
    config.android?.enableMinifyInReleaseBuilds !== true
  ) {
    throw new Error(
      '`android.enableShrinkResourcesInReleaseBuilds` requires `android.enableMinifyInReleaseBuilds` to be enabled.'

Review comment (suggestion):
```suggestion
  if (!hermesCompilerPackageJsonPath) {
```

The file check is redundant, if we're already catching below

Code after:
  if (
    config &&
    typeof config === 'object' &&
    'android' in config &&
    config.android &&
    typeof config.android === 'object'
  ) {
    const androidConfig = config.android as PluginConfigTypeAndroid & Record<string, unknown>;
    if (androidConfig.enableProguardInReleaseBuilds != null) {
      if (androidConfig.enableMinifyInReleaseBuilds === undefined) {
        androidConfig.enableMinifyInReleaseBuilds = !!androidConfig.enableProguardInReleaseBuilds;
      }
    }
  }
};

/**
 * Reads the hermes-compiler version from node_modules
 * @ignore
 */
function getHermesCompilerVersion(projectRoot: string): string | null {
  const reactNativePath = resolveFrom.silent(projectRoot, 'react-native/package.json');
  const hermesCompilerPackageJsonPath =
    reactNativePath && resolveFrom.silent(reactNativePath, 'hermes-compiler/package.json');
  if (!hermesCompilerPackageJsonPath) {
    return null;
  }

  try {
    const packageJson = JSON.parse(fs.readFileSync(hermesCompilerPackageJsonPath, 'utf8'));
    return packageJson.version ?? null;
  } catch {
    return null;
  }
}

/**
 * @ignore
 */
export function validateConfig(config: unknown, projectRoot?: string): PluginConfigType {
  fixupDeprecatedEnableProguardInReleaseBuilds(config);
  validate(schema, config);
  maybeThrowInvalidVersions(config);

  if (
    config.android?.enableShrinkResourcesInReleaseBuilds === true &&
    config.android?.enableMinifyInReleaseBuilds !== true
  ) {
    throw new Error(
      '`android.enableShrinkResourcesInReleaseBuilds` requires `android.enableMinifyInReleaseBuilds` to be enabled.'
    );