Skip to content

SPM: fix raw Flow type annotations in bare-node scripts - #57660

Closed
chrfalch wants to merge 1 commit into
mainfrom
chrfalch/fix-spm-raw-flow-annotations
Closed

SPM: fix raw Flow type annotations in bare-node scripts#57660
chrfalch wants to merge 1 commit into
mainfrom
chrfalch/fix-spm-raw-flow-annotations

Conversation

@chrfalch

@chrfalchchrfalch commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

Summary

The scripts under packages/react-native/scripts/spm/ are executed as plain node (via setup-apple-spm.js during 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 on require, so each one throws SyntaxError: 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-node shipped path (SwiftPM setup) hits the error.

Fix

Convert each offending declaration 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 (inert) initializer — every variable is reassigned in the immediately-following try/branch before any use:

filelinesform
autolinking-plugins.js120, 178/*: unknown */ = undefined
download-spm-artifacts.js946, 973/*: string */ = ''
download-spm-artifacts.js1352/*: {...} */ = {}
generate-spm-autolinking.js429/*: Array<...> */ = []
generate-spm-xcodeproj.js1802/*: string */ = ''
generate-spm-xcodeproj.js1808/*: unknown */ = undefined
generate-spm-xcodeproj.js1863/*: Array<...> */ = []
scaffold-package-swift.js200, 1129/*: Array<...> */ = []
scaffold-package-swift.js933annotation dropped — Flow infers PodspecModel from readPodspec()

Test plan

  • node --check passes on all 14 scripts/spm/*.js (previously autolinking-plugins.js and download-spm-artifacts.js threw SyntaxError at parse time).
  • flow focus-check reports 0 errors in the touched files.
  • Prettier: clean.
  • SPM jest suites: green.

Changelog:

[INTERNAL] [FIXED] - Fix raw Flow type annotations that broke bare-node execution of the SwiftPM setup scripts

🤖 Generated with Claude Code

@meta-clameta-claBot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 24, 2026
@facebook-github-toolsfacebook-github-toolsBot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Jul 24, 2026
@chrfalch
chrfalchforce-pushed the chrfalch/fix-spm-raw-flow-annotations branch from 1515070 to 542fe9cCompareJuly 24, 2026 08:05
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
chrfalchforce-pushed the chrfalch/fix-spm-raw-flow-annotations branch from 542fe9c to cfa4b25CompareJuly 24, 2026 08:17

@cipolleschicipolleschi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for fixing these

@meta-codesync

Copy link
Copy Markdown

@cipolleschi has imported this pull request. If you are a Meta employee, you can view this in D113554595.

@cortinicocortinico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

@meta-codesync

Copy link
Copy Markdown

@cipolleschi merged this pull request in e9eac58.

@meta-codesyncmeta-codesyncBot added the Merged This PR has been merged. label Jul 27, 2026
chrfalch added a commit that referenced this pull request Jul 27, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
chrfalch added a commit that referenced this pull request Jul 27, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
chrfalch added a commit that referenced this pull request Jul 28, 2026
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
fabriziocucci pushed a commit that referenced this pull request Aug 3, 2026
Summary:
The scripts under `packages/react-native/scripts/spm/` are executed as plain `node` (via `setup-apple-spm.js` during 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 on `require`, so each one throws `SyntaxError: 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-`node` shipped path (SwiftPM setup) hits the error.
## Fix
Convert each offending declaration 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 (inert) initializer — every variable is reassigned in the immediately-following `try`/branch before any use:
| file | lines | form |
|---|---|---|
| `autolinking-plugins.js` | 120, 178 | `/*: unknown */ = undefined` |
| `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 */ = undefined` |
| `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()` |
## Changelog:
[INTERNAL] [FIXED] - Fix raw Flow type annotations that broke bare-node execution of the SwiftPM setup scripts
Pull Request resolved: #57660
Test Plan:
- `node --check` passes on all 14 `scripts/spm/*.js` (previously `autolinking-plugins.js` and `download-spm-artifacts.js` threw `SyntaxError` at parse time).
- `flow focus-check` reports **0 errors** in the touched files.
- Prettier: clean.
- SPM jest suites: green.
## Changelog:
[INTERNAL] [FIXED] - Fix raw Flow type annotations that broke bare-node execution of the SwiftPM setup scripts
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reviewed By: cortinico
Differential Revision: D113554595
Pulled By: cipolleschi
fbshipit-source-id: b7fa29dd54266b749e1671333fb0530f6b6a8aab
(cherry picked from commit e9eac58)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA SignedThis label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.MergedThis PR has been merged.p: ExpoPartner: ExpoPartnerShared with MetaApplied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@chrfalch@cortinico@cipolleschi