@oxy.so/app-preset 4.0.0 → 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
@@ -232,6 +232,37 @@ 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
package/metro/index.js CHANGED
@@ -271,6 +271,74 @@ function createOxyMetroConfig(projectRoot, options = {}) {
271
271
  });
272
272
  }
273
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
+
274
342
  /**
275
343
  * Wraps a NativeWind Metro config with the Bloom single-instance rewrite and the
276
344
  * web `ws` shim. In hoisted monorepos the same Bloom version is duplicated under
@@ -300,8 +368,9 @@ function withBloomSingleInstance(nativeWindConfig, projectRoot) {
300
368
 
301
369
  /**
302
370
  * Wraps the finished config for react-native-worklets' Bundle Mode. Applied
303
- * LAST, so worklets' resolver sees every request first and hands the rest to
304
- * 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.
305
374
  */
306
375
  function withWorkletsBundleMode(config, projectRoot) {
307
376
  let bundleMode;
@@ -321,11 +390,15 @@ function createOxyMetroConfigWithBloom(projectRoot, options = {}) {
321
390
  const nativeWindConfig = createOxyMetroConfig(projectRoot, options);
322
391
  let config = withBloomSingleInstance(nativeWindConfig, projectRoot);
323
392
  if (staticHydrationBoundary) config = withStaticHydrationBoundary(config, projectRoot);
324
- 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);
325
397
  }
326
398
 
327
399
  module.exports = {
328
400
  createOxyMetroConfig: createOxyMetroConfigWithBloom,
329
401
  findWorkspaceRoot,
330
402
  withBloomSingleInstance,
403
+ withCompleteReactNative,
331
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": "4.0.0",
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": {
@@ -84,14 +84,16 @@
84
84
  "react-dom": ">=19.0.0 <20.0.0"
85
85
  },
86
86
  "devDependencies": {
87
- "expo": "~58.0.14",
88
- "nativewind": "5.0.0-preview.3",
87
+ "expo": "~58.0.19",
88
+ "nativewind": "5.0.0-rc.0",
89
89
  "tailwindcss": "4.3.3",
90
90
  "react": "19.3.0",
91
91
  "react-dom": "19.3.0",
92
92
  "jsdom": "^29.1.1",
93
- "expo-router": "~58.0.23",
94
- "@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"
95
97
  },
96
98
  "peerDependenciesMeta": {
97
99
  "@oxy.so/bloom": {