@oxy.so/app-preset 3.2.2 → 3.4.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
@@ -55,6 +55,25 @@ The iOS and build-property pieces are overridable:
55
55
  }]
56
56
  ```
57
57
 
58
+ ##### Dropping React Native's GIF / WebP decoders (opt-in, Expo SDK 58+)
59
+
60
+ An app that renders no GIF and no animated WebP through react-native's own
61
+ `Image`/`ImageBackground` (Bloom included — `expo-image` decodes on its own) can
62
+ leave Fresco's GIF and WebP decoders out of the Android build, about 340 KB of
63
+ download and 870 KB installed with R8:
64
+
65
+ ```js
66
+ ['@oxy.so/app-preset', {
67
+ android: { gifEnabled: false, webpEnabled: false }, // deep-merges over the defaults
68
+ }]
69
+ ```
70
+
71
+ The keys pass straight through to `expo-build-properties`, which writes
72
+ `expo.gif.enabled=false` / `expo.webp.enabled=false` to `gradle.properties`. This
73
+ is **not a default**: an app that still shows a GIF or an animated WebP through
74
+ react-native's `Image` renders nothing for it, with no error. The keys exist from
75
+ `expo-build-properties` 58 (Expo SDK 58); older versions ignore them silently.
76
+
58
77
  The `sharedUserId` and `sharedIdentityReader` options were removed in 3.0.0 and
59
78
  throw if passed. `@oxy.so/services` 11+ is a required peer.
60
79
 
@@ -147,10 +166,17 @@ module.exports = createOxyMetroConfig(__dirname, {
147
166
  cssInput: './global.css', // optional, this is the default
148
167
  dropConsole: true, // optional, production web only
149
168
  // svgTransformerPath: require.resolve('react-native-svg-transformer/expo'),
150
- // extraBlockList: [path.join(__dirname, '../../.claude/worktrees')],
169
+ // workspaceRoot: path.join(__dirname, '../..'), // optional, see below
151
170
  });
152
171
  ```
153
172
 
173
+ Metro watches the app's install root and resolves hoisted dependencies from its
174
+ `node_modules`. The root is found by walking up from the project, never past its
175
+ git checkout: the nearest `package.json` that declares `workspaces`, else the
176
+ nearest lockfile, else the checkout's top level. A monorepo app watches the
177
+ monorepo; a single-package app watches only itself. `workspaceRoot` overrides it.
178
+ Worktrees under `<root>/.worktrees` and `<root>/.claude/worktrees` are blocked.
179
+
154
180
  `workletsBundleMode: true` (opt-in, 3.2.0+) turns on react-native-worklets'
155
181
  [Bundle Mode](https://docs.swmansion.com/react-native-worklets/docs/bundleMode).
156
182
  It wraps the finished config with worklets' `getBundleModeMetroConfig`. Use it
@@ -215,5 +241,10 @@ factories throw a clear, actionable error if a required peer is missing.
215
241
 
216
242
  ## Compatibility
217
243
 
218
- Requires **Expo SDK 56+**; validated against **Expo SDK 57 / React Native 0.86**
219
- (the current Oxy ecosystem target) via `test-app-expo`.
244
+ Requires **Expo SDK 56+**; validated against **Expo SDK 58 / React Native 0.88**
245
+ (the current Oxy ecosystem target) with a clean `expo prebuild` of `test-app-expo`,
246
+ `accounts` and `commons` (Android and iOS). SDK 58's Android template already
247
+ uses `proguard-android-optimize.txt` and turns R8 on through `gradle.properties`
248
+ (`android.enableMinifyInReleaseBuilds`), so on SDK 58 `withOxyAndroidRelease`
249
+ only adds the release signing config; on SDK 56/57 it also swaps in the
250
+ `-optimize` ProGuard file.
package/metro/index.js CHANGED
@@ -28,6 +28,8 @@
28
28
  * When set, `svg` moves from asset extensions to source extensions.
29
29
  * @param {Record<string,string>} [options.extraNodeModules={}] Extra aliases.
30
30
  * @param {string[]} [options.extraWatchFolders=[]] Additional watch roots.
31
+ * @param {string} [options.workspaceRoot] The install root Metro watches and
32
+ * resolves hoisted deps from. Defaults to {@link findWorkspaceRoot}.
31
33
  * @param {string[]} [options.extraAssetExts=[]] Additional asset extensions.
32
34
  * @param {string[]} [options.extraSourceExts=[]] Additional source extensions.
33
35
  * @param {boolean} [options.workletsBundleMode=false] react-native-worklets'
@@ -39,19 +41,81 @@
39
41
  */
40
42
  const { getDefaultConfig } = require('expo/metro-config');
41
43
  const { withNativeWind } = require('nativewind/metro');
42
- const path = require('path');
44
+ const fs = require('node:fs');
45
+ const path = require('node:path');
43
46
  const { resolveOxyBuildId } = require('../build-id');
44
47
  const { requireFromProject } = require('../plugin/requireFromProject');
45
48
 
49
+ function escapeRegExp(value) {
50
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
51
+ }
52
+
46
53
  function blockPath(dir) {
47
- const resolved = path.resolve(dir);
48
- return new RegExp(`${resolved.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}/.*`);
54
+ return new RegExp(`${escapeRegExp(path.resolve(dir))}/.*`);
55
+ }
56
+
57
+ /**
58
+ * Every directory called `name` BELOW one of `roots` — never one in a root's
59
+ * own path. An unanchored `.cache/` pattern also matched the CHECKOUT when it
60
+ * lived under `~/.cache` (a worktree there), blocking every file of the app and
61
+ * failing the bundle with "Unable to resolve module ./node_modules/expo-router/
62
+ * entry"; the same held for `.expo`, `.expo-shared`, `.metro` and `__tests__`.
63
+ */
64
+ function dirsUnder(roots, name) {
65
+ const anyRoot = unique(roots.map((root) => escapeRegExp(path.resolve(root)))).join('|');
66
+ return new RegExp(`^(?:${anyRoot})/(?:.*/)?${escapeRegExp(name)}/.*`);
49
67
  }
50
68
 
51
69
  function unique(values) {
52
70
  return [...new Set(values)];
53
71
  }
54
72
 
73
+ const LOCKFILES = [
74
+ 'bun.lock',
75
+ 'bun.lockb',
76
+ 'package-lock.json',
77
+ 'yarn.lock',
78
+ 'pnpm-lock.yaml',
79
+ 'pnpm-workspace.yaml',
80
+ ];
81
+
82
+ function declaresWorkspaces(dir) {
83
+ try {
84
+ const manifest = JSON.parse(fs.readFileSync(path.join(dir, 'package.json'), 'utf8'));
85
+ return Boolean(manifest?.workspaces);
86
+ } catch {
87
+ return false;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * The directory the app was installed from — what Metro watches and resolves
93
+ * hoisted deps from. Walking up from the project, never past the git checkout
94
+ * that contains it: the nearest ancestor whose package.json declares
95
+ * `workspaces`, else the nearest one holding a lockfile, else the checkout's
96
+ * top level, else the project itself.
97
+ *
98
+ * Never a blind `../..`: for a single-package app at `~/Oxy/<repo>` that is the
99
+ * home directory, and Metro crawled all of it (every sibling repo and worktree
100
+ * with its node_modules) until it ran out of memory.
101
+ *
102
+ * @param {string} projectRoot
103
+ * @returns {string}
104
+ */
105
+ function findWorkspaceRoot(projectRoot) {
106
+ const start = path.resolve(projectRoot);
107
+ let lockfileRoot;
108
+ for (let dir = start; ; dir = path.dirname(dir)) {
109
+ if (declaresWorkspaces(dir)) return dir;
110
+ if (!lockfileRoot && LOCKFILES.some((name) => fs.existsSync(path.join(dir, name)))) {
111
+ lockfileRoot = dir;
112
+ }
113
+ // `.git` is a directory in a checkout and a file in a worktree.
114
+ if (fs.existsSync(path.join(dir, '.git'))) return lockfileRoot || dir;
115
+ if (path.dirname(dir) === dir) return lockfileRoot || start;
116
+ }
117
+ }
118
+
55
119
  function createOxyMetroConfig(projectRoot, options = {}) {
56
120
  const {
57
121
  sharedTypesPackage,
@@ -63,9 +127,10 @@ function createOxyMetroConfig(projectRoot, options = {}) {
63
127
  extraWatchFolders = [],
64
128
  extraAssetExts = [],
65
129
  extraSourceExts = [],
130
+ workspaceRoot,
66
131
  } = options;
67
132
 
68
- const monorepoRoot = path.resolve(projectRoot, '../..');
133
+ const monorepoRoot = workspaceRoot ? path.resolve(workspaceRoot) : findWorkspaceRoot(projectRoot);
69
134
  const config = getDefaultConfig(projectRoot);
70
135
 
71
136
  // The preset's Babel plugin inlines this id into every module, but Metro's
@@ -78,7 +143,7 @@ function createOxyMetroConfig(projectRoot, options = {}) {
78
143
 
79
144
  config.projectRoot = projectRoot;
80
145
 
81
- // Include the monorepo root so Metro resolves hoisted deps in root node_modules/.
146
+ // Watch the install root so Metro resolves hoisted deps in its node_modules/.
82
147
  config.watchFolders = unique([
83
148
  monorepoRoot,
84
149
  ...extraWatchFolders.map((folder) => path.resolve(folder)),
@@ -91,14 +156,13 @@ function createOxyMetroConfig(projectRoot, options = {}) {
91
156
  // full node_modules; leaving them watchable makes Metro's file crawler walk
92
157
  // hundreds of thousands of extra directories and time out starting watch mode.
93
158
  blockPath(path.join(monorepoRoot, '.worktrees')),
94
- /\.expo\/.*/,
95
- /\.expo-shared\/.*/,
96
- /\.metro\/.*/,
97
- /\.cache\/.*/,
98
- /node_modules\/\.cache\/.*/,
159
+ blockPath(path.join(monorepoRoot, '.claude/worktrees')),
160
+ // Caches and tests anywhere inside what Metro crawls (`node_modules/.cache`
161
+ // and `.expo/types` included), and nowhere above it.
162
+ ...['.expo', '.expo-shared', '.metro', '.cache', '__tests__'].map((name) =>
163
+ dirsUnder([projectRoot, ...config.watchFolders], name),
164
+ ),
99
165
  /\.tsbuildinfo$/,
100
- /.*\.expo\/types\/.*/,
101
- /__tests__\/.*/,
102
166
  /\.test\.(js|ts|tsx|jsx)$/,
103
167
  /\.spec\.(js|ts|tsx|jsx)$/,
104
168
  /\.md$/,
@@ -124,10 +188,10 @@ function createOxyMetroConfig(projectRoot, options = {}) {
124
188
  ...configuredExtraNodeModules,
125
189
  },
126
190
  // Resolve from the app's node_modules first, then the monorepo root (hoisted deps).
127
- nodeModulesPaths: [
191
+ nodeModulesPaths: unique([
128
192
  path.join(projectRoot, 'node_modules'),
129
193
  path.join(monorepoRoot, 'node_modules'),
130
- ],
194
+ ]),
131
195
  // Enable symlinks for workspace resolution.
132
196
  unstable_enableSymlinks: true,
133
197
  // Enable package.json "exports" resolution (required by @oxy.so/bloom subpath exports).
@@ -254,4 +318,8 @@ function createOxyMetroConfigWithBloom(projectRoot, options = {}) {
254
318
  return workletsBundleMode ? withWorkletsBundleMode(config, projectRoot) : config;
255
319
  }
256
320
 
257
- module.exports = { createOxyMetroConfig: createOxyMetroConfigWithBloom, withBloomSingleInstance };
321
+ module.exports = {
322
+ createOxyMetroConfig: createOxyMetroConfigWithBloom,
323
+ findWorkspaceRoot,
324
+ withBloomSingleInstance,
325
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxy.so/app-preset",
3
- "version": "3.2.2",
3
+ "version": "3.4.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": {
@@ -80,7 +80,7 @@
80
80
  "tailwindcss": ">=4.0.0"
81
81
  },
82
82
  "devDependencies": {
83
- "expo": "^57.0.6",
83
+ "expo": "~58.0.14",
84
84
  "nativewind": "5.0.0-preview.3",
85
85
  "tailwindcss": "4.3.3"
86
86
  },
@@ -15,6 +15,8 @@
15
15
  * only meaningful line is `-dontoptimize`. Swapping to the `-optimize`
16
16
  * variant drops that and adds `-allowaccessmodification`, which is what lets
17
17
  * R8 inline and merge classes. Worth a few MB of dex on a typical Oxy app.
18
+ * Expo SDK 58's template already generates the `-optimize` file, so on SDK
19
+ * 58 this step is a no-op and only the signing config below changes.
18
20
  *
19
21
  * 2. Release signing
20
22
  * Expo generates `signingConfig signingConfigs.debug` for release, and Play