Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/odd-chefs-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@callstack/repack-plugin-reanimated": patch
---

Suppress non-actionable critical dependency warnings from `react-native-worklets` and legacy `react-native-reanimated` `initializers` modules during dev server builds.
53 changes: 48 additions & 5 deletions packages/plugin-reanimated/src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,46 @@ import semver, { type SemVer } from 'semver';
import type { Compiler as WebpackCompiler } from 'webpack';
import { createReanimatedModuleRules } from './rules.js';

const REANIMATED_SETUP_TESTS_WARNING =
/'`setUpTests` is available only in Jest environment\.'/;
const WORKLETS_CRITICAL_DEPENDENCY_WARNING =
/Critical dependency: require function is used in a way in which dependencies cannot be statically extracted/;
const WORKLETS_INITIALIZERS_MODULE =
/react-native-(?:worklets|reanimated)[\\/].*initializers(?:\.[cm]?[jt]sx?)?/;

type WarningLike = {
message?: unknown;
details?: unknown;
moduleName?: unknown;
moduleIdentifier?: unknown;
module?: {
resource?: unknown;
userRequest?: unknown;
};
};

function warningToSearchableText(warning: unknown): string {
if (typeof warning === 'string') {
return warning;
}

if (!warning || typeof warning !== 'object') {
return '';
}

const warningObject = warning as WarningLike;
return [
warningObject.message,
warningObject.details,
warningObject.moduleName,
warningObject.moduleIdentifier,
warningObject.module?.resource,
warningObject.module?.userRequest,
]
.filter((value): value is string => typeof value === 'string')
.join('\n');
}

interface ReanimatedPluginOptions {
/**
* Custom options passed to 'react-native-reanimated/plugin' or 'react-native-worklets/plugin' babel plugins.
Expand Down Expand Up @@ -51,11 +91,14 @@ export class ReanimatedPlugin {

// ignore the 'setUpTests' warning from reanimated which is not relevant
compiler.options.ignoreWarnings = compiler.options.ignoreWarnings ?? [];
compiler.options.ignoreWarnings.push((warning) =>
/'`setUpTests` is available only in Jest environment\.'/.test(
warning.message
)
);
compiler.options.ignoreWarnings.push((warning) => {
const warningText = warningToSearchableText(warning);
return (
REANIMATED_SETUP_TESTS_WARNING.test(warningText) ||
(WORKLETS_CRITICAL_DEPENDENCY_WARNING.test(warningText) &&
WORKLETS_INITIALIZERS_MODULE.test(warningText))
);
});
}

private ensureDependencyInstalled(context: string, dependency: string) {
Expand Down