expo 58.0.1 → 58.0.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.
@@ -18,6 +18,8 @@ const xcode = require(
18
18
  require.resolve('xcode', { paths: [path.dirname(require.resolve('@expo/config-plugins'))] })
19
19
  );
20
20
 
21
+ const { pluginError } = require('./diagnostics');
22
+
21
23
  /** Written by RN's SwiftPM injector into the .xcodeproj it modified. */
22
24
  const INJECTION_MARKER = '.spm-injected.json';
23
25
 
@@ -205,4 +207,43 @@ function resolveAppTarget(appRoot) {
205
207
  };
206
208
  }
207
209
 
208
- module.exports = { resolveAppTarget };
210
+ /**
211
+ * Podfile.properties.json (as precompiled_modules.rb#read_podfile_properties). Missing → {};
212
+ * present but unusable → throw, since every gate would silently fall to its default.
213
+ */
214
+ function readPodfileProperties(propertiesPath) {
215
+ if (typeof propertiesPath !== 'string' || propertiesPath.length === 0) return {};
216
+ let properties;
217
+ try {
218
+ properties = JSON.parse(fs.readFileSync(propertiesPath, 'utf8'));
219
+ } catch (error) {
220
+ if (error.code === 'ENOENT') return {};
221
+ throw unusablePropertiesError(propertiesPath, error.message, { cause: error });
222
+ }
223
+ if (properties == null || typeof properties !== 'object' || Array.isArray(properties)) {
224
+ throw unusablePropertiesError(
225
+ propertiesPath,
226
+ `it holds ${describeType(properties)}, not an object`
227
+ );
228
+ }
229
+ return properties;
230
+ }
231
+
232
+ /** Type only: JSON.stringify can overflow on a deep payload. */
233
+ function describeType(payload) {
234
+ if (payload === null) return 'null';
235
+ return Array.isArray(payload) ? 'an array' : `a ${typeof payload}`;
236
+ }
237
+
238
+ function unusablePropertiesError(propertiesPath, reason, options) {
239
+ return pluginError(
240
+ {
241
+ what: `${propertiesPath} could not be read as Podfile properties (${reason}), so the plugin cannot tell which products this app links.`,
242
+ why: "Carrying on would read every property as unset and leave each gated product to its own default instead of the app's configuration, which only shows up at runtime, so the sync stops here.",
243
+ how: 'Restore the file to a JSON object of properties, then re-run `npx react-native spm update`.',
244
+ },
245
+ options
246
+ );
247
+ }
248
+
249
+ module.exports = { readPodfileProperties, resolveAppTarget };
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Port of `companion_autolink_condition_met?`/`_label` (precompiled_modules.rb); its
3
+ * pod_lookup_map is the prebuilt-metadata document here.
4
+ */
5
+
6
+ 'use strict';
7
+
8
+ /**
9
+ * First declared key decides (podName, npmPackage, podfileProperty); none → not met.
10
+ * declaredPodNames = every DECLARED pod, not the ones emitted so far.
11
+ */
12
+ function autolinkConditionMet(
13
+ condition,
14
+ { declaredPodNames, autolinkedPackages, podfileProperties } = {}
15
+ ) {
16
+ if (condition?.podName != null) return declaredPodNames?.has(condition.podName) === true;
17
+ if (condition?.npmPackage != null) return autolinkedPackages?.has(condition.npmPackage) === true;
18
+ if (condition?.podfileProperty != null) {
19
+ // Opt-out; unset and undeclared both read as nil in Ruby.
20
+ // Keeping them apart would link a product that CocoaPods withholds.
21
+ return (
22
+ (podfileProperties?.[condition.podfileProperty] ?? null) !== (condition.disabledValue ?? null)
23
+ );
24
+ }
25
+ return false;
26
+ }
27
+
28
+ /** What to call the condition in a diagnostic: the key that decides it. */
29
+ function autolinkConditionLabel(condition) {
30
+ return condition?.podName ?? condition?.npmPackage ?? condition?.podfileProperty ?? null;
31
+ }
32
+
33
+ /** Which kind of condition it is: the name of the key that decides it. */
34
+ function autolinkConditionKey(condition) {
35
+ return (
36
+ ['podName', 'npmPackage', 'podfileProperty'].find((key) => condition?.[key] != null) ?? null
37
+ );
38
+ }
39
+
40
+ module.exports = { autolinkConditionKey, autolinkConditionLabel, autolinkConditionMet };
@@ -27,10 +27,6 @@ function appleSourceDir(moduleRoot) {
27
27
  );
28
28
  }
29
29
 
30
- function isIgnoredDir(name) {
31
- return IGNORED_DIR_RX.test(name);
32
- }
33
-
34
30
  // A direct source-level import of the React/Hermes/jsi families (NOT ExpoModulesCore).
35
31
  const REACT_IMPORT_RX =
36
32
  /(#import\s*[<"](React|react|ReactCommon|RCTDeprecation|hermes|jsi|cxxreact|jsinspector|jsireact)[/>]|@?import\s+(React|ReactCommon|ReactAppDependencyProvider|hermes|jsi)\b)/;
@@ -78,53 +74,66 @@ function collectWatchPaths(moduleRoots) {
78
74
  return watchPaths;
79
75
  }
80
76
 
81
- function sourceTreeImportsReact(dir) {
82
- let entries = [];
77
+ /**
78
+ * Every file under `dir` outside the ignored directories, and those directories
79
+ * relative to `dir`, sorted. An ignored directory is not descended into: SwiftPM
80
+ * rejects an exclude path already covered by an excluded ancestor.
81
+ */
82
+ function walkSourceTree(dir) {
83
+ const files = [];
84
+ const ignoredDirs = [];
85
+ const visit = (current, prefix) => {
86
+ let entries = [];
87
+ try {
88
+ entries = fs.readdirSync(current, { withFileTypes: true });
89
+ } catch {
90
+ return;
91
+ }
92
+ for (const e of entries) {
93
+ const rel = prefix ? `${prefix}/${e.name}` : e.name;
94
+ if (!e.isDirectory()) files.push(path.join(current, e.name));
95
+ else if (IGNORED_DIR_RX.test(e.name)) ignoredDirs.push(rel);
96
+ else visit(path.join(current, e.name), rel);
97
+ }
98
+ };
99
+ visit(dir, '');
100
+ return { files, ignoredDirs: ignoredDirs.sort() };
101
+ }
102
+
103
+ const REACT_SCANNED_RX = /\.(swift|m|mm|c|h|hpp|cpp|cc)$/;
104
+ const NON_SWIFT_SOURCE_RX = /\.(m|mm|c|cpp|cc)$/;
105
+
106
+ function fileImportsReact(file) {
83
107
  try {
84
- entries = fs.readdirSync(dir, { withFileTypes: true });
108
+ return textImportsReact(fs.readFileSync(file, 'utf8'));
85
109
  } catch {
86
110
  return false;
87
111
  }
88
- for (const e of entries) {
89
- const p = path.join(dir, e.name);
90
- if (e.isDirectory()) {
91
- if (isIgnoredDir(e.name)) continue;
92
- if (sourceTreeImportsReact(p)) return true;
93
- } else if (/\.(swift|m|mm|c|h|hpp|cpp|cc)$/.test(e.name)) {
94
- let content = '';
95
- try {
96
- content = fs.readFileSync(p, 'utf8');
97
- } catch {
98
- continue;
99
- }
100
- if (textImportsReact(content)) return true;
101
- }
102
- }
103
- return false;
104
112
  }
105
113
 
106
114
  /**
107
- * The ignored directories under `dir`, relative to it and sorted. A generated
108
- * target must exclude exactly what classification skipped, or its production
109
- * library compiles test sources (and their `@testable` imports and mocks).
110
- * An ignored directory is not descended into: SwiftPM rejects an exclude path
111
- * already covered by an excluded ancestor.
115
+ * What classification needs from a module's Apple sources, from one walk of each
116
+ * source directory. `ignoredDirs` are the ones under the source directory a
117
+ * generated target compiles: it must exclude exactly what classification skipped,
118
+ * or its production library compiles test sources (and their `@testable` imports
119
+ * and mocks). React is looked for in `common/` too, which a module shares across
120
+ * platforms.
112
121
  */
113
- function collectIgnoredDirs(dir, prefix = '') {
114
- let entries = [];
115
- try {
116
- entries = fs.readdirSync(dir, { withFileTypes: true });
117
- } catch {
118
- return [];
119
- }
120
- const ignored = [];
121
- for (const e of entries) {
122
- if (!e.isDirectory()) continue;
123
- const rel = prefix ? `${prefix}/${e.name}` : e.name;
124
- if (isIgnoredDir(e.name)) ignored.push(rel);
125
- else ignored.push(...collectIgnoredDirs(path.join(dir, e.name), rel));
122
+ function scanAppleSources(moduleRoot) {
123
+ const sourceDir = appleSourceDir(moduleRoot);
124
+ let pureSwift = true;
125
+ let importsReact = false;
126
+ let ignoredDirs = [];
127
+ for (const sub of [...APPLE_SOURCE_DIRS, 'common']) {
128
+ const dir = path.join(moduleRoot, sub);
129
+ const tree = walkSourceTree(dir);
130
+ if (dir === sourceDir) ignoredDirs = tree.ignoredDirs;
131
+ for (const file of tree.files) {
132
+ if (sub !== 'common' && NON_SWIFT_SOURCE_RX.test(file)) pureSwift = false;
133
+ if (!importsReact && REACT_SCANNED_RX.test(file)) importsReact = fileImportsReact(file);
134
+ }
126
135
  }
127
- return prefix ? ignored : ignored.sort();
136
+ return { hasSources: sourceDir != null, pureSwift, importsReact, ignoredDirs };
128
137
  }
129
138
 
130
139
  /**
@@ -133,38 +142,8 @@ function collectIgnoredDirs(dir, prefix = '') {
133
142
  * Modules API does NOT inherit React — only modules whose own source imports the
134
143
  * React/Hermes/jsi families (or the core bridge layer itself) do.
135
144
  */
136
- function moduleNeedsReact(podName, moduleRoot) {
137
- if (CORE_REACT_PRODUCTS.has(podName)) return true;
138
- for (const sub of [...APPLE_SOURCE_DIRS, 'common']) {
139
- const dir = path.join(moduleRoot, sub);
140
- if (sourceTreeImportsReact(dir)) return true;
141
- }
142
- return false;
143
- }
144
-
145
- /** Cheap check: a module is pure-Swift if its iOS/apple source has no .m/.mm/.c/.cpp files. */
146
- function isPureSwift(moduleRoot) {
147
- const hasNonSwift = (dir) => {
148
- let entries = [];
149
- try {
150
- entries = fs.readdirSync(dir, { withFileTypes: true });
151
- } catch {
152
- return false;
153
- }
154
- for (const e of entries) {
155
- const p = path.join(dir, e.name);
156
- if (e.isDirectory()) {
157
- if (isIgnoredDir(e.name)) continue;
158
- if (hasNonSwift(p)) return true;
159
- } else if (/\.(m|mm|c|cpp|cc)$/.test(e.name)) {
160
- return true;
161
- }
162
- }
163
- return false;
164
- };
165
- return APPLE_SOURCE_DIRS.map((s) => path.join(moduleRoot, s))
166
- .filter((d) => fs.existsSync(d))
167
- .every((d) => !hasNonSwift(d));
145
+ function moduleNeedsReact(podName, sources) {
146
+ return CORE_REACT_PRODUCTS.has(podName) || sources.importsReact;
168
147
  }
169
148
 
170
149
  module.exports = {
@@ -173,11 +152,9 @@ module.exports = {
173
152
  REACT_IMPORT_RX,
174
153
  appleSourceDir,
175
154
  textImportsReact,
176
- sourceTreeImportsReact,
177
- collectIgnoredDirs,
178
155
  collectWatchPaths,
179
156
  documentedPackageRoot,
180
157
  findModuleRoot,
181
158
  moduleNeedsReact,
182
- isPureSwift,
159
+ scanAppleSources,
183
160
  };