Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Make manifest.env available in publish and export commands #540

Closed
wants to merge 1 commit into from

Conversation

rodrigorm
Copy link

@rodrigorm rodrigorm commented Apr 23, 2019

Make process.env variables available in manifest.env in expo publish and expo export commands like in expo start allowing a project to have a app.json with settings which can be set using environment variables, eg:

In app.json:

{
  "expo": {
    "extra": {
      "apiEndpoint": "http://www.example.com/api"
    }
  }
}

In src/App.js:

import { Constants } from 'expo';

class App extends Component {
  constructor(props) {
    super(props);
    this.apiUrl = process.env.EXPO_API_URL || Constants.manifest.extra.apiUrl;
  }
}
$ # Following already works in `start` command
$ EXPO_API_URL="http://localhost:8080/api" expo start
$ # Usage in `publish` command
$ EXPO_API_URL="http://localhost:8080/api" expo publish

@brentvatne
Copy link
Member

hey there! sorry nobody got back to you on this.

i think i would suggest using babel-plugin-inline-environment-variables instead of building similar functionality into expo-cli. open to be convinced, but i'll close this pr for now until i am convinced :)

@brentvatne brentvatne closed this Dec 6, 2019
@rodrigorm
Copy link
Author

rodrigorm commented Dec 10, 2019 via email

@brentvatne brentvatne reopened this Dec 11, 2019
@brentvatne
Copy link
Member

i'm not crazy about this existing on expo start but you raise a good point that it would seem to be consistent to have expo publish behave the same. i'll have to investigate the justification for including it on expo start in the first place to decide what we should do here. i appreciate your clarification, thanks!

@brentvatne brentvatne self-assigned this Dec 11, 2019
@brentvatne
Copy link
Member

ok i think this is reasonable to include. really sorry for the delay and back and forth on it. if you can resolve conflicts then i'll happily merge it. thanks @rodrigorm!

@rodrigorm
Copy link
Author

@brentvatne resolved the conflicts, but I am not sure if it is all working because the packages structure changed since my PR is open. Can you help me with the tests to verify the expected changes is working?

@brentvatne
Copy link
Member

hey @rodrigorm - thank you! I'll get back to you on this after the holiday

@brentvatne
Copy link
Member

brentvatne commented Jan 9, 2020

the change that you made should work fine, but i've thought about this more and i don't think that this is a safe change for us to make without some additional work. it's quite possible that some folks have environment variables with EXPO_ or REACT_NATIVE_ prefixes that contain sensitive information, and that others will do this in the future. this change would leak that information into the public via the published manifest.

i think an allow list (aka whitelist) rather than block list (aka blacklist) in app.json might be a safer way to expose environment variables. alternatively, we could put this behind an explicit flag or app.json config option

@brentvatne
Copy link
Member

actually a cleaner way to do this will be possible with #1342

you could explicitly pull out env vars and pass them through the extra field

@rodrigorm
Copy link
Author

@brentvatne you are right, variables like EXPO_APPLE_PASSWORD from other expo cli commands will be included in the manifest. Maybe it is better to remove this functionality even from the expo start command.

@brentvatne
Copy link
Member

closing this for now, will follow up in #1435 when #1342 is ready :) thank you for the insights @rodrigorm!

@brentvatne brentvatne closed this Jan 14, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants