@@ -4,6 +4,46 @@ import semver, { type SemVer } from 'semver';
44import type { Compiler as WebpackCompiler } from 'webpack' ;
55import { createReanimatedModuleRules } from './rules.js' ;
66
7+ const REANIMATED_SETUP_TESTS_WARNING =
8+ / ' ` s e t U p T e s t s ` i s a v a i l a b l e o n l y i n J e s t e n v i r o n m e n t \. ' / ;
9+ const WORKLETS_CRITICAL_DEPENDENCY_WARNING =
10+ / C r i t i c a l d e p e n d e n c y : r e q u i r e f u n c t i o n i s u s e d i n a w a y i n w h i c h d e p e n d e n c i e s c a n n o t b e s t a t i c a l l y e x t r a c t e d / ;
11+ const WORKLETS_INITIALIZERS_MODULE =
12+ / r e a c t - n a t i v e - (?: w o r k l e t s | r e a n i m a t e d ) [ \\ / ] .* i n i t i a l i z e r s (?: \. [ c m ] ? [ j t ] s x ? ) ? / ;
13+
14+ type WarningLike = {
15+ message ?: unknown ;
16+ details ?: unknown ;
17+ moduleName ?: unknown ;
18+ moduleIdentifier ?: unknown ;
19+ module ?: {
20+ resource ?: unknown ;
21+ userRequest ?: unknown ;
22+ } ;
23+ } ;
24+
25+ function warningToSearchableText ( warning : unknown ) : string {
26+ if ( typeof warning === 'string' ) {
27+ return warning ;
28+ }
29+
30+ if ( ! warning || typeof warning !== 'object' ) {
31+ return '' ;
32+ }
33+
34+ const warningObject = warning as WarningLike ;
35+ return [
36+ warningObject . message ,
37+ warningObject . details ,
38+ warningObject . moduleName ,
39+ warningObject . moduleIdentifier ,
40+ warningObject . module ?. resource ,
41+ warningObject . module ?. userRequest ,
42+ ]
43+ . filter ( ( value ) : value is string => typeof value === 'string' )
44+ . join ( '\n' ) ;
45+ }
46+
747interface ReanimatedPluginOptions {
848 /**
949 * Custom options passed to 'react-native-reanimated/plugin' or 'react-native-worklets/plugin' babel plugins.
@@ -51,11 +91,14 @@ export class ReanimatedPlugin {
5191
5292 // ignore the 'setUpTests' warning from reanimated which is not relevant
5393 compiler . options . ignoreWarnings = compiler . options . ignoreWarnings ?? [ ] ;
54- compiler . options . ignoreWarnings . push ( ( warning ) =>
55- / ' ` s e t U p T e s t s ` i s a v a i l a b l e o n l y i n J e s t e n v i r o n m e n t \. ' / . test (
56- warning . message
57- )
58- ) ;
94+ compiler . options . ignoreWarnings . push ( ( warning ) => {
95+ const warningText = warningToSearchableText ( warning ) ;
96+ return (
97+ REANIMATED_SETUP_TESTS_WARNING . test ( warningText ) ||
98+ ( WORKLETS_CRITICAL_DEPENDENCY_WARNING . test ( warningText ) &&
99+ WORKLETS_INITIALIZERS_MODULE . test ( warningText ) )
100+ ) ;
101+ } ) ;
59102 }
60103
61104 private ensureDependencyInstalled ( context : string , dependency : string ) {
0 commit comments