SPM: fix raw Flow type annotations in bare-node scripts#57660
Open
chrfalch wants to merge 1 commit into
Open
Conversation
chrfalch
force-pushed
the
chrfalch/fix-spm-raw-flow-annotations
branch
from
July 24, 2026 08:05
1515070 to
542fe9c
Compare
The scripts under `scripts/spm/` are executed as plain `node` (via
`setup-apple-spm.js` during the SwiftPM Xcode build), with no Babel to
strip Flow. They therefore use Flow-in-comment syntax (`/*: T */`)
throughout so they parse un-transpiled.
A handful of uninitialized `let X: T;` declarations had slipped in with
raw annotations. Node parses the whole file on `require`, so each one
threw `SyntaxError: Unexpected token ':'` at load time, taking the entire
module down. The jest suites didn't catch it because jest runs these
files through @react-native/babel-preset, which strips raw and
comment-form annotations alike.
Convert them to Flow-comment form. Prettier's `flow` parser only keeps a
comment type attached to the binding when the declaration is initialized,
so each site gets a type-appropriate initializer (the variable is always
reassigned in the immediately-following try/branch before any use, so the
initializer is inert):
autolinking-plugins.js 120, 178 /*: unknown */ = null
download-spm-artifacts.js 946, 973 /*: string */ = ''
download-spm-artifacts.js 1352 /*: {...} */ = {}
generate-spm-autolinking.js 429 /*: Array<...> */ = []
generate-spm-xcodeproj.js 1802 /*: string */ = ''
generate-spm-xcodeproj.js 1808 /*: unknown */ = null
generate-spm-xcodeproj.js 1863 /*: Array<...> */ = []
scaffold-package-swift.js 200, 1129 /*: Array<...> */ = []
scaffold-package-swift.js 933 (annotation dropped; Flow infers
PodspecModel from readPodspec())
`unknown` sites use `= null` rather than `= undefined` to satisfy the
`no-undef-init` lint rule.
Verified: `node --check` passes on all 14 spm scripts; eslint
(--max-warnings 0), prettier, and `flow focus-check` are all clean on the
touched files; the spm jest suites remain green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
chrfalch
force-pushed
the
chrfalch/fix-spm-raw-flow-annotations
branch
from
July 24, 2026 08:17
542fe9c to
cfa4b25
Compare
cipolleschi
approved these changes
Jul 24, 2026
cipolleschi
left a comment
Contributor
There was a problem hiding this comment.
thanks for fixing these
|
@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D113554595. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The scripts under
packages/react-native/scripts/spm/are executed as plainnode(viasetup-apple-spm.jsduring the SwiftPM Xcode build), with no Babel to strip Flow. They use Flow-in-comment syntax (/*: T */) throughout so they parse un-transpiled.A handful of uninitialized
let X: T;declarations had slipped in with raw Flow annotations. Node parses the whole file onrequire, so each one throwsSyntaxError: Unexpected token ':'at load time — taking the entire module down before it can run.The jest suites didn't catch it because jest runs these files through
@react-native/babel-preset, which strips raw and comment-form annotations alike. Only the bare-nodeshipped path (SwiftPM setup) hits the error.Fix
Convert each offending declaration to Flow-comment form. Prettier's
flowparser only keeps a comment type attached to the binding when the declaration is initialized, so each site gets a type-appropriate (inert) initializer — every variable is reassigned in the immediately-followingtry/branch before any use:autolinking-plugins.js/*: unknown */ = undefineddownload-spm-artifacts.js/*: string */ = ''download-spm-artifacts.js/*: {...} */ = {}generate-spm-autolinking.js/*: Array<...> */ = []generate-spm-xcodeproj.js/*: string */ = ''generate-spm-xcodeproj.js/*: unknown */ = undefinedgenerate-spm-xcodeproj.js/*: Array<...> */ = []scaffold-package-swift.js/*: Array<...> */ = []scaffold-package-swift.jsPodspecModelfromreadPodspec()Test plan
node --checkpasses on all 14scripts/spm/*.js(previouslyautolinking-plugins.jsanddownload-spm-artifacts.jsthrewSyntaxErrorat parse time).flow focus-checkreports 0 errors in the touched files.Changelog:
[INTERNAL] [FIXED] - Fix raw Flow type annotations that broke bare-node execution of the SwiftPM setup scripts
🤖 Generated with Claude Code