Skip to content

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

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

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

@chrfalch chrfalch 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:

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()

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-cla meta-cla Bot 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
@chrfalch
chrfalch requested a review from cipolleschi July 24, 2026 07:47
@facebook-github-tools facebook-github-tools Bot 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
chrfalch force-pushed the chrfalch/fix-spm-raw-flow-annotations branch from 1515070 to 542fe9c Compare July 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
chrfalch force-pushed the chrfalch/fix-spm-raw-flow-annotations branch from 542fe9c to cfa4b25 Compare July 24, 2026 08:17

@cipolleschi cipolleschi 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

meta-codesync Bot commented Jul 24, 2026

Copy link
Copy Markdown

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Expo Partner: Expo Partner Shared with Meta Applied 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.

2 participants