@oxy.so/app-preset 3.6.1 → 4.1.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/README.md CHANGED
@@ -19,7 +19,7 @@ and JSON.
19
19
  | Android WebP resources | `@oxy.so/app-preset/plugin/withOxyAndroidWebp` | re-encoding generated mipmaps/splash bitmaps to real lossless WebP (opt-in, needs `sharp`) |
20
20
  | Oxy Updates (OTA) | `@oxy.so/app-preset/plugin/withOxyUpdates` | the `expo-updates` manifest URL, release channel, `runtimeVersion` policy and the shared code-signing certificate (opt-in, see below) |
21
21
  | Metro | `@oxy.so/app-preset/metro` | monorepo watch folders, block list, symlink + package-exports resolution, web-font/wasm asset exts, release minifier, NativeWind wrapper |
22
- | Babel | `@oxy.so/app-preset/babel` | `babel-preset-expo` + `module-resolver` + `react-native-worklets/plugin` |
22
+ | Babel | `@oxy.so/app-preset/babel` | `babel-preset-expo` alone in development, so Expo's oxc transformer (Noxcturnal) runs; the build-id inliner in production |
23
23
  | ESLint | `@oxy.so/app-preset/eslint` | `eslint-config-expo/flat` + `dist/*` ignore |
24
24
  | CSS base | `@oxy.so/app-preset/base.css` | Tailwind v4 + NativeWind + Bloom design-token imports + SDK `@source` globs |
25
25
  | tsconfig | `@oxy.so/app-preset/tsconfig/{base,frontend,backend}.json` | the shared strict/composite TypeScript bases |
@@ -232,12 +232,58 @@ paths are escaped and block only their descendants. `extraNodeModules`,
232
232
  `extraWatchFolders`, `extraAssetExts`, and `extraSourceExts` extend the shared
233
233
  defaults without replacing them.
234
234
 
235
+ #### `react-native` on native: the complete NativeWind shim (4.1.0+)
236
+
237
+ On native, NativeWind's resolver sends every `import … from 'react-native'`
238
+ outside React Native itself to `react-native-css/components`, a shim that
239
+ re-exports a FIXED list of React Native's API. A name React Native adds and the
240
+ list lacks reads as `undefined`: React Native 0.88 added `AssetRegistry`, Expo
241
+ SDK 58's `expo-asset` imports it from `'react-native'`, every `useFonts` failed
242
+ (`Cannot read property 'getAssetByID' of undefined`), Bloom's font loader never
243
+ rendered its children, and Android release builds showed a blank screen with no
244
+ visible error (upstream: nativewind/react-native-css#506, #504).
245
+
246
+ `createOxyMetroConfig` returns `metro/react-native.js` wherever NativeWind
247
+ resolved `react-native` to that shim: the shim's own properties, copied as they
248
+ are (so `className` behaves exactly as NativeWind makes it), plus every other
249
+ name of React Native's index, forwarded to React Native. Only a request for
250
+ exactly `react-native` that NativeWind resolved to the shim is touched; web,
251
+ deep `react-native/…` imports and every other module resolve as before. No
252
+ `node_modules` patch is needed, and a name React Native adds later is covered
253
+ without one. An app that wraps the returned `resolveRequest` in its own (Allo's
254
+ `@hpke` and harness aliases) sits above this one, which is fine as long as it
255
+ hands `react-native` and `react-native-css/components` down unchanged.
256
+
257
+ An app that still composes `withNativeWind` itself gets the same fix by
258
+ wrapping its finished config, LAST (over worklets' Bundle Mode too):
259
+
260
+ ```js
261
+ const { withCompleteReactNative } = require('@oxy.so/app-preset/metro');
262
+
263
+ module.exports = withCompleteReactNative(withNativeWind(config, options), __dirname);
264
+ ```
265
+
235
266
  ### 3. Babel (`babel.config.js`)
236
267
 
237
268
  ```js
238
269
  module.exports = require('@oxy.so/app-preset/babel');
239
270
  ```
240
271
 
272
+ In development this is exactly `babel-preset-expo`. Expo's oxc transformer,
273
+ Noxcturnal, runs only when the Babel config resolves to the bare Expo preset;
274
+ one extra plugin or preset option sends every file back to Babel. The config
275
+ plugin turns the experiment (`experiments.noxcturnalTransformWorker`) on for
276
+ development; `noxcturnal: false` opts out. Production builds stay on Babel,
277
+ with the build-id inliner, because Noxcturnal keeps the requires of dead
278
+ platform branches and pulls native-only packages into a web bundle.
279
+
280
+ `@/` resolves from the app's `tsconfig.json` paths (`"@/*": ["./*"]`), not from
281
+ Babel. Jest needs the same alias in `moduleNameMapper`
282
+ (`"^@/(.*)$": "<rootDir>/$1"`). `babel-preset-expo` adds
283
+ `react-native-worklets/plugin` and the `import.meta` transform itself. An app
284
+ that adds its own Babel plugins, or a custom `babelTransformerPath` such as
285
+ `react-native-svg-transformer`, keeps every file on Babel.
286
+
241
287
  With Bundle Mode (opt-in, 3.2.0+), a worker runtime runs the app's own modules:
242
288
 
243
289
  ```js
package/babel/index.js CHANGED
@@ -1,10 +1,18 @@
1
1
  /**
2
2
  * @oxy.so/app-preset — Babel config factory.
3
3
  *
4
- * The standard Babel config every Oxy Expo app shares: babel-preset-expo with
5
- * `unstable_transformImportMeta`, the `@ → ./` module-resolver alias, and the
6
- * `react-native-worklets/plugin` LAST (Reanimated 4 re-exports it — it must be
7
- * the final plugin).
4
+ * In development the config is exactly `babel-preset-expo`, nothing else.
5
+ * Expo's oxc transformer (Noxcturnal, `experiments.noxcturnalTransformWorker`,
6
+ * which the preset's config plugin turns on) runs only when the project's Babel
7
+ * config resolves to the bare Expo preset; one extra plugin or preset option
8
+ * sends every file back to Babel. Everything the config used to add is covered
9
+ * without it in SDK 58: `babel-preset-expo` adds `react-native-worklets/plugin`
10
+ * and the `import.meta` transform itself, and Metro resolves `@/` from the
11
+ * app's `tsconfig.json` paths.
12
+ *
13
+ * A production build adds the build-id inliner (`./inline-oxy-build-id`).
14
+ * Production stays on Babel either way: Noxcturnal keeps the requires of dead
15
+ * platform branches, pulling native-only packages into a web bundle.
8
16
  *
9
17
  * Usage — a one-line babel.config.js:
10
18
  *
@@ -22,11 +30,11 @@
22
30
  * workletsBundleMode: true })`). `importForwarding` (worklets'
23
31
  * `moduleNames`/`relativePaths`) names the modules whose imports a worklet
24
32
  * 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.
33
+ * synchronous call to it from a worker runtime throws. Its plugin options make
34
+ * the config non-default, so a Bundle Mode app stays on Babel.
26
35
  *
27
- * The peer packages (`babel-preset-expo`, `babel-plugin-module-resolver`,
28
- * `react-native-worklets`) resolve from the consuming app's node_modules, where
29
- * Expo already installs them.
36
+ * The peer packages (`babel-preset-expo`, `react-native-worklets`) resolve from
37
+ * the consuming app's node_modules, where Expo already installs them.
30
38
  */
31
39
 
32
40
  const FORWARDING_KEYS = ['moduleNames', 'relativePaths'];
@@ -78,33 +86,17 @@ function bundleModeOptions(value) {
78
86
  function createOxyBabelConfig(options = {}) {
79
87
  const bundleMode = bundleModeOptions(options.workletsBundleMode);
80
88
  return function oxyBabelPreset(api) {
81
- api.cache(true);
89
+ const production = api.cache.using(() => process.env.NODE_ENV === 'production');
90
+ const plugins = [
91
+ // The build id `@oxy.so/services` busts its persisted caches on.
92
+ ...(production ? [require.resolve('./inline-oxy-build-id')] : []),
93
+ // In Bundle Mode the worklets plugin needs its options, so
94
+ // babel-preset-expo must not add a second, option-less copy.
95
+ ...(bundleMode ? [['react-native-worklets/plugin', bundleMode]] : []),
96
+ ];
82
97
  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',
107
- ],
98
+ presets: [bundleMode ? ['babel-preset-expo', { worklets: false }] : 'babel-preset-expo'],
99
+ plugins,
108
100
  };
109
101
  };
110
102
  }
package/metro/index.js CHANGED
@@ -25,7 +25,8 @@
25
25
  * @param {boolean} [options.dropConsole=false] Strip console calls from the
26
26
  * production web bundle. Hermes native bundles do not use Metro's minifier.
27
27
  * @param {string} [options.svgTransformerPath] Resolved SVG transformer path.
28
- * When set, `svg` moves from asset extensions to source extensions.
28
+ * When set, `svg` moves from asset extensions to source extensions. A custom
29
+ * Babel transformer keeps every file on Babel, so the app loses Noxcturnal.
29
30
  * @param {Record<string,string>} [options.extraNodeModules={}] Extra aliases.
30
31
  * @param {string[]} [options.extraWatchFolders=[]] Additional watch roots.
31
32
  * @param {string} [options.workspaceRoot] The install root Metro watches and
@@ -136,7 +137,8 @@ function createOxyMetroConfig(projectRoot, options = {}) {
136
137
  const monorepoRoot = workspaceRoot ? path.resolve(workspaceRoot) : findWorkspaceRoot(projectRoot);
137
138
  const config = getDefaultConfig(projectRoot);
138
139
 
139
- // The preset's Babel plugin inlines this id into every module, but Metro's
140
+ // In a production build the preset's Babel plugin inlines this id into every
141
+ // module (development uses a constant id and no plugin), but Metro's
140
142
  // transform cache key does not cover it: without the id in `cacheVersion`, a
141
143
  // cached SDK module would keep an old build's id. Published so the Babel
142
144
  // workers Metro forks resolve the same value.
@@ -269,6 +271,74 @@ function createOxyMetroConfig(projectRoot, options = {}) {
269
271
  });
270
272
  }
271
273
 
274
+ const COMPLETE_REACT_NATIVE = path.join(__dirname, 'react-native.js');
275
+ /** Both spellings: Metro reports real paths, and the preset may sit behind a symlink. */
276
+ const COMPLETE_REACT_NATIVE_PATHS = new Set([
277
+ COMPLETE_REACT_NATIVE,
278
+ fs.realpathSync(COMPLETE_REACT_NATIVE),
279
+ ]);
280
+ /** `react-native-css/components`' entry, by any of the conditions Metro may pick. */
281
+ const CSS_COMPONENTS_ENTRY =
282
+ /[/\\]react-native-css[/\\](?:dist[/\\](?:commonjs|module)[/\\]components[/\\]index\.cjs|src[/\\]components[/\\]index\.cts)$/;
283
+
284
+ /**
285
+ * Wraps a NativeWind Metro config so that wherever NativeWind sends
286
+ * `react-native` to `react-native-css/components`, the import gets
287
+ * `./react-native.js` instead: that shim with every name of React Native's
288
+ * index it lacks (React Native 0.88's `AssetRegistry`, which `expo-asset`
289
+ * reads) forwarded to React Native. Every name the shim defines keeps its own
290
+ * getter, so `className` behaves exactly as NativeWind makes it.
291
+ *
292
+ * Narrow on purpose: only a request for exactly `react-native` that NativeWind
293
+ * resolved to the shim's entry is touched. Web (NativeWind leaves
294
+ * `react-native-web` imports alone at this level), deep `react-native/…`
295
+ * imports and every other module resolve as before.
296
+ *
297
+ * Apply it LAST, over every other resolver (NativeWind's, worklets' Bundle
298
+ * Mode, an app's own): it has to see the final resolution, and the completed
299
+ * module's own two imports must reach no redirect beneath it. They go straight
300
+ * to Metro's resolver (NativeWind's redirect would point the module at itself,
301
+ * worklets' at a module that requires it back) and resolve from the project,
302
+ * which sees both packages under any linker; the preset depends on neither.
303
+ *
304
+ * @param {import('metro-config').MetroConfig} config The finished config, NativeWind applied.
305
+ * @param {string} [projectRoot=config.projectRoot] The app package.
306
+ * @returns {import('metro-config').MetroConfig} `config`, its resolver wrapped.
307
+ */
308
+ function withCompleteReactNative(config, projectRoot = config.projectRoot) {
309
+ const parentResolveRequest = config.resolver.resolveRequest;
310
+ const projectOrigin = path.join(projectRoot, 'package.json');
311
+
312
+ config.resolver.resolveRequest = (context, moduleName, platform) => {
313
+ if (
314
+ COMPLETE_REACT_NATIVE_PATHS.has(context.originModulePath) &&
315
+ (moduleName === 'react-native' || moduleName === 'react-native-css/components')
316
+ ) {
317
+ return context.resolveRequest(
318
+ { ...context, originModulePath: projectOrigin },
319
+ moduleName,
320
+ platform,
321
+ );
322
+ }
323
+
324
+ const resolution = (parentResolveRequest ?? context.resolveRequest)(
325
+ context,
326
+ moduleName,
327
+ platform,
328
+ );
329
+ if (
330
+ moduleName === 'react-native' &&
331
+ resolution?.type === 'sourceFile' &&
332
+ CSS_COMPONENTS_ENTRY.test(resolution.filePath)
333
+ ) {
334
+ return { type: 'sourceFile', filePath: COMPLETE_REACT_NATIVE };
335
+ }
336
+ return resolution;
337
+ };
338
+
339
+ return config;
340
+ }
341
+
272
342
  /**
273
343
  * Wraps a NativeWind Metro config with the Bloom single-instance rewrite and the
274
344
  * web `ws` shim. In hoisted monorepos the same Bloom version is duplicated under
@@ -298,8 +368,9 @@ function withBloomSingleInstance(nativeWindConfig, projectRoot) {
298
368
 
299
369
  /**
300
370
  * Wraps the finished config for react-native-worklets' Bundle Mode. Applied
301
- * LAST, so worklets' resolver sees every request first and hands the rest to
302
- * the Bloom and NativeWind resolvers underneath.
371
+ * after Bloom's and NativeWind's resolvers, so worklets' resolver sees every
372
+ * request before them and hands the rest down; only
373
+ * {@link withCompleteReactNative} sits above it.
303
374
  */
304
375
  function withWorkletsBundleMode(config, projectRoot) {
305
376
  let bundleMode;
@@ -319,11 +390,15 @@ function createOxyMetroConfigWithBloom(projectRoot, options = {}) {
319
390
  const nativeWindConfig = createOxyMetroConfig(projectRoot, options);
320
391
  let config = withBloomSingleInstance(nativeWindConfig, projectRoot);
321
392
  if (staticHydrationBoundary) config = withStaticHydrationBoundary(config, projectRoot);
322
- return workletsBundleMode ? withWorkletsBundleMode(config, projectRoot) : config;
393
+ if (workletsBundleMode) config = withWorkletsBundleMode(config, projectRoot);
394
+ // Outermost, so it sees the final resolution and its own module's imports
395
+ // reach no redirect beneath it.
396
+ return withCompleteReactNative(config, projectRoot);
323
397
  }
324
398
 
325
399
  module.exports = {
326
400
  createOxyMetroConfig: createOxyMetroConfigWithBloom,
327
401
  findWorkspaceRoot,
328
402
  withBloomSingleInstance,
403
+ withCompleteReactNative,
329
404
  };
@@ -0,0 +1,44 @@
1
+ /**
2
+ * What `import … from 'react-native'` resolves to on native under the preset,
3
+ * wherever NativeWind would have sent it to `react-native-css/components`.
4
+ *
5
+ * NativeWind's resolver (`globalClassNamePolyfill`) redirects every
6
+ * `react-native` import outside React Native itself to that shim, which
7
+ * re-exports a FIXED list of React Native's API: the components it wraps for
8
+ * `className`, and a getter per remaining name. A name React Native adds and the
9
+ * list lacks reads as `undefined`. React Native 0.88 added `AssetRegistry`;
10
+ * Expo SDK 58's `expo-asset` imports it from 'react-native', so every
11
+ * `useFonts` failed (`Cannot read property 'getAssetByID' of undefined`) and a
12
+ * release build sat on a blank screen with no visible error.
13
+ *
14
+ * This module is that shim plus every name of React Native's runtime index it
15
+ * does not define. The shim's own properties are copied as they are (the same
16
+ * getters), so every component NativeWind wraps, and every name it lists,
17
+ * behaves exactly as before; a missing name forwards to React Native's.
18
+ * Nothing is read until it is used: React Native's index is an object of
19
+ * getters, and only property NAMES are enumerated here.
20
+ *
21
+ * `withCompleteReactNative` (`./index.js`) routes both requires below past
22
+ * NativeWind: the first to the real shim, the second to the real React Native.
23
+ */
24
+ const css = require('react-native-css/components');
25
+ const reactNative = require('react-native');
26
+
27
+ const completed = {};
28
+
29
+ for (const key of Object.getOwnPropertyNames(css)) {
30
+ Object.defineProperty(completed, key, Object.getOwnPropertyDescriptor(css, key));
31
+ }
32
+
33
+ for (const key of Object.getOwnPropertyNames(reactNative)) {
34
+ if (Object.hasOwn(completed, key)) continue;
35
+ Object.defineProperty(completed, key, {
36
+ configurable: true,
37
+ enumerable: Object.getOwnPropertyDescriptor(reactNative, key).enumerable,
38
+ get() {
39
+ return reactNative[key];
40
+ },
41
+ });
42
+ }
43
+
44
+ module.exports = completed;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/app-preset",
3
- "version": "3.6.1",
3
+ "version": "4.1.0",
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": {
@@ -60,14 +60,12 @@
60
60
  "node": ">=18.0.0"
61
61
  },
62
62
  "scripts": {
63
- "prepublishOnly": "node ../../scripts/assert-bun-publish.mjs && bun run test",
64
63
  "test": "node --test __tests__/*.test.js"
65
64
  },
66
65
  "//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
66
  "peerDependencies": {
68
67
  "@oxy.so/bloom": "^2.0.0 || ^3.0.0 || ^4.2.0 || ^5.1.0 || >=6.0.0",
69
68
  "@oxy.so/services": ">=11.0.0",
70
- "babel-plugin-module-resolver": "*",
71
69
  "babel-preset-expo": "*",
72
70
  "eslint": ">=9.0.0",
73
71
  "eslint-config-expo": "*",
@@ -86,22 +84,21 @@
86
84
  "react-dom": ">=19.0.0 <20.0.0"
87
85
  },
88
86
  "devDependencies": {
89
- "expo": "~58.0.14",
90
- "nativewind": "5.0.0-preview.3",
87
+ "expo": "~58.0.19",
88
+ "nativewind": "5.0.0-rc.0",
91
89
  "tailwindcss": "4.3.3",
92
90
  "react": "19.3.0",
93
91
  "react-dom": "19.3.0",
94
92
  "jsdom": "^29.1.1",
95
- "expo-router": "~58.0.23",
96
- "@expo/router-server": "58.0.14"
93
+ "expo-router": "~58.0.26",
94
+ "@expo/router-server": "58.0.14",
95
+ "react-native": "0.88.0",
96
+ "react-native-css": "3.1.0-rc.0"
97
97
  },
98
98
  "peerDependenciesMeta": {
99
99
  "@oxy.so/bloom": {
100
100
  "optional": true
101
101
  },
102
- "babel-plugin-module-resolver": {
103
- "optional": true
104
- },
105
102
  "babel-preset-expo": {
106
103
  "optional": true
107
104
  },
@@ -19,6 +19,7 @@
19
19
  * ios: { deploymentTarget: '17.0' }, // false → skip iOS build properties
20
20
  * android: { targetSdkVersion: 34 }, // false → skip Android build properties
21
21
  * webgpu: true, // opt-in: react-native-webgpu's config plugin
22
+ * noxcturnal: false, // opt out of Expo's oxc transformer in development
22
23
  * }]
23
24
  *
24
25
  * Android never gets `android:sharedUserId`: each Oxy app has its own UID and
@@ -37,6 +38,13 @@
37
38
  * @param {boolean} [options.webgpu=false] Apply `react-native-webgpu`'s
38
39
  * config plugin (an app drawing with WebGPU on native). Needs
39
40
  * `react-native-webgpu` installed in the app.
41
+ * @param {boolean} [options.noxcturnal=true] Bundle development builds with
42
+ * Noxcturnal, Expo's oxc transformer (`experiments.noxcturnalTransformWorker`),
43
+ * about twice as fast as Babel on a cold cache. It only runs when the app's
44
+ * Babel config is the preset's (or none), and never in a production build: it
45
+ * keeps the requires of dead platform branches, pulling native-only packages
46
+ * into a web bundle. The Expo CLI sets NODE_ENV before it reads the config.
47
+ * An app that sets the experiment itself keeps its own value.
40
48
  */
41
49
  const withOxyKeychain = require('./withOxyKeychain');
42
50
  const withOxyBuildProperties = require('./withOxyBuildProperties');
@@ -58,10 +66,26 @@ module.exports = function withOxyAppPreset(config, options = {}) {
58
66
  }
59
67
  }
60
68
 
61
- const { keychainGroup = 'group.so.oxy.shared', ios = {}, android = {}, webgpu = false } = options;
69
+ const {
70
+ keychainGroup = 'group.so.oxy.shared',
71
+ ios = {},
72
+ android = {},
73
+ webgpu = false,
74
+ noxcturnal = true,
75
+ } = options;
62
76
 
63
77
  let next = config;
64
78
 
79
+ if (noxcturnal && next.experiments?.noxcturnalTransformWorker === undefined) {
80
+ next = {
81
+ ...next,
82
+ experiments: {
83
+ ...next.experiments,
84
+ noxcturnalTransformWorker: process.env.NODE_ENV !== 'production',
85
+ },
86
+ };
87
+ }
88
+
65
89
  if (keychainGroup !== false) {
66
90
  next = withOxyKeychain(next, keychainGroup);
67
91
  }