Skip to content

Conversation

@molant
Copy link
Contributor

@molant molant commented Feb 28, 2020

Summary:

While working on #976 I saw that I needed to modify the properties requested to envinfo and that it was being accessed in a couple different places with different configurations.

This PR changes that to use a single point (and single configuration) to get the info.

Copy link
Member

@thymikee thymikee left a comment

Choose a reason for hiding this comment

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

This is great! Let's iterate on the typings so we don't have to cast


beforeAll(async () => {
environmentInfo = await getEnvironmentInfo();
environmentInfo = (await getEnvironmentInfo()) as EnvironmentInfo;
Copy link
Member

Choose a reason for hiding this comment

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

This is not good. Let's type getEnvironmentInfo properly so it returns correct type based on the arguments

@molant molant force-pushed the refactor/envinfo branch 4 times, most recently from 2773aba to 6fb73a2 Compare February 28, 2020 16:17
* If set to `false`, it will be a `string`.
*/
async function getEnvironmentInfo(): Promise<EnvironmentInfo>;
async function getEnvironmentInfo(json: boolean): Promise<string>;
Copy link
Contributor Author

@molant molant Feb 28, 2020

Choose a reason for hiding this comment

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

I'm not super thrilled with this but haven't come up with a better idea yet.

  • getEnvironmentInfo() return type will be EnvironmentInfo
  • getEnvironmentInfo(false) return type will be a string
  • getEnvironmentInfo(true) return type will be a string

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it finally right 😊

): Promise<string | EnvironmentInfo> {
const options = json
? {json: true, showNotFound: true}
: {json: false, showNotFound: true};
Copy link
Member

Choose a reason for hiding this comment

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

We can have a single object and use json value because it's already boolean

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

async function getEnvironmentInfo(
json = true,
): Promise<string | EnvironmentInfo> {
const options = {json, showNotFound: json};
Copy link
Member

Choose a reason for hiding this comment

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

I thought we always want to show Not Found?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm all for always showing Not Found. Is just that in one place it was explicit and in the other not (and I think the default is false).

I'll update the PR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

@molant molant force-pushed the refactor/envinfo branch 2 times, most recently from 8af0ba9 to 2bd4513 Compare February 29, 2020 20:47
@thymikee thymikee merged commit 9629311 into react-native-community:master Feb 29, 2020
@thymikee
Copy link
Member

Thanks!

@molant molant deleted the refactor/envinfo branch March 3, 2020 15:11
@grabbou
Copy link
Member

grabbou commented Mar 3, 2020

and that it was being accessed in a couple of different places with different configurations.

I only see a single call site being updated as a part of this PR. Are there any other places we haven't refactored?

@thymikee
Copy link
Member

thymikee commented Mar 3, 2020

This was the only one and it also got out of sync with options, so it's an improvement already.

@molant
Copy link
Contributor Author

molant commented Mar 3, 2020

The other call used tools/envinfo already. I meant a couple using the npm package 😊

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.

3 participants