isCppModule function

bool isCppModule(
  1. File specFile
)

Returns true when the spec file declares at least one platform as a direct C++ implementation (no JNI/Swift bridge). Recognises both:

  • Legacy shorthand: NativeImpl.cpp
  • Per-platform types: AppleNativeImpl.cpp, AndroidNativeImpl.cpp, WindowsNativeImpl.cpp, LinuxNativeImpl.cpp

Broad check — true if ANY platform uses C++. Use for deciding whether to create a HybridXxx.cpp stub file or load the library on Android.

Implementation

bool isCppModule(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|android|macos|windows|linux)\s*:\s*'
    r'(?:NativeImpl|AppleNativeImpl|AndroidNativeImpl|WindowsNativeImpl|LinuxNativeImpl)\.cpp\b',
  ).hasMatch(annotation);
}