@oxy.so/app-preset 3.1.0 → 3.2.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.
package/README.md CHANGED
@@ -58,6 +58,10 @@ The iOS and build-property pieces are overridable:
58
58
  The `sharedUserId` and `sharedIdentityReader` options were removed in 3.0.0 and
59
59
  throw if passed. `@oxy.so/services` 11+ is a required peer.
60
60
 
61
+ `webgpu: true` (opt-in, 3.2.0+) also applies `react-native-webgpu`'s config
62
+ plugin, for an app that draws with WebGPU on native. Install
63
+ `react-native-webgpu` in the app first; the option throws without it.
64
+
61
65
  #### Android release-build plugins (opt-in)
62
66
 
63
67
  These two are deliberately NOT part of `['@oxy.so/app-preset', {}]`: one writes a
@@ -147,6 +151,11 @@ module.exports = createOxyMetroConfig(__dirname, {
147
151
  });
148
152
  ```
149
153
 
154
+ `workletsBundleMode: true` (opt-in, 3.2.0+) turns on react-native-worklets'
155
+ [Bundle Mode](https://docs.swmansion.com/react-native-worklets/docs/bundleMode).
156
+ It wraps the finished config with worklets' `getBundleModeMetroConfig`. Use it
157
+ together with the Babel option of the same name (below); neither works alone.
158
+
150
159
  `extraBlockList` accepts regular expressions or directory paths. Directory
151
160
  paths are escaped and block only their descendants. `extraNodeModules`,
152
161
  `extraWatchFolders`, `extraAssetExts`, and `extraSourceExts` extend the shared
@@ -158,6 +167,19 @@ defaults without replacing them.
158
167
  module.exports = require('@oxy.so/app-preset/babel');
159
168
  ```
160
169
 
170
+ With Bundle Mode (opt-in, 3.2.0+), a worker runtime runs the app's own modules:
171
+
172
+ ```js
173
+ module.exports = require('@oxy.so/app-preset/babel').createOxyBabelConfig({
174
+ workletsBundleMode: {
175
+ // The modules whose imports a worklet runs ON its runtime (worklets'
176
+ // `importForwarding`). An import not forwarded stays on the RN runtime,
177
+ // and a synchronous call to it from a worker runtime throws.
178
+ importForwarding: { relativePaths: ['components/map/engine/city3d'] },
179
+ },
180
+ });
181
+ ```
182
+
161
183
  ### 4. ESLint (`eslint.config.js`)
162
184
 
163
185
  ```js
package/babel/index.js CHANGED
@@ -10,31 +10,106 @@
10
10
  *
11
11
  * module.exports = require('@oxy.so/app-preset/babel');
12
12
  *
13
+ * With options (all opt-in; an app that passes none gets the config above):
14
+ *
15
+ * module.exports = require('@oxy.so/app-preset/babel').createOxyBabelConfig({
16
+ * workletsBundleMode: { importForwarding: { relativePaths: ['components/engine'] } },
17
+ * });
18
+ *
19
+ * `workletsBundleMode` turns on react-native-worklets' Bundle Mode, in which a
20
+ * worker runtime runs the app's own MODULES rather than only copied worklet
21
+ * closures. It needs the Metro side too (`createOxyMetroConfig(…, {
22
+ * workletsBundleMode: true })`). `importForwarding` (worklets'
23
+ * `moduleNames`/`relativePaths`) names the modules whose imports a worklet
24
+ * runs ON its runtime; an import not forwarded stays on the RN runtime and a
25
+ * synchronous call to it from a worker runtime throws.
26
+ *
13
27
  * The peer packages (`babel-preset-expo`, `babel-plugin-module-resolver`,
14
28
  * `react-native-worklets`) resolve from the consuming app's node_modules, where
15
29
  * Expo already installs them.
30
+ */
31
+
32
+ const FORWARDING_KEYS = ['moduleNames', 'relativePaths'];
33
+
34
+ /**
35
+ * The worklets plugin's Bundle Mode options, or `null` when it is off.
16
36
  *
17
- * @param {import('@babel/core').ConfigAPI} api
18
- * @returns {import('@babel/core').TransformOptions}
37
+ * @param {boolean | { importForwarding?: { moduleNames?: string[], relativePaths?: string[] } } | undefined} value
38
+ */
39
+ function bundleModeOptions(value) {
40
+ if (value === undefined || value === false) return null;
41
+ if (value === true) return { bundleMode: true };
42
+ if (typeof value !== 'object' || value === null) {
43
+ throw new TypeError(
44
+ '[@oxy.so/app-preset/babel] `workletsBundleMode` is a boolean or an object.',
45
+ );
46
+ }
47
+ for (const key of Object.keys(value)) {
48
+ if (key !== 'importForwarding') {
49
+ throw new TypeError(
50
+ `[@oxy.so/app-preset/babel] Unknown \`workletsBundleMode.${key}\`; the only option is \`importForwarding\`.`,
51
+ );
52
+ }
53
+ }
54
+ const forwarding = value.importForwarding;
55
+ if (forwarding === undefined) return { bundleMode: true };
56
+ const importForwarding = {};
57
+ for (const [key, list] of Object.entries(forwarding)) {
58
+ if (!FORWARDING_KEYS.includes(key)) {
59
+ throw new TypeError(
60
+ `[@oxy.so/app-preset/babel] Unknown \`importForwarding.${key}\`; expected ${FORWARDING_KEYS.join(' or ')}.`,
61
+ );
62
+ }
63
+ if (!Array.isArray(list) || !list.every((entry) => typeof entry === 'string')) {
64
+ throw new TypeError(
65
+ `[@oxy.so/app-preset/babel] \`importForwarding.${key}\` is a list of strings.`,
66
+ );
67
+ }
68
+ importForwarding[key] = [...list];
69
+ }
70
+ return { bundleMode: true, importForwarding };
71
+ }
72
+
73
+ /**
74
+ * @param {object} [options]
75
+ * @param {boolean | { importForwarding?: { moduleNames?: string[], relativePaths?: string[] } }} [options.workletsBundleMode=false]
76
+ * @returns {(api: import('@babel/core').ConfigAPI) => import('@babel/core').TransformOptions}
19
77
  */
20
- module.exports = function oxyBabelPreset(api) {
21
- api.cache(true);
22
- return {
23
- presets: [['babel-preset-expo', { unstable_transformImportMeta: true }]],
24
- plugins: [
25
- // The module-resolver must come first for correct module resolution.
26
- [
27
- 'module-resolver',
28
- {
29
- root: ['./'],
30
- alias: { '@': './' },
31
- extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.svg'],
32
- },
78
+ function createOxyBabelConfig(options = {}) {
79
+ const bundleMode = bundleModeOptions(options.workletsBundleMode);
80
+ return function oxyBabelPreset(api) {
81
+ api.cache(true);
82
+ return {
83
+ presets: [
84
+ [
85
+ 'babel-preset-expo',
86
+ // In Bundle Mode the worklets plugin needs its options, so
87
+ // babel-preset-expo must not add a second, option-less copy.
88
+ bundleMode
89
+ ? { unstable_transformImportMeta: true, worklets: false }
90
+ : { unstable_transformImportMeta: true },
91
+ ],
92
+ ],
93
+ plugins: [
94
+ // The module-resolver must come first for correct module resolution.
95
+ [
96
+ 'module-resolver',
97
+ {
98
+ root: ['./'],
99
+ alias: { '@': './' },
100
+ extensions: ['.ts', '.tsx', '.js', '.jsx', '.json', '.svg'],
101
+ },
102
+ ],
103
+ // The build id `@oxy.so/services` busts its persisted caches on.
104
+ require.resolve('./inline-oxy-build-id'),
105
+ // Must be LAST.
106
+ bundleMode ? ['react-native-worklets/plugin', bundleMode] : 'react-native-worklets/plugin',
33
107
  ],
34
- // The build id `@oxy.so/services` busts its persisted caches on.
35
- require.resolve('./inline-oxy-build-id'),
36
- // Must be LAST.
37
- 'react-native-worklets/plugin',
38
- ],
108
+ };
39
109
  };
40
- };
110
+ }
111
+
112
+ const oxyBabelPreset = createOxyBabelConfig();
113
+
114
+ module.exports = oxyBabelPreset;
115
+ module.exports.createOxyBabelConfig = createOxyBabelConfig;
package/metro/index.js CHANGED
@@ -30,12 +30,18 @@
30
30
  * @param {string[]} [options.extraWatchFolders=[]] Additional watch roots.
31
31
  * @param {string[]} [options.extraAssetExts=[]] Additional asset extensions.
32
32
  * @param {string[]} [options.extraSourceExts=[]] Additional source extensions.
33
+ * @param {boolean} [options.workletsBundleMode=false] react-native-worklets'
34
+ * Bundle Mode: wraps the config with `getBundleModeMetroConfig` (worklets'
35
+ * module ids, its resolver shims, inline requires), so a worker runtime can
36
+ * load the app's bundle. Pair it with the Babel factory's option of the same
37
+ * name; neither works alone. Needs `react-native-worklets` installed.
33
38
  * @returns {import('metro-config').MetroConfig}
34
39
  */
35
40
  const { getDefaultConfig } = require('expo/metro-config');
36
41
  const { withNativeWind } = require('nativewind/metro');
37
42
  const path = require('path');
38
43
  const { resolveOxyBuildId } = require('../build-id');
44
+ const { requireFromProject } = require('../plugin/requireFromProject');
39
45
 
40
46
  function blockPath(dir) {
41
47
  const resolved = path.resolve(dir);
@@ -223,9 +229,29 @@ function withBloomSingleInstance(nativeWindConfig, projectRoot) {
223
229
  return nativeWindConfig;
224
230
  }
225
231
 
232
+ /**
233
+ * Wraps the finished config for react-native-worklets' Bundle Mode. Applied
234
+ * LAST, so worklets' resolver sees every request first and hands the rest to
235
+ * the Bloom and NativeWind resolvers underneath.
236
+ */
237
+ function withWorkletsBundleMode(config, projectRoot) {
238
+ let bundleMode;
239
+ try {
240
+ bundleMode = requireFromProject('react-native-worklets/bundleMode', projectRoot);
241
+ } catch (error) {
242
+ throw new Error(
243
+ "[@oxy.so/app-preset/metro] `workletsBundleMode` needs 'react-native-worklets' installed in the app. " +
244
+ `(${error instanceof Error ? error.message : String(error)})`,
245
+ );
246
+ }
247
+ return bundleMode.getBundleModeMetroConfig(config);
248
+ }
249
+
226
250
  function createOxyMetroConfigWithBloom(projectRoot, options = {}) {
251
+ const { workletsBundleMode = false } = options;
227
252
  const nativeWindConfig = createOxyMetroConfig(projectRoot, options);
228
- return withBloomSingleInstance(nativeWindConfig, projectRoot);
253
+ const config = withBloomSingleInstance(nativeWindConfig, projectRoot);
254
+ return workletsBundleMode ? withWorkletsBundleMode(config, projectRoot) : config;
229
255
  }
230
256
 
231
257
  module.exports = { createOxyMetroConfig: createOxyMetroConfigWithBloom, withBloomSingleInstance };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/app-preset",
3
- "version": "3.1.0",
3
+ "version": "3.2.2",
4
4
  "description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
5
5
  "main": "./app.plugin.js",
6
6
  "publishConfig": {
@@ -50,7 +50,7 @@
50
50
  ],
51
51
  "repository": {
52
52
  "type": "git",
53
- "url": "https://github.com/oxyhq/sdk",
53
+ "url": "git+https://github.com/OxyHQ/oxy.git",
54
54
  "directory": "packages/app-preset"
55
55
  },
56
56
  "author": "OxyHQ",
@@ -63,10 +63,10 @@
63
63
  "prepublishOnly": "node ../../scripts/assert-bun-publish.mjs",
64
64
  "test": "node --test __tests__/*.test.js"
65
65
  },
66
- "//peerDependencies": "THE TWO @oxy.so PEERS ARE DELIBERATE. This package couples to them by FILE PATH, not by API: `css/base.css` imports `@oxy.so/bloom/design-tokens/theme.css`, and `plugin/withOxyAppPreset.js` requires `@oxy.so/services/plugins/withOxySharedPermissions` (services 11+, where it first exists, so the services floor is the major that ships it). Both peers retain a measured floor and a breaking-major cap so compatible patches deduplicate in consumers. Never replace either constraint with `*` or an uncapped range.",
66
+ "//peerDependencies": "THE TWO @oxy.so PEERS ARE DELIBERATE. This package couples to them by FILE PATH, not by API: `css/base.css` imports `@oxy.so/bloom/design-tokens/theme.css`, and `plugin/withOxyAppPreset.js` requires `@oxy.so/services/plugins/withOxySharedPermissions` (services 11+, where it first exists, so the services floor is the major that ships it). Both peers retain a measured floor and are deliberately OPEN-ENDED above it: Oxy apps always run the latest Bloom and Services, so a new release of either must never need a preset release first. A release that breaks this package's file-path coupling is caught by its own tests and the apps' CI, not by a cap. Never replace either constraint with `*`.",
67
67
  "peerDependencies": {
68
- "@oxy.so/bloom": "^2.0.0 || ^3.0.0 || ^4.2.0 || ^5.1.0 || ^6.0.0",
69
- "@oxy.so/services": "^11.0.0",
68
+ "@oxy.so/bloom": "^2.0.0 || ^3.0.0 || ^4.2.0 || ^5.1.0 || >=6.0.0",
69
+ "@oxy.so/services": ">=11.0.0",
70
70
  "babel-plugin-module-resolver": "*",
71
71
  "babel-preset-expo": "*",
72
72
  "eslint": ">=9.0.0",
@@ -74,6 +74,7 @@
74
74
  "expo": ">=56.0.0",
75
75
  "expo-build-properties": "*",
76
76
  "nativewind": ">=5.0.0-preview.0",
77
+ "react-native-webgpu": ">=0.5.18 <1.0.0",
77
78
  "react-native-worklets": "*",
78
79
  "sharp": ">=0.33.0",
79
80
  "tailwindcss": ">=4.0.0"
@@ -102,6 +103,9 @@
102
103
  "expo-build-properties": {
103
104
  "optional": true
104
105
  },
106
+ "react-native-webgpu": {
107
+ "optional": true
108
+ },
105
109
  "react-native-worklets": {
106
110
  "optional": true
107
111
  },
@@ -18,6 +18,7 @@
18
18
  * keychainGroup: 'group.so.oxy.shared', // false → skip iOS keychain entitlement
19
19
  * ios: { deploymentTarget: '17.0' }, // false → skip iOS build properties
20
20
  * android: { targetSdkVersion: 34 }, // false → skip Android build properties
21
+ * webgpu: true, // opt-in: react-native-webgpu's config plugin
21
22
  * }]
22
23
  *
23
24
  * Android never gets `android:sharedUserId`: each Oxy app has its own UID and
@@ -33,6 +34,9 @@
33
34
  * @param {string|false} [options.keychainGroup='group.so.oxy.shared']
34
35
  * @param {object|false} [options.ios]
35
36
  * @param {object|false} [options.android]
37
+ * @param {boolean} [options.webgpu=false] Apply `react-native-webgpu`'s
38
+ * config plugin (an app drawing with WebGPU on native). Needs
39
+ * `react-native-webgpu` installed in the app.
36
40
  */
37
41
  const withOxyKeychain = require('./withOxyKeychain');
38
42
  const withOxyBuildProperties = require('./withOxyBuildProperties');
@@ -54,7 +58,7 @@ module.exports = function withOxyAppPreset(config, options = {}) {
54
58
  }
55
59
  }
56
60
 
57
- const { keychainGroup = 'group.so.oxy.shared', ios = {}, android = {} } = options;
61
+ const { keychainGroup = 'group.so.oxy.shared', ios = {}, android = {}, webgpu = false } = options;
58
62
 
59
63
  let next = config;
60
64
 
@@ -80,5 +84,18 @@ module.exports = function withOxyAppPreset(config, options = {}) {
80
84
  }
81
85
  next = withOxySharedPermissions(next);
82
86
 
87
+ if (webgpu) {
88
+ let withWebGPU;
89
+ try {
90
+ withWebGPU = requireFromProject('react-native-webgpu/app.plugin.js', projectRootOf(config));
91
+ } catch (error) {
92
+ throw new Error(
93
+ "[@oxy.so/app-preset] `webgpu: true` needs 'react-native-webgpu' installed in the app. " +
94
+ `(${error instanceof Error ? error.message : String(error)})`,
95
+ );
96
+ }
97
+ next = withWebGPU(next);
98
+ }
99
+
83
100
  return next;
84
101
  };