Skip to content

chore(scripts): validate react-native export conditions in yarn constraints - #4370

Open
udit (UditDewan) wants to merge 1 commit into
microsoft:mainfrom
UditDewan:fix/lint-react-native-exports
Open

udit (UditDewan) wants to merge 1 commit into
microsoft:mainfrom
UditDewan:fix/lint-react-native-exports

Conversation

@UditDewan

Copy link
Copy Markdown

Platforms Impacted

  • iOS
  • macOS
  • win32 (Office)
  • windows
  • android

Description of changes

Addresses #3936 by enforcing the "react-native" export-condition pattern in package.json files.

Metro resolves the react-native export condition to TypeScript source. Nothing validated those targets, and one was already broken: @fluentui-react-native/tester pointed react-native at ./src/index.ts, but the entry file is ./src/index.tsx. Its default condition already uses .tsx.

scripts/src/tasks/constrain.ts adds ensureReactNativeExports, run as part of yarn constraints (and therefore yarn lint-repo) for every non-private workspace:

  • Each exports entry's "react-native" target must exist. If only the .ts/.tsx extension is wrong, yarn constraints --fix corrects it; otherwise it reports an error.
  • Packages that declare react-native in peerDependencies must provide a "react-native" condition on every export. All current RN libraries already comply, so this only guards new packages.
  • Node-only tooling (desktop-driver, storybook-desktop, scripts) and private apps are not affected.

apps/fluent-tester/package.json gets the fix from yarn constraints --fix, plus a patch changeset.

Verification

  • yarn constraints on main with the new rule reports exactly one error:
    @fluentui-react-native/tester: Invalid field exports["."]["react-native"]; expected "./src/index.tsx", found "./src/index.ts". After --fix it is clean.
  • Temporarily removing react-native from @fluentui-react-native/menu's exports and adding a bogus ./x entry produced both new errors (is missing a "react-native" condition, points to ./src/nope.ts, which does not exist). The edit was reverted afterward.
  • yarn build, yarn lint in scripts, yarn format:check, yarn change:check.
  • yarn knip fails identically on main (pre-existing unused-dependency findings); this change removes its apps/fluent-tester "Package entry file not found" hint.
Before After
react-native export targets are unchecked; tester's points at a missing file Constraint validates/fixes targets and requires the condition for RN libraries

Pull request checklist

This PR has considered (when applicable):

  • Automated Tests
  • Documentation and examples
  • Keyboard Accessibility
  • Voiceover
  • Internationalization and Right-to-left Layouts

Add a yarn constraint for published packages:
- each exports entry's "react-native" condition must point to a file
  that exists (auto-fixed when only the .ts/.tsx extension is wrong)
- packages that peer-depend on react-native must provide a
  "react-native" condition for every export

This catches @fluentui-react-native/tester, whose "react-native"
condition pointed at ./src/index.ts while the entry is ./src/index.tsx;
fixed via yarn constraints --fix.

Part of microsoft#3936
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant