Skip to content

Commit c87371b

Browse files
chrfalchclaude
andcommitted
fix(spm): Flow/ESLint/Prettier compliance for the SPM tooling
The newer toolchain on the rebased base flags deprecated Flow utility types and a few lint nits in the SPM scripts + test library: - Flow: `$ReadOnly`/`$ReadOnlyArray`/`$ReadOnlySet` -> `Readonly*`, `$Shape` -> `Partial`, `mixed` -> `unknown`, `+` variance sigil -> `readonly`; narrow the nullable remote-package config before reading `.url`/`.version` (the `plan.isRemote` branch didn't refine it). - ESLint: sort requires in expand-spm-dependencies.js and the two react-native-test-library entrypoints; drop unnecessary `\"` escapes in generate-spm-autolinking-test.js. - Prettier formatting on spm-pbxproj.js. No behavior change; 349 scripts/spm tests still green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8d8fa75 commit c87371b

11 files changed

Lines changed: 27 additions & 26 deletions

File tree

packages/react-native-test-library/apple/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
import type {Greeting} from 'react-native-test-library-common';
1414

15-
import {formatGreeting} from 'react-native-test-library-common';
1615
import {NativeModules, Platform} from 'react-native';
16+
import {formatGreeting} from 'react-native-test-library-common';
1717

1818
export function greet(g: Greeting): Promise<string> {
1919
const TestLibraryApple = NativeModules.TestLibraryApple;

packages/react-native-test-library/common/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import {NativeModules, Platform} from 'react-native';
1414

15-
export type Greeting = $ReadOnly<{
15+
export type Greeting = Readonly<{
1616
name: string,
1717
language: string,
1818
}>;

packages/react-native/scripts/spm/__tests__/generate-spm-autolinking-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ describe('generateSynthPackageSwift', () => {
256256
);
257257
// No header-search-path vars, no flags, no legacy VFS machinery.
258258
expect(result).not.toContain('rnCoreHeaders');
259-
expect(result).not.toContain('unsafeFlags([\"-I\"');
259+
expect(result).not.toContain('unsafeFlags(["-I"');
260260
expect(result).not.toContain('ReactHeadersAll');
261261
expect(result).not.toContain('-ivfsoverlay');
262262
expect(result).not.toContain('let xcfwHeaders');

packages/react-native/scripts/spm/expand-spm-dependencies.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
'use strict';
1212

1313
const {toSwiftName} = require('./spm-utils');
14+
const fs = require('fs');
15+
const path = require('path');
1416

1517
/**
1618
* expand-spm-dependencies.js — Resolves transitive native deps declared via
@@ -34,9 +36,6 @@ const {toSwiftName} = require('./spm-utils');
3436
* testable.
3537
*/
3638

37-
const fs = require('fs');
38-
const path = require('path');
39-
4039
/*::
4140
import type {AutolinkedDep} from './spm-types';
4241

packages/react-native/scripts/spm/generate-spm-autolinking.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ function inferPublicHeadersPath(sourcePath /*: string */) /*: string | null */ {
215215
}
216216

217217
/*::
218-
type ExtensionFilter = $ReadOnlySet<string>;
218+
type ExtensionFilter = ReadonlySet<string>;
219219
*/
220220

221221
const HEADER_EXTENSIONS /*: ExtensionFilter */ = new Set(['.h', '.hpp']);
@@ -234,7 +234,7 @@ const ALL_SOURCE_EXTENSIONS /*: ExtensionFilter */ = new Set([
234234
// Directory names whose contents should never be included in an SPM target —
235235
// test fixtures, Android sources, vendored modules. Shared between the source
236236
// walker and the header linker so they agree on what to skip.
237-
const SKIP_DIRS_DEFAULT /*: $ReadOnlySet<string> */ = new Set([
237+
const SKIP_DIRS_DEFAULT /*: ReadonlySet<string> */ = new Set([
238238
'android',
239239
'tests',
240240
'__tests__',
@@ -767,8 +767,8 @@ function autolinkingDepToSpmTarget(
767767
function generateAutolinkedPackageSwift(
768768
input /*: AggregatorInput */,
769769
) /*: string */ {
770-
const npmDeps /*: $ReadOnlyArray<NpmDepRef> */ = input.npmDeps ?? [];
771-
const inlineTargets /*: $ReadOnlyArray<SpmTarget> */ =
770+
const npmDeps /*: ReadonlyArray<NpmDepRef> */ = input.npmDeps ?? [];
771+
const inlineTargets /*: ReadonlyArray<SpmTarget> */ =
772772
input.inlineTargets ?? [];
773773
const hasReactDep /*: boolean */ = input.hasReactDep !== false;
774774
// Relative path from autolinked/ to build/xcframeworks/, e.g. "../build/xcframeworks".

packages/react-native/scripts/spm/generate-spm-xcodeproj.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ function injectSpmIntoPbxproj(
763763
// 1. Insert the new objects (skip any UUID already present — idempotency).
764764
const insertObjects = (
765765
sectionName /*: string */,
766-
objs /*: $ReadOnlyArray<{+uuid: string, +comment?: ?string, +fields: {+[string]: string}, ...}> */,
766+
objs /*: ReadonlyArray<{readonly uuid: string, readonly comment?: ?string, readonly fields: {readonly [string]: string}, ...}> */,
767767
) => {
768768
const fresh = objs.filter(o => !text.includes(o.uuid));
769769
for (const o of objs) {

packages/react-native/scripts/spm/read-podspec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const fs = require('fs');
3232
const path = require('path');
3333

3434
/*::
35-
type RawSpec = {[string]: mixed};
35+
type RawSpec = {[string]: unknown};
3636
*/
3737

3838
// ---------------------------------------------------------------------------
@@ -380,7 +380,7 @@ function flattenSubspecs(rawSpec /*: RawSpec */) /*: PodspecModel */ {
380380
const partial /*: boolean */ = rawSpec.__regex_partial__ === true;
381381
if (Array.isArray(rawSpec.__warnings__)) {
382382
// $FlowFixMe[incompatible-type] runtime-validated dynamic shape
383-
const rawWarnings /*: $ReadOnlyArray<string> */ = rawSpec.__warnings__;
383+
const rawWarnings /*: ReadonlyArray<string> */ = rawSpec.__warnings__;
384384
for (const w of rawWarnings) {
385385
warnings.push(w);
386386
}
@@ -598,7 +598,7 @@ function flattenSubspecs(rawSpec /*: RawSpec */) /*: PodspecModel */ {
598598
}
599599

600600
// $FlowFixMe[prop-missing] dynamic shape
601-
const reqArc /*: mixed */ = rawSpec.requires_arc;
601+
const reqArc /*: unknown */ = rawSpec.requires_arc;
602602
const requiresArc =
603603
reqArc === false || (Array.isArray(reqArc) && reqArc.length === 0)
604604
? false

packages/react-native/scripts/spm/scaffold-package-swift.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const SCAFFOLD_PREFIX_HEADER_CONTENTS = `// AUTO-SCAFFOLDED by react-native spm
122122
// Names of deps the scaffolder always refuses to touch — `react-native`
123123
// itself is handled by the xcframework subpackage, never as an autolinked
124124
// target.
125-
const NEVER_SCAFFOLD /*: $ReadOnlySet<string> */ = new Set(['react-native']);
125+
const NEVER_SCAFFOLD /*: ReadonlySet<string> */ = new Set(['react-native']);
126126

127127
// React-core / React-Fabric / etc. dependency names collapse to a single
128128
// `.product(name: "ReactNative", package: "ReactNative")` reference because
@@ -980,7 +980,7 @@ type ScaffoldAllOptions = {
980980
// npm dep names to skip entirely — used when the user declined the
981981
// confirmation prompt for first-time scaffolds. Skipped deps still
982982
// appear in the returned results array with status='skipped-opt-out'.
983-
skipDeps?: $ReadOnlyArray<string>,
983+
skipDeps?: ReadonlyArray<string>,
984984
};
985985
*/
986986

packages/react-native/scripts/spm/spm-pbxproj.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function quoteIfNeeded(s /*: string */) /*: string */ {
4343
* entries into an existing project.
4444
*/
4545
function serializeEntry(
46-
entry /*: {+uuid: string, +comment?: ?string, +fields: {+[string]: string}, ...} */,
46+
entry /*: {readonly uuid: string, readonly comment?: ?string, readonly fields: {readonly [string]: string}, ...} */,
4747
) /*: string */ {
4848
const comment =
4949
entry.comment != null && entry.comment !== ''
@@ -334,12 +334,14 @@ function addArrayMembers(
334334
text /*: string */,
335335
obj /*: BodyRange */,
336336
key /*: string */,
337-
members /*: $ReadOnlyArray<{+uuid: string, +comment?: ?string, ...}> */,
337+
members /*: ReadonlyArray<{readonly uuid: string, readonly comment?: ?string, ...}> */,
338338
options /*: {prepend?: boolean} */ = {},
339339
) /*: string */ {
340340
const fieldIndent = detectFieldIndent(text, obj);
341341
const memberIndent = fieldIndent + '\t';
342-
const line = (m /*: {+uuid: string, +comment?: ?string, ...} */) =>
342+
const line = (
343+
m /*: {readonly uuid: string, readonly comment?: ?string, ...} */,
344+
) =>
343345
`${memberIndent}${m.uuid}${m.comment != null && m.comment !== '' ? ` /* ${m.comment} */` : ''},\n`;
344346

345347
const field = findField(text, obj, key);
@@ -460,7 +462,7 @@ function removeObjectByUuid(
460462
*/
461463
function removeArrayMembersByUuid(
462464
text /*: string */,
463-
uuids /*: $ReadOnlyArray<string> */,
465+
uuids /*: ReadonlyArray<string> */,
464466
) /*: string */ {
465467
let out = text;
466468
for (const uuid of uuids) {
@@ -495,7 +497,7 @@ function removeArrayStringValues(
495497
text /*: string */,
496498
obj /*: BodyRange */,
497499
key /*: string */,
498-
values /*: $ReadOnlyArray<string> */,
500+
values /*: ReadonlyArray<string> */,
499501
) /*: string */ {
500502
const f = findField(text, obj, key);
501503
if (f == null) {

packages/react-native/scripts/spm/spm-types.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@ export type NpmDepRef = {
182182
};
183183
184184
export type AggregatorInput = {
185-
npmDeps?: $ReadOnlyArray<NpmDepRef>,
186-
inlineTargets?: $ReadOnlyArray<SpmTarget>,
185+
npmDeps?: ReadonlyArray<NpmDepRef>,
186+
inlineTargets?: ReadonlyArray<SpmTarget>,
187187
hasReactDep?: boolean,
188188
// Relative path from the aggregator's dir (autolinking/) to
189189
// build/xcframeworks. Used for the inline-target ReactNative dep.

0 commit comments

Comments
 (0)