react-native-worklets 0.8.0-bundle-mode-preview-1 → 0.8.0-bundle-mode-preview-2

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.
@@ -0,0 +1 @@
1
+ The purpose of this file is always have `.worklets` directory in the package, as some environments have trouble creating it dynamically.
@@ -1,3 +1,6 @@
1
1
  declare module 'react-native-worklets/bundleMode' {
2
+ /** Use in React Native Community projects. */
2
3
  export const bundleModeMetroConfig: any;
4
+ /** Use in Expo projects. */
5
+ export function getBundleModeMetroConfig(): any;
3
6
  }
@@ -1,10 +1,92 @@
1
- const { getDefaultConfig } = require('@react-native/metro-config');
1
+ /* eslint-disable */
2
+ // @ts-nocheck
2
3
  const path = require('path');
3
4
 
5
+ let getDefaultConfig = () => ({});
6
+ try {
7
+ getDefaultConfig = require('@react-native/metro-config').getDefaultConfig;
8
+ } catch {
9
+ /* empty */
10
+ }
11
+
4
12
  const workletsPackageParentDir = path.resolve(__dirname, '../..');
5
13
 
6
14
  const defaults = getDefaultConfig(__dirname);
7
15
 
16
+ const workletsDirPath = path.join('react-native-worklets', '.worklets');
17
+
18
+ function bundleModeResolveRequest(
19
+ /** @type {any} */ context,
20
+ /** @type {string} */ moduleName,
21
+ /** @type {any} */ platform
22
+ ) {
23
+ if (moduleName.startsWith(workletsDirPath)) {
24
+ const fullModuleName = path.join(workletsPackageParentDir, moduleName);
25
+ return { type: 'sourceFile', filePath: fullModuleName };
26
+ }
27
+ return context.resolveRequest(context, moduleName, platform);
28
+ }
29
+
30
+ /** Use in React Native Community projects. */
31
+ const bundleModeMetroConfig = {
32
+ serializer: {
33
+ getModulesRunBeforeMainModule(/** @type {string} dirname */ dirname) {
34
+ return [
35
+ ...getEntryPoints(),
36
+ ...(defaults?.serializer?.getModulesRunBeforeMainModule?.(dirname) ||
37
+ []),
38
+ ];
39
+ },
40
+ createModuleIdFactory: bundleModeCreateModuleIdFactory,
41
+ },
42
+ resolver: {
43
+ resolveRequest: (
44
+ /** @type {any} */ context,
45
+ /** @type {string} */ moduleName,
46
+ /** @type {any} */ platform
47
+ ) => {
48
+ if (moduleName.startsWith(workletsDirPath)) {
49
+ const fullModuleName = path.join(workletsPackageParentDir, moduleName);
50
+ return { type: 'sourceFile', filePath: fullModuleName };
51
+ }
52
+ return context.resolveRequest(context, moduleName, platform);
53
+ },
54
+ },
55
+ };
56
+
57
+ /** Use in Expo projects. */
58
+ function getBundleModeMetroConfig(config) {
59
+ const currentGetModulesRunBeforeMainModule =
60
+ config?.serializer?.getModulesRunBeforeMainModule;
61
+
62
+ config.serializer.getModulesRunBeforeMainModule = (
63
+ /** @type {string} dirname */ dirname
64
+ ) => [
65
+ ...getEntryPoints(),
66
+ ...(currentGetModulesRunBeforeMainModule?.(dirname) || []),
67
+ ];
68
+
69
+ config.serializer.createModuleIdFactory = bundleModeCreateModuleIdFactory;
70
+
71
+ config.resolver.resolveRequest = bundleModeResolveRequest;
72
+
73
+ const currentGetTransformOptions = config?.transformer?.getTransformOptions;
74
+ config.transformer.getTransformOptions = async () => {
75
+ const options = currentGetTransformOptions
76
+ ? await currentGetTransformOptions()
77
+ : {};
78
+ return {
79
+ ...options,
80
+ transform: {
81
+ ...options.transform,
82
+ inlineRequires: true,
83
+ },
84
+ };
85
+ };
86
+
87
+ return config;
88
+ }
89
+
8
90
  function getEntryPoints() {
9
91
  const entryPoints = [];
10
92
  try {
@@ -28,48 +110,25 @@ function getEntryPoints() {
28
110
  return entryPoints;
29
111
  }
30
112
 
113
+ function bundleModeCreateModuleIdFactory() {
114
+ let nextId = 0;
115
+ const idFileMap = new Map();
116
+ return (/** @type {string} */ moduleName) => {
117
+ if (idFileMap.has(moduleName)) {
118
+ return idFileMap.get(moduleName);
119
+ }
120
+ if (moduleName.includes(workletsDirPath)) {
121
+ const base = path.basename(moduleName, '.js');
122
+ const id = Number(base);
123
+ idFileMap.set(moduleName, id);
124
+ return id;
125
+ }
126
+ idFileMap.set(moduleName, nextId++);
127
+ return idFileMap.get(moduleName);
128
+ };
129
+ }
130
+
31
131
  module.exports = {
32
- bundleModeMetroConfig: {
33
- serializer: {
34
- getModulesRunBeforeMainModule(/** @type {string} dirname */ dirname) {
35
- return [
36
- ...getEntryPoints(),
37
- ...defaults.serializer.getModulesRunBeforeMainModule(dirname),
38
- ];
39
- },
40
- createModuleIdFactory() {
41
- let nextId = 0;
42
- const idFileMap = new Map();
43
- return (/** @type {string} */ moduleName) => {
44
- if (idFileMap.has(moduleName)) {
45
- return idFileMap.get(moduleName);
46
- }
47
- if (moduleName.includes('react-native-worklets/.worklets/')) {
48
- const base = path.basename(moduleName, '.js');
49
- const id = Number(base);
50
- idFileMap.set(moduleName, id);
51
- return id;
52
- }
53
- idFileMap.set(moduleName, nextId++);
54
- return idFileMap.get(moduleName);
55
- };
56
- },
57
- },
58
- resolver: {
59
- resolveRequest: (
60
- /** @type {any} */ context,
61
- /** @type {string} */ moduleName,
62
- /** @type {any} */ platform
63
- ) => {
64
- if (moduleName.startsWith('react-native-worklets/.worklets/')) {
65
- const fullModuleName = path.join(
66
- workletsPackageParentDir,
67
- moduleName
68
- );
69
- return { type: 'sourceFile', filePath: fullModuleName };
70
- }
71
- return context.resolveRequest(context, moduleName, platform);
72
- },
73
- },
74
- },
132
+ getBundleModeMetroConfig,
133
+ bundleModeMetroConfig,
75
134
  };
@@ -5,5 +5,5 @@
5
5
  * version used to build the native part of the library in runtime. Remember to
6
6
  * keep this in sync with the version declared in `package.json`
7
7
  */
8
- export const jsVersion = '0.8.0-bundle-mode-preview-1';
8
+ export const jsVersion = '0.8.0-bundle-mode-preview-2';
9
9
  //# sourceMappingURL=jsVersion.js.map
@@ -3,5 +3,5 @@
3
3
  * version used to build the native part of the library in runtime. Remember to
4
4
  * keep this in sync with the version declared in `package.json`
5
5
  */
6
- export declare const jsVersion = "0.8.0-bundle-mode-preview-1";
6
+ export declare const jsVersion = "0.8.0-bundle-mode-preview-2";
7
7
  //# sourceMappingURL=jsVersion.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-worklets",
3
- "version": "0.8.0-bundle-mode-preview-1",
3
+ "version": "0.8.0-bundle-mode-preview-2",
4
4
  "description": "The React Native multithreading library",
5
5
  "keywords": [
6
6
  "react-native",
@@ -52,6 +52,7 @@
52
52
  "homepage": "https://docs.swmansion.com/react-native-worklets",
53
53
  "peerDependencies": {
54
54
  "@babel/core": "*",
55
+ "@react-native/metro-config": "*",
55
56
  "react": "*",
56
57
  "react-native": "*"
57
58
  },
@@ -115,6 +116,8 @@
115
116
  "!android/gradlew",
116
117
  "!android/gradlew.bat",
117
118
  "!android/local.properties",
119
+ "!.worklets",
120
+ ".worklets/dummy.md",
118
121
  "!**/__tests__",
119
122
  "!**/__fixtures__",
120
123
  "!**/__mocks__",
@@ -149,13 +152,6 @@
149
152
  "jsSrcsDir": "src/specs",
150
153
  "android": {
151
154
  "javaPackageName": "com.swmansion.worklets"
152
- },
153
- "ios": {
154
- "modulesConformingToProtocol": {
155
- "RCTBundleConsumer": [
156
- "WorkletsModule"
157
- ]
158
- }
159
155
  }
160
156
  }
161
157
  }
package/plugin/index.js CHANGED
@@ -689,9 +689,6 @@ var require_generate = __commonJS({
689
689
  comments: false
690
690
  })) === null || _a === void 0 ? void 0 : _a.code;
691
691
  (0, assert_1.default)(transformedProg, "[Worklets] `transformedProg` is undefined.");
692
- if (!(0, fs_1.existsSync)(filesDirPath)) {
693
- (0, fs_1.mkdirSync)(filesDirPath, {});
694
- }
695
692
  const dedicatedFilePath = (0, path_1.resolve)(filesDirPath, `${workletHash}.js`);
696
693
  (0, fs_1.writeFileSync)(dedicatedFilePath, transformedProg);
697
694
  }
@@ -5,4 +5,4 @@
5
5
  * version used to build the native part of the library in runtime. Remember to
6
6
  * keep this in sync with the version declared in `package.json`
7
7
  */
8
- export const jsVersion = '0.8.0-bundle-mode-preview-1';
8
+ export const jsVersion = '0.8.0-bundle-mode-preview-2';