-
Notifications
You must be signed in to change notification settings - Fork 24.4k
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
Support for configurable debug origin/port (issue 1429) #1546
Conversation
Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla - and if you have received this in error or have any questions, please drop us a line at cla@fb.com. Thanks! |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
I believe @frantic is the best person to review this |
); | ||
runOnlyForDeploymentPostprocessing = 0; | ||
shellPath = /bin/bash; | ||
shellScript = "export ORIGIN=$(/usr/libexec/PlistBuddy -c \"Print :RCTWebSocketExecutor:origin\" \"${INFOPLIST_FILE}\")\nexport PORT=$(/usr/libexec/PlistBuddy -c \"Print :RCTWebSocketExecutor:port\" \"${INFOPLIST_FILE}\")\n\nif nc -w 5 -z localhost $PORT ; then\n if ! curl -s \"${ORIGIN}:${PORT}/status\" | grep -q \"packager-status:running\" ; then\n echo \"Port ${PORT} already in use, packager is either not running or not running correctly\"\n exit 2\n fi\nelse\n # open w/t --args doesn't work:\n # open $SRCROOT/../../packager/launchPackager.command --args 111 222 || echo \"Can't start packager automatically\"\n osascript -e 'tell app \"Terminal\"\n do script \"'$SRCROOT'/../../packager/launchPackager.command --origin='${ORIGIN}' --port='${PORT}'\"\n end tell' || echo \"Can't start packager automatically\"\nfi"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script is very long, can you extract it to a separate file and call that file from here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@frantic Sure, can do. What's a good place to place that shell script? This one?: ./scripts
.
Good work, thank you! But I feel like we should probably do the other way around - have React target be pure and ReactWithPackager do what React target does now. @nicklockwood / @tadeuzagallo - do you think my suggestion makes sence? |
@frantic fwiw I agree with that structure, and would take it a step further by skipping ReactWithPackager and just having SampleApp, UIExplorer, TicTacToe, etc... call the packager from their own pbxproj files. |
@frantic @ide Thanks for the feedback. This is one of my weekend projects, please expect some delays etc. Now, you guys realize that that will break modified old projects. The
All those old |
command: 'origin', | ||
default: 'http://localhost', | ||
type: 'string', | ||
}, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi "origin" (as in specs like CORS) includes the port number
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ide I wanted to model it after HTML's location.origin
. But you are right, origin
includes the port number. Not sure whether hostname
would be a better choice, because it doesn't include the protocol
part. Is there a better name than origin
? I went through the HTML location properties. But nothing seems to fit...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we could split up protocol and hostname since most of the time (for development) the protocol is http and only the hostname needs to change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ide What I am hearing you say is that we should model everything after HTML location
and replace origin
with hostname
and protocol
. Is that what you are proposing? If so: I like it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! protocol
, hostname
, and port
as three separately configurable fields. Could even use Node's url.format()
to construct the complete origin string if that helps.
Ok, I've made the following changes:
But:
These are the custom port setting for each example:
Breaking changes: required/optional changes.If you have an old project and update your react-native module to this version then your old project will not launch the packager, because I removed the launch script from the React project. Here are the changes that are required/optional... REQUIRED: Add a launch scriptAdd a run script to your project with this line $SRCROOT/../../packager/launchPackager.command ${INFOPLIST_FILE} OPTIONAL: Use RCTWebSocketExecutorURLUse jsCodeLocation = RCTWebSocketExecutorURL(@"/Examples/SampleApp/index.ios.bundle"); OPTIONAL: Add a RCTWebSocketExecutor dictionaryAdd a Please let me know if this looks good to you. |
Hmm, Travis CI build failed. It looks like I need to add the launch scripts to every test targets. Give me a minute! |
One remaining problem is that |
@frantic I am a little bit puzzled why Travis CI is failing.
I even removed my workaround for #1654 . But that didn't help either. Would you know what's going on here? Thanks! |
I can now at least reproduce the problem locally w/t |
Ok, I found the problem (don't ask how I found it): react-native's For that reason this PR contains this workaround. In "babel": "5.4.3",
"babel-core": "5.5.6", Would somebody please figure out why |
Almost there: The last remaining build loop error is:
That's not really my problem, is it? |
|
4caebf4
to
bd925ac
Compare
Reviewed By: @DmitrySoshnikov Differential Revision: D2445071
Summary: I can't find anywhere these are being used by the bridge / native views anymore. I don't think they work anymore. ART has a similar API but uses a different code path. We might as well clean this up. Makes it easier to reason about. @public Reviewed By: @vjeux Differential Revision: D2445353
Summary: @public RCTNetworking currently relies on network responses to include an accurate text encoding, otherwise it is unable to convert the response data to text unless it's encoded as UTF8. See: facebook#1780 (comment) for details. This diff makes use of a new feature in iOS8 to detect the encoding of the text authomatically Reviewed By: @sahrens Differential Revision: D2443446
Jest 0.5.2 ships with a fix for bound functions, which RN exercises. And with this Travis change, the automated tests will install Node 4.x with nvm before running. Test Plan:`nvm use 4 && npm i && npm test` See if Travis tests pass.
Summary: beeper node modules has a `return` statement outside of a function which doesn't parse. To fix it, we mock it. Also, setupEnvPolyfills is no longer being used. Closes facebook#2770 Reviewed By: @svcscm Differential Revision: D2448882 Pulled By: @vjeux
…o webSocketConfig
Just to add my 2c here. This issue is important because it stops developers from getting on board as quickly as possible with debugging from devices. We still have to manually update RCTWebSocketManager.m, and these changes are overwritten when updating React Native. Now that hot reloading is a reality in React Native projects, it's even more important. |
Time is up. I am closing this PR. |
Hmm, too bad on this one. Given android is out now, maybe it's time to look at a single cross platform solution that doesn't depend on plist files or anything platform-specific. A global config file - maybe package.json? |
Sad, this is something that would be really useful. |
I've posted this on product pains so it would be great if you could upvote it there and show the react-native team that this is an important feature https://productpains.com/post/react-native/allow-packager-port-to-be-configurable-change-from-8081/ |
Reviewed By: frantic Differential Revision: D2613142 fb-gh-sync-id: fadcea3d23825420c0412f2e4d8d51c70b0f08ed
This PR adds support for configurable debug origin/port information as discussed in #1429 .
Summary
Here is a brief summary of my changes:
ReactWithoutPackager
toReact.xcodeproj
that is a copy of theReact
target but does not execute thelaunchPackager.command
script.UIExplorer
now links againstlibReactWithoutPackager.a
, which attracts theReactWithoutPackager
target w/olaunchPackager.command
.--origin
parameter topackager.sh
UIExplorer
that launcheslaunchPackager.command
with--origin
and--port
parameters.--origin
and--port
as parameters tolaunchPackager.command
andopen
w/t--args
does not seem to work withTerminal
, I changed that code to usingosascript
instead.Changing the port number
This is a screenshot after changing the port number to
8086
inInfo.plist
and rebuildingUIExplorer
:Backwards compatibility
I decided to make this change backwards compatible so clients can choose to continue using the old hard-coded origin/port (
http://localhost:8081
). The main reason is that many devs probably pick an example project and start modifying it to fit their needs. If we requiredInfo.plist
entries for origin/port values those old modified examples would break.Usage in examples
At this point I only modified
UIExplorer
to show that origin/port can be configured. But I could change all examples if needed.Utility function
There are three places where I added code that looks up the values for origin/port from
Info.plist
. That code is fairly trivial but could still be extracted and shared as a utility function. Please advise if that is necessary and let me know where I should add that utility function to.