Skip to content

feat: Adapt an inline-plugin for more cases#1732

Open
retyui wants to merge 1 commit into
react:mainfrom
retyui:update-inline-plugin
Open

feat: Adapt an inline-plugin for more cases#1732
retyui wants to merge 1 commit into
react:mainfrom
retyui:update-inline-plugin

Conversation

@retyui

@retyui retyui commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Summary

This v2 implementation that fixes the next missing cases of inline-plugin

  1. Relative imports (work only for react-native package files)
// 1. source code
import Platform from '../../Utilities/Platform';
Platform.OS === 'ios';

// 2. after `@react-native/babel-preset` preset
var _Platform = _interopRequireDefault(require("../../Utilities/Platform"));
_Platform.default.OS === 'ios';

// 3. after  `inline-plugin`
"android" === 'ios';
  1. Babel helpers for imports (import * as NAME from "<module>")
// 1. source code
import * as RN from 'react-native';
RN.Platform.OS === 'ios';

// 2. after `@react-native/babel-preset` preset
var RN = _interopRequireWildcard(require('react-native'));
RN.Platform.OS === 'ios';

// 3. after  `inline-plugin`
"android" === 'ios';

Other info:

  • Plugin check if Platform was imported from allowed package
  • I refactor a bit code structure to make more readable some important plugin parts
  • Add comments to explain some checks
  • Move duplicated checks to top level functions (see begin of: isPlatformNode, isPlatformSelectNode)
  • Cover with tests app possible scenarios
    • relative imports inside src folder or react-native package
    • relative imports uses Platform from associated module
    • both Platform.OS and Platform.select should works in new cases

Changelog: [Fix] Adapt an inline-plugin for more cases to remove a dead-code from final bundle

Test plan

yarn jest packages/metro-transform-plugins/src/__tests__/inline-plugin-test.js

@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 Jun 12, 2026
@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 Jun 12, 2026
@retyui retyui force-pushed the update-inline-plugin branch from f7cd701 to 29089f3 Compare June 12, 2026 14:48
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. 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.

1 participant