Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break up require/import statements in strings #18222

Merged
merged 1 commit into from
Mar 5, 2020

Conversation

cpojer
Copy link
Contributor

@cpojer cpojer commented Mar 5, 2020

Summary

We have a number of dependency extractors in JavaScript tools, like Jest but also in internal FB tooling, that are using RegExp to extract static dependencies and create a graph. I am trying to reduce the amount of extractors we have at FB and noticed the Jest one has a few issues that are hard to fix with regex. I realize that RegExp dependency tracking is inherently imprecise but hope we can bear some minor inconvenience in just a few places.

In this PR I'm adjusting the React files we use to make sure require and import statements don't get extracted by Jest. Right now Jest extracts them, and when it looks up dependencies in reverse it just ignores the ones that don't exist. I'd like to make that fail hard in some tools and this change is a pre-requisite for that.

Test Plan

When running this dependencyExtractor from Jest (via jest-haste-map) on react-native, the React files (ReactFabric-dev.fb.js etc.) will no longer have invalid dependencies associated with them.

@codesandbox-ci
Copy link

codesandbox-ci bot commented Mar 5, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 49e68a0:

Sandbox Source
lucid-moore-5tcps Configuration

@sizebot
Copy link

sizebot commented Mar 5, 2020

Details of bundled changes.

Comparing: 6a0efdd...49e68a0

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactTestRenderer-dev.js +0.1% +0.1% 553.46 KB 553.88 KB 116.82 KB 116.93 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 38.39 KB 38.39 KB 9.29 KB 9.29 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 12.91 KB 12.91 KB 3.93 KB 3.93 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 552.33 KB 552.67 KB 114.97 KB 115.07 KB UMD_DEV
react-test-renderer.production.min.js 0.0% -0.0% 71.22 KB 71.22 KB 21.66 KB 21.66 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 526.38 KB 526.72 KB 113.66 KB 113.76 KB NODE_DEV
react-test-renderer.production.min.js 0.0% 0.0% 71.04 KB 71.04 KB 21.34 KB 21.34 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler.development.js +0.1% +0.1% 555.93 KB 556.27 KB 117.59 KB 117.7 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% 0.0% 16.24 KB 16.24 KB 4.96 KB 4.96 KB NODE_DEV
react-reconciler-reflection.production.min.js 0.0% 🔺+0.2% 2.8 KB 2.8 KB 1.2 KB 1.2 KB NODE_PROD
react-reconciler-persistent.development.js +0.1% +0.1% 554.58 KB 554.99 KB 117.45 KB 117.56 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% 0.0% 73.72 KB 73.72 KB 21.78 KB 21.78 KB NODE_PROD

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom-server.browser.development.js +0.1% +0.1% 135.19 KB 135.28 KB 34.75 KB 34.78 KB UMD_DEV
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.15 KB 1.15 KB 652 B 653 B NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.05 KB 20.05 KB 7.42 KB 7.42 KB UMD_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.86 KB 55.86 KB 14.46 KB 14.46 KB NODE_DEV
react-dom.development.js 0.0% 0.0% 884.16 KB 884.5 KB 194.84 KB 194.94 KB UMD_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 9.99 KB 9.99 KB 3.36 KB 3.37 KB NODE_PROD
react-dom.production.min.js 0.0% 0.0% 116.01 KB 116.01 KB 37.17 KB 37.17 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.54 KB 119.54 KB 38.33 KB 38.33 KB UMD_PROFILING
react-dom.development.js 0.0% +0.1% 841.41 KB 841.74 KB 192.41 KB 192.51 KB NODE_DEV
react-dom-server.node.development.js +0.1% +0.1% 129.48 KB 129.57 KB 34.58 KB 34.61 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 116.09 KB 116.09 KB 36.5 KB 36.5 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.38 KB 20.38 KB 7.52 KB 7.53 KB NODE_PROD
react-dom.profiling.min.js 0.0% 0.0% 119.77 KB 119.77 KB 37.58 KB 37.58 KB NODE_PROFILING
ReactDOM-dev.js 0.0% 0.0% 949.32 KB 949.74 KB 211.7 KB 211.8 KB FB_WWW_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.68 KB 3.68 KB 1.33 KB 1.33 KB NODE_DEV
ReactDOMTesting-dev.js 0.0% +0.1% 899.4 KB 899.81 KB 201 KB 201.16 KB FB_WWW_DEV
react-dom-server.browser.development.js +0.1% +0.1% 128.27 KB 128.35 KB 34.33 KB 34.36 KB NODE_DEV
react-dom-test-utils.development.js 0.0% 0.0% 53.77 KB 53.77 KB 14 KB 14 KB UMD_DEV
react-dom-server.browser.production.min.js 0.0% 0.0% 19.97 KB 19.97 KB 7.38 KB 7.38 KB NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.34 KB 3.34 KB 1.26 KB 1.26 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.94 KB 10.94 KB 4.16 KB 4.16 KB UMD_PROD
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.17 KB 1.17 KB 689 B 691 B UMD_PROD
ReactDOMServer-dev.js +0.1% +0.1% 138.16 KB 138.25 KB 35.22 KB 35.25 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 49.55 KB 49.55 KB 13.51 KB 13.51 KB NODE_DEV
ReactDOMServer-prod.js 0.0% -0.0% 47.49 KB 47.49 KB 11.05 KB 11.05 KB FB_WWW_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.3% 2.94 KB 2.94 KB 1.17 KB 1.17 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.79 KB 10.79 KB 4.09 KB 4.09 KB NODE_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.9 KB 58.9 KB 14.7 KB 14.7 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1013 B 1013 B 600 B 602 B NODE_PROD
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.26 KB 10.26 KB 3.49 KB 3.49 KB UMD_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactFabric-dev.js 0.0% +0.1% 614.69 KB 614.87 KB 132.86 KB 132.94 KB RN_OSS_DEV
ReactNativeRenderer-dev.js +0.1% +0.1% 632.59 KB 632.92 KB 137.13 KB 137.23 KB RN_OSS_DEV
ReactNativeRenderer-profiling.js 0.0% 0.0% 271.13 KB 271.13 KB 47.34 KB 47.34 KB RN_OSS_PROFILING

ReactDOM: size: 0.0%, gzip: 0.0%

Size changes (stable)

Generated by 🚫 dangerJS against 49e68a0

Copy link
Collaborator

@gaearon gaearon left a comment

Choose a reason for hiding this comment

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

Sure. Add a comment to each? “Intentionally broken down require” or something. Otherwise someone will regress.

@sizebot
Copy link

sizebot commented Mar 5, 2020

Details of bundled changes.

Comparing: 6a0efdd...49e68a0

react-dom

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-dom.profiling.min.js 0.0% 0.0% 123.84 KB 123.84 KB 38.64 KB 38.64 KB NODE_PROFILING
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 58.91 KB 58.91 KB 14.71 KB 14.71 KB UMD_DEV
ReactDOM-dev.js 0.0% 0.0% 905.76 KB 906.17 KB 202.13 KB 202.22 KB FB_WWW_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10.27 KB 10.27 KB 3.49 KB 3.5 KB UMD_PROD
ReactDOMServer-dev.js +0.1% +0.1% 137.31 KB 137.4 KB 35.08 KB 35.12 KB FB_WWW_DEV
react-dom-test-utils.development.js 0.0% 0.0% 53.78 KB 53.78 KB 14.01 KB 14.01 KB UMD_DEV
react-dom-test-utils.production.min.js 0.0% 0.0% 10.96 KB 10.96 KB 4.17 KB 4.17 KB UMD_PROD
ReactDOMTesting-dev.js 0.0% +0.1% 872.76 KB 873.17 KB 195.47 KB 195.59 KB FB_WWW_DEV
ReactDOMTesting-prod.js 0.0% 0.0% 368.74 KB 368.74 KB 67.46 KB 67.46 KB FB_WWW_PROD
react-dom-test-utils.development.js 0.0% 0.0% 49.56 KB 49.56 KB 13.52 KB 13.52 KB NODE_DEV
ReactDOMTesting-profiling.js 0.0% 0.0% 368.74 KB 368.74 KB 67.46 KB 67.46 KB FB_WWW_PROFILING
react-dom-server.node.development.js +0.1% +0.1% 131 KB 131.08 KB 34.81 KB 34.83 KB NODE_DEV
react-dom-test-utils.production.min.js 0.0% -0.0% 10.81 KB 10.81 KB 4.1 KB 4.1 KB NODE_PROD
react-dom-server.node.production.min.js 0.0% 0.0% 20.83 KB 20.83 KB 7.61 KB 7.61 KB NODE_PROD
react-dom.development.js 0.0% 0.0% 912.84 KB 913.18 KB 199.76 KB 199.86 KB UMD_DEV
react-dom-server.browser.development.js +0.1% +0.1% 136.78 KB 136.87 KB 34.96 KB 34.99 KB UMD_DEV
react-dom.production.min.js 0.0% 0.0% 119.89 KB 119.89 KB 38.28 KB 38.28 KB UMD_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.51 KB 20.51 KB 7.51 KB 7.51 KB UMD_PROD
react-dom.profiling.min.js 0.0% 0.0% 123.54 KB 123.54 KB 39.47 KB 39.47 KB UMD_PROFILING
react-dom.development.js 0.0% 0.0% 868.91 KB 869.24 KB 197.31 KB 197.4 KB NODE_DEV
react-dom-server.browser.development.js +0.1% +0.1% 129.78 KB 129.87 KB 34.55 KB 34.58 KB NODE_DEV
react-dom.production.min.js 0.0% 0.0% 120.04 KB 120.04 KB 37.52 KB 37.53 KB NODE_PROD
react-dom-server.browser.production.min.js 0.0% 0.0% 20.43 KB 20.43 KB 7.46 KB 7.46 KB NODE_PROD
ReactDOM-prod.js 0.0% 0.0% 376.26 KB 376.26 KB 68.37 KB 68.37 KB FB_WWW_PROD
react-dom-unstable-native-dependencies.development.js 0.0% 0.0% 55.87 KB 55.87 KB 14.47 KB 14.47 KB NODE_DEV
react-dom-unstable-fizz.node.development.js 0.0% +0.1% 3.69 KB 3.69 KB 1.34 KB 1.34 KB NODE_DEV
react-dom-unstable-native-dependencies.production.min.js 0.0% 🔺+0.1% 10 KB 10 KB 3.37 KB 3.38 KB NODE_PROD
react-dom-unstable-fizz.node.production.min.js 0.0% 🔺+0.2% 1.16 KB 1.16 KB 661 B 662 B NODE_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 3.35 KB 3.35 KB 1.27 KB 1.27 KB UMD_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1.19 KB 1.19 KB 697 B 699 B UMD_PROD
react-dom-unstable-fizz.browser.development.js 0.0% +0.2% 2.95 KB 2.95 KB 1.18 KB 1.18 KB NODE_DEV
react-dom-unstable-fizz.browser.production.min.js 0.0% 🔺+0.3% 1 KB 1 KB 608 B 610 B NODE_PROD

react-test-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactTestRenderer-dev.js +0.1% +0.1% 553.47 KB 553.89 KB 116.83 KB 116.94 KB FB_WWW_DEV
react-test-renderer-shallow.development.js 0.0% -0.0% 38.4 KB 38.4 KB 9.3 KB 9.3 KB UMD_DEV
react-test-renderer-shallow.production.min.js 0.0% 0.0% 12.92 KB 12.92 KB 3.94 KB 3.94 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 552.35 KB 552.69 KB 114.98 KB 115.08 KB UMD_DEV
react-test-renderer.production.min.js 0.0% -0.0% 71.25 KB 71.25 KB 21.67 KB 21.67 KB UMD_PROD
react-test-renderer.development.js +0.1% +0.1% 526.41 KB 526.74 KB 113.68 KB 113.77 KB NODE_DEV
react-test-renderer.production.min.js 0.0% 0.0% 71.06 KB 71.06 KB 21.36 KB 21.36 KB NODE_PROD

react-reconciler

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
react-reconciler-persistent.development.js +0.1% +0.1% 554.59 KB 555 KB 117.46 KB 117.56 KB NODE_DEV
react-reconciler-reflection.development.js 0.0% 0.0% 16.25 KB 16.25 KB 4.96 KB 4.97 KB NODE_DEV
react-reconciler-persistent.production.min.js 0.0% 0.0% 73.73 KB 73.73 KB 21.78 KB 21.78 KB NODE_PROD
react-reconciler-reflection.production.min.js 0.0% 🔺+0.1% 2.81 KB 2.81 KB 1.21 KB 1.21 KB NODE_PROD
react-reconciler.development.js +0.1% +0.1% 576.69 KB 577.02 KB 121.48 KB 121.58 KB NODE_DEV
react-reconciler.production.min.js 0.0% 0.0% 76.48 KB 76.48 KB 22.44 KB 22.44 KB NODE_PROD

react-native-renderer

File Filesize Diff Gzip Diff Prev Size Current Size Prev Gzip Current Gzip ENV
ReactNativeRenderer-profiling.js 0.0% 0.0% 271.15 KB 271.15 KB 47.35 KB 47.35 KB RN_OSS_PROFILING
ReactFabric-dev.js 0.0% +0.1% 617.34 KB 617.6 KB 133.2 KB 133.28 KB RN_FB_DEV
ReactNativeRenderer-dev.js +0.1% +0.1% 632.6 KB 632.93 KB 137.13 KB 137.23 KB RN_OSS_DEV
ReactNativeRenderer-dev.js +0.1% +0.1% 635.23 KB 635.64 KB 137.47 KB 137.58 KB RN_FB_DEV
ReactNativeRenderer-profiling.js 0.0% 0.0% 271.29 KB 271.29 KB 47.4 KB 47.4 KB RN_FB_PROFILING
ReactFabric-dev.js 0.0% +0.1% 614.7 KB 614.88 KB 132.87 KB 132.95 KB RN_OSS_DEV

ReactDOM: size: 0.0%, gzip: 🔺+0.1%

Size changes (experimental)

Generated by 🚫 dangerJS against 49e68a0

@cpojer
Copy link
Contributor Author

cpojer commented Mar 5, 2020

FB: The stack of D20282825 explains the reasons behind this change for FB employees.

@acdlite
Copy link
Collaborator

acdlite commented Mar 5, 2020

A comment definitely, would be extra nice to have a test or lint rule. Otherwise this absolutely will regress.

@cpojer cpojer merged commit 4027f2a into facebook:master Mar 5, 2020
@cpojer cpojer deleted the import-require branch March 5, 2020 22:27
sthagen added a commit to sthagen/facebook-react that referenced this pull request Mar 6, 2020
Break up require/import statements in strings (facebook#18222)
facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Mar 6, 2020
Summary:
Similar to the previous diff in this stack, I'm adjusting the React files we use to make sure require and import statements don't get extracted by Jest. Right now Jest extracts them, and when it looks up dependencies in reverse it just ignores the ones that don't exist.

Corresponding React PR (to make sure this change doesn't get reverted during the next sync): facebook/react#18222

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D20282829

fbshipit-source-id: 5ff6a64d31672dd29243d020e8174797a44d9267
osdnk pushed a commit to osdnk/react-native that referenced this pull request Mar 9, 2020
Summary:
Similar to the previous diff in this stack, I'm adjusting the React files we use to make sure require and import statements don't get extracted by Jest. Right now Jest extracts them, and when it looks up dependencies in reverse it just ignores the ones that don't exist.

Corresponding React PR (to make sure this change doesn't get reverted during the next sync): facebook/react#18222

Changelog: [Internal]

Reviewed By: motiz88

Differential Revision: D20282829

fbshipit-source-id: 5ff6a64d31672dd29243d020e8174797a44d9267
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants