Skip to content

Commit 6085a1d

Browse files
authored
fix(plugin-reanimated): suppress non-actionable initializers warning (#1351)
1 parent b083b9d commit 6085a1d

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

.changeset/odd-chefs-hang.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@callstack/repack-plugin-reanimated": patch
3+
---
4+
5+
Suppress non-actionable critical dependency warnings from `react-native-worklets` and legacy `react-native-reanimated` `initializers` modules during dev server builds.

packages/plugin-reanimated/src/plugin.ts

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,46 @@ import semver, { type SemVer } from 'semver';
44
import type { Compiler as WebpackCompiler } from 'webpack';
55
import { createReanimatedModuleRules } from './rules.js';
66

7+
const REANIMATED_SETUP_TESTS_WARNING =
8+
/'`setUpTests` is available only in Jest environment\.'/;
9+
const WORKLETS_CRITICAL_DEPENDENCY_WARNING =
10+
/Critical dependency: require function is used in a way in which dependencies cannot be statically extracted/;
11+
const WORKLETS_INITIALIZERS_MODULE =
12+
/react-native-(?:worklets|reanimated)[\\/].*initializers(?:\.[cm]?[jt]sx?)?/;
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+
747
interface 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-
/'`setUpTests` is available only in Jest environment\.'/.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

Comments
 (0)