@callstack/repack-plugin-reanimated 5.0.0-rc.3
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/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/loader.d.ts +7 -0
- package/dist/loader.js +52 -0
- package/dist/plugin.d.ts +4 -0
- package/dist/plugin.js +14 -0
- package/dist/rules.d.ts +23 -0
- package/dist/rules.js +54 -0
- package/loader/index.d.ts +1 -0
- package/loader/index.js +1 -0
- package/package.json +57 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Callstack
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/callstack/repack/HEAD/logo.png">
|
|
3
|
+
</p>
|
|
4
|
+
<p align="center">
|
|
5
|
+
A toolkit to build your React Native application with Rspack or Webpack.
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
[![Build Status][build-badge]][build]
|
|
11
|
+
[![Version][version-badge]][version]
|
|
12
|
+
[![MIT License][license-badge]][license]
|
|
13
|
+
[![PRs Welcome][prs-welcome-badge]][prs-welcome]
|
|
14
|
+
[![Code of Conduct][coc-badge]][coc]
|
|
15
|
+
|
|
16
|
+
`@callstack/repack-plugin-reanimated` is a plugin for `@callstack/repack` that integrates `react-native-reanimated` into your React Native projects.
|
|
17
|
+
|
|
18
|
+
## About
|
|
19
|
+
|
|
20
|
+
This plugin exists in order to simplify the setup required to get `react-native-reanimated` working with Re.Pack and to minimize the impact on build performance. It looks for relevant keywords like `worklet` inside the source before transforming the file with `babel`.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
npm install -D @callstack/repack-plugin-reanimated
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
### Plugin
|
|
31
|
+
|
|
32
|
+
To add the plugin to your Re.Pack configuration, update your `rspack.config.js` or `webpack.config.js` as follows:
|
|
33
|
+
|
|
34
|
+
```js
|
|
35
|
+
import { ReanimatedPlugin } from '@callstack/repack-plugin-reanimated';
|
|
36
|
+
|
|
37
|
+
export default (env) => {
|
|
38
|
+
// ...
|
|
39
|
+
return {
|
|
40
|
+
// ...
|
|
41
|
+
plugins: [
|
|
42
|
+
// ...
|
|
43
|
+
new ReanimatedPlugin(),
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Loader
|
|
50
|
+
|
|
51
|
+
The plugin also comes with it's own loader, which you can use on it's own inside `rspack.config.js` or `webpack.config.js` like this:
|
|
52
|
+
|
|
53
|
+
```js
|
|
54
|
+
export default (env) => {
|
|
55
|
+
// ...
|
|
56
|
+
return {
|
|
57
|
+
// ...
|
|
58
|
+
module: {
|
|
59
|
+
rules: [
|
|
60
|
+
{
|
|
61
|
+
test: /\.ts$/,
|
|
62
|
+
use: {
|
|
63
|
+
loader: '@callstack/repack-plugin-reanimated/loader',
|
|
64
|
+
options: {
|
|
65
|
+
babelPlugins: [
|
|
66
|
+
[
|
|
67
|
+
'@babel/plugin-syntax-typescript',
|
|
68
|
+
{ isTSX: false, allowNamespaces: true },
|
|
69
|
+
],
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
Check out our website at https://re-pack.dev for more info and documentation or our GitHub: https://github.com/callstack/repack.
|
|
83
|
+
|
|
84
|
+
<!-- badges -->
|
|
85
|
+
|
|
86
|
+
[callstack-readme-with-love]: https://callstack.com/?utm_source=github.com&utm_medium=referral&utm_campaign=react-native-paper&utm_term=readme-with-love
|
|
87
|
+
[build-badge]: https://img.shields.io/github/workflow/status/callstack/repack/CI/main?style=flat-square
|
|
88
|
+
[build]: https://github.com/callstack/repack/actions/workflows/main.yml
|
|
89
|
+
[version-badge]: https://img.shields.io/npm/v/@callstack/repack-plugin-reanimated?style=flat-square
|
|
90
|
+
[version]: https://www.npmjs.com/package/@callstack/repack-plugin-reanimated
|
|
91
|
+
[license-badge]: https://img.shields.io/npm/l/@callstack/repack-plugin-reanimated?style=flat-square
|
|
92
|
+
[license]: https://github.com/callstack/repack/blob/master/LICENSE
|
|
93
|
+
[prs-welcome-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
|
|
94
|
+
[prs-welcome]: ./CONTRIBUTING.md
|
|
95
|
+
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
|
|
96
|
+
[coc]: https://github.com/callstack/repack/blob/master/CODE_OF_CONDUCT.md
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reanimatedModuleRules = exports.ReanimatedPlugin = void 0;
|
|
4
|
+
var plugin_js_1 = require("./plugin.js");
|
|
5
|
+
Object.defineProperty(exports, "ReanimatedPlugin", { enumerable: true, get: function () { return plugin_js_1.ReanimatedPlugin; } });
|
|
6
|
+
var rules_js_1 = require("./rules.js");
|
|
7
|
+
Object.defineProperty(exports, "reanimatedModuleRules", { enumerable: true, get: function () { return rules_js_1.reanimatedModuleRules; } });
|
package/dist/loader.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { LoaderContext } from '@rspack/core';
|
|
2
|
+
interface ReanimatedLoaderOptions {
|
|
3
|
+
babelPlugins?: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare const raw = false;
|
|
6
|
+
export default function reanimatedLoader(this: LoaderContext<ReanimatedLoaderOptions>, source: string): void;
|
|
7
|
+
export {};
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.raw = void 0;
|
|
4
|
+
exports.default = reanimatedLoader;
|
|
5
|
+
const core_1 = require("@babel/core");
|
|
6
|
+
// Reference: https://github.com/software-mansion/react-native-reanimated/blob/3.16.3/packages/react-native-reanimated/plugin/src/autoworkletization.ts#L19-L59
|
|
7
|
+
const REANIMATED_AUTOWORKLETIZATION_KEYWORDS = [
|
|
8
|
+
'worklet',
|
|
9
|
+
'useAnimatedGestureHandler',
|
|
10
|
+
'useAnimatedScrollHandler',
|
|
11
|
+
'useFrameCallback',
|
|
12
|
+
'useAnimatedStyle',
|
|
13
|
+
'useAnimatedProps',
|
|
14
|
+
'createAnimatedPropAdapter',
|
|
15
|
+
'useDerivedValue',
|
|
16
|
+
'useAnimatedReaction',
|
|
17
|
+
'useWorkletCallback',
|
|
18
|
+
'withTiming',
|
|
19
|
+
'withSpring',
|
|
20
|
+
'withDecay',
|
|
21
|
+
'withRepeat',
|
|
22
|
+
'runOnUI',
|
|
23
|
+
'executeOnUIRuntimeSync',
|
|
24
|
+
];
|
|
25
|
+
const REANIMATED_REGEX = new RegExp(REANIMATED_AUTOWORKLETIZATION_KEYWORDS.join('|'));
|
|
26
|
+
exports.raw = false;
|
|
27
|
+
function reanimatedLoader(source) {
|
|
28
|
+
this.cacheable();
|
|
29
|
+
const callback = this.async();
|
|
30
|
+
const options = this.getOptions();
|
|
31
|
+
if (!REANIMATED_REGEX.test(source)) {
|
|
32
|
+
callback(null, source);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const babelPlugins = options.babelPlugins ?? [];
|
|
36
|
+
(0, core_1.transform)(source, {
|
|
37
|
+
filename: this.resourcePath,
|
|
38
|
+
babelrc: false,
|
|
39
|
+
configFile: false,
|
|
40
|
+
compact: false,
|
|
41
|
+
comments: true,
|
|
42
|
+
plugins: [...babelPlugins, 'react-native-reanimated/plugin'],
|
|
43
|
+
}, (err, result) => {
|
|
44
|
+
if (err) {
|
|
45
|
+
callback(err);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// @ts-ignore
|
|
49
|
+
callback(null, result.code, result.map);
|
|
50
|
+
return;
|
|
51
|
+
});
|
|
52
|
+
}
|
package/dist/plugin.d.ts
ADDED
package/dist/plugin.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReanimatedPlugin = void 0;
|
|
4
|
+
const rules_js_1 = require("./rules.js");
|
|
5
|
+
class ReanimatedPlugin {
|
|
6
|
+
apply(compiler) {
|
|
7
|
+
// add rules for transpiling wih reanimated loader
|
|
8
|
+
compiler.options.module.rules.push(rules_js_1.reanimatedModuleRules);
|
|
9
|
+
// ignore the 'setUpTests' warning from reanimated which is not relevant
|
|
10
|
+
compiler.options.ignoreWarnings = compiler.options.ignoreWarnings ?? [];
|
|
11
|
+
compiler.options.ignoreWarnings.push((warning) => /'`setUpTests` is available only in Jest environment\.'/.test(warning.message));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ReanimatedPlugin = ReanimatedPlugin;
|
package/dist/rules.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const reanimatedModuleRules: {
|
|
2
|
+
exclude: RegExp[];
|
|
3
|
+
oneOf: ({
|
|
4
|
+
test: RegExp;
|
|
5
|
+
use: {
|
|
6
|
+
loader: string;
|
|
7
|
+
options: {
|
|
8
|
+
babelPlugins: (string | {
|
|
9
|
+
isTSX: boolean;
|
|
10
|
+
allowNamespaces: boolean;
|
|
11
|
+
})[][];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
} | {
|
|
15
|
+
test: RegExp;
|
|
16
|
+
use: {
|
|
17
|
+
loader: string;
|
|
18
|
+
options: {
|
|
19
|
+
babelPlugins: string[];
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
})[];
|
|
23
|
+
};
|
package/dist/rules.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reanimatedModuleRules = void 0;
|
|
4
|
+
const repack_1 = require("@callstack/repack");
|
|
5
|
+
exports.reanimatedModuleRules = {
|
|
6
|
+
exclude: (0, repack_1.getModulePaths)([
|
|
7
|
+
'react',
|
|
8
|
+
'react-native',
|
|
9
|
+
'@react-native',
|
|
10
|
+
'react-native-macos',
|
|
11
|
+
'react-native-windows',
|
|
12
|
+
'react-native-tvos',
|
|
13
|
+
'@callstack/react-native-visionos',
|
|
14
|
+
]),
|
|
15
|
+
oneOf: [
|
|
16
|
+
{
|
|
17
|
+
test: /\.ts$/,
|
|
18
|
+
use: {
|
|
19
|
+
loader: '@callstack/repack-plugin-reanimated/loader',
|
|
20
|
+
options: {
|
|
21
|
+
babelPlugins: [
|
|
22
|
+
[
|
|
23
|
+
'@babel/plugin-syntax-typescript',
|
|
24
|
+
{ isTSX: false, allowNamespaces: true },
|
|
25
|
+
],
|
|
26
|
+
],
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
test: /\.tsx$/,
|
|
32
|
+
use: {
|
|
33
|
+
loader: '@callstack/repack-plugin-reanimated/loader',
|
|
34
|
+
options: {
|
|
35
|
+
babelPlugins: [
|
|
36
|
+
[
|
|
37
|
+
'@babel/plugin-syntax-typescript',
|
|
38
|
+
{ isTSX: true, allowNamespaces: true },
|
|
39
|
+
],
|
|
40
|
+
],
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
test: /\.jsx?$/,
|
|
46
|
+
use: {
|
|
47
|
+
loader: '@callstack/repack-plugin-reanimated/loader',
|
|
48
|
+
options: {
|
|
49
|
+
babelPlugins: ['babel-plugin-syntax-hermes-parser'],
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
],
|
|
54
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '../dist/loader.js';
|
package/loader/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('../dist/loader.js');
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@callstack/repack-plugin-reanimated",
|
|
3
|
+
"version": "5.0.0-rc.3",
|
|
4
|
+
"description": "A plugin for @callstack/repack that integrates react-native-reanimated",
|
|
5
|
+
"author": "Jakub Romańczyk <jakub.romanczyk@callstack.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/callstack/repack",
|
|
8
|
+
"repository": "github:callstack/repack",
|
|
9
|
+
"type": "commonjs",
|
|
10
|
+
"main": "dist/index.js",
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist",
|
|
14
|
+
"loader"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./loader": {
|
|
22
|
+
"types": "./loader/index.d.ts",
|
|
23
|
+
"default": "./loader/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"repack",
|
|
28
|
+
"re.pack",
|
|
29
|
+
"plugin",
|
|
30
|
+
"repack-plugin",
|
|
31
|
+
"reanimated",
|
|
32
|
+
"react-native-reanimated"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"registry": "https://registry.npmjs.org/",
|
|
36
|
+
"access": "public"
|
|
37
|
+
},
|
|
38
|
+
"engineStrict": true,
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=18"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {},
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"@babel/core": "^7.20",
|
|
45
|
+
"@callstack/repack": "^5.0.0-rc.3"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@rspack/core": "1.0.8",
|
|
49
|
+
"@types/babel__core": "7.20.5",
|
|
50
|
+
"@types/node": "^18",
|
|
51
|
+
"@callstack/repack": "5.0.0-rc.3"
|
|
52
|
+
},
|
|
53
|
+
"scripts": {
|
|
54
|
+
"build": "tsc -p tsconfig.build.json",
|
|
55
|
+
"typecheck": "tsc --noEmit"
|
|
56
|
+
}
|
|
57
|
+
}
|