isAppleCppModule function

bool isAppleCppModule(
  1. File specFile
)

Returns true when the spec file uses direct C++ for Apple platforms (ios or macos). Only Apple C++ modules need a HybridXxx.cpp forwarder in ios/Classes/ or macos/Classes/ so CocoaPods compiles the implementation into the pod target.

Implementation

bool isAppleCppModule(File specFile) {
  final content = specFile.readAsStringSync();
  final annotationMatch = RegExp(r'@NitroModule\s*\(([^)]+)\)', dotAll: true).firstMatch(content);
  if (annotationMatch == null) return false;
  final annotation = annotationMatch.group(1)!.replaceAll('\n', ' ');
  return RegExp(
    r'\b(?:ios|macos)\s*:\s*(?:NativeImpl|AppleNativeImpl)\.cpp\b',
  ).hasMatch(annotation);
}