@callstack/repack-plugin-reanimated 5.1.3 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -1
- package/dist/loader.d.ts +4 -0
- package/dist/loader.js +28 -2
- package/dist/plugin.d.ts +22 -3
- package/dist/plugin.js +47 -3
- package/dist/rules.d.ts +35 -9
- package/dist/rules.js +60 -42
- package/package.json +10 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { ReanimatedPlugin } from './plugin.js';
|
|
2
|
-
export { reanimatedModuleRules } from './rules.js';
|
|
2
|
+
export { reanimated3ModuleRules, reanimated4ModuleRules, reanimatedModuleRules, } from './rules.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reanimatedModuleRules = exports.ReanimatedPlugin = void 0;
|
|
3
|
+
exports.reanimatedModuleRules = exports.reanimated4ModuleRules = exports.reanimated3ModuleRules = exports.ReanimatedPlugin = void 0;
|
|
4
4
|
var plugin_js_1 = require("./plugin.js");
|
|
5
5
|
Object.defineProperty(exports, "ReanimatedPlugin", { enumerable: true, get: function () { return plugin_js_1.ReanimatedPlugin; } });
|
|
6
6
|
var rules_js_1 = require("./rules.js");
|
|
7
|
+
Object.defineProperty(exports, "reanimated3ModuleRules", { enumerable: true, get: function () { return rules_js_1.reanimated3ModuleRules; } });
|
|
8
|
+
Object.defineProperty(exports, "reanimated4ModuleRules", { enumerable: true, get: function () { return rules_js_1.reanimated4ModuleRules; } });
|
|
7
9
|
Object.defineProperty(exports, "reanimatedModuleRules", { enumerable: true, get: function () { return rules_js_1.reanimatedModuleRules; } });
|
package/dist/loader.d.ts
CHANGED
|
@@ -2,6 +2,10 @@ import type { LoaderContext } from '@rspack/core';
|
|
|
2
2
|
interface ReanimatedLoaderOptions {
|
|
3
3
|
babelPlugins?: string[];
|
|
4
4
|
}
|
|
5
|
+
interface ReanimatedLoaderData {
|
|
6
|
+
skip?: boolean;
|
|
7
|
+
}
|
|
5
8
|
export declare const raw = false;
|
|
6
9
|
export default function reanimatedLoader(this: LoaderContext<ReanimatedLoaderOptions>, source: string): void;
|
|
10
|
+
export declare function pitch(this: LoaderContext<ReanimatedLoaderOptions>, _remainingRequest: string, _previousRequest: string, data: ReanimatedLoaderData): void;
|
|
7
11
|
export {};
|
package/dist/loader.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.raw = void 0;
|
|
4
4
|
exports.default = reanimatedLoader;
|
|
5
|
+
exports.pitch = pitch;
|
|
5
6
|
const core_1 = require("@babel/core");
|
|
6
7
|
// Reference: https://github.com/software-mansion/react-native-reanimated/blob/3.16.3/packages/react-native-reanimated/plugin/src/autoworkletization.ts#L19-L59
|
|
7
8
|
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
|
|
@@ -28,7 +29,8 @@ function reanimatedLoader(source) {
|
|
|
28
29
|
this.cacheable();
|
|
29
30
|
const callback = this.async();
|
|
30
31
|
const options = this.getOptions();
|
|
31
|
-
|
|
32
|
+
const loaderData = this.data;
|
|
33
|
+
if (loaderData.skip || !REANIMATED_REGEX.test(source)) {
|
|
32
34
|
callback(null, source);
|
|
33
35
|
return;
|
|
34
36
|
}
|
|
@@ -39,7 +41,7 @@ function reanimatedLoader(source) {
|
|
|
39
41
|
configFile: false,
|
|
40
42
|
compact: false,
|
|
41
43
|
comments: true,
|
|
42
|
-
plugins:
|
|
44
|
+
plugins: babelPlugins,
|
|
43
45
|
}, (err, result) => {
|
|
44
46
|
if (err) {
|
|
45
47
|
callback(err);
|
|
@@ -50,3 +52,27 @@ function reanimatedLoader(source) {
|
|
|
50
52
|
return;
|
|
51
53
|
});
|
|
52
54
|
}
|
|
55
|
+
// resolve the path to the babel-swc-loader once
|
|
56
|
+
const babelSwcLoader = require.resolve('@callstack/repack/babel-swc-loader');
|
|
57
|
+
let warningDisplayed = false;
|
|
58
|
+
function pitch(_remainingRequest, _previousRequest, data) {
|
|
59
|
+
const logger = this.getLogger('RepackReanimatedLoader');
|
|
60
|
+
for (const loader of this.loaders) {
|
|
61
|
+
// if the babel-swc-loader is found, we skip the reanimated-loader
|
|
62
|
+
// since babel-swc-loader is more performant and uses the official
|
|
63
|
+
// babel plugin directly
|
|
64
|
+
if (loader.path === babelSwcLoader) {
|
|
65
|
+
data.skip = true;
|
|
66
|
+
if (!warningDisplayed) {
|
|
67
|
+
warningDisplayed = true;
|
|
68
|
+
logger.warn('When using `@callstack/repack-plugin-reanimated` together with ' +
|
|
69
|
+
'`@callstack/repack/babel-swc-loader` you should turn off the ' +
|
|
70
|
+
'transforms for `react-native-reanimated` via the ' +
|
|
71
|
+
'`unstable_disableTransform` option. Instead, please add the ' +
|
|
72
|
+
'`react-native-reanimated/plugin` (or ' +
|
|
73
|
+
'`react-native-worklets/plugin`) directly to your list of babel ' +
|
|
74
|
+
'plugins in the `babel.config.js` file in the project root.');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
|
-
import type { Compiler
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { Compiler as RspackCompiler } from '@rspack/core';
|
|
2
|
+
import type { Compiler as WebpackCompiler } from 'webpack';
|
|
3
|
+
interface ReanimatedPluginOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Custom options passed to 'react-native-reanimated/plugin' or 'react-native-worklets/plugin' babel plugins.
|
|
6
|
+
*/
|
|
7
|
+
babelPluginOptions?: Record<string, any>;
|
|
8
|
+
/**
|
|
9
|
+
* Disable adding transformation rules for reanimated / worklets babel plugin.
|
|
10
|
+
* This is useful when handling using `babel-swc-loader` or `babel-loader` and
|
|
11
|
+
* you have already added the babel plugin to your babel config.
|
|
12
|
+
*/
|
|
13
|
+
unstable_disableTransform?: boolean;
|
|
4
14
|
}
|
|
15
|
+
export declare class ReanimatedPlugin {
|
|
16
|
+
private options;
|
|
17
|
+
constructor(options?: ReanimatedPluginOptions);
|
|
18
|
+
apply(compiler: RspackCompiler): void;
|
|
19
|
+
apply(compiler: WebpackCompiler): void;
|
|
20
|
+
private ensureDependencyInstalled;
|
|
21
|
+
private getReanimatedVersion;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
package/dist/plugin.js
CHANGED
|
@@ -1,14 +1,58 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.ReanimatedPlugin = void 0;
|
|
7
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
8
|
+
const semver_1 = __importDefault(require("semver"));
|
|
4
9
|
const rules_js_1 = require("./rules.js");
|
|
5
10
|
class ReanimatedPlugin {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
11
|
+
constructor(options = {}) {
|
|
12
|
+
this.options = options;
|
|
13
|
+
}
|
|
14
|
+
apply(__compiler) {
|
|
15
|
+
const compiler = __compiler;
|
|
16
|
+
const reanimatedPath = this.ensureDependencyInstalled(compiler.context, 'react-native-reanimated');
|
|
17
|
+
const reanimatedVersion = this.getReanimatedVersion(reanimatedPath);
|
|
18
|
+
if (reanimatedVersion.major >= 4) {
|
|
19
|
+
this.ensureDependencyInstalled(compiler.context, 'react-native-worklets');
|
|
20
|
+
}
|
|
21
|
+
if (!this.options.unstable_disableTransform) {
|
|
22
|
+
// add rules for transpiling with reanimated loader
|
|
23
|
+
// TODO made obsolete by the new babel-swc-loader, remove in 6.0
|
|
24
|
+
compiler.options.module.rules.push((0, rules_js_1.createReanimatedModuleRules)(reanimatedVersion.major, this.options.babelPluginOptions));
|
|
25
|
+
}
|
|
9
26
|
// ignore the 'setUpTests' warning from reanimated which is not relevant
|
|
10
27
|
compiler.options.ignoreWarnings = compiler.options.ignoreWarnings ?? [];
|
|
11
28
|
compiler.options.ignoreWarnings.push((warning) => /'`setUpTests` is available only in Jest environment\.'/.test(warning.message));
|
|
12
29
|
}
|
|
30
|
+
ensureDependencyInstalled(context, dependency) {
|
|
31
|
+
try {
|
|
32
|
+
// resolve the path to the dependency package.json
|
|
33
|
+
// since its always in the root dir of the dependency
|
|
34
|
+
const dependencyPackageJsonPath = node_path_1.default.join(dependency, 'package.json');
|
|
35
|
+
const dependencyPath = require.resolve(dependencyPackageJsonPath, {
|
|
36
|
+
paths: [context],
|
|
37
|
+
});
|
|
38
|
+
return node_path_1.default.dirname(dependencyPath);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
const error = new Error(`[RepackReanimatedPlugin] Dependency named '${dependency}' is required but not found in your project. ` +
|
|
42
|
+
'Did you forget to install it?');
|
|
43
|
+
// remove the stack trace to make the error more readable
|
|
44
|
+
error.stack = undefined;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
getReanimatedVersion(reanimatedPath) {
|
|
49
|
+
const reanimatedPackageJsonPath = node_path_1.default.join(reanimatedPath, 'package.json');
|
|
50
|
+
const reanimatedPackageJson = require(reanimatedPackageJsonPath);
|
|
51
|
+
const version = semver_1.default.parse(reanimatedPackageJson.version);
|
|
52
|
+
if (!version) {
|
|
53
|
+
throw new Error(`[RepackReanimatedPlugin] Unable to parse version for react-native-reanimated: ${reanimatedPackageJson.version}`);
|
|
54
|
+
}
|
|
55
|
+
return version;
|
|
56
|
+
}
|
|
13
57
|
}
|
|
14
58
|
exports.ReanimatedPlugin = ReanimatedPlugin;
|
package/dist/rules.d.ts
CHANGED
|
@@ -1,23 +1,49 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const createReanimatedModuleRules: (majorVersion: number, pluginOptions?: Record<string, any>) => {
|
|
2
2
|
exclude: RegExp[];
|
|
3
|
-
oneOf:
|
|
3
|
+
oneOf: {
|
|
4
4
|
test: RegExp;
|
|
5
5
|
use: {
|
|
6
6
|
loader: string;
|
|
7
7
|
options: {
|
|
8
|
-
babelPlugins: (string |
|
|
9
|
-
isTSX: boolean;
|
|
10
|
-
allowNamespaces: boolean;
|
|
11
|
-
})[][];
|
|
8
|
+
babelPlugins: (string | (string | Record<string, any>)[])[];
|
|
12
9
|
};
|
|
13
10
|
};
|
|
14
|
-
}
|
|
11
|
+
}[];
|
|
12
|
+
};
|
|
13
|
+
declare const reanimated3ModuleRules: {
|
|
14
|
+
exclude: RegExp[];
|
|
15
|
+
oneOf: {
|
|
16
|
+
test: RegExp;
|
|
17
|
+
use: {
|
|
18
|
+
loader: string;
|
|
19
|
+
options: {
|
|
20
|
+
babelPlugins: (string | (string | Record<string, any>)[])[];
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
}[];
|
|
24
|
+
};
|
|
25
|
+
declare const reanimated4ModuleRules: {
|
|
26
|
+
exclude: RegExp[];
|
|
27
|
+
oneOf: {
|
|
28
|
+
test: RegExp;
|
|
29
|
+
use: {
|
|
30
|
+
loader: string;
|
|
31
|
+
options: {
|
|
32
|
+
babelPlugins: (string | (string | Record<string, any>)[])[];
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
}[];
|
|
36
|
+
};
|
|
37
|
+
declare const reanimatedModuleRules: {
|
|
38
|
+
exclude: RegExp[];
|
|
39
|
+
oneOf: {
|
|
15
40
|
test: RegExp;
|
|
16
41
|
use: {
|
|
17
42
|
loader: string;
|
|
18
43
|
options: {
|
|
19
|
-
babelPlugins: string[];
|
|
44
|
+
babelPlugins: (string | (string | Record<string, any>)[])[];
|
|
20
45
|
};
|
|
21
46
|
};
|
|
22
|
-
}
|
|
47
|
+
}[];
|
|
23
48
|
};
|
|
49
|
+
export { reanimatedModuleRules, reanimated3ModuleRules, reanimated4ModuleRules, };
|
package/dist/rules.js
CHANGED
|
@@ -1,54 +1,72 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.reanimatedModuleRules = void 0;
|
|
3
|
+
exports.reanimated4ModuleRules = exports.reanimated3ModuleRules = exports.reanimatedModuleRules = exports.createReanimatedModuleRules = void 0;
|
|
4
4
|
const repack_1 = require("@callstack/repack");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'react'
|
|
8
|
-
'react-native'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
const createReanimatedModuleRules = (majorVersion, pluginOptions = {}) => {
|
|
6
|
+
const workletsBabelPlugin = majorVersion < 4
|
|
7
|
+
? 'react-native-reanimated/plugin'
|
|
8
|
+
: 'react-native-worklets/plugin';
|
|
9
|
+
return {
|
|
10
|
+
exclude: (0, repack_1.getModulePaths)([
|
|
11
|
+
'react',
|
|
12
|
+
'react-native',
|
|
13
|
+
'@react-native',
|
|
14
|
+
'react-native-macos',
|
|
15
|
+
'react-native-windows',
|
|
16
|
+
'react-native-tvos',
|
|
17
|
+
'@callstack/react-native-visionos',
|
|
18
|
+
]),
|
|
19
|
+
oneOf: [
|
|
20
|
+
{
|
|
21
|
+
test: /\.[cm]?ts$/,
|
|
22
|
+
use: {
|
|
23
|
+
loader: '@callstack/repack-plugin-reanimated/loader',
|
|
24
|
+
options: {
|
|
25
|
+
babelPlugins: [
|
|
26
|
+
[
|
|
27
|
+
'@babel/plugin-syntax-typescript',
|
|
28
|
+
{ isTSX: false, allowNamespaces: true },
|
|
29
|
+
],
|
|
30
|
+
[workletsBabelPlugin, pluginOptions],
|
|
25
31
|
],
|
|
26
|
-
|
|
32
|
+
},
|
|
27
33
|
},
|
|
28
34
|
},
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
{
|
|
36
|
+
test: /\.[cm]?tsx$/,
|
|
37
|
+
use: {
|
|
38
|
+
loader: '@callstack/repack-plugin-reanimated/loader',
|
|
39
|
+
options: {
|
|
40
|
+
babelPlugins: [
|
|
41
|
+
[
|
|
42
|
+
'@babel/plugin-syntax-typescript',
|
|
43
|
+
{ isTSX: true, allowNamespaces: true },
|
|
44
|
+
],
|
|
45
|
+
[workletsBabelPlugin, pluginOptions],
|
|
39
46
|
],
|
|
40
|
-
|
|
47
|
+
},
|
|
41
48
|
},
|
|
42
49
|
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
+
{
|
|
51
|
+
test: /\.[cm]?jsx?$/,
|
|
52
|
+
use: {
|
|
53
|
+
loader: '@callstack/repack-plugin-reanimated/loader',
|
|
54
|
+
options: {
|
|
55
|
+
babelPlugins: [
|
|
56
|
+
'babel-plugin-syntax-hermes-parser',
|
|
57
|
+
[workletsBabelPlugin, pluginOptions],
|
|
58
|
+
],
|
|
59
|
+
},
|
|
50
60
|
},
|
|
51
61
|
},
|
|
52
|
-
|
|
53
|
-
|
|
62
|
+
],
|
|
63
|
+
};
|
|
54
64
|
};
|
|
65
|
+
exports.createReanimatedModuleRules = createReanimatedModuleRules;
|
|
66
|
+
const reanimated3ModuleRules = (0, exports.createReanimatedModuleRules)(3);
|
|
67
|
+
exports.reanimated3ModuleRules = reanimated3ModuleRules;
|
|
68
|
+
const reanimated4ModuleRules = (0, exports.createReanimatedModuleRules)(4);
|
|
69
|
+
exports.reanimated4ModuleRules = reanimated4ModuleRules;
|
|
70
|
+
// backwards compatibility export
|
|
71
|
+
const reanimatedModuleRules = reanimated3ModuleRules;
|
|
72
|
+
exports.reanimatedModuleRules = reanimatedModuleRules;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@callstack/repack-plugin-reanimated",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "A plugin for @callstack/repack that integrates react-native-reanimated",
|
|
5
5
|
"author": "Jakub Romańczyk <jakub.romanczyk@callstack.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,16 +39,20 @@
|
|
|
39
39
|
"engines": {
|
|
40
40
|
"node": ">=18"
|
|
41
41
|
},
|
|
42
|
-
"dependencies": {
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"semver": "^7.7.2"
|
|
44
|
+
},
|
|
43
45
|
"peerDependencies": {
|
|
44
46
|
"@babel/core": "^7.20",
|
|
45
|
-
"@callstack/repack": "5.
|
|
47
|
+
"@callstack/repack": "5.2.0"
|
|
46
48
|
},
|
|
47
49
|
"devDependencies": {
|
|
48
|
-
"@rspack/core": "^1.
|
|
50
|
+
"@rspack/core": "^1.4.11",
|
|
49
51
|
"@types/babel__core": "7.20.5",
|
|
50
|
-
"@types/node": "^
|
|
51
|
-
"@
|
|
52
|
+
"@types/node": "^20",
|
|
53
|
+
"@types/semver": "^7.7.0",
|
|
54
|
+
"webpack": "^5.99.9",
|
|
55
|
+
"@callstack/repack": "5.2.0"
|
|
52
56
|
},
|
|
53
57
|
"scripts": {
|
|
54
58
|
"build": "tsc -p tsconfig.build.json",
|